Source Code Cross Referenced for Uri.java in  » 6.0-JDK-Modules » jaxb-xjc » com » sun » xml » xsom » impl » 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 » 6.0 JDK Modules » jaxb xjc » com.sun.xml.xsom.impl.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        Copyright (c) 2001, 2002 Thai Open Source Software Center Ltd
003:        All rights reserved.
004:
005:        Redistribution and use in source and binary forms, with or without
006:        modification, are permitted provided that the following conditions are
007:        met:
008:
009:            Redistributions of source code must retain the above copyright
010:            notice, this list of conditions and the following disclaimer.
011:
012:            Redistributions in binary form must reproduce the above copyright
013:            notice, this list of conditions and the following disclaimer in
014:            the documentation and/or other materials provided with the
015:            distribution.
016:
017:            Neither the name of the Thai Open Source Software Center Ltd nor
018:            the names of its contributors may be used to endorse or promote
019:            products derived from this software without specific prior written
020:            permission.
021:
022:        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
023:        "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
024:        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
025:        A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
026:        CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
027:        EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
028:        PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
029:        PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
030:        LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
031:        NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
032:        SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
033:         */
034:        package com.sun.xml.xsom.impl.util;
035:
036:        import java.io.IOException;
037:        import java.io.UnsupportedEncodingException;
038:        import java.net.URL;
039:
040:        public class Uri {
041:            private static String utf8 = "UTF-8";
042:
043:            public static boolean isValid(String s) {
044:                return isValidPercent(s) && isValidFragment(s)
045:                        && isValidScheme(s);
046:            }
047:
048:            private static final String HEX_DIGITS = "0123456789abcdef";
049:
050:            public static String escapeDisallowedChars(String s) {
051:                StringBuffer buf = null;
052:                int len = s.length();
053:                int done = 0;
054:                for (;;) {
055:                    int i = done;
056:                    for (;;) {
057:                        if (i == len) {
058:                            if (done == 0)
059:                                return s;
060:                            break;
061:                        }
062:                        if (isExcluded(s.charAt(i)))
063:                            break;
064:                        i++;
065:                    }
066:                    if (buf == null)
067:                        buf = new StringBuffer();
068:                    if (i > done) {
069:                        buf.append(s.substring(done, i));
070:                        done = i;
071:                    }
072:                    if (i == len)
073:                        break;
074:                    for (i++; i < len && isExcluded(s.charAt(i)); i++)
075:                        ;
076:                    String tem = s.substring(done, i);
077:                    byte[] bytes;
078:                    try {
079:                        bytes = tem.getBytes(utf8);
080:                    } catch (UnsupportedEncodingException e) {
081:                        utf8 = "UTF8";
082:                        try {
083:                            bytes = tem.getBytes(utf8);
084:                        } catch (UnsupportedEncodingException e2) {
085:                            // Give up
086:                            return s;
087:                        }
088:                    }
089:                    for (int j = 0; j < bytes.length; j++) {
090:                        buf.append('%');
091:                        buf.append(HEX_DIGITS.charAt((bytes[j] & 0xFF) >> 4));
092:                        buf.append(HEX_DIGITS.charAt(bytes[j] & 0xF));
093:                    }
094:                    done = i;
095:                }
096:                return buf.toString();
097:            }
098:
099:            private static String excluded = "<>\"{}|\\^`";
100:
101:            private static boolean isExcluded(char c) {
102:                return c <= 0x20 || c >= 0x7F || excluded.indexOf(c) >= 0;
103:            }
104:
105:            private static boolean isAlpha(char c) {
106:                return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
107:            }
108:
109:            private static boolean isHexDigit(char c) {
110:                return ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F')
111:                        || isDigit(c);
112:            }
113:
114:            private static boolean isDigit(char c) {
115:                return '0' <= c && c <= '9';
116:            }
117:
118:            private static boolean isSchemeChar(char c) {
119:                return isAlpha(c) || isDigit(c) || c == '+' || c == '-'
120:                        || c == '.';
121:            }
122:
123:            private static boolean isValidPercent(String s) {
124:                int len = s.length();
125:                for (int i = 0; i < len; i++)
126:                    if (s.charAt(i) == '%') {
127:                        if (i + 2 >= len)
128:                            return false;
129:                        else if (!isHexDigit(s.charAt(i + 1))
130:                                || !isHexDigit(s.charAt(i + 2)))
131:                            return false;
132:                    }
133:                return true;
134:            }
135:
136:            private static boolean isValidFragment(String s) {
137:                int i = s.indexOf('#');
138:                return i < 0 || s.indexOf('#', i + 1) < 0;
139:            }
140:
141:            private static boolean isValidScheme(String s) {
142:                if (!isAbsolute(s))
143:                    return true;
144:                int i = s.indexOf(':');
145:                if (i == 0 || i + 1 == s.length() || !isAlpha(s.charAt(0)))
146:                    return false;
147:                while (--i > 0)
148:                    if (!isSchemeChar(s.charAt(i)))
149:                        return false;
150:                return true;
151:            }
152:
153:            public static String resolve(String baseUri, String uriReference)
154:                    throws IOException {
155:                if (isAbsolute(uriReference))
156:                    return uriReference;
157:
158:                if (baseUri == null)
159:                    throw new IOException("Unable to resolve relative URI "
160:                            + uriReference + " without a base URI");
161:
162:                if (!isAbsolute(baseUri))
163:                    throw new IOException("Unable to resolve relative URI "
164:                            + uriReference
165:                            + " because base URI is not absolute: " + baseUri);
166:
167:                return new URL(new URL(baseUri), uriReference).toString();
168:            }
169:
170:            public static boolean hasFragmentId(String uri) {
171:                return uri.indexOf('#') >= 0;
172:            }
173:
174:            public static boolean isAbsolute(String uri) {
175:                int i = uri.indexOf(':');
176:                if (i < 0)
177:                    return false;
178:                while (--i >= 0) {
179:                    switch (uri.charAt(i)) {
180:                    case '#':
181:                    case '/':
182:                    case '?':
183:                        return false;
184:                    }
185:                }
186:                return true;
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.