KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import javax.swing.text.Document JavaDoc;
25 import java.net.URLClassLoader JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.StringTokenizer JavaDoc;
30
31 import org.openide.ErrorManager;
32 import org.openide.util.Lookup;
33 import org.openide.filesystems.FileObject;
34 import org.openide.text.CloneableEditorSupport;
35
36 import org.netbeans.modules.web.jsps.parserapi.JspParserFactory;
37 import org.netbeans.modules.web.jsps.parserapi.JspParserAPI;
38 import org.netbeans.modules.web.core.syntax.spi.JSPColoringData;
39 import org.netbeans.modules.web.core.syntax.spi.JspContextInfo;
40 import org.netbeans.modules.web.api.webmodule.WebModule;
41 import org.openide.filesystems.FileStateInvalidException;
42 import org.openide.loaders.DataObject;
43 import org.openide.loaders.DataNode;
44
45 public class JspContextInfoImpl extends JspContextInfo {
46     
47     public JspContextInfoImpl() {
48     }
49     
50     private static TagLibParseSupport getTagLibParseSupport(Document JavaDoc doc, FileObject fo){
51         TagLibParseSupport tlps = null;
52         if (fo != null && fo.isValid()){
53             try {
54                 tlps = (TagLibParseSupport)DataObject.find(fo).getCookie(TagLibParseSupport.class);
55             }
56             catch (org.openide.loaders.DataObjectNotFoundException e){
57                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
58             }
59         }
60         return tlps;
61     }
62     
63     public URLClassLoader JavaDoc getModuleClassLoader(Document JavaDoc doc, FileObject fo){
64         return JspParserFactory.getJspParser().getModuleClassLoader(JspParserAccess.getJspParserWM (WebModule.getWebModule (fo)));
65     }
66     
67     /** Returns the taglib map as returned by the parser, taking data from the editor as parameters.
68      * Returns null in case of a failure (exception, no web module, no parser etc.)
69      */

70     public Map JavaDoc getTaglibMap(Document JavaDoc doc, FileObject fo) {
71         try {
72             JspParserAPI parser = JspParserFactory.getJspParser();
73             if (parser == null) {
74                 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL,
75                 new NullPointerException JavaDoc());
76             }
77             else {
78                 return parser.getTaglibMap(JspParserAccess.getJspParserWM (WebModule.getWebModule (fo)));
79             }
80         }
81         catch (IOException JavaDoc e) {
82             ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, e);
83         }
84         return null;
85     }
86     
87     /** This method returns an image, which is displayed for the FileObject in the explorer.
88      * It is used to display objects in editor (e.g. in code completion).
89      * @param doc This is the documet, in which the icon will be used (for exmaple for completion).
90      * @param fo file object for which the icon is looking for
91      * @return an Image which is dislayed in the explorer for the file.
92      */

93     public java.awt.Image JavaDoc getIcon(Document JavaDoc doc, FileObject fo){
94         
95         java.awt.Image JavaDoc icon = null;
96         
97         try {
98             icon = DataObject.find(fo).getNodeDelegate().getIcon(java.beans.BeanInfo.ICON_COLOR_16x16);
99         }
100         catch(org.openide.loaders.DataObjectNotFoundException e) {
101             e.printStackTrace(System.out);
102         }
103         
104         return icon;
105     }
106     
107    
108     public JspParserAPI.ParseResult getCachedParseResult (Document JavaDoc doc, FileObject fo, boolean successfulOnly, boolean preferCurrent, boolean forceParse) {
109         TagLibParseSupport sup = getTagLibParseSupport (doc, fo);
110         if (sup != null) {
111             return sup.getCachedParseResult (successfulOnly, preferCurrent, forceParse);
112         }
113         return null;
114     }
115     
116     public JspParserAPI.ParseResult getCachedParseResult (Document JavaDoc doc, FileObject fo, boolean successfulOnly, boolean preferCurrent) {
117         return getCachedParseResult(doc, fo, successfulOnly, preferCurrent, false);
118     }
119     
120     public JSPColoringData getJSPColoringData (Document JavaDoc doc, FileObject fo) {
121         TagLibParseSupport sup = getTagLibParseSupport (doc, fo);
122         if (sup != null) {
123             return sup.getJSPColoringData ();
124         }
125         return null;
126     }
127     
128     public org.netbeans.modules.web.jsps.parserapi.JspParserAPI.JspOpenInfo getCachedOpenInfo(Document JavaDoc doc, FileObject fo, boolean preferCurrent) {
129         TagLibParseSupport sup = getTagLibParseSupport (doc, fo);
130         if (sup != null) {
131             return sup.getCachedOpenInfo(preferCurrent, true);
132         }
133         return null;
134     }
135     
136     public FileObject guessWebModuleRoot (Document JavaDoc doc, FileObject fo) {
137         WebModule wm = WebModule.getWebModule (fo);
138         if (wm != null)
139             return wm.getDocumentBase ();
140         return null;
141     }
142 }
Popular Tags