View Javadoc

1   /*
2    * XMLCV - Gestion de CV sous forme XML
3    * 
4    * Copyright (C) 2004-2005, Damien Raude-Morvan
5    * 
6    * This file is part of XMLCV.
7    *
8    * XMLCV is free software; you can redistribute it and/or modify
9    * it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * XMLCV is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   *
18   * You should have received a copy of the GNU General Public License
19   * along with XMLCV; if not, write to the Free Software
20   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21   * 
22   * Contacts :
23   * - Sébastien Mathy <smathy@tuxfamily.org>
24   * - Emmanuel Berre <eberre@tuxfamily.org>
25   * - Damien Raude-Morvan <drazzib@drazzib.com>
26   */
27  package org.xmlcv;
28  
29  import java.io.File;
30  import java.io.IOException;
31  
32  import javax.xml.transform.TransformerException;
33  import javax.xml.transform.sax.SAXResult;
34  import javax.xml.transform.stream.StreamSource;
35  
36  import org.apache.fop.apps.Driver;
37  import org.xmlcv.util.Config;
38  import org.xmlcv.util.I18n;
39  
40  /***
41   * Thread for RTF convertion
42   * 
43   * @see org.xmlcv.Convert
44   * @version $Revision: 114 $
45   * @author <a href="mailto:drazzib@drazzib.com">Damien Raude-Morvan </a>
46   */
47  public class ConvertRTF extends Convert {
48  
49  	/***
50  	 * Convert a <code>p_cv</code> CvModel to a RTF <code>p_file</code>
51  	 * file.
52  	 * 
53  	 * @param p_cv
54  	 *            CVModel object
55  	 * @param p_file
56  	 *            file, will be written/overwritten
57  	 * @throws XmlCVException
58  	 */
59  	public ConvertRTF(CVModel p_cv, File p_file) throws XmlCVException {
60  		super(new StreamSource(p_cv.getInputStream()), p_file);
61  		this.go();
62  	}
63  
64  	public void go() {
65  		// Construct driver and output format
66  		Driver fop = new Driver();
67  		// FIXME
68  		fop.setRenderer(Driver.RENDER_TXT);
69  
70  		try {
71  			setXslt(Config.STYLES_XSL_FO);
72  			setupTransformer();
73  
74  			fop.setOutputStream(this._doneStream);
75  
76  			// Resulting SAX events (the generated FO) must be piped through to
77  			// FOP
78  			SAXResult res = new SAXResult(fop.getContentHandler());
79  
80  			// Start XSLT transformation and FOP processing
81  			this._transformer.transform(this._srcXml, res);
82  		} catch (TransformerException e) {
83  			e.printStackTrace();
84  		} finally {
85  			try {
86  				this._doneStream.close();
87  			} catch (IOException e1) {
88  				e1.printStackTrace();
89  			}
90  		}
91  	}
92  
93  	public static void main(String[] args) throws XmlCVException {
94  		if (args.length != 2) {
95  			System.out.println(I18n.getString("Convert.WrongParameters")); //$NON-NLS-1$
96  			System.out.println(I18n.getString("ConvertRTF.Usage")); //$NON-NLS-1$
97  		} else {
98  			CVModel cv = new CVModel(args[0]);
99  			new ConvertRTF(cv, new File(args[1]));
100 		}
101 	}
102 
103 }