1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.netbeans.modules.office.utils; 25 26 import java.io.InputStream; 27 import java.io.OutputStream; 28 import java.io.IOException; 29 import java.io.File; 30 31 import org.w3c.dom.Document; 32 import org.xml.sax.InputSource; 33 import org.xml.sax.SAXException; 34 import org.xml.sax.SAXParseException; 35 36 import org.openide.xml.XMLUtil; 37 38 import com.sun.star.script.framework.container.XMLParser; 39 import org.openoffice.netbeans.modules.office.options.OfficeSettings; 40 import org.openoffice.idesupport.OfficeInstallation; 41 42 public class ManifestParser implements XMLParser { 43 44 private static ManifestParser parser = null; 45 ManifestParser()46 private ManifestParser() { 47 } 48 getManifestParser()49 public static ManifestParser getManifestParser() { 50 if (parser == null) { 51 synchronized(ManifestParser.class) { 52 if (parser == null) 53 parser = new ManifestParser(); 54 } 55 } 56 return parser; 57 } 58 parse(InputStream inputStream)59 public Document parse(InputStream inputStream) { 60 InputSource is; 61 Document result = null; 62 63 try { 64 OfficeInstallation oi = OfficeSettings.getDefault().getOfficeDirectory(); 65 String id = oi.getURL("share/dtd/officedocument/1_0/"); 66 67 is = new InputSource(inputStream); 68 is.setSystemId(id); 69 70 result = XMLUtil.parse(is, false, false, null, null); 71 } 72 catch (IOException ioe) { 73 System.out.println("IO Error parsing stream."); 74 return null; 75 } 76 catch (SAXParseException spe) { 77 System.out.println("Sax Error parsing stream: " + spe.getMessage()); 78 System.out.println("\tPublicId: " + spe.getPublicId()); 79 System.out.println("\tSystemId: " + spe.getSystemId()); 80 return null; 81 } 82 catch (SAXException se) { 83 System.out.println("Sax Error parsing stream: " + se.getMessage()); 84 return null; 85 } 86 87 return result; 88 } 89 write(Document doc, OutputStream out)90 public void write(Document doc, OutputStream out) throws IOException { 91 XMLUtil.write(doc, out, ""); 92 } 93 } 94