1 31 36 37 package com.hp.hpl.jena.rdf.arp; 38 import java.util.*; 39 40 41 46 class XMLContext extends Object { 47 final private String base; 48 final private String lang; 49 final private URI uri; 50 final private Map namespaces; 51 XMLContext document; 52 53 XMLContext(String base) throws MalformedURIException { 54 this(base,new URI(base)); 55 } 56 XMLContext(String base,URI uri) { 57 this(null,uri,base,"",ParserSupport.xmlNameSpace()); 58 document = this; 59 } 60 61 66 XMLContext(XMLContext document,URI uri,String base,String lang,Map namespaces) { 67 this.base=base; 68 this.lang=lang; 69 this.uri = uri; 70 this.document = document; 71 this.namespaces = namespaces; 72 } 73 XMLContext withBase(String b) throws MalformedURIException { 74 return new XMLContext(document,new URI(b),b,lang,namespaces); 75 } 76 XMLContext revertToDocument() { 77 return document.withLang(lang); 78 } 79 XMLContext withLang(String l) { 80 return clone(document,uri,base,l,namespaces); 81 } 82 String getLang() { 83 return lang; 84 } 85 86 String getBase() { 87 return base; 88 } 89 Map getNamespaces() { 90 return namespaces; 91 } 92 XMLContext addNamespace(Token prefix, Token ur) { 93 Map newns = new HashMap(namespaces); 94 newns.put(((StrToken)prefix).value,((StrToken)ur).value); 95 return clone(document,uri,base,lang,newns); 96 } 97 URI getURI() { 98 return uri; 99 } 100 boolean isSameAsDocument() { 101 return this==document || uri.equals(document.uri); 102 } 103 XMLContext getDocument() { 104 return document; 105 } 106 XMLContext clone(XMLContext document,URI uri,String base,String lang,Map namespaces) { 107 return new XMLContext(document,uri,base,lang,namespaces); 108 } 109 String resolve(Location l, String uri) throws MalformedURIException, ParseException { 110 return new URI(getURI(),uri).getURIString(); 111 } 112 String resolveSameDocRef(Location l, String sameDoc) throws ParseException { 113 return base + sameDoc; 114 } 115 } 116 | Popular Tags |