[FOray-commit] SF.net SVN: foray: [7795] trunk/foray/foray-core/src/java/org/foray/core
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2006-07-18 16:26:31
|
Revision: 7795 Author: victormote Date: 2006-07-18 09:26:21 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7795&view=rev Log Message: ----------- Remove no-longer-needed class. Modified Paths: -------------- trunk/foray/foray-app/src/java/org/foray/app/test/TestConverter.java Removed Paths: ------------- trunk/foray/foray-core/src/java/org/foray/core/TraxInputHandler.java Modified: trunk/foray/foray-app/src/java/org/foray/app/test/TestConverter.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/test/TestConverter.java 2006-07-18 16:22:37 UTC (rev 7794) +++ trunk/foray/foray-app/src/java/org/foray/app/test/TestConverter.java 2006-07-18 16:26:21 UTC (rev 7795) @@ -35,7 +35,6 @@ import org.foray.core.FOrayTarget; import org.foray.core.InputHandler; import org.foray.core.SessionConfig; -import org.foray.core.TraxInputHandler; import org.foray.output.OutputConfig; import org.axsl.output.OutputTarget; @@ -263,22 +262,23 @@ log.error("Error setting base directory"); } - InputHandler inputHandler = null; + FOraySession session = FOraySpecific.makeFOraySession( + configuration); + + FOrayDocument document = null; if (xsl == null) { + InputHandler inputHandler = null; inputHandler = new FOInputHandler(log, xmlFile); + XMLReader parser = inputHandler.getParser(); + setParserFeatures(parser); + document = new FOrayDocument(session, + inputHandler.getInputSource(), parser); } else { - inputHandler = new TraxInputHandler(log, xmlFile.toURL(), + document = new FOrayDocument(session, xmlFile.toURL(), URLFactory.createURL(baseDir + "/" + xsl)); } - FOraySession session = FOraySpecific.makeFOraySession( - configuration); - XMLReader parser = inputHandler.getParser(); - setParserFeatures(parser); - FOrayDocument document = new FOrayDocument(session, - inputHandler.getInputSource(), parser); - String outname = xmlFile.getName(); if (outname.endsWith(".xml")) { outname = outname.substring(0, outname.length() - 4); Deleted: trunk/foray/foray-core/src/java/org/foray/core/TraxInputHandler.java =================================================================== --- trunk/foray/foray-core/src/java/org/foray/core/TraxInputHandler.java 2006-07-18 16:22:37 UTC (rev 7794) +++ trunk/foray/foray-core/src/java/org/foray/core/TraxInputHandler.java 2006-07-18 16:26:21 UTC (rev 7795) @@ -1,184 +0,0 @@ -/* - * Copyright 2004 The FOray Project. - * http://www.foray.org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This work is in part derived from the following work(s), used with the - * permission of the licensor: - * Apache FOP, licensed by the Apache Software Foundation - * - */ - -/* $Id$ */ - -package org.foray.core; - - - - -import org.apache.commons.logging.Log; - -import org.xml.sax.InputSource; -import org.xml.sax.XMLFilter; -import org.xml.sax.XMLReader; - -import java.io.File; -import java.io.IOException; -import java.net.URL; - -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.sax.SAXResult; -import javax.xml.transform.sax.SAXSource; -import javax.xml.transform.sax.SAXTransformerFactory; -import javax.xml.transform.stream.StreamSource; - -/** - * XSLTInputHandler basically takes an xml source and transforms it with - * an xslt source and the resulting xsl:fo document is input for FOray. - */ -public class TraxInputHandler extends InputHandler { - private Transformer transformer; - private StreamSource xmlSource; - private Source xsltSource; - - public TraxInputHandler(Log logger, URL xmlfile, URL xsltfile) - throws FOrayException { - super(logger); - try { - xmlSource = new StreamSource(xmlfile.openStream()); - xsltSource = new StreamSource(xsltfile.openStream()); - } catch (IOException e) { - throw new FOrayException(e); - } - initTransformer(); - } - - public TraxInputHandler(Log logger, String xmlURL, String xsltURL) - throws FOrayException { - super(logger); - this.xmlSource = new StreamSource(xmlURL); - this.xsltSource = new StreamSource(xsltURL); - initTransformer(); - } - - public TraxInputHandler(Log logger, InputSource xmlSource, - InputSource xsltSource) throws FOrayException { - super(logger); - this.xmlSource = new StreamSource(xmlSource.getByteStream(), - xmlSource.getSystemId()); - this.xsltSource = new StreamSource(xsltSource.getByteStream(), - xsltSource.getSystemId()); - initTransformer(); - } - - private void initTransformer() throws FOrayException { - try { - transformer = TransformerFactory.newInstance().newTransformer( - xsltSource); - } - catch(Exception ex) { - throw new FOrayException(ex); - } - } - - /** - * Overwrites the method of the super class to return the xmlfile. - * Use run(Driver driver) instead. - * @deprecated - */ - public InputSource getInputSource() { - InputSource is = new InputSource(); - is.setByteStream(xmlSource.getInputStream()); - is.setSystemId(xmlSource.getSystemId()); - return is; - } - - /** - * Overwrites this method of the super class and returns an - * XMLFilter instead of a simple XMLReader which allows chaining - * of transformations. - * Use run(Driver driver) instead. - * @deprecated - * - */ - public XMLReader getParser() throws FOrayException { - return getXMLFilter(xsltSource); - } - - /** - * Creates from the transformer an instance of an XMLFilter which - * then can be used in a chain with the XMLReader passed to Driver. This way - * during the conversion of the xml file + xslt stylesheet the resulting - * data is fed into FOary. This should help to avoid memory problems - * @param xsltSource An xslt stylesheet. - * @return An XMLFilter which can be chained together with other XMLReaders - * or XMLFilters. - */ - private XMLFilter getXMLFilter(Source xsltSource) - throws FOrayException { - try { - // Instantiate a TransformerFactory. - TransformerFactory tFactory = TransformerFactory.newInstance(); - // Determine whether the TransformerFactory supports the - // use of SAXSource and SAXResult - if (tFactory.getFeature(SAXSource.FEATURE) - && tFactory.getFeature(SAXResult.FEATURE)) { - // Cast the TransformerFactory to SAXTransformerFactory. - SAXTransformerFactory saxTFactory = - ((SAXTransformerFactory)tFactory); - // Create an XMLFilter for each stylesheet. - XMLFilter xmlfilter = - saxTFactory.newXMLFilter(xsltSource); - - // Create an XMLReader. - XMLReader parser = createParser(); - if (parser == null) { - throw new FOrayException("Unable to create SAX parser"); - } - - // xmlFilter uses the XMLReader as its reader. - xmlfilter.setParent(parser); - return xmlfilter; - } - throw new FOrayException("Your parser doesn't support the " - + "features SAXSource and SAXResult.\n" - + "Use an XSL parser which supports TrAX"); - } catch (Exception ex) { - throw new FOrayException(ex); - } - } - - - /** - * Creates from the transformer an instance of an XMLFilter which - * then can be used in a chain with the XMLReader passed to Driver. This way - * during the conversion of the xml file + xslt stylesheet the resulting - * data is fed into FOray. This should help to avoid memory problems - * @param xmlfile The xmlfile containing the text data - * @param xsltfile An xslt stylesheet - * @return XMLFilter an XMLFilter which can be chained together with other - * XMLReaders or XMLFilters - */ - public XMLFilter getXMLFilter(File xmlfile, File xsltfile) - throws FOrayException { - return getXMLFilter(new StreamSource(xsltfile)); - } - - public void setParameter(String name, Object value) { - transformer.setParameter(name, value); - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |