You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Matthew Lancashire <m....@ies.uk.com> on 2003/02/10 13:48:58 UTC
File not found error
I get a file not found error when I do the .transform
javax.xml.transform.TransformerException: java.io.FileNotFoundException:
C:\m1\Project1\< (The filename, directory name, or volume label syntax is
incorrect)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
686)
//Java
import java.io.File;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
//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 XML2PDF
{
public static void main(String[] args)
{
try
{
System.out.println("FOP ExampleXML2PDF\n");
System.out.println("Preparing...");
XML2PDF app = new XML2PDF();
app.convertXML2PDF(args[0], args[1]);
System.out.println("Success!");
}
catch (Exception e)
{
System.err.println(ExceptionUtil.printStackTrace(e));
System.exit(-1);
}
}
public void convertXML2PDF(String xml, String xslt)
throws IOException, FOPException, TransformerException
{
//Setup output
xml = "<?xml
vesion=1.0?><ROOT><QueryString><Mode>Edit</Mode><SearchID>5</SearchID></Quer
yString><Parameters><ReturnValue>True</ReturnValue><AccessLevel>15</AccessLe
vel></Parameters><tSection><tsSectionID>5</tsSectionID><tsSectionLabel>Facto
ryShop</tsSectionLabel><tsSectionOrder>1</tsSectionOrder><tsQuoteID>15</tsQu
oteID><tsIsQuoteSummary>1</tsIsQuoteSummary><tsDescription>Description</tsDe
scription><tsCalcPrice>1200.00</tsCalcPrice><tsCalcCost>.00</tsCalcCost><tsC
alcMargin>.00</tsCalcMargin><tsCalcLabourHours>.00</tsCalcLabourHours><tsTot
alCost>.00</tsTotalCost><tsMaintenance1>.00</tsMaintenance1><tsMonitoring1>.
00</tsMonitoring1><tsMaintenancePerc2>.00</tsMaintenancePerc2><tsDiscountPer
c>.00</tsDiscountPerc><tsDiscountAmt>100</tsDiscountAmt><tsDiscountIsAmt>1</
tsDiscountIsAmt><tsAdjustAmt>259.877</tsAdjustAmt><tsSubTotal>.00</tsSubTota
l><tsTotalPrice>.00</tsTotalPrice><tsProfit>.00</tsProfit><tsProfitPerDay>.0
0</tsProfitPerDay><tsTotalCharge1>.00</tsTotalCharge1><tsTotalCharge2>.00</t
sTotalCharge2><tsOptional>1</tsOptional><tsIsDirty>0</tsIsDirty><tsMaintenan
cePerc1></tsMaintenancePerc1><tsMaintenance1IsAmt></tsMaintenance1IsAmt><tsM
aintenance2></tsMaintenance2><tsMaintenance2IsAmt></tsMaintenance2IsAmt><tsM
onitoring2></tsMonitoring2><tsCalcLabourCost></tsCalcLabourCost></tSection><
/ROOT>";
System.out.println("Stylesheet: ");
System.out.println();
System.out.println(xslt);
System.out.println();
System.out.println("Data: ");
System.out.println();
System.out.println(xml);
System.out.println();
System.out.println("Transforming...");
try
{
//Setup logger
System.out.println("Setup logger");
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_WARN);
//Construct driver
System.out.println("Construct driver");
Driver driver = new Driver();
driver.setLogger(logger);
//Setup FOP
System.out.println("Setup FOP");
driver.setRenderer(Driver.RENDER_PDF);
// driver.initialize();
//Setup output
System.out.println("Setup output");
ByteArrayOutputStream pdf = new ByteArrayOutputStream();
driver.setOutputStream(pdf);
//Setup sources
System.out.println("Setup sources");
Source xmlSrc = new StreamSource(new String(xml));
Source xsltSrc = new StreamSource(new File(xslt));
//Setup XSLT
System.out.println("Setup XSLT");
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xsltSrc);
//Make sure the XSL transformation's result is piped through to FOP
System.out.println("Pass transform to FOP");
Result res = new SAXResult(driver.getContentHandler());
//Start the transformation and rendering process
System.out.println("Start render");
transformer.transform(xmlSrc, res);
System.out.println(pdf);
}
catch (Exception e)
{
System.err.println(ExceptionUtil.printStackTrace(e));
System.exit(-1);
}
}
}
Matthew Lancashire
IT Project Manager
Intitial Electronic Security Ltd
Tel: +44 1282 473554
Fax: +44 1254 267552
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
Re: File not found error
Posted by Jeremias Maerki <de...@greenmail.ch>.
http://java.sun.com/j2se/1.4/docs/api/index.html
On 10.02.2003 16:41:55 Matthew Lancashire wrote:
> Thanks for the stringreader tip.
> Where can I find better Java docs
Jeremias Maerki
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
RE: File not found error
Posted by Matthew Lancashire <m....@ies.uk.com>.
Thanks for the stringreader tip.
Where can I find better Java docs
-----Original Message-----
From: Matthew Lancashire [mailto:m.lancashire@ies.uk.com]
Sent: 10 Feb 2003 15:26
To: fop-user@xml.apache.org
Subject: RE: File not found error
I just read more of the example on the cvs site and it seems that I cannot
have anything other than a source of type file.
I wish I had read that bitearlier as I need to have source of type streamed
xml
-----Original Message-----
From: Fabrizio Tringali [mailto:f.tringali@infser.it]
Sent: 10 Feb 2003 13:59
To: fop-user@xml.apache.org
Subject: Re: File not found error
this for me works
String xsltSystemId = "file:///C:/m1/Project1/someFile.xsl";
Transformer transformer = factory.newTransformer(new
StreamSource(xsltSystemId));
bye
From: "Matthew Lancashire" <m....@ies.uk.com>
> I get a file not found error when I do the .transform
>
>
> javax.xml.transform.TransformerException: java.io.FileNotFoundException:
> C:\m1\Project1\< (The filename, directory name, or volume label syntax is
> incorrect)
> at
>
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
> 686)
>
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
RE: File not found error
Posted by Matthew Lancashire <m....@ies.uk.com>.
I just read more of the example on the cvs site and it seems that I cannot
have anything other than a source of type file.
I wish I had read that bitearlier as I need to have source of type streamed
xml
-----Original Message-----
From: Fabrizio Tringali [mailto:f.tringali@infser.it]
Sent: 10 Feb 2003 13:59
To: fop-user@xml.apache.org
Subject: Re: File not found error
this for me works
String xsltSystemId = "file:///C:/m1/Project1/someFile.xsl";
Transformer transformer = factory.newTransformer(new
StreamSource(xsltSystemId));
bye
From: "Matthew Lancashire" <m....@ies.uk.com>
> I get a file not found error when I do the .transform
>
>
> javax.xml.transform.TransformerException: java.io.FileNotFoundException:
> C:\m1\Project1\< (The filename, directory name, or volume label syntax is
> incorrect)
> at
>
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
> 686)
>
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
Re: File not found error
Posted by Fabrizio Tringali <f....@infser.it>.
this for me works
String xsltSystemId = "file:///C:/m1/Project1/someFile.xsl";
Transformer transformer = factory.newTransformer(new
StreamSource(xsltSystemId));
bye
From: "Matthew Lancashire" <m....@ies.uk.com>
> I get a file not found error when I do the .transform
>
>
> javax.xml.transform.TransformerException: java.io.FileNotFoundException:
> C:\m1\Project1\< (The filename, directory name, or volume label syntax is
> incorrect)
> at
>
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
> 686)
>
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
Re: File not found error
Posted by Jeremias Maerki <de...@greenmail.ch>.
See below
On 10.02.2003 13:48:58 Matthew Lancashire wrote:
> I get a file not found error when I do the .transform
>
>
> javax.xml.transform.TransformerException: java.io.FileNotFoundException:
> C:\m1\Project1\< (The filename, directory name, or volume label syntax is
> incorrect)
> at
> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
> 686)
<snip/>
> //Setup sources
> System.out.println("Setup sources");
> Source xmlSrc = new StreamSource(new String(xml));
You can't do that. If you supply a String to StreamSource it is meant to
be a URI or filename. If you want to supply your XML as String use the
following:
Source xmlSrc = new StreamSource(new StringReader(xml));
Please consult the JavaDocs for the JAXP API.
<snip/>
Jeremias Maerki
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org