1 5 package org.exoplatform.portlets.content.explorer.component; 6 7 import java.io.File ; 8 import javax.faces.context.FacesContext; 9 import javax.portlet.PortletPreferences; 10 import org.exoplatform.faces.FacesUtil; 11 import org.exoplatform.faces.core.component.UIGrid; 12 import org.exoplatform.faces.core.component.UINode; 13 import org.exoplatform.faces.core.component.model.ComponentCell; 14 import org.exoplatform.faces.core.component.model.Row; 15 import org.exoplatform.faces.core.event.ExoActionEvent; 16 import org.exoplatform.faces.core.event.ExoActionListener; 17 import org.exoplatform.portlets.content.ACL; 18 import org.exoplatform.portlets.content.FileACL; 19 import org.exoplatform.portlets.content.explorer.component.model.FileNodeDescriptor; 20 import org.exoplatform.portlets.content.explorer.component.model.NodeDescriptor; 21 27 public class UIFileExplorer extends UIExplorer { 28 private String reposistory_ ; 29 private String relativePathBaseDir_ ; 30 private String realPathBaseDir_ ; 31 private ACL acl_ ; 32 33 public UIFileExplorer() throws Exception { 34 init() ; 35 UINode uiDetail = (UINode)addChild(UINode.class) ; 36 uiDetail.setRendererType("PyramidTabBarRenderer") ; 37 UINode uiNodeContent = (UINode)uiDetail.addChild(UINode.class) ; 38 39 uiNodeContent.setRendererType("ChildrenRenderer") ; 40 uiNodeContent.setName("View") ; 41 uiNodeContent.setId("UINodeContent") ; 42 uiNodeContent.addChild(UIFileChildrenInfo.class) ; 43 uiNodeContent.addChild(UIFileContentViewer.class).setRendered(false) ; 44 45 if(acl_.hasWriteRole(null)) { 46 UINode uiAdmin = (UINode)uiDetail.addChild(UINode.class) ; 47 uiAdmin.setRendered(false) ; 48 uiAdmin.setId("UIAdmin") ; 49 uiAdmin.setName("Admin") ; 50 uiAdmin.setRendererType("SimpleTabRenderer") ; 51 uiAdmin.addChild(UIFileNodeInfo.class) ; 52 UINode uiEditor = (UINode) uiAdmin.addChild(UINode.class) ; 53 uiEditor.setId("UINodeEditor") ; 54 uiEditor.setRendered(false) ; 55 uiEditor.setRendererType("ChildrenRenderer") ; 56 57 UIGrid grid = (UIGrid) uiEditor.addChild(UIGrid.class); 58 grid.setId("UICreateOrUpload"); 59 60 UIFileUpload uiUpload = new UIFileUpload(); 61 uiUpload.setRendered(true) ; 62 uiUpload.setClazz("UIUpload"); 63 uiUpload.addFileSystemActionListener() ; 64 65 grid.add(new Row(). 66 add(new ComponentCell(grid, new UIFileNodeEditor()))); 67 grid.add(new Row(). 68 add(new ComponentCell(grid, new UIChoiceLabel()))); 69 grid.add(new Row(). 70 add(new ComponentCell(grid, uiUpload))); 71 uiEditor.addChild(UIFileContentEditor.class) ; 72 } 73 74 addActionListener(ChangeNodeActionListener.class, CHANGE_NODE_ACTION) ; 75 changeNode("/") ; 76 } 77 78 public void init() throws Exception { 79 PortletPreferences prefs = FacesUtil.getPortletPreferences() ; 80 String user = FacesContext.getCurrentInstance().getExternalContext().getRemoteUser() ; 81 if(user == null) user = "" ; 82 reposistory_ = FacesUtil.getServletContext().getInitParameter("file.portlet.reposistory") ; 83 if(reposistory_ == null || reposistory_.length() ==0 || reposistory_.equals("default")) { 84 reposistory_= FacesUtil.getServletContext().getRealPath("/") ; 85 } 86 if(reposistory_.endsWith("/")) { 87 reposistory_ = reposistory_.substring(0, reposistory_.length() - 1) ; 88 } 89 relativePathBaseDir_ = prefs.getValue("base-dir", "default") ; 90 if(relativePathBaseDir_ == null || 91 relativePathBaseDir_.length() ==0 || 92 relativePathBaseDir_.equals("default")) { 93 relativePathBaseDir_ = "" ; 94 } 95 if(relativePathBaseDir_.endsWith("/")) { 96 relativePathBaseDir_ = relativePathBaseDir_.substring(0, relativePathBaseDir_.length() - 1) ; 97 } 98 realPathBaseDir_ = reposistory_ + relativePathBaseDir_ ; 99 String readRole = prefs.getValue("read-role", "any") ; 100 String writeRole = prefs.getValue("write-role", "admin") ; 101 acl_ = new FileACL(user, readRole, writeRole) ; 102 } 103 104 public String getRealPathBaseDir() { return realPathBaseDir_ ; } 105 106 public String getRelativePathBaseDir() { return relativePathBaseDir_ ; } 107 108 final public void changeNode(String uri) throws Exception { 109 setSelectNode(createNodeDescriptor(uri)) ; 110 } 111 112 public NodeDescriptor createNodeDescriptor(String uri) { 113 String parentUri = getParentUri(uri) ; 114 String realPath = realPathBaseDir_ + uri ; 115 File file = new File (realPath) ; 116 NodeDescriptor node = new FileNodeDescriptor(file, uri, parentUri) ; 117 return node ; 118 } 119 120 static public class ChangeNodeActionListener extends ExoActionListener { 121 public void execute(ExoActionEvent event) throws Exception { 122 UIFileExplorer uiExplorer = (UIFileExplorer) event.getComponent() ; 123 String uri = event.getParameter("uri") ; 124 if("../".equals(uri)) uri = uiExplorer.getSelectNode().getParentUri() ; 125 uiExplorer.changeNode(uri); 126 } 127 } 128 129 } | Popular Tags |