diff options
author | Tore Engvig <tore@apache.org> | 2001-07-30 20:29:35 +0000 |
---|---|---|
committer | Tore Engvig <tore@apache.org> | 2001-07-30 20:29:35 +0000 |
commit | e0edd215721150e6c04ac49706622d6189cb0b42 (patch) | |
tree | 6b59b872d9c0e93f99316ea2f421209b71a97755 /src/org/apache/fop/tools/anttasks | |
parent | eb57915dec9bcd907e495595efac60dbf3579ad8 (diff) | |
download | xmlgraphics-fop-e0edd215721150e6c04ac49706622d6189cb0b42.tar.gz xmlgraphics-fop-e0edd215721150e6c04ac49706622d6189cb0b42.zip |
Formatted code according to code standards.
Changed license to use short license.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194380 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/tools/anttasks')
-rw-r--r-- | src/org/apache/fop/tools/anttasks/Compare.java | 327 | ||||
-rw-r--r-- | src/org/apache/fop/tools/anttasks/CompileXMLFiles.java | 462 | ||||
-rw-r--r-- | src/org/apache/fop/tools/anttasks/Fop.java | 45 | ||||
-rw-r--r-- | src/org/apache/fop/tools/anttasks/Manifest.java | 370 | ||||
-rw-r--r-- | src/org/apache/fop/tools/anttasks/RunTest.java | 80 | ||||
-rw-r--r-- | src/org/apache/fop/tools/anttasks/SerializeHyphPattern.java | 166 | ||||
-rw-r--r-- | src/org/apache/fop/tools/anttasks/Xslt.java | 294 |
7 files changed, 777 insertions, 967 deletions
diff --git a/src/org/apache/fop/tools/anttasks/Compare.java b/src/org/apache/fop/tools/anttasks/Compare.java index effc7fb88..20e401ea8 100644 --- a/src/org/apache/fop/tools/anttasks/Compare.java +++ b/src/org/apache/fop/tools/anttasks/Compare.java @@ -1,56 +1,10 @@ /* - * 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 - * <http://www.apache.org/>. + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.tools.anttasks; @@ -60,141 +14,158 @@ import org.apache.tools.ant.Task; import org.apache.tools.ant.BuildException; import java.text.DateFormat; - /** This class is an extension of Ant, a script utility from - * jakarta.apache.org. - * It provides methods to compare two files - */ +/** + * This class is an extension of Ant, a script utility from + * jakarta.apache.org. + * It provides methods to compare two files + */ public class Compare { - private String referenceDirectory, testDirectory; - private String [] filenameList; - private String filenames; - private static boolean IDENTICAL_FILES = true; - private static boolean NOTIDENTICAL_FILES = false; - private BufferedInputStream oldfileInput; - private BufferedInputStream newfileInput; - - //sets directory for test files - public void setTestDirectory(String testDirectory) { - if (!(testDirectory.endsWith("/") | testDirectory.endsWith("\\"))) { - testDirectory += File.separator; - } - this.testDirectory = testDirectory; - } - - //sets directory for reference files - public void setReferenceDirectory(String referenceDirectory) { - if (!(referenceDirectory.endsWith("/") | referenceDirectory.endsWith("\\"))) { - referenceDirectory += File.separator; + private String referenceDirectory, testDirectory; + private String[] filenameList; + private String filenames; + private static boolean IDENTICAL_FILES = true; + private static boolean NOTIDENTICAL_FILES = false; + private BufferedInputStream oldfileInput; + private BufferedInputStream newfileInput; + + // sets directory for test files + public void setTestDirectory(String testDirectory) { + if (!(testDirectory.endsWith("/") | testDirectory.endsWith("\\"))) { + testDirectory += File.separator; + } + this.testDirectory = testDirectory; } - this.referenceDirectory = referenceDirectory; - } - - public void setFilenames (String filenames) { - StringTokenizer tokens = new StringTokenizer(filenames,","); - Vector filenameListTmp = new Vector(20); - while (tokens.hasMoreTokens()) { - filenameListTmp.addElement(tokens.nextToken()); + + // sets directory for reference files + public void setReferenceDirectory(String referenceDirectory) { + if (!(referenceDirectory.endsWith("/") + | referenceDirectory.endsWith("\\"))) { + referenceDirectory += File.separator; + } + this.referenceDirectory = referenceDirectory; } - filenameList = new String [filenameListTmp.size()] ; - filenameListTmp.copyInto((String[]) filenameList); - } - - private boolean compareBytes (File oldFile, File newFile) { - try { - oldfileInput = new BufferedInputStream(new FileInputStream(oldFile)); - newfileInput = new BufferedInputStream(new FileInputStream(newFile)); - int charactO = 0; - int charactN = 0; - boolean identical = true; - - while (identical & (charactO != -1)) { - if (charactO == charactN) { - charactO = oldfileInput.read(); - charactN = newfileInput.read(); - } else { - return NOTIDENTICAL_FILES; + + public void setFilenames(String filenames) { + StringTokenizer tokens = new StringTokenizer(filenames, ","); + Vector filenameListTmp = new Vector(20); + while (tokens.hasMoreTokens()) { + filenameListTmp.addElement(tokens.nextToken()); } - } - return IDENTICAL_FILES; - } catch (IOException io) { - System.err.println("Task Compare - Error: \n" + io.toString()); + filenameList = new String[filenameListTmp.size()]; + filenameListTmp.copyInto((String[])filenameList); } - return NOTIDENTICAL_FILES; - } - - private boolean compareFileSize(File oldFile, File newFile) { - if (oldFile.length() != newFile.length()) { - return NOTIDENTICAL_FILES; - } else { - return IDENTICAL_FILES; + + private boolean compareBytes(File oldFile, File newFile) { + try { + oldfileInput = + new BufferedInputStream(new FileInputStream(oldFile)); + newfileInput = + new BufferedInputStream(new FileInputStream(newFile)); + int charactO = 0; + int charactN = 0; + boolean identical = true; + + while (identical & (charactO != -1)) { + if (charactO == charactN) { + charactO = oldfileInput.read(); + charactN = newfileInput.read(); + } else { + return NOTIDENTICAL_FILES; + } + } + return IDENTICAL_FILES; + } catch (IOException io) { + System.err.println("Task Compare - Error: \n" + io.toString()); + } + return NOTIDENTICAL_FILES; } - } //end: compareBytes - - private boolean filesExist (File oldFile, File newFile) { - if (!oldFile.exists()) { - System.err.println("Task Compare - ERROR: File " - + referenceDirectory + oldFile.getName() - + " doesn't exist!"); - return false; - } else if (!newFile.exists()) { - System.err.println("Task Compare - ERROR: File " - + testDirectory + newFile.getName() + " doesn't exist!"); - return false; - } else { - return true; + + private boolean compareFileSize(File oldFile, File newFile) { + if (oldFile.length() != newFile.length()) { + return NOTIDENTICAL_FILES; + } else { + return IDENTICAL_FILES; + } + } // end: compareBytes + + private boolean filesExist(File oldFile, File newFile) { + if (!oldFile.exists()) { + System.err.println("Task Compare - ERROR: File " + + referenceDirectory + oldFile.getName() + + " doesn't exist!"); + return false; + } else if (!newFile.exists()) { + System.err.println("Task Compare - ERROR: File " + testDirectory + + newFile.getName() + " doesn't exist!"); + return false; + } else { + return true; + } } - } - - public void writeHeader (PrintWriter results) { - String dateTime = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM).format(new Date()); - results.println("<html><head><title>Test Results</title></head><body>\n"); - results.println("<h2>Compare Results<br>"); - results.println("<font size='1'>created " + dateTime + "</font></h2>"); - results.println("<table cellpadding='10' border='2'><thead><th align='center'>reference file</th><th align='center'>test file</th>" - + "<th align='center'>identical?</th></thead>"); - - - } - - //main method of task compare - public void execute () throws BuildException { - boolean identical = false; - File oldFile; - File newFile; - try { - PrintWriter results = new PrintWriter (new FileWriter("results.html"),true); - this.writeHeader(results); - for (int i = 0; i < filenameList.length; i++) { - oldFile = new File (referenceDirectory + filenameList[i]); - newFile = new File (testDirectory + filenameList[i]); - if (filesExist(oldFile, newFile)) { - identical = compareFileSize(oldFile, newFile); - if (identical) { - identical = compareBytes(oldFile,newFile); - } - if (!identical) { - System.out.println("Task Compare: \nFiles " + referenceDirectory - + oldFile.getName()+ " - " + testDirectory - + newFile.getName() + " are *not* identical."); - results.println("<tr><td><a href='" + referenceDirectory + oldFile.getName() + "'>" - + oldFile.getName() + "</a> </td><td> <a href='" - + testDirectory + newFile.getName() +"'>" - + newFile.getName() +"</a>" - + " </td><td><font color='red'>No</font></td></tr>"); - } else { - results.println("<tr><td><a href='" + referenceDirectory + oldFile.getName() + "'>" - + oldFile.getName() + "</a> </td><td> <a href='" - + testDirectory + newFile.getName() + "'>" - + newFile.getName() + "</a>" - + " </td><td>Yes</td></tr>"); - } - } - } - results.println("</table></html>"); - } catch (IOException ioe) { - System.err.println("ERROR: " + ioe); + + public void writeHeader(PrintWriter results) { + String dateTime = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, + DateFormat.MEDIUM).format(new Date()); + results.println("<html><head><title>Test Results</title></head><body>\n"); + results.println("<h2>Compare Results<br>"); + results.println("<font size='1'>created " + dateTime + + "</font></h2>"); + results.println("<table cellpadding='10' border='2'><thead><th align='center'>reference file</th><th align='center'>test file</th>" + + "<th align='center'>identical?</th></thead>"); + + } - } //end: execute() + + // main method of task compare + public void execute() throws BuildException { + boolean identical = false; + File oldFile; + File newFile; + try { + PrintWriter results = + new PrintWriter(new FileWriter("results.html"), true); + this.writeHeader(results); + for (int i = 0; i < filenameList.length; i++) { + oldFile = new File(referenceDirectory + filenameList[i]); + newFile = new File(testDirectory + filenameList[i]); + if (filesExist(oldFile, newFile)) { + identical = compareFileSize(oldFile, newFile); + if (identical) { + identical = compareBytes(oldFile, newFile); + } + if (!identical) { + System.out.println("Task Compare: \nFiles " + + referenceDirectory + + oldFile.getName() + " - " + + testDirectory + + newFile.getName() + + " are *not* identical."); + results.println("<tr><td><a href='" + + referenceDirectory + + oldFile.getName() + "'>" + + oldFile.getName() + + "</a> </td><td> <a href='" + + testDirectory + newFile.getName() + + "'>" + newFile.getName() + "</a>" + + " </td><td><font color='red'>No</font></td></tr>"); + } else { + results.println("<tr><td><a href='" + + referenceDirectory + + oldFile.getName() + "'>" + + oldFile.getName() + + "</a> </td><td> <a href='" + + testDirectory + newFile.getName() + + "'>" + newFile.getName() + "</a>" + + " </td><td>Yes</td></tr>"); + } + } + } + results.println("</table></html>"); + } catch (IOException ioe) { + System.err.println("ERROR: " + ioe); + } + } // end: execute() + } diff --git a/src/org/apache/fop/tools/anttasks/CompileXMLFiles.java b/src/org/apache/fop/tools/anttasks/CompileXMLFiles.java index 0a9ab2af5..15568d03f 100644 --- a/src/org/apache/fop/tools/anttasks/CompileXMLFiles.java +++ b/src/org/apache/fop/tools/anttasks/CompileXMLFiles.java @@ -1,68 +1,20 @@ /* - * 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 - * <http://www.apache.org/>. - * - * + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.tools.anttasks; - /** 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. - */ +/** + * 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; @@ -81,216 +33,202 @@ 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 Vector files = new Vector(); - - //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."); +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 Vector files = new Vector(); + + // 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; } - - Parser parser = createParser(); - - if (parser == null) { - System.err.println("Task CompileXMLFiles - ERROR: Unable to create SAX parser"); - errors = true; + + public void notationDecl(String name, String publicId, String systemId) { + // no op } - parser.setDocumentHandler(this); - try { - parser.parse(CompileXMLFiles.fileInputSource(configFile)); - } catch (SAXException e) { - System.out.println(e); - } catch (IOException ioe) { - System.out.println(ioe); + + public void unparsedEntityDecl(String name, String publicId, + String systemId, String notationName) { + // no op } - } //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; - Enumeration iterator = files.elements(); - try { - BufferedWriter out = - new BufferedWriter (new FileWriter("compileXMLFiles-tmp.xml")); - out.write("<?xml version=\"1.0\"?>\n" + - "<!DOCTYPE documentation [\n" + - "<!ENTITY nbsp \" \">\n" + - "]>\n<documentation>"); - while (iterator.hasMoreElements()) { - filename = (String) iterator.nextElement(); - 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("<!DOCTYPE ")!= -1 || line.indexOf("<?xml ")!= -1 ) { - line = ""; - } - out.write(line+"\n"); + + 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; + Enumeration iterator = files.elements(); + try { + BufferedWriter out = + new BufferedWriter(new FileWriter("compileXMLFiles-tmp.xml")); + out.write("<?xml version=\"1.0\"?>\n" + + "<!DOCTYPE documentation [\n" + + "<!ENTITY nbsp \" \">\n" + "]>\n<documentation>"); + while (iterator.hasMoreElements()) { + filename = (String)iterator.nextElement(); + 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("<!DOCTYPE ") != -1 + || line.indexOf("<?xml ") != -1) { + line = ""; + } + out.write(line + "\n"); + } + out.flush(); + } + out.write("\n</documentation>"); + out.close(); + } catch (Exception e) { + System.out.println(e); } - out.flush(); - } - out.write("\n</documentation>"); - 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.addElement(source); + + 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.addElement(source); + } + } + + public void endElement(String name) throws SAXException { + // no op } - } - 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"; + + public void characters(char ch[], int start, + int length) throws SAXException { + // no op } - 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"); + + public void ignorableWhitespace(char ch[], int start, + int length) throws SAXException { + // no op } - 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"); + + 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"); + } + } + } diff --git a/src/org/apache/fop/tools/anttasks/Fop.java b/src/org/apache/fop/tools/anttasks/Fop.java index a04810903..4369c7119 100644 --- a/src/org/apache/fop/tools/anttasks/Fop.java +++ b/src/org/apache/fop/tools/anttasks/Fop.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -34,10 +35,10 @@ import org.apache.fop.configuration.Configuration; * Wrapper for Fop which allows it to be accessed from within an Ant task. * Accepts the inputs: * <ul> - * <li>fofile -> formatting objects file to be transformed</li> - * <li>pdffile -> output filename</li> - * <li>baseDir -> directory to work from</li> - * <li>messagelevel -> (info | verbose | debug) level to output non-error messages</li> + * <li>fofile -> formatting objects file to be transformed</li> + * <li>pdffile -> output filename</li> + * <li>baseDir -> directory to work from</li> + * <li>messagelevel -> (info | verbose | debug) level to output non-error messages</li> * </ul> */ public class Fop extends Task { @@ -96,8 +97,8 @@ public class Fop extends Task { } else if (messageLevel.equalsIgnoreCase("debug")) { messageType = Project.MSG_DEBUG; } else { - log("messagelevel set to unknown value \"" + messageLevel + - "\"", Project.MSG_ERR); + log("messagelevel set to unknown value \"" + messageLevel + "\"", + Project.MSG_ERR); throw new BuildException("unknown messagelevel"); } } @@ -128,7 +129,7 @@ public class Fop extends Task { /** * Starts execution of this task */ - public void execute () throws BuildException { + public void execute() throws BuildException { try { Starter starter = new FOPTaskStarter(this); starter.run(); @@ -137,6 +138,7 @@ public class Fop extends Task { } } + } class FOPTaskStarter extends Starter { @@ -150,10 +152,11 @@ class FOPTaskStarter extends Starter { logger.setMessageLevel(task.getMessageType()); } - public void run () throws FOPException { + public void run() throws FOPException { try { - //Configuration.put("baseDir", task.getBasedir().toURL().toExternalForm()); - Configuration.put("baseDir", task.getFofile().getParentFile().toURL().toExternalForm()); + // Configuration.put("baseDir", task.getBasedir().toURL().toExternalForm()); + Configuration.put("baseDir", + task.getFofile().getParentFile().toURL().toExternalForm()); } catch (Exception e) { task.log("Error setting base directory", Project.MSG_DEBUG); } @@ -170,14 +173,13 @@ class FOPTaskStarter extends Starter { throw new BuildException(ex); } - task.log("Using base directory: " + - Configuration.getValue("baseDir"), Project.MSG_DEBUG); - task.log(task.getFofile().getName() + " -> " + - task.getPdffile().getName(), Project.MSG_INFO); + task.log("Using base directory: " + + Configuration.getValue("baseDir"), Project.MSG_DEBUG); + task.log(task.getFofile().getName() + " -> " + + task.getPdffile().getName(), Project.MSG_INFO); try { - Driver driver = - new Driver(inputHandler.getInputSource(), pdfOut); + Driver driver = new Driver(inputHandler.getInputSource(), pdfOut); driver.setRenderer(Driver.RENDER_PDF); driver.setXMLReader(parser); driver.run(); @@ -187,6 +189,7 @@ class FOPTaskStarter extends Starter { } logger.die(); } + } class MessageLogger implements MessageListener { @@ -245,8 +248,7 @@ class MessageLogger implements MessageListener { } for (int i = 0; !flushed && i < breakChars.length(); i++) { - if (event.getMessage().lastIndexOf(breakChars.charAt(i)) != - -1) { + if (event.getMessage().lastIndexOf(breakChars.charAt(i)) != -1) { flush(); flushed = true; } @@ -254,8 +256,8 @@ class MessageLogger implements MessageListener { } public void flush() { - StringTokenizer output = - new StringTokenizer(cache.toString(), "\n", false); + StringTokenizer output = new StringTokenizer(cache.toString(), "\n", + false); while (output.hasMoreElements()) { task.log(output.nextElement().toString(), lastMessageLevel); } @@ -269,4 +271,5 @@ class MessageLogger implements MessageListener { // multiple <fop> tags in a buildfile handler.removeListener(this); } + } diff --git a/src/org/apache/fop/tools/anttasks/Manifest.java b/src/org/apache/fop/tools/anttasks/Manifest.java index f0e7c68a0..3c7820348 100644 --- a/src/org/apache/fop/tools/anttasks/Manifest.java +++ b/src/org/apache/fop/tools/anttasks/Manifest.java @@ -1,7 +1,8 @@ -/* +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources." + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.tools.anttasks; @@ -22,42 +23,43 @@ import java.util.Properties; * <P> * Attributes are as follows: * <dl> - * <dt>file</dt> <dd>the manifest file to write out to (required)</dd> - * <dt>overwrite</dt> <dd>if set to yes or true, overwrite the given - * manifest file. Default is no</dd> - * <dt>version</dt> <dd>manifest version. Defaults to "1.0"</dd> - * <dt>spectitle</dt> <dd>the specification title</dd> - * <dt>specversion</dt> <dd>the specification version</dd> - * <dt>specvendor</dt> <dd>the specification vendor</dd> - * <dt>impltitle</dt> <dd>the implementation title</dd> - * <dt>implversion</dt> <dd>the implementation version.</dd> - * <dt>implvendor</dt> <dd>the implementation vendor</dd> - * <dt>mainclass</dt> <dd>the class to run when java -jar is invoked</dd> - * <dt>classpath</dt> <dd>the classpath to use when java -jar is invoked</dd> - * <dt>createdby</dt> <dd>the string to set the Created-By field to</dd> - * <dt>buildid</dt> <dd>A build identifier. Defaults to a build identifier - * containing <tt>date + " ("+username+"@"+hostname+" ["+os+" "+version+" "+arch+"]</tt> </dd> + * <dt>file</dt> <dd>the manifest file to write out to (required)</dd> + * <dt>overwrite</dt> <dd>if set to yes or true, overwrite the given + * manifest file. Default is no</dd> + * <dt>version</dt> <dd>manifest version. Defaults to "1.0"</dd> + * <dt>spectitle</dt> <dd>the specification title</dd> + * <dt>specversion</dt> <dd>the specification version</dd> + * <dt>specvendor</dt> <dd>the specification vendor</dd> + * <dt>impltitle</dt> <dd>the implementation title</dd> + * <dt>implversion</dt> <dd>the implementation version.</dd> + * <dt>implvendor</dt> <dd>the implementation vendor</dd> + * <dt>mainclass</dt> <dd>the class to run when java -jar is invoked</dd> + * <dt>classpath</dt> <dd>the classpath to use when java -jar is invoked</dd> + * <dt>createdby</dt> <dd>the string to set the Created-By field to</dd> + * <dt>buildid</dt> <dd>A build identifier. Defaults to a build identifier + * containing <tt>date + " ("+username+"@"+hostname+" ["+os+" "+version+" "+arch+"]</tt> </dd> * </dl> * * @author Kelly A. Campbell */ -public class Manifest extends Task -{ +public class Manifest extends Task { public static final String MANIFEST_VERSION = "Manifest-Version: "; public static final String CREATED_BY = "Created-By: "; public static final String REQUIRED_VERSION = "Required-Version: "; - + public static final String SPECIFICATION_TITLE = "Specification-Title: "; - public static final String SPECIFICATION_VERSION = "Specification-Version: "; - public static final String SPECIFICATION_VENDOR = "Specification-Vendor: "; - public static final String IMPL_TITLE = "Implementation-Title: "; + public static final String SPECIFICATION_VERSION = + "Specification-Version: "; + public static final String SPECIFICATION_VENDOR = + "Specification-Vendor: "; + public static final String IMPL_TITLE = "Implementation-Title: "; public static final String IMPL_VERSION = "Implementation-Version: "; - public static final String IMPL_VENDOR = "Implementation-Vendor: "; - public static final String BUILD_ID = "Build-ID: "; - public static final String MAIN_CLASS = "Main-Class: "; - public static final String CLASS_PATH = "Class-Path: "; - + public static final String IMPL_VENDOR = "Implementation-Vendor: "; + public static final String BUILD_ID = "Build-ID: "; + public static final String MAIN_CLASS = "Main-Class: "; + public static final String CLASS_PATH = "Class-Path: "; + private String _manifestVersion = "1.0"; private String _spectitle; @@ -70,170 +72,160 @@ public class Manifest extends Task private String _classpath; private String _createdby; private String _buildid; - + private String _manifestFilename; private Boolean _overwrite = Boolean.FALSE; - - public void setFile(String s) - { - _manifestFilename = s; - } - - public void setOverwrite(Boolean b) - { - _overwrite = b; - } - - public void setSpectitle(String s) - { - _spectitle = s; - } - public void setSpecversion(String s) - { - _specvers = s; - } - public void setSpecvendor(String s) - { - _specvend = s; - } - public void setImpltitle(String s) - { - _impltitle = s; - } - public void setImplversion(String s) - { - _implvers = s; - } - public void setImplvendor(String s) - { - _implvend = s; - } - public void setMainclass(String s) - { - _mainclass = s; - } - public void setClasspath(String s) - { - _classpath = s; - } - public void setCreatedby(String s) - { - _createdby = s; - } - public void setBuildid(String s) - { - _buildid = s; - } - + + public void setFile(String s) { + _manifestFilename = s; + } + + public void setOverwrite(Boolean b) { + _overwrite = b; + } + + public void setSpectitle(String s) { + _spectitle = s; + } + + public void setSpecversion(String s) { + _specvers = s; + } + + public void setSpecvendor(String s) { + _specvend = s; + } + + public void setImpltitle(String s) { + _impltitle = s; + } + + public void setImplversion(String s) { + _implvers = s; + } + + public void setImplvendor(String s) { + _implvend = s; + } + + public void setMainclass(String s) { + _mainclass = s; + } + + public void setClasspath(String s) { + _classpath = s; + } + + public void setCreatedby(String s) { + _createdby = s; + } + + public void setBuildid(String s) { + _buildid = s; + } + /** * Main task method which runs this task and creates the manifest file. * @exception BuildException if one of the required attributes isn't set */ - public void execute () - throws BuildException - { - // System.out.println("Executing manifest task"); - - PrintWriter out; - try { - if (_manifestFilename != null) { - // open the file for writing - File f = new File(_manifestFilename); - if (f.exists()) { - if (_overwrite.booleanValue()) { - f.delete(); - } - else { - throw new BuildException("Will not overwrite existing file: "+_manifestFilename+". Use overwrite='yes' if you wish to overwrite the file."); - } - } - System.out.println("creating "+f); - - //jdk1.2 -- f.createNewFile(); - out = new PrintWriter(new FileOutputStream(f)); - - } - else { - throw new BuildException("Manifest task requires a 'file' attribute"); - } - } - catch (IOException ex) { - throw new BuildException(ex); - } - - // setup the implementation versionn (buildID) - if (_buildid == null || _buildid.trim().equals("")) { - _buildid = createBuildID(); - } - if (_createdby == null || _createdby.trim().equals("")) { - _createdby = getCreator(); - } - - print(out, MANIFEST_VERSION, _manifestVersion); - print(out, CREATED_BY, _createdby); - - print(out, SPECIFICATION_TITLE, _spectitle); - print(out, SPECIFICATION_VERSION, _specvers); - print(out, SPECIFICATION_VENDOR, _specvend); - print(out, IMPL_TITLE, _impltitle); - print(out, IMPL_VERSION, _implvers); - print(out, IMPL_VENDOR, _implvend); - print(out, BUILD_ID, _buildid); - print(out, MAIN_CLASS, _mainclass); - print(out, CLASS_PATH, _classpath); - - out.flush(); - out.close(); - - } - - protected void print(PrintWriter out, String header, String value) - { - if (value != null && !value.trim().equals("")) { - out.println(header+value); - // System.out.println("manifest: "+header+value); - } - } - - private static String createBuildID() - { - Date d = new Date(); - SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd-HHmmss-z"); - String date = f.format(d); - String hostname, username, os, version, arch; - try { - hostname = InetAddress.getLocalHost().getHostName(); - } - catch (Exception ex) { - hostname = "unknown"; - } - username = System.getProperty("user.name"); - os = System.getProperty("os.name"); - version = System.getProperty("os.version"); - arch = System.getProperty("os.arch"); - String buildid = date + " ("+username+"@"+hostname+" ["+os+" "+version+" "+arch+"])"; - return buildid; - - } - - private static String getCreator() - { - try { - Properties props = new Properties(); - InputStream in = org.apache.tools.ant.Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt"); - if (in != null) { - props.load(in); - in.close(); - - return "Ant "+props.getProperty("VERSION"); - } - else { - return null; - } - } - catch (IOException ex) { - return null; - } - } - + public void execute() throws BuildException { + // System.out.println("Executing manifest task"); + + PrintWriter out; + try { + if (_manifestFilename != null) { + // open the file for writing + File f = new File(_manifestFilename); + if (f.exists()) { + if (_overwrite.booleanValue()) { + f.delete(); + } else { + throw new BuildException("Will not overwrite existing file: " + + _manifestFilename + + ". Use overwrite='yes' if you wish to overwrite the file."); + } + } + System.out.println("creating " + f); + + // jdk1.2 -- f.createNewFile(); + out = new PrintWriter(new FileOutputStream(f)); + + } else { + throw new BuildException("Manifest task requires a 'file' attribute"); + } + } catch (IOException ex) { + throw new BuildException(ex); + } + + // setup the implementation versionn (buildID) + if (_buildid == null || _buildid.trim().equals("")) { + _buildid = createBuildID(); + } + if (_createdby == null || _createdby.trim().equals("")) { + _createdby = getCreator(); + } + + print(out, MANIFEST_VERSION, _manifestVersion); + print(out, CREATED_BY, _createdby); + + print(out, SPECIFICATION_TITLE, _spectitle); + print(out, SPECIFICATION_VERSION, _specvers); + print(out, SPECIFICATION_VENDOR, _specvend); + print(out, IMPL_TITLE, _impltitle); + print(out, IMPL_VERSION, _implvers); + print(out, IMPL_VENDOR, _implvend); + print(out, BUILD_ID, _buildid); + print(out, MAIN_CLASS, _mainclass); + print(out, CLASS_PATH, _classpath); + + out.flush(); + out.close(); + + } + + protected void print(PrintWriter out, String header, String value) { + if (value != null &&!value.trim().equals("")) { + out.println(header + value); + // System.out.println("manifest: "+header+value); + } + } + + private static String createBuildID() { + Date d = new Date(); + SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd-HHmmss-z"); + String date = f.format(d); + String hostname, username, os, version, arch; + try { + hostname = InetAddress.getLocalHost().getHostName(); + } catch (Exception ex) { + hostname = "unknown"; + } + username = System.getProperty("user.name"); + os = System.getProperty("os.name"); + version = System.getProperty("os.version"); + arch = System.getProperty("os.arch"); + String buildid = date + " (" + username + "@" + hostname + " [" + os + + " " + version + " " + arch + "])"; + return buildid; + + } + + private static String getCreator() { + try { + Properties props = new Properties(); + InputStream in = + org.apache.tools.ant.Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt"); + if (in != null) { + props.load(in); + in.close(); + + return "Ant " + props.getProperty("VERSION"); + } else { + return null; + } + } catch (IOException ex) { + return null; + } + } + } diff --git a/src/org/apache/fop/tools/anttasks/RunTest.java b/src/org/apache/fop/tools/anttasks/RunTest.java index 0cb25f627..53e58f89b 100644 --- a/src/org/apache/fop/tools/anttasks/RunTest.java +++ b/src/org/apache/fop/tools/anttasks/RunTest.java @@ -1,4 +1,5 @@ /* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -36,8 +37,7 @@ public class RunTest extends Task { String referenceJar = ""; String refVersion = ""; - public RunTest() { - } + public RunTest() {} public void setTestSuite(String str) { testsuite = str; @@ -73,18 +73,21 @@ public class RunTest extends Task { */ protected void testNewBuild() { try { - ClassLoader loader = new URLClassLoader(new URL[]{new URL("file:build/fop.jar")}); - Hashtable diff = runConverter(loader, "areatree", "reference/output/"); - if (diff != null && !diff.isEmpty()) { + ClassLoader loader = new URLClassLoader(new URL[] { + new URL("file:build/fop.jar") + }); + Hashtable diff = runConverter(loader, "areatree", + "reference/output/"); + if (diff != null &&!diff.isEmpty()) { System.out.println("===================================="); System.out.println("The following files differ:"); boolean broke = false; for (Enumeration keys = diff.keys(); - keys.hasMoreElements();) { + keys.hasMoreElements(); ) { Object fname = keys.nextElement(); - Boolean pass = (Boolean) diff.get(fname); - System.out.println("file: " + fname + - " - reference success: " + pass); + Boolean pass = (Boolean)diff.get(fname); + System.out.println("file: " + fname + + " - reference success: " + pass); if (pass.booleanValue()) { broke = true; } @@ -108,13 +111,14 @@ public class RunTest extends Task { protected void runReference() throws BuildException { // check not already done File f = new File(basedir + "/reference/output/"); - //if(f.exists()) { + // if(f.exists()) { // need to check that files have actually been created. - //return; - //} else { + // return; + // } else { try { - ClassLoader loader = new URLClassLoader( - new URL[]{new URL("file:" + referenceJar)}); + ClassLoader loader = new URLClassLoader(new URL[] { + new URL("file:" + referenceJar) + }); boolean failed = false; try { @@ -125,39 +129,32 @@ public class RunTest extends Task { loader); Method get = cla.getMethod("getVersion", new Class[]{}); if (!get.invoke(null, new Object[]{}).equals(refVersion)) { - throw new BuildException( - "Reference jar is not correct version it must be: " + - refVersion); + throw new BuildException("Reference jar is not correct version it must be: " + + refVersion); } } catch (IllegalAccessException iae) { failed = true; - } - catch (IllegalArgumentException are) { + } catch (IllegalArgumentException are) { failed = true; - } - catch (InvocationTargetException are) { + } catch (InvocationTargetException are) { failed = true; - } - catch (ClassNotFoundException are) { + } catch (ClassNotFoundException are) { failed = true; - } - catch (InstantiationException are) { + } catch (InstantiationException are) { failed = true; - } - catch (NoSuchMethodException are) { + } catch (NoSuchMethodException are) { failed = true; } if (failed) { - throw new BuildException( - "Reference jar could not be found in: " + - basedir + "/reference/"); + throw new BuildException("Reference jar could not be found in: " + + basedir + "/reference/"); } f.mkdirs(); runConverter(loader, "reference/output/", null); } catch (MalformedURLException mue) { mue.printStackTrace(); } - //} + // } } /** @@ -178,16 +175,23 @@ public class RunTest extends Task { Object tc = cla.newInstance(); Method meth; - meth = cla.getMethod("setBaseDir", new Class[]{String.class}); - meth.invoke(tc, new Object[]{basedir}); - - meth = cla.getMethod("runTests", new Class[]{String.class, - String.class, String.class}); - diff = (Hashtable) meth.invoke(tc, new Object[]{testsuite, - dest, compDir}); + meth = cla.getMethod("setBaseDir", new Class[] { + String.class + }); + meth.invoke(tc, new Object[] { + basedir + }); + + meth = cla.getMethod("runTests", new Class[] { + String.class, String.class, String.class + }); + diff = (Hashtable)meth.invoke(tc, new Object[] { + testsuite, dest, compDir + }); } catch (Exception e) { e.printStackTrace(); } return diff; } + } diff --git a/src/org/apache/fop/tools/anttasks/SerializeHyphPattern.java b/src/org/apache/fop/tools/anttasks/SerializeHyphPattern.java index e3477d325..db205d9b0 100644 --- a/src/org/apache/fop/tools/anttasks/SerializeHyphPattern.java +++ b/src/org/apache/fop/tools/anttasks/SerializeHyphPattern.java @@ -1,59 +1,13 @@ /* - * 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 - * <http://www.apache.org/>. + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.tools.anttasks; -//package org.apache.tools.ant.taskdefs; +// package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.taskdefs.MatchingTask; import org.apache.tools.ant.DirectoryScanner; @@ -62,12 +16,12 @@ import java.io.*; import java.util.*; import org.xml.sax.SAXException; -//fop +// fop import org.apache.fop.layout.hyphenation.HyphenationTree; import org.apache.fop.layout.hyphenation.HyphenationException; /** - * SerializeHyphPattern + * SerializeHyphPattern */ @@ -76,56 +30,56 @@ public class SerializeHyphPattern extends MatchingTask { private boolean errorDump = false; /** - * Main method, which is called by ant. - */ - public void execute () throws org.apache.tools.ant.BuildException { + * Main method, which is called by ant. + */ + public void execute() throws org.apache.tools.ant.BuildException { DirectoryScanner ds = this.getDirectoryScanner(sourceDir); String[] files = ds.getIncludedFiles(); - for (int i = 0; i < files.length ; i++) { + for (int i = 0; i < files.length; i++) { processFile(files[i].substring(0, files[i].length() - 4)); } - } //end execute + } // end execute /** - * Sets the source directory - * - */ - public void setSourceDir (String sourceDir) { + * Sets the source directory + * + */ + public void setSourceDir(String sourceDir) { File dir = new File(sourceDir); if (!dir.exists()) { - System.err.println("Fatal Error: source directory " + - sourceDir + " for hyphenation files doesn't exist."); + System.err.println("Fatal Error: source directory " + sourceDir + + " for hyphenation files doesn't exist."); System.exit(1); } this.sourceDir = dir; } /** - * Sets the target directory - * - */ - public void setTargetDir (String targetDir) { + * Sets the target directory + * + */ + public void setTargetDir(String targetDir) { File dir = new File(targetDir); this.targetDir = dir; } /** - * more error information - * - */ - public void setErrorDump (boolean errorDump) { + * more error information + * + */ + public void setErrorDump(boolean errorDump) { this.errorDump = errorDump; } /* - * checks whether input or output files exists or the latter is older than input file - * and start build if necessary - */ - private void processFile (String filename) { - File infile = new File (sourceDir , filename + ".xml"); - File outfile = new File(targetDir , filename + ".hyp"); + * checks whether input or output files exists or the latter is older than input file + * and start build if necessary + */ + private void processFile(String filename) { + File infile = new File(sourceDir, filename + ".xml"); + File outfile = new File(targetDir, filename + ".hyp"); long outfileLastModified = outfile.lastModified(); boolean startProcess = true; @@ -136,9 +90,9 @@ public class SerializeHyphPattern extends MatchingTask { } /* - * serializes pattern files - */ - private void buildPatternFile (File infile, File outfile) { + * serializes pattern files + */ + private void buildPatternFile(File infile, File outfile) { System.out.println("Processing " + infile); HyphenationTree hTree = new HyphenationTree(); try { @@ -148,52 +102,52 @@ public class SerializeHyphPattern extends MatchingTask { hTree.printStats(); } } catch (HyphenationException ex) { - System.err.println("Can't load patterns from xml file " + - infile + " - Maybe hyphenation.dtd is missing?"); + System.err.println("Can't load patterns from xml file " + infile + + " - Maybe hyphenation.dtd is missing?"); if (errorDump) { System.err.println(ex.toString()); } } - //serialize class + // serialize class try { - ObjectOutputStream out = new ObjectOutputStream ( - new FileOutputStream(outfile)); + ObjectOutputStream out = + new ObjectOutputStream(new FileOutputStream(outfile)); out.writeObject(hTree); out.close(); } catch (IOException ioe) { - System.err.println("Can't write compiled pattern file: " + - outfile); + System.err.println("Can't write compiled pattern file: " + + outfile); System.err.println(ioe); } } /** - * Checks for existence of output file and compares - * dates with input and stylesheet file - */ - private boolean rebuild (File infile, File outfile) { + * Checks for existence of output file and compares + * dates with input and stylesheet file + */ + private boolean rebuild(File infile, File outfile) { if (outfile.exists()) { - //checks whether output file is older than input file + // checks whether output file is older than input file if (outfile.lastModified() < infile.lastModified()) { return true; } } else { - //if output file does not exist, start process + // if output file does not exist, start process return true; } return false; - } //end rebuild + } // end rebuild -/* - //quick access for debugging - public static void main (String args[]) { - SerializeHyphPattern ser = new SerializeHyphPattern(); - ser.setIncludes("*.xml"); - ser.setSourceDir("\\xml-fop\\hyph\\"); - ser.setTargetDir("\\xml-fop\\hyph\\"); - ser.execute(); - } -*/ + /* + * //quick access for debugging + * public static void main (String args[]) { + * SerializeHyphPattern ser = new SerializeHyphPattern(); + * ser.setIncludes("*.xml"); + * ser.setSourceDir("\\xml-fop\\hyph\\"); + * ser.setTargetDir("\\xml-fop\\hyph\\"); + * ser.execute(); + * } + */ } diff --git a/src/org/apache/fop/tools/anttasks/Xslt.java b/src/org/apache/fop/tools/anttasks/Xslt.java index c38fd6961..1bc56492a 100644 --- a/src/org/apache/fop/tools/anttasks/Xslt.java +++ b/src/org/apache/fop/tools/anttasks/Xslt.java @@ -1,55 +1,8 @@ /* - * 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 - * <http://www.apache.org/>. + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.tools.anttasks; @@ -97,68 +50,70 @@ import org.xml.sax.SAXException; public class Xslt extends Task { private String infile, outfile, xsltfile, mergefile; - private String smart = "no"; //defaults to do conversion everytime task is called - private String dependent = "none"; //defaults to no dependencies + private String smart = + "no"; // defaults to do conversion everytime task is called + private String dependent = "none"; // defaults to no dependencies private boolean startXslt = false; - /** When true, we use the trax api's from xalan2, otherwise + /** + * When true, we use the trax api's from xalan2, otherwise * just the xalan1 native interfaces */ private boolean useTrax = false; - + /** * Sets the input file * */ - public void setInfile (String infile) { + public void setInfile(String infile) { this.infile = infile; } - public void setMergefile (String mergefile) { + public void setMergefile(String mergefile) { this.mergefile = mergefile; } /** - * Sets the stylesheet file - * - */ - public void setXsltfile (String xsltfile) { + * Sets the stylesheet file + * + */ + public void setXsltfile(String xsltfile) { this.xsltfile = xsltfile; } /** - * Sets the output file - * - */ - public void setOutfile (String outfile) { + * Sets the output file + * + */ + public void setOutfile(String outfile) { this.outfile = outfile; } /** - * Sets the value for smart - * - * @param option valid values: - * <ul> - * <li>yes: check whether output file is older than input or stylesheet - * <li>no: (default) do conversion everytime task is called - * </ul> - */ - public void setSmart (String smart) { + * Sets the value for smart + * + * @param option valid values: + * <ul> + * <li>yes: check whether output file is older than input or stylesheet + * <li>no: (default) do conversion everytime task is called + * </ul> + */ + public void setSmart(String smart) { this.smart = smart; } /** - * Sets the value for dependent - * - * @param option valid values: - * <ul> - * <li>none: (default) - * <li>comma delimited list of files whose existence and date is checked - * against the output file - * </ul> - */ - public void setDependent (String dependent) { + * Sets the value for dependent + * + * @param option valid values: + * <ul> + * <li>none: (default) + * <li>comma delimited list of files whose existence and date is checked + * against the output file + * </ul> + */ + public void setDependent(String dependent) { this.dependent = dependent; } @@ -167,90 +122,86 @@ public class Xslt extends Task { * Builds a document from the given file, merging the mergefile onto the end of the root node */ private org.w3c.dom.Document buildDocument(String xmlFile) - throws IOException, SAXException { + throws IOException, SAXException { try { javax.xml.parsers.DocumentBuilder docBuilder = - javax.xml.parsers.DocumentBuilderFactory.newInstance(). - newDocumentBuilder(); + javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = docBuilder.parse(new FileInputStream(xmlFile)); - if (mergefile != null && !mergefile.equals("")) { + if (mergefile != null &&!mergefile.equals("")) { File mergefileF = new File(mergefile); Document mergedoc = - docBuilder.parse(new FileInputStream(mergefileF)); - Node mergenode = - doc.importNode(mergedoc.getDocumentElement(), true); + docBuilder.parse(new FileInputStream(mergefileF)); + Node mergenode = doc.importNode(mergedoc.getDocumentElement(), + true); doc.getDocumentElement().appendChild(mergenode); } return doc; } catch (javax.xml.parsers.ParserConfigurationException e) { - System.out.println("Task xslt - SAX ERROR:\n " + - e.getMessage()); + System.out.println("Task xslt - SAX ERROR:\n " + + e.getMessage()); } return null; } /** - * Calls Xalan and does the transformation - * - */ - private void transform() { - try { - org.w3c.dom.Document source = buildDocument(infile); - // Perform the transformation. - System.out.println("============================"); - System.out.println("xslt \nin: " + infile + "\nstyle: " + - xsltfile + "\nout: " + outfile); - System.out.println("============================"); - org.apache.fop.tools.xslt.XSLTransform.transform(source,xsltfile,outfile); - - - } catch (org.xml.sax.SAXException saxerror) { + * Calls Xalan and does the transformation + * + */ + private void transform() { + try { + org.w3c.dom.Document source = buildDocument(infile); + // Perform the transformation. + System.out.println("============================"); + System.out.println("xslt \nin: " + infile + "\nstyle: " + + xsltfile + "\nout: " + outfile); + System.out.println("============================"); + org.apache.fop.tools.xslt.XSLTransform.transform(source, + xsltfile, outfile); + + + } catch (org.xml.sax.SAXException saxerror) { System.out.println("Task xslt - SAX ERROR:\n " + saxerror); - } - catch (MalformedURLException urlerror) { + } catch (MalformedURLException urlerror) { System.out.println("Task xslt - URL ERROR:\n " + urlerror); - } - catch (IOException ioerror) { + } catch (IOException ioerror) { System.out.println("Task xslt - IO ERROR:\n " + ioerror); + } catch (Exception ex) { + ex.printStackTrace(); } - - catch (Exception ex) { - ex.printStackTrace(); - } - - } //end transform - - + + } // end transform + + /** - * Checks for existence of output file and compares - * dates with input and stylesheet file + * Checks for existence of output file and compares + * dates with input and stylesheet file */ - private boolean smartCheck (File outfileF, - long outfileLastModified, File infileF, File xsltfileF) { + private boolean smartCheck(File outfileF, long outfileLastModified, + File infileF, File xsltfileF) { if (outfileF.exists()) { - //checks whether output file is older than input file or xslt stylesheet file - if ((outfileLastModified < infileF.lastModified()) | - (outfileLastModified < xsltfileF.lastModified())) { + // checks whether output file is older than input file or xslt stylesheet file + if ((outfileLastModified < infileF.lastModified()) + | (outfileLastModified < xsltfileF.lastModified())) { return true; } } else { - //if output file does not exist, start xslt process + // if output file does not exist, start xslt process return true; } return false; - } //end smartCheck + } // end smartCheck /** - * Checks for existence and date of dependent files - * This could be folded together with smartCheck by using - * a general routine but it wouldn't be as fast as now + * Checks for existence and date of dependent files + * This could be folded together with smartCheck by using + * a general routine but it wouldn't be as fast as now */ private boolean dependenciesCheck(File outfileF, long outfileLastModified) { @@ -258,82 +209,79 @@ public class Xslt extends Task { File dependentFile; StringTokenizer tokens = new StringTokenizer(dependent, ","); while (tokens.hasMoreTokens()) { - dependentFileName = (String) tokens.nextToken(); - dependentFile = new File (dependentFileName); - //check: does dependent file exist + dependentFileName = (String)tokens.nextToken(); + dependentFile = new File(dependentFileName); + // check: does dependent file exist if (dependentFile.exists()) { - //check dates + // check dates if ((outfileLastModified < dependentFile.lastModified())) { return true; } } else { - System.err.println( - "Task xslt - ERROR in attribute 'dependent':\n file " + - dependentFileName + " does not exist."); + System.err.println("Task xslt - ERROR in attribute 'dependent':\n file " + + dependentFileName + " does not exist."); } } return false; - } //end dependenciesCheck + } // end dependenciesCheck /** - * Main method, which is called by ant. - * Checks for the value of smart and calls startTransform accordingly + * Main method, which is called by ant. + * Checks for the value of smart and calls startTransform accordingly */ - public void execute () throws org.apache.tools.ant.BuildException { + public void execute() throws org.apache.tools.ant.BuildException { - File outfileF = new File (outfile); + File outfileF = new File(outfile); File infileF = new File(infile); - File xsltfileF = new File (xsltfile); + File xsltfileF = new File(xsltfile); long outfileLastModified = outfileF.lastModified(); boolean startFileExist = true; - //checks whether input and stylesheet exist. - //this could be left to the parser, but this solution does make problems if smart is set to yes + // checks whether input and stylesheet exist. + // this could be left to the parser, but this solution does make problems if smart is set to yes if (!infileF.exists()) { - System.err.println( - "Task xslt - ERROR:\n Input file " + infile + - " does not exist!"); + System.err.println("Task xslt - ERROR:\n Input file " + + infile + " does not exist!"); startFileExist = false; } else if (!xsltfileF.exists()) { - System.err.println( - "Task xslt - ERROR:\n Stylesheet file " + - xsltfile + " does not exist!"); + System.err.println("Task xslt - ERROR:\n Stylesheet file " + + xsltfile + " does not exist!"); startFileExist = false; } - //checks attribute 'smart' + // checks attribute 'smart' if (smart.equals("no")) { startXslt = true; - //if attribute smart = 'yes' + // if attribute smart = 'yes' } else if (smart.equals("yes")) { - startXslt = smartCheck (outfileF, outfileLastModified, - infileF, xsltfileF); - //checks dependent files against output file, makes only sense if smartCheck returns false + startXslt = smartCheck(outfileF, outfileLastModified, infileF, + xsltfileF); + // checks dependent files against output file, makes only sense if smartCheck returns false if (!dependent.equals("none") & (startXslt == false)) { - startXslt = - dependenciesCheck(outfileF, outfileLastModified); + startXslt = dependenciesCheck(outfileF, outfileLastModified); } - //returns error message, if smart has another value as 'yes' or 'no' + // returns error message, if smart has another value as 'yes' or 'no' } else { System.err.println("Task xslt - ERROR: Allowed values for the attribute smart are 'yes' or 'no'"); } if (startFileExist & startXslt) { transform(); } - } //end execute + } // end execute - //quick access for debugging - //usage XSLT infile xsltfile outfile (smart is 'yes') + // quick access for debugging + // usage XSLT infile xsltfile outfile (smart is 'yes') /* - public static void main (String args[]) { - Xslt xslt = new Xslt(); - xslt.setInfile(args[0]); - xslt.setXsltfile(args[1]); - xslt.setOutfile(args[2]); - xslt.setSmart("yes"); - xslt.setDependent("test1,test2"); - xslt.execute(); -} */ + * public static void main (String args[]) { + * Xslt xslt = new Xslt(); + * xslt.setInfile(args[0]); + * xslt.setXsltfile(args[1]); + * xslt.setOutfile(args[2]); + * xslt.setSmart("yes"); + * xslt.setDependent("test1,test2"); + * xslt.execute(); + * } + */ |