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