001: /*
002: * (c) Copyright 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: * * $Id: XMLContext.java,v 1.11 2008/01/02 12:09:08 andy_seaborne Exp $
028:
029: AUTHOR: Jeremy J. Carroll
030: */
031: /*
032: * XMLContext.java
033: *
034: * Created on July 10, 2001, 2:35 AM
035: */
036:
037: package com.hp.hpl.jena.rdf.arp.impl;
038:
039: import org.xml.sax.SAXParseException;
040:
041: import com.hp.hpl.jena.iri.IRI;
042: import com.hp.hpl.jena.rdf.arp.ARPErrorNumbers;
043: import com.hp.hpl.jena.rdf.arp.lang.LanguageTagCodes;
044:
045: /**
046: *
047: * Both the baseURI and the lang may be tainted with errors. They should not be
048: * accessed without providing a taint object to propogate such tainting.
049: *
050: * @author jjc
051: *
052: */
053: public class XMLContext extends AbsXMLContext implements
054: ARPErrorNumbers, LanguageTagCodes {
055: // final private String base;
056:
057: /**
058: * Creates new XMLContext
059: *
060: * @throws SAXParseException
061: */
062: XMLContext(XMLHandler h, String base) throws SAXParseException {
063:
064: this (h, h.iriFactory().create(base));
065: }
066:
067: protected XMLContext(XMLHandler h, IRI uri, Taint baseT) {
068: super (!h.ignoring(IGN_XMLBASE_SIGNIFICANT), null, uri, baseT,
069: "", new TaintImpl());
070: }
071:
072: private XMLContext(XMLHandler h, IRI baseMaybeWithFrag)
073: throws SAXParseException {
074: this (h, baseMaybeWithFrag.create(""), baseMaybeWithFrag);
075: }
076:
077: private XMLContext(XMLHandler h, IRI base, IRI baseMaybeWithFrag)
078: throws SAXParseException {
079: this (h, base, initTaint(h, baseMaybeWithFrag));
080: }
081:
082: XMLContext(boolean b, AbsXMLContext document, IRI uri, Taint baseT,
083: String lang, Taint langT) {
084: super (b, document, uri, baseT, lang, langT);
085: }
086:
087: boolean keepDocument(XMLHandler forErrors) {
088: return true;
089: }
090:
091: boolean isSameAsDocument() {
092: return this == document
093: || (uri == null ? document.uri == null : uri
094: .equals(document.uri));
095: }
096:
097: AbsXMLContext clone(IRI u, Taint baseT, String lng, Taint langT) {
098: return new XMLContext(true, document, u, baseT, lng, langT);
099: }
100:
101: void baseUsed(XMLHandler forErrors, Taint taintMe, String relUri,
102: String resolvedURI) throws SAXParseException {
103:
104: if (document == null || relUri.equals(resolvedURI))
105: return;
106: if (!isSameAsDocument()) {
107: String other = document.uri.create(relUri).toString();
108: if (!other.equals(resolvedURI)) {
109: forErrors.warning(taintMe, IGN_XMLBASE_SIGNIFICANT,
110: "Use of attribute xml:base changes interpretation of relative URI: \""
111: + relUri + "\".");
112: }
113: }
114: }
115:
116: void checkBaseUse(XMLHandler forErrors, Taint taintMe,
117: String relUri, IRI rslt) throws SAXParseException {
118: if (document == null)
119: return;
120:
121: String resolvedURI = rslt.toString();
122: if (relUri.equals(resolvedURI))
123: return;
124: if (!isSameAsDocument()) {
125: String other = document.uri.create(relUri).toString();
126: if (!other.equals(resolvedURI)) {
127: forErrors.warning(taintMe, IGN_XMLBASE_SIGNIFICANT,
128: "Use of attribute xml:base changes interpretation of relative URI: \""
129: + relUri + "\".");
130: }
131: }
132:
133: }
134:
135: }
|