KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > syntax > spi > JspContextInfo


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.syntax.spi;
21
22 import java.util.Hashtable JavaDoc;
23 import javax.swing.text.Document JavaDoc;
24 import java.net.URLClassLoader JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.openide.filesystems.FileObject;
28
29 import org.netbeans.modules.web.jsps.parserapi.JspParserAPI;
30 import org.openide.ErrorManager;
31 import org.openide.cookies.InstanceCookie;
32 import org.openide.filesystems.Repository;
33 import org.openide.loaders.DataFolder;
34 import org.openide.loaders.DataObject;
35 import org.openide.loaders.DataObjectNotFoundException;
36 //import org.netbeans.api.registry.Context;
37
import org.openide.util.NbBundle;
38
39 /** The JspContextInfo can be implemented with other modules,
40  * which want to reuse the JSPKit for coloring their documents.
41  * One example can be Facelets. Facelets are mix of xhtml,
42  * jsf and facelets tags. The editor for Facelets can looks
43  * as the editor for jsp, but the data for code completion
44  * and the syntax highlighting (user tags) are not obtained
45  * from jspparser, but are counted externally. You can supply
46  * your data through your implementation of this class.
47  * Your implementation has to be registered on default
48  * file system (in layer file) in the folder
49  * /J2EE/JSPSyntaxColoring/${file_type_mimetype}.
50  *
51  * For every mimetype is obtained only one instance.
52  */

53 public abstract class JspContextInfo {
54     
55     /** Name of the settings context where an instance of this class should be registered */
56     public static final String JavaDoc CONTEXT_NAME = "/J2EE/JSPSyntaxColoring/"; //NOI18N
57

58     private static Hashtable JavaDoc <String JavaDoc, JspContextInfo> instances = new Hashtable JavaDoc();
59     
60     public static synchronized JspContextInfo getContextInfo( FileObject fo ) {
61         if (fo == null){
62             return null;
63         }
64         JspContextInfo instance = instances.get(fo.getMIMEType());
65         
66         if (instance == null) {
67             FileObject f = Repository.getDefault().getDefaultFileSystem().findResource(CONTEXT_NAME + fo.getMIMEType()); // NOI18N
68
if (f != null) {
69                 try {
70                     DataFolder folder = (DataFolder)DataObject.find(f).getCookie(DataFolder.class);
71                     DataObject[] dobjs = folder.getChildren();
72                     
73                     for (int i = 0; i < dobjs.length; i ++){
74                         InstanceCookie ic = (InstanceCookie)dobjs[i].getCookie(InstanceCookie.class);
75                         Object JavaDoc o = ic.instanceCreate();
76                         if (o instanceof JspContextInfo){
77                             instance = (JspContextInfo)o;
78                             instances.put(fo.getMIMEType(), instance);
79                             continue;
80                         }
81                     }
82                 } catch (DataObjectNotFoundException ex) {
83                     ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
84                 } catch (java.io.IOException JavaDoc ex) {
85                     ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
86                 } catch (java.lang.ClassNotFoundException JavaDoc ex){
87                     ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
88                 }
89             }
90             if (instance == null) {
91                 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION,
92                         new Exception JavaDoc(NbBundle.getBundle(JspContextInfo.class).getString("EXC_JspContextInfoNotInstalled")));
93             }
94         }
95         return instance;
96     }
97     
98     public abstract JSPColoringData getJSPColoringData(Document JavaDoc doc, FileObject fo);
99     
100     public abstract JspParserAPI.ParseResult getCachedParseResult(Document JavaDoc doc, FileObject fo, boolean successfulOnly, boolean preferCurrent, boolean forceReload);
101     
102     public abstract JspParserAPI.ParseResult getCachedParseResult(Document JavaDoc doc, FileObject fo, boolean successfulOnly, boolean preferCurrent);
103     
104     public abstract JspParserAPI.JspOpenInfo getCachedOpenInfo(Document JavaDoc doc, FileObject fo, boolean preferCurrent);
105     
106     public abstract URLClassLoader JavaDoc getModuleClassLoader(Document JavaDoc doc, FileObject fo);
107     
108     /** Returns the root of the web module containing the given file object.
109      * If the resource belongs to the subtree of the project's web module,
110      * returns this module's document base directory.
111      * Otherwise (or if the project parameter is null), it checks for the WEB-INF directory,
112      * and determines the root accordingly. If WEB-INF is not found, returns null.
113      *
114      * @param fo the resource for which to find the web module root
115      * @param doc document in which is fileobject editted.
116      * @return the root of the web module, or null if a directory containing WEB-INF
117      * is not on the path from resource to the root
118      */

119     public abstract FileObject guessWebModuleRoot(Document JavaDoc doc, FileObject fo);
120     
121     /** Returns the taglib map as returned by the parser, taking data from the editor as parameters.
122      * Returns null in case of a failure (exception, no web module, no parser etc.)
123      */

124     public abstract Map JavaDoc getTaglibMap(Document JavaDoc doc, FileObject fo);
125     
126     /** This method returns an image, which is displayed for the FileObject in the explorer.
127      * It is used to display objects in editor (e.g. in code completion).
128      * @param doc This is the documet, in which the icon will be used (for exmaple for completion).
129      * @param fo file object for which the icon is looking for
130      * @return an Image which is dislayed in the explorer for the file.
131      */

132     public abstract java.awt.Image JavaDoc getIcon(Document JavaDoc doc, FileObject fo);
133     
134 }
135
Popular Tags