KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jspparser > TestUtil


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.jspparser;
21
22 import java.beans.PropertyVetoException JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26 import org.netbeans.api.java.classpath.ClassPath;
27 import org.netbeans.junit.Manager;
28 import org.netbeans.junit.NbTestCase;
29 import org.netbeans.modules.web.api.webmodule.WebModule;
30 import org.netbeans.modules.web.spi.webmodule.WebModuleImplementation;
31 import org.netbeans.modules.web.core.jsploader.JspParserAccess;
32 import org.netbeans.modules.web.jsps.parserapi.JspParserAPI;
33 import org.openide.ErrorManager;
34 import org.openide.filesystems.FileObject;
35 import org.openide.filesystems.FileUtil;
36 import org.openide.filesystems.Repository;
37
38 /**
39  *
40  * @author pj97932
41  */

42 class TestUtil {
43     
44     static FileObject getFileInWorkDir(String JavaDoc path, NbTestCase test) throws Exception JavaDoc {
45         File JavaDoc f = new File JavaDoc(Manager.getWorkDirPath());
46         FileObject workDirFO = FileUtil.fromFile(f)[0];
47         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(path, "/");
48         FileObject tempFile = workDirFO;
49         while (st.hasMoreTokens()) {
50             tempFile = tempFile.getFileObject(st.nextToken());
51         }
52         return tempFile;
53     }
54     
55      static JspParserAPI.WebModule getWebModule(FileObject fo){
56         WebModule wm = WebModule.getWebModule(fo);
57         if (wm == null) {
58             return null;
59         }
60         FileObject wmRoot = wm.getDocumentBase();
61         if (fo == wmRoot || FileUtil.isParentOf(wmRoot, fo)) {
62             return JspParserAccess.getJspParserWM(WebModule.getWebModule(fo));
63         }
64         return null;
65     }
66      
67     /*static JspParserAPI.WebModule getWebModule(FileObject wmRoot, FileObject jspFile) throws Exception {
68         WebModule wm = createWebModule(new UnpWarWebModuleImplementation(wmRoot));
69         return JspParserAccess.getJspParserWM(wm);
70     }
71     
72     private static WebModule createWebModule(WebModuleImplementation impl) throws Exception {
73         java.lang.reflect.Constructor c = WebModule.class.getDeclaredConstructor(
74             new Class[] {WebModuleImplementation.class});
75         c.setAccessible(true);
76         return (WebModule)c.newInstance(new Object[] {impl});
77     }
78     
79     static class UnpWarWebModuleImplementation implements WebModuleImplementation {
80         
81         private FileObject docBase;
82         private String contextPath;
83         
84         public UnpWarWebModuleImplementation(FileObject docBase) {
85             this.docBase = docBase;
86             contextPath = "";
87         }
88
89         public FileObject getDocumentBase () {
90             return docBase;
91         }
92     
93         public FileObject getJavaSourcesFolder () {
94             return docBase.getFileObject("WEB-INF/classes");
95         }
96     
97         public String getContextPath () {
98             return contextPath;
99         }
100     
101         public void setContextPath (String path) {
102             this.contextPath = path;
103         }
104         
105         public String getJ2eePlatformVersion (){
106             return "";
107         }
108         
109         public ClassPath getJavaSources (){
110             return null;
111         }
112     }*/

113     
114 }
115
Popular Tags