KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
22 import java.io.StringReader JavaDoc;
23
24 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
25 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
26 import javax.xml.parsers.ParserConfigurationException JavaDoc;
27
28 import org.openharmonise.commons.xml.*;
29 import org.openharmonise.commons.xml.namespace.*;
30 import org.openharmonise.him.editors.report.*;
31 import org.openharmonise.vfs.*;
32 import org.openharmonise.vfs.status.*;
33 import org.w3c.dom.Document JavaDoc;
34 import org.xml.sax.SAXException JavaDoc;
35
36
37 /**
38  * Handles editing of system reports.
39  *
40  * @author Matthew Large
41  * @version $Revision: 1.1 $
42  *
43  */

44 public class SystemReportEditor implements Editor {
45     
46     private boolean m_bResourceCreated = false;
47
48     /**
49      *
50      */

51     public SystemReportEditor() {
52         super();
53     }
54
55     /* (non-Javadoc)
56      * @see com.simulacramedia.contentmanager.editors.Editor#open(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
57      */

58     public PathStatusWrapper open(String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
59         VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource();
60         if(vfFile!=null) {
61             Document JavaDoc xml = null;
62             try {
63                 xml = DocumentBuilderFactory
64                 .newInstance()
65                 .newDocumentBuilder()
66                 .parse(
67                 new org.xml.sax.InputSource JavaDoc(new StringReader JavaDoc( new String JavaDoc(vfFile.getContent()) )));
68             } catch (SAXException JavaDoc e) {
69                 e.printStackTrace();
70             } catch (IOException JavaDoc e) {
71                 e.printStackTrace();
72             } catch (ParserConfigurationException JavaDoc e) {
73                 e.printStackTrace();
74             } catch (FactoryConfigurationError JavaDoc e) {
75                 e.printStackTrace();
76             }
77             
78             ReportEditor editor = null;
79             if(xml!=null) {
80                 editor = new ReportEditor(sPath, xml);
81             } else {
82                 editor = new ReportEditor(sPath);
83             }
84             editor.show();
85             
86             xml = editor.getQuery();
87             if(xml!=null) {
88                 XMLPrettyPrint printer = new XMLPrettyPrint();
89                 String JavaDoc sXML = null;
90                 try {
91                     sXML = printer.printNode(xml.getDocumentElement());
92                     vfFile.setContent(sXML.getBytes());
93                 } catch (NamespaceClashException e1) {
94                     e1.printStackTrace();
95                 }
96             }
97         }
98
99         return new PathStatusWrapper(null, new VFSStatus());
100     }
101
102     /* (non-Javadoc)
103      * @see com.simulacramedia.contentmanager.editors.Editor#createNew(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
104      */

105     public PathStatusWrapper createNew(String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
106         PathStatusWrapper statusWrapper = new PathStatusWrapper(null, new VFSStatus());
107         
108         Document JavaDoc xml = null;
109         try {
110             xml =
111                 DocumentBuilderFactory
112                     .newInstance()
113                     .newDocumentBuilder().newDocument();
114         } catch (ParserConfigurationException JavaDoc e1) {
115             e1.printStackTrace();
116         } catch (FactoryConfigurationError JavaDoc e1) {
117             e1.printStackTrace();
118         }
119
120         if(xml!=null) {
121             xml.appendChild( xml.createElement("ReportQuery") );
122             
123             XMLPrettyPrint printer = new XMLPrettyPrint();
124             try {
125                 String JavaDoc sXML = printer.printNode(xml.getDocumentElement());
126                 statusWrapper = this.createNew(sPath, sXML.getBytes(), vfs);
127             } catch (NamespaceClashException e) {
128                 e.printStackTrace();
129             }
130         }
131         
132         return statusWrapper;
133     }
134
135     /* (non-Javadoc)
136      * @see com.simulacramedia.contentmanager.editors.Editor#createNew(java.lang.String, byte[], com.simulacramedia.vfs.AbstractVirtualFileSystem)
137      */

138     public PathStatusWrapper createNew(
139         String JavaDoc sPath,
140         byte[] content,
141         AbstractVirtualFileSystem vfs) {
142         ResourceStatusWrapper statusWrapper = new ResourceStatusWrapper(null, new VFSStatus());
143         
144             
145         VirtualFile vfFile = new VirtualFile(sPath);
146     
147         vfs.getVirtualFileSystemView().setContentType(vfFile, "text/xml");
148
149         vfFile.setContent(content);
150         
151         statusWrapper = vfs.addVirtualFile(sPath, vfFile);
152         
153         vfFile = vfs.getVirtualFile(sPath).getResource();
154
155         if(statusWrapper.getStatus().isOK()) {
156             this.m_bResourceCreated = true;
157         }
158
159         return new PathStatusWrapper(null, statusWrapper.getStatus());
160     }
161
162     /* (non-Javadoc)
163      * @see com.simulacramedia.contentmanager.editors.Editor#discardChanges(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
164      */

165     public StatusData discardChanges(String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
166         return new VFSStatus();
167     }
168
169     /* (non-Javadoc)
170      * @see com.simulacramedia.contentmanager.editors.Editor#export(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
171      */

172     public StatusData export(String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
173         return new VFSStatus();
174     }
175
176     /* (non-Javadoc)
177      * @see com.simulacramedia.contentmanager.editors.Editor#hasResourceBeenCreated()
178      */

179     public boolean hasResourceBeenCreated() {
180         return this.m_bResourceCreated;
181     }
182
183     /* (non-Javadoc)
184      * @see com.simulacramedia.contentmanager.editors.Editor#preview(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
185      */

186     public PathStatusWrapper preview(String JavaDoc sPath, AbstractVirtualFileSystem vfs) {
187         return new PathStatusWrapper(null, new VFSStatus());
188     }
189
190     /* (non-Javadoc)
191      * @see com.simulacramedia.contentmanager.editors.Editor#upload(java.lang.String, com.simulacramedia.vfs.AbstractVirtualFileSystem)
192      */

193     public PathStatusWrapper upload(String JavaDoc path, AbstractVirtualFileSystem vfs) {
194         return new PathStatusWrapper(null, new VFSStatus());
195     }
196
197 }
Popular Tags