1 5 package org.exoplatform.portlets.content.explorer.component; 6 7 import java.io.FileOutputStream ; 8 import java.util.Iterator ; 9 import org.exoplatform.faces.application.ExoFacesMessage; 10 import org.exoplatform.faces.core.component.InformationProvider; 11 import org.exoplatform.faces.core.event.ExoActionEvent; 12 import org.exoplatform.faces.core.event.ExoActionListener; 13 import org.exoplatform.portlets.content.explorer.component.model.NodeDescriptor; 14 19 public class UIFileUpload extends org.exoplatform.faces.core.component.UIFileUpload 20 implements ExplorerListener { 21 22 public UIFileUpload() { 23 setShowCancel(false) ; 24 setShowHeader(false) ; 25 } 26 27 public void addFileSystemActionListener() { 28 addActionListener(FileSystemUploadActionListener.class, UPLOAD_ACTION) ; 29 } 30 31 public void onChange(UIExplorer uiExplorer, NodeDescriptor node) { 32 if(node.isLeafNode()) setRendered(false) ; 33 else setRendered(true) ; 34 } 35 36 public void onModify(UIExplorer uiExplorer, NodeDescriptor node) {} 37 38 public void onAddChild(UIExplorer uiExplorer, NodeDescriptor node) { } 39 40 public void onRemove(UIExplorer uiExplorer, NodeDescriptor node) { } 41 42 43 static public class FileSystemUploadActionListener extends ExoActionListener { 44 public void execute(ExoActionEvent event) throws Exception { 45 UIFileUpload uiFileUpload = (UIFileUpload) event.getComponent() ; 46 UIFileExplorer uiExplorer = 47 (UIFileExplorer) uiFileUpload.getAncestorOfType(UIFileExplorer.class) ; 48 NodeDescriptor node = uiExplorer.getSelectNode() ; 49 InformationProvider iprovider = findInformationProvider(uiFileUpload) ; 50 String dir = uiExplorer.getRealPathBaseDir() + node.getUri() ; 51 Iterator i = uiFileUpload.getUserInputs().iterator() ; 52 while(i.hasNext()) { 53 UIFileUpload.UserInput input = (UIFileUpload.UserInput) i.next() ; 54 String fileName = input.getName() ; 55 if (fileName == null || fileName.length() == 0) fileName = input.getFileName() ; 56 String realPath = dir + "/" + fileName ; 57 FileOutputStream os = new FileOutputStream (realPath) ; 58 os.write(input.getStream()) ; 59 os.close() ; 60 } 61 uiExplorer.broadcastOnAddChild(node) ; 62 iprovider.addMessage(new ExoFacesMessage("#{UIFilePortlet.msg.file-upload-success}")) ; 63 } 64 } 65 } 66 | Popular Tags |