< prev index next >
jaxws/src/jdk.xml.bind/share/classes/com/sun/xml/internal/xsom/impl/parser/NGCCRuntimeEx.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -32,11 +32,10 @@
import com.sun.xml.internal.xsom.impl.SchemaImpl;
import com.sun.xml.internal.xsom.impl.UName;
import com.sun.xml.internal.xsom.impl.Const;
import com.sun.xml.internal.xsom.impl.parser.state.NGCCRuntime;
import com.sun.xml.internal.xsom.impl.parser.state.Schema;
-import com.sun.xml.internal.xsom.impl.util.Uri;
import com.sun.xml.internal.xsom.parser.AnnotationParser;
import com.sun.xml.internal.org.relaxng.datatype.ValidationContext;
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
@@ -46,12 +45,14 @@
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.LocatorImpl;
import java.io.IOException;
import java.net.URI;
+import java.net.URL;
import java.text.MessageFormat;
import java.util.Stack;
+import java.util.regex.Pattern;
/**
* NGCCRuntime extended with various utility methods for
* parsing XML Schema.
*
@@ -148,16 +149,19 @@
}
/* registers a patcher that will run after all the parsing has finished. */
+ @Override
public void addPatcher( Patch patcher ) {
parser.patcherManager.addPatcher(patcher);
}
+ @Override
public void addErrorChecker( Patch patcher ) {
parser.patcherManager.addErrorChecker(patcher);
}
+ @Override
public void reportError( String msg, Locator loc ) throws SAXException {
parser.patcherManager.reportError(msg,loc);
}
public void reportError( String msg ) throws SAXException {
reportError(msg,getLocator());
@@ -186,12 +190,19 @@
baseUri=documentSystemId;
EntityResolver er = parser.getEntityResolver();
String systemId = null;
- if (relativeUri!=null)
- systemId = Uri.resolve(baseUri,relativeUri);
+ if (relativeUri!=null) {
+ if (isAbsolute(relativeUri)) {
+ systemId = relativeUri;
+ }
+ if (baseUri == null || !isAbsolute(baseUri)) {
+ throw new IOException("Unable to resolve relative URI " + relativeUri + " because base URI is not absolute: " + baseUri);
+ }
+ systemId = new URL(new URL(baseUri), relativeUri).toString();
+ }
if (er!=null) {
InputSource is = er.resolveEntity(namespaceURI,systemId);
if (is == null) {
try {
@@ -215,11 +226,24 @@
parser.errorHandler.error(se);
return null;
}
}
- /** Includes the specified schema. */
+ private static final Pattern P = Pattern.compile(".*[/#?].*");
+
+ private static boolean isAbsolute(String uri) {
+ int i = uri.indexOf(':');
+ if (i < 0) {
+ return false;
+ }
+ return !P.matcher(uri.substring(0, i)).matches();
+ }
+
+ /**
+ * Includes the specified schema.
+ * @param schemaLocation
+ * @throws org.xml.sax.SAXException */
public void includeSchema( String schemaLocation ) throws SAXException {
NGCCRuntimeEx runtime = new NGCCRuntimeEx(parser,chameleonMode,this);
runtime.currentSchema = this.currentSchema;
runtime.blockDefault = this.blockDefault;
runtime.finalDefault = this.finalDefault;
@@ -233,11 +257,15 @@
runtime.parseEntity( resolveRelativeURL(null,schemaLocation),
true, currentSchema.getTargetNamespace(), getLocator() );
}
- /** Imports the specified schema. */
+ /**
+ * Imports the specified schema.
+ * @param ns
+ * @param schemaLocation
+ * @throws org.xml.sax.SAXException */
public void importSchema( String ns, String schemaLocation ) throws SAXException {
NGCCRuntimeEx newRuntime = new NGCCRuntimeEx(parser,false,this);
InputSource source = resolveRelativeURL(ns,schemaLocation);
if(source!=null)
newRuntime.parseEntity( source, false, ns, getLocator() );
@@ -315,13 +343,17 @@
}
/**
* Parses the specified entity.
*
+ * @param source
* @param importLocation
* The source location of the import/include statement.
* Used for reporting errors.
+ * @param includeMode
+ * @param expectedNamespace
+ * @throws org.xml.sax.SAXException
*/
public void parseEntity( InputSource source, boolean includeMode, String expectedNamespace, Locator importLocation )
throws SAXException {
documentSystemId = source.getSystemId();
@@ -340,27 +372,29 @@
}
}
/**
* Creates a new instance of annotation parser.
+ * @return
*/
public AnnotationParser createAnnotationParser() {
if(parser.getAnnotationParserFactory()==null)
return DefaultAnnotationParser.theInstance;
else
return parser.getAnnotationParserFactory().create();
}
/**
- * Gets the element name that contains the annotation element.
- * This method works correctly only when called by the annotation handler.
+ * Gets the element name that contains the annotation element.This method works correctly only when called by the annotation handler.
+ * @return
*/
public String getAnnotationContextElementName() {
return elementNames.get( elementNames.size()-2 );
}
- /** Creates a copy of the current locator object. */
+ /** Creates a copy of the current locator object.
+ * @return */
public Locator copyLocator() {
return new LocatorImpl(getLocator());
}
public ErrorHandler getErrorHandler() {
@@ -395,10 +429,11 @@
this.previous = _context;
this.prefix = _prefix;
this.uri = _uri;
}
+ @Override
public String resolveNamespacePrefix(String p) {
if(p.equals(prefix)) return uri;
if(previous==null) return null;
else return previous.resolveNamespacePrefix(p);
}
@@ -406,18 +441,22 @@
private final String prefix;
private final String uri;
private final Context previous;
// XSDLib don't use those methods, so we cut a corner here.
+ @Override
public String getBaseUri() { return null; }
+ @Override
public boolean isNotation(String arg0) { return false; }
+ @Override
public boolean isUnparsedEntity(String arg0) { return false; }
}
private Context currentContext=null;
- /** Returns an immutable snapshot of the current context. */
+ /** Returns an immutable snapshot of the current context.
+ * @return */
public ValidationContext createValidationContext() {
return currentContext;
}
public XmlString createXmlString(String value) {
@@ -444,10 +483,11 @@
/**
* Parses UName under the given context.
* @param qname Attribute name.
* @return New {@link UName} instance based on attribute name.
+ * @throws org.xml.sax.SAXException
*/
public UName parseUName(final String qname ) throws SAXException {
int idx = qname.indexOf(':');
if(idx<0) {
String uri = resolveNamespacePrefix("");
< prev index next >