Explorar el Código

extensions to Ant


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193459 13f79535-47bb-0310-9956-ffa450edef68
tags/pre-columns
fotis hace 24 años
padre
commit
613b24a8e2
Se han modificado 3 ficheros con 315 adiciones y 4 borrados
  1. BIN
      lib/CollectDocFiles.class
  2. 259
    0
      lib/CollectDocFiles.java
  3. 56
    4
      lib/Compare.java

BIN
lib/CollectDocFiles.class Ver fichero


+ 259
- 0
lib/CollectDocFiles.java Ver fichero

@@ -0,0 +1,259 @@
/*
* 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/>.
*
*
*/

/** 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. The outputFile determines the target file.
*/
// 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 CollectDocFiles 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
* creates a sax parser and parses configuration file
*/
public void execute () throws BuildException {
boolean errors = false;

if (!(new File(configFile).exists())) {
errors = true;
System.err.println("Task CollectDocFiles - ERROR: config file " + configFile + " is missing.");
}
Parser parser = createParser();
if (parser == null) {
System.err.println("Task CollectDocFiles - ERROR: Unable to create SAX parser");
errors = true;
}
parser.setDocumentHandler(this);
try {
parser.parse(CollectDocFiles.fileInputSource(configFile));
} catch (SAXException e) {
System.out.println(e);
} catch (IOException ioe) {
System.out.println(ioe);
}
} //end: execute()
/** 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
*/
private void collectFiles () {
String line, filename;
BufferedReader in;
Iterator iterator = files.iterator();
try {
BufferedWriter out =
new BufferedWriter (new FileWriter("fop-doc.xml"));
//write new xml header including an Entity for nbsp
out.write("<?xml version=\"1.0\"?>\n" +
"<!DOCTYPE documentation [\n" +
"<!ENTITY nbsp \"-\">\n" +
"]>\n<documentation>");
//for each file read content and write it to output file
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("<!DOCTYPE ")!= -1 || line.indexOf("<?xml ")!= -1 ) {
line = "";
}
out.write(line+"\n");
}
out.flush();
}
out.write("\n</documentation>");
out.close();
} catch (IOException e) {
System.out.println(e);
}
}
/*the following methods belong to the sax parser and implement the Document Handler*/
/** extract file names from attr source in elements document and entry
*/
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);
}
}
/** calls method to collect all files
*/
public void endDocument () throws SAXException {
this.collectFiles();
}
/* the folling methods have to be implemented for the sax parser */
public InputSource resolveEntity (String publicId, String systemId) throws SAXException {
return null;
}
public void notationDecl (String name, String publicId, String systemId) {}
public void unparsedEntityDecl (String name, String publicId,String systemId, String notationName) {}
public void setDocumentLocator (Locator locator) {}
public void startDocument () throws SAXException {}
public void endElement (String name) throws SAXException {}
public void characters (char ch[], int start, int length) throws SAXException {}
public void ignorableWhitespace (char ch[], int start, int length) throws SAXException {}
public void processingInstruction (String target, String data) throws SAXException {}
public void warning (SAXParseException e) throws SAXException {}
public void error (SAXParseException e) throws SAXException {}
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");
}
}
}


+ 56
- 4
lib/Compare.java Ver fichero

@@ -1,8 +1,56 @@
/*
// header - edit "Data/yourJavaHeader" to customize
// contents - edit "EventHandlers/Java file/onCreate" to customize
//
*/
* 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/>.
*/

import java.util.*;
import java.io.*;
@@ -10,6 +58,10 @@ 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
*/

public class Compare {
private String referenceDirectory, testDirectory;

Cargando…
Cancelar
Guardar