KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > ant > JspCSingle


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.project.ant;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.PrintWriter JavaDoc;
25 import java.util.LinkedList JavaDoc;
26 import java.util.StringTokenizer JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import org.apache.jasper.JasperException;
29 import org.apache.tools.ant.BuildException;
30 import org.apache.tools.ant.PathTokenizer;
31 import org.apache.tools.ant.Task;
32 import org.apache.tools.ant.Project;
33 import org.apache.tools.ant.types.FileSet;
34
35 /**
36  * Ant task that extends org.apache.jasper.JspC to allow calling single file
37  * compilation from Ant.
38  *
39  * @author Pavel Buzek
40  */

41 public class JspCSingle extends JspC {
42
43     public static final String JavaDoc FILES_PARAM = "-jspc.files";
44     public static final String JavaDoc URIROOT_PARAM = "-uriroot";
45     
46     /*
47     private static PrintWriter debugwriter = null;
48     private static void debug(String s) {
49         if (debugwriter == null) {
50             try {
51                 debugwriter = new PrintWriter(new java.io.FileWriter("c:\\temp\\JspCSingle.log")); // NOI18N
52             } catch (java.io.IOException ioe) {
53                 return;
54             }
55         }
56         debugwriter.println(s);
57         debugwriter.flush();
58     }
59     */

60     
61     public static void main(String JavaDoc args[]) {
62         ArrayList JavaDoc newArgs = new ArrayList JavaDoc();
63         String JavaDoc uriRoot = null;
64         for (int i = 0; i < args.length; i++) {
65             String JavaDoc p = args[i];
66             
67             // -uriroot
68
if (URIROOT_PARAM.equals(p)) {
69                 newArgs.add(p);
70                 i++;
71                 if (i < args.length) {
72                     uriRoot = args[i];
73                     newArgs.add(uriRoot);
74                 }
75                 continue;
76             }
77             
78             // -jspc.files
79
if (FILES_PARAM.equals(p)) {
80                 i++;
81                 if (i < args.length) {
82                     p = args[i];
83                     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(p, File.pathSeparator);
84                     while (st.hasMoreTokens()) {
85                         if (uriRoot != null) {
86                             //File f = new File(uriRoot, st.nextToken());
87
//newArgs.add(f.getAbsolutePath());
88
newArgs.add(st.nextToken());
89                         }
90                     }
91                 }
92                 continue;
93             }
94             
95             // other
96
newArgs.add(p);
97         }
98         String JavaDoc newArgsS[] = (String JavaDoc[])newArgs.toArray(new String JavaDoc[newArgs.size()]);
99         
100         JspC.main(newArgsS);
101     }
102     
103     private String JavaDoc uriroot;
104     private String JavaDoc jspFiles;
105     
106     public void setUriroot( String JavaDoc s ) {
107         this.uriroot = s;
108         super.setUriroot ( s );
109         setPages ();
110     }
111     
112     public void setJspIncludes (String JavaDoc jspFiles) throws BuildException {
113         this.jspFiles = jspFiles;
114         setPages ();
115     }
116     
117     private void setPages () throws BuildException {
118         if (uriroot != null && jspFiles != null) {
119             try {
120                 StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc (jspFiles, " ,"); //NOI18N
121
LinkedList JavaDoc list = new LinkedList JavaDoc ();
122                 while (tok.hasMoreTokens ()) {
123                     String JavaDoc jsp = uriroot + "/" + tok.nextToken ();
124                     list.add (jsp);
125                 }
126                 setArgs( (String JavaDoc []) list.toArray (new String JavaDoc[list.size ()]));
127             } catch (JasperException e) {
128                 throw new BuildException (e);
129             }
130         }
131     }
132     
133    
134 }
135
Popular Tags