KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > editors > LinkEditor


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

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 /**
34  * The link editor handles the url and e-mail asset types.
35  *
36  * @author Matthew Large
37  * @version $Revision: 1.1 $
38  *
39  */

40 public class LinkEditor implements Editor {
41
42     private boolean m_bResourceCreated = false;
43
44     /**
45      *
46      */

47     public LinkEditor() {
48         super();
49     }
50
51     /* (non-Javadoc)
52      * @see com.simulacramedia.contentmanager.editors.Editor#open(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
53      */

54     public PathStatusWrapper open(String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
55         VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource();
56
57         String JavaDoc 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 JavaDoc sContent = new String JavaDoc(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     /* (non-Javadoc)
82      * @see com.simulacramedia.contentmanager.editors.Editor#createNew(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
83      */

84     public PathStatusWrapper createNew(String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
85         ResourceStatusWrapper statusWrapper = new ResourceStatusWrapper(null, new VFSStatus());
86         
87         String JavaDoc 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 JavaDoc) MimeTypeMapping.getMimeTypes("url").get(0));
107             } else if (sPath.startsWith("/webdav/Content/Assets/e-mail")) {
108                 vfs.getVirtualFileSystemView().setContentType(
109                     vfFile,
110                     (String JavaDoc) MimeTypeMapping.getMimeTypes("adr").get(0));
111             } else {
112                 vfs.getVirtualFileSystemView().setContentType(
113                     vfFile,
114                     (String JavaDoc) 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     /* (non-Javadoc)
131      * @see com.simulacramedia.contentmanager.editors.Editor#discardChanges(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
132      */

133     public StatusData discardChanges(String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
134         return new VFSStatus();
135     }
136
137     /* (non-Javadoc)
138      * @see com.simulacramedia.contentmanager.editors.Editor#export(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
139      */

140     public StatusData export(String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
141         return new VFSStatus();
142     }
143
144     /* (non-Javadoc)
145      * @see com.simulacramedia.contentmanager.editors.Editor#createNew(java.lang.String, byte[], com.simulacramedia.vfs.AbstractVirtualFileSystem)
146      */

147     public PathStatusWrapper createNew(
148         String JavaDoc 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 JavaDoc) MimeTypeMapping.getMimeTypes("url").get(0));
159         } else if (sPath.startsWith("/webdav/Content/Assets/e-mail")) {
160             vfs.getVirtualFileSystemView().setContentType(
161                 vfFile,
162                 (String JavaDoc) MimeTypeMapping.getMimeTypes("adr").get(0));
163         } else {
164             vfs.getVirtualFileSystemView().setContentType(
165                 vfFile,
166                 (String JavaDoc) 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     /* (non-Javadoc)
182      * @see com.simulacramedia.contentmanager.editors.Editor#hasResourceBeenCreated()
183      */

184     public boolean hasResourceBeenCreated() {
185         return this.m_bResourceCreated;
186     }
187
188     /* (non-Javadoc)
189      * @see com.simulacramedia.contentmanager.editors.Editor#preview(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
190      */

191     public PathStatusWrapper preview(String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
192         VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource();
193         String JavaDoc sContent = new String JavaDoc(vfFile.getContent());
194         try {
195             if (sPath.startsWith("/webdav/Content/Assets/links")) {
196                 Process JavaDoc proc5 = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + sContent);
197             } else if (sPath.startsWith("/webdav/Content/Assets/e-mail")) {
198                 Process JavaDoc proc5 = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler mailto:" + sContent);
199             } else {
200                 Process JavaDoc 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     /* (non-Javadoc)
212      * @see com.simulacramedia.contentmanager.editors.Editor#upload(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
213      */

214     public PathStatusWrapper upload(String JavaDoc path, AbstractVirtualFileSystem vfs) {
215         return new PathStatusWrapper(null, new VFSStatus());
216     }
217
218 }
219
Popular Tags