Source Code Cross Referenced for Util.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » rdf » model » impl » 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 » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.rdf.model.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
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
007:         * are met:
008:         * 1. Redistributions of source code must retain the above copyright
009:         *    notice, this list of conditions and the following disclaimer.
010:         * 2. Redistributions in binary form must reproduce the above copyright
011:         *    notice, this list of conditions and the following disclaimer in the
012:         *    documentation and/or other materials provided with the distribution.
013:         * 3. The name of the author may not be used to endorse or promote products
014:         *    derived from this software without specific prior written permission.
015:
016:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026:         *
027:         * Util.java
028:         *
029:         * Created on 01 August 2000, 16:31
030:         */
031:
032:        package com.hp.hpl.jena.rdf.model.impl;
033:
034:        import java.util.regex.*;
035:
036:        import org.apache.xerces.util.XMLChar;
037:
038:        import com.hp.hpl.jena.shared.*;
039:
040:        /** Some utility functions.
041:         *
042:         * @author  bwm
043:         * @version   Release='$Name:  $' Revision='$Revision: 1.14 $' Date='$Date: 2008/01/02 12:05:07 $'
044:         */
045:        public class Util extends Object {
046:
047:            public static final String CLASSPATH = "com.hp.hpl.jena";
048:
049:            /** Given an absolute URI, determine the split point between the namespace part
050:             * and the localname part.
051:             * If there is no valid localname part then the length of the
052:             * string is returned.
053:             * The algorithm tries to find the longest NCName at the end
054:             * of the uri, not immediately preceeded by the first colon
055:             * in the string.
056:             * @param uri
057:             * @return the index of the first character of the localname
058:             */
059:            public static int splitNamespace(String uri) {
060:                char ch;
061:                int lg = uri.length();
062:                if (lg == 0)
063:                    return 0;
064:                int j;
065:                int i;
066:                for (i = lg - 1; i >= 1; i--) {
067:                    ch = uri.charAt(i);
068:                    if (notNameChar(ch))
069:                        break;
070:                }
071:                for (j = i + 1; j < lg; j++) {
072:                    ch = uri.charAt(j);
073:                    if (XMLChar.isNCNameStart(ch)) {
074:                        if (uri.charAt(j - 1) == ':'
075:                                && uri.lastIndexOf(':', j - 2) == -1)
076:                            continue; // split "mailto:me" as "mailto:m" and "e" !
077:                        else
078:                            break;
079:                    }
080:                }
081:                return j;
082:            }
083:
084:            /**
085:                answer true iff this is not a legal NCName character, ie, is
086:                a possible split-point start.
087:             */
088:            public static boolean notNameChar(char ch) {
089:                return !XMLChar.isNCName(ch);
090:            }
091:
092:            protected static Pattern standardEntities = Pattern
093:                    .compile("&|<|>|\t|\n|\r|\'|\"");
094:
095:            public static String substituteStandardEntities(String s) {
096:                if (standardEntities.matcher(s).find()) {
097:                    return substituteEntitiesInElementContent(s).replaceAll(
098:                            "'", "&apos;").replaceAll("\t", "&#9;").replaceAll(
099:                            "\n", "&#xA;").replaceAll("\r", "&#xD;")
100:                            .replaceAll("\"", "&quot;");
101:                } else
102:                    return s;
103:            }
104:
105:            protected static Pattern entityValueEntities = Pattern
106:                    .compile("&|%|\'|\"");
107:
108:            public static String substituteEntitiesInEntityValue(String s) {
109:                if (entityValueEntities.matcher(s).find()) {
110:                    return s.replaceAll("&", "&amp;").replaceAll("'", "&apos;")
111:                            .replaceAll("%", "&#37;")
112:                            .replaceAll("\"", "&quot;");
113:                } else
114:                    return s;
115:            }
116:
117:            protected static Pattern elementContentEntities = Pattern
118:                    .compile("<|>|&|[\0-\37&&[^\n\r\t]]|\uFFFF|\uFFFE");
119:
120:            /**
121:                Answer <code>s</code> modified to replace &lt;, &gt;, and &amp; by
122:                their corresponding entity references. 
123:                
124:            <p>
125:                Implementation note: as a (possibly misguided) performance hack, 
126:                the obvious cascade of replaceAll calls is replaced by an explicit
127:                loop that looks for all three special characters at once.
128:             */
129:            public static String substituteEntitiesInElementContent(String s) {
130:                Matcher m = elementContentEntities.matcher(s);
131:                if (!m.find())
132:                    return s;
133:                else {
134:                    int start = 0;
135:                    StringBuffer result = new StringBuffer();
136:                    do {
137:                        result.append(s.substring(start, m.start()));
138:                        char ch = s.charAt(m.start());
139:                        switch (ch) {
140:                        case '<':
141:                            result.append("&lt;");
142:                            break;
143:                        case '&':
144:                            result.append("&amp;");
145:                            break;
146:                        case '>':
147:                            result.append("&gt;");
148:                            break;
149:                        default:
150:                            throw new CannotEncodeCharacterException(ch, "XML");
151:                        }
152:                        start = m.end();
153:                    } while (m.find(start));
154:                    result.append(s.substring(start));
155:                    return result.toString();
156:                }
157:            }
158:
159:            public static String replace(String s, String oldString,
160:                    String newString) {
161:                String result = "";
162:                int length = oldString.length();
163:                int pos = s.indexOf(oldString);
164:                int lastPos = 0;
165:                while (pos >= 0) {
166:                    result = result + s.substring(lastPos, pos) + newString;
167:                    lastPos = pos + length;
168:                    pos = s.indexOf(oldString, lastPos);
169:                }
170:                return result + s.substring(lastPos, s.length());
171:            }
172:
173:            /** Call System.getProperty and suppresses SecurityException, (simply returns null).
174:             *@return The property value, or null if none or there is a SecurityException.
175:             */
176:            public static String XgetProperty(String p) {
177:                return XgetProperty(p, null);
178:            }
179:
180:            /** Call System.getProperty and suppresses SecurityException, (simply returns null).
181:             *@return The property value, or null if none or there is a SecurityException.
182:             */
183:            public static String XgetProperty(String p, String def) {
184:                try {
185:                    return System.getProperty(p, def);
186:                } catch (SecurityException e) {
187:                    return def;
188:                }
189:            }
190:
191:        }
w__ww.___ja__v_a2_s_.___c___om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.