1 5 package org.exoplatform.portlets.content.explorer.component; 6 7 import org.exoplatform.commons.utils.IOUtil; 8 import org.exoplatform.portlets.content.explorer.component.model.*; 9 13 public class UIFileContentViewer extends UIContentViewer { 14 public UIFileContentViewer() { 15 16 } 17 18 public void onChange(UIExplorer uiExplorer, NodeDescriptor node) { 19 if(!node.isLeafNode()) { 20 setRendered(false) ; 21 return; 22 } 23 String content = "" ; 24 String mimeType = node.getNodeType() ; 25 try { 26 UIFileExplorer uiFileExplorer = (UIFileExplorer) uiExplorer ; 27 String uri = node.getUri() ; 28 renderer_ = getRenderer(mimeType) ; 29 if (renderer_ != null) { 30 if (mimeType.startsWith("text")) { 31 FileNodeDescriptor fnode = (FileNodeDescriptor) node ; 32 if(fnode.getCacheContent() == null ) { 33 String realPath = uiFileExplorer.getRealPathBaseDir() + uri ; 34 content = IOUtil.getFileContenntAsString(realPath) ; 35 fnode.setCacheContent(content) ; 36 } else { 37 content = fnode.getCacheContent() ; 38 } 39 } else { 40 String relativePath = uiFileExplorer.getRelativePathBaseDir() + uri ; 41 content = "/content/file" + relativePath ; 42 } 43 } else { 44 String relativePath = uiFileExplorer.getRelativePathBaseDir() + uri ; 45 renderer_ = getRenderer("default") ; 46 content = "/content/file" + relativePath ; 47 54 } 55 } catch (Exception ex) { 56 renderer_ = getRenderer("text/plain") ; 57 content = org.exoplatform.commons.utils.ExceptionUtil.getExoStackTrace(ex) ; 58 } 59 setContent(content) ; 60 setContentType(mimeType) ; 61 setRendered(true) ; 62 } 63 64 public void onModify(UIExplorer uiExplorer, NodeDescriptor node) { 65 FileNodeDescriptor fnode = (FileNodeDescriptor) node ; 66 setContent(fnode.getCacheContent()) ; 67 } 68 } 69 | Popular Tags |