View Javadoc

1   /*   Copyright (C) 2004 Finalist IT Group
2    *
3    *   This file is part of JAG - the Java J2EE Application Generator
4    *
5    *   JAG is free software; you can redistribute it and/or modify
6    *   it under the terms of the GNU General Public License as published by
7    *   the Free Software Foundation; either version 2 of the License, or
8    *   (at your option) any later version.
9    *   JAG is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *   GNU General Public License for more details.
13   *   You should have received a copy of the GNU General Public License
14   *   along with JAG; if not, write to the Free Software
15   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16   */
17  
18  package com.finalist.ant.tasks.docbook;
19  
20  import javax.xml.transform.Transformer;
21  import javax.xml.transform.TransformerConfigurationException;
22  import javax.xml.transform.TransformerException;
23  import javax.xml.transform.sax.SAXSource;
24  import javax.xml.transform.stream.StreamResult;
25  
26  import org.apache.tools.ant.BuildException;
27  import org.xml.sax.InputSource;
28  import org.xml.sax.SAXException;
29  import org.xml.sax.XMLReader;
30  import org.xml.sax.helpers.XMLReaderFactory;
31  
32  
33  
34  /***
35   * <code>HTMLTask.java</code>
36   *
37   *	This task extends the AbstractDocBookTask
38   * It does the transformation of the docbook file to a html file
39   *
40   * @author Stefan Lenselink
41   * @version $Revision: 1.1 $
42   */
43  
44  public class HTMLTask extends AbstractDocBookTask {
45  
46  
47  	/***
48  	 * This method actually transforms the Docbook file to a html file
49  	 * 
50  	 * @see com.finalist.ant.tasks.AbstractDocBookTask#execute()
51  	 */
52  	public void execute() throws BuildException {
53  		try {
54  			//Get the Transformer
55  			Transformer transformer = getTransformer();
56  			
57  			//Set the Draft watermark image to local to prevent error while creating pdf
58  
59  			//Set the parameters
60  			doSetParameter(transformer);
61  			
62  			XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.crimson.parser.XMLReaderImpl");
63  			reader.setEntityResolver(new DTDResolver());
64  			
65  			for(int i = 0; i < getNumberOfCycles(); i++){
66  				StreamResult result = new StreamResult(getOutputFile("html"));
67  				SAXSource source = new SAXSource(reader, new InputSource( getDocbookfile()));
68  				transformer.transform(source, result);
69  			}
70  			
71  		} catch (TransformerConfigurationException e) {
72  			//System.out.println(); needed to tel the use that we recieved a problem
73  			System.out.println("Error while setting a Configuration Option " + e.toString());
74  		} catch (TransformerException e) {
75  			//System.out.println(); needed to tel the use that we recieved a problem
76  			e.printStackTrace();
77  			System.out.println("Error while transforming the docbook file to HTML " + e.toString());
78  //		} catch (FileNotFoundException e){
79  //			System.out.println("Cann't find output file " + e.toString());
80  		} catch (SAXException e){
81  			System.out.println("Faild to load the docbook file " + e.toString());
82  		}
83  	}
84  }
85  
86  
87  /*
88   * $Log: HTMLTask.java,v $
89   * Revision 1.1  2004/03/12 22:16:00  ekkelenkamp
90   * no message
91   *
92   * Revision 1.3  2004/01/14 14:40:13  stefan
93   * Added support for nested filesets, see manual for details
94   *
95   * Revision 1.2  2004/01/06 13:26:39  stefan
96   * Added local dtd support and local watermark image support, now it's independent from the Internet
97   *
98   * Revision 1.1  2003/12/29 15:46:41  stefan
99   * initial checkin of the DocBook Ant Task
100  *
101  *
102  */