KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > cli > AreaTreeInputHandler


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id$ */
19
20 package org.apache.fop.cli;
21
22 import java.io.File JavaDoc;
23 import java.io.OutputStream JavaDoc;
24 import java.util.Vector JavaDoc;
25
26 import javax.xml.transform.Result JavaDoc;
27 import javax.xml.transform.sax.SAXResult JavaDoc;
28
29 import org.apache.fop.apps.FOPException;
30 import org.apache.fop.apps.FOUserAgent;
31 import org.apache.fop.area.AreaTreeModel;
32 import org.apache.fop.area.AreaTreeParser;
33 import org.apache.fop.area.RenderPagesModel;
34 import org.apache.fop.fonts.FontInfo;
35 import org.xml.sax.SAXException JavaDoc;
36
37 /**
38  * InputHandler for the area tree XML (intermediate format) as input.
39  */

40 public class AreaTreeInputHandler extends InputHandler {
41
42     /**
43      * Constructor for XML->XSLT->area tree XML input
44      * @param xmlfile XML file
45      * @param xsltfile XSLT file
46      * @param params Vector of command-line parameters (name, value,
47      * name, value, ...) for XSL stylesheet, null if none
48      */

49     public AreaTreeInputHandler(File JavaDoc xmlfile, File JavaDoc xsltfile, Vector JavaDoc params) {
50         super(xmlfile, xsltfile, params);
51     }
52
53     /**
54      * Constructor for area tree XML input
55      * @param atfile the file to read the area tree document.
56      */

57     public AreaTreeInputHandler(File JavaDoc atfile) {
58         super(atfile);
59     }
60
61     /** @see org.apache.fop.cli.InputHandler */
62     public void renderTo(FOUserAgent userAgent, String JavaDoc outputFormat, OutputStream JavaDoc out)
63                 throws FOPException {
64         FontInfo fontInfo = new FontInfo();
65         AreaTreeModel treeModel = new RenderPagesModel(userAgent,
66                 outputFormat, fontInfo, out);
67         
68         //Iterate over all intermediate files
69
AreaTreeParser parser = new AreaTreeParser();
70         
71         // Resulting SAX events (the generated FO) must be piped through to FOP
72
Result JavaDoc res = new SAXResult JavaDoc(parser.getContentHandler(treeModel, userAgent));
73
74         transformTo(res);
75         
76         try {
77             treeModel.endDocument();
78         } catch (SAXException JavaDoc e) {
79             throw new FOPException(e);
80         }
81     }
82
83 }
84
Popular Tags