Source Code Cross Referenced for ServletIndexer.java in  » Web-Server » Jigsaw » org » w3c » jigsaw » servlet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » Jigsaw » org.w3c.jigsaw.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // ServletIndexer.java
002:        // $Id: ServletIndexer.java,v 1.10 2002/06/26 17:55:05 ylafon Exp $
003:        // (c) COPYRIGHT MIT and INRIA, 1998.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.jigsaw.servlet;
007:
008:        import java.io.File;
009:
010:        import java.util.Enumeration;
011:        import java.util.Hashtable;
012:
013:        import org.w3c.tools.resources.AttributeHolder;
014:        import org.w3c.tools.resources.FramedResource;
015:        import org.w3c.tools.resources.InvalidResourceException;
016:        import org.w3c.tools.resources.RequestInterface;
017:        import org.w3c.tools.resources.Resource;
018:        import org.w3c.tools.resources.ResourceReference;
019:
020:        import org.w3c.tools.resources.indexer.SampleResourceIndexer;
021:
022:        /**
023:         * @version $Revision: 1.10 $
024:         * @author  Benoît Mahé (bmahe@w3.org)
025:         */
026:        public class ServletIndexer extends SampleResourceIndexer {
027:
028:            /**
029:             * Copy one hastable in another one.
030:             * @param fromdefs The source
031:             * @param todefs The destination
032:             */
033:            protected void copyDefs(Hashtable fromdefs, Hashtable toDefs) {
034:                Enumeration keys = fromdefs.keys();
035:                while (keys.hasMoreElements()) {
036:                    Object key = keys.nextElement();
037:                    toDefs.put(keys, fromdefs.get(key));
038:                }
039:            }
040:
041:            /**
042:             * Create a default file resource for this file (that exists).
043:             * @param directory The directory of the file.
044:             * @param name The name of the file.
045:             * @param defs A set of default attribute values.
046:             * @return An instance of Resource, or <strong>null</strong> if
047:             *    we were unable to create it.
048:             */
049:
050:            protected Resource createFileResource(File directory,
051:                    RequestInterface req, String name, Hashtable defs) {
052:                if (!name.endsWith(".class"))
053:                    return super .createFileResource(directory, req, name, defs);
054:                ResourceReference rr = null;
055:                FramedResource template = null;
056:
057:                // Check that at least one class is defined for all the extensions:
058:                String exts[] = getFileExtensions(name);
059:                if (exts == null)
060:                    return null;
061:                for (int i = exts.length - 1; i >= 0; i--) {
062:                    rr = getTemplateFor(exts[i]);
063:                    if (rr != null)
064:                        break;
065:                }
066:                if (rr == null) {
067:                    // Look for a default template:
068:                    if ((rr = loadExtension(defname)) == null)
069:                        return null;
070:                    return super .createFileResource(directory, req, name, defs);
071:                } else {
072:                    //this could become a servlet
073:                    Hashtable tempdefs = null;
074:                    String s_dir = "directory".intern();
075:                    String s_ide = "identifier".intern();
076:                    String s_ser = "servlet-class".intern();
077:                    String s_con = "context".intern();
078:                    String s_url = "url".intern();
079:                    if (defs != null) {
080:                        tempdefs = (Hashtable) defs.clone();
081:                    } else {
082:                        tempdefs = new Hashtable(5);
083:                    }
084:                    if (tempdefs.get(s_dir) == null)
085:                        tempdefs.put(s_dir, directory);
086:                    if (tempdefs.get(s_con) == null)
087:                        tempdefs.put(s_con, getContext());
088:                    try {
089:                        template = (FramedResource) rr.lock();
090:                        if (template instanceof  ServletWrapper) {
091:                            if (tempdefs.get(s_ser) == null)
092:                                tempdefs.put(s_ser, name);
093:                            String id = getIndexedFileName(name);
094:                            tempdefs.put(s_ide, id);
095:                            String url = (String) tempdefs.get(s_url);
096:                            if ((url != null) && (url.endsWith(".class"))) {
097:                                int idx = url.lastIndexOf(".class");
098:                                tempdefs.put(s_url, url.substring(0, idx));
099:                            }
100:                        } else {
101:                            if (tempdefs.get(s_ide) == null)
102:                                tempdefs.put(s_ide, name);
103:                        }
104:                        if (exts != null) {
105:                            // Merge with values defined by the extension:
106:                            for (int i = exts.length; --i >= 0;)
107:                                mergeDefaultAttributes(template, exts[i],
108:                                        tempdefs);
109:                        }
110:                        // Create, initialize and return the new resource
111:                        try {
112:                            FramedResource cloned = (FramedResource) template
113:                                    .getClone(tempdefs);
114:                            if (cloned instanceof  ServletWrapper) {
115:                                ServletWrapper wrapper = (ServletWrapper) cloned;
116:                                // check the servlet class
117:                                if (!wrapper.isWrappingAServlet())
118:                                    return null;
119:                            }
120:                            //ok, the defs are good.
121:                            copyDefs(tempdefs, defs);
122:                            return cloned;
123:                        } catch (Exception ex) {
124:                            ex.printStackTrace();
125:                            return null;
126:                        }
127:                    } catch (InvalidResourceException ex) {
128:                        ex.printStackTrace();
129:                        return null;
130:                    } finally {
131:                        rr.unlock();
132:                    }
133:                }
134:            }
135:
136:            /**
137:             * Try to create a virtual resource if the real (physical) resource
138:             * is not there.
139:             * @param directory The directory the file is in.
140:             * @param name The name of the file.
141:             * @param defs Any default attribute values that should be provided
142:             *    to the created resource at initialization time.
143:             * @return A Resource instance, or <strong>null</strong> if the given
144:             *    file can't be truned into a resource given our configuration
145:             *    database.
146:             */
147:
148:            protected Resource createVirtualResource(File directory,
149:                    RequestInterface req, String name, Hashtable defs) {
150:                Resource res = super .createVirtualResource(directory, req,
151:                        name, defs);
152:                if (res != null)
153:                    return res;
154:                //could be a servlet
155:                char fileSeparatorChar = File.separatorChar;
156:                String sname = name.replace('.', fileSeparatorChar) + ".class";
157:                File servletfile = new File(directory, sname);
158:                if (servletfile.exists())
159:                    return createFileResource(directory, null, name + ".class",
160:                            defs);
161:                else
162:                    return null;
163:            }
164:
165:            protected String getIndexedFileName(String name) {
166:                String indexed = name;
167:                int idx = name.lastIndexOf(".class");
168:                if (idx != -1)
169:                    indexed = name.substring(0, idx);
170:                return indexed;
171:            }
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.