You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2007/12/28 16:11:57 UTC
svn commit: r607261 - in
/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli:
AreaTreeInputHandler.java CommandLineOptions.java ImageInputHandler.java
InputHandler.java image2fo.xsl
Author: jeremias
Date: Fri Dec 28 07:11:56 2007
New Revision: 607261
URL: http://svn.apache.org/viewvc?rev=607261&view=rev
Log:
Added -imagein to command-line so (multi-page) images such as TIFF files can be converted to PDF and other formats supported by FOP. The default stylesheet can be overwritten (with -xslt) if desired.
Added:
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/ImageInputHandler.java (with props)
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/image2fo.xsl (with props)
Modified:
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/AreaTreeInputHandler.java (props changed)
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/CommandLineOptions.java
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/InputHandler.java
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/AreaTreeInputHandler.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/CommandLineOptions.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/CommandLineOptions.java?rev=607261&r1=607260&r2=607261&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/CommandLineOptions.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/CommandLineOptions.java Fri Dec 28 07:11:56 2007
@@ -29,6 +29,11 @@
import javax.swing.UIManager;
+import org.xml.sax.SAXException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import org.apache.fop.Version;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
@@ -38,19 +43,12 @@
import org.apache.fop.pdf.PDFEncryptionManager;
import org.apache.fop.pdf.PDFEncryptionParams;
import org.apache.fop.pdf.PDFXMode;
-import org.apache.fop.render.awt.AWTRenderer;
import org.apache.fop.render.Renderer;
+import org.apache.fop.render.awt.AWTRenderer;
import org.apache.fop.render.pdf.PDFRenderer;
import org.apache.fop.render.xml.XMLRenderer;
import org.apache.fop.util.CommandLineLogger;
-// commons logging
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-// SAX
-import org.xml.sax.SAXException;
-
/**
* Options parses the commandline arguments
*/
@@ -71,6 +69,8 @@
public static final int XSLT_INPUT = 2;
/** input: Area Tree XML file */
public static final int AREATREE_INPUT = 3;
+ /** input: Image file */
+ public static final int IMAGE_INPUT = 4;
/* show configuration information */
private Boolean showConfiguration = Boolean.FALSE;
@@ -86,6 +86,8 @@
private File xmlfile = null;
/* area tree input file */
private File areatreefile = null;
+ /* area tree input file */
+ private File imagefile = null;
/* output file */
private File outfile = null;
/* input mode */
@@ -249,6 +251,8 @@
i = i + parseXMLInputOption(args, i);
} else if (args[i].equals("-atin")) {
i = i + parseAreaTreeInputOption(args, i);
+ } else if (args[i].equals("-imagein")) {
+ i = i + parseImageInputOption(args, i);
} else if (args[i].equals("-awt")) {
i = i + parseAWTOutputOption(args, i);
} else if (args[i].equals("-pdf")) {
@@ -594,6 +598,17 @@
}
}
+ private int parseImageInputOption(String[] args, int i) throws FOPException {
+ inputmode = IMAGE_INPUT;
+ if ((i + 1 == args.length)
+ || (args[i + 1].charAt(0) == '-')) {
+ throw new FOPException("you must specify the image file for the '-imagein' option");
+ } else {
+ imagefile = new File(args[i + 1]);
+ return 1;
+ }
+ }
+
private PDFEncryptionParams getPDFEncryptionParams() throws FOPException {
PDFEncryptionParams params = (PDFEncryptionParams)renderingOptions.get(
PDFRenderer.ENCRYPTION_PARAMS);
@@ -768,6 +783,20 @@
+ areatreefile.getAbsolutePath()
+ " not found ");
}
+ } else if (inputmode == IMAGE_INPUT) {
+ if (outputmode.equals(MimeConstants.MIME_XSL_FO)) {
+ throw new FOPException(
+ "FO output mode is only available if you use -xml and -xsl");
+ }
+ if (xmlfile != null) {
+ log.warn("area tree input mode, but XML file is set:");
+ log.error("XML file: " + xmlfile.toString());
+ }
+ if (!imagefile.exists()) {
+ throw new FileNotFoundException("Error: image file "
+ + areatreefile.getAbsolutePath()
+ + " not found ");
+ }
}
} // end checkSettings
@@ -814,6 +843,8 @@
return new AreaTreeInputHandler(areatreefile);
case XSLT_INPUT:
return new InputHandler(xmlfile, xsltfile, xsltParams);
+ case IMAGE_INPUT:
+ return new ImageInputHandler(imagefile, xsltfile, xsltParams);
default:
throw new IllegalArgumentException("Error creating InputHandler object.");
}
@@ -920,6 +951,7 @@
+ " -fo infile xsl:fo input file \n"
+ " -xml infile xml input file, must be used together with -xsl \n"
+ " -atin infile area tree input file \n"
+ + " -imagein infile image input file \n"
+ " -xsl stylesheet xslt stylesheet \n \n"
+ " -param name value <value> to use for parameter <name> in xslt stylesheet\n"
+ " (repeat '-param name value' for each parameter)\n \n"
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/ImageInputHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/ImageInputHandler.java?rev=607261&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/ImageInputHandler.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/ImageInputHandler.java Fri Dec 28 07:11:56 2007
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.cli;
+
+import java.io.File;
+import java.io.StringReader;
+import java.util.Vector;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+/**
+ * InputHandler for the images (for example TIFF) as input.
+ */
+public class ImageInputHandler extends InputHandler {
+
+ /**
+ * Main constructor.
+ * @param imagefile the image file
+ * @param xsltfile XSLT file (may be null in which case the default stylesheet is used)
+ * @param params Vector of command-line parameters (name, value,
+ * name, value, ...) for XSL stylesheet, null if none
+ */
+ public ImageInputHandler(File imagefile, File xsltfile, Vector params) {
+ super(imagefile, xsltfile, params);
+ }
+
+ /** {@inheritDoc} */
+ protected Source createMainSource() {
+ return new StreamSource(new StringReader(
+ "<image>" + this.sourcefile.toURI().toASCIIString() + "</image>"));
+ }
+
+ /** {@inheritDoc} */
+ protected Source createXSLTSource() {
+ Source src = super.createXSLTSource();
+ if (src == null) {
+ src = new StreamSource(getClass().getResource("image2fo.xsl").toExternalForm());
+ }
+ return src;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/ImageInputHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/ImageInputHandler.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/InputHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/InputHandler.java?rev=607261&r1=607260&r2=607261&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/InputHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/InputHandler.java Fri Dec 28 07:11:56 2007
@@ -24,7 +24,6 @@
import java.io.OutputStream;
import java.util.Vector;
-// Imported TraX classes
import javax.xml.transform.ErrorListener;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
@@ -37,6 +36,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
@@ -50,7 +50,8 @@
*/
public class InputHandler implements ErrorListener, Renderable {
- private File sourcefile = null; // either FO or XML/XSLT usage
+ /** original source file */
+ protected File sourcefile = null;
private File stylesheet = null; // for XML/XSLT usage
private Vector xsltParams = null; // for XML/XSLT usage
@@ -132,6 +133,26 @@
}
/**
+ * Creates a Source for the main input file.
+ * @return the Source for the main input file
+ */
+ protected Source createMainSource() {
+ return new StreamSource(this.sourcefile);
+ }
+
+ /**
+ * Creates a Source for the selected stylesheet.
+ * @return the Source for the selected stylesheet or null if there's no stylesheet
+ */
+ protected Source createXSLTSource() {
+ if (this.stylesheet != null) {
+ return new StreamSource(this.stylesheet);
+ } else {
+ return null;
+ }
+ }
+
+ /**
* Transforms the input document to the input format expected by FOP using XSLT.
* @param result the Result object where the result of the XSL transformation is sent to
* @throws FOPException in case of an error during processing
@@ -142,11 +163,11 @@
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer;
- if (stylesheet == null) { // FO Input
+ Source xsltSource = createXSLTSource();
+ if (xsltSource == null) { // FO Input
transformer = factory.newTransformer();
} else { // XML/XSLT input
- transformer = factory.newTransformer(new StreamSource(
- stylesheet));
+ transformer = factory.newTransformer(xsltSource);
// Set the value of parameters, if any, defined for stylesheet
if (xsltParams != null) {
@@ -159,7 +180,7 @@
transformer.setErrorListener(this);
// Create a SAXSource from the input Source file
- Source src = new StreamSource(sourcefile);
+ Source src = createMainSource();
// Start XSLT transformation and FOP processing
transformer.transform(src, result);
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/image2fo.xsl
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/image2fo.xsl?rev=607261&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/image2fo.xsl (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/image2fo.xsl Fri Dec 28 07:11:56 2007
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<!-- $Id$ -->
+<xsl:stylesheet
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:fo="http://www.w3.org/1999/XSL/Format"
+ xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
+ version="1.0">
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template name="masters">
+ <fo:layout-master-set>
+ <!-- not really used but mandatory -->
+ <fo:simple-page-master master-name="dummy" page-height="29.7cm" page-width="21cm">
+ <fo:region-body/>
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+ </xsl:template>
+
+ <xsl:template match="/image">
+ <fo:root>
+ <xsl:call-template name="masters"/>
+ <fox:external-document>
+ <xsl:attribute name="src"><xsl:value-of select="."/></xsl:attribute>
+ </fox:external-document>
+ </fo:root>
+ </xsl:template>
+
+</xsl:stylesheet>
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/image2fo.xsl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/image2fo.xsl
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org
Re: svn commit: r607261 - in /xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli:
AreaTreeInputHandler.java CommandLineOptions.java ImageInputHandler.java
InputHandler.java image2fo.xsl
Posted by Vincent Hennebert <vi...@anyware-tech.com>.
Hi Jeremias,
> Author: jeremias
> Date: Fri Dec 28 07:11:56 2007
> New Revision: 607261
>
> Modified:
> xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/cli/CommandLineOptions.java
> @@ -768,6 +783,20 @@
> + areatreefile.getAbsolutePath()
> + " not found ");
> }
> + } else if (inputmode == IMAGE_INPUT) {
> + if (outputmode.equals(MimeConstants.MIME_XSL_FO)) {
> + throw new FOPException(
> + "FO output mode is only available if you use -xml and -xsl");
> + }
> + if (xmlfile != null) {
> + log.warn("area tree input mode, but XML file is set:");
^^^^^^^^^^^^^^^^^^^^
Copy-paste error? Only had a quick look, but this should probably be
replaced with “image input mode”?
Vincent
--
Vincent Hennebert Anyware Technologies
http://people.apache.org/~vhennebert http://www.anyware-tech.com
Apache FOP Committer FOP Development/Consulting