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 PS 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 ConvertPS extends Convert {
48  
49  	/***
50  	 * Convert a <code>p_cv</code> CvModel to a PS <code>p_file</code> file.
51  	 * 
52  	 * @param p_cv
53  	 *            CVModel object
54  	 * @param p_file
55  	 *            file, will be written/overwritten
56  	 * @throws XmlCVException
57  	 */
58  	public ConvertPS(CVModel p_cv, File p_file) throws XmlCVException {
59  		super(new StreamSource(p_cv.getInputStream()), p_file);
60  		this.go();
61  	}
62  
63  	public void go() {
64  		// Construct driver and output format
65  		Driver fop = new Driver();
66  		fop.setRenderer(Driver.RENDER_PS);
67  
68  		try {
69  			setXslt(Config.STYLES_XSL_FO);
70  			setupTransformer();
71  
72  			fop.setOutputStream(this._doneStream);
73  
74  			// Resulting SAX events (the generated FO) must be piped through to
75  			// FOP
76  			SAXResult res = new SAXResult(fop.getContentHandler());
77  
78  			// Start XSLT transformation and FOP processing
79  			this._transformer.transform(this._srcXml, res);
80  		} catch (TransformerException e) {
81  			e.printStackTrace();
82  		} finally {
83  			try {
84  				this._doneStream.close();
85  			} catch (IOException e1) {
86  				e1.printStackTrace();
87  			}
88  		}
89  	}
90  
91  	public static void main(String[] args) throws XmlCVException {
92  		if (args.length != 2) {
93  			System.out.println(I18n.getString("Convert.WrongParameters")); //$NON-NLS-1$
94  			System.out.println(I18n.getString("ConvertPS.Usage")); //$NON-NLS-1$
95  		} else {
96  			CVModel cv = new CVModel(args[0]);
97  			new ConvertPS(cv, new File(args[1]));
98  		}
99  	}
100 
101 }