git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196077 13f79535-47bb-0310-9956-ffa450edef68pull/30/head
@@ -0,0 +1,2 @@ | |||
build | |||
out |
@@ -0,0 +1,17 @@ | |||
FOP Embedding Examples Readme | |||
This directory contains several examples on using FOP in Java. | |||
To compile the examples you can use the build.bat/build.sh scripts. | |||
You can also directly run the individual examples with these scripts. | |||
Just call | |||
Windows: build -projecthelp | |||
Unix: ./build.sh -projecthelp | |||
for a listing of all available examples. | |||
Please go to the page indicated below to find more information: | |||
http://xml.apache.org/fop/embedding.html |
@@ -0,0 +1,34 @@ | |||
@echo off | |||
echo Fop Build System | |||
echo ---------------- | |||
if "%JAVA_HOME%" == "" goto error | |||
set LIBDIR=../../lib | |||
set LOCALCLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\classes.zip | |||
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\ant.jar | |||
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xml-apis.jar | |||
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xercesImpl-2.2.1.jar | |||
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xalan-2.4.1.jar | |||
set ANT_HOME=%LIBDIR% | |||
echo Building with classpath %LOCALCLASSPATH% | |||
echo Starting Ant... | |||
%JAVA_HOME%\bin\java.exe -Dant.home=%ANT_HOME% -classpath "%LOCALCLASSPATH%" org.apache.tools.ant.Main %1 %2 %3 %4 %5 | |||
goto end | |||
:error | |||
echo ERROR: JAVA_HOME not found in your environment. | |||
echo Please, set the JAVA_HOME variable in your environment to match the | |||
echo location of the Java Virtual Machine you want to use. | |||
:end | |||
rem set LOCALCLASSPATH= | |||
@@ -0,0 +1,29 @@ | |||
#!/bin/sh | |||
# This file should be executable. | |||
echo | |||
echo "Fop Build System" | |||
echo "----------------" | |||
echo | |||
if [ "$JAVA_HOME" = "" ] ; then | |||
echo "ERROR: JAVA_HOME not found in your environment." | |||
echo | |||
echo "Please, set the JAVA_HOME variable in your environment to match the" | |||
echo "location of the Java Virtual Machine you want to use." | |||
exit 1 | |||
fi | |||
LIBDIR=../../lib | |||
LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip | |||
LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/ant.jar | |||
LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/xml-apis.jar | |||
LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/xercesImpl-2.2.1.jar | |||
LOCALCLASSPATH=$LOCALCLASSPATH:$LIBDIR/xalan-2.4.1.jar | |||
ANT_HOME=$LIBDIR | |||
echo | |||
echo Building with classpath $LOCALCLASSPATH | |||
echo Starting Ant... | |||
echo | |||
$JAVA_HOME/bin/java -Dant.home=$ANT_HOME -classpath "$LOCALCLASSPATH" org.apache.tools.ant.Main $* |
@@ -0,0 +1,111 @@ | |||
<?xml version="1.0"?> | |||
<project default="compile" basedir="."> | |||
<property name="Name" value="Fop Embedding Examples"/> | |||
<property name="name" value="embedding"/> | |||
<property name="version" value="0.20.5cvs"/> | |||
<!-- compiler switches --> | |||
<property name="debug" value="on"/> | |||
<property name="optimize" value="off"/> | |||
<property name="deprecation" value="on"/> | |||
<!-- directories --> | |||
<property name="src.dir" value="./java"/> | |||
<property name="fop.lib.dir" value="../../lib"/> | |||
<property name="lib.dir" value="./lib"/> | |||
<property name="build.dir" value="./build"/> | |||
<property name="build.src" value="./build/src"/> | |||
<property name="build.dest" value="./build/classes"/> | |||
<!-- stuff --> | |||
<path id="project.class.path"> | |||
<fileset dir="${fop.lib.dir}"> | |||
<include name="avalon-framework*.jar"/> | |||
<include name="batik*.jar"/> | |||
<include name="xml-apis.jar"/> | |||
<include name="xerces*.jar"/> | |||
<include name="xalan*.jar"/> | |||
</fileset> | |||
<fileset dir="${fop.lib.dir}/../build"> | |||
<include name="fop.jar"/> | |||
</fileset> | |||
</path> | |||
<!-- =================================================================== --> | |||
<!-- Initialization target --> | |||
<!-- =================================================================== --> | |||
<target name="init"> | |||
<tstamp/> | |||
<filter token="version" value="${version}"/> | |||
<property name="year" value="2002-2003"/> | |||
<echo message="------------------- ${Name} ${version} [${year}] ----------------"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Prepares the build directory --> | |||
<!-- =================================================================== --> | |||
<target name="prepare" depends="init"> | |||
<!-- create directories --> | |||
<echo message="Preparing the build directories"/> | |||
<mkdir dir="${build.dir}"/> | |||
<mkdir dir="${build.dest}"/> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Compiles the source directory --> | |||
<!-- =================================================================== --> | |||
<target name="compile" depends="prepare" description="Compiles the examples"> | |||
<echo message="Compiling the sources"/> | |||
<javac srcdir="${src.dir}" destdir="${build.dest}" debug="${debug}" deprecation="${deprecation}" optimize="${optimize}"> | |||
<classpath refid="project.class.path"/> | |||
</javac> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Runs the various examples --> | |||
<!-- =================================================================== --> | |||
<target name="example1" depends="compile" description="Runs the FO to PDF example"> | |||
<echo message="Running the FO to PDF example"/> | |||
<java classname="${name}.ExampleFO2PDF" fork="yes"> | |||
<classpath> | |||
<path refid="project.class.path"/> | |||
<pathelement location="${build.dest}"/> | |||
</classpath> | |||
</java> | |||
</target> | |||
<target name="example2" depends="compile" description="Runs the XML to FO example"> | |||
<echo message="Running the XML to FO example"/> | |||
<java classname="${name}.ExampleXML2FO" fork="yes"> | |||
<classpath> | |||
<path refid="project.class.path"/> | |||
<pathelement location="${build.dest}"/> | |||
</classpath> | |||
</java> | |||
</target> | |||
<target name="example3" depends="compile" description="Runs the XML to PDF example"> | |||
<echo message="Running the XML to PDF example"/> | |||
<java classname="${name}.ExampleXML2PDF" fork="yes"> | |||
<classpath> | |||
<path refid="project.class.path"/> | |||
<pathelement location="${build.dest}"/> | |||
</classpath> | |||
</java> | |||
</target> | |||
<target name="example4" depends="compile" description="Runs the Object to XML example"> | |||
<echo message="Running the Object to XML example"/> | |||
<java classname="${name}.ExampleObj2XML" fork="yes"> | |||
<classpath> | |||
<path refid="project.class.path"/> | |||
<pathelement location="${build.dest}"/> | |||
</classpath> | |||
</java> | |||
</target> | |||
<target name="example5" depends="compile" description="Runs the Object to PDF example"> | |||
<echo message="Running the Object to PDF example"/> | |||
<java classname="${name}.ExampleObj2PDF" fork="yes"> | |||
<classpath> | |||
<path refid="project.class.path"/> | |||
<pathelement location="${build.dest}"/> | |||
</classpath> | |||
</java> | |||
</target> | |||
<!-- =================================================================== --> | |||
<!-- Clean targets --> | |||
<!-- =================================================================== --> | |||
<target name="clean" depends="init" description="Cleans the build directory"> | |||
<delete dir="${build.dir}"/> | |||
</target> | |||
</project> |
@@ -0,0 +1,149 @@ | |||
/* | |||
* $Id: ExampleFO2PDF.java,v 1.1.2.2 2003/02/25 16:06:34 jeremias Exp $ | |||
* ============================================================================ | |||
* The Apache Software License, Version 1.1 | |||
* ============================================================================ | |||
* | |||
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without modifica- | |||
* tion, 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 acknowledgment: "This product includes software | |||
* developed by the Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, if | |||
* and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "FOP" 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 name, without prior written permission of the | |||
* Apache Software Foundation. | |||
* | |||
* 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 (INCLU- | |||
* DING, 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 and was originally created by | |||
* James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package embedding; | |||
//Java | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.OutputStream; | |||
//SAX | |||
import org.xml.sax.InputSource; | |||
//Avalon | |||
import org.apache.avalon.framework.ExceptionUtil; | |||
import org.apache.avalon.framework.logger.Logger; | |||
import org.apache.avalon.framework.logger.ConsoleLogger; | |||
//FOP | |||
import org.apache.fop.apps.Driver; | |||
import org.apache.fop.apps.FOPException; | |||
/** | |||
* This class demonstrates the conversion of an FO file to PDF using FOP. | |||
*/ | |||
public class ExampleFO2PDF { | |||
/** | |||
* Converts an FO file to a PDF file using FOP | |||
* @param fo the FO file | |||
* @param pdf the target PDF file | |||
* @throws IOException In case of an I/O problem | |||
* @throws FOPException In case of a FOP problem | |||
*/ | |||
public void convertFO2PDF(File fo, File pdf) throws IOException, FOPException { | |||
//Construct driver | |||
Driver driver = new Driver(); | |||
//Setup logger | |||
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); | |||
driver.enableLogging(logger); | |||
driver.initialize(); | |||
//Setup Renderer (output format) | |||
driver.setRenderer(Driver.RENDER_PDF); | |||
//Setup output | |||
OutputStream out = new java.io.FileOutputStream(pdf); | |||
try { | |||
driver.setOutputStream(out); | |||
//Setup input | |||
InputStream in = new java.io.FileInputStream(fo); | |||
try { | |||
driver.setInputSource(new InputSource(in)); | |||
//Process FO | |||
driver.run(); | |||
} finally { | |||
in.close(); | |||
} | |||
} finally { | |||
out.close(); | |||
} | |||
} | |||
/** | |||
* Main method. | |||
* @param args command-line arguments | |||
*/ | |||
public static void main(String[] args) { | |||
try { | |||
System.out.println("FOP ExampleFO2PDF\n"); | |||
System.out.println("Preparing..."); | |||
//Setup directories | |||
File baseDir = new File("."); | |||
File outDir = new File(baseDir, "out"); | |||
outDir.mkdirs(); | |||
//Setup input and output files | |||
File fofile = new File(baseDir, "xml/fo/helloworld.fo"); | |||
File pdffile = new File(outDir, "ResultFO2PDF.pdf"); | |||
System.out.println("Input: XSL-FO (" + fofile + ")"); | |||
System.out.println("Output: PDF (" + pdffile + ")"); | |||
System.out.println(); | |||
System.out.println("Transforming..."); | |||
ExampleFO2PDF app = new ExampleFO2PDF(); | |||
app.convertFO2PDF(fofile, pdffile); | |||
System.out.println("Success!"); | |||
} catch (Exception e) { | |||
System.err.println(ExceptionUtil.printStackTrace(e)); | |||
System.exit(-1); | |||
} | |||
} | |||
} |
@@ -0,0 +1,163 @@ | |||
/* | |||
* $Id: ExampleObj2PDF.java,v 1.1.2.2 2003/02/25 16:06:34 jeremias Exp $ | |||
* ============================================================================ | |||
* The Apache Software License, Version 1.1 | |||
* ============================================================================ | |||
* | |||
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without modifica- | |||
* tion, 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 acknowledgment: "This product includes software | |||
* developed by the Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, if | |||
* and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "FOP" 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 name, without prior written permission of the | |||
* Apache Software Foundation. | |||
* | |||
* 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 (INCLU- | |||
* DING, 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 and was originally created by | |||
* James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package embedding; | |||
//Java | |||
import java.io.File; | |||
import java.io.OutputStream; | |||
import java.io.IOException; | |||
//JAXP | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.TransformerFactory; | |||
import javax.xml.transform.TransformerException; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Result; | |||
import javax.xml.transform.stream.StreamSource; | |||
import javax.xml.transform.sax.SAXResult; | |||
//Avalon | |||
import org.apache.avalon.framework.ExceptionUtil; | |||
import org.apache.avalon.framework.logger.ConsoleLogger; | |||
import org.apache.avalon.framework.logger.Logger; | |||
//FOP | |||
import org.apache.fop.apps.Driver; | |||
import org.apache.fop.apps.FOPException; | |||
import embedding.model.ProjectTeam; | |||
/** | |||
* This class demonstrates the conversion of an arbitrary object file to a | |||
* PDF using JAXP (XSLT) and FOP (XSL:FO). | |||
*/ | |||
public class ExampleObj2PDF { | |||
/** | |||
* Converts a ProjectTeam object to a PDF file. | |||
* @param team the ProjectTeam object | |||
* @param xslt the stylesheet file | |||
* @param pdf the target PDF file | |||
* @throws IOException In case of an I/O problem | |||
* @throws FOPException In case of a FOP problem | |||
* @throws TransformerException In case of a XSL transformation problem | |||
*/ | |||
public void convertProjectTeam2PDF(ProjectTeam team, File xslt, File pdf) | |||
throws IOException, FOPException, TransformerException { | |||
//Construct driver | |||
Driver driver = new Driver(); | |||
//Setup logger | |||
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); | |||
driver.enableLogging(logger); | |||
driver.initialize(); | |||
//Setup Renderer (output format) | |||
driver.setRenderer(Driver.RENDER_PDF); | |||
//Setup output | |||
OutputStream out = new java.io.FileOutputStream(pdf); | |||
try { | |||
driver.setOutputStream(out); | |||
//Setup XSLT | |||
TransformerFactory factory = TransformerFactory.newInstance(); | |||
Transformer transformer = factory.newTransformer(new StreamSource(xslt)); | |||
//Setup input for XSLT transformation | |||
Source src = team.getSourceForProjectTeam(); | |||
//Resulting SAX events (the generated FO) must be piped through to FOP | |||
Result res = new SAXResult(driver.getContentHandler()); | |||
//Start XSLT transformation and FOP processing | |||
transformer.transform(src, res); | |||
} finally { | |||
out.close(); | |||
} | |||
} | |||
/** | |||
* Main method. | |||
* @param args command-line arguments | |||
*/ | |||
public static void main(String[] args) { | |||
try { | |||
System.out.println("FOP ExampleObj2PDF\n"); | |||
System.out.println("Preparing..."); | |||
//Setup directories | |||
File baseDir = new File("."); | |||
File outDir = new File(baseDir, "out"); | |||
outDir.mkdirs(); | |||
//Setup input and output | |||
File xsltfile = new File(baseDir, "xml/xslt/projectteam2FO.xsl"); | |||
File pdffile = new File(outDir, "ResultObj2PDF.pdf"); | |||
System.out.println("Input: a ProjectTeam object"); | |||
System.out.println("Stylesheet: " + xsltfile); | |||
System.out.println("Output: PDF (" + pdffile + ")"); | |||
System.out.println(); | |||
System.out.println("Transforming..."); | |||
ExampleObj2PDF app = new ExampleObj2PDF(); | |||
app.convertProjectTeam2PDF(ExampleObj2XML.createSampleProjectTeam(), xsltfile, pdffile); | |||
System.out.println("Success!"); | |||
} catch (Exception e) { | |||
System.err.println(ExceptionUtil.printStackTrace(e)); | |||
System.exit(-1); | |||
} | |||
} | |||
} |
@@ -0,0 +1,157 @@ | |||
/* | |||
* $Id: ExampleObj2XML.java,v 1.1.2.2 2003/02/25 16:06:34 jeremias Exp $ | |||
* ============================================================================ | |||
* The Apache Software License, Version 1.1 | |||
* ============================================================================ | |||
* | |||
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without modifica- | |||
* tion, 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 acknowledgment: "This product includes software | |||
* developed by the Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, if | |||
* and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "FOP" 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 name, without prior written permission of the | |||
* Apache Software Foundation. | |||
* | |||
* 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 (INCLU- | |||
* DING, 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 and was originally created by | |||
* James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package embedding; | |||
//Hava | |||
import java.io.File; | |||
import java.io.IOException; | |||
//JAXP | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.TransformerFactory; | |||
import javax.xml.transform.TransformerException; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Result; | |||
import javax.xml.transform.stream.StreamResult; | |||
//Avalon | |||
import org.apache.avalon.framework.ExceptionUtil; | |||
import embedding.model.ProjectMember; | |||
import embedding.model.ProjectTeam; | |||
/** | |||
* This class demonstrates the conversion of an arbitrary object file to an | |||
* XML file. | |||
*/ | |||
public class ExampleObj2XML { | |||
/** | |||
* Converts a ProjectTeam object to XML. | |||
* @param team the ProjectTeam object | |||
* @param xml the target XML file | |||
* @throws IOException In case of an I/O problem | |||
* @throws TransformerException In case of a XSL transformation problem | |||
*/ | |||
public void convertProjectTeam2XML(ProjectTeam team, File xml) | |||
throws IOException, TransformerException { | |||
//Setup XSLT | |||
TransformerFactory factory = TransformerFactory.newInstance(); | |||
Transformer transformer = factory.newTransformer(); | |||
/* Note: | |||
We use the identity transformer, no XSL transformation is done. | |||
The transformer is basically just used to serialize the | |||
generated document to XML. */ | |||
//Setup input | |||
Source src = team.getSourceForProjectTeam(); | |||
//Setup output | |||
Result res = new StreamResult(xml); | |||
//Start XSLT transformation | |||
transformer.transform(src, res); | |||
} | |||
/** | |||
* Creates a sample ProjectTeam instance for this demo. | |||
* @return ProjectTeam the newly created ProjectTeam instance | |||
*/ | |||
public static ProjectTeam createSampleProjectTeam() { | |||
ProjectTeam team = new ProjectTeam(); | |||
team.setProjectName("Rule the Galaxy"); | |||
team.addMember(new ProjectMember( | |||
"Emperor Palpatine", "lead", "palpatine@empire.gxy")); | |||
team.addMember(new ProjectMember( | |||
"Lord Darth Vader", "Jedi-Killer", "vader@empire.gxy")); | |||
team.addMember(new ProjectMember( | |||
"Grand Moff Tarkin", "Planet-Killer", "tarkin@empire.gxy")); | |||
team.addMember(new ProjectMember( | |||
"Admiral Motti", "Death Star operations", "motti@empire.gxy")); | |||
return team; | |||
} | |||
/** | |||
* Main method. | |||
* @param args command-line arguments | |||
*/ | |||
public static void main(String[] args) { | |||
try { | |||
System.out.println("FOP ExampleObj2XML\n"); | |||
System.out.println("Preparing..."); | |||
//Setup directories | |||
File baseDir = new File("."); | |||
File outDir = new File(baseDir, "out"); | |||
outDir.mkdirs(); | |||
//Setup input and output | |||
File xmlfile = new File(outDir, "ResultObj2XML.xml"); | |||
System.out.println("Input: a ProjectTeam object"); | |||
System.out.println("Output: XML (" + xmlfile + ")"); | |||
System.out.println(); | |||
System.out.println("Serializing..."); | |||
ExampleObj2XML app = new ExampleObj2XML(); | |||
app.convertProjectTeam2XML(createSampleProjectTeam(), xmlfile); | |||
System.out.println("Success!"); | |||
} catch (Exception e) { | |||
System.err.println(ExceptionUtil.printStackTrace(e)); | |||
System.exit(-1); | |||
} | |||
} | |||
} |
@@ -0,0 +1,142 @@ | |||
/* | |||
* $Id: ExampleXML2FO.java,v 1.1.2.2 2003/02/25 16:06:34 jeremias Exp $ | |||
* ============================================================================ | |||
* The Apache Software License, Version 1.1 | |||
* ============================================================================ | |||
* | |||
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without modifica- | |||
* tion, 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 acknowledgment: "This product includes software | |||
* developed by the Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, if | |||
* and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "FOP" 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 name, without prior written permission of the | |||
* Apache Software Foundation. | |||
* | |||
* 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 (INCLU- | |||
* DING, 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 and was originally created by | |||
* James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package embedding; | |||
//Java | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
//JAXP | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.TransformerFactory; | |||
import javax.xml.transform.TransformerException; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Result; | |||
import javax.xml.transform.stream.StreamResult; | |||
import javax.xml.transform.stream.StreamSource; | |||
//Avalon | |||
import org.apache.avalon.framework.ExceptionUtil; | |||
/** | |||
* This class demonstrates the conversion of an XML file to an XSL-FO file | |||
* using JAXP (XSLT). | |||
*/ | |||
public class ExampleXML2FO { | |||
/** | |||
* Converts an XML file to an XSL-FO file using JAXP (XSLT). | |||
* @param xml the XML file | |||
* @param xslt the stylesheet file | |||
* @param fo the target XSL-FO file | |||
* @throws IOException In case of an I/O problem | |||
* @throws TransformerException In case of a XSL transformation problem | |||
*/ | |||
public void convertXML2FO(File xml, File xslt, File fo) | |||
throws IOException, TransformerException { | |||
//Setup output | |||
OutputStream out = new java.io.FileOutputStream(fo); | |||
try { | |||
//Setup XSLT | |||
TransformerFactory factory = TransformerFactory.newInstance(); | |||
Transformer transformer = factory.newTransformer(new StreamSource(xslt)); | |||
//Setup input for XSLT transformation | |||
Source src = new StreamSource(xml); | |||
//Resulting SAX events (the generated FO) must be piped through to FOP | |||
Result res = new StreamResult(out); | |||
//Start XSLT transformation and FOP processing | |||
transformer.transform(src, res); | |||
} finally { | |||
out.close(); | |||
} | |||
} | |||
/** | |||
* Main method. | |||
* @param args command-line arguments | |||
*/ | |||
public static void main(String[] args) { | |||
try { | |||
System.out.println("FOP ExampleXML2FO\n"); | |||
System.out.println("Preparing..."); | |||
//Setup directories | |||
File baseDir = new File("."); | |||
File outDir = new File(baseDir, "out"); | |||
outDir.mkdirs(); | |||
//Setup input and output files | |||
File xmlfile = new File(baseDir, "xml/xml/projectteam.xml"); | |||
File xsltfile = new File(baseDir, "xml/xslt/projectteam2FO.xsl"); | |||
File fofile = new File(outDir, "ResultXML2FO.fo"); | |||
System.out.println("Input: XML (" + xmlfile + ")"); | |||
System.out.println("Stylesheet: " + xsltfile); | |||
System.out.println("Output: XSL-FO (" + fofile + ")"); | |||
System.out.println(); | |||
System.out.println("Transforming..."); | |||
ExampleXML2FO app = new ExampleXML2FO(); | |||
app.convertXML2FO(xmlfile, xsltfile, fofile); | |||
System.out.println("Success!"); | |||
} catch (Exception e) { | |||
System.err.println(ExceptionUtil.printStackTrace(e)); | |||
System.exit(-1); | |||
} | |||
} | |||
} |
@@ -0,0 +1,161 @@ | |||
/* | |||
* $Id: ExampleXML2PDF.java,v 1.1.2.2 2003/02/25 16:06:34 jeremias Exp $ | |||
* ============================================================================ | |||
* The Apache Software License, Version 1.1 | |||
* ============================================================================ | |||
* | |||
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without modifica- | |||
* tion, 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 acknowledgment: "This product includes software | |||
* developed by the Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, if | |||
* and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "FOP" 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 name, without prior written permission of the | |||
* Apache Software Foundation. | |||
* | |||
* 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 (INCLU- | |||
* DING, 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 and was originally created by | |||
* James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package embedding; | |||
//Java | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
//JAXP | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.TransformerFactory; | |||
import javax.xml.transform.TransformerException; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Result; | |||
import javax.xml.transform.stream.StreamSource; | |||
import javax.xml.transform.sax.SAXResult; | |||
//Avalon | |||
import org.apache.avalon.framework.ExceptionUtil; | |||
import org.apache.avalon.framework.logger.ConsoleLogger; | |||
import org.apache.avalon.framework.logger.Logger; | |||
//FOP | |||
import org.apache.fop.apps.Driver; | |||
import org.apache.fop.apps.FOPException; | |||
/** | |||
* This class demonstrates the conversion of an XML file to PDF using | |||
* JAXP (XSLT) and FOP (XSL-FO). | |||
*/ | |||
public class ExampleXML2PDF { | |||
/** | |||
* Converts an XML file to a PDF file using JAXP and FOP. | |||
* @param xml the XML file | |||
* @param xslt the stylesheet file | |||
* @param pdf the target PDF file | |||
* @throws IOException In case of an I/O problem | |||
* @throws FOPException In case of a FOP problem | |||
* @throws TransformerException In case of a XSL transformation problem | |||
*/ | |||
public void convertXML2PDF(File xml, File xslt, File pdf) | |||
throws IOException, FOPException, TransformerException { | |||
//Construct driver | |||
Driver driver = new Driver(); | |||
//Setup logger | |||
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); | |||
driver.enableLogging(logger); | |||
driver.initialize(); | |||
//Setup Renderer (output format) | |||
driver.setRenderer(Driver.RENDER_PDF); | |||
//Setup output | |||
OutputStream out = new java.io.FileOutputStream(pdf); | |||
try { | |||
driver.setOutputStream(out); | |||
//Setup XSLT | |||
TransformerFactory factory = TransformerFactory.newInstance(); | |||
Transformer transformer = factory.newTransformer(new StreamSource(xslt)); | |||
//Setup input for XSLT transformation | |||
Source src = new StreamSource(xml); | |||
//Resulting SAX events (the generated FO) must be piped through to FOP | |||
Result res = new SAXResult(driver.getContentHandler()); | |||
//Start XSLT transformation and FOP processing | |||
transformer.transform(src, res); | |||
} finally { | |||
out.close(); | |||
} | |||
} | |||
/** | |||
* Main method. | |||
* @param args command-line arguments | |||
*/ | |||
public static void main(String[] args) { | |||
try { | |||
System.out.println("FOP ExampleXML2PDF\n"); | |||
System.out.println("Preparing..."); | |||
//Setup directories | |||
File baseDir = new File("."); | |||
File outDir = new File(baseDir, "out"); | |||
outDir.mkdirs(); | |||
//Setup input and output files | |||
File xmlfile = new File(baseDir, "xml/xml/projectteam.xml"); | |||
File xsltfile = new File(baseDir, "xml/xslt/projectteam2FO.xsl"); | |||
File pdffile = new File(outDir, "ResultXML2PDF.pdf"); | |||
System.out.println("Input: XML (" + xmlfile + ")"); | |||
System.out.println("Stylesheet: " + xsltfile); | |||
System.out.println("Output: PDF (" + pdffile + ")"); | |||
System.out.println(); | |||
System.out.println("Transforming..."); | |||
ExampleXML2PDF app = new ExampleXML2PDF(); | |||
app.convertXML2PDF(xmlfile, xsltfile, pdffile); | |||
System.out.println("Success!"); | |||
} catch (Exception e) { | |||
System.err.println(ExceptionUtil.printStackTrace(e)); | |||
System.exit(-1); | |||
} | |||
} | |||
} |
@@ -0,0 +1,135 @@ | |||
/* | |||
* $Id: ProjectMember.java,v 1.1.2.2 2003/02/25 16:06:34 jeremias Exp $ | |||
* ============================================================================ | |||
* The Apache Software License, Version 1.1 | |||
* ============================================================================ | |||
* | |||
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without modifica- | |||
* tion, 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 acknowledgment: "This product includes software | |||
* developed by the Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, if | |||
* and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "FOP" 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 name, without prior written permission of the | |||
* Apache Software Foundation. | |||
* | |||
* 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 (INCLU- | |||
* DING, 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 and was originally created by | |||
* James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package embedding.model; | |||
/** | |||
* This bean represents a project member. | |||
*/ | |||
public class ProjectMember { | |||
private String name; | |||
private String function; | |||
private String email; | |||
/** | |||
* Default no-parameter constructor. | |||
*/ | |||
public ProjectMember() { | |||
} | |||
/** | |||
* Convenience constructor. | |||
* @param name name of the project member | |||
* @param function function in the team | |||
* @param email email address | |||
*/ | |||
public ProjectMember(String name, String function, String email) { | |||
setName(name); | |||
setFunction(function); | |||
setEmail(email); | |||
} | |||
/** | |||
* Returns the name. | |||
* @return String the name | |||
*/ | |||
public String getName() { | |||
return name; | |||
} | |||
/** | |||
* Returns the function. | |||
* @return String the function | |||
*/ | |||
public String getFunction() { | |||
return function; | |||
} | |||
/** | |||
* Returns the email address. | |||
* @return String the email address | |||
*/ | |||
public String getEmail() { | |||
return email; | |||
} | |||
/** | |||
* Sets the name. | |||
* @param name The name to set | |||
*/ | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
/** | |||
* Sets the function. | |||
* @param function The function to set | |||
*/ | |||
public void setFunction(String function) { | |||
this.function = function; | |||
} | |||
/** | |||
* Sets the email address. | |||
* @param email The email address to set | |||
*/ | |||
public void setEmail(String email) { | |||
this.email = email; | |||
} | |||
} |
@@ -0,0 +1,114 @@ | |||
/* | |||
* $Id: ProjectTeam.java,v 1.1.2.2 2003/02/25 16:06:34 jeremias Exp $ | |||
* ============================================================================ | |||
* The Apache Software License, Version 1.1 | |||
* ============================================================================ | |||
* | |||
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without modifica- | |||
* tion, 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 acknowledgment: "This product includes software | |||
* developed by the Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, if | |||
* and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "FOP" 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 name, without prior written permission of the | |||
* Apache Software Foundation. | |||
* | |||
* 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 (INCLU- | |||
* DING, 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 and was originally created by | |||
* James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package embedding.model; | |||
import java.util.List; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.sax.SAXSource; | |||
/** | |||
* This bean represents a ProjectTeam. | |||
*/ | |||
public class ProjectTeam { | |||
private String projectName; | |||
private List members = new java.util.ArrayList(); | |||
/** | |||
* Returns a list of project members. | |||
* @return List a list of ProjectMember objects | |||
*/ | |||
public List getMembers() { | |||
return this.members; | |||
} | |||
/** | |||
* Adds a ProjectMember to this project team. | |||
* @param member the member to add | |||
*/ | |||
public void addMember(ProjectMember member) { | |||
this.members.add(member); | |||
} | |||
/** | |||
* Returns the name of the project | |||
* @return String the name of the project | |||
*/ | |||
public String getProjectName() { | |||
return projectName; | |||
} | |||
/** | |||
* Sets the name of the project. | |||
* @param projectName the project name to set | |||
*/ | |||
public void setProjectName(String projectName) { | |||
this.projectName = projectName; | |||
} | |||
/** | |||
* Resturns a Source object for this object so it can be used as input for | |||
* a JAXP transformation. | |||
* @return Source The Source object | |||
*/ | |||
public Source getSourceForProjectTeam() { | |||
return new SAXSource(new ProjectTeamXMLReader(), | |||
new ProjectTeamInputSource(this)); | |||
} | |||
} |
@@ -0,0 +1,87 @@ | |||
/* | |||
* $Id: ProjectTeamInputSource.java,v 1.1.2.2 2003/02/25 16:06:34 jeremias Exp $ | |||
* ============================================================================ | |||
* The Apache Software License, Version 1.1 | |||
* ============================================================================ | |||
* | |||
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without modifica- | |||
* tion, 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 acknowledgment: "This product includes software | |||
* developed by the Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, if | |||
* and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "FOP" 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 name, without prior written permission of the | |||
* Apache Software Foundation. | |||
* | |||
* 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 (INCLU- | |||
* DING, 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 and was originally created by | |||
* James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package embedding.model; | |||
import org.xml.sax.InputSource; | |||
/** | |||
* This class is a special InputSource decendant for using ProjectTeam | |||
* instances as XML sources. | |||
*/ | |||
public class ProjectTeamInputSource extends InputSource { | |||
private ProjectTeam projectTeam; | |||
/** | |||
* Constructor for the ProjectTeamInputSource | |||
* @param projectTeam The ProjectTeam object to use | |||
*/ | |||
public ProjectTeamInputSource(ProjectTeam projectTeam) { | |||
this.projectTeam = projectTeam; | |||
} | |||
/** | |||
* Returns the projectTeam. | |||
* @return ProjectTeam | |||
*/ | |||
public ProjectTeam getProjectTeam() { | |||
return projectTeam; | |||
} | |||
/** | |||
* Sets the projectTeam. | |||
* @param projectTeam The projectTeam to set | |||
*/ | |||
public void setProjectTeam(ProjectTeam projectTeam) { | |||
this.projectTeam = projectTeam; | |||
} | |||
} |
@@ -0,0 +1,149 @@ | |||
/* | |||
* $Id: ProjectTeamXMLReader.java,v 1.1.2.2 2003/02/25 16:06:34 jeremias Exp $ | |||
* ============================================================================ | |||
* The Apache Software License, Version 1.1 | |||
* ============================================================================ | |||
* | |||
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without modifica- | |||
* tion, 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 acknowledgment: "This product includes software | |||
* developed by the Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, if | |||
* and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "FOP" 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 name, without prior written permission of the | |||
* Apache Software Foundation. | |||
* | |||
* 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 (INCLU- | |||
* DING, 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 and was originally created by | |||
* James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package embedding.model; | |||
//Java | |||
import java.util.Iterator; | |||
import java.io.IOException; | |||
//SAX | |||
import org.xml.sax.InputSource; | |||
import org.xml.sax.SAXException; | |||
import embedding.tools.AbstractObjectReader; | |||
/** | |||
* XMLReader implementation for the ProjectTeam class. This class is used to | |||
* generate SAX events from the ProjectTeam class. | |||
*/ | |||
public class ProjectTeamXMLReader extends AbstractObjectReader { | |||
/** | |||
* @see org.xml.sax.XMLReader#parse(InputSource) | |||
*/ | |||
public void parse(InputSource input) throws IOException, SAXException { | |||
if (input instanceof ProjectTeamInputSource) { | |||
parse(((ProjectTeamInputSource)input).getProjectTeam()); | |||
} else { | |||
throw new SAXException("Unsupported InputSource specified. " | |||
+ "Must be a ProjectTeamInputSource"); | |||
} | |||
} | |||
/** | |||
* Starts parsing the ProjectTeam object. | |||
* @param projectTeam The object to parse | |||
* @throws SAXException In case of a problem during SAX event generation | |||
*/ | |||
public void parse(ProjectTeam projectTeam) throws SAXException { | |||
if (projectTeam == null) { | |||
throw new NullPointerException("Parameter projectTeam must not be null"); | |||
} | |||
if (handler == null) { | |||
throw new IllegalStateException("ContentHandler not set"); | |||
} | |||
//Start the document | |||
handler.startDocument(); | |||
//Generate SAX events for the ProjectTeam | |||
generateFor(projectTeam); | |||
//End the document | |||
handler.endDocument(); | |||
} | |||
/** | |||
* Generates SAX events for a ProjectTeam object. | |||
* @param projectTeam ProjectTeam object to use | |||
* @throws SAXException In case of a problem during SAX event generation | |||
*/ | |||
protected void generateFor(ProjectTeam projectTeam) throws SAXException { | |||
if (projectTeam == null) { | |||
throw new NullPointerException("Parameter projectTeam must not be null"); | |||
} | |||
if (handler == null) { | |||
throw new IllegalStateException("ContentHandler not set"); | |||
} | |||
handler.startElement("projectteam"); | |||
handler.element("projectname", projectTeam.getProjectName()); | |||
Iterator i = projectTeam.getMembers().iterator(); | |||
while (i.hasNext()) { | |||
ProjectMember member = (ProjectMember)i.next(); | |||
generateFor(member); | |||
} | |||
handler.endElement("projectteam"); | |||
} | |||
/** | |||
* Generates SAX events for a ProjectMember object. | |||
* @param projectMember ProjectMember object to use | |||
* @throws SAXException In case of a problem during SAX event generation | |||
*/ | |||
protected void generateFor(ProjectMember projectMember) throws SAXException { | |||
if (projectMember == null) { | |||
throw new NullPointerException("Parameter projectMember must not be null"); | |||
} | |||
if (handler == null) { | |||
throw new IllegalStateException("ContentHandler not set"); | |||
} | |||
handler.startElement("member"); | |||
handler.element("name", projectMember.getName()); | |||
handler.element("function", projectMember.getFunction()); | |||
handler.element("email", projectMember.getEmail()); | |||
handler.endElement("member"); | |||
} | |||
} |
@@ -0,0 +1,210 @@ | |||
/* | |||
* $Id: AbstractObjectReader.java,v 1.1.2.2 2003/02/25 16:06:34 jeremias Exp $ | |||
* ============================================================================ | |||
* The Apache Software License, Version 1.1 | |||
* ============================================================================ | |||
* | |||
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without modifica- | |||
* tion, 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 acknowledgment: "This product includes software | |||
* developed by the Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, if | |||
* and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "FOP" 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 name, without prior written permission of the | |||
* Apache Software Foundation. | |||
* | |||
* 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 (INCLU- | |||
* DING, 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 and was originally created by | |||
* James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package embedding.tools; | |||
//Java | |||
import java.io.IOException; | |||
import java.util.Map; | |||
//SAX | |||
import org.xml.sax.SAXException; | |||
import org.xml.sax.InputSource; | |||
import org.xml.sax.XMLReader; | |||
import org.xml.sax.ContentHandler; | |||
import org.xml.sax.DTDHandler; | |||
import org.xml.sax.ErrorHandler; | |||
import org.xml.sax.EntityResolver; | |||
/** | |||
* This class can be used as base class for XMLReaders that generate SAX | |||
* events from Java objects. | |||
*/ | |||
public abstract class AbstractObjectReader implements XMLReader { | |||
private static final String NAMESPACES = | |||
"http://xml.org/sax/features/namespaces"; | |||
private static final String NS_PREFIXES = | |||
"http://xml.org/sax/features/namespace-prefixes"; | |||
private Map features = new java.util.HashMap(); | |||
private ContentHandler orgHandler; | |||
/** Proxy for easy SAX event generation */ | |||
protected EasyGenerationContentHandlerProxy handler; | |||
/** Error handler */ | |||
protected ErrorHandler errorHandler; | |||
/** | |||
* Constructor for the AbstractObjectReader object | |||
*/ | |||
public AbstractObjectReader() { | |||
setFeature(NAMESPACES, false); | |||
setFeature(NS_PREFIXES, false); | |||
} | |||
/* ============ XMLReader interface ============ */ | |||
/** | |||
* @see org.xml.sax.XMLReader#getContentHandler() | |||
*/ | |||
public ContentHandler getContentHandler() { | |||
return this.orgHandler; | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#setContentHandler(ContentHandler) | |||
*/ | |||
public void setContentHandler(ContentHandler handler) { | |||
this.orgHandler = handler; | |||
this.handler = new EasyGenerationContentHandlerProxy(handler); | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#getErrorHandler() | |||
*/ | |||
public ErrorHandler getErrorHandler() { | |||
return this.errorHandler; | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#setErrorHandler(ErrorHandler) | |||
*/ | |||
public void setErrorHandler(ErrorHandler handler) { | |||
this.errorHandler = handler; | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#getDTDHandler() | |||
*/ | |||
public DTDHandler getDTDHandler() { | |||
return null; | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#setDTDHandler(DTDHandler) | |||
*/ | |||
public void setDTDHandler(DTDHandler handler) { | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#getEntityResolver() | |||
*/ | |||
public EntityResolver getEntityResolver() { | |||
return null; | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#setEntityResolver(EntityResolver) | |||
*/ | |||
public void setEntityResolver(EntityResolver resolver) { | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#getProperty(String) | |||
*/ | |||
public Object getProperty(java.lang.String name) { | |||
return null; | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#setProperty(String, Object) | |||
*/ | |||
public void setProperty(java.lang.String name, java.lang.Object value) { | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#getFeature(String) | |||
*/ | |||
public boolean getFeature(java.lang.String name) { | |||
return ((Boolean) features.get(name)).booleanValue(); | |||
} | |||
/** | |||
* Returns true if the NAMESPACES feature is enabled. | |||
* @return boolean true if enabled | |||
*/ | |||
protected boolean isNamespaces() { | |||
return getFeature(NAMESPACES); | |||
} | |||
/** | |||
* Returns true if the MS_PREFIXES feature is enabled. | |||
* @return boolean true if enabled | |||
*/ | |||
protected boolean isNamespacePrefixes() { | |||
return getFeature(NS_PREFIXES); | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#setFeature(String, boolean) | |||
*/ | |||
public void setFeature(java.lang.String name, boolean value) { | |||
this.features.put(name, new Boolean(value)); | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#parse(String) | |||
*/ | |||
public void parse(String systemId) throws IOException, SAXException { | |||
throw new SAXException( | |||
this.getClass().getName() | |||
+ " cannot be used with system identifiers (URIs)"); | |||
} | |||
/** | |||
* @see org.xml.sax.XMLReader#parse(InputSource) | |||
*/ | |||
public abstract void parse(InputSource input) | |||
throws IOException, SAXException; | |||
} |
@@ -0,0 +1,245 @@ | |||
/* | |||
* $Id: EasyGenerationContentHandlerProxy.java,v 1.1.2.2 2003/02/25 16:06:34 jeremias Exp $ | |||
* ============================================================================ | |||
* The Apache Software License, Version 1.1 | |||
* ============================================================================ | |||
* | |||
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without modifica- | |||
* tion, 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 acknowledgment: "This product includes software | |||
* developed by the Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, if | |||
* and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "FOP" 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 name, without prior written permission of the | |||
* Apache Software Foundation. | |||
* | |||
* 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 (INCLU- | |||
* DING, 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 and was originally created by | |||
* James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package embedding.tools; | |||
//SAX | |||
import org.xml.sax.ContentHandler; | |||
import org.xml.sax.Locator; | |||
import org.xml.sax.Attributes; | |||
import org.xml.sax.SAXException; | |||
import org.xml.sax.helpers.AttributesImpl; | |||
/** | |||
* This class is an implementation of ContentHandler which acts as a proxy to | |||
* another ContentHandler and has the purpose to provide a few handy methods | |||
* that make life easier when generating SAX events. | |||
* <br> | |||
* Note: This class is only useful for simple cases with no namespaces. | |||
*/ | |||
public class EasyGenerationContentHandlerProxy implements ContentHandler { | |||
/** An empty Attributes object used when no attributes are needed. */ | |||
public static final Attributes EMPTY_ATTS = new AttributesImpl(); | |||
private ContentHandler target; | |||
/** | |||
* Main constructor. | |||
* @param forwardTo ContentHandler to forward the SAX event to. | |||
*/ | |||
public EasyGenerationContentHandlerProxy(ContentHandler forwardTo) { | |||
this.target = forwardTo; | |||
} | |||
/** | |||
* Sends the notification of the beginning of an element. | |||
* @param name Name for the element. | |||
* @throws SAXException Any SAX exception, possibly wrapping another exception. | |||
*/ | |||
public void startElement(String name) throws SAXException { | |||
startElement(name, EMPTY_ATTS); | |||
} | |||
/** | |||
* Sends the notification of the beginning of an element. | |||
* @param name Name for the element. | |||
* @param atts The attributes attached to the element. If there are no | |||
* attributes, it shall be an empty Attributes object. | |||
* @throws SAXException Any SAX exception, possibly wrapping another exception. | |||
*/ | |||
public void startElement(String name, Attributes atts) throws SAXException { | |||
startElement(null, name, name, atts); | |||
} | |||
/** | |||
* Send a String of character data. | |||
* @param s The content String | |||
* @throws SAXException Any SAX exception, possibly wrapping another exception. | |||
*/ | |||
public void characters(String s) throws SAXException { | |||
target.characters(s.toCharArray(), 0, s.length()); | |||
} | |||
/** | |||
* Send the notification of the end of an element. | |||
* @param name Name for the element. | |||
* @throws SAXException Any SAX exception, possibly wrapping another exception. | |||
*/ | |||
public void endElement(String name) throws SAXException { | |||
endElement(null, name, name); | |||
} | |||
/** | |||
* Sends notifications for a whole element with some String content. | |||
* @param name Name for the element. | |||
* @param value Content of the element. | |||
* @throws SAXException Any SAX exception, possibly wrapping another exception. | |||
*/ | |||
public void element(String name, String value) throws SAXException { | |||
element(name, value, EMPTY_ATTS); | |||
} | |||
/** | |||
* Sends notifications for a whole element with some String content. | |||
* @param name Name for the element. | |||
* @param value Content of the element. | |||
* @param atts The attributes attached to the element. If there are no | |||
* attributes, it shall be an empty Attributes object. | |||
* @throws SAXException Any SAX exception, possibly wrapping another exception. | |||
*/ | |||
public void element(String name, String value, Attributes atts) throws SAXException { | |||
startElement(name, atts); | |||
if (value != null) { | |||
characters(value.toCharArray(), 0, value.length()); | |||
} | |||
endElement(name); | |||
} | |||
/* =========== ContentHandler interface =========== */ | |||
/** | |||
* @see org.xml.sax.ContentHandler#setDocumentLocator(Locator) | |||
*/ | |||
public void setDocumentLocator(Locator locator) { | |||
target.setDocumentLocator(locator); | |||
} | |||
/** | |||
* @see org.xml.sax.ContentHandler#startDocument() | |||
*/ | |||
public void startDocument() throws SAXException { | |||
target.startDocument(); | |||
} | |||
/** | |||
* @see org.xml.sax.ContentHandler#endDocument() | |||
*/ | |||
public void endDocument() throws SAXException { | |||
target.endDocument(); | |||
} | |||
/** | |||
* @see org.xml.sax.ContentHandler#startPrefixMapping(String, String) | |||
*/ | |||
public void startPrefixMapping(String prefix, String uri) throws SAXException { | |||
target.startPrefixMapping(prefix, uri); | |||
} | |||
/** | |||
* @see org.xml.sax.ContentHandler#endPrefixMapping(String) | |||
*/ | |||
public void endPrefixMapping(String prefix) throws SAXException { | |||
target.endPrefixMapping(prefix); | |||
} | |||
/** | |||
* @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes) | |||
*/ | |||
public void startElement(String namespaceURI, String localName, | |||
String qName, Attributes atts) throws SAXException { | |||
target.startElement(namespaceURI, localName, qName, atts); | |||
} | |||
/** | |||
* @see org.xml.sax.ContentHandler#endElement(String, String, String) | |||
*/ | |||
public void endElement(String namespaceURI, String localName, String qName) | |||
throws SAXException { | |||
target.endElement(namespaceURI, localName, qName); | |||
} | |||
/** | |||
* @see org.xml.sax.ContentHandler#characters(char[], int, int) | |||
*/ | |||
public void characters(char[] ch, int start, int length) throws SAXException { | |||
target.characters(ch, start, length); | |||
} | |||
/** | |||
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int) | |||
*/ | |||
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { | |||
target.ignorableWhitespace(ch, start, length); | |||
} | |||
/** | |||
* @see org.xml.sax.ContentHandler#processingInstruction(String, String) | |||
*/ | |||
public void processingInstruction(String target, String data) throws SAXException { | |||
this.target.processingInstruction(target, data); | |||
} | |||
/** | |||
* @see org.xml.sax.ContentHandler#skippedEntity(String) | |||
*/ | |||
public void skippedEntity(String name) throws SAXException { | |||
target.skippedEntity(name); | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> | |||
<fo:layout-master-set> | |||
<fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm"> | |||
<fo:region-body/> | |||
</fo:simple-page-master> | |||
</fo:layout-master-set> | |||
<fo:page-sequence master-reference="simpleA4"> | |||
<fo:flow flow-name="xsl-region-body"> | |||
<fo:block>Hello World!</fo:block> | |||
</fo:flow> | |||
</fo:page-sequence> | |||
</fo:root> |
@@ -0,0 +1,29 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<projectteam> | |||
<projectname>The Killer Application</projectname> | |||
<member> | |||
<name>John Doe</name> | |||
<function>lead</function> | |||
<email>jon.doe@killerapp.fun</email> | |||
</member> | |||
<member> | |||
<name>Paul Coder</name> | |||
<function>dev</function> | |||
<email>paul.coder@killerapp.fun</email> | |||
</member> | |||
<member> | |||
<name>Max Hacker</name> | |||
<function>dev</function> | |||
<email>max.hacker@killerapp.fun</email> | |||
</member> | |||
<member> | |||
<name>Donna Book</name> | |||
<function>doc</function> | |||
<email>donna.book@killerapp.fun</email> | |||
</member> | |||
<member> | |||
<name>Henry Tester</name> | |||
<function>qa</function> | |||
<email>henry.tester@killerapp.fun</email> | |||
</member> | |||
</projectteam> |
@@ -0,0 +1,57 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo"> | |||
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/> | |||
<!-- ========================= --> | |||
<!-- root element: projectteam --> | |||
<!-- ========================= --> | |||
<xsl:template match="projectteam"> | |||
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> | |||
<fo:layout-master-set> | |||
<fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm"> | |||
<fo:region-body/> | |||
</fo:simple-page-master> | |||
</fo:layout-master-set> | |||
<fo:page-sequence master-reference="simpleA4"> | |||
<fo:flow flow-name="xsl-region-body"> | |||
<fo:block font-size="16pt" font-weight="bold" space-after="5mm">Project: <xsl:value-of select="projectname"/> | |||
</fo:block> | |||
<fo:block font-size="10pt"> | |||
<fo:table table-layout="fixed"> | |||
<fo:table-column column-width="4cm"/> | |||
<fo:table-column column-width="4cm"/> | |||
<fo:table-column column-width="5cm"/> | |||
<fo:table-body> | |||
<xsl:apply-templates select="member"/> | |||
</fo:table-body> | |||
</fo:table> | |||
</fo:block> | |||
</fo:flow> | |||
</fo:page-sequence> | |||
</fo:root> | |||
</xsl:template> | |||
<!-- ========================= --> | |||
<!-- child element: member --> | |||
<!-- ========================= --> | |||
<xsl:template match="member"> | |||
<fo:table-row> | |||
<xsl:if test="function = 'lead'"> | |||
<xsl:attribute name="font-weight">bold</xsl:attribute> | |||
</xsl:if> | |||
<fo:table-cell> | |||
<fo:block> | |||
<xsl:value-of select="name"/> | |||
</fo:block> | |||
</fo:table-cell> | |||
<fo:table-cell> | |||
<fo:block> | |||
<xsl:value-of select="function"/> | |||
</fo:block> | |||
</fo:table-cell> | |||
<fo:table-cell> | |||
<fo:block> | |||
<xsl:value-of select="email"/> | |||
</fo:block> | |||
</fo:table-cell> | |||
</fo:table-row> | |||
</xsl:template> | |||
</xsl:stylesheet> |