KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > pci > model > ExoPortletPreferences


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.portletcontainer.pci.model;
6
7 import java.io.Serializable JavaDoc;
8 import java.util.*;
9 import javax.portlet.* ;
10 import org.exoplatform.commons.utils.ExoEnumeration;
11
12 /**
13  * Jun 9, 2004
14  * @author: Tuan Nguyen
15  * @email: tuan08@users.sourceforge.net
16  * @version: $Id: ExoPortletPreferences.java,v 1.1 2004/07/13 02:31:13 tuan08 Exp $
17  */

18 public class ExoPortletPreferences extends HashMap implements PortletPreferences, Serializable JavaDoc {
19   private String JavaDoc preferencesValidator ;
20     
21   public Map getMap() { return this ; }
22   
23     public boolean isReadOnly(String JavaDoc key) {
24     if(key == null) throw new IllegalArgumentException JavaDoc("preference name is null") ;
25         Preference preference = (Preference) get(key) ;
26     if(preference == null) return false ;
27     return preference.isReadOnly() ;
28   }
29     
30   public java.lang.String JavaDoc getValue(String JavaDoc key, String JavaDoc def) {
31     if(key == null) throw new IllegalArgumentException JavaDoc("preference name is null") ;
32     Preference preference = (Preference) get(key) ;
33     return preference.getValue(def) ;
34   }
35   
36   public String JavaDoc[] getValues(String JavaDoc key, String JavaDoc[] def) {
37     if(key == null) throw new IllegalArgumentException JavaDoc("preference name is null") ;
38     Preference preference = (Preference) get(key) ;
39     if(preference == null) return def ;
40     return preference.getValues(key, def) ;
41   }
42   
43   public void setValue(String JavaDoc key, String JavaDoc value) throws ReadOnlyException {
44      if(key == null) throw new IllegalArgumentException JavaDoc("preference name is null") ;
45      Preference preference = (Preference) get(key) ;
46      if(preference == null) {
47        preference = new Preference() ;
48        preference.setName(key) ;
49        put(key, preference) ;
50      }
51      if(preference.isReadOnly()) throw new ReadOnlyException("This preference is readonly") ;
52      if(value == null) return ;
53      preference.addValue(value) ;
54   }
55   
56   public void setValues(String JavaDoc key, String JavaDoc[] value) throws ReadOnlyException {
57     if(key == null) throw new IllegalArgumentException JavaDoc("preference name is null") ;
58     Preference preference = (Preference) get(key) ;
59     if(preference == null) {
60       preference = new Preference() ;
61       preference.setName(key) ;
62       put(key, preference) ;
63     }
64     if(preference.isReadOnly()) throw new ReadOnlyException("This preference is readonly") ;
65     if(value == null) return ;
66     ArrayList list = new ArrayList() ;
67     for(int i = 0; i < value.length; i++) {
68         list.add(value[i]) ;
69     }
70     preference.setValues(list) ;
71  }
72   
73   public Enumeration getNames() {
74     return new ExoEnumeration(keySet().iterator()) ;
75   }
76   
77   public void reset(java.lang.String JavaDoc key) throws ReadOnlyException {
78     if(key == null) throw new IllegalArgumentException JavaDoc("preference name is null") ;
79     Preference preference = (Preference) get(key) ;
80     if(preference == null) return ;
81     if(preference.isReadOnly()) throw new ReadOnlyException("This preference is readonly") ;
82     preference.clear() ;
83   }
84   
85   public void store() throws java.io.IOException JavaDoc, ValidatorException {
86     throw new Error JavaDoc("NOT SUPPORT") ;
87   }
88   
89   public void addPreference(Preference pref) {
90     put(pref.getName(), pref) ;
91   }
92   
93     public String JavaDoc getPreferencesValidator() {
94         return preferencesValidator;
95     }
96   
97     public void setPreferencesValidator(String JavaDoc preferencesValidator) {
98         this.preferencesValidator = preferencesValidator;
99     }
100 }
Popular Tags