1 19 package org.openharmonise.him.editors; 20 21 import java.awt.*; 22 import java.io.*; 23 import java.net.*; 24 25 import javax.swing.*; 26 27 import org.openharmonise.commons.net.*; 28 import org.openharmonise.swing.*; 29 import org.openharmonise.vfs.*; 30 import org.openharmonise.vfs.gui.*; 31 import org.openharmonise.vfs.status.*; 32 33 40 public class LinkEditor implements Editor { 41 42 private boolean m_bResourceCreated = false; 43 44 47 public LinkEditor() { 48 super(); 49 } 50 51 54 public PathStatusWrapper open(String sPath, AbstractVirtualFileSystem vfs) { 55 VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource(); 56 57 String sTitle = "Link editor"; 58 if (sPath.startsWith("/webdav/Content/Assets/e-mail")) { 59 sTitle = "E-mail address editor"; 60 } 61 62 Frame frame = new Frame(); 63 frame.setIconImage( 64 ((ImageIcon) IconManager.getInstance().getIcon("32-sim-logo.gif")) 65 .getImage()); 66 SingleTextEntryDialog dialog = new SingleTextEntryDialog(frame, sTitle); 67 68 String sContent = new String (vfFile.getContent()); 69 dialog.setTextValue(sContent); 70 71 dialog.show(); 72 73 if (dialog.getTextValue() != null 74 && !dialog.getTextValue().equals("")) { 75 vfFile.setContent(dialog.getTextValue().getBytes()); 76 } 77 78 return new PathStatusWrapper(null, new VFSStatus()); 79 } 80 81 84 public PathStatusWrapper createNew(String sPath, AbstractVirtualFileSystem vfs) { 85 ResourceStatusWrapper statusWrapper = new ResourceStatusWrapper(null, new VFSStatus()); 86 87 String sTitle = "Link editor"; 88 if (sPath.startsWith("/webdav/Content/Assets/e-mail")) { 89 sTitle = "E-mail address editor"; 90 } 91 92 Frame frame = new Frame(); 93 frame.setIconImage( 94 ((ImageIcon) IconManager.getInstance().getIcon("32-sim-logo.gif")) 95 .getImage()); 96 SingleTextEntryDialog dialog = new SingleTextEntryDialog(frame, sTitle); 97 dialog.show(); 98 99 if (dialog.getTextValue() != null 100 && !dialog.getTextValue().equals("")) { 101 VirtualFile vfFile = new VirtualFile(sPath); 102 103 if (sPath.startsWith("/webdav/Content/Assets/links")) { 104 vfs.getVirtualFileSystemView().setContentType( 105 vfFile, 106 (String ) MimeTypeMapping.getMimeTypes("url").get(0)); 107 } else if (sPath.startsWith("/webdav/Content/Assets/e-mail")) { 108 vfs.getVirtualFileSystemView().setContentType( 109 vfFile, 110 (String ) MimeTypeMapping.getMimeTypes("adr").get(0)); 111 } else { 112 vfs.getVirtualFileSystemView().setContentType( 113 vfFile, 114 (String ) MimeTypeMapping.getMimeTypes("url").get(0)); 115 } 116 117 vfFile.setContent(dialog.getTextValue().getBytes()); 118 statusWrapper = vfs.addVirtualFile(sPath, vfFile); 119 120 vfFile = vfs.getVirtualFile(sPath).getResource(); 121 122 if(statusWrapper.getStatus().isOK()) { 123 this.m_bResourceCreated = true; 124 } 125 } 126 127 return new PathStatusWrapper(null, statusWrapper.getStatus()); 128 } 129 130 133 public StatusData discardChanges(String sPath, AbstractVirtualFileSystem vfs) { 134 return new VFSStatus(); 135 } 136 137 140 public StatusData export(String sPath, AbstractVirtualFileSystem vfs) { 141 return new VFSStatus(); 142 } 143 144 147 public PathStatusWrapper createNew( 148 String sPath, 149 byte[] content, 150 AbstractVirtualFileSystem vfs) { 151 ResourceStatusWrapper statusWrapper = new ResourceStatusWrapper(null, new VFSStatus()); 152 153 VirtualFile vfFile = new VirtualFile(sPath); 154 155 if (sPath.startsWith("/webdav/Content/Assets/links")) { 156 vfs.getVirtualFileSystemView().setContentType( 157 vfFile, 158 (String ) MimeTypeMapping.getMimeTypes("url").get(0)); 159 } else if (sPath.startsWith("/webdav/Content/Assets/e-mail")) { 160 vfs.getVirtualFileSystemView().setContentType( 161 vfFile, 162 (String ) MimeTypeMapping.getMimeTypes("adr").get(0)); 163 } else { 164 vfs.getVirtualFileSystemView().setContentType( 165 vfFile, 166 (String ) MimeTypeMapping.getMimeTypes("url").get(0)); 167 } 168 169 vfFile.setContent(content); 170 statusWrapper = vfs.addVirtualFile(sPath, vfFile); 171 172 vfFile = vfs.getVirtualFile(sPath).getResource(); 173 174 if(statusWrapper.getStatus().isOK()) { 175 this.m_bResourceCreated = true; 176 } 177 178 return new PathStatusWrapper(null, statusWrapper.getStatus()); 179 } 180 181 184 public boolean hasResourceBeenCreated() { 185 return this.m_bResourceCreated; 186 } 187 188 191 public PathStatusWrapper preview(String sPath, AbstractVirtualFileSystem vfs) { 192 VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource(); 193 String sContent = new String (vfFile.getContent()); 194 try { 195 if (sPath.startsWith("/webdav/Content/Assets/links")) { 196 Process proc5 = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + sContent); 197 } else if (sPath.startsWith("/webdav/Content/Assets/e-mail")) { 198 Process proc5 = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler mailto:" + sContent); 199 } else { 200 Process proc5 = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + sContent); 201 } 202 } catch (MalformedURLException e1) { 203 e1.printStackTrace(); 204 } catch (IOException e1) { 205 e1.printStackTrace(); 206 } 207 208 return new PathStatusWrapper(null, new VFSStatus()); 209 } 210 211 214 public PathStatusWrapper upload(String path, AbstractVirtualFileSystem vfs) { 215 return new PathStatusWrapper(null, new VFSStatus()); 216 } 217 218 } 219
| Popular Tags
|