Source code: com/obinary/cms/taglibs/MainBar.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.beans.ParagraphInfo;
23 import com.obinary.cms.util.Resource;
24
25 import javax.servlet.jsp.tagext.TagSupport;
26 import javax.servlet.jsp.JspWriter;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.jcr.RepositoryException;
29 import javax.jcr.access.Permission;
30 import java.io.IOException;
31
32
33 /**
34 * Date: Apr 28, 2003
35 * Time: 11:20:59 AM
36 * @author Marcel Salathe
37 * @author Sameer Charles
38 * @version 1.0
39 */
40
41
42 public class MainBar extends TagSupport {
43
44
45 private static final String PROPERTIES_DIALOG_HANDLE = "/.CMSadmin/dialogs/properties.html";
46
47
48 private HttpServletRequest request;
49 private String parFile;
50
51
52 /**
53 * <p>starts Admin tag</p>
54 *
55 * @return int
56 */
57 public int doStartTag() {
58 this.request = (HttpServletRequest)pageContext.getRequest();
59 return EVAL_BODY_INCLUDE;
60 }
61
62
63
64 /**
65 * <p>print out</p>
66 *
67 * @return int
68 */
69 public int doEndTag() {
70 if (!ServerInfo.isAdmin())
71 return EVAL_PAGE;
72 if (!Resource.getActivePage(this.request).isGranted(Permission.WRITE_PROPERTY))
73 return EVAL_PAGE;
74 try {
75 if (Resource.showPreview((HttpServletRequest)pageContext.getRequest()))
76 this.displayPreview();
77 else
78 this.display();
79 } catch (Exception e) {}
80 return EVAL_PAGE;
81 }
82
83
84
85
86
87 /**
88 * <p>construct and return properties handle</p>
89 *
90 * @return String , URL for the properties box
91 */
92 private String getHandle() {
93 return PROPERTIES_DIALOG_HANDLE+"?path="+this.getPath()+"&type="+this.getParFile();
94 }
95
96
97
98 /**
99 * <p>get the content path (Page or Node)</p>
100 *
101 * @return String path
102 */
103 private String getPath() {
104 try {
105 return Resource.getCurrentActivePage(this.request).getHandle();
106 } catch (RepositoryException re) {return "";}
107
108 }
109
110
111
112 /**
113 * <p>set current content type, could be any developer defined name</p>
114 *
115 * @param type , content type
116 */
117 public void setParFile(String type) {
118 this.parFile = type;
119 }
120
121
122
123 /**
124 * @return content type
125 */
126 private String getParFile() {
127 if (this.parFile == null)
128 return "/properties.xml";
129 return this.parFile;
130 }
131
132
133 /**
134 * <p>displays main admin bar</p>
135 *
136 * @throws java.io.IOException
137 */
138 private void display() throws IOException {
139 JspWriter out = pageContext.getOut();
140 out.println("<script src='/admindocroot/js/js.js'></script>");
141 out.println("<table class='obinaryMainBar' border='0' cellspacing='0' cellpadding='0' width='100%' bgcolor='c0c0c0'>");
142 out.println("<tr><td><a href='javascript:preview(window.document.location.href,window.document.location.search)'><< Preview</a></td>");
143 out.print("<td align='right'><a href=\"javascript:openWin('"+this.getHandle()+"','editwin','width=500,height=500,scrollbars')\" >");
144 out.print("Page Properties");
145 out.print("</a></td></tr>");
146 out.println("</table>");
147 }
148
149
150
151 /**
152 * <p>displays main admin bar</p>
153 *
154 * @throws java.io.IOException
155 */
156 private void displayPreview() throws IOException {
157 JspWriter out = pageContext.getOut();
158 out.println("<script src='/admindocroot/js/js.js'></script>");
159 out.println("<div id='preview' width='1%'>");
160 out.println("<table class='obinaryMainBar' width='1%' border='0' cellspacing='0' cellpadding='0' bgcolor='c0c0c0'>");
161 out.println("<tr><td><a href='javascript:unPreview(window.document.location.href);'><nobr>>></nobr></a></td></tr>");
162 out.println("</table></div>");
163 }
164
165
166
167 }