KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jasper > compiler > ExtractPageData


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.apache.jasper.compiler;
21
22 import java.io.FileNotFoundException JavaDoc;
23 import java.io.IOException JavaDoc;
24 import org.apache.jasper.JasperException;
25 import org.apache.jasper.JspCompilationContext;
26 import org.apache.jasper.Options;
27 import org.openide.ErrorManager;
28
29 /**
30  *
31  * @author Petr Jiricka
32  */

33 public class ExtractPageData {
34
35     protected JspCompilationContext ctxt;
36
37     protected Options options;
38     private CompilerHacks compHacks;
39
40     private boolean isXml;
41     private String JavaDoc sourceEnc;
42
43     /** Creates a new instance of ExtractPageData */
44     public ExtractPageData(JspCompilationContext ctxt) {
45         this.ctxt = ctxt;
46         this.options = ctxt.getOptions();
47         this.compHacks = new CompilerHacks(ctxt);
48     }
49     
50     
51     public boolean isXMLSyntax() throws JasperException, FileNotFoundException JavaDoc, IOException JavaDoc {
52         if (sourceEnc == null) {
53             extractPageData();
54         }
55         return isXml;
56     }
57
58     public String JavaDoc getEncoding() throws JasperException, FileNotFoundException JavaDoc, IOException JavaDoc {
59         if (sourceEnc == null) {
60             extractPageData();
61         }
62         return sourceEnc;
63     }
64
65     
66     private void extractPageData() throws JasperException, FileNotFoundException JavaDoc, IOException JavaDoc {
67         
68         // the following also sets up ErrorDispatcher and PageInfo in the compiler
69
Compiler JavaDoc comp = compHacks.getCompiler();
70         PageInfo pageInfo = comp.getPageInfo();
71         
72     JspConfig jspConfig = options.getJspConfig();
73     JspConfig.JspProperty jspProperty =
74             jspConfig.findJspProperty(ctxt.getJspFile());
75
76     /*
77      * If the current uri is matched by a pattern specified in
78      * a jsp-property-group in web.xml, initialize pageInfo with
79      * those properties.
80      */

81     pageInfo.setELIgnored(JspUtil.booleanValue(jspProperty.isELIgnored()));
82     pageInfo.setScriptingInvalid(JspUtil.booleanValue(jspProperty.isScriptingInvalid()));
83     if (jspProperty.getIncludePrelude() != null) {
84         pageInfo.setIncludePrelude(jspProperty.getIncludePrelude());
85     }
86     if (jspProperty.getIncludeCoda() != null) {
87         pageInfo.setIncludeCoda(jspProperty.getIncludeCoda());
88     }
89         /*String javaFileName = ctxt.getServletJavaFileName();
90
91         // Setup the ServletWriter
92         String javaEncoding = ctxt.getOptions().getJavaEncoding();
93     OutputStreamWriter osw = null;
94     try {
95         osw = new OutputStreamWriter(new FileOutputStream(javaFileName),
96                      javaEncoding);
97     } catch (UnsupportedEncodingException ex) {
98             errDispatcher.jspError("jsp.error.needAlternateJavaEncoding", javaEncoding);
99     }
100
101     ServletWriter writer = new ServletWriter(new PrintWriter(osw));
102         ctxt.setWriter(writer);*/

103
104         // Reset the temporary variable counter for the generator.
105
JspUtil.resetTemporaryVariableName();
106
107     // Parse the file
108
ParserControllerProxy parserCtl = new ParserControllerProxy(ctxt, comp);
109     parserCtl.extractSyntaxAndEncoding(ctxt.getJspFile());
110         
111         isXml = parserCtl.isXml;
112         sourceEnc = parserCtl.sourceEnc;
113     }
114     
115 }
116
Popular Tags