KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > content > explorer > renderer > html > JCRNodeInfoRenderer


1 /**
2  **************************************************************************
3  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
4  * Please look at license.txt in info directory for more license detail. *
5  */

6 package org.exoplatform.portlets.content.explorer.renderer.html;
7
8 import java.io.IOException JavaDoc;
9 import java.util.ResourceBundle JavaDoc;
10 import javax.faces.component.UIComponent;
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13 import javax.jcr.*;
14 import javax.jcr.nodetype.NodeDef;
15 import javax.jcr.version.OnParentVersionAction;
16 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
17 import org.exoplatform.portlets.content.explorer.component.UIJCRNodeInfo;
18 /**
19  * @author <a HREF="tuan08@users.sourceforge.net">Tuan Nguyen</a>
20  * @author <a HREF="mailto:geaz@users.sourceforge.net">Gennady Azarenkov</a>
21  * @version $Id: JCRExplorerRenderer.java,v 1.1 2004/11/02 20:02:53 geaz Exp $
22  */

23 public class JCRNodeInfoRenderer extends HtmlBasicRenderer {
24   
25   public void encodeChildren(FacesContext context, UIComponent component) throws IOException JavaDoc {
26     UIJCRNodeInfo uiInfo = (UIJCRNodeInfo)component;
27     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext());
28     Node currentNode = uiInfo.getCurrentNode() ;
29     ResponseWriter w = context.getResponseWriter();
30     //render header
31
renderNodeDetail(w, res, currentNode) ;
32   }
33   
34   private void renderNodeDetail(ResponseWriter w, ResourceBundle JavaDoc res, Node node) throws IOException JavaDoc {
35     // Attrs
36
renderNodeAttributes(node, w, res);
37     w.write("<br>");
38     // Properies
39
renderNodeProperties(node, w, res);
40     w.write("<br>");
41     // Definition
42
renderNodeDefinition(node, w, res);
43   }
44   
45   private void renderNodeAttributes(Node node, ResponseWriter w, ResourceBundle JavaDoc res) throws IOException JavaDoc {
46     w.write("<table class='detail'>");
47     w. write("<tr>") ;
48     w. write("<th colspan='2'>"); w.write("Details"); w.write("</th>");
49     w. write("</tr>") ;
50     
51     w. write("<tr>");
52     w. write("<td>"); w.write("Name"); w.write("</td>");
53     w. write("<td>"); w.write((node.getName())); w.write("</td>");
54     w. write("</tr>");
55     
56     w. write("<tr>");
57     w. write("<td>"); w.write("Paths"); w.write("</td>");
58     w. write("<td>");
59     StringIterator paths = node.getPaths();
60     while(paths.hasNext()) w.write(paths.nextString()+" ");
61     w. write("</td>");
62     w. write("</tr>");
63     
64     w. write("<tr>");
65     w. write("<td>"); w.write("Primary Node Type"); w.write("</td>");
66     w. write("<td>"); w.write((node.getPrimaryNodeType().getName())); w.write("</td>");
67     w. write("</tr>");
68     
69     w. write("<tr>");
70     w. write("<td>"); w.write("Mixin Node Types"); w.write("</td>");
71     w. write("<td>");
72     for(int i=0;i<node.getMixinNodeTypes().length; i++)
73       w.write(node.getMixinNodeTypes()[i].getName());
74           w.write("</td>");
75     w. write("</tr>");
76     
77     w. write("<tr>");
78     w. write("<td>"); w.write("Primary Item"); w.write("</td>");
79     w. write("<td>");
80     try {
81       w.write((node.getPrimaryItem().getPath()));
82     } catch (ItemNotFoundException e) {
83     } catch (RepositoryException e) {
84       w.write(e.getMessage());
85     }
86     w. write("</td>");
87     w. write("</tr>");
88     w.write("</table>");
89   }
90   
91   private void renderNodeProperties(Node node, ResponseWriter w, ResourceBundle JavaDoc res) throws IOException JavaDoc {
92     w.write("<table>");
93     w. write("<tr>") ;
94     w. write("<th>"); w.write("Property"); w.write("</th>");
95     w. write("<th>"); w.write("Value"); w.write("</th>");
96     w. write("<th>"); w.write("Type"); w.write("</th>");
97     w. write("</tr>") ;
98     PropertyIterator properties;
99     try {
100       properties = node.getProperties();
101     } catch (RepositoryException e) {
102       throw new IOException JavaDoc("Render Exception " + e);
103     }
104     Property property;
105     Value value;
106     while (properties.hasNext()) {
107       try {
108         property = properties.nextProperty();
109         value = property.getValue();
110       } catch (RepositoryException e) {
111         throw new IOException JavaDoc("Render Exception " + e);
112       }
113       if(!property.getName().startsWith("jcr:")) continue ;
114       w.write("<tr>");
115       w. write("<td width='30%'>"); w.write(property.getName()); w.write("</td>");
116       try {
117         w.write("<td>"); w.write(value.getString()); w.write("</td>");
118       } catch (RepositoryException e) {
119         w.write("<td>"); w.write("Format error"); w.write("</td>");
120       }
121       w.write("<td>"); w.write(PropertyType.nameFromValue(value.getType())); w.write("</td>");
122       w.write("</tr>");
123     }
124     w.write("</table>");
125   }
126   
127   private void renderNodeDefinition(Node node, ResponseWriter w, ResourceBundle JavaDoc res) throws IOException JavaDoc {
128     w.write("<table>");
129     w. write("<tr>") ;
130     w. write("<th>"); w.write("Primary Type Definition"); w.write("</th>");
131     w. write("<th>"); w.write(""); w.write("</th>");
132     w. write("</tr>") ;
133     NodeDef nodeDef;
134     try {
135       nodeDef = node.getDefinition();
136     } catch (Exception JavaDoc e) {
137       throw new IOException JavaDoc("Render Exception " + e);
138     }
139     w. write("<tr>");
140     w. write("<td>"); w.write("Name"); w.write("</td>");
141     w. write("<td>");
142     w. write((nodeDef.getName() == null) ? "&lt;residual set&gt;" : nodeDef.getName());
143     w. write("</td>");
144     w.write("</tr>");
145     
146     w. write("<tr>");
147     w. write("<td>"); w.write("Default primary type"); w.write("</td>");
148     w. write("<td>"); w.write(nodeDef.getDefaultPrimaryType().getName()); w.write("</td>");
149     w. write("</tr>");
150     
151     w. write("<tr>");
152     w. write("<td >"); w.write("Auto create"); w.write("</td>");
153     w. write("<td>"); w.write(Boolean.toString(nodeDef.isAutoCreate())); w.write("</td>");
154     w. write("</tr>");
155     
156     w. write("<tr>");
157     w. write("<td>"); w.write("Mandatory"); w.write("</td>");
158     w. write("<td>"); w.write(Boolean.toString(nodeDef.isMandatory())); w.write("</td>");
159     w. write("</tr>");
160     
161     w. write("<tr>");
162     w. write("<td>"); w.write("Primary item"); w.write("</td>");
163     w. write("<td>"); w.write(Boolean.toString(nodeDef.isPrimaryItem())); w.write("</td>");
164     w. write("</tr>");
165     
166     w. write("<tr>");
167     w. write("<td>"); w.write("Protected"); w.write("</td>");
168     w. write("<td>"); w.write(Boolean.toString(nodeDef.isReadOnly())); w.write("</td>");
169     w. write("</tr>");
170     
171     w. write("<tr>");
172     w. write("<td>"); w.write("On Parent Version action"); w.write("</td>");
173     w. write("<td>"); w.write(OnParentVersionAction.nameFromValue(nodeDef.getOnParentVersion()));w.write("</td>");
174     w. write("</tr>");
175     w.write("</table>");
176   }
177 }
Popular Tags