1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 package com.sun.star.wizards.common; 19 20 import com.sun.star.beans.PropertyValue; 21 import java.util.*; 22 23 /** 24 * Simplifies handling Arrays of PropertyValue. 25 * To make a use of this class, instantiate it, and call 26 * the put(propName,propValue) method. 27 * caution: propName should always be a String. 28 * When finished, call the getProperties() method to get an array of the set properties. 29 */ 30 public class Properties extends HashMap<String,Object> 31 { 32 getPropertyValue(PropertyValue[] props, String propName)33 public static Object getPropertyValue(PropertyValue[] props, String propName) 34 { 35 for (int i = 0; i < props.length; i++) 36 { 37 if (propName.equals(props[i].Name)) 38 { 39 return props[i].Value; 40 } 41 } 42 throw new IllegalArgumentException("Property '" + propName + "' not found."); 43 } 44 hasPropertyValue(PropertyValue[] props, String propName)45 public static boolean hasPropertyValue(PropertyValue[] props, String propName) 46 { 47 for (int i = 0; i < props.length; i++) 48 { 49 if (propName.equals(props[i].Name)) 50 { 51 return true; 52 } 53 } 54 return false; 55 } 56 createProperty(String name, Object value)57 public static PropertyValue createProperty(String name, Object value) 58 { 59 PropertyValue pv = new PropertyValue(); 60 pv.Name = name; 61 pv.Value = value; 62 return pv; 63 } 64 createProperty(String name, Object value, int handle)65 public static PropertyValue createProperty(String name, Object value, int handle) 66 { 67 PropertyValue pv = createProperty(name, value); 68 pv.Handle = handle; 69 return pv; 70 } 71 convertToPropertyValueArray(Object[] _oObjectArray)72 public static PropertyValue[] convertToPropertyValueArray(Object[] _oObjectArray) 73 { 74 PropertyValue[] retproperties = null; 75 if (_oObjectArray != null && _oObjectArray.length > 0) 76 { 77 retproperties = new PropertyValue[_oObjectArray.length]; 78 for (int i = 0; i < _oObjectArray.length; i++) 79 { 80 retproperties[i] = (PropertyValue) _oObjectArray[i]; 81 } 82 } 83 return retproperties; 84 } 85 } 86