KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > jsploader > CompileData


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.core.jsploader;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.net.URI JavaDoc;
25 import java.util.*;
26 import org.netbeans.modules.j2ee.deployment.devmodules.api.JSPServletFinder;
27 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
28 import org.netbeans.modules.web.api.webmodule.WebModule;
29
30 import org.openide.ErrorManager;
31
32 import org.openide.filesystems.*;
33
34 /** Data related to compilation attached to one JSP page.
35  * Basically a copy of the data retrieved from the compilation plugin.
36  * This data will change during the compilation process.
37  * This class is also responsible for translating File-view of compiled data to
38  * FileObject-view, including the creation of the necessary filesystems.
39  *
40  * @author Petr Jiricka
41  * @version
42  */

43 public class CompileData {
44
45     private JspDataObject jspPage;
46     private FileObject docRoot;
47     //private ServerInstance serverInstance;
48
private String JavaDoc servletEncoding;
49     
50     private final static boolean debug = false;
51     
52     private File JavaDoc servletJavaRoot;
53     private String JavaDoc servletResourceName;
54      
55
56     /** Creates new CompileData */
57     public CompileData(JspDataObject jspPage) {
58         this.jspPage = jspPage;
59         WebModule wm = WebModule.getWebModule (jspPage.getPrimaryFile());
60         if (wm != null) {
61             this.docRoot = wm.getDocumentBase ();
62             String JavaDoc jspResourcePath = JspCompileUtil.findRelativeContextPath(docRoot, jspPage.getPrimaryFile());
63             JSPServletFinder finder = JSPServletFinder.findJSPServletFinder (docRoot);
64             servletJavaRoot = finder.getServletTempDirectory();
65             servletResourceName = finder.getServletResourcePath(jspResourcePath);
66             servletEncoding = finder.getServletEncoding(jspResourcePath);
67         }
68     }
69     
70     public FileObject getServletJavaRoot() {
71         if ((servletJavaRoot != null) && servletJavaRoot.exists()) {
72             return FileUtil.toFileObject(servletJavaRoot);
73         }
74         else {
75             return null;
76         }
77     }
78     
79 /* public FileObject getServletJavaRoot() {
80         // PENDING - this is incorrect!!!
81         return WebModule.getWebModule (jspPage.getPrimaryFile ()).getJavaSourcesFolder ();
82     }*/

83     
84     public String JavaDoc getServletResourceName() {
85         return servletResourceName;
86     }
87     
88     private File JavaDoc getServletFile() {
89         if (servletJavaRoot == null) {
90             return null;
91         }
92         URI JavaDoc rootURI = servletJavaRoot.toURI();
93         URI JavaDoc servletURI = rootURI.resolve(servletResourceName);
94         return new File JavaDoc(servletURI);
95     }
96     
97     public FileObject getServletFileObject() {
98         FileObject root = getServletJavaRoot();
99         if (root == null) {
100             return null;
101         }
102         File JavaDoc servlet = getServletFile();
103         if ((servlet == null) || !servlet.exists()) {
104             return null;
105         }
106         
107         FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(servlet));
108         if (fo != null) {
109             return fo;
110         }
111         try {
112             FileSystem rootFs = root.getFileSystem();
113             root.getFileSystem().refresh(false);
114             return root.getFileObject(getServletResourceName());
115         }
116         catch (FileStateInvalidException e) {
117             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
118         }
119         
120         return null;
121     }
122     
123     
124     /** Returns encoding for the servlet generated from the JSP. */
125     public String JavaDoc getServletEncoding() {
126         return servletEncoding;
127     }
128     
129     public String JavaDoc toString() {
130         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
131         sb.append("--COMPILE DATA--"); // NOI18N
132
sb.append("\n"); // NOI18N
133
// sb.append("server : " + serverInstance); // NOI18N
134
// sb.append("\n"); // NOI18N
135
sb.append("JSP page : " + FileUtil.getFileDisplayName(jspPage.getPrimaryFile())); // NOI18N
136
sb.append("\n"); // NOI18N
137
sb.append("servletJavaRoot : " + servletJavaRoot + ", exists= " + // NOI18N
138
((servletJavaRoot == null) ? "false" : "" + servletJavaRoot.exists())); // NOI18N
139
sb.append("\n"); // NOI18N
140
sb.append("servletResource : " + servletResourceName + ", fileobject exists= " + // NOI18N
141
(getServletFileObject() != null)); // NOI18N
142
sb.append("\n"); // NOI18N
143
File JavaDoc sf = getServletFile();
144         if (sf != null) {
145             sb.append("servletFile : " + sf.getAbsolutePath() + ", exists= " + // NOI18N
146
getServletFile().exists()); // NOI18N
147
}
148         else {
149             sb.append("servletFile : null"); // NOI18N
150
}
151         sb.append("\n"); // NOI18N
152
sb.append("--end COMPILE DATA--"); // NOI18N
153
return sb.toString();
154     }
155     
156 }
157
Popular Tags