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


001:        /*
002:         * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:         * All rights reserved.
004:         * [See end of file]
005:         */
006:
007:        package com.hp.hpl.jena.n3;
008:
009:        import com.hp.hpl.jena.iri.IRI;
010:        import com.hp.hpl.jena.iri.IRIException;
011:        import com.hp.hpl.jena.iri.IRIFactory;
012:        import com.hp.hpl.jena.util.FileUtils;
013:
014:        /** A simple class to access IRI resolution 
015:         * 
016:         * @author Andy Seaborne, Jeremy Carroll
017:         * */
018:
019:        public class IRIResolver {
020:            /**
021:             * The current working directory, as a string.
022:             */
023:            static private String globalBase = "http://localhost/LocalHostBase/";
024:
025:            // Try to set the global base from the current directory.  
026:            // Security (e.g. Tomcat) may prevent this in which case we
027:            // use a common default set above.
028:            static {
029:                try {
030:                    globalBase = FileUtils.toURL(".");
031:                } catch (Throwable th) {
032:                }
033:            }
034:
035:            /**
036:             * The current working directory, as an IRI.
037:             */
038:            static final IRI cwd;
039:
040:            /**
041:             * An IRIFactory appropriately configuired.
042:             */
043:            static final IRIFactory factory = new IRIFactory(IRIFactory
044:                    .jenaImplementation());
045:            static {
046:                factory.setSameSchemeRelativeReferences("file");
047:            }
048:
049:            static {
050:
051:                IRI cwdx;
052:                try {
053:                    cwdx = factory.construct(globalBase);
054:                } catch (IRIException e) {
055:                    System.err
056:                            .println("Unexpected IRIException in initializer: "
057:                                    + e.getMessage());
058:                    cwdx = factory.create("file:///");
059:                }
060:                cwd = cwdx;
061:            }
062:
063:            /**
064:             * Turn a filename into a well-formed file: URL relative to the working
065:             * directory.
066:             * 
067:             * @param filename
068:             * @return String The filename as an absolute URL
069:             */
070:            static public String resolveFileURL(String filename)
071:                    throws IRIException {
072:                IRI r = cwd.resolve(filename);
073:                if (!r.getScheme().equalsIgnoreCase("file")) {
074:                    return resolveFileURL("./" + filename);
075:                }
076:                return r.toString();
077:            }
078:
079:            /**
080:             * Create resolve a URI against a base. If baseStr is a relative file IRI
081:             * then it is first resolved against the current working directory.
082:             * 
083:             * @param relStr
084:             * @param baseStr
085:             *            Can be null if relStr is absolute
086:             * @return String An absolute URI
087:             * @throws JenaURIException
088:             *             If result would not be legal, absolute IRI
089:             */
090:            static public String resolve(String relStr, String baseStr)
091:                    throws JenaURIException {
092:                return exceptions(resolveIRI(relStr, baseStr)).toString();
093:            }
094:
095:            /*
096:             * No exception thrown by this method.
097:             */
098:            static private IRI resolveIRI(String relStr, String baseStr) {
099:                IRI i = factory.create(relStr);
100:                if (i.isAbsolute())
101:                    // removes excess . segments
102:                    return cwd.create(i);
103:
104:                IRI base = factory.create(baseStr);
105:
106:                if ("file".equalsIgnoreCase(base.getScheme()))
107:                    return cwd.create(base).create(i);
108:                return base.create(i);
109:            }
110:
111:            final private IRI base;
112:
113:            /**
114:             * Construct an IRIResolver with base as the 
115:             * current working directory.
116:             *
117:             */
118:            public IRIResolver() {
119:                this (null);
120:            }
121:
122:            /**
123:             * Construct an IRIResolver with base determined
124:             * by the argument URI. If this is relative,
125:             * it is relative against the current working directory.
126:             * @param baseS
127:             * 
128:             * @throws JenaURIException
129:             *             If resulting base would not be legal, absolute IRI
130:             */
131:            public IRIResolver(String baseS) {
132:                if (baseS == null)
133:                    baseS = chooseBaseURI();
134:                // IRI aaa = RelURI.factory.construct(baseS);
135:                base = exceptions(cwd.create(baseS));
136:            }
137:
138:            /**
139:             * The base of this IRIResolver.
140:             * @return
141:             */
142:            public String getBaseIRI() {
143:                return base.toString();
144:            }
145:
146:            /**
147:             * Resolve the relative URI against the base of
148:             * this IRIResolver.
149:             * @param relURI
150:             * @return the resolved IRI
151:             * @throws JenaURIException
152:             *             If resulting URI would not be legal, absolute IRI
153:            
154:             */
155:            public String resolve(String relURI) {
156:                return exceptions(base.resolve(relURI)).toString();
157:            }
158:
159:            /**
160:             * Throw any exceptions resulting from IRI.
161:             * @param iri
162:             * @return iri
163:             */
164:            static private IRI exceptions(IRI iri) {
165:                if (iri.hasViolation(false)) {
166:                    try {
167:                        cwd.construct(iri);
168:                    } catch (IRIException e) {
169:                        throw new JenaURIException(e);
170:                    }
171:                }
172:                return iri;
173:            }
174:
175:            /**
176:             * Resolve the relative URI str against the current
177:             * working directory.
178:             * @param str
179:             * @return
180:             */
181:            public static String resolveGlobal(String str) {
182:                return exceptions(cwd.resolve(str)).toString();
183:            }
184:
185:            /**
186:             * Choose a base URI based on the current directory
187:             * 
188:             * @return String Absolute URI
189:             */
190:
191:            static public String chooseBaseURI() {
192:                return chooseBaseURI(null);
193:            }
194:
195:            /**
196:             * Choose a baseURI based on a suggestion
197:             * 
198:             * @return String URI (if relative, relative to current working directory).
199:             */
200:
201:            static public String chooseBaseURI(String baseURI) {
202:                if (baseURI == null)
203:                    baseURI = "file:.";
204:                return resolveGlobal(baseURI);
205:            }
206:
207:        }
208:
209:        /*
210:         * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP All rights
211:         * reserved.
212:         * 
213:         * Redistribution and use in source and binary forms, with or without
214:         * modification, are permitted provided that the following conditions are met:
215:         * 1. Redistributions of source code must retain the above copyright notice,
216:         * this list of conditions and the following disclaimer. 2. Redistributions in
217:         * binary form must reproduce the above copyright notice, this list of
218:         * conditions and the following disclaimer in the documentation and/or other
219:         * materials provided with the distribution. 3. The name of the author may not
220:         * be used to endorse or promote products derived from this software without
221:         * specific prior written permission.
222:         * 
223:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
224:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
225:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
226:         * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
227:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
228:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
229:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
230:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
231:         * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
232:         * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
233:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.