Source Code Cross Referenced for PublicId.java in  » 6.0-JDK-Modules » jaxb-xjc » com » sun » org » apache » xml » internal » resolver » helpers » 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.org.apache.xml.internal.resolver.helpers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // PublicId.java - Information about public identifiers
002:
003:        /*
004:         * Copyright 2001-2004 The Apache Software Foundation or its licensors,
005:         * as applicable.
006:         * 
007:         * Licensed under the Apache License, Version 2.0 (the "License");
008:         * you may not use this file except in compliance with the License.
009:         * You may obtain a copy of the License at
010:         * 
011:         *      http://www.apache.org/licenses/LICENSE-2.0
012:         * 
013:         * Unless required by applicable law or agreed to in writing, software
014:         * distributed under the License is distributed on an "AS IS" BASIS,
015:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:         * See the License for the specific language governing permissions and
017:         * limitations under the License.
018:         */
019:
020:        package com.sun.org.apache.xml.internal.resolver.helpers;
021:
022:        /**
023:         * Static methods for dealing with public identifiers.
024:         *
025:         * <p>This class defines a set of static methods that can be called
026:         * to handle public identifiers.</p>
027:         *
028:         * @author Norman Walsh
029:         * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
030:         *
031:         * @version 1.0
032:         */
033:        public abstract class PublicId {
034:            protected PublicId() {
035:            }
036:
037:            /**
038:             * Normalize a public identifier.
039:             *
040:             * <p>Public identifiers must be normalized according to the following
041:             * rules before comparisons between them can be made:</p>
042:             *
043:             * <ul>
044:             * <li>Whitespace characters are normalized to spaces (e.g., line feeds,
045:             * tabs, etc. become spaces).</li>
046:             * <li>Leading and trailing whitespace is removed.</li>
047:             * <li>Multiple internal whitespaces are normalized to a single
048:             * space.</li>
049:             * </ul>
050:             *
051:             * <p>This method is declared static so that other classes
052:             * can use it directly.</p>
053:             *
054:             * @param publicId The unnormalized public identifier.
055:             *
056:             * @return The normalized identifier.
057:             */
058:            public static String normalize(String publicId) {
059:                String normal = publicId.replace('\t', ' ');
060:                normal = normal.replace('\r', ' ');
061:                normal = normal.replace('\n', ' ');
062:                normal = normal.trim();
063:
064:                int pos;
065:
066:                while ((pos = normal.indexOf("  ")) >= 0) {
067:                    normal = normal.substring(0, pos)
068:                            + normal.substring(pos + 1);
069:                }
070:
071:                return normal;
072:            }
073:
074:            /**
075:             * Encode a public identifier as a "publicid" URN.
076:             *
077:             * <p>This method is declared static so that other classes
078:             * can use it directly.</p>
079:             *
080:             * @param publicId The unnormalized public identifier.
081:             *
082:             * @return The normalized identifier.
083:             */
084:            public static String encodeURN(String publicId) {
085:                String urn = PublicId.normalize(publicId);
086:
087:                urn = PublicId.stringReplace(urn, "%", "%25");
088:                urn = PublicId.stringReplace(urn, ";", "%3B");
089:                urn = PublicId.stringReplace(urn, "'", "%27");
090:                urn = PublicId.stringReplace(urn, "?", "%3F");
091:                urn = PublicId.stringReplace(urn, "#", "%23");
092:                urn = PublicId.stringReplace(urn, "+", "%2B");
093:                urn = PublicId.stringReplace(urn, " ", "+");
094:                urn = PublicId.stringReplace(urn, "::", ";");
095:                urn = PublicId.stringReplace(urn, ":", "%3A");
096:                urn = PublicId.stringReplace(urn, "//", ":");
097:                urn = PublicId.stringReplace(urn, "/", "%2F");
098:
099:                return "urn:publicid:" + urn;
100:            }
101:
102:            /**
103:             * Decode a "publicid" URN into a public identifier.
104:             *
105:             * <p>This method is declared static so that other classes
106:             * can use it directly.</p>
107:             *
108:             * @param urn The urn:publicid: URN
109:             *
110:             * @return The normalized identifier.
111:             */
112:            public static String decodeURN(String urn) {
113:                String publicId = "";
114:
115:                if (urn.startsWith("urn:publicid:")) {
116:                    publicId = urn.substring(13);
117:                } else {
118:                    return urn;
119:                }
120:
121:                publicId = PublicId.stringReplace(publicId, "%2F", "/");
122:                publicId = PublicId.stringReplace(publicId, ":", "//");
123:                publicId = PublicId.stringReplace(publicId, "%3A", ":");
124:                publicId = PublicId.stringReplace(publicId, ";", "::");
125:                publicId = PublicId.stringReplace(publicId, "+", " ");
126:                publicId = PublicId.stringReplace(publicId, "%2B", "+");
127:                publicId = PublicId.stringReplace(publicId, "%23", "#");
128:                publicId = PublicId.stringReplace(publicId, "%3F", "?");
129:                publicId = PublicId.stringReplace(publicId, "%27", "'");
130:                publicId = PublicId.stringReplace(publicId, "%3B", ";");
131:                publicId = PublicId.stringReplace(publicId, "%25", "%");
132:
133:                return publicId;
134:            }
135:
136:            /**
137:             * Replace one string with another.
138:             *
139:             */
140:            private static String stringReplace(String str, String oldStr,
141:                    String newStr) {
142:
143:                String result = "";
144:                int pos = str.indexOf(oldStr);
145:
146:                //    System.out.println(str + ": " + oldStr + " => " + newStr);
147:
148:                while (pos >= 0) {
149:                    //      System.out.println(str + " (" + pos + ")");
150:                    result += str.substring(0, pos);
151:                    result += newStr;
152:                    str = str.substring(pos + 1);
153:
154:                    pos = str.indexOf(oldStr);
155:                }
156:
157:                return result + str;
158:            }
159:        }
ww_w___.j___a__v__a_2_s___.__c_o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.