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.stream.StreamResult;
34  import javax.xml.transform.stream.StreamSource;
35  
36  import org.xmlcv.util.Config;
37  import org.xmlcv.util.I18n;
38  
39  /***
40   * Thread for HTML convertion
41   * 
42   * @see org.xmlcv.Convert
43   * @version $Revision: 114 $
44   * @author <a href="mailto:drazzib@drazzib.com">Damien Raude-Morvan </a>
45   */
46  public class ConvertHTML extends Convert {
47  
48  	/***
49  	 * Convert a <code>p_cv</code> CvModel to a HTML <code>p_file</code>
50  	 * 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 ConvertHTML(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  
65  		try {
66  			setXslt(Config.STYLES_XSL);
67  			setupTransformer();
68  
69  			StreamResult res = new StreamResult(this._doneStream);
70  
71  			// Start XSLT transformation
72  			this._transformer.transform(this._srcXml, res);
73  
74  		} catch (TransformerException e) {
75  			e.printStackTrace();
76  		} finally {
77  			try {
78  				this._doneStream.close();
79  			} catch (IOException e1) {
80  				e1.printStackTrace();
81  			}
82  		}
83  	}
84  
85  	public static void main(String[] args) throws XmlCVException {
86  		if (args.length != 2) {
87  			System.out.println(I18n.getString("Convert.WrongParameters")); //$NON-NLS-1$
88  			System.out.println(I18n.getString("ConvertHTML.Usage")); //$NON-NLS-1$
89  		} else {
90  			CVModel cv = new CVModel(args[0]);
91  			new ConvertHTML(cv, new File(args[1]));
92  		}
93  	}
94  
95  }