Source Code Cross Referenced for ClassLoaderEntityResolver.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » xml » 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 » ERP CRM Financial » Kuali Financial System » edu.iu.uis.eden.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2006 The Kuali Foundation.
003:         * 
004:         * 
005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         * 
009:         * http://www.opensource.org/licenses/ecl1.php
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package edu.iu.uis.eden.xml;
018:
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:
022:        import org.apache.log4j.Logger;
023:        import org.xml.sax.EntityResolver;
024:        import org.xml.sax.InputSource;
025:        import org.xml.sax.SAXException;
026:
027:        /**
028:         * Internal workflow EntityResolver which resolves system ids with the
029:         * "resource:" prefix to ClassLoader resources
030:         * 
031:         * TODO: maybe prefix should be changed from "resource:" to "internal:" or just "workflow:"
032:         * given that it can be resolved in arbitrary ways other than ClassLoader "resources"
033:         * 
034:         * @author Aaron Hamid (arh14 at cornell dot edu)
035:         */
036:        public class ClassLoaderEntityResolver implements  EntityResolver {
037:            private static final Logger LOG = Logger
038:                    .getLogger(ClassLoaderEntityResolver.class);
039:
040:            /**
041:             * This contains definitions for items in the core "xml" schema, i.e. base, id, lang, and space attributes. 
042:             */
043:            private static final String XML_NAMESPACE_SCHEMA = "http://www.w3.org/2001/xml.xsd";
044:            private static final String XSD_NAMESPACE_SCHEMA = "http://www.w3.org/2001/XMLSchema.xsd";
045:
046:            private final String base;
047:
048:            public ClassLoaderEntityResolver() {
049:                this .base = "schema";
050:            }
051:
052:            public ClassLoaderEntityResolver(String base) {
053:                this .base = base;
054:            }
055:
056:            public InputSource resolveEntity(String publicId, String systemId)
057:                    throws SAXException, IOException {
058:                LOG.debug("Resolving '" + publicId + "' / '" + systemId + "'");
059:                String path = "";
060:                if (systemId.equals(XML_NAMESPACE_SCHEMA)) {
061:                    path = base + "/xml.xsd";
062:                } else if (systemId.equals(XSD_NAMESPACE_SCHEMA)) {
063:                    path = base + "/XMLSchema.xsd";
064:                } else if (systemId.startsWith("resource")) {
065:                    /* It turns out that the stock XMLSchema.xsd refers to XMLSchema.dtd in a relative
066:                       fashion which results in the parser qualifying it to some local file:// path
067:                       which breaks our detection here.
068:                       So I have made a small mod to the stock XMLSchema.xsd so that it instead refers to
069:                       resource:XMLSchema.dtd which can be looked up locally.
070:                       The same is true for XMLSchema.dtd with regard to datatypes.dtd, so I have also
071:                       modified XMLSchema.dtd to refer to resource:datatypes.dtd.
072:                       An alternative would be to rely on publicId, however that would essentially hard code
073:                       the lookup to always be in the classpath and rule out being able to redirect the location
074:                       of the physical resource through the systemId, which is useful.
075:                     */
076:
077:                    // TODO: revisit making this more sophisticated than just the classloader
078:                    // of this class (thread context classloader? plugin classloader?)
079:                    path = base + "/"
080:                            + systemId.substring("resource:".length());
081:                    // ok, if the path does not itself end in .xsd or .dtd, it is bare/abstract
082:                    // so realize it by appending .xsd
083:                    // this allows us to support looking up files ending with ".dtd" through resource: without
084:                    // having extra logic to attempt to look up both suffixes for every single resource:
085:                    // (all of which except XMLSchema.dtd and datatypes.dtd at this point are .xsd files)
086:                    if (!(systemId.endsWith(".xsd") || systemId
087:                            .endsWith(".dtd"))) {
088:                        path += ".xsd";
089:                    }
090:                } else {
091:                    LOG
092:                            .error("Unable to resolve system id '"
093:                                    + systemId
094:                                    + "' locally...delegating to default resolution strategy.");
095:                    return null;
096:                }
097:                InputStream is = getClass().getClassLoader()
098:                        .getResourceAsStream(path);
099:                if (is == null) {
100:                    String message = "Unable to find schema (" + path
101:                            + ") for: " + systemId;
102:                    LOG.error(message);
103:                    throw new SAXException(message);
104:                }
105:                return new InputSource(is);
106:            }
107:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.