KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > fields > JahiaFieldDefinition


1 //
2
// JahiaFieldDefinition
3
// EV 25.11.2000
4
//
5
// getID
6
// getJahiaID
7
// getName
8
// getSubDefs
9
// getTemplateID
10
// getTitle
11
// getType
12
// getDefaultValue
13
//
14
// setID
15
// setTitle
16
// setType
17
// setDefaultValue
18
//
19

20 package org.jahia.data.fields;
21
22 import java.util.Hashtable JavaDoc;
23 import java.util.Locale JavaDoc;
24 import java.util.Properties JavaDoc;
25
26 import org.jahia.content.ContentDefinition;
27 import org.jahia.content.ContentObject;
28 import org.jahia.content.FieldDefinitionKey;
29 import org.jahia.exceptions.JahiaException;
30 import org.jahia.resourcebundle.ResourceBundleMarker;
31 import org.jahia.services.fields.ContentField;
32 import org.jahia.services.pages.ContentPage;
33 import org.jahia.services.version.ContentObjectEntryState;
34 import org.jahia.services.version.EntryLoadRequest;
35 import org.jahia.utils.LanguageCodeConverters;
36 import java.io.Serializable JavaDoc;
37
38 public class JahiaFieldDefinition extends ContentDefinition implements Serializable JavaDoc {
39
40     private static org.apache.log4j.Logger logger =
41             org.apache.log4j.Logger.getLogger(JahiaFieldDefinition.class);
42
43     static {
44         ContentDefinition.registerType(FieldDefinitionKey.FIELD_TYPE,
45                                    JahiaFieldDefinition.class.getName());
46     }
47
48
49     private int ID;
50     private int jahiaID;
51     private String JavaDoc name;
52
53     /**
54      * @associates JahiaFieldSubDefinition
55      */

56     private Hashtable JavaDoc subDefs;
57
58
59     private Properties JavaDoc props = new Properties JavaDoc();
60
61     /***
62         * constructor
63         * EV 25.11.2000
64         *
65         */

66     public JahiaFieldDefinition(int ID,
67                                 int jahiaID,
68                                 String JavaDoc name,
69                                 Hashtable JavaDoc subDefs )
70     {
71         super(new FieldDefinitionKey(ID));
72         this.ID = ID;
73         this.jahiaID = jahiaID;
74         this.name = name;
75         this.subDefs = subDefs;
76     } // end constructor
77

78
79     /**
80      * No arg constructor required for serialization support.
81      */

82     protected JahiaFieldDefinition() {
83
84     }
85
86     /***
87         * accessor methods
88         * EV 25.11.2000
89         *
90         */

91     public int getID() { return ID; }
92     public int getJahiaID() { return jahiaID; }
93     public String JavaDoc getName() { return name; }
94     public Hashtable JavaDoc getSubDefs() { return subDefs; }
95     public Properties JavaDoc getProperties() { return this.props; }
96
97     public void setID( int value ) {
98         this.ID = value;
99         setObjectKey(new FieldDefinitionKey(ID));
100     }
101
102     public void setProperties( Properties JavaDoc props ){
103         if ( props != null ){
104             this.props = props;
105         }
106     }
107
108     public String JavaDoc getProperty(String JavaDoc name){
109         return this.props.getProperty(name);
110     }
111
112     public void setProperty(String JavaDoc name, String JavaDoc value){
113         if ( name != null && value != null ){
114             this.props.setProperty(name,value);
115         }
116     }
117
118     /**
119      *
120      * @param IDInType
121      * @param loadRequest
122      * @return
123      */

124     public static ContentDefinition getChildInstance(String JavaDoc IDInType) {
125
126         try {
127             return org.jahia.registries.JahiaFieldDefinitionsRegistry
128                 .getInstance().getDefinition(Integer.parseInt(IDInType));
129         } catch (JahiaException je) {
130             logger.debug("Error retrieving ContentDefinition instance for id : " + IDInType, je);
131         }
132         return null;
133     }
134
135     /**
136      *
137      * @param contentObject
138      * @param entryState
139      * @return
140      */

141     public String JavaDoc getTitle( ContentObject contentObject,
142                             ContentObjectEntryState entryState ) {
143         String JavaDoc title = "";
144         int pageID = ((ContentField)contentObject).getPageID();
145         try {
146             int pageDefID = ContentPage.getPage(pageID)
147                           .getPageTemplateID(new EntryLoadRequest(entryState));
148             return this.getTitle(pageDefID,
149                                  LanguageCodeConverters
150                                  .languageCodeToLocale(entryState.getLanguageCode()));
151         } catch ( Throwable JavaDoc t ){
152             t.printStackTrace();
153         }
154         return title;
155     }
156
157     public String JavaDoc getTitle( int pageDefID ) {
158         JahiaFieldSubDefinition theSubDef = getSubDef( pageDefID );
159         if (theSubDef != null) {
160             return theSubDef.getTitle();
161         } else {
162             return "";
163         }
164     }
165
166     public String JavaDoc getTitle( int pageDefID , Locale JavaDoc locale) {
167         String JavaDoc title = "";
168
169         title = getTitle(pageDefID);
170         ResourceBundleMarker resMarker = ResourceBundleMarker.parseMarkerValue(title);
171         if ( resMarker == null ){
172             return title;
173         }
174         try {
175             title = resMarker.getValue(locale);
176         } catch ( Throwable JavaDoc t ){
177             title = this.getName();
178         }
179         return title;
180     }
181
182     public String JavaDoc getDefaultValue( int pageDefID ) {
183         JahiaFieldSubDefinition theSubDef = getSubDef( pageDefID );
184         if (theSubDef != null) {
185             return theSubDef.getDefaultValue();
186         } else {
187             return "";
188         }
189     }
190
191     public int getType( int pageDefID ) {
192         JahiaFieldSubDefinition theSubDef = getSubDef( pageDefID );
193         if (theSubDef != null) {
194             return theSubDef.getType();
195         } else {
196             return -1;
197         }
198     }
199
200     public void setTitle( String JavaDoc title, int pageDefID ) {
201         JahiaFieldSubDefinition theSubDef = getSubDef( pageDefID );
202         if (theSubDef == null) {
203             theSubDef = createSubDef( pageDefID );
204         }
205         theSubDef.setTitle( title );
206     }
207
208     public void setDefaultValue( String JavaDoc defaultValue, int pageDefID ) {
209         JahiaFieldSubDefinition theSubDef = getSubDef( pageDefID );
210         if (theSubDef == null) {
211             theSubDef = createSubDef( pageDefID );
212         }
213         theSubDef.setDefaultValue( defaultValue );
214     }
215
216     public void setType( int type, int pageDefID ) {
217         JahiaFieldSubDefinition theSubDef = getSubDef( pageDefID );
218         if (theSubDef == null) {
219             theSubDef = createSubDef( pageDefID );
220         }
221         theSubDef.setType( type );
222     }
223     // end accessor methods
224

225
226
227     /***
228         * gets the field sub definition, from its page def id
229         *
230         */

231     private JahiaFieldSubDefinition getSubDef( int pageDefID )
232     {
233
234         //JahiaConsole.println("JahiaFieldDefinition.getSubDef","field def " + name + "[" + ID + "], request subdef for pageDefID=" + pageDefID);
235

236         JahiaFieldSubDefinition sd = (JahiaFieldSubDefinition)subDefs.get( new Integer JavaDoc(pageDefID) );
237         /*
238         if ( sd != null ){
239             JahiaConsole.println("JahiaFieldDefinition.getSubDef",sd.toString());
240         } else {
241             JahiaConsole.println("JahiaFieldDefinition.getSubDef","sub def not found");
242         }
243         */

244         return sd;
245     } // end getSubDef
246

247
248
249     /***
250         * creates a sub definition
251         *
252         */

253     private JahiaFieldSubDefinition createSubDef( int pageDefID )
254     {
255         JahiaFieldSubDefinition theSubDef = new JahiaFieldSubDefinition( 0, 0, pageDefID, "", -1, "" );
256         if (subDefs == null) {
257             subDefs = new Hashtable JavaDoc();
258         }
259         subDefs.put( new Integer JavaDoc(theSubDef.getPageDefID()), theSubDef );
260         return theSubDef;
261     } // end createSubDef
262

263
264
265
266 } // end JahiaFieldDefinition
267
Popular Tags