KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > taglibs > url > ViewLocksURLTag


1 package org.jahia.taglibs.url;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import javax.servlet.jsp.JspException JavaDoc;
7
8 import org.jahia.content.ContentObject;
9 import org.jahia.exceptions.JahiaException;
10 import org.jahia.services.lock.LockKey;
11 import org.jahia.content.PageReferenceableInterface;
12
13 /**
14  * <p>Title: </p>
15  * <p>Description: </p>
16  * <p>Copyright: Copyright (c) 2002</p>
17  * <p>Company: </p>
18  * @author Serge Huber
19  * @version 1.0
20  */

21 public class ViewLocksURLTag extends AbstractURLTag {
22
23     public String JavaDoc getActionType () {
24         return actionType;
25     }
26
27     public void setActionType (String JavaDoc actionType) {
28         this.actionType = actionType;
29     }
30
31     protected void init () {
32         if (getName() != null) {
33             this.contentObject = (ContentObject) pageContext.findAttribute(
34                 getName());
35         } else {
36             JahiaException je = new JahiaException("ViewLocksURLTag",
37                 "You *must* specify the 'name' attribute",
38                 JahiaException.TEMPLATE_ERROR,
39                 JahiaException.WARNING_SEVERITY);
40             logger.error("Error in lock tag:", je);
41         }
42         String JavaDoc lockType = (String JavaDoc) actionTypeMap.get(actionType);
43         if (lockType == null) {
44             JahiaException je = new JahiaException("ViewLocksURLTag",
45                 "Action type not defined " + actionType +
46                 ". Choose one of " + actionTypeMap.keySet().toString(),
47                 JahiaException.TEMPLATE_ERROR, JahiaException.WARNING_SEVERITY);
48             logger.error("Error in lock tag:", je);
49         }
50         int pageID = -1;
51         if (contentObject instanceof PageReferenceableInterface) {
52             pageID = ((PageReferenceableInterface)contentObject).getPageID();
53         }
54         lockKey = LockKey.composeLockKey(lockType, contentObject.getID(), pageID);
55     }
56
57     protected Object JavaDoc getIdObject () {
58         String JavaDoc resultURL = null;
59         if (isWithJSPopup()) {
60             resultURL = getJSPopupURL();
61         } else {
62             resultURL = getURL();
63         }
64         if ( (resultURL != null) &&
65             (resultURL.length() > 0)) {
66             return resultURL;
67         }
68         return null;
69     }
70
71     protected String JavaDoc getURL () {
72         if (contentObject != null) {
73             try {
74                 return getJahiaData().gui().drawLockUrl(this.lockKey);
75             } catch (JahiaException je) {
76                 logger.error("Error during URL generation:", je);
77             }
78         }
79         return null;
80     }
81
82     protected String JavaDoc getJSPopupURL () {
83         if (contentObject != null) {
84             try {
85                 String JavaDoc popupURL = getJahiaData().gui().html().
86                                   drawReleaseLockObjectLauncher(this.
87                     contentObject, this.lockKey);
88                 if ( (popupURL != null) && (!"".equals(popupURL))) {
89                     return popupURL;
90                 } else {
91                     return null;
92                 }
93             } catch (JahiaException je) {
94                 logger.error("Error while generating URL : ", je);
95             }
96         }
97         return null;
98     }
99
100     public int doEndTag ()
101         throws JspException JavaDoc {
102         // let's reinitialize the tag variables to allow tag object reuse in
103
// pooling.
104
contentObject = null;
105         actionType = null;
106         lockKey = null;
107         return EVAL_PAGE;
108     }
109
110     private ContentObject contentObject = null;
111     private String JavaDoc actionType = null;
112     private LockKey lockKey = null;
113
114     private static org.apache.log4j.Logger logger =
115         org.apache.log4j.Logger.getLogger(ViewLocksURLTag.class);
116
117     private static Map JavaDoc actionTypeMap = new HashMap JavaDoc();
118
119     static {
120         actionTypeMap.put("updateContainerList",
121                             LockKey.UPDATE_CONTAINERLIST_TYPE);
122         actionTypeMap.put("addContainer", LockKey.ADD_CONTAINER_TYPE);
123         actionTypeMap.put("updateContainer", LockKey.UPDATE_CONTAINER_TYPE);
124         actionTypeMap.put("deleteContainer", LockKey.DELETE_CONTAINER_TYPE);
125         actionTypeMap.put("updatePage", LockKey.UPDATE_PAGE_TYPE);
126         actionTypeMap.put("updateField", LockKey.UPDATE_FIELD_TYPE);
127     }
128
129 }
Popular Tags