Source Code Cross Referenced for DTDResolver.java in  » Portal » Open-Portal » com » sun » portal » util » 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 » Portal » Open Portal » com.sun.portal.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /**
02:         * $Id: DTDResolver.java,v 1.1 2005/03/21 05:25:46 ru111118 Exp $
03:         * Copyright 2004 Sun Microsystems, Inc. All
04:         * rights reserved. Use of this product is subject
05:         * to license terms. Federal Acquisitions:
06:         * Commercial Software -- Government Users
07:         * Subject to Standard License Terms and
08:         * Conditions.
09:         *
10:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
11:         * are trademarks or registered trademarks of Sun Microsystems,
12:         * Inc. in the United States and other countries.
13:         */package com.sun.portal.util;
14:
15:        import java.io.Reader;
16:        import java.io.BufferedReader;
17:        import java.io.StringReader;
18:        import java.io.InputStream;
19:        import java.io.FileInputStream;
20:        import java.io.InputStreamReader;
21:        import java.io.IOException;
22:        import java.io.FileNotFoundException;
23:        import java.net.URL;
24:
25:        import org.xml.sax.InputSource;
26:        import org.xml.sax.SAXException;
27:        import org.xml.sax.SAXParseException;
28:        import org.xml.sax.helpers.DefaultHandler;
29:
30:        public class DTDResolver extends DefaultHandler {
31:
32:            public InputSource resolveEntity(String aPublicID, String aSystemID)
33:                    throws SAXException {
34:
35:                String sysid = aSystemID.trim();
36:                if (sysid.toLowerCase().startsWith("jar://")) {
37:                    String dtdname = sysid.substring(5);
38:                    String dtdValue = read(dtdname, DTDResolver.class).trim();
39:                    return new InputSource(new StringReader(dtdValue));
40:                }
41:
42:                return super .resolveEntity(aPublicID, aSystemID);
43:
44:            }
45:
46:            public static String read(String fileName, Class cl)
47:                    throws SAXException {
48:
49:                String data = "";
50:
51:                try {
52:
53:                    InputStream in = cl.getResourceAsStream(fileName);
54:                    //may be absolute file path is given
55:                    if (in == null) {
56:                        try {
57:                            //works well if the user has given absolute path
58:                            in = new FileInputStream(fileName);
59:                        } catch (FileNotFoundException e) {
60:                            //works well if the user has given the relative path to the
61:                            //location of class file
62:                            String directoryURL = cl.getProtectionDomain()
63:                                    .getCodeSource().getLocation().toString();
64:                            String fileURL = directoryURL + fileName;
65:                            URL url = new URL(fileURL);
66:                            in = url.openStream();
67:                        }
68:                    }
69:                    data = read(new InputStreamReader(in));
70:                    in.close();
71:                } catch (Exception e) {
72:                    throw new SAXException("Failed to fetch the DTD", e);
73:                }
74:                return data;
75:            }
76:
77:            /**
78:             * This method reads the resource from a reader
79:             */
80:            public static String read(Reader aReader) throws IOException {
81:
82:                StringBuffer sb = new StringBuffer();
83:                BufferedReader bReader = new BufferedReader(aReader);
84:                char[] data = new char[2048];
85:
86:                int count = 0;
87:                while ((count = bReader.read(data)) != -1) {
88:                    sb.append(data, 0, count);
89:                }
90:
91:                bReader.close();
92:                aReader.close();
93:
94:                return sb.toString();
95:            }
96:
97:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.