Source Code Cross Referenced for SystemIdResolver.java in  » 6.0-JDK-Modules-com.sun » xml » com » sun » xml » internal » fastinfoset » sax » 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 » 6.0 JDK Modules com.sun » xml » com.sun.xml.internal.fastinfoset.sax 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         * 
025:         * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
026:         */
027:
028:        /*
029:         * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
030:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
031:         *
032:         * This code is free software; you can redistribute it and/or modify it
033:         * under the terms of the GNU General Public License version 2 only, as
034:         * published by the Free Software Foundation.  Sun designates this
035:         * particular file as subject to the "Classpath" exception as provided
036:         * by Sun in the LICENSE file that accompanied this code.
037:         *
038:         * This code is distributed in the hope that it will be useful, but WITHOUT
039:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
040:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
041:         * version 2 for more details (a copy is included in the LICENSE file that
042:         * accompanied this code).
043:         *
044:         * You should have received a copy of the GNU General Public License version
045:         * 2 along with this work; if not, write to the Free Software Foundation,
046:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
047:         *
048:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
049:         * CA 95054 USA or visit www.sun.com if you need additional information or
050:         * have any questions.
051:         * 
052:         * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
053:         *
054:         */
055:
056:        package com.sun.xml.internal.fastinfoset.sax;
057:
058:        import java.io.*;
059:
060:        public class SystemIdResolver {
061:
062:            public SystemIdResolver() {
063:            }
064:
065:            public static String getAbsoluteURIFromRelative(String localPath) {
066:                if (localPath == null || localPath.length() == 0) {
067:                    return "";
068:                }
069:
070:                String absolutePath = localPath;
071:                if (!isAbsolutePath(localPath)) {
072:                    try {
073:                        absolutePath = getAbsolutePathFromRelativePath(localPath);
074:                    } catch (SecurityException se) {
075:                        return "file:" + localPath;
076:                    }
077:                }
078:
079:                String urlString;
080:                if (null != absolutePath) {
081:                    urlString = absolutePath.startsWith(File.separator) ? ("file://" + absolutePath)
082:                            : ("file:///" + absolutePath);
083:                } else {
084:                    urlString = "file:" + localPath;
085:                }
086:
087:                return replaceChars(urlString);
088:            }
089:
090:            private static String getAbsolutePathFromRelativePath(
091:                    String relativePath) {
092:                return new File(relativePath).getAbsolutePath();
093:            }
094:
095:            public static boolean isAbsoluteURI(String systemId) {
096:                if (systemId == null) {
097:                    return false;
098:                }
099:
100:                if (isWindowsAbsolutePath(systemId)) {
101:                    return false;
102:                }
103:
104:                final int fragmentIndex = systemId.indexOf('#');
105:                final int queryIndex = systemId.indexOf('?');
106:                final int slashIndex = systemId.indexOf('/');
107:                final int colonIndex = systemId.indexOf(':');
108:
109:                int index = systemId.length() - 1;
110:                if (fragmentIndex > 0) {
111:                    index = fragmentIndex;
112:                }
113:                if (queryIndex > 0 && queryIndex < index) {
114:                    index = queryIndex;
115:                }
116:                if (slashIndex > 0 && slashIndex < index) {
117:                    index = slashIndex;
118:                }
119:                return (colonIndex > 0) && (colonIndex < index);
120:            }
121:
122:            public static boolean isAbsolutePath(String systemId) {
123:                if (systemId == null)
124:                    return false;
125:                final File file = new File(systemId);
126:                return file.isAbsolute();
127:
128:            }
129:
130:            private static boolean isWindowsAbsolutePath(String systemId) {
131:                if (!isAbsolutePath(systemId))
132:                    return false;
133:                if (systemId.length() > 2
134:                        && systemId.charAt(1) == ':'
135:                        && Character.isLetter(systemId.charAt(0))
136:                        && (systemId.charAt(2) == '\\' || systemId.charAt(2) == '/'))
137:                    return true;
138:                else
139:                    return false;
140:            }
141:
142:            private static String replaceChars(String str) {
143:                StringBuffer buf = new StringBuffer(str);
144:                int length = buf.length();
145:                for (int i = 0; i < length; i++) {
146:                    char currentChar = buf.charAt(i);
147:                    // Replace space with "%20"
148:                    if (currentChar == ' ') {
149:                        buf.setCharAt(i, '%');
150:                        buf.insert(i + 1, "20");
151:                        length = length + 2;
152:                        i = i + 2;
153:                    }
154:                    // Replace backslash with forward slash
155:                    else if (currentChar == '\\') {
156:                        buf.setCharAt(i, '/');
157:                    }
158:                }
159:
160:                return buf.toString();
161:            }
162:
163:            public static String getAbsoluteURI(String systemId) {
164:                String absoluteURI = systemId;
165:                if (isAbsoluteURI(systemId)) {
166:                    if (systemId.startsWith("file:")) {
167:                        String str = systemId.substring(5);
168:
169:                        if (str != null && str.startsWith("/")) {
170:                            if (str.startsWith("///") || !str.startsWith("//")) {
171:                                int secondColonIndex = systemId.indexOf(':', 5);
172:                                if (secondColonIndex > 0) {
173:                                    String localPath = systemId
174:                                            .substring(secondColonIndex - 1);
175:                                    try {
176:                                        if (!isAbsolutePath(localPath))
177:                                            absoluteURI = systemId.substring(0,
178:                                                    secondColonIndex - 1)
179:                                                    + getAbsolutePathFromRelativePath(localPath);
180:                                    } catch (SecurityException se) {
181:                                        return systemId;
182:                                    }
183:                                }
184:                            }
185:                        } else {
186:                            return getAbsoluteURIFromRelative(systemId
187:                                    .substring(5));
188:                        }
189:
190:                        return replaceChars(absoluteURI);
191:                    } else {
192:                        return systemId;
193:                    }
194:                } else {
195:                    return getAbsoluteURIFromRelative(systemId);
196:                }
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.