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

Quick Search    Search Deep

Source code: com/obinary/cms/beans/admin/AdminList.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  package com.obinary.cms.beans.admin;
20  
21  import com.obinary.cms.core.HierarchyManager;
22  import com.obinary.cms.core.Content;
23  import com.obinary.cms.core.MetaData;
24  import com.obinary.cms.Aggregator;
25  import com.obinary.cms.admin.Authenticator;
26  import com.obinary.cms.beans.ConfigLoader;
27  import com.obinary.cms.beans.TemplateInfo;
28  import com.obinary.cms.beans.ServerInfo;
29  
30  import javax.servlet.http.HttpServletRequest;
31  import javax.jcr.Ticket;
32  import javax.jcr.PasswordCredentials;
33  import javax.jcr.Node;
34  import javax.jcr.access.Permission;
35  import java.util.Collection;
36  import java.util.Iterator;
37  import java.util.Calendar;
38  
39  
40  /**
41   * User: marcelsalathe
42   * Date: Jul 20, 2003
43   * Time: 11:20:59 AM
44   * @author Marcel Salathe
45   * @version 1.0
46   */
47  
48  
49  public class AdminList implements java.io.Serializable {
50  
51      private String context = "";
52      private String html = "";
53      private HttpServletRequest request;
54      private Content actpage;
55      // path is the handle of the father whose children we show on the detail view.
56      // it is the folder that was clicked on in the the treeview.
57      private String path = "/";
58      private String action = "listPages";
59  
60      public void setRequest(HttpServletRequest request) {
61          this.request = request;
62          setActpage();
63      }
64  
65      public HttpServletRequest getRequest() {
66          return this.request;
67      }
68  
69      public String getContext() {
70          return this.context;
71      }
72  
73      public void setContext(String context) {
74          this.context = context;
75      }
76  
77      public void setActpage() {
78          this.actpage = (Content) this.request.getAttribute("actpage");
79  
80      }
81  
82      public Content getActpage() {
83          return this.actpage;
84      }
85  
86      public void setPath(String path) {
87          this.path = path;
88          if (this.path == null || this.path.equals("")) this.path = "/";
89      }
90  
91      public String getPath() {
92          return this.path;
93      }
94  
95      public void setAction(String action) {
96          this.action = action;
97      }
98  
99      public String getAction() {
100         return this.action;
101     }
102 
103     public String getHtml() {
104     this.html="";
105         this.html+="<table class='adminTable' cellpadding='0' cellspacing='0' border='0' width='100%'>";
106         if (this.getAction().equals("createPage")) {
107             try {
108                 Iterator customTemplates = TemplateInfo.getAvailableTemplates(TemplateInfo.CUSTOM_TEMPLATES);
109                 int numberOfTemplates = 0;
110         while (customTemplates.hasNext()) {
111                     TemplateInfo template;
112                     template = (TemplateInfo) customTemplates.next();
113                     this.html+="<tr>";
114                     this.html+=("<td width=\"20\" height=\"20\"><input type=\"radio\" name=\"template\"");
115                     this.html+=(" value=\""+template.getName()+"\"");
116                     if (numberOfTemplates == 0) this.html+=(" checked=\"checked\"");
117                     numberOfTemplates++;
118                     this.html+=(" /></td>");
119                     this.html+=("<td width=\"99%\" class=\"adminWithRadioBox\"><span class=\"adminTitle\">"+template.getTitle()+"<br>");
120                     this.html+="<span class=\"adminDescription\">"+template.getDescription()+"<span></td></tr>";
121                     this.html+="<tr><td colspan=\"2\" class=\"separationLine\"><img src=\"/admindocroot/0.gif\"></td></tr>";
122                     if (!template.getImage().equals("")) {
123                         this.html+="<tr><td></td><td class=\"adminWithRadioBox\"><img src=\""+template.getImage()+"\"></td></tr>";
124                         this.html+="<tr><td colspan=\"2\" class=\"separationLine\"><img src=\"/admindocroot/0.gif\"></td></tr>";
125                     }
126                 }
127             }
128             catch (Exception e) {}
129         }
130         else  {
131             try {
132                 HierarchyManager hm = new HierarchyManager(this.request);
133                 if (this.context.equals("Website")) hm = (HierarchyManager) this.request.getAttribute(Aggregator.HIERARCHY_MANAGER);
134                 if (this.context.equals("Users")) {
135                     Ticket t = ConfigLoader.usersRepository.connect(new PasswordCredentials(Authenticator.getUserId(this.request),Authenticator.getPassword(this.request)));
136                     Node rootNode = t.getRootNode();
137                     hm.setStartPage(rootNode);
138                 }
139                 if (this.context.equals("Roles")) {
140                     Ticket t = ConfigLoader.userRolesRepository.connect(new PasswordCredentials(Authenticator.getUserId(this.request),Authenticator.getPassword(this.request)));
141                     Node rootNode = t.getRootNode();
142                     hm.setStartPage(rootNode);
143                 }
144                 Content parent = hm.getPage(this.path);
145                 Collection children = parent.getChildren();
146                 Iterator childrenIterator = children.iterator();
147 
148         String lastName="";
149 
150         this.html+="<script>";
151         this.html+="var nodesInfo = new Object();"; // initalize nodesInfo (handles information of the listed pages to the js functions (i.e. is activated for deleting)
152         this.html+="</script>";
153 
154         if (this.context.equals("Website")) {
155           this.html+="<script>";
156           this.html+="var ancestorsInfo=new Object();"; // ancestorsInfo handles information of the superior pages to the js functions (i.e. for activation)
157           if (parent.getHandle()!="/") {
158             this.html+="ancestorsInfo[0]=new Object();";
159             this.html+="ancestorsInfo[0].title='"+parent.getTitle()+"';";
160             this.html+="ancestorsInfo[0].handle='"+parent.getHandle()+"';";
161             this.html+="ancestorsInfo[0].isActivated="+parent.getMetaData(MetaData.ACTIVATION_INFO).getIsActivated()+";";
162             this.html+="ancestorsInfo[0].activatePermission="+parent.isGranted(Permission.WRITE_PROPERTY) +";";
163             Iterator it=parent.getAncestors().iterator();
164             int i=1;
165             while (it.hasNext()) {
166               Content c=(Content) it.next();
167               if (c.getHandle()!="/") {
168                 this.html+="ancestorsInfo["+i+"]=new Object();";
169                 this.html+="ancestorsInfo["+i+"].title='"+c.getTitle()+"';";
170                 this.html+="ancestorsInfo["+i+"].handle='"+c.getHandle()+"';";
171                 this.html+="ancestorsInfo["+i+"].isActivated="+c.getMetaData(MetaData.ACTIVATION_INFO).getIsActivated()+";";
172                 this.html+="ancestorsInfo["+i+"].activatePermission="+c.isGranted(Permission.WRITE_PROPERTY) +";";
173               }
174               i++;
175             }
176           }
177         this.html+="</script>";
178         }
179 
180         while (childrenIterator.hasNext()) {
181                     Content child;
182                     child = (Content) childrenIterator.next();
183                     if (child.getName().equals(".CMSadmin")) continue;
184           this.html+="<tr id=sadminTr"+child.getName()+"Pre><td colspan=4><img src=/admindocroot/0.gif width=1 height=1></td></tr>";
185                     this.html+="<tr id=sadminTr"+child.getName()+">";
186                     this.html+=("<td height=\"20\">");
187                     this.html+=("<input type=\"checkbox\" name=\""+child.getHandle()+"\" value=\""+child.getHandle()+"\"></td>");
188           if (this.context.equals("Website")) {
189                         String imgString = getActivationImage(child);
190             this.html+=("<td height=\"20\" width=\"1%\"><a href=javascript:mgnlSortPageStart('"+child.getName()+"','"+child.getHandle()+"'); onmousedown=mgnlSortPageEnd('"+child.getName()+"','"+child.getHandle()+"'); alt=\"Sort page\" onmouseover=mgnlSortPageHigh('"+child.getName()+"','"+child.getHandle()+"','"+lastName+"'); onmouseout=mgnlSortPageReset('"+child.getName()+"','"+child.getHandle()+"'); ><img src=/admindocroot/images/sadminIconDoc.gif border=0></a></td>");
191                         this.html+=("<td class=\"adminStatusTd\" height=\"20\" width=\"1%\">"+imgString+"</td>");
192                     }
193                     this.html+=("<td class=\"adminPageNameTd\" width=\"100%\">");
194                     if (this.context.equals("Website")) this.html+=("<a class=\"adminLink\" href=\""+child.getHandle()+".html\" target=\""+child.getHandle()+"\">");
195           else if (this.context.equals("Users")) this.html+=("<a class=\"adminLink\" href=\"javascript:openWin('/.CMSadmin/edituser.html?path="+child.getHandle()+"','editUser','width=400,height=500')\">");
196                     else if (this.context.equals("Roles")) this.html+=("<a class=\"adminLink\" href=\"javascript:openWin('/.CMSadmin/editrole.html?path="+child.getHandle()+"','editRole','width=400,height=500')\">");
197                     String title=child.getAtom("title").getString();
198           if (!title.equals("")) this.html+=title;
199                     else this.html+=child.getName();
200           this.html+=("</a>");
201 
202           if (this.context.equals("Website")) {
203             this.html+=" ("+child.getName() + "." + ServerInfo.getDefaultExtension() + ")";
204           }
205           else {
206             this.html+=" ("+child.getName() +")";
207           }
208 
209           this.html+="<script>";
210           this.html+="nodesInfo['"+child.getHandle()+"']=new Object();";
211           this.html+="nodesInfo['"+child.getHandle()+"'].title='"+title+"';";
212           this.html+="nodesInfo['"+child.getHandle()+"'].handle='"+child.getHandle() +"';";
213           this.html+="nodesInfo['"+child.getHandle()+"'].name='"+child.getName() +"';";
214           if (this.context.equals("Website")) {
215             this.html+="nodesInfo['"+child.getHandle()+"'].isActivated="+child.getMetaData(MetaData.ACTIVATION_INFO).getIsActivated()+";";
216             this.html+="nodesInfo['"+child.getHandle()+"'].hasChildren="+child.hasChildren()+";";
217           }
218           this.html+="</script>";
219 
220           if (this.context.equals("Website")) {
221             // tmp:show sequence position number
222             //this.html+=(" <br><font color=666666>["+child.getMetaData().getSequencePosition() +"] ");
223             //this.html+=(" ["+child.getAtom("sequenceposition").getString()+"]</font>");
224 
225             //tmp: show creation/modification date
226             //String activated = child.getMetaData(MetaData.ACTIVATION_INFO).getLastActionDate().getTime().toString();
227             //String modified = child.getMetaData().getModificationDate().getTime().toString();
228             //String created = child.getMetaData().getCreationDate().getTime().toString();
229             //this.html+="<br>CR:"+created;
230             //this.html+="<br>MD"+modified;
231             //this.html+="<br>AC"+activated;
232           }
233 
234           this.html+="</td>";
235                     this.html+="</tr>";
236           lastName=child.getName();
237                 }
238         if (this.context.equals("Website")) {
239           this.html+="<tr id=sadminTrLastPre><td colspan=4><img src=/admindocroot/0.gif width=1 height=1></td></tr>";
240           this.html+="<tr id=sadminTrLast>";
241           this.html+=("<td></td>");
242           this.html+=("<td height=\"20\" width=\"1%\"><a href=# onmousedown=mgnlSortPageEnd('Last','Last'); alt=\"Sort page\" onmouseover=mgnlSortPageHigh('Last','Last','"+lastName+"'); onmouseout=mgnlSortPageReset('Last','Last'); ><img src=/admindocroot/0.gif border=0 width=16 heigth=16></a></td>");
243         }
244       }
245             catch (Exception e) {}
246         }
247         this.html += "</table>";
248         return this.html;
249     }
250 
251     private String getActivationImage(Content page) {
252         try {
253             String activationImage = "";
254             String activationImageSrc = "";
255             String activationImageAlt = "";
256             MetaData activationMetaData = page.getMetaData(MetaData.ACTIVATION_INFO);
257             MetaData generalMetaData = page.getMetaData();
258             boolean isActivated = activationMetaData.getIsActivated();
259             String activatorId = activationMetaData.getActivatorId();
260             Calendar actionDate = activationMetaData.getLastActionDate();
261             Calendar lastModifiedDate = generalMetaData.getModificationDate();
262             if (isActivated) {
263                 // if node has been modified after last activation
264                 if (lastModifiedDate.after(actionDate)) {
265                     activationImageSrc = "/admindocroot/images/activatedAndModified.gif";
266                     activationImageAlt = "activated by " + activatorId + ", modified by " + generalMetaData.getAuthorId();
267                 }
268                 //activated and not modified ever since
269                 else {
270                     activationImageSrc = "/admindocroot/images/activated.gif";
271                     activationImageAlt = "activated by " + activatorId;
272                  }
273             }
274             if (!isActivated) {
275                 // not activated yet
276                 if (activatorId.equals("")) {
277                     activationImageSrc = "/admindocroot/images/unactivated.gif";
278                     activationImageAlt = "not activated yet";
279                 }
280                 // deactivated
281                 else {
282                     activationImageSrc = "/admindocroot/images/unactivated.gif";
283                     activationImageAlt = "deactivated by " + activatorId;
284                 }
285             }
286             activationImage = "<img src=\""+activationImageSrc+"\" alt=\""+activationImageAlt+"\" />";
287             return activationImage;
288         }
289         catch (Exception e) {return "";}
290     }
291 
292 
293 
294 }