From 750e4c2fc7a6f96a8c3e17b3ca59b696feb4f802 Mon Sep 17 00:00:00 2001 From: fotis Date: Fri, 23 Jun 2000 13:18:32 +0000 Subject: [PATCH] add: ant task needed by an ant script to write all xml documentation files into one pdf file git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193437 13f79535-47bb-0310-9956-ffa450edef68 --- lib/CompileXMLFiles.class | Bin 0 -> 7056 bytes lib/CompileXMLFiles.java | 294 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 lib/CompileXMLFiles.class create mode 100644 lib/CompileXMLFiles.java diff --git a/lib/CompileXMLFiles.class b/lib/CompileXMLFiles.class new file mode 100644 index 0000000000000000000000000000000000000000..a0ce839d25615cd9d0e5f9285e9f4451f630dd94 GIT binary patch literal 7056 zcmbtZ33wc5d49juO0!yxuk|6zSJp~m%aSbFAu)-p_>yI;M3x-cu_K!hM!O?jTpWe$6w=bn(!_Bt%1KY@b?D(A&zxAe?9&&hHuAl z9sVhX@5J!k82(vDzo$$8MVI_*4Byw6e>3od7=EatKZ@bUF`RC~Pw?*=-+#pLpK-eK zUorf54F40yPw_Lo{M^9*8h9>-=M6zj#E?i#>I{j-q@J-$Lre_nlbBu_^%7^)(qxEf z$h;Vyh-1IZ=S34Sj87V}z>tM8Sro@1eM=a!*pMZLEHz}AAIZ9!u2 zxOLL%&RV&N?gOrq$xUn(82OUxPn+YE%2|{4V5aB_79Xu8-dGVT3hMQl_ocpI$<1WD zcRG%BN)=FbLvJRRakmNT+BO^#MEmk-da+Hjo%BQUCA+Bc|f7O8h$(RTX+aV>4T(o;1Ur`&KQI>Vl_Qze%UG}w-lcc@#A z@TFimMcWZ98O%Eq-BXjf zi>HdNJ*kgoF7I0E;ch#X72NWo%+xTf+oq5pcuF}hRcYUKU+?YzN4>QzRh=I4Epq#I z=ToIgJLe7(A#R@Aw7e~pi}LtZ-EJdW5n5VPMuFp6PF1I%$$ zIa>6c<<{;hjgQ-oogT5RwC!l_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lHuK+3?>`Q9*B!?bBwqev e;K#8UuR@lvVYtAjI$AIp`bCB=Bx6P2rC$I;5U890 literal 0 HcmV?d00001 diff --git a/lib/CompileXMLFiles.java b/lib/CompileXMLFiles.java new file mode 100644 index 000000000..714b228f4 --- /dev/null +++ b/lib/CompileXMLFiles.java @@ -0,0 +1,294 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * + */ + + /** This class is an extension of Ant, a script utility from + jakarta.apache.org. + It takes a couple of xml files conforming to the xml-site dtd and + writes them all into one xml file, deleting any reference to + the proprietary protocol sbk. The configFile determines what files + are read in what sequence. + */ +// Ant +import org.apache.tools.ant.Task; +import org.apache.tools.ant.BuildException; + + +// SAX +import org.xml.sax.Parser; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.Locator; +import org.xml.sax.AttributeList; + +// Java +import java.io.*; +import java.util.*; +import java.net.URL; + +public class CompileXMLFiles extends Task + implements org.xml.sax.EntityResolver, + org.xml.sax.DTDHandler, + org.xml.sax.DocumentHandler, + org.xml.sax.ErrorHandler { + private String configFile, outFile; + private String [] filenameList; + private String filenames; + private ArrayList files = new ArrayList(); + + //sets name of configuration file, which must + //be an xml file conforming to the book.dtd used by xml-site + public void setConfigFile(String configFile) { + this.configFile = configFile; + } + + public void setOutFile(String outFile) { + this.outFile = outFile; + } + + + //main method of this task + public void execute () throws BuildException { + boolean errors = false; + + if (!(new File(configFile).exists())) { + errors = true; + System.err.println("Task CompileXMLFiles - ERROR: config file " + configFile + " is missing."); + } + + Parser parser = createParser(); + + if (parser == null) { + System.err.println("Task CompileXMLFiles - ERROR: Unable to create SAX parser"); + errors = true; + } + parser.setDocumentHandler(this); + try { + parser.parse(CompileXMLFiles.fileInputSource(configFile)); + } catch (SAXException e) { + System.out.println(e); + } catch (IOException ioe) { + System.out.println(ioe); + } + } //end: execute() + + + /*the following methods belong to the sax parser and implement the Document Handler*/ + public InputSource resolveEntity (String publicId, String systemId) + throws SAXException + { + return null; + } + + public void notationDecl (String name, String publicId, String systemId) + { + // no op + } + + public void unparsedEntityDecl (String name, String publicId, + String systemId, String notationName) + { + // no op + } + + public void setDocumentLocator (Locator locator) + { + // no op + } + + public void startDocument () + throws SAXException + { + // no op + } + + /* After the cnfiguration file has been parsed all files which + have been collected in the ArrayList files are concatinated + and written to a new (temporary) file */ + public void endDocument () + throws SAXException + { + String line, filename; + BufferedReader in; + Iterator iterator = files.iterator(); + try { + BufferedWriter out = + new BufferedWriter (new FileWriter("compileXMLFiles-tmp.xml")); + out.write("\n" + + "\n" + + "]>\n"); + while (iterator.hasNext()) { + filename = (String) iterator.next(); + in = new BufferedReader(new FileReader(filename)); + while ((line = in.readLine()) != null) { + //kill the lines pointing to the sbk protocol and the xml declaration + if (line.indexOf(""); + out.close(); + } catch (Exception e) { + System.out.println(e); + } + + } + + public void startElement (String name, AttributeList atts) + throws SAXException { + String id, label, source; + if (name.equals("document") || name.equals("entry")) { + source = atts.getValue("source"); + files.add(source); + } + } + public void endElement (String name) + throws SAXException + { + // no op + } + + public void characters (char ch[], int start, int length) + throws SAXException + { + // no op + } + + public void ignorableWhitespace (char ch[], int start, int length) + throws SAXException + { + // no op + } + public void processingInstruction (String target, String data) + throws SAXException + { + // no op + } + + public void warning (SAXParseException e) + throws SAXException + { + // no op + } + public void error (SAXParseException e) + throws SAXException + { + // no op + } + + public void fatalError (SAXParseException e) + throws SAXException + { + throw e; + } + + /* ------------------------*/ + /** + * creates a SAX parser, using the value of org.xml.sax.parser + * defaulting to org.apache.xerces.parsers.SAXParser + * + * @return the created SAX parser + */ + static Parser createParser() { + String parserClassName = System.getProperty("org.xml.sax.parser"); + if (parserClassName == null) { + parserClassName = "org.apache.xerces.parsers.SAXParser"; + } + System.err.println("using SAX parser " + parserClassName); + + try { + return (Parser) Class.forName(parserClassName).newInstance(); + } catch (ClassNotFoundException e) { + System.err.println("Could not find " + parserClassName); + } catch (InstantiationException e) { + System.err.println("Could not instantiate " + parserClassName); + } catch (IllegalAccessException e) { + System.err.println("Could not access " + parserClassName); + } catch (ClassCastException e) { + System.err.println(parserClassName + " is not a SAX driver"); + } + return null; + } + + /** + * create an InputSource from a file name + * + * @param filename the name of the file + * @return the InputSource created + */ + protected static InputSource fileInputSource(String filename) { + + /* this code adapted from James Clark's in XT */ + File file = new File(filename); + String path = file.getAbsolutePath(); + String fSep = System.getProperty("file.separator"); + if (fSep != null && fSep.length() == 1) + path = path.replace(fSep.charAt(0), '/'); + if (path.length() > 0 && path.charAt(0) != '/') + path = '/' + path; + try { + return new InputSource(new URL("file", null, path).toString()); + } catch (java.net.MalformedURLException e) { + throw new Error("unexpected MalformedURLException"); + } + } + +} + -- 2.39.5