KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > cpp > lib > PreprocessorJPP


1 /*====================================================================
2
3 ObjectWeb Util Preprocessor Package.
4 Copyright (C) 2004 INRIA & USTL - LIFL - GOAL
5 Contact: architecture@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 --------------------------------------------------------------------
26 $Id: PreprocessorJPP.java,v 1.1 2004/02/05 20:29:57 rouvoy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.cpp.lib;
30
31 import java.io.File JavaDoc;
32 import java.io.FileNotFoundException JavaDoc;
33 import java.io.FileOutputStream JavaDoc;
34 import java.io.IOException JavaDoc;
35 import java.io.OutputStream JavaDoc;
36 import java.util.Hashtable JavaDoc;
37 import java.util.Vector JavaDoc;
38
39 import org.objectweb.util.misc.api.ExceptionWrapper;
40
41
42 /**
43  * This provides a preprocessor written in Java.
44  *
45  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
46  * @version 0.1
47  */

48 public class PreprocessorJPP
49      extends PreprocessorBase
50 {
51     // ==================================================================
52
//
53
// Internal state.
54
//
55
// ==================================================================
56

57     // ==================================================================
58
//
59
// Constructor.
60
//
61
// ==================================================================
62

63     /** The default constructor. */
64     public PreprocessorJPP() {
65     }
66
67     // ==================================================================
68
//
69
// Internal methods.
70
//
71
// ==================================================================
72

73     // ==================================================================
74
//
75
// Public methods for org.objectweb.util.cpp.api.Preprocessor
76
//
77
// ==================================================================
78

79     /**
80      * Preprocesses a file.
81      *
82      * @param fileName The name of the file to preprocess.
83      * @param tmpFile The file containing the output file.
84      *
85      * @return True if OK.
86      */

87     public boolean preprocess(String JavaDoc fileName, File JavaDoc tmpFile) {
88         FileOutputStream JavaDoc output = null;
89         try {
90             // Creates an output stream on this temp file.
91
output = new FileOutputStream JavaDoc(tmpFile);
92         } catch(IOException JavaDoc exc) {
93             // Wraps any java.io.IOException exception.
94
throw new ExceptionWrapper(exc);
95         }
96
97         boolean status = false;
98         try {
99             // Preprocesses.
100
status = preprocess(fileName, output);
101         } finally {
102             // Always closes the stream.
103
IOHelper.close(output);
104         }
105         
106         return status;
107     }
108
109     /**
110      * Preprocesses a file.
111      *
112      * @param fileName The name of the file to preprocess.
113      * @param output The output stream.
114      */

115     public boolean preprocess(String JavaDoc fileName, OutputStream JavaDoc output) {
116         try {
117             // Creates the preprocessor.
118
JPP jpp = new JPP(fileName, output,
119                               ((Vector JavaDoc)includeDirectories_.clone()),
120                               ((Hashtable JavaDoc)macros_.clone()));
121             // Preprocesses.
122
return jpp.preprocess();
123         } catch(FileNotFoundException JavaDoc exc) {
124             getConsole().error(fileName + ": No such file or directory");
125             return false;
126         } catch(IOException JavaDoc exc) {
127             throw new ExceptionWrapper(exc);
128         }
129     }
130 }
131
Popular Tags