Source Code Cross Referenced for URIUtil.java in  » RSS-RDF » sesame » org » openrdf » model » 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 » RSS RDF » sesame » org.openrdf.model.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
003:         *
004:         * Licensed under the Aduna BSD-style license.
005:         */
006:        package org.openrdf.model.util;
007:
008:        import org.openrdf.model.URI;
009:
010:        /**
011:         * @author Arjohn Kampman
012:         */
013:        public class URIUtil {
014:
015:            /**
016:             * Finds the index of the first local name character in an (non-relative)
017:             * URI. This index is determined by the following the following steps:
018:             * <ul>
019:             * <li>Find the <em>first</em> occurrence of the '#' character,
020:             * <li>If this fails, find the <em>last</em> occurrence of the '/'
021:             * character,
022:             * <li>If this fails, find the <em>last</em> occurrence of the ':'
023:             * character.
024:             * <li>Add <tt>1<tt> to the found index and return this value.
025:             * </ul>
026:             * Note that the third step should never fail as every legal (non-relative)
027:             * URI contains at least one ':' character to seperate the scheme from the
028:             * rest of the URI. If this fails anyway, the method will throw an
029:             * {@link IllegalArgumentException}.
030:             * 
031:             * @param uri
032:             *        A URI string.
033:             * @return The index of the first local name character in the URI string. Note that
034:             * this index does not reference an actual character if the algorithm determines
035:             * that there is not local name. In that case, the return index is equal to the
036:             * length of the URI string.
037:             * @throws IllegalArgumentException
038:             *         If the supplied URI string doesn't contain any of the separator
039:             *         characters. Every legal (non-relative) URI contains at least one
040:             *         ':' character to seperate the scheme from the rest of the URI.
041:             */
042:            public static int getLocalNameIndex(String uri) {
043:                int separatorIdx = uri.indexOf('#');
044:
045:                if (separatorIdx < 0) {
046:                    separatorIdx = uri.lastIndexOf('/');
047:                }
048:
049:                if (separatorIdx < 0) {
050:                    separatorIdx = uri.lastIndexOf(':');
051:                }
052:
053:                if (separatorIdx < 0) {
054:                    throw new IllegalArgumentException(
055:                            "No separator character founds in URI: " + uri);
056:                }
057:
058:                return separatorIdx + 1;
059:            }
060:
061:            /**
062:             * Checks whether the URI consisting of the specified namespace and local
063:             * name has been split correctly according to the URI splitting rules
064:             * specified in {@link URI}.
065:             * 
066:             * @param namespace
067:             *        The URI's namespace, must not be <tt>null</tt>.
068:             * @param localName
069:             *        The URI's local name, must not be <tt>null</tt>.
070:             * @return <tt>true</tt> if the specified URI has been correctly split into
071:             *         a namespace and local name, <tt>false</tt> otherwise.
072:             * @see URI
073:             * @see #getLocalNameIndex(String)
074:             */
075:            public static boolean isCorrectURISplit(String namespace,
076:                    String localName) {
077:                assert namespace != null : "namespace must not be null";
078:                assert localName != null : "localName must not be null";
079:
080:                if (namespace.length() == 0) {
081:                    return false;
082:                }
083:
084:                int nsLength = namespace.length();
085:                char lastNsChar = namespace.charAt(nsLength - 1);
086:
087:                if (lastNsChar == '#'
088:                        && namespace.lastIndexOf('#', nsLength - 2) == -1) {
089:                    // namespace ends with a '#' and does not contain any futher '#'
090:                    // characters
091:                    return true;
092:                } else if (localName.indexOf('#') == -1
093:                        && localName.indexOf('/') == -1) {
094:                    if (lastNsChar == '/') {
095:                        // URI does not contain any '#' characters and the namespace ends
096:                        // with the last '/' character
097:                        return true;
098:                    } else if (lastNsChar == ':'
099:                            && localName.indexOf(':') == -1) {
100:                        // URI does not contain any '#' or '/' characters and the namespace
101:                        // ends with the last ':' character
102:                        return true;
103:                    }
104:                }
105:
106:                return false;
107:            }
108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.