From aafe96253d244243929b99a08e78f8ad0d8086c4 Mon Sep 17 00:00:00 2001 From: Pascal Sancho Date: Fri, 18 Jun 2010 10:38:27 +0000 Subject: Bugzilla #78887: Bugfix: documentation update according to javadoc in Trunk tab > Embed git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@955927 13f79535-47bb-0310-9956-ffa450edef68 --- .../content/xdocs/trunk/embedding.xml | 216 ++++++++++----------- 1 file changed, 108 insertions(+), 108 deletions(-) (limited to 'src/documentation/content/xdocs/trunk') diff --git a/src/documentation/content/xdocs/trunk/embedding.xml b/src/documentation/content/xdocs/trunk/embedding.xml index 362062bbe..3289e68c7 100644 --- a/src/documentation/content/xdocs/trunk/embedding.xml +++ b/src/documentation/content/xdocs/trunk/embedding.xml @@ -29,7 +29,7 @@
Overview

- Review Running FOP for important information that applies + Review Running FOP for important information that applies to embedded applications as well as command-line use, such as options and performance.

@@ -54,7 +54,7 @@

Basic Usage Pattern

- Apache FOP relies heavily on JAXP. It uses SAX events exclusively to receive the XSL-FO + Apache FOP relies heavily on JAXP. It uses SAX events exclusively to receive the XSL-FO input document. It is therefore a good idea that you know a few things about JAXP (which is a good skill anyway). Let's look at the basic usage pattern for FOP...

@@ -82,14 +82,14 @@ try { // Step 4: Setup JAXP using identity transformer TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); // identity transformer - - // Step 5: Setup input and output for XSLT transformation + + // Step 5: Setup input and output for XSLT transformation // Setup input stream Source src = new StreamSource(new File("C:/Temp/myfile.fo")); // Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); - + // Step 6: Start XSLT transformation and FOP processing transformer.transform(src, res); @@ -102,13 +102,13 @@ try {

  • - Step 1: You create a new FopFactory instance. The FopFactory instance holds + Step 1: You create a new FopFactory instance. The FopFactory instance holds references to configuration information and cached data. It's important to reuse this instance if you plan to render multiple documents during a JVM's lifetime.
  • Step 2: You set up an OutputStream that the generated document - will be written to. It's a good idea to buffer the OutputStream as demonstrated + will be written to. It's a good idea to buffer the OutputStream as demonstrated to improve performance.
  • @@ -119,26 +119,26 @@ try { OutputStream you've setup up in step 2.
  • - Step 4 We recommend that you use JAXP Transformers even - if you don't do XSLT transformations to generate the XSL-FO file. This way - you can always use the same basic pattern. The example here sets up an - "identity transformer" which just passes the input (Source) unchanged to the - output (Result). You don't have to work with a SAXParser if you don't do any + Step 4 We recommend that you use JAXP Transformers even + if you don't do XSLT transformations to generate the XSL-FO file. This way + you can always use the same basic pattern. The example here sets up an + "identity transformer" which just passes the input (Source) unchanged to the + output (Result). You don't have to work with a SAXParser if you don't do any XSLT transformations.
  • - Step 5: Here you set up the input and output for the XSLT - transformation. The Source object is set up to load the "myfile.fo" file. - The Result is set up so the output of the XSLT transformation is sent to FOP. - The FO file is sent to FOP in the form of SAX events which is the most efficient - way. Please always avoid saving intermediate results to a file or a memory buffer + Step 5: Here you set up the input and output for the XSLT + transformation. The Source object is set up to load the "myfile.fo" file. + The Result is set up so the output of the XSLT transformation is sent to FOP. + The FO file is sent to FOP in the form of SAX events which is the most efficient + way. Please always avoid saving intermediate results to a file or a memory buffer because that affects performance negatively.
  • - Step 6: Finally, we start the XSLT transformation by starting - the JAXP Transformer. As soon as the JAXP Transformer starts to send its output - to FOP, FOP itself starts its processing in the background. When the - transform() method returns FOP will also have finished converting + Step 6: Finally, we start the XSLT transformation by starting + the JAXP Transformer. As soon as the JAXP Transformer starts to send its output + to FOP, FOP itself starts its processing in the background. When the + transform() method returns FOP will also have finished converting the FO file to a PDF file and you can close the OutputStream. It's a good idea to enclose the whole conversion in a try..finally statement. If @@ -148,16 +148,16 @@ try {

- If you're not totally familiar with JAXP Transformers, please have a look at the + If you're not totally familiar with JAXP Transformers, please have a look at the Embedding examples below. The section contains examples for all sorts of use cases. If you look at all of them in turn you should be able to see the patterns in use and the flexibility this approach offers without adding too much complexity.

- This may look complicated at first, but it's really just the combination of an + This may look complicated at first, but it's really just the combination of an XSL transformation and a FOP run. It's also easy to comment out the FOP part - for debugging purposes, for example when you're tracking down a bug in your + for debugging purposes, for example when you're tracking down a bug in your stylesheet. You can easily write the XSL-FO output from the XSL transformation to a file to check if that part generates the expected output. An example for that can be found in the Embedding examples (See "ExampleXML2FO"). @@ -170,7 +170,7 @@ try { While with Avalon Logging the loggers were directly given to FOP, FOP now retrieves its logger(s) through a statically available LogFactory. This is similar to the general pattern that you use when you work with Apache Log4J directly, for example. - We call this "static logging" (Commons Logging, Log4J) as opposed to "instance logging" + We call this "static logging" (Commons Logging, Log4J) as opposed to "instance logging" (Avalon Logging). This has a consequence: You can't give FOP a logger for each processing run anymore. The log output of multiple, simultaneously running FOP instances is sent to the same logger. @@ -204,12 +204,12 @@ try { the Events subsystem is the right approach.

- +
Processing XSL-FO

- Once the Fop instance is set up, call getDefaultHandler() to obtain a SAX - DefaultHandler instance to which you can send the SAX events making up the XSL-FO + Once the Fop instance is set up, call getDefaultHandler() to obtain a SAX + DefaultHandler instance to which you can send the SAX events making up the XSL-FO document you'd like to render. FOP processing starts as soon as the DefaultHandler's startDocument() method is called. Processing stops again when the DefaultHandler's endDocument() method is called. Please refer to the basic @@ -220,15 +220,15 @@ try {

Processing XSL-FO generated from XML+XSLT

- If you want to process XSL-FO generated from XML using XSLT we recommend - again using standard JAXP to do the XSLT part and piping the generated SAX - events directly through to FOP. The only thing you'd change to do that + If you want to process XSL-FO generated from XML using XSLT we recommend + again using standard JAXP to do the XSLT part and piping the generated SAX + events directly through to FOP. The only thing you'd change to do that on the basic usage pattern above is to set up the Transformer differently:

@@ -237,14 +237,14 @@ try {
Input Sources

- The input XSL-FO document is always received by FOP as a SAX stream (see the + The input XSL-FO document is always received by FOP as a SAX stream (see the Parsing Design Document for the rationale).

- However, you may not always have your input document available as a SAX stream. + However, you may not always have your input document available as a SAX stream. But with JAXP it's easy to convert different input sources to a SAX stream so you can pipe it into FOP. That sounds more difficult than it is. You simply have - to set up the right Source instance as input for the JAXP transformation. + to set up the right Source instance as input for the JAXP transformation. A few examples:

    @@ -273,8 +273,8 @@ try {

    There are a variety of upstream data manipulations possible. For example, you may have a DOM and an XSL stylesheet; or you may want to - set variables in the stylesheet. Interface documentation and some cookbook - solutions to these situations are provided in + set variables in the stylesheet. Interface documentation and some cookbook + solutions to these situations are provided in Xalan Basic Usage Patterns.

@@ -288,7 +288,7 @@ try { Customizing the FopFactory

The FopFactory holds configuration data and references to objects which are reusable over - multiple rendering runs. It's important to instantiate it only once (except in special + multiple rendering runs. It's important to instantiate it only once (except in special environments) and reuse it every time to create new FOUserAgent and Fop instances.

@@ -299,34 +299,34 @@ try {

The font base URL to use when resolving relative URLs for fonts. Example:

- fopFactory.setFontBaseURL("file:///C:/Temp/fonts"); + fopFactory.getFontManager().setFontBaseURL("file:///C:/Temp/fonts");
  • - The hyphenation base URL to use when resolving relative URLs for + The hyphenation base URL to use when resolving relative URLs for hyphenation patterns. Example:

    fopFactory.setHyphenBaseURL("file:///C:/Temp/hyph");
  • - Disable strict validation. When disabled FOP is less strict about the rules + Disable strict validation. When disabled FOP is less strict about the rules established by the XSL-FO specification. Example:

    fopFactory.setStrictValidation(false);
  • - Enable an alternative set of rules for text indents that tries to mimic the behaviour of many commercial - FO implementations, that chose to break the specification in this respect. The default of this option is - 'false', which causes Apache FOP to behave exactly as described in the specification. To enable the + Enable an alternative set of rules for text indents that tries to mimic the behaviour of many commercial + FO implementations, that chose to break the specification in this respect. The default of this option is + 'false', which causes Apache FOP to behave exactly as described in the specification. To enable the alternative behaviour, call:

    fopFactory.setBreakIndentInheritanceOnReferenceAreaBoundary(true);
  • - Set the source resolution for the document. This is used internally to determine the pixel + Set the source resolution for the document. This is used internally to determine the pixel size for SVG images and bitmap images without resolution information. Default: 72 dpi. Example:

    fopFactory.setSourceResolution(96); // =96dpi (dots/pixels per Inch) @@ -334,7 +334,7 @@ try {
  • Manually add an ElementMapping instance. If you want to supply a special FOP extension - you can give the instance to the FOUserAgent. Normally, the FOP extensions can be automatically detected + you can give the instance to the FOUserAgent. Normally, the FOP extensions can be automatically detected (see the documentation on extension for more info). Example:

    fopFactory.addElementMapping(myElementMapping); // myElementMapping is a org.apache.fop.fo.ElementMapping @@ -342,13 +342,13 @@ try {
  • Set a URIResolver for custom URI resolution. By supplying a JAXP URIResolver you can add - custom URI resolution functionality to FOP. For example, you can use + custom URI resolution functionality to FOP. For example, you can use Apache XML Commons Resolver to make use of XCatalogs. Example:

    fopFactory.setURIResolver(myResolver); // myResolver is a javax.xml.transform.URIResolver Both the FopFactory and the FOUserAgent have a method to set a URIResolver. The URIResolver on the FopFactory - is primarily used to resolve URIs on factory-level (hyphenation patterns, for example) and it is always used + is primarily used to resolve URIs on factory-level (hyphenation patterns, for example) and it is always used if no other URIResolver (for example on the FOUserAgent) resolved the URI first.
  • @@ -357,9 +357,9 @@ try {
    Customizing the User Agent

    - The user agent is the entity that allows you to interact with a single rendering run, i.e. the processing of a single + The user agent is the entity that allows you to interact with a single rendering run, i.e. the processing of a single document. If you wish to customize the user agent's behaviour, the first step is to create your own instance - of FOUserAgent using the appropriate factory method on FopFactory and pass that + of FOUserAgent using the appropriate factory method on FopFactory and pass that to the factory method that will create a new Fop instance:

  • - Set the target resolution for the document. This is used to - specify the output resolution for bitmap images generated by bitmap renderers - (such as the TIFF renderer) and by bitmaps generated by Apache Batik for filter + Set the target resolution for the document. This is used to + specify the output resolution for bitmap images generated by bitmap renderers + (such as the TIFF renderer) and by bitmaps generated by Apache Batik for filter effects and such. Default: 72 dpi. Example:

    userAgent.setTargetResolution(300); // =300dpi (dots/pixels per Inch)
  • - Set your own Renderer instance. If you want to supply your own renderer or + Set your own Renderer instance. If you want to supply your own renderer or configure a Renderer in a special way you can give the instance to the FOUserAgent. Normally, the Renderer instance is created by FOP. Example:

    @@ -433,8 +433,8 @@ try {
  • - Set your own FOEventHandler instance. If you want to supply your own FOEventHandler or - configure an FOEventHandler subclass in a special way you can give the instance to the FOUserAgent. Normally, + Set your own FOEventHandler instance. If you want to supply your own FOEventHandler or + configure an FOEventHandler subclass in a special way you can give the instance to the FOUserAgent. Normally, the FOEventHandler instance is created by FOP. Example:

    userAgent.setFOEventHandlerOverride(myFOEventHandler); // myFOEventHandler is an org.apache.fop.fo.FOEventHandler @@ -442,7 +442,7 @@ try {
  • Set a URIResolver for custom URI resolution. By supplying a JAXP URIResolver you can add - custom URI resolution functionality to FOP. For example, you can use + custom URI resolution functionality to FOP. For example, you can use Apache XML Commons Resolver to make use of XCatalogs. Example:

    userAgent.setURIResolver(myResolver); // myResolver is a javax.xml.transform.URIResolver @@ -462,7 +462,7 @@ try {
    Using a Configuration File

    - Instead of setting the parameters manually in code as shown above you can also set + Instead of setting the parameters manually in code as shown above you can also set many values from an XML configuration file:

    Fop instances shouldn't (and can't) be reused. Please recreate Fop and FOUserAgent instances for each rendering run using the FopFactory. - This is a cheap operation as all reusable information is held in the + This is a cheap operation as all reusable information is held in the FopFactory. That's why it's so important to reuse the FopFactory instance.

    @@ -515,12 +515,12 @@ fopFactory.setUserConfig(new File("C:/Temp/mycfg.xml"));]]>
    Getting information on the rendering process

    - To get the number of pages that were rendered by FOP you can call - Fop.getResults(). This returns a FormattingResults object - where you can look up the number of pages produced. It also gives you the - page-sequences that were produced along with their id attribute and their - numbers of pages. This is particularly useful if you render multiple - documents (each enclosed by a page-sequence) and have to know the number of + To get the number of pages that were rendered by FOP you can call + Fop.getResults(). This returns a FormattingResults object + where you can look up the number of pages produced. It also gives you the + page-sequences that were produced along with their id attribute and their + numbers of pages. This is particularly useful if you render multiple + documents (each enclosed by a page-sequence) and have to know the number of pages of each document.

    @@ -532,19 +532,19 @@ fopFactory.setUserConfig(new File("C:/Temp/mycfg.xml"));]]>

    • - Whenever possible, try to use SAX to couple the individual components involved + Whenever possible, try to use SAX to couple the individual components involved (parser, XSL transformer, SQL datasource etc.).
    • - Depending on the target OutputStream (in case of a FileOutputStream, but not - for a ByteArrayOutputStream, for example) it may improve performance considerably - if you buffer the OutputStream using a BufferedOutputStream: + Depending on the target OutputStream (in case of a FileOutputStream, but not + for a ByteArrayOutputStream, for example) it may improve performance considerably + if you buffer the OutputStream using a BufferedOutputStream: out = new java.io.BufferedOutputStream(out);
      Make sure you properly close the OutputStream when FOP is finished.
    • - Cache the stylesheet. If you use the same stylesheet multiple times + Cache the stylesheet. If you use the same stylesheet multiple times you can set up a JAXP Templates object and reuse it each time you do the XSL transformation. (More information can be found here.) @@ -570,7 +570,7 @@ fopFactory.setUserConfig(new File("C:/Temp/mycfg.xml"));]]> If you encounter any suspicious behaviour, please notify us.

      - There is also a known issue with fonts being jumbled between threads when using + There is also a known issue with fonts being jumbled between threads when using the Java2D/AWT renderer (which is used by the -awt and -print output options). In general, you cannot safely run multiple threads through the AWT renderer.

      @@ -578,7 +578,7 @@ fopFactory.setUserConfig(new File("C:/Temp/mycfg.xml"));]]>
      Examples

      - The directory "{fop-dir}/examples/embedding" contains several working examples. + The directory "{fop-dir}/examples/embedding" contains several working examples.

      ExampleFO2PDF.java @@ -592,104 +592,104 @@ file to PDF using FOP.
      ExampleXML2FO.java -

      This +

      This example -has nothing to do with FOP. It is there to show you how an XML +has nothing to do with FOP. It is there to show you how an XML file can be converted to XSL-FO using XSLT. The JAXP API is used to do the -transformation. Make sure you've got a JAXP-compliant XSLT processor in your +transformation. Make sure you've got a JAXP-compliant XSLT processor in your classpath (ex. Xalan).

      ExampleXML2PDF.java -

      This +

      This example -demonstrates how you can convert an arbitrary XML file to PDF -using XSLT and XSL-FO/FOP. It is a combination of the first two examples -above. The example uses JAXP to transform the XML file to XSL-FO and FOP to +demonstrates how you can convert an arbitrary XML file to PDF +using XSLT and XSL-FO/FOP. It is a combination of the first two examples +above. The example uses JAXP to transform the XML file to XSL-FO and FOP to transform the XSL-FO to PDF.

      -The output (XSL-FO) from the XSL transformation is piped through to FOP using -SAX events. This is the most efficient way to do this because the -intermediate result doesn't have to be saved somewhere. Often, novice users -save the intermediate result in a file, a byte array or a DOM tree. We -strongly discourage you to do this if it isn't absolutely necessary. The +The output (XSL-FO) from the XSL transformation is piped through to FOP using +SAX events. This is the most efficient way to do this because the +intermediate result doesn't have to be saved somewhere. Often, novice users +save the intermediate result in a file, a byte array or a DOM tree. We +strongly discourage you to do this if it isn't absolutely necessary. The performance is significantly higher with SAX.

      ExampleObj2XML.java -

      This +

      This example -is a preparatory example for the next one. It's an example that -shows how an arbitrary Java object can be converted to XML. It's an often -needed task to do this. Often people create a DOM tree from a Java object and +is a preparatory example for the next one. It's an example that +shows how an arbitrary Java object can be converted to XML. It's an often +needed task to do this. Often people create a DOM tree from a Java object and use that. This is pretty straightforward. The example here, however, shows how -to do this using SAX, which will probably be faster and not even more +to do this using SAX, which will probably be faster and not even more complicated once you know how this works.

      -For this example we've created two classes: ProjectTeam and ProjectMember -(found in xml-fop/examples/embedding/java/embedding/model). They represent -the same data structure found in -xml-fop/examples/embedding/xml/xml/projectteam.xml. We want to serialize to XML a -project team with several members which exist as Java objects. -Therefore we created the two classes: ProjectTeamInputSource and +For this example we've created two classes: ProjectTeam and ProjectMember +(found in xml-fop/examples/embedding/java/embedding/model). They represent +the same data structure found in +xml-fop/examples/embedding/xml/xml/projectteam.xml. We want to serialize to XML a +project team with several members which exist as Java objects. +Therefore we created the two classes: ProjectTeamInputSource and ProjectTeamXMLReader (in the same place as ProjectTeam above).

      -The XMLReader implementation (regard it as a special kind of XML parser) is -responsible for creating SAX events from the Java object. The InputSource +The XMLReader implementation (regard it as a special kind of XML parser) is +responsible for creating SAX events from the Java object. The InputSource class is only used to hold the ProjectTeam object to be used.

      -Have a look at the source of ExampleObj2XML.java to find out how this is -used. For more detailed information see other resources on JAXP (ex. +Have a look at the source of ExampleObj2XML.java to find out how this is +used. For more detailed information see other resources on JAXP (ex. An older JAXP tutorial).

      ExampleObj2PDF.java -

      This +

      This example -combines the previous and the third to demonstrate +combines the previous and the third to demonstrate how you can transform a Java object to a PDF directly in one smooth run -by generating SAX events from the Java object that get fed to an XSL -transformation. The result of the transformation is then converted to PDF +by generating SAX events from the Java object that get fed to an XSL +transformation. The result of the transformation is then converted to PDF using FOP as before.

      ExampleDOM2PDF.java -

      This +

      This example -has FOP use a DOMSource instead of a StreamSource in order to +has FOP use a DOMSource instead of a StreamSource in order to use a DOM tree as input for an XSL transformation.

      ExampleSVG2PDF.java (PDF Transcoder example) -

      This +

      This example -shows the usage of the PDF Transcoder, a sub-application within FOP. +shows the usage of the PDF Transcoder, a sub-application within FOP. It is used to generate a PDF document from an SVG file.

      Final notes

      -These examples should give you an idea of what's possible. It should be easy +These examples should give you an idea of what's possible. It should be easy to adjust these examples to your needs. Also, if you have other examples that you think should be added here, please let us know via either the fop-users or fop-dev mailing lists. Finally, for more help please send your questions to the fop-users -- cgit v1.2.3