001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.editors;
020:
021: import java.awt.*;
022: import java.io.*;
023: import java.net.*;
024:
025: import javax.swing.*;
026:
027: import org.openharmonise.commons.net.*;
028: import org.openharmonise.swing.*;
029: import org.openharmonise.vfs.*;
030: import org.openharmonise.vfs.gui.*;
031: import org.openharmonise.vfs.status.*;
032:
033: /**
034: * The link editor handles the url and e-mail asset types.
035: *
036: * @author Matthew Large
037: * @version $Revision: 1.1 $
038: *
039: */
040: public class LinkEditor implements Editor {
041:
042: private boolean m_bResourceCreated = false;
043:
044: /**
045: *
046: */
047: public LinkEditor() {
048: super ();
049: }
050:
051: /* (non-Javadoc)
052: * @see com.simulacramedia.contentmanager.editors.Editor#open(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
053: */
054: public PathStatusWrapper open(String sPath,
055: AbstractVirtualFileSystem vfs) {
056: VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource();
057:
058: String sTitle = "Link editor";
059: if (sPath.startsWith("/webdav/Content/Assets/e-mail")) {
060: sTitle = "E-mail address editor";
061: }
062:
063: Frame frame = new Frame();
064: frame.setIconImage(((ImageIcon) IconManager.getInstance()
065: .getIcon("32-sim-logo.gif")).getImage());
066: SingleTextEntryDialog dialog = new SingleTextEntryDialog(frame,
067: sTitle);
068:
069: String sContent = new String(vfFile.getContent());
070: dialog.setTextValue(sContent);
071:
072: dialog.show();
073:
074: if (dialog.getTextValue() != null
075: && !dialog.getTextValue().equals("")) {
076: vfFile.setContent(dialog.getTextValue().getBytes());
077: }
078:
079: return new PathStatusWrapper(null, new VFSStatus());
080: }
081:
082: /* (non-Javadoc)
083: * @see com.simulacramedia.contentmanager.editors.Editor#createNew(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
084: */
085: public PathStatusWrapper createNew(String sPath,
086: AbstractVirtualFileSystem vfs) {
087: ResourceStatusWrapper statusWrapper = new ResourceStatusWrapper(
088: null, new VFSStatus());
089:
090: String sTitle = "Link editor";
091: if (sPath.startsWith("/webdav/Content/Assets/e-mail")) {
092: sTitle = "E-mail address editor";
093: }
094:
095: Frame frame = new Frame();
096: frame.setIconImage(((ImageIcon) IconManager.getInstance()
097: .getIcon("32-sim-logo.gif")).getImage());
098: SingleTextEntryDialog dialog = new SingleTextEntryDialog(frame,
099: sTitle);
100: dialog.show();
101:
102: if (dialog.getTextValue() != null
103: && !dialog.getTextValue().equals("")) {
104: VirtualFile vfFile = new VirtualFile(sPath);
105:
106: if (sPath.startsWith("/webdav/Content/Assets/links")) {
107: vfs.getVirtualFileSystemView().setContentType(
108: vfFile,
109: (String) MimeTypeMapping.getMimeTypes("url")
110: .get(0));
111: } else if (sPath
112: .startsWith("/webdav/Content/Assets/e-mail")) {
113: vfs.getVirtualFileSystemView().setContentType(
114: vfFile,
115: (String) MimeTypeMapping.getMimeTypes("adr")
116: .get(0));
117: } else {
118: vfs.getVirtualFileSystemView().setContentType(
119: vfFile,
120: (String) MimeTypeMapping.getMimeTypes("url")
121: .get(0));
122: }
123:
124: vfFile.setContent(dialog.getTextValue().getBytes());
125: statusWrapper = vfs.addVirtualFile(sPath, vfFile);
126:
127: vfFile = vfs.getVirtualFile(sPath).getResource();
128:
129: if (statusWrapper.getStatus().isOK()) {
130: this .m_bResourceCreated = true;
131: }
132: }
133:
134: return new PathStatusWrapper(null, statusWrapper.getStatus());
135: }
136:
137: /* (non-Javadoc)
138: * @see com.simulacramedia.contentmanager.editors.Editor#discardChanges(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
139: */
140: public StatusData discardChanges(String sPath,
141: AbstractVirtualFileSystem vfs) {
142: return new VFSStatus();
143: }
144:
145: /* (non-Javadoc)
146: * @see com.simulacramedia.contentmanager.editors.Editor#export(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
147: */
148: public StatusData export(String sPath, AbstractVirtualFileSystem vfs) {
149: return new VFSStatus();
150: }
151:
152: /* (non-Javadoc)
153: * @see com.simulacramedia.contentmanager.editors.Editor#createNew(java.lang.String, byte[], com.simulacramedia.vfs.AbstractVirtualFileSystem)
154: */
155: public PathStatusWrapper createNew(String sPath, byte[] content,
156: AbstractVirtualFileSystem vfs) {
157: ResourceStatusWrapper statusWrapper = new ResourceStatusWrapper(
158: null, new VFSStatus());
159:
160: VirtualFile vfFile = new VirtualFile(sPath);
161:
162: if (sPath.startsWith("/webdav/Content/Assets/links")) {
163: vfs.getVirtualFileSystemView()
164: .setContentType(
165: vfFile,
166: (String) MimeTypeMapping
167: .getMimeTypes("url").get(0));
168: } else if (sPath.startsWith("/webdav/Content/Assets/e-mail")) {
169: vfs.getVirtualFileSystemView()
170: .setContentType(
171: vfFile,
172: (String) MimeTypeMapping
173: .getMimeTypes("adr").get(0));
174: } else {
175: vfs.getVirtualFileSystemView()
176: .setContentType(
177: vfFile,
178: (String) MimeTypeMapping
179: .getMimeTypes("url").get(0));
180: }
181:
182: vfFile.setContent(content);
183: statusWrapper = vfs.addVirtualFile(sPath, vfFile);
184:
185: vfFile = vfs.getVirtualFile(sPath).getResource();
186:
187: if (statusWrapper.getStatus().isOK()) {
188: this .m_bResourceCreated = true;
189: }
190:
191: return new PathStatusWrapper(null, statusWrapper.getStatus());
192: }
193:
194: /* (non-Javadoc)
195: * @see com.simulacramedia.contentmanager.editors.Editor#hasResourceBeenCreated()
196: */
197: public boolean hasResourceBeenCreated() {
198: return this .m_bResourceCreated;
199: }
200:
201: /* (non-Javadoc)
202: * @see com.simulacramedia.contentmanager.editors.Editor#preview(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
203: */
204: public PathStatusWrapper preview(String sPath,
205: AbstractVirtualFileSystem vfs) {
206: VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource();
207: String sContent = new String(vfFile.getContent());
208: try {
209: if (sPath.startsWith("/webdav/Content/Assets/links")) {
210: Process proc5 = Runtime.getRuntime().exec(
211: "rundll32 url.dll,FileProtocolHandler "
212: + sContent);
213: } else if (sPath
214: .startsWith("/webdav/Content/Assets/e-mail")) {
215: Process proc5 = Runtime.getRuntime().exec(
216: "rundll32 url.dll,FileProtocolHandler mailto:"
217: + sContent);
218: } else {
219: Process proc5 = Runtime.getRuntime().exec(
220: "rundll32 url.dll,FileProtocolHandler "
221: + sContent);
222: }
223: } catch (MalformedURLException e1) {
224: e1.printStackTrace();
225: } catch (IOException e1) {
226: e1.printStackTrace();
227: }
228:
229: return new PathStatusWrapper(null, new VFSStatus());
230: }
231:
232: /* (non-Javadoc)
233: * @see com.simulacramedia.contentmanager.editors.Editor#upload(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
234: */
235: public PathStatusWrapper upload(String path,
236: AbstractVirtualFileSystem vfs) {
237: return new PathStatusWrapper(null, new VFSStatus());
238: }
239:
240: }
|