1 19 package org.openharmonise.him.editors; 20 21 import java.io.IOException ; 22 import java.io.StringReader ; 23 24 import javax.xml.parsers.DocumentBuilderFactory ; 25 import javax.xml.parsers.FactoryConfigurationError ; 26 import javax.xml.parsers.ParserConfigurationException ; 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 ; 34 import org.xml.sax.SAXException ; 35 36 37 44 public class SystemReportEditor implements Editor { 45 46 private boolean m_bResourceCreated = false; 47 48 51 public SystemReportEditor() { 52 super(); 53 } 54 55 58 public PathStatusWrapper open(String sPath, AbstractVirtualFileSystem vfs) { 59 VirtualFile vfFile = vfs.getVirtualFile(sPath).getResource(); 60 if(vfFile!=null) { 61 Document xml = null; 62 try { 63 xml = DocumentBuilderFactory 64 .newInstance() 65 .newDocumentBuilder() 66 .parse( 67 new org.xml.sax.InputSource (new StringReader ( new String (vfFile.getContent()) ))); 68 } catch (SAXException e) { 69 e.printStackTrace(); 70 } catch (IOException e) { 71 e.printStackTrace(); 72 } catch (ParserConfigurationException e) { 73 e.printStackTrace(); 74 } catch (FactoryConfigurationError 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 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 105 public PathStatusWrapper createNew(String sPath, AbstractVirtualFileSystem vfs) { 106 PathStatusWrapper statusWrapper = new PathStatusWrapper(null, new VFSStatus()); 107 108 Document xml = null; 109 try { 110 xml = 111 DocumentBuilderFactory 112 .newInstance() 113 .newDocumentBuilder().newDocument(); 114 } catch (ParserConfigurationException e1) { 115 e1.printStackTrace(); 116 } catch (FactoryConfigurationError 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 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 138 public PathStatusWrapper createNew( 139 String 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 165 public StatusData discardChanges(String sPath, AbstractVirtualFileSystem vfs) { 166 return new VFSStatus(); 167 } 168 169 172 public StatusData export(String sPath, AbstractVirtualFileSystem vfs) { 173 return new VFSStatus(); 174 } 175 176 179 public boolean hasResourceBeenCreated() { 180 return this.m_bResourceCreated; 181 } 182 183 186 public PathStatusWrapper preview(String sPath, AbstractVirtualFileSystem vfs) { 187 return new PathStatusWrapper(null, new VFSStatus()); 188 } 189 190 193 public PathStatusWrapper upload(String path, AbstractVirtualFileSystem vfs) { 194 return new PathStatusWrapper(null, new VFSStatus()); 195 } 196 197 }
| Popular Tags
|