Source Code Cross Referenced for ConfigResourceIndexer.java in  » Web-Server » Jigsaw » org » w3c » jigsaw » indexer » 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.indexer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // ConfigResourceIndexer.java
002:        // $Id: ConfigResourceIndexer.java,v 1.3 2000/07/13 09:49:00 ylafon Exp $
003:        // (c) COPYRIGHT MIT,INRIA and Keio, 2000.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.jigsaw.indexer;
007:
008:        import java.io.File;
009:        import java.io.BufferedInputStream;
010:        import java.io.FileInputStream;
011:
012:        import java.util.Enumeration;
013:        import java.util.Hashtable;
014:
015:        import org.w3c.tools.resources.Resource;
016:        import org.w3c.tools.resources.ResourceFrame;
017:        import org.w3c.tools.resources.ContainerResource;
018:        import org.w3c.tools.resources.RequestInterface;
019:        import org.w3c.tools.resources.indexer.SampleResourceIndexer;
020:        import org.w3c.www.mime.MimeParser;
021:        import org.w3c.www.http.MimeParserMessageFactory;
022:        import org.w3c.www.http.HttpEntityMessage;
023:        import org.w3c.www.http.HeaderDescription;
024:        import org.w3c.jigsaw.frames.HTTPFrame;
025:        import org.w3c.www.mime.MimeType;
026:
027:        /**
028:         * This indexer allow to add a configuration file
029:         * to overwrite the computed configuration
030:         * for now, ./foo.html will have its configuration file in
031:         * ./.meta/foo.html.meta
032:         * but it can be extended to match other filename.
033:         */
034:        public class ConfigResourceIndexer extends SampleResourceIndexer {
035:
036:            /**
037:             * compute and return the file containing the configuration
038:             */
039:            private File getConfigFile(File directory, String name) {
040:                File configdir = new File(directory, ".meta");
041:                if (configdir.exists() && configdir.isDirectory()) {
042:                    File config = new File(configdir, name + ".meta");
043:                    if (config.exists() && !config.isDirectory())
044:                        return config;
045:                }
046:                return null;
047:            }
048:
049:            /**
050:             * Try to create a resource for the given file.
051:             * This method makes its best efforts to try to build a default
052:             * resource out of a file. 
053:             * @param directory The directory the file is in.
054:             * @param name The name of the file.
055:             * @param defs Any default attribute values that should be provided
056:             *    to the created resource at initialization time.
057:             * @return A Resource instance, or <strong>null</strong> if the given
058:             *    file can't be truned into a resource given our configuration
059:             *    database.
060:             */
061:            public Resource createResource(ContainerResource container,
062:                    RequestInterface request, File directory, String name,
063:                    Hashtable defs) {
064:                Resource r = super .createResource(container, request,
065:                        directory, name, defs);
066:                Class proto = null;
067:                try {
068:                    proto = Class.forName("org.w3c.jigsaw.frames.HTTPFrame");
069:                } catch (Exception ex) {
070:                    // fatal error!
071:                    return r;
072:                }
073:                if (r == null)
074:                    return r;
075:                HTTPFrame frame = null;
076:                ResourceFrame rf[] = r.collectFrames(proto);
077:                if (rf != null) {
078:                    frame = (HTTPFrame) rf[0];
079:                }
080:                if (frame == null) {
081:                    return r;
082:                }
083:
084:                File config = getConfigFile(directory, name);
085:                if (config != null) {
086:                    // we found a configuration file, do some more processing!
087:                    try {
088:                        // first, extract and parse the config file
089:                        BufferedInputStream buf;
090:                        buf = new BufferedInputStream(new FileInputStream(
091:                                config));
092:                        MimeParser p = new MimeParser(buf,
093:                                new MimeParserMessageFactory());
094:                        HttpEntityMessage msg = (HttpEntityMessage) p.parse();
095:                        Enumeration e = msg.enumerateHeaderDescriptions();
096:                        // then override some configuration
097:                        while (e.hasMoreElements()) {
098:                            // use some well known descriptions
099:                            HeaderDescription d = (HeaderDescription) e
100:                                    .nextElement();
101:                            if (d.isHeader(HttpEntityMessage.H_CONTENT_TYPE)) {
102:                                MimeType mtype = null;
103:                                try {
104:                                    mtype = msg.getContentType();
105:                                } catch (Exception ex) {
106:                                    // ok by default use something binary
107:                                    mtype = MimeType.APPLICATION_OCTET_STREAM;
108:                                }
109:                                if (mtype.hasParameter("charset")) {
110:                                    String charset = mtype
111:                                            .getParameterValue("charset");
112:                                    MimeType m = new MimeType(mtype.getType(),
113:                                            mtype.getSubtype());
114:                                    frame.setValue("content-type", m);
115:                                    frame.setValue("charset", charset);
116:                                } else {
117:                                    frame.setValue("content-type", mtype);
118:                                }
119:                                continue;
120:                            }
121:                            if (d
122:                                    .isHeader(HttpEntityMessage.H_CONTENT_LANGUAGE)) {
123:                                String lang[] = msg.getContentLanguage();
124:                                if (lang.length > 0) {
125:                                    frame.setValue("content-language", lang[0]);
126:                                }
127:                                continue;
128:                            }
129:                            if (d
130:                                    .isHeader(HttpEntityMessage.H_CONTENT_ENCODING)) {
131:                                String enc[] = msg.getContentEncoding();
132:                                if (enc.length > 0) {
133:                                    frame.setValue("content-encoding", enc[0]);
134:                                }
135:                                continue;
136:                            }
137:                        }
138:                    } catch (Exception ex) {
139:                        // do nothing, keep configured as it was
140:                        // by the super indexer
141:                        ex.printStackTrace();
142:                    }
143:                }
144:                return r;
145:            }
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.