KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > workflowtool > util > InfogluePropertySet


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23 package org.infoglue.cms.applications.workflowtool.util;
24
25 import java.io.UnsupportedEncodingException JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.Date JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.Properties JavaDoc;
31
32 import org.apache.log4j.Logger;
33 import org.w3c.dom.Document JavaDoc;
34
35 import com.opensymphony.module.propertyset.PropertyException;
36 import com.opensymphony.module.propertyset.PropertySet;
37 import com.opensymphony.module.propertyset.PropertySetSchema;
38
39 /**
40  *
41  */

42 public class InfogluePropertySet implements PropertySet {
43     /**
44      *
45      */

46     private final static Logger logger = Logger.getLogger(InfogluePropertySet.class.getName());
47
48     /**
49      *
50      */

51     private static final String JavaDoc UTF8_ENCODING = "utf-8";
52     
53     /**
54      *
55      */

56     private final PropertySet delegate;
57
58     
59     
60     /**
61      *
62      */

63     public InfogluePropertySet(final PropertySet delegate)
64     {
65         this.delegate = delegate;
66     }
67     
68     /**
69      *
70      */

71     public void setDataString(final String JavaDoc key, final String JavaDoc value) throws PropertyException
72     {
73         if(value == null || value.length() == 0)
74         {
75             if(exists(key))
76             {
77                 remove(key);
78             }
79         }
80         else
81         {
82             try
83             {
84                 logger.debug("PropertysetHelper.setData(\"" + key + "\",\"" + value + "\")");
85                 setData(key, value.getBytes(UTF8_ENCODING));
86             }
87             catch(UnsupportedEncodingException JavaDoc e)
88             {
89                 throw new PropertyException("Unable to set data for [" + key + "].");
90             }
91         }
92         
93     }
94
95     /**
96      *
97      */

98     public String JavaDoc getDataString(final String JavaDoc key) throws PropertyException
99     {
100         try
101         {
102             final byte[] b = getData(key);
103             final String JavaDoc value = (b == null) ? null : new String JavaDoc(b, UTF8_ENCODING);
104             logger.debug("PropertysetHelper.getData(\"" + key + "\")=\"" + (value == null ? "NULL" : value) + "\"");
105             return value;
106         }
107         catch(UnsupportedEncodingException JavaDoc e)
108         {
109             throw new PropertyException("Unable to get data for [" + key + "].");
110         }
111     }
112     
113     
114     /**
115      *
116      */

117     public void removeKeys(final String JavaDoc key, final boolean isPrefix) throws PropertyException
118     {
119         if(key == null)
120         {
121             remove();
122         }
123         else
124         {
125             if(isPrefix)
126             {
127                 for(Iterator JavaDoc i = getKeys(key).iterator(); i.hasNext(); )
128                 {
129                     remove(i.next().toString());
130                 }
131             }
132             else
133             {
134                 if(exists(key))
135                 {
136                     remove(key);
137                 }
138             }
139         }
140     }
141
142     /**
143      *
144      */

145     public String JavaDoc getAsString(final String JavaDoc key)
146     {
147         if(!exists(key) || getAsActualType(key) == null)
148         {
149             return null;
150         }
151         
152         switch(getType(key))
153         {
154             case PropertySet.BOOLEAN:
155                 return new Boolean JavaDoc(getBoolean(key)).toString();
156             case PropertySet.DATA:
157                 return getDataString(key);
158             case PropertySet.DATE:
159                 return getDate(key).toString();
160             case PropertySet.DOUBLE:
161                 return new Double JavaDoc(getDouble(key)).toString();
162             case PropertySet.INT:
163                 return new Integer JavaDoc(getInt(key)).toString();
164             case PropertySet.LONG:
165                 return new Long JavaDoc(getLong(key)).toString();
166             case PropertySet.STRING:
167                 return getString(key);
168             case PropertySet.TEXT:
169                 return getText(key);
170             default:
171                 logger.warn("Unsupported type [" + getType(key) + "].");
172         }
173         return null;
174     }
175     
176     
177     // -----------------------------------------------------------------------------
178
// --- delegate
179
// -----------------------------------------------------------------------------
180

181     /**
182      *
183      */

184     public boolean exists(String JavaDoc key) throws PropertyException
185     {
186         return delegate.exists(key);
187     }
188
189     /**
190      *
191      */

192     public Object JavaDoc getAsActualType(String JavaDoc key) throws PropertyException
193     {
194         return delegate.exists(key) ? delegate.getAsActualType(key) : null;
195     }
196
197     /**
198      *
199      */

200     public boolean getBoolean(String JavaDoc key) throws PropertyException
201     {
202         return delegate.getBoolean(key);
203     }
204
205     /**
206      *
207      */

208     public byte[] getData(String JavaDoc key) throws PropertyException
209     {
210         return delegate.getData(key);
211     }
212
213     /**
214      *
215      */

216     public Date JavaDoc getDate(String JavaDoc key) throws PropertyException
217     {
218         return delegate.getDate(key);
219     }
220
221     /**
222      *
223      */

224     public double getDouble(String JavaDoc key) throws PropertyException
225     {
226         return delegate.getDouble(key);
227     }
228
229     /**
230      *
231      */

232     public int getInt(String JavaDoc key) throws PropertyException
233     {
234         return delegate.getInt(key);
235     }
236
237     /**
238      *
239      */

240     public Collection JavaDoc getKeys() throws PropertyException
241     {
242         return delegate.getKeys();
243     }
244
245     /**
246      *
247      */

248     public Collection JavaDoc getKeys(int type) throws PropertyException
249     {
250         return delegate.getKeys(type);
251     }
252
253     /**
254      *
255      */

256     public Collection JavaDoc getKeys(String JavaDoc prefix, int type) throws PropertyException
257     {
258         return delegate.getKeys(prefix, type);
259     }
260
261     /**
262      *
263      */

264     public Collection JavaDoc getKeys(String JavaDoc prefix) throws PropertyException
265     {
266         return delegate.getKeys(prefix);
267     }
268
269     /**
270      *
271      */

272     public long getLong(String JavaDoc key) throws PropertyException
273     {
274         return delegate.getLong(key);
275     }
276
277     /**
278      *
279      */

280     public Object JavaDoc getObject(String JavaDoc key) throws PropertyException
281     {
282         return delegate.getObject(key);
283     }
284
285     /**
286      *
287      */

288     public Properties JavaDoc getProperties(String JavaDoc key) throws PropertyException
289     {
290         return delegate.getProperties(key);
291     }
292
293     /**
294      *
295      */

296     public PropertySetSchema getSchema() throws PropertyException
297     {
298         return delegate.getSchema();
299     }
300
301     /**
302      *
303      */

304     public String JavaDoc getString(String JavaDoc key) throws PropertyException
305     {
306         return delegate.getString(key);
307     }
308
309     /**
310      *
311      */

312     public String JavaDoc getText(String JavaDoc key) throws PropertyException
313     {
314         return delegate.getText(key);
315     }
316
317     /**
318      *
319      */

320     public int getType(String JavaDoc key) throws PropertyException
321     {
322         return delegate.getType(key);
323     }
324
325     /**
326      *
327      */

328     public Document JavaDoc getXML(String JavaDoc key) throws PropertyException
329     {
330         return delegate.getXML(key);
331     }
332
333     /**
334      *
335      */

336     public void init(Map JavaDoc config, Map JavaDoc args)
337     {
338         delegate.init(config, args);
339     }
340
341     /**
342      *
343      */

344     public boolean isSettable(String JavaDoc property)
345     {
346         return delegate.isSettable(property);
347     }
348
349     /**
350      *
351      */

352     public void remove() throws PropertyException
353     {
354         delegate.remove();
355     }
356
357     /**
358      *
359      */

360     public void remove(String JavaDoc key) throws PropertyException
361     {
362         delegate.remove(key);
363     }
364
365     /**
366      *
367      */

368     public void setAsActualType(String JavaDoc key, Object JavaDoc value) throws PropertyException
369     {
370         delegate.setAsActualType(key, value);
371     }
372
373     /**
374      *
375      */

376     public void setBoolean(String JavaDoc key, boolean value) throws PropertyException
377     {
378         delegate.setBoolean(key, value);
379     }
380
381     /**
382      *
383      */

384     public void setData(String JavaDoc key, byte[] value) throws PropertyException
385     {
386         delegate.setData(key, value);
387     }
388
389     /**
390      *
391      */

392     public void setDate(String JavaDoc key, Date JavaDoc value) throws PropertyException
393     {
394         delegate.setDate(key, value);
395     }
396
397     /**
398      *
399      */

400     public void setDouble(String JavaDoc key, double value) throws PropertyException
401     {
402         delegate.setDouble(key, value);
403     }
404
405     /**
406      *
407      */

408     public void setInt(String JavaDoc key, int value) throws PropertyException
409     {
410         delegate.setInt(key, value);
411     }
412
413     /**
414      *
415      */

416     public void setLong(String JavaDoc key, long value) throws PropertyException
417     {
418         delegate.setLong(key, value);
419     }
420
421     /**
422      *
423      */

424     public void setObject(String JavaDoc key, Object JavaDoc value) throws PropertyException
425     {
426         delegate.setObject(key, value);
427     }
428
429     /**
430      *
431      */

432     public void setProperties(String JavaDoc key, Properties JavaDoc value) throws PropertyException
433     {
434         delegate.setProperties(key, value);
435     }
436
437     /**
438      *
439      */

440     public void setSchema(PropertySetSchema schema) throws PropertyException
441     {
442         delegate.setSchema(schema);
443     }
444
445     /**
446      *
447      */

448     public void setString(String JavaDoc key, String JavaDoc value) throws PropertyException
449     {
450         delegate.setString(key, value);
451     }
452
453     /**
454      *
455      */

456     public void setText(String JavaDoc key, String JavaDoc value) throws PropertyException
457     {
458         delegate.setText(key, value);
459     }
460
461     /**
462      *
463      */

464     public void setXML(String JavaDoc key, Document JavaDoc value) throws PropertyException
465     {
466         delegate.setXML(key, value);
467     }
468
469     /**
470      *
471      */

472     public boolean supportsType(int type)
473     {
474         return delegate.supportsType(type);
475     }
476
477     /**
478      *
479      */

480     public boolean supportsTypes()
481     {
482         return delegate.supportsTypes();
483     }
484 }
Popular Tags