1 5 package org.exoplatform.portlets.content.explorer.renderer.html; 6 7 import java.io.IOException ; 8 import java.util.List ; 9 import java.util.ResourceBundle ; 10 import javax.faces.component.UIComponent; 11 import javax.faces.context.FacesContext; 12 import javax.faces.context.ResponseWriter; 13 import org.apache.commons.lang.StringUtils; 14 import org.exoplatform.faces.core.component.model.Parameter; 15 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer; 16 import org.exoplatform.portlets.content.explorer.component.UIExplorer; 17 import org.exoplatform.portlets.content.explorer.component.model.NodeDescriptor; 18 22 public class ExplorerRenderer extends HtmlBasicRenderer { 23 private static Parameter CHANGE_NODE = new Parameter(ACTION , UIExplorer.CHANGE_NODE_ACTION) ; 24 25 public void encodeChildren( FacesContext context, UIComponent component ) throws IOException { 26 UIExplorer uiExplorer = (UIExplorer) component; 27 ResourceBundle res = getApplicationResourceBundle(context.getExternalContext()) ; 28 String currentUri = uiExplorer.getSelectNode().getUri() ; 29 String [] path = StringUtils.split(currentUri, "/") ; 30 if(path.length == 0) { 31 path = new String [0] ; 32 } 33 String currentPath = "" ; 34 Parameter uriParam = new Parameter("uri", "/") ; 35 Parameter[] changeNodeParams = { CHANGE_NODE , uriParam} ; 36 ResponseWriter w = context.getResponseWriter() ; 37 w.write("<table class='UIExplorer'>"); 39 w. write("<tr>"); 40 w. write("<td class='header' colspan='2'>") ; 41 linkRenderer_.render(w, uiExplorer, "/", changeNodeParams) ; 42 String pathSeparator = res.getString("UIExplorer.img.path-separator") ; 43 for (int i = 0; i < path.length; i++) { 44 currentPath += "/" + path[i] ; 45 uriParam.setValue(currentPath) ; 46 w.write("<img SRC='"); w.write(pathSeparator) ; w.write("'/>") ; 47 linkRenderer_.render(w,uiExplorer, path[i], changeNodeParams) ; 48 } 49 w. write("</td>") ; 50 w. write("</tr>"); 51 w. write("<tr>"); 53 w. write("<td class='tree'>") ; 54 renderNodeTree(w, uiExplorer) ; 55 w. write("</td>"); 56 w. write("<td>") ; 57 renderChildren(context, component) ; 58 w. write("</td>"); 59 w. write("</tr>"); 60 w.write("</table>"); 61 } 62 63 final public void renderNodeTree(ResponseWriter w, UIExplorer uiExplorer) throws IOException { 64 NodeDescriptor node = uiExplorer.getSelectNode() ; 65 Parameter uriParam = new Parameter("uri", "../") ; 66 Parameter[] changeNodeParams = { CHANGE_NODE , uriParam} ; 67 w.write("<div>") ; 68 linkRenderer_.render(w, uiExplorer, "[..]", changeNodeParams) ; 69 w.write("</div>") ; 70 List children = node.getChildren() ; 71 for (int i = 0; i < children.size(); i++) { 72 NodeDescriptor childNode = (NodeDescriptor) children.get(i) ; 73 if (!childNode.isLeafNode()) { 74 uriParam.setValue(childNode.getUri()) ; 75 w.write("<div style='padding: 2px'>") ; 76 w.write(childNode.getIcon()) ; 77 linkRenderer_.render(w,uiExplorer, childNode.getName(), changeNodeParams) ; 78 w.write("</div>") ; 79 } 80 } 81 } 82 } | Popular Tags |