KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > control > TreeColumnHtmlRendererImpl


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-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.control;
14
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.core.MetaData;
17 import info.magnolia.cms.core.NodeData;
18 import info.magnolia.cms.util.MetaDataUtil;
19 import info.magnolia.cms.util.NodeDataUtil;
20
21 import java.util.Calendar JavaDoc;
22
23
24 /**
25  * @author joshu
26  */

27 public class TreeColumnHtmlRendererImpl implements TreeColumnHtmlRenderer {
28
29     /**
30      * @see info.magnolia.cms.gui.control.TreeColumnHtmlRenderer#getHtml(info.magnolia.cms.gui.control.TreeColumn)
31      */

32     public String JavaDoc renderHtml(TreeColumn treeColumn, Content content) {
33         String JavaDoc html;
34         if (treeColumn.getIsMeta()) {
35             html = new MetaDataUtil(content).getPropertyValueString(treeColumn.getName(), treeColumn.getDateFormat());
36         }
37         else if (treeColumn.getIsLabel()) {
38             html = content.getName();
39         }
40         else if (treeColumn.getIsIcons()) {
41             html = getHtmlIcons(treeColumn, content);
42         }
43         else {
44             NodeData data = content.getNodeData(treeColumn.getName());
45             html = new NodeDataUtil(data).getValueString(treeColumn.getDateFormat());
46         }
47         // @todo (value is not shown after saving ...)
48
if (treeColumn.getKeyValue().size() != 0) {
49             String JavaDoc value = (String JavaDoc) treeColumn.getKeyValue().get(html);
50             if (value != null) {
51                 html = value;
52             }
53         }
54         return html;
55
56     }
57
58     /**
59      * Returns the html for the activation info flag and the permission flag.
60      * @param treeColumn TreeColumn instance
61      * @param content current page
62      * @return html snippet for the activation info flag and the permission flag
63      */

64     private String JavaDoc getHtmlIcons(TreeColumn treeColumn, Content content) {
65         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
66         if (treeColumn.getIconsActivation()) {
67             MetaData activationMetaData = content.getMetaData(MetaData.ACTIVATION_INFO);
68             MetaData generalMetaData = content.getMetaData();
69             boolean isActivated = activationMetaData.getIsActivated();
70             Calendar JavaDoc actionDate = activationMetaData.getLastActionDate();
71             Calendar JavaDoc lastModifiedDate = generalMetaData.getModificationDate();
72             String JavaDoc imgSrc;
73             if (isActivated) {
74                 if (lastModifiedDate != null && lastModifiedDate.after(actionDate)) {
75                     // node has been modified after last activation
76
imgSrc = Tree.ICONDOCROOT + "indicator_yellow.gif"; //$NON-NLS-1$
77
}
78                 else {
79                     // activated and not modified ever since
80
imgSrc = Tree.ICONDOCROOT + "indicator_green.gif"; //$NON-NLS-1$
81
}
82             }
83             else {
84                 // never activated or deactivated
85
imgSrc = Tree.ICONDOCROOT + "indicator_red.gif"; //$NON-NLS-1$
86
}
87             html.append("<img SRC=\"" + treeColumn.getRequest().getContextPath() + imgSrc + "\" />"); //$NON-NLS-1$ //$NON-NLS-2$
88
}
89         if (treeColumn.getIconsPermission()) {
90             if (!content.isGranted(info.magnolia.cms.security.Permission.WRITE)) {
91                 html.append("<img SRC=\"" //$NON-NLS-1$
92
+ treeColumn.getRequest().getContextPath() + Tree.ICONDOCROOT + "pen_blue_canceled.gif\" />"); //$NON-NLS-1$
93
}
94         }
95         return html.toString();
96     }
97
98 }
99
Popular Tags