KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > pages > PageProperty


1 package org.jahia.services.pages;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Set JavaDoc;
6 import java.io.Serializable JavaDoc;
7
8 /**
9  * <p>Title: Page property bean object </p>
10  * <p>Description: This object contains all the values for multilingual
11  * page properties. This class does not support versioning or workflow
12  * elements for the moment.</p>
13  * <p>Copyright: Copyright (c) 2002</p>
14  * <p>Company: </p>
15  *
16  * @author Serge Huber
17  * @version 1.0
18  */

19
20 public class PageProperty implements Serializable JavaDoc {
21
22     public final static String JavaDoc SHARED_LANGUAGE_MARKER = "shared";
23
24     public final static String JavaDoc PAGE_URL_KEY_PROPNAME = "pageURLKey";
25
26     private int pageID;
27     private String JavaDoc name;
28     // The following hashmas' key is a language code, and the value is
29
// a string representing the value for the property. If the key is SHARED_LANGUAGE_MARKER
30
// then this entry is matched for any languages.
31
private HashMap JavaDoc languageValues;
32
33     protected PageProperty (int pageID, String JavaDoc name) {
34         this.pageID = pageID;
35         this.name = name;
36         languageValues = new HashMap JavaDoc ();
37     }
38
39     /**
40      * Returns the page ID this property is attached to.
41      *
42      * @return an integer corresponding to the page ID of this property
43      */

44     public int getPageID () {
45         return pageID;
46     }
47
48     /**
49      * Returns the name of the property
50      *
51      * @return a string containing the name of the property
52      */

53     public String JavaDoc getName () {
54         return name;
55     }
56
57     /**
58      * Returns the value for the property. This is the "default value" that
59      * is returned. If accessing multi-language properties, please use the
60      * other getValue(String languageCode) method.
61      *
62      * @return a String containing the property default value.
63      */

64     public String JavaDoc getValue () {
65         return getValue (SHARED_LANGUAGE_MARKER);
66     }
67
68     /**
69      * Returns the value for the property according to the language passed.
70      * This value might be empty if no value exists NEITHER for the language
71      * nor the default value. If there is a default value it will be returned
72      * in place of the language entry.
73      *
74      * @param languageCode the RFC 3066 language code for which to retrieve the
75      * property value.
76      *
77      * @return a String containing the value of the property for the given
78      * language, or the default value, or an empty String if neither values
79      * could be found.
80      */

81     public String JavaDoc getValue (String JavaDoc languageCode) {
82         if (languageValues.containsKey (languageCode)) {
83             return (String JavaDoc) languageValues.get (languageCode);
84         }
85
86         if (languageValues.containsKey (SHARED_LANGUAGE_MARKER)) {
87             return (String JavaDoc) languageValues.get (SHARED_LANGUAGE_MARKER);
88         }
89
90         return "";
91     }
92
93     /**
94      * Sets the default value for the property. This value will be used either
95      * when retrieving a value without specifying a language, or when trying
96      * to retrieve a language for which no value is defined.
97      *
98      * @param value the String value for the property (must convert to String
99      * if coming from a non string value)
100      */

101     public void setValue (String JavaDoc value) {
102         setValue (value, SHARED_LANGUAGE_MARKER);
103     }
104
105     /**
106      * Sets the property value for a given language.
107      *
108      * @param value the String value for the property (must convert to String
109      * if coming from another type of object)
110      * @param languageCode the RFC 3066 language code for which to stored the
111      * property.
112      */

113     public void setValue (String JavaDoc value, String JavaDoc languageCode) {
114         languageValues.put (languageCode, value);
115     }
116
117     /**
118      * Returns an iterator on the language codes contained in the language
119      * values internal structure
120      *
121      * @return an iterator of String object that correspond to the available
122      * languages in this property.
123      */

124     public Iterator JavaDoc getLanguageCodes () {
125         Set JavaDoc languagesCodeSet = languageValues.keySet ();
126         return languagesCodeSet.iterator ();
127     }
128
129 }
130
Popular Tags