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

Quick Search    Search Deep

Source code: com/obinary/cms/taglibs/New.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  package com.obinary.cms.taglibs;
19  
20  
21  import com.obinary.cms.beans.ServerInfo;
22  import com.obinary.cms.util.Resource;
23  
24  import javax.servlet.jsp.JspWriter;
25  import javax.servlet.jsp.tagext.TagSupport;
26  import javax.servlet.http.HttpServletRequest;
27  import javax.jcr.RepositoryException;
28  import javax.jcr.access.Permission;
29  import java.io.IOException;
30  
31  
32  /**
33   * User: sameercharles
34   * Date: Apr 28, 2003
35   * Time: 11:20:59 AM
36   * @author Sameer Charles
37   * @version 1.0
38   */
39  
40  
41  public class New extends TagSupport {
42  
43  
44      private static final String SELECT_DIALOG_HANDLE = "/.CMSadmin/dialogs/newbox.html";
45      private static final String DEFAULT_NEW_LABEL = "New";
46  
47  
48      private String containerListName;
49      private String types;
50      private String newLabel;
51      private HttpServletRequest request;
52  
53  
54  
55      /**
56       * <p>starts Edit tag</p>
57       *
58       * @return int
59       */
60      public int doStartTag() {
61          this.request = (HttpServletRequest)pageContext.getRequest();
62          return EVAL_BODY_INCLUDE;
63      }
64  
65  
66  
67      /**
68       * <p>print out</p>
69       *
70       * @return int
71       */
72      public int doEndTag() {
73          if (!ServerInfo.isAdmin() || Resource.showPreview(this.request))
74              return EVAL_PAGE;
75          if (!Resource.getActivePage(this.request).isGranted(Permission.WRITE_PROPERTY))
76              return EVAL_PAGE;
77          try {
78              this.display();
79          } catch (Exception e) {}
80          return EVAL_PAGE;
81      }
82  
83  
84  
85      /**
86       * <p>set working container list</p>
87       *
88       * @param name , comtainer list name
89       */
90      public void setContainerListName(String name) {
91          this.containerListName = name;
92      }
93  
94  
95  
96      /**
97       * <p>get the content path (Page or Node)</p>
98       *
99       * @return String path
100      */
101     private String getPath() {
102         try {
103             return Resource.getCurrentActivePage(this.request).getHandle();
104         } catch (RepositoryException re) {return "";}
105 
106     }
107 
108 
109     /**
110      * <p>set the tapes which defines all paragraps available in this container list</p>
111      *
112      * @param list , comma seperated list of all allowed paragraphs
113      */
114     public void setParFiles(String list) {
115         this.types = list;
116     }
117 
118 
119 
120     /**
121      * <p>set the new label (else "New")</p>
122      *
123      * @param label , under which content must be stored
124      */
125     public void setNewLabel(String label) {
126         this.newLabel = label;
127     }
128 
129 
130 
131     /**
132      *
133      * @return String , label for the new bar
134      */
135     private String getNewLabel() {
136         if (this.newLabel == null)
137             return New.DEFAULT_NEW_LABEL;
138         return this.newLabel;
139     }
140 
141 
142 
143     /**
144      * <p>construct and return edit handle</p>
145      *
146      * @return String , URL for the edit box with all posted values
147      */
148     private String getHandle() {
149         return SELECT_DIALOG_HANDLE+"?path="+this.getPath()+"&clname="+this.containerListName+"&types="+this.types;
150     }
151 
152 
153 
154     /**
155      * <p>displays new bar</p>
156      *
157      * @throws java.io.IOException
158      */
159     private void display() throws IOException {
160         JspWriter out = pageContext.getOut();
161         out.println("<table id="+this.containerListName+"__LAST"+" class='obinaryEditBar' border='0' cellspacing='0' cellpadding='0' width='100%' bgcolor='c0c0c0' onmousedown='mgnlMoveContEnd(this,\""+this.getPath()+"\");' onmouseover='mgnlMoveContHigh(this);' onmouseout='mgnlMoveContReset(this);'>");
162         out.print("<tr><td><a href=\"javascript:openWin('"+this.getHandle()+"','editwin','width=500,height=500,scrollbars')\" >");
163         out.print(this.getNewLabel());
164         out.print("</a></td></tr>");
165         out.println("</table>");
166 
167     }
168 
169 
170 
171 
172 
173 }