1*cdf0e10cSrcweir /* 2*cdf0e10cSrcweir ************************************************************************ 3*cdf0e10cSrcweir * 4*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * This file is part of OpenOffice.org. 11*cdf0e10cSrcweir * 12*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 13*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 14*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 15*cdf0e10cSrcweir * 16*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 17*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 18*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 20*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 21*cdf0e10cSrcweir * 22*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 23*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 24*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 25*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 26*cdf0e10cSrcweir * 27*cdf0e10cSrcweir ************************************************************************/ 28*cdf0e10cSrcweir /* 29*cdf0e10cSrcweir * Properties.java 30*cdf0e10cSrcweir * 31*cdf0e10cSrcweir * Created on 1. Oktober 2003, 17:16 32*cdf0e10cSrcweir */ 33*cdf0e10cSrcweir package com.sun.star.wizards.common; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 36*cdf0e10cSrcweir import java.util.*; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir /** 39*cdf0e10cSrcweir * Simplifies handling Arrays of PropertyValue. 40*cdf0e10cSrcweir * To make a use of this class, instantiate it, and call 41*cdf0e10cSrcweir * the put(propName,propValue) method. 42*cdf0e10cSrcweir * caution: propName should always be a String. 43*cdf0e10cSrcweir * When finished, call the getProperties() method to get an array of the set properties. 44*cdf0e10cSrcweir * @author rp 45*cdf0e10cSrcweir */ 46*cdf0e10cSrcweir public class Properties extends Hashtable 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir public static Object getPropertyValue(PropertyValue[] props, String propName) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir for (int i = 0; i < props.length; i++) 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir if (propName.equals(props[i].Name)) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir return props[i].Value; 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir throw new IllegalArgumentException("Property '" + propName + "' not found."); 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir public static boolean hasPropertyValue(PropertyValue[] props, String propName) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir for (int i = 0; i < props.length; i++) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir if (propName.equals(props[i].Name)) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir return true; 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir return false; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir public PropertyValue[] getProperties() 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir return getProperties(this); 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir public static PropertyValue[] getProperties(Map map) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir PropertyValue[] pv = new PropertyValue[map.size()]; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir Iterator it = map.keySet().iterator(); 83*cdf0e10cSrcweir for (int i = 0; i < pv.length; i++) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir pv[i] = createProperty((String) it.next(), map); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir return pv; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir public static PropertyValue createProperty(String name, Map map) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir return createProperty(name, map.get(name)); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir public static PropertyValue createProperty(String name, Object value) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir PropertyValue pv = new PropertyValue(); 98*cdf0e10cSrcweir pv.Name = name; 99*cdf0e10cSrcweir pv.Value = value; 100*cdf0e10cSrcweir return pv; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir public static PropertyValue createProperty(String name, Object value, int handle) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir PropertyValue pv = createProperty(name, value); 106*cdf0e10cSrcweir pv.Handle = handle; 107*cdf0e10cSrcweir return pv; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir public static PropertyValue[] convertToPropertyValueArray(Object[] _oObjectArray) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir PropertyValue[] retproperties = null; 113*cdf0e10cSrcweir if (_oObjectArray != null) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir if (_oObjectArray.length > 0) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir retproperties = new PropertyValue[_oObjectArray.length]; 118*cdf0e10cSrcweir for (int i = 0; i < _oObjectArray.length; i++) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir retproperties[i] = (PropertyValue) _oObjectArray[i]; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir return retproperties; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir } 127