Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/obinary/cms/taglibs/Edit.java


1   /**
2    *
3    * Magnolia and its source-code is licensed under the LGPL.
4    * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5    * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6    * you are required to provide proper attribution to obinary.
7    * If you reproduce or distribute the document without making any substantive modifications to its content,
8    * please use the following attribution line:
9    *
10   * Copyright 1993-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11   *
12   * */
13  
14  
15  
16  
17  
18  
19  
20  package com.obinary.cms.taglibs;
21  
22  
23  
24  import com.obinary.cms.beans.ServerInfo;
25  import com.obinary.cms.beans.ParagraphInfo;
26  import com.obinary.cms.util.Resource;
27  
28  import javax.servlet.jsp.JspWriter;
29  import javax.servlet.jsp.tagext.TagSupport;
30  import javax.servlet.http.HttpServletRequest;
31  import javax.jcr.RepositoryException;
32  import javax.jcr.access.Permission;
33  import java.io.IOException;
34  
35  
36  /**
37   * Date: Apr 28, 2003
38   * Time: 11:20:59 AM
39   * @author Sameer Charles
40   * @author Marcel Salathe
41   * @version 1.0
42   */
43  
44  
45  public class Edit extends TagSupport {
46  
47  
48      private static final String EDIT_DIALOG_HANDLE = "/.CMSadmin/dialogs/editbox.html";
49      private static final String DEFAULT_EDIT_LABEL = "Edit";
50      private static final String DEFAULT_DELETE_LABEL = "Delete";
51  
52      private String containerName;
53      private String containerListName;
54      private String contentType;
55      private String editLabel;
56      private String deleteLabel;
57      private String displayHandler;
58      private HttpServletRequest request;
59  
60  
61  
62      /**
63       * <p>starts Edit tag</p>
64       *
65       * @return int
66       */
67      public int doStartTag() {
68          this.displayHandler = "";
69          this.request = (HttpServletRequest)pageContext.getRequest();
70          return EVAL_BODY_INCLUDE;
71      }
72  
73  
74  
75      /**
76       * <p>print out</p>
77       *
78       * @return int
79       */
80      public int doEndTag() {
81          if (!ServerInfo.isAdmin() || Resource.showPreview(this.request))
82              return EVAL_PAGE;
83          if (!Resource.getActivePage(this.request).isGranted(Permission.WRITE_PROPERTY))
84              return EVAL_PAGE;
85          try {
86              this.display();
87          } catch (Exception e) {}
88          return EVAL_PAGE;
89      }
90  
91  
92  
93      /**
94       * <p>set working container</p>
95       *
96       * @param name , comtainer name which will be used to access/write content
97       */
98      public void setContainerName(String name) {
99          this.containerName = name;
100     }
101 
102 
103 
104     /**
105      *
106      */
107     private String getContainerName() {
108         if (this.containerName == null)
109             return Resource.getLocalContainer(this.request).getName();
110         else
111             return this.containerName;
112     }
113 
114 
115     /**
116      * <p>set working container list</p>
117      *
118      * @param name , comtainer list name
119      */
120     public void setContainerListName(String name) {
121         this.containerListName = name;
122     }
123 
124 
125 
126     /**
127      * <p>set current content type, could be any developer defined name</p>
128      *
129      * @param type , content type
130      */
131     public void setParFile(String type) {
132         this.contentType = type;
133     }
134 
135 
136 
137     /**
138      * @return content type
139      */
140     private String getParFile() {
141         if (this.contentType == null) {
142             String uuid = Resource.getLocalContainer(this.request).getAtom("UUID").getString();
143             try {
144                 return ParagraphInfo.getInfo(uuid).getPath();
145             } catch (Exception e) {return "";}
146         }
147         return this.contentType;
148     }
149 
150 
151 
152     /**
153      * <p>set display handler (JSP / Servlet), needs to know the relative path from WEB-INF</p>
154      *
155      * @param path , relative to WEB-INF
156      */
157     public void setTemplate(String path) {
158         this.displayHandler = path;
159     }
160 
161 
162 
163     /**
164      * @return template path
165      */
166     private String getTemplate() {
167         if (this.displayHandler == null) {
168             return Resource.getLocalContainer(this.request).getTemplate();
169         }
170         return this.displayHandler;
171     }
172 
173 
174 
175     /**
176      * <p>get the content path (Page or Node)</p>
177      *
178      * @return String path
179      */
180     private String getPath() {
181         try {
182             return Resource.getCurrentActivePage(this.request).getHandle();
183         } catch (RepositoryException re) {return "";}
184     }
185 
186 
187 
188     /**
189      * <p>set the edit label (else "Edit")</p>
190      *
191      * @param label , under which content must be stored
192      */
193     public void setEditLabel(String label) {
194         this.editLabel = label;
195     }
196 
197 
198 
199     /**
200      *
201      * @return String , label for the edit bar
202      */
203     private String getEditLabel() {
204         if (this.editLabel == null)
205             return Edit.DEFAULT_EDIT_LABEL;
206         return this.editLabel;
207     }
208 
209 
210 
211     /**
212      * <p>set the delete label (else "Delete")</p>
213      *
214      * @param label , under which content must be stored
215      */
216     public void setDeleteLabel(String label) {
217         this.deleteLabel = label;
218     }
219 
220 
221 
222     /**
223      *
224      * @return String , label for the edit bar
225      */
226     private String getDeleteLabel() {
227         if (this.deleteLabel == null)
228             return Edit.DEFAULT_DELETE_LABEL;
229         return this.deleteLabel;
230     }
231 
232 
233 
234     /**
235      * @return containerlist Name
236      */
237     private String getContainerListName() {
238         if (this.containerListName == null) {
239             if (Resource.getLocalContainerListName(this.request) == null)
240                 return "";
241             else
242                 return Resource.getLocalContainerListName(this.request);
243         }
244         return this.containerListName;
245     }
246 
247 
248 
249     /**
250      * <p>construct and return edit handle</p>
251      *
252      * @return String , URL for the edit box with all posted values
253      */
254     private String getEditHandle() {
255         return EDIT_DIALOG_HANDLE+"?path="+this.getPath()+"&clname="+this.getContainerListName()+"&name="+this.getContainerName()+"&type="+this.getParFile()+"&ck="+System.currentTimeMillis();
256     }
257 
258 
259 
260     /**
261      * <p>displays edit bar</p>
262      *
263      * @throws IOException
264      */
265     private void display() throws IOException {
266         JspWriter out = pageContext.getOut();
267         //out.println("<table id='"+this.getContainerListName()+"__"+this.getContainerName()+"' class='obinaryEditBar' border='0' cellspacing='0' cellpadding='0' width='100%' bgcolor='c0c0c0' onmouseup='mgnlMoveContStart(this);' onmousedown='mgnlMoveContEnd(this,\""+this.getPath()+"\");' onmouseover='mgnlMoveContHigh(this);' onmouseout='mgnlMoveContReset(this);'>");
268     out.println("<table id='"+this.getContainerListName()+"__"+this.getContainerName()+"' class='obinaryEditBar' border='0' cellspacing='0' cellpadding='0' width='100%' bgcolor='c0c0c0' onmousedown='mgnlMoveContEnd(this,\""+this.getPath()+"\");' onmouseover='mgnlMoveContHigh(this);' onmouseout='mgnlMoveContReset(this);'>");
269         out.print("<tr><td><a href=\"javascript:openWin('"+this.getEditHandle()+"','editwin','width=500,height=500,scrollbars')\"  onmousedown=\"mgnlMoveDont=true;\" onmouseout=\"mgnlMoveDont=false;\">");
270         out.print(this.getEditLabel());
271         out.print("</a><img src='/admindocroot/0.gif' width='5' height='1'><a href=\"javascript:mgnlMoveContStart('"+this.getContainerListName()+"','"+this.getContainerName()+"');\">");
272     out.print("Move");
273     out.print("</a></td><td><img src='/admindocroot/0.gif' width='20' height='0'></td>");
274     out.print("<td align='right'><a href=\"javascript:deleteContainer('"+this.getPath()+"','"+this.getContainerListName()+"','"+this.getContainerName()+"')\"  onmousedown=\"mgnlMoveDont=true;\" onmouseout=\"mgnlMoveDont=false;\">");
275         out.print(this.getDeleteLabel());
276         out.print("</a></td></tr>");
277         out.println("</table>");
278     }
279 }