KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > beans > FieldBean


1 package org.jahia.data.beans;
2
3 import java.util.Enumeration JavaDoc;
4 import java.util.Hashtable JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.Map JavaDoc;
7 import java.util.Properties JavaDoc;
8
9 import org.apache.log4j.Logger;
10 import org.jahia.content.JahiaObject;
11 import org.jahia.data.containers.JahiaContainer;
12 import org.jahia.data.fields.JahiaField;
13 import org.jahia.data.fields.JahiaFieldDefinition;
14 import org.jahia.exceptions.JahiaException;
15 import org.jahia.gui.GuiBean;
16 import org.jahia.gui.HTMLToolBox;
17 import org.jahia.params.ParamBean;
18 import org.jahia.registries.ServicesRegistry;
19 import org.jahia.services.acl.JahiaBaseACL;
20 import org.jahia.services.containers.ContentContainer;
21 import org.jahia.services.fields.ContentField;
22 import org.jahia.services.lock.LockKey;
23 import org.jahia.services.lock.LockService;
24 import org.jahia.services.pages.ContentPage;
25 import org.jahia.services.pages.JahiaPage;
26 import org.jahia.utils.InsertionSortedMap;
27
28 /**
29  * <p>Title: Field JavaBean compliant JahiaField facade</p>
30  * <p>Description: </p>
31  * <p>Copyright: Copyright (c) 2002</p>
32  * <p>Company: Jahia Ltd</p>
33  * @author Serge Huber
34  * @version 1.0
35  */

36
37 public class FieldBean extends ContentBean {
38
39     private static Logger logger = Logger.getLogger(FieldBean.class);
40
41     private JahiaField jahiaField;
42     private ParamBean paramBean;
43     private Properties JavaDoc properties;
44     private Map JavaDoc actionURIs = null;
45     private boolean completelyLocked = false;
46
47     public FieldBean() {
48     }
49
50     static {
51         registerType(ContentField.class.getName(), FieldBean.class.getName());
52     }
53
54
55     public FieldBean(JahiaField jahiaField_, ParamBean paramBean_) {
56         this.jahiaField = jahiaField_;
57         this.paramBean = paramBean_;
58     }
59
60     public static AbstractJahiaObjectBean getChildInstance (JahiaObject
61         jahiaObject,
62         ParamBean paramBean) {
63         ContentField contentField = (ContentField) jahiaObject;
64         try {
65             return new FieldBean(contentField.getJahiaField(
66                 paramBean.getEntryLoadRequest()), paramBean);
67         } catch (JahiaException je) {
68             logger.error("Error while converting content container to jahia container", je);
69             return null;
70         }
71     }
72
73     public JahiaField getJahiaField() {
74         return jahiaField;
75     }
76
77     public String JavaDoc getValue() {
78         return jahiaField.getValue();
79     }
80
81     public Object JavaDoc getObject() {
82         Object JavaDoc fieldObject = jahiaField.getObject();
83         if (fieldObject == null) {
84             return null;
85         }
86         if (fieldObject instanceof JahiaPage) {
87             PageBean pageBean = new PageBean((JahiaPage)fieldObject, paramBean);
88             return pageBean;
89         }
90         return fieldObject;
91     }
92
93     public int getId() {
94         return jahiaField.getID();
95     }
96
97     public String JavaDoc getHighLightDiffValue() {
98         return jahiaField.getHighLightDiffValue(paramBean);
99     }
100
101     public JahiaFieldDefinition getDefinition() {
102         try {
103             return jahiaField.getDefinition();
104         } catch (JahiaException je) {
105             logger.error("Error retrieving field definition for field " + getId() + ":", je);
106             return null;
107         }
108     }
109
110     public String JavaDoc getName() {
111         try {
112             return jahiaField.getDefinition().getName();
113         } catch (JahiaException je) {
114             logger.error("Error retrieving field definition for field " + getId() + ":", je);
115             return null;
116         }
117     }
118
119     public String JavaDoc getTitle() {
120         try {
121             return jahiaField.getDefinition().getTitle(paramBean.getPage().getPageTemplateID(), paramBean.getLocale());
122         } catch (JahiaException je) {
123             logger.error("Error retrieving field definition for field " + getId() + ":", je);
124             return null;
125         }
126     }
127
128     public int getContainerID() {
129         return jahiaField.getctnid();
130     }
131
132     public ContentField getContentField() {
133         return jahiaField.getContentField();
134     }
135
136     public String JavaDoc getAnchor() {
137         return jahiaField.getAnchor();
138     }
139
140     public JahiaBaseACL getACL() {
141         return jahiaField.getACL();
142     }
143
144     public Properties JavaDoc getProperties() {
145         if (properties != null) {
146             return properties;
147         }
148         properties = new Properties JavaDoc();
149         Hashtable JavaDoc fieldProps = jahiaField.getProperties();
150         Enumeration JavaDoc propNameEnum = fieldProps.keys();
151         while (propNameEnum.hasMoreElements()) {
152             String JavaDoc curPropName = (String JavaDoc) propNameEnum.nextElement();
153             String JavaDoc curPropValue = (String JavaDoc) fieldProps.get(curPropName);
154             properties.setProperty(curPropName, curPropValue);
155         }
156         return properties;
157     }
158
159     public String JavaDoc getRawValue() {
160         return jahiaField.getRawValue();
161     }
162
163     public int getSiteID() {
164         return jahiaField.getSiteID();
165     }
166
167     public int getType() {
168         return jahiaField.getType();
169     }
170
171     public String JavaDoc getIconNameOff() {
172         return jahiaField.getIconNameOff();
173     }
174
175     public String JavaDoc getIconNameOn() {
176         return jahiaField.getIconNameOn();
177     }
178
179     public int getAclID() {
180         return jahiaField.getAclID();
181     }
182
183     public int getConnectType() {
184         return jahiaField.getConnectType();
185     }
186
187     public int getFieldDefinitionID() {
188         return jahiaField.getFieldDefID();
189     }
190
191     public String JavaDoc getLanguageCode() {
192         return jahiaField.getLanguageCode();
193     }
194
195     public int getPageID() {
196         return jahiaField.getPageID();
197     }
198
199     public int getRank() {
200         return jahiaField.getRank();
201     }
202
203     public int getVersionID() {
204         return jahiaField.getVersionID();
205     }
206
207     public int getWorkflowState() {
208         return jahiaField.getWorkflowState();
209     }
210
211     public Map JavaDoc getActionURIBeans() {
212         if (actionURIs == null) {
213             buildActionURIs();
214         }
215         return actionURIs;
216     }
217
218     public boolean isCompletelyLocked() {
219         if (actionURIs == null) {
220             buildActionURIs();
221         }
222         return completelyLocked;
223     }
224
225     public boolean isPartiallyLocked() {
226         if (actionURIs == null) {
227             buildActionURIs();
228         }
229         if (!completelyLocked) {
230             Iterator JavaDoc actionURIIter = actionURIs.entrySet().iterator();
231             boolean partiallyLocked = false;
232             while (actionURIIter.hasNext()) {
233                 Map.Entry JavaDoc curActionURIEntry = (Map.Entry JavaDoc) actionURIIter.next();
234                 ActionURIBean curActionURIBean = (ActionURIBean) curActionURIEntry.getValue();
235                 if (curActionURIBean.isLocked()) {
236                     partiallyLocked = true;
237                 }
238             }
239             return partiallyLocked;
240         } else {
241             return false;
242         }
243     }
244
245     public boolean isActionURIsEmpty() {
246         if (!paramBean.getOperationMode().equals(ParamBean.EDIT)) {
247             return true;
248         }
249         if (actionURIs == null) {
250             buildActionURIs();
251         }
252         return actionURIs.isEmpty();
253     }
254
255     public ContentBean getParent() {
256         if (jahiaField.getctnid() == 0) {
257             try {
258                 ContentPage parentContentPage = ContentPage.getPage(jahiaField.
259                     getPageID());
260                 JahiaPage parentJahiaPage = parentContentPage.getPage(paramBean);
261                 PageBean parentPageBean = new PageBean(parentJahiaPage,
262                     paramBean);
263                 return parentPageBean;
264             } catch (JahiaException je) {
265                 logger.error("Error while loading parent page " +
266                              jahiaField.getPageID() + " for field " +
267                              jahiaField.getID(), je);
268             }
269             return null;
270         }
271
272         try {
273             ContentContainer parentContentContainer = ContentContainer.
274                 getContainer(jahiaField.getctnid());
275             JahiaContainer parentJahiaContainer = parentContentContainer.getJahiaContainer(paramBean, paramBean.getEntryLoadRequest());
276             if (parentJahiaContainer != null) {
277               ContainerBean parentContainerBean = new ContainerBean(
278                 parentJahiaContainer, paramBean);
279               return parentContainerBean;
280             }
281         } catch (Exception JavaDoc je) {
282         logger.error("Error while loading parent container " + jahiaField.getctnid() + " for field " + jahiaField.getID(), je);
283         }
284         return null;
285
286     }
287
288     private void buildActionURIs() {
289         actionURIs = new InsertionSortedMap();
290         GuiBean guiBean = new GuiBean(paramBean);
291         HTMLToolBox htmlToolBox = new HTMLToolBox(guiBean, paramBean);
292         completelyLocked = true;
293         try {
294             String JavaDoc curURL = guiBean.drawUpdateFieldUrl(jahiaField);
295             String JavaDoc curLauncherURI = htmlToolBox.drawUpdateFieldLauncher(jahiaField);
296             ActionURIBean curActionURIBean = new ActionURIBean("update", curURL, curLauncherURI);
297             LockService lockRegistry = ServicesRegistry.getInstance().getLockService();
298             LockKey lockKey = LockKey.composeLockKey(LockKey.UPDATE_FIELD_TYPE, jahiaField.getID(), jahiaField.getPageID());
299             if (!lockRegistry.isAcquireable(lockKey, paramBean.getUser(), paramBean.getSessionID())) {
300                 curActionURIBean.setLocked(true);
301             } else {
302                 completelyLocked = false;
303             }
304             if (!lockRegistry.canRelease(lockKey, paramBean.getUser(), paramBean.getSessionID())) {
305                 curActionURIBean.setReleaseable(true);
306             }
307             if ((curActionURIBean.getUri() != null) && (!"".equals(curActionURIBean.getUri()))) {
308                 actionURIs.put(curActionURIBean.getName(), curActionURIBean);
309             }
310         } catch (JahiaException je) {
311             logger.error("Error while retrieving action URI map for field " + getId(), je);
312         }
313     }
314
315 }
Popular Tags