001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.web.core.jsploader;
043:
044: import java.io.File;
045: import java.net.URI;
046: import java.util.*;
047: import java.util.logging.Level;
048: import java.util.logging.Logger;
049: import org.netbeans.modules.j2ee.deployment.devmodules.api.JSPServletFinder;
050: import org.netbeans.modules.web.api.webmodule.WebModule;
051:
052: import org.openide.filesystems.*;
053:
054: /** Data related to compilation attached to one JSP page.
055: * Basically a copy of the data retrieved from the compilation plugin.
056: * This data will change during the compilation process.
057: * This class is also responsible for translating File-view of compiled data to
058: * FileObject-view, including the creation of the necessary filesystems.
059: *
060: * @author Petr Jiricka
061: * @version
062: */
063: public class CompileData {
064:
065: private JspDataObject jspPage;
066: private FileObject docRoot;
067: //private ServerInstance serverInstance;
068: private String servletEncoding;
069:
070: private final static boolean debug = false;
071:
072: private File servletJavaRoot;
073: private String servletResourceName;
074:
075: /** Creates new CompileData */
076: public CompileData(JspDataObject jspPage) {
077: this .jspPage = jspPage;
078: WebModule wm = WebModule.getWebModule(jspPage.getPrimaryFile());
079: if (wm != null) {
080: this .docRoot = wm.getDocumentBase();
081: String jspResourcePath = JspCompileUtil
082: .findRelativeContextPath(docRoot, jspPage
083: .getPrimaryFile());
084: JSPServletFinder finder = JSPServletFinder
085: .findJSPServletFinder(docRoot);
086: servletJavaRoot = finder.getServletTempDirectory();
087: servletResourceName = finder
088: .getServletResourcePath(jspResourcePath);
089: servletEncoding = finder
090: .getServletEncoding(jspResourcePath);
091: }
092: }
093:
094: public FileObject getServletJavaRoot() {
095: if ((servletJavaRoot != null) && servletJavaRoot.exists()) {
096: return FileUtil.toFileObject(servletJavaRoot);
097: } else {
098: return null;
099: }
100: }
101:
102: /* public FileObject getServletJavaRoot() {
103: // PENDING - this is incorrect!!!
104: return WebModule.getWebModule (jspPage.getPrimaryFile ()).getJavaSourcesFolder ();
105: }*/
106:
107: public String getServletResourceName() {
108: return servletResourceName;
109: }
110:
111: private File getServletFile() {
112: if (servletJavaRoot == null) {
113: return null;
114: }
115: URI rootURI = servletJavaRoot.toURI();
116: URI servletURI = rootURI.resolve(servletResourceName);
117: return new File(servletURI);
118: }
119:
120: public FileObject getServletFileObject() {
121: FileObject root = getServletJavaRoot();
122: if (root == null) {
123: return null;
124: }
125: File servlet = getServletFile();
126: if ((servlet == null) || !servlet.exists()) {
127: return null;
128: }
129:
130: FileObject fo = FileUtil.toFileObject(FileUtil
131: .normalizeFile(servlet));
132: if (fo != null) {
133: return fo;
134: }
135: try {
136: FileSystem rootFs = root.getFileSystem();
137: root.getFileSystem().refresh(false);
138: return root.getFileObject(getServletResourceName());
139: } catch (FileStateInvalidException e) {
140: Logger.getLogger("global").log(Level.INFO, null, e);
141: }
142:
143: return null;
144: }
145:
146: /** Returns encoding for the servlet generated from the JSP. */
147: public String getServletEncoding() {
148: return servletEncoding;
149: }
150:
151: public String toString() {
152: StringBuffer sb = new StringBuffer();
153: sb.append("--COMPILE DATA--"); // NOI18N
154: sb.append("\n"); // NOI18N
155: // sb.append("server : " + serverInstance); // NOI18N
156: // sb.append("\n"); // NOI18N
157: sb
158: .append("JSP page : "
159: + FileUtil.getFileDisplayName(jspPage
160: .getPrimaryFile())); // NOI18N
161: sb.append("\n"); // NOI18N
162: sb.append("servletJavaRoot : "
163: + servletJavaRoot
164: + ", exists= "
165: + // NOI18N
166: ((servletJavaRoot == null) ? "false" : ""
167: + servletJavaRoot.exists())); // NOI18N
168: sb.append("\n"); // NOI18N
169: sb.append("servletResource : " + servletResourceName
170: + ", fileobject exists= " + // NOI18N
171: (getServletFileObject() != null)); // NOI18N
172: sb.append("\n"); // NOI18N
173: File sf = getServletFile();
174: if (sf != null) {
175: sb.append("servletFile : " + sf.getAbsolutePath()
176: + ", exists= " + // NOI18N
177: getServletFile().exists()); // NOI18N
178: } else {
179: sb.append("servletFile : null"); // NOI18N
180: }
181: sb.append("\n"); // NOI18N
182: sb.append("--end COMPILE DATA--"); // NOI18N
183: return sb.toString();
184: }
185:
186: }
|