001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: XMLBaselessContext.java,v 1.6 2008/01/02 12:09:05 andy_seaborne Exp $
005: */
006: package com.hp.hpl.jena.rdf.arp.impl;
007:
008: import org.xml.sax.SAXParseException;
009:
010: import com.hp.hpl.jena.iri.IRI;
011: import com.hp.hpl.jena.rdf.arp.ARPErrorNumbers;
012:
013: /**
014: * @author <a href="mailto:Jeremy.Carroll@hp.com">Jeremy Carroll</a>
015: *
016: */
017: public class XMLBaselessContext extends AbsXMLContext implements
018: ARPErrorNumbers {
019:
020: final int errno;
021:
022: final String errmsg;
023:
024: public XMLBaselessContext(XMLHandler f, int eno) {
025: this (f, eno, f.sameDocRef());
026: }
027:
028: // XMLBaselessContext(XMLHandler f, int eno, String baseURI) {
029: // this(f,eno,f.iriFactory().create(baseURI).create(""));
030: // }
031: XMLBaselessContext(XMLHandler f, int eno, IRI baseURI) {
032: super (true, null, baseURI, new TaintImpl(), "", new TaintImpl());
033: errno = eno;
034: switch (errno) {
035: case ERR_RESOLVING_URI_AGAINST_NULL_BASE:
036: errmsg = "Base URI is null, but there are relative URIs to resolve.";
037: break;
038: case WARN_RESOLVING_URI_AGAINST_EMPTY_BASE:
039: errmsg = "Base URI is \"\", relative URIs left as relative.";
040: break;
041: case ERR_RESOLVING_AGAINST_MALFORMED_BASE:
042: errmsg = "Resolving against bad URI <" + baseURI + ">";
043: break;
044: case ERR_RESOLVING_AGAINST_RELATIVE_BASE:
045: errmsg = "Resolving against relative URI <" + baseURI + ">";
046: break;
047: default:
048: throw new IllegalArgumentException("Unknown error code: "
049: + eno);
050: }
051: }
052:
053: private XMLBaselessContext(AbsXMLContext document, IRI uri,
054: Taint baseT, String lang, Taint langT,
055: XMLBaselessContext parent) {
056: super (true, document, uri, baseT, lang, langT);
057: errno = parent.errno;
058: errmsg = parent.errmsg;
059: }
060:
061: AbsXMLContext clone(IRI u, Taint baseT, String lng, Taint langT) {
062: return new XMLBaselessContext(document, u, baseT, lng, langT,
063: this );
064: }
065:
066: public AbsXMLContext withBase(XMLHandler forErrors, String b)
067: throws SAXParseException {
068: TaintImpl taintB = new TaintImpl();
069: IRI newB = resolveAsURI(forErrors, taintB, b, false);
070: if (newB.isRelative())
071: return new XMLBaselessContext(forErrors, errno, newB
072: .create(""));
073:
074: if (newB.hasViolation(false))
075: return new XMLBaselessContext(forErrors,
076: ERR_RESOLVING_AGAINST_MALFORMED_BASE, newB);
077: return new XMLContext(keepDocument(forErrors), document, newB
078: .create(""), taintB, lang, langTaint);
079: }
080:
081: boolean keepDocument(XMLHandler forErrors) {
082: return !forErrors.ignoring(IGN_XMLBASE_SIGNIFICANT);
083: }
084:
085: boolean isSameAsDocument() {
086: return this == document;
087: }
088:
089: void baseUsed(XMLHandler forErrors, Taint taintMe, String relUri,
090: String string) throws SAXParseException {
091: forErrors
092: .warning(taintMe, errno, errmsg + ": <" + relUri + ">");
093:
094: }
095:
096: void checkBaseUse(XMLHandler forErrors, Taint taintMe,
097: String relUri, IRI rslt) throws SAXParseException {
098:
099: String resolvedURI = rslt.toString();
100: if (relUri.equals(resolvedURI) && rslt.isAbsolute())
101: return;
102:
103: forErrors
104: .warning(taintMe, errno, errmsg + ": <" + relUri + ">");
105:
106: }
107:
108: }
109:
110: /*
111: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP All
112: * rights reserved.
113: *
114: * Redistribution and use in source and binary forms, with or without
115: * modification, are permitted provided that the following conditions are met:
116: *
117: * 1. Redistributions of source code must retain the above copyright notice,
118: * this list of conditions and the following disclaimer.
119: *
120: * 2. Redistributions in binary form must reproduce the above copyright notice,
121: * this list of conditions and the following disclaimer in the documentation
122: * and/or other materials provided with the distribution.
123: *
124: * 3. The name of the author may not be used to endorse or promote products
125: * derived from this software without specific prior written permission.
126: *
127: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
128: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
129: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
130: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
131: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
132: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
133: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
134: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
135: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
136: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
137: */
|