1 19 package org.openharmonise.him.editors; 20 21 import java.io.*; 22 import java.util.*; 23 24 import javax.swing.*; 25 26 import org.openharmonise.commons.net.*; 27 import org.openharmonise.him.configuration.*; 28 import org.openharmonise.him.editors.filefilters.*; 29 import org.openharmonise.him.harmonise.*; 30 import org.openharmonise.him.window.*; 31 import org.openharmonise.vfs.*; 32 import org.openharmonise.vfs.status.*; 33 34 35 42 public class FileAssetEditor extends GenericEditor { 43 44 private boolean m_bResourceCreated = false; 45 46 49 public FileAssetEditor() { 50 super(); 51 } 52 53 59 public PathStatusWrapper createNew(String sPath, AbstractVirtualFileSystem vfs) { 60 ResourceStatusWrapper statusWrapper = new ResourceStatusWrapper(null, new VFSStatus()); 61 62 VirtualFile vfFile = new VirtualFile(sPath); 63 64 JFileChooser chooser = getChooser(sPath); 65 66 int returnVal = chooser.showOpenDialog(DisplayManager.getInstance() 67 .getMainWindow()); 68 if (returnVal == JFileChooser.APPROVE_OPTION) { 69 File fFile = chooser.getSelectedFile(); 70 File currentFile = chooser.getCurrentDirectory(); 71 ConfigStore.getInstance().setProperty("ASSET_PATH", 72 currentFile.getPath()); 73 74 String sFilename = fFile.getName(); 75 if (sFilename.indexOf(".") > -1) { 76 String sExt = sFilename.substring(sFilename.indexOf(".") + 1); 77 78 List mimes = MimeTypeMapping.getMimeTypes(sExt); 79 if (mimes.size() > 0) { 80 String sMimeType = (String ) mimes.get(0); 81 vfs.getVirtualFileSystemView().setContentType(vfFile, 82 sMimeType); 83 84 byte[] bytes = new byte[new Long (fFile.length()).intValue()]; 85 86 BufferedInputStream buff; 87 try { 88 buff = new BufferedInputStream(new FileInputStream( 89 fFile)); 90 buff.read(bytes); 91 92 vfFile.setContent(bytes); 93 94 statusWrapper = vfs.addVirtualFile(sPath, vfFile); 95 96 vfFile = vfs.getVirtualFile(sPath).getResource(); 97 if(statusWrapper.getStatus().isOK()) { 98 this.m_bResourceCreated = true; 99 return new PathStatusWrapper(null, statusWrapper.getStatus()); 101 } 102 } catch (FileNotFoundException e) { 103 e.printStackTrace(); 104 } catch (IOException e) { 105 e.printStackTrace(); 106 } 107 } 108 } 109 } 110 111 statusWrapper.getStatus().setStatusLevel(StatusData.LEVEL_ERROR); 112 return new PathStatusWrapper(null, statusWrapper.getStatus()); 113 } 114 115 119 private JFileChooser getChooser(String sPath) { 120 JFileChooser chooser = new JFileChooser(); 121 String sValue = ConfigStore.getInstance() 122 .getPropertyValue("ASSET_PATH"); 123 if (sValue != null && sValue != "") { 124 chooser.setCurrentDirectory(new File(sValue)); 125 } 126 127 if (sPath.startsWith(HarmonisePaths.PATH_IMAGES)) { 128 chooser.setFileFilter(new ImageFilter()); 129 } else if (sPath.startsWith(HarmonisePaths.PATH_PDF)) { 130 chooser.setFileFilter(new PDFFilter()); 131 } else if (sPath.startsWith(HarmonisePaths.PATH_FLASH)) { 132 chooser.setFileFilter(new FlashFilter()); 133 } else if (sPath.startsWith(HarmonisePaths.PATH_MOVIES)) { 134 chooser.setFileFilter(new MovieFilter()); 135 } else if (sPath.startsWith(HarmonisePaths.PATH_AUDIO)) { 136 chooser.setFileFilter(new AudioFilter()); 137 } else if (sPath.startsWith(HarmonisePaths.PATH_OFFICE)) { 138 chooser.setFileFilter(new OfficeFilter()); 139 } 140 return chooser; 141 } 142 143 149 public StatusData export(String sPath, AbstractVirtualFileSystem vfs) { 150 VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource(); 151 String sFilename = super.getFileName(vfFile); 152 153 String sTempPath = m_sEditFilePath + sFilename; 154 File fTempFile = new File(sTempPath); 155 156 JFileChooser chooser = new JFileChooser(); 157 chooser.setSelectedFile(fTempFile); 158 159 if (sPath.startsWith(HarmonisePaths.PATH_IMAGES)) { 160 chooser.setFileFilter(new ImageFilter()); 161 } else if (sPath.startsWith(HarmonisePaths.PATH_PDF)) { 162 chooser.setFileFilter(new PDFFilter()); 163 } else if (sPath.startsWith(HarmonisePaths.PATH_FLASH)) { 164 chooser.setFileFilter(new FlashFilter()); 165 } else if (sPath.startsWith(HarmonisePaths.PATH_MOVIES)) { 166 chooser.setFileFilter(new MovieFilter()); 167 } 168 169 int returnVal = chooser.showSaveDialog(DisplayManager.getInstance() 170 .getMainWindow()); 171 if (returnVal == JFileChooser.APPROVE_OPTION) { 172 File fFile = chooser.getSelectedFile(); 173 super.createWorkingFile(vfFile, fFile); 174 } 175 176 return new VFSStatus(); 177 } 178 179 184 public boolean hasResourceBeenCreated() { 185 return this.m_bResourceCreated; 186 } 187 188 public PathStatusWrapper upload(String sPath, AbstractVirtualFileSystem vfs) { 189 VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource(); 190 191 JFileChooser chooser = getChooser(sPath); 192 193 String sValue = ConfigStore.getInstance() 194 .getPropertyValue("ASSET_PATH"); 195 if (sValue != null && sValue != "") { 196 chooser.setCurrentDirectory(new File(sValue)); 197 } 198 int returnVal = chooser.showOpenDialog(DisplayManager.getInstance() 199 .getMainWindow()); 200 if (returnVal == JFileChooser.APPROVE_OPTION) { 201 File fFile = chooser.getSelectedFile(); 202 File currentFile = chooser.getCurrentDirectory(); 203 ConfigStore.getInstance().setProperty("ASSET_PATH", 204 currentFile.getPath()); 205 206 String sFilename = fFile.getName(); 207 if (sFilename.indexOf(".") > -1) { 208 String sExt = sFilename.substring(sFilename.indexOf(".") + 1); 209 210 List mimes = MimeTypeMapping.getMimeTypes(sExt); 211 if (mimes.size() > 0) { 212 String sMimeType = (String ) mimes.get(0); 213 vfs.getVirtualFileSystemView().setContentType(vfFile, sMimeType); 214 215 byte[] bytes = new byte[new Long (fFile.length()) 216 .intValue()]; 217 218 BufferedInputStream buff; 219 try { 220 buff = new BufferedInputStream(new FileInputStream( 221 fFile)); 222 buff.read(bytes); 223 224 vfFile.setContent(bytes); 225 226 return new PathStatusWrapper(super.createWorkingFile(vfFile), new VFSStatus()); 227 } catch (FileNotFoundException e) { 228 e.printStackTrace(); 229 } catch (IOException e) { 230 e.printStackTrace(); 231 } 232 } 233 } 234 } 235 return new PathStatusWrapper(null, new VFSStatus()); 236 } 237 238 }
| Popular Tags
|