8306055: Add a built-in Catalog to JDK XML module

Reviewed-by: ihse, lancea, alanb
This commit is contained in:
Joe Wang 2023-11-22 17:11:26 +00:00
parent a4bd9e4d0b
commit 93bdc2a6db
50 changed files with 1730 additions and 216 deletions

View File

@ -27,4 +27,5 @@ DISABLED_WARNINGS_java += lossy-conversions this-escape
DOCLINT += -Xdoclint:all/protected \
'-Xdoclint/package:$(call CommaList, javax.xml.catalog javax.xml.datatype \
javax.xml.transform javax.xml.validation javax.xml.xpath)'
COPY += .dtd .xsd .xml
CLEAN += .properties

View File

@ -46,7 +46,7 @@ import jdk.xml.internal.XMLSecurityManager;
* @author K Venugopal
* @author Sunitha Reddy
*
* @LastModified: July 2023
* @LastModified: Nov 2023
*/
public class PropertyManager {
@ -150,10 +150,7 @@ public class PropertyManager {
// Initialize Catalog features
supportedProps.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
for (CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) {
supportedProps.put(f.getPropertyName(), null);
}
JdkXmlUtils.initCatalogFeatures(supportedProps);
supportedProps.put(JdkConstants.CDATA_CHUNK_SIZE, JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
}

View File

@ -74,7 +74,7 @@ import jdk.xml.internal.XMLSecurityManager.Limit;
* @author Eric Ye, IBM
* @author Sunitha Reddy, SUN Microsystems
*
* @LastModified: July 2023
* @LastModified: Nov 2023
*/
public class XMLDocumentFragmentScannerImpl
extends XMLScanner
@ -343,6 +343,13 @@ public class XMLDocumentFragmentScannerImpl
*/
protected String fAccessExternalDTD = EXTERNAL_ACCESS_DEFAULT;
/**
* Properties to determine whether to use a user-specified Catalog:
* Feature USE_CATALOG, Resolve and Catalog File
*/
protected boolean fUseCatalog = true;
protected String fCatalogFile;
/**
* standard uri conformant (strict uri).
* http://apache.org/xml/features/standard-uri-conformant

View File

@ -43,9 +43,11 @@ import com.sun.xml.internal.stream.dtd.DTDGrammarUtil;
import java.io.CharConversionException;
import java.io.EOFException;
import java.io.IOException;
import javax.xml.XMLConstants;
import javax.xml.stream.events.XMLEvent;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty.State;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
import jdk.xml.internal.XMLSecurityManager.Limit;
@ -69,7 +71,7 @@ import jdk.xml.internal.XMLSecurityManager.Limit;
* Refer to the table in unit-test javax.xml.stream.XMLStreamReaderTest.SupportDTD for changes
* related to property SupportDTD.
* @author Joe Wang, Sun Microsystems
* @LastModified: July 2023
* @LastModified: Nov 2023
*/
public class XMLDocumentScannerImpl
extends XMLDocumentFragmentScannerImpl{
@ -281,6 +283,9 @@ public class XMLDocumentScannerImpl
fLoadExternalDTD = !((Boolean)propertyManager.getProperty(
Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD));
fUseCatalog = (Boolean)propertyManager.getProperty(XMLConstants.USE_CATALOG);
fCatalogFile = (String)propertyManager.getProperty(JdkXmlUtils.CATALOG_FILES);
setScannerState(XMLEvent.START_DOCUMENT);
setDriver(fXMLDeclDriver);
fSeenInternalSubset = false;
@ -327,6 +332,8 @@ public class XMLDocumentScannerImpl
// xerces features
fLoadExternalDTD = componentManager.getFeature(LOAD_EXTERNAL_DTD, true);
fUseCatalog = componentManager.getFeature(XMLConstants.USE_CATALOG, true);
fCatalogFile = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_FILES);
fNamespaces = componentManager.getFeature(NAMESPACES, true);
fSeenInternalSubset = false;

View File

@ -56,6 +56,7 @@ import javax.xml.catalog.CatalogManager;
import javax.xml.catalog.CatalogResolver;
import javax.xml.stream.XMLInputFactory;
import javax.xml.transform.Source;
import jdk.xml.internal.JdkCatalog;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty;
import jdk.xml.internal.JdkXmlUtils;
@ -93,7 +94,7 @@ import org.xml.sax.InputSource;
* @author K.Venugopal SUN Microsystems
* @author Neeraj Bajaj SUN Microsystems
* @author Sunitha Reddy SUN Microsystems
* @LastModified: July 2023
* @LastModified: Nov 2023
*/
public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
@ -265,9 +266,6 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
/** Debug switching readers for encodings. */
private static final boolean DEBUG_ENCODINGS = false;
// should be diplayed trace resolving messages
private static final boolean DEBUG_RESOLVER = false ;
//
// Data
//
@ -355,6 +353,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
/** Security Manager */
protected XMLSecurityManager fSecurityManager = null;
XMLSecurityPropertyManager fSecurityPropertyMgr;
protected XMLLimitAnalyzer fLimitAnalyzer = null;
@ -418,8 +417,11 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
/** indicate whether Catalog should be used for resolving external resources */
private boolean fUseCatalog = true;
// user-specified Catalog Resolver
CatalogFeatures fCatalogFeatures;
CatalogResolver fCatalogResolver;
// the default JDK Catalog Resolver
CatalogResolver fDefCR;
private String fCatalogFile;
private String fDefer;
@ -434,11 +436,16 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* If this constructor is used to create the object, reset() should be invoked on this object
*/
public XMLEntityManager() {
this(null, new XMLSecurityManager(true));
}
public XMLEntityManager(XMLSecurityPropertyManager securityPropertyMgr, XMLSecurityManager securityManager) {
//for entity managers not created by parsers
fSecurityManager = new XMLSecurityManager(true);
fSecurityManager = securityManager;
fSecurityPropertyMgr = securityPropertyMgr;
fEntityStorage = new XMLEntityStorage(this) ;
setScannerVersion(Constants.XML_VERSION_1_0);
} // <init>()
}
/** Default constructor. */
public XMLEntityManager(PropertyManager propertyManager) {
@ -653,8 +660,12 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
URL location = new URL(expandedSystemId);
URLConnection connect = location.openConnection();
if (!(connect instanceof HttpURLConnection)) {
if (expandedSystemId.startsWith("jrt:/java.xml")) {
stream = SecuritySupport.getInputStream(connect);
} else {
stream = connect.getInputStream();
}
}
else {
boolean followRedirects = true;
@ -1012,75 +1023,128 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
ri = fResourceIdentifier;
}
ri.setValues(publicId, literalSystemId, baseSystemId, expandedSystemId);
if(DEBUG_RESOLVER){
System.out.println("BEFORE Calling resolveEntity") ;
}
fISCreatedByResolver = false;
//either of Stax or Xerces would be null
// Step 1: custom resolver, either StAX or Entity
if (fStaxEntityResolver != null) {
staxInputSource = fStaxEntityResolver.resolveEntity(ri);
if(staxInputSource != null) {
fISCreatedByResolver = true;
}
}
if(fEntityResolver != null){
} else if (fEntityResolver != null) {
xmlInputSource = fEntityResolver.resolveEntity(ri);
if (xmlInputSource != null) {
//wrap it in StaxXMLInputSource
fISCreatedByResolver = true;
}
}
if(xmlInputSource != null){
//wrap this XMLInputSource to StaxInputSource
staxInputSource = new StaxXMLInputSource(xmlInputSource, fISCreatedByResolver);
}
if (staxInputSource == null && fUseCatalog) {
if (fCatalogFeatures == null) {
fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
}
fCatalogFile = fCatalogFeatures.get(Feature.FILES);
if (fCatalogFile != null) {
try {
// Step 2: custom catalog if specified
if (staxInputSource == null && (fUseCatalog && fCatalogFile != null)) {
if (fCatalogResolver == null) {
fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
fCatalogResolver = CatalogManager.catalogResolver(fCatalogFeatures);
}
InputSource is = fCatalogResolver.resolveEntity(publicId, literalSystemId);
if (is != null && !is.isEmpty()) {
staxInputSource = new StaxXMLInputSource(new XMLInputSource(is, true), true);
}
} catch (CatalogException e) {
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,"CatalogException",
new Object[]{SecuritySupport.sanitizePath(fCatalogFile)},
XMLErrorReporter.SEVERITY_FATAL_ERROR, e );
}
}
staxInputSource = resolveWithCatalogStAX(fCatalogResolver, fCatalogFile, publicId, literalSystemId);
}
// do default resolution
//this works for both stax & Xerces, if staxInputSource is null,
//it means parser need to revert to default resolution
if (staxInputSource == null) {
// REVISIT: when systemId is null, I think we should return null.
// is this the right solution? -SG
//if (systemId != null)
// Step 3: use the default JDK Catalog Resolver if Step 2's resolve is continue
if (staxInputSource == null && JdkXmlUtils.isResolveContinue(fCatalogFeatures)) {
initJdkCatalogResolver();
staxInputSource = resolveWithCatalogStAX(fDefCR, JdkCatalog.JDKCATALOG, publicId, literalSystemId);
}
// Step 4: default resolution if not resolved by a resolver and the RESOLVE
// feature is set to 'continue'
if (staxInputSource != null) {
fISCreatedByResolver = true;
} else if (JdkXmlUtils.isResolveContinue(fCatalogFeatures) &&
fSecurityManager.is(Limit.JDKCATALOG_RESOLVE, JdkConstants.CONTINUE)) {
staxInputSource = new StaxXMLInputSource(
new XMLInputSource(publicId, literalSystemId, baseSystemId, true), false);
}else if(staxInputSource.hasXMLStreamOrXMLEventReader()){
//Waiting for the clarification from EG. - nb
}
if (DEBUG_RESOLVER) {
System.err.println("XMLEntityManager.resolveEntity(" + publicId + ")");
System.err.println(" = " + xmlInputSource);
}
return staxInputSource;
}
private void initJdkCatalogResolver() {
if (fDefCR == null) {
fDefCR = fSecurityManager.getJDKCatalogResolver();
}
}
/**
* Resolves the external resource using the Catalog specified and returns
* a StaxXMLInputSource.
*/
private StaxXMLInputSource resolveWithCatalogStAX(CatalogResolver cr, String cFile,
String publicId, String systemId) {
InputSource is = resolveWithCatalog(cr, cFile, publicId, systemId);
// note that empty source isn't considered resolved
if (is != null) {
return new StaxXMLInputSource(new XMLInputSource(is, true), true);
}
return null;
}
/**
* Resolves the external resource using the Catalog specified and returns
* a InputSource.
*/
private InputSource resolveWithCatalog(CatalogResolver cr, String cFile,
String publicId, String systemId) {
if (cr != null) {
try {
return cr.resolveEntity(publicId, systemId);
} catch (CatalogException e) {
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,"CatalogException",
new Object[]{SecuritySupport.sanitizePath(cFile)},
XMLErrorReporter.SEVERITY_FATAL_ERROR, e );
}
}
return null;
}
/**
* Resolves the external resource using the Catalog specified and returns
* a XMLInputSource. Since the Resolve method can be called from various processors,
* this method attempts to resolve the resource as an EntityResolver first
* and then URIResolver if no match is found.
*/
private XMLInputSource resolveEntityOrURI(CatalogResolver cr, String publicId, String systemId, String base) {
XMLInputSource xis = resolveEntity(cr, publicId, systemId, base);
if (xis != null) {
return xis;
} else if (systemId != null) {
Source source = null;
try {
source = cr.resolve(systemId, base);
} catch (CatalogException e) {
throw new XNIException(e);
}
if (source != null && !source.isEmpty()) {
return new XMLInputSource(publicId, source.getSystemId(), base, true);
}
}
return null;
}
private XMLInputSource resolveEntity(CatalogResolver cr, String publicId, String systemId, String base) {
InputSource is = null;
try {
if (publicId != null || systemId != null) {
is = cr.resolveEntity(publicId, systemId);
}
} catch (CatalogException e) {}
if (is != null && !is.isEmpty()) {
return new XMLInputSource(is, true);
}
return null;
}
/**
* Resolves the specified public and system identifiers. This
* method first attempts to resolve the entity based on the
@ -1128,7 +1192,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
if (needExpand)
expandedSystemId = expandSystemId(literalSystemId, baseSystemId,false);
// give the entity resolver a chance
// Step 1: custom Entity resolver
XMLInputSource xmlInputSource = null;
if (fEntityResolver != null) {
@ -1137,65 +1201,32 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
}
if (xmlInputSource == null && fUseCatalog) {
if (fCatalogFeatures == null) {
fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
}
fCatalogFile = fCatalogFeatures.get(Feature.FILES);
if (fCatalogFile != null) {
/*
since the method can be called from various processors, both
EntityResolver and URIResolver are used to attempt to find
a match
*/
InputSource is = null;
try {
// Step 2: custom catalog if specified
if ((publicId != null || literalSystemId != null || resourceIdentifier.getNamespace() !=null)
&& xmlInputSource == null && (fUseCatalog && fCatalogFile != null)) {
if (fCatalogResolver == null) {
fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
fCatalogResolver = CatalogManager.catalogResolver(fCatalogFeatures);
}
String pid = (publicId != null? publicId : resourceIdentifier.getNamespace());
if (pid != null || literalSystemId != null) {
is = fCatalogResolver.resolveEntity(pid, literalSystemId);
}
} catch (CatalogException e) {}
if (is != null && !is.isEmpty()) {
xmlInputSource = new XMLInputSource(is, true);
} else if (literalSystemId != null) {
if (fCatalogResolver == null) {
fCatalogResolver = CatalogManager.catalogResolver(fCatalogFeatures);
xmlInputSource = resolveEntityOrURI(fCatalogResolver, pid, literalSystemId, baseSystemId);
}
Source source = null;
try {
source = fCatalogResolver.resolve(literalSystemId, baseSystemId);
} catch (CatalogException e) {
throw new XNIException(e);
}
if (source != null && !source.isEmpty()) {
xmlInputSource = new XMLInputSource(publicId, source.getSystemId(), baseSystemId, true);
}
}
}
// Step 3: use the default JDK Catalog Resolver if Step 2's resolve is continue
if ((publicId != null || literalSystemId != null)
&& xmlInputSource == null && JdkXmlUtils.isResolveContinue(fCatalogFeatures)) {
initJdkCatalogResolver();
// unlike a custom catalog, the JDK Catalog only contains entity references
xmlInputSource = resolveEntity(fDefCR, publicId, literalSystemId, baseSystemId);
}
// do default resolution
// REVISIT: what's the correct behavior if the user provided an entity
// resolver (fEntityResolver != null), but resolveEntity doesn't return
// an input source (xmlInputSource == null)?
// do we do default resolution, or do we just return null? -SG
if (xmlInputSource == null) {
// REVISIT: when systemId is null, I think we should return null.
// is this the right solution? -SG
//if (systemId != null)
// Step 4: default resolution if not resolved by a resolver and the RESOLVE
// feature is set to 'continue'
if ((xmlInputSource == null) && JdkXmlUtils.isResolveContinue(fCatalogFeatures) &&
fSecurityManager.is(Limit.JDKCATALOG_RESOLVE, JdkConstants.CONTINUE)) {
xmlInputSource = new XMLInputSource(publicId, literalSystemId, baseSystemId, false);
}
if (DEBUG_RESOLVER) {
System.err.println("XMLEntityManager.resolveEntity(" + publicId + ")");
System.err.println(" = " + xmlInputSource);
}
return xmlInputSource;
} // resolveEntity(XMLResourceIdentifier):XMLInputSource

View File

@ -63,7 +63,7 @@ import org.xml.sax.helpers.DefaultHandler;
* @author Rajiv Mordani
* @author Edwin Goei
*
* @LastModified: July 2023
* @LastModified: Nov 2023
*/
@SuppressWarnings("deprecation")
public class SAXParserImpl extends javax.xml.parsers.SAXParser
@ -402,7 +402,7 @@ public class SAXParserImpl extends javax.xml.parsers.SAXParser
JAXPSAXParser(SAXParserImpl saxParser, XMLSecurityPropertyManager securityPropertyMgr,
XMLSecurityManager securityManager) {
super();
super(null, null, securityPropertyMgr, securityManager);
fSAXParser = saxParser;
fSecurityManager = securityManager;
fSecurityPropertyMgr = securityPropertyMgr;

View File

@ -162,9 +162,6 @@ public final class XMLSchemaFactory extends SchemaFactory {
// use catalog
fXMLSchemaLoader.setFeature(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
for (Feature f : Feature.values()) {
fXMLSchemaLoader.setProperty(f.getPropertyName(), null);
}
fXMLSchemaLoader.setProperty(JdkConstants.CDATA_CHUNK_SIZE, JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
fXmlFeatures = new JdkXmlFeatures(fSecurityManager.isSecureProcessing());

View File

@ -41,7 +41,7 @@ import org.xml.sax.SAXNotSupportedException;
* @author Arnaud Le Hors, IBM
* @author Andy Clark, IBM
*
* @LastModified: Sep 2023
* @LastModified: Nov 2023
*/
public class SAXParser
extends AbstractSAXParser {
@ -91,21 +91,21 @@ public class SAXParser
*/
public SAXParser(XMLParserConfiguration config) {
super(config);
initSecurityManager();
initSecurityManager(null, null);
} // <init>(XMLParserConfiguration)
/**
* Constructs a SAX parser using the dtd/xml schema parser configuration.
*/
public SAXParser() {
this(null, null);
this(null, null, null, null);
} // <init>()
/**
* Constructs a SAX parser using the specified symbol table.
*/
public SAXParser(SymbolTable symbolTable) {
this(symbolTable, null);
this(symbolTable, null, null, null);
} // <init>(SymbolTable)
/**
@ -113,6 +113,11 @@ public class SAXParser
* grammar pool.
*/
public SAXParser(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
this(symbolTable, grammarPool, null, null);
}
public SAXParser(SymbolTable symbolTable, XMLGrammarPool grammarPool,
XMLSecurityPropertyManager securityPropertyMgr, XMLSecurityManager securityManager) {
super(new XIncludeAwareParserConfiguration());
// set features
@ -128,7 +133,7 @@ public class SAXParser
fConfiguration.setProperty(XMLGRAMMAR_POOL, grammarPool);
}
initSecurityManager();
initSecurityManager(securityPropertyMgr, securityManager);
} // <init>(SymbolTable,XMLGrammarPool)
/**
@ -172,25 +177,4 @@ public class SAXParser
}
}
}
/**
* Initiates the SecurityManager. This becomes necessary when the SAXParser
* is constructed directly by, for example, XMLReaderFactory rather than
* through SAXParserFactory.
*/
private void initSecurityManager() {
try {
if (securityManager == null) {
securityManager = new XMLSecurityManager(true);
super.setProperty(Constants.SECURITY_MANAGER, securityManager);
}
if (securityPropertyManager == null) {
securityPropertyManager = new XMLSecurityPropertyManager();
super.setProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
}
} catch (SAXException e) {
Utils.dPrint(() -> e.getMessage());
}
}
} // class SAXParser

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -25,6 +24,7 @@ import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.util.FeatureState;
import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
import com.sun.org.apache.xerces.internal.util.SymbolTable;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
import com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler;
import com.sun.org.apache.xerces.internal.xinclude.XIncludeNamespaceSupport;
import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
@ -33,6 +33,7 @@ import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
import jdk.xml.internal.XMLSecurityManager;
/**
* This class is the configuration used to parse XML 1.0 and XML 1.1 documents
@ -40,6 +41,7 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
*
* @author Michael Glavassevich, IBM
*
* @LastModified: Nov 2023
*/
public class XIncludeAwareParserConfiguration extends XML11Configuration {
@ -88,7 +90,7 @@ public class XIncludeAwareParserConfiguration extends XML11Configuration {
/** Default constructor. */
public XIncludeAwareParserConfiguration() {
this(null, null, null);
this(null, null, null, null, null);
} // <init>()
/**
@ -97,7 +99,7 @@ public class XIncludeAwareParserConfiguration extends XML11Configuration {
* @param symbolTable The symbol table to use.
*/
public XIncludeAwareParserConfiguration(SymbolTable symbolTable) {
this(symbolTable, null, null);
this(symbolTable, null, null, null, null);
} // <init>(SymbolTable)
/**
@ -111,7 +113,7 @@ public class XIncludeAwareParserConfiguration extends XML11Configuration {
public XIncludeAwareParserConfiguration(
SymbolTable symbolTable,
XMLGrammarPool grammarPool) {
this(symbolTable, grammarPool, null);
this(symbolTable, grammarPool, null, null, null);
} // <init>(SymbolTable,XMLGrammarPool)
/**
@ -123,11 +125,15 @@ public class XIncludeAwareParserConfiguration extends XML11Configuration {
* @param grammarPool The grammar pool to use.
* @param parentSettings The parent settings.
*/
public XIncludeAwareParserConfiguration(
SymbolTable symbolTable,
XMLGrammarPool grammarPool,
public XIncludeAwareParserConfiguration(SymbolTable symbolTable, XMLGrammarPool grammarPool,
XMLComponentManager parentSettings) {
super(symbolTable, grammarPool, parentSettings);
this(symbolTable, grammarPool, parentSettings, null, null);
}
public XIncludeAwareParserConfiguration(SymbolTable symbolTable, XMLGrammarPool grammarPool,
XMLComponentManager parentSettings, XMLSecurityPropertyManager securityPropertyMgr,
XMLSecurityManager securityManager) {
super(symbolTable, grammarPool, parentSettings, securityPropertyMgr, securityManager);
final String[] recognizedFeatures = {
ALLOW_UE_AND_NOTATION_EVENTS,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -46,6 +46,7 @@ import com.sun.org.apache.xerces.internal.util.FeatureState;
import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;
import com.sun.org.apache.xerces.internal.util.PropertyState;
import com.sun.org.apache.xerces.internal.util.SymbolTable;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
@ -70,6 +71,7 @@ import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.XMLSecurityManager;
/**
* This class is the configuration used to parse XML 1.0 and XML 1.1 documents.
@ -78,7 +80,7 @@ import jdk.xml.internal.JdkXmlUtils;
* @author Neil Graham, IBM
* @author Michael Glavassevich, IBM
*
* @LastModified: May 2021
* @LastModified: Nov 2023
*/
public class XML11Configuration extends ParserConfigurationSettings
implements XMLPullParserConfiguration, XML11Configurable {
@ -432,7 +434,7 @@ public class XML11Configuration extends ParserConfigurationSettings
/** Default constructor. */
public XML11Configuration() {
this(null, null, null);
this(null, null, null, null, null);
} // <init>()
/**
@ -441,7 +443,7 @@ public class XML11Configuration extends ParserConfigurationSettings
* @param symbolTable The symbol table to use.
*/
public XML11Configuration(SymbolTable symbolTable) {
this(symbolTable, null, null);
this(symbolTable, null, null, null, null);
} // <init>(SymbolTable)
/**
@ -456,7 +458,7 @@ public class XML11Configuration extends ParserConfigurationSettings
* @param grammarPool The grammar pool to use.
*/
public XML11Configuration(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
this(symbolTable, grammarPool, null);
this(symbolTable, grammarPool, null, null, null);
} // <init>(SymbolTable,XMLGrammarPool)
/**
@ -471,10 +473,14 @@ public class XML11Configuration extends ParserConfigurationSettings
* @param grammarPool The grammar pool to use.
* @param parentSettings The parent settings.
*/
public XML11Configuration(
SymbolTable symbolTable,
XMLGrammarPool grammarPool,
public XML11Configuration(SymbolTable symbolTable, XMLGrammarPool grammarPool,
XMLComponentManager parentSettings) {
this(symbolTable, grammarPool, parentSettings, null, null);
}
public XML11Configuration(SymbolTable symbolTable, XMLGrammarPool grammarPool,
XMLComponentManager parentSettings, XMLSecurityPropertyManager securityPropertyMgr,
XMLSecurityManager securityManager) {
super(parentSettings);
@ -592,7 +598,7 @@ public class XML11Configuration extends ParserConfigurationSettings
fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
}
fEntityManager = new XMLEntityManager();
fEntityManager = new XMLEntityManager(securityPropertyMgr, securityManager);
fProperties.put(ENTITY_MANAGER, fEntityManager);
addCommonComponent(fEntityManager);
@ -640,11 +646,6 @@ public class XML11Configuration extends ParserConfigurationSettings
// REVISIT: What is the right thing to do? -Ac
}
// Initialize Catalog features
for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) {
fProperties.put(f.getPropertyName(), null);
}
setProperty(JdkConstants.CDATA_CHUNK_SIZE, JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
fConfigUpdated = false;

View File

@ -28,7 +28,9 @@ import com.sun.org.apache.xerces.internal.xni.XNIException;
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.Utils;
import jdk.xml.internal.XMLSecurityManager;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXNotRecognizedException;
@ -48,7 +50,7 @@ import org.xml.sax.SAXNotRecognizedException;
*
* @author Arnaud Le Hors, IBM
* @author Andy Clark, IBM
* @LastModified: July 2023
* @LastModified: Nov 2023
*/
public abstract class XMLParser {
@ -127,20 +129,29 @@ public abstract class XMLParser {
public void parse(XMLInputSource inputSource)
throws XNIException, IOException {
// null indicates that the parser is called directly, initialize them
if (securityManager == null) {
securityManager = new XMLSecurityManager(true);
fConfiguration.setProperty(Constants.SECURITY_MANAGER, securityManager);
}
if (securityPropertyManager == null) {
securityPropertyManager = new XMLSecurityPropertyManager();
fConfiguration.setProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
}
initSecurityManager(null, null);
reset();
fConfiguration.parse(inputSource);
} // parse(XMLInputSource)
/**
* Initiates the SecurityManager. This becomes necessary when the Parser
* is constructed directly by, for example, XMLReaderFactory rather than
* through SAXParserFactory.
*/
void initSecurityManager(XMLSecurityPropertyManager spm, XMLSecurityManager sm) {
if (securityManager == null) {
securityManager = sm != null ? sm : new XMLSecurityManager(true);
}
fConfiguration.setProperty(Constants.SECURITY_MANAGER, securityManager);
if (securityPropertyManager == null) {
securityPropertyManager = spm != null ? spm : new XMLSecurityPropertyManager();
}
fConfiguration.setProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
}
//
// Protected methods
//

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -28,6 +28,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jdk.xml.internal.JdkXmlUtils;
/**
* This class implements the basic operations for managing parser
@ -42,7 +43,7 @@ import java.util.Map;
*
* @author Andy Clark, IBM
*
* @LastModified: Apr 2019
* @LastModified: Nov 2023
*/
public class ParserConfigurationSettings
implements XMLComponentManager {
@ -97,6 +98,8 @@ public class ParserConfigurationSettings
// save parent
fParentSettings = parent;
// Initialize Catalog features
JdkXmlUtils.initCatalogFeatures(fProperties);
} // <init>(XMLComponentManager)
//

View File

@ -165,7 +165,7 @@ class Util {
case SCHEME_FILE:
String path = uri.getPath();
File f1 = new File(path);
if (f1.isFile()) {
if (SecuritySupport.isFile(f1)) {
return true;
}
break;

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2023, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.xml.internal;
import java.net.URI;
import javax.xml.catalog.Catalog;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogManager;
/**
* Represents the built-in Catalog that hosts the DTDs for the Java platform.
*/
public class JdkCatalog {
public static final String JDKCATALOG = "/jdk/xml/internal/jdkcatalog/JDKCatalog.xml";
private static final String JDKCATALOG_URL = SecuritySupport.getResource(JDKCATALOG).toExternalForm();
public static Catalog catalog;
public static void init(String resolve) {
if (catalog == null) {
CatalogFeatures cf = JdkXmlUtils.getCatalogFeatures(null, JDKCATALOG_URL, null, resolve);
catalog = CatalogManager.catalog(cf, URI.create(JDKCATALOG_URL));
}
}
}

View File

@ -291,6 +291,7 @@ public final class JdkConstants {
/**
* System Property for the DTD property
* @since 22
*/
public static final String DTD_PROPNAME = "jdk.xml.dtd.support";
@ -299,6 +300,17 @@ public final class JdkConstants {
public static final int IGNORE = 1;
public static final int DENY = 2;
/**
* System Property for the JDKCatalog' RESOLVE property
* @since 22
*/
public static final String JDKCATALOG_RESOLVE = "jdk.xml.jdkCatalog.resolve";
// Catalog Resolve Integer mappings for String values
public static final int CONTINUE = 0;
//public static final int IGNORE = 1; // same as that of DTD
public static final int STRICT = 2;
/**
* Values for a feature
*/

View File

@ -31,6 +31,7 @@ import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
import java.util.Map;
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogFeatures.Feature;
@ -156,6 +157,31 @@ public class JdkXmlUtils {
return null;
}
/**
* Initialize catalog features, including setting the default values and reading
* from the JAXP configuration file and System Properties.
*
* @param properties the Map object that holds the properties
*/
public static void initCatalogFeatures(Map<String, Object> properties) {
CatalogFeatures cf = getCatalogFeatures();
for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) {
properties.put(f.getPropertyName(), cf.get(f));
}
}
/**
* Creates an instance of a CatalogFeatures with default settings.
* Note: the CatalogFeatures is initialized with settings in the following
* order:
* Default values -> values in the config -> values set with System Properties
*
* @return an instance of a CatalogFeatures
*/
public static CatalogFeatures getCatalogFeatures() {
return CatalogFeatures.builder().build();
}
/**
* Creates an instance of a CatalogFeatures.
*

View File

@ -30,6 +30,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Paths;
import java.security.AccessController;
import java.security.CodeSource;
@ -266,6 +267,18 @@ public class SecuritySupport {
-> f.exists()));
}
/**
* Tests whether the input is file.
*
* @param f the file to be tested
* @return true if the input is file, false otherwise
*/
@SuppressWarnings("removal")
public static boolean isFile(final File f) {
return (AccessController.doPrivileged((PrivilegedAction<Boolean>) ()
-> f.isFile()));
}
/**
* Creates and returns a new FileInputStream from a file.
* @param file the specified file
@ -283,6 +296,23 @@ public class SecuritySupport {
}
}
/**
* Returns an InputStream from a URLConnection.
* @param uc the URLConnection
* @return the InputStream
* @throws IOException if an I/O error occurs while creating the input stream
*/
@SuppressWarnings("removal")
public static InputStream getInputStream(final URLConnection uc)
throws IOException {
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<InputStream>) ()
-> uc.getInputStream());
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}
}
/**
* Returns the resource as a stream.
* @param name the resource name
@ -294,6 +324,17 @@ public class SecuritySupport {
SecuritySupport.class.getResourceAsStream("/"+name));
}
/**
* Returns the resource by the name.
* @param name the resource name
* @return the resource
*/
@SuppressWarnings("removal")
public static URL getResource(final String name) {
return AccessController.doPrivileged((PrivilegedAction<URL>) () ->
SecuritySupport.class.getResource(name));
}
/**
* Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.
* @param bundle the base name of the resource bundle, a fully qualified class name

View File

@ -32,6 +32,9 @@ import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import javax.xml.catalog.CatalogManager;
import javax.xml.catalog.CatalogResolver;
import javax.xml.catalog.CatalogResolver.NotFoundAction;
import javax.xml.stream.XMLInputFactory;
import jdk.xml.internal.JdkProperty.State;
import jdk.xml.internal.JdkProperty.ImplPropMap;
@ -67,15 +70,30 @@ public final class XMLSecurityManager {
DTD_MAP = Collections.unmodifiableMap(map);
}
// Valid values for Catalog Resolve, and mappings between the string and
// interger values
static final Map<String, Integer> CR_MAP;
// Source Level JDK 8
static {
Map<String, Integer> map = new HashMap<>();
map.put("continue", 0);
map.put("ignore", 1);
map.put("strict", 2);
CR_MAP = Collections.unmodifiableMap(map);
}
// Value converter for properties of type Boolean
private static final BooleanMapper BOOLMAPPER = new BooleanMapper();
// Value converter for properties of type Integer
private static final IntegerMapper INTMAPPER = new IntegerMapper();
// DTD value map
// DTD value mapper
private static final StringMapper DTDMAPPER = new StringMapper(DTD_MAP);
// Catalog Resolve value mapper
private static final StringMapper CRMAPPER = new StringMapper(CR_MAP);
/**
* Limits managed by the security manager
*/
@ -109,6 +127,8 @@ public final class XMLSecurityManager {
JdkConstants.ALLOW, JdkConstants.ALLOW, Processor.PARSER, DTDMAPPER),
XERCES_DISALLOW_DTD("disallowDTD", DISALLOW_DTD, null, null, 0, 0, Processor.PARSER, BOOLMAPPER),
STAX_SUPPORT_DTD("supportDTD", XMLInputFactory.SUPPORT_DTD, null, null, 1, 1, Processor.PARSER, BOOLMAPPER),
JDKCATALOG_RESOLVE("JDKCatalogResolve", JdkConstants.JDKCATALOG_RESOLVE, JdkConstants.JDKCATALOG_RESOLVE, null,
JdkConstants.CONTINUE, JdkConstants.CONTINUE, Processor.PARSER, CRMAPPER),
;
final String key;
@ -266,6 +286,48 @@ public final class XMLSecurityManager {
//read system properties or the config file (jaxp.properties by default)
readSystemProperties();
// prepare the JDK Catalog
prepareCatalog();
}
/**
* Flag indicating whether the JDK Catalog has been initialized
*/
static volatile boolean jdkcatalogInitialized = false;
private final Object lock = new Object();
private void prepareCatalog() {
if (!jdkcatalogInitialized) {
synchronized (lock) {
if (!jdkcatalogInitialized) {
jdkcatalogInitialized = true;
String resolve = getLimitValueAsString(Limit.JDKCATALOG_RESOLVE);
JdkCatalog.init(resolve);
}
}
}
}
/**
* Returns the JDKCatalogResolver with the current setting of the RESOLVE
* property.
*
* @return the JDKCatalogResolver
*/
public CatalogResolver getJDKCatalogResolver() {
String resolve = getLimitValueAsString(Limit.JDKCATALOG_RESOLVE);
return CatalogManager.catalogResolver(JdkCatalog.catalog, toActionType(resolve));
}
// convert the string value of the RESOLVE property to the corresponding
// action type
private NotFoundAction toActionType(String resolve) {
for (NotFoundAction type : NotFoundAction.values()) {
if (type.toString().equals(resolve)) {
return type;
}
}
return null;
}
/**

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* Copyright (c) 2023, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
-->
<!--
Catalog of DTDs for the Java platform
@implNote: DTDs in the built-in catalog are resolved against its URI and the
xml:base attribute. The preferences.dtd for example is resolved as:
jrt:/java.xml/jdk/xml/internal/jdkcatalog/java/dtd/preferences.dtd
-->
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<group id="javadtds" prefer = "system" xml:base = "java/dtd/">
<system systemId="http://java.sun.com/dtd/preferences.dtd" uri="preferences.dtd"/>
<system systemId="http://java.sun.com/dtd/properties.dtd" uri="properties.dtd"/>
</group>
</catalog>

View File

@ -0,0 +1,110 @@
<!--
Copyright 2001 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, CA 94303, U.S.A. All rights reserved.
This product or document is protected by copyright and distributed
under licenses restricting its use, copying, distribution, and
decompilation. No part of this product or documentation may be
reproduced in any form by any means without prior written authorization
of Sun and its licensors, if any.
Third party software, including font technology, is copyrighted and
licensed from Sun suppliers.
Sun, Sun Microsystems, the Sun Logo, Solaris, Java, JavaServer Pages, Java
Naming and Directory Interface, JDBC, JDK, JavaMail and Enterprise JavaBeans,
are trademarks or registered trademarks of Sun Microsystems, Inc in the U.S.
and other countries.
All SPARC trademarks are used under license and are trademarks
or registered trademarks of SPARC International, Inc.
in the U.S. and other countries. Products bearing SPARC
trademarks are based upon an architecture developed by Sun Microsystems, Inc.
PostScript is a registered trademark of Adobe Systems, Inc.
Federal Acquisitions: Commercial Software - Government Users Subject to
Standard License Terms and Conditions.
DOCUMENTATION IS PROVIDED "AS IS" AND ALL EXPRESS OR IMPLIED
CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT
TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY
INVALID.
_________________________________________________________________________
Copyright 2000-2001 Sun Microsystems, Inc.,
901 San Antonio Road, Palo Alto, CA 94303, Etats-Unis.
Tous droits re'serve's.
Ce produit ou document est prote'ge' par un copyright et distribue' avec
des licences qui en restreignent l'utilisation, la copie, la distribution,
et la de'compilation. Aucune partie de ce produit ou de sa documentation
associe'e ne peut e^tre reproduite sous aucune forme, par quelque moyen
que ce soit, sans l'autorisation pre'alable et e'crite de Sun et de ses
bailleurs de licence, s'il y en a.
Le logiciel de'tenu par des tiers, et qui comprend la technologie
relative aux polices de caracte`res, est prote'ge' par un copyright
et licencie' par des fournisseurs de Sun.
Sun, Sun Microsystems, le logo Sun, Solaris, Java, JavaServer Pages, Java
Naming and Directory Interface, JDBC, JDK, JavaMail, et Enterprise JavaBeans,
sont des marques de fabrique ou des marques de'pose'es de Sun
Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
Toutes les marques SPARC sont utilise'es sous licence et sont
des marques de fabrique ou des marques de'pose'es de SPARC
International, Inc. aux Etats-Unis et dans
d'autres pays. Les produits portant les marques SPARC sont
base's sur une architecture de'veloppe'e par Sun Microsystems, Inc.
Postcript est une marque enregistre'e d'Adobe Systems Inc.
LA DOCUMENTATION EST FOURNIE "EN L'ETAT" ET TOUTES AUTRES CONDITIONS,
DECLARATIONS ET GARANTIES EXPRESSES OU TACITES SONT FORMELLEMENT EXCLUES,
DANS LA MESURE AUTORISEE PAR LA LOI APPLICABLE, Y COMPRIS NOTAMMENT
TOUTE GARANTIE IMPLICITE RELATIVE A LA QUALITE MARCHANDE, A L'APTITUDE
A UNE UTILISATION PARTICULIERE OU A L'ABSENCE DE CONTREFACON.
-->
<!-- DTD for a Preferences tree. -->
<!-- The preferences element is at the root of an XML document
representing a Preferences tree. -->
<!ELEMENT preferences (root)>
<!-- The preferences element contains an optional version attribute,
which specifies version of DTD. -->
<!ATTLIST preferences EXTERNAL_XML_VERSION CDATA "0.0" >
<!-- The root element has a map representing the root's preferences
(if any), and one node for each child of the root (if any). -->
<!ELEMENT root (map, node*) >
<!-- Additionally, the root contains a type attribute, which
specifies whether it's the system or user root. -->
<!ATTLIST root
type (system|user) #REQUIRED >
<!-- Each node has a map representing its preferences (if any),
and one node for each child (if any). -->
<!ELEMENT node (map, node*) >
<!-- Additionally, each node has a name attribute -->
<!ATTLIST node
name CDATA #REQUIRED >
<!-- A map represents the preferences stored at a node (if any). -->
<!ELEMENT map (entry*) >
<!-- An entry represents a single preference, which is simply
a key-value pair. -->
<!ELEMENT entry EMPTY >
<!ATTLIST entry
key CDATA #REQUIRED
value CDATA #REQUIRED >

View File

@ -0,0 +1,15 @@
<!--
Copyright 2006 Sun Microsystems, Inc. All rights reserved.
-->
<!-- DTD for properties -->
<!ELEMENT properties ( comment?, entry* ) >
<!ATTLIST properties version CDATA #FIXED "1.0">
<!ELEMENT comment (#PCDATA) >
<!ELEMENT entry (#PCDATA) >
<!ATTLIST entry key CDATA #REQUIRED>

View File

@ -402,6 +402,11 @@
* @implNote
*
* <ul>
* <li><a href="#JDKCATALOG">JDK built-in Catalog</a>
* <ul>
* <li><a href="#JC_PROCESS">External Resource Resolution Process with the built-in Catalog</a></li>
* </ul>
* </li>
* <li><a href="#IN_ISFP">Implementation Specific Properties</a>
* <ul>
* <li><a href="#Processor">Processor Support</a></li>
@ -411,6 +416,33 @@
* </li>
* </ul>
*
* <h2 id="JDKCATALOG">JDK built-in Catalog</h2>
* The JDK has a built-in catalog that hosts the following DTDs defined by the Java Platform:
* <ul>
* <li>DTD for {@link java.util.prefs.Preferences java.util.prefs.Preferences}, preferences.dtd</li>
* <li>DTD for {@link java.util.Properties java.util.Properties}, properties.dtd</li>
* </ul>
* <p>
* The catalog is loaded once when the first JAXP processor factory is created.
*
* <h3 id="JC_PROCESS">External Resource Resolution Process with the built-in Catalog</h3>
* The JDK creates a {@link javax.xml.catalog.CatalogResolver CatalogResolver}
* with the built-in catalog when needed. This CatalogResolver is used as the
* default external resource resolver.
* <p>
* XML processors may use resolvers (such as {@link org.xml.sax.EntityResolver EntityResolver},
* {@link javax.xml.stream.XMLResolver XMLResolver}, and {@link javax.xml.catalog.CatalogResolver CatalogResolver})
* to handle external references. In the absence of the user-defined resolvers,
* the JDK XML processors fall back to the default CatalogResolver to attempt to
* find a resolution before making a connection to fetch the resources. The fall-back
* also takes place if a user-defined resolver exists but allows the process to
* continue when unable to resolve the resource.
* <p>
* If the default CatalogResolver is unable to locate a resource, it may signal
* the XML processors to continue processing, or skip the resource, or
* throw a CatalogException. The behavior is configured with the
* <a href="#JDKCATALOG_RESOLVE">{@code jdk.xml.jdkcatalog.resolve}</a> property.
*
* <h2 id="IN_ISFP">Implementation Specific Properties</h2>
* In addition to the standard <a href="#Conf_Properties">JAXP Properties</a>,
* the JDK implementation supports a number of implementation specific properties
@ -752,7 +784,7 @@
* <td id="ExtFunc">{@systemProperty jdk.xml.enableExtensionFunctions}</td>
* <td>Determines if XSLT and XPath extension functions are to be allowed.
* </td>
* <td style="text-align:center" rowspan="4">yes</td>
* <td style="text-align:center" rowspan="5">yes</td>
* <td style="text-align:center" rowspan="3">Boolean</td>
* <td>
* true or false. True indicates that extension functions are allowed; False otherwise.
@ -842,6 +874,40 @@
* <td style="text-align:center"><a href="#Processor">Method 1</a></td>
* <td style="text-align:center">22</td>
* </tr>
* <tr>
* <td id="JDKCATALOG_RESOLVE">{@systemProperty jdk.xml.jdkcatalog.resolve}</td>
* <td>Instructs the JDK default CatalogResolver to act in accordance with the setting
* of this property when unable to resolve an external reference with the built-in Catalog.
* The options are:
* <ul>
* <li><p>
* {@code continue} -- Indicates that the processing should continue
* </li>
* <li><p>
* {@code ignore} -- Indicates that the reference is skipped
* </li>
* <li><p>
* {@code strict} -- Indicates that the resolver should throw a CatalogException
* </li>
* </ul>
* </td>
* <td style="text-align:center">String</td>
* <td>
* {@code continue, ignore, and strict}. Values are case-insensitive.
* </td>
* <td style="text-align:center">continue</td>
* <td style="text-align:center">No</td>
* <td style="text-align:center">Yes</td>
* <td style="text-align:center">
* <a href="#DOM">DOM</a><br>
* <a href="#SAX">SAX</a><br>
* <a href="#StAX">StAX</a><br>
* <a href="#Validation">Validation</a><br>
* <a href="#Transform">Transform</a>
* </td>
* <td style="text-align:center"><a href="#Processor">Method 1</a></td>
* <td style="text-align:center">22</td>
* </tr>
* </tbody>
* </table>
* <p id="Note1">

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -45,6 +45,7 @@ import java.util.StringJoiner;
* This is a base class that every test class must extend if it needs to be run
* with security mode.
*/
@SuppressWarnings("removal")
public class JAXPPolicyManager {
/*
* Backing up policy.
@ -161,6 +162,7 @@ public class JAXPPolicyManager {
* Simple Policy class that supports the required Permissions to validate the
* JAXP concrete classes.
*/
@SuppressWarnings("removal")
class TestPolicy extends Policy {
private final static Set<String> TEST_JARS =
Set.of("jtreg.*jar", "javatest.*jar", "testng.*jar", "jcommander.*jar");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, 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
@ -371,7 +371,9 @@ public class CatalogSupportBase {
if (setUseCatalog) {
factory.setFeature(XMLConstants.USE_CATALOG, useCatalog);
}
if (catalog != null) {
factory.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog);
}
Schema schema = factory.newSchema(new StreamSource(new StringReader(xsd)));
success("XMLSchema.dtd and datatypes.dtd are resolved.");
@ -472,7 +474,9 @@ public class CatalogSupportBase {
}
SAXParser parser = spf.newSAXParser();
if (catalog != null) {
parser.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog);
}
return parser;
}
@ -495,7 +499,9 @@ public class CatalogSupportBase {
if (setUseCatalog) {
reader.setFeature(XMLConstants.USE_CATALOG, useCatalog);
}
if (catalog != null) {
reader.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog);
}
return reader;
}
@ -566,7 +572,9 @@ public class CatalogSupportBase {
if (setUseCatalog) {
xif.setProperty(XMLConstants.USE_CATALOG, useCatalog);
}
if (catalog != null) {
xif.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog);
}
ss = new StAXSource(xif.createXMLEventReader(
xmlFileId, new FileInputStream(xmlFile)));
} catch (Exception e) {}
@ -1013,6 +1021,7 @@ public class CatalogSupportBase {
* Simple policy implementation that grants a set of permissions to all code
* sources and protection domains.
*/
@SuppressWarnings("removal")
static class SimplePolicy extends Policy {
private final Permissions perms;

View File

@ -0,0 +1,361 @@
/*
* Copyright (c) 2023, 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package common.catalog;
import common.util.TestBase;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.stream.XMLInputFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.validation.SchemaFactory;
//import org.testng.annotations.DataProvider;
/**
* Tests the JDK Catalog
*/
public class CatalogTestBase extends TestBase {
/*
* DataProvider for testing configuring properties for parsers.
*
* Fields:
* file, FSP, state of setting, config file, system property, api property,
* Custom Catalog, error expected, error code or expected result
*/
//@DataProvider(name = "configWCatalogForParsers")
public Object[][] getConfigs(Processor processor) {
// file with an external DTD that's not in JdkCatalog
String fileDTDNotInC = "properties1.xml";
// file with an external DTD that's in the Custom Catalog
String fileDTDInCC = "test.xml";
// file with an external DTD that's in JdkCatalog
String javaDTD = "properties.xml";
// file with an external DTD thats in the Custom Catalog
String w3cDTD = "xhtml11.xml";
// error code when CATALOG=strict; The cause for DOM
String errCode = "JAXP09040001";
// error (not from catalog) is expect when CATALOG=continue
boolean isErrExpected = true;
String expected1 = "invalid.site.com";
// expected when reference is resolved by Catalog
String expected3 = "", expected4 = "";
switch (processor) {
case SAX:
errCode = "JAXP00090001";
break;
case STAX:
errCode = "JAXP00090001";
//errCode = "JAXP00090001";
// StAX is non-validating parser
isErrExpected = false;
expected1 = ".*[\\w\\s]*(value1)[\\w\\s]*.*";
expected3 = "Minimal XHTML 1.1 DocumentThis is a minimal XHTML 1.1 document.";
expected4 = ".*(123)[\\w\\s]*.*";
break;
default:
break;
}
return new Object[][]{
// Case 1: external reference not in the JDKCatalog
/**
* Case 1-1: default setting; no Config file; Catalog: continue (by default)
* Expect: error as the parser continues and tries to access an invalid site
* java.net.UnknownHostException: invalid.site.com
*/
{fileDTDNotInC, null, null, null, null, null, null, isErrExpected, expected1},
/**
* Case 1-2: set JDK Catalog to strict in a Config file
* Expect: Exception since the external reference is not in the Catalog
* Error Msg:
* [Fatal Error] properties1.xml:2:75: JAXP00090001: The CatalogResolver is enabled with the catalog "JdkCatalog.xml", but a CatalogException is returned.
* org.xml.sax.SAXException: javax.xml.catalog.CatalogException: JAXP09040001: No match found for publicId 'null' and systemId 'http://invalid.site.com/dtd/properties1.dtd'.
* javax.xml.catalog.CatalogException: JAXP09040001: No match found for publicId 'null' and systemId 'http://invalid.site.com/dtd/properties1.dtd'.
*/
{fileDTDNotInC, null, PropertyState.CONFIG_FILE, Properties.CONFIG_FILE_CATALOG_STRICT, null, null, null, true, errCode},
/**
* Case 1-3: set CATALOG back to continue through the System Property
* Expect: error as the parser continues and tries to access an invalid site
* java.net.UnknownHostException: invalid.site.com
*/
{fileDTDNotInC, null, PropertyState.CONFIG_FILE_SYSTEM, Properties.CONFIG_FILE_CATALOG_STRICT, new Properties[]{Properties.CATALOG0}, null, null, isErrExpected, expected1},
/**
* Case 1-4: override the settings in Case 3 with the API property, and set Catalog to strict
* Expect: Exception since the external reference is not in the Catalog
*/
{fileDTDNotInC, null, PropertyState.CONFIG_FILE_SYSTEM_API, Properties.CONFIG_FILE_CATALOG_STRICT, new Properties[]{Properties.CATALOG0}, new Properties[]{Properties.CATALOG2}, null, true, errCode},
// Case 2: external reference in the JDKCatalog
/**
* Case 2-1: set CATALOG to strict in a Config file
* Compare to: case 1-2
* Expect: pass without error
*/
{javaDTD, null, PropertyState.CONFIG_FILE, Properties.CONFIG_FILE_CATALOG_STRICT, null, null, null, false, expected1},
/**
* Case 2-2: override the settings in Case 3 with the API property, and set Catalog to strict
* Compare to: case 1-4
* Expect: pass without error
*/
{javaDTD, null, PropertyState.CONFIG_FILE_SYSTEM_API, Properties.CONFIG_FILE_CATALOG_STRICT, new Properties[]{Properties.CATALOG0}, new Properties[]{Properties.CATALOG2}, null, false, expected1},
// Case 3: external reference in the Custom Catalog
/**
* Case 3-1: set CATALOG to strict in a Config file
* Compare to: case 1-2, would have resulted in an error without the
* custom catalog
* Expect: pass without error because the external reference is in
* the custom catalog
*/
{fileDTDInCC, null, PropertyState.CONFIG_FILE, Properties.CONFIG_FILE_CATALOG_STRICT, null, null, CustomCatalog.STRICT, false, expected4},
/**
* Case 3-2: override the settings in Case 3 with the API property, and set Catalog to strict
* Compare to: case 1-4, would have resulted in an error without the
* custom catalog
* Expect: pass without error
*/
{fileDTDInCC, null, PropertyState.CONFIG_FILE_SYSTEM_API, Properties.CONFIG_FILE_CATALOG_STRICT, new Properties[]{Properties.CATALOG0}, new Properties[]{Properties.CATALOG2}, CustomCatalog.STRICT, false, expected4},
// Case 4: Parameter Entity reference
/**
* Case 4-1: set CATALOG to strict in a Config file
* Compare to: case 1-2, would have resulted in an error since the external
* reference can not be found
* Expect: pass without error because the external reference is in
* the custom catalog
*/
{"testExternalParameter.xml", null, PropertyState.CONFIG_FILE, Properties.CONFIG_FILE_CATALOG_STRICT, null, null, CustomCatalog.STRICT, false, expected1},
// Case 5: resolve xInclude with the Custom Catalog
/**
* Case 5-1: set CATALOG to strict in a Config file
* Compare to: case 1-2, would have resulted in an error without the
* custom catalog
* Expect: pass without error because the external reference is in
* the custom catalog
*/
{"XI_roottest.xml", null, PropertyState.CONFIG_FILE, Properties.CONFIG_FILE_CATALOG_STRICT, null, null, CustomCatalog.STRICT, false, ""},
};
}
/*
* DataProvider for testing configuring properties for validation or transform.
*
* Fields:
* xml file, xsd or xsl file, FSP, state of setting, config file, system property,
* api property, Custom Catalog, error expected, error code or expected result
*/
//@DataProvider(name = "validationOrTransform")
public Object[][] getConfig(String m) {
// Schema Import
String xmlFile = "XSDImport_company.xsd";
String xsdOrXsl = null;
String expected = "";
String errCode = "JAXP00090001";
switch (m) {
case "SchemaTest2":
// Schema Include
xmlFile = "XSDInclude_company.xsd";
break;
case "Validation":
// Schema Location
xmlFile = "val_test.xml";
break;
case "Stylesheet":
errCode = "JAXP09040001";
xmlFile = "XSLDTD.xsl";
break;
case "Transform":
xmlFile = "XSLPI.xml";
errCode = "JAXP09040001";
xsdOrXsl = "<?xml version='1.0'?>"
+ "<!DOCTYPE top SYSTEM 'test.dtd'"
+ "["
+ "<!ENTITY % pe \"x\">"
+ "<!ENTITY x1 \"AAAAA\">"
+ "<!ENTITY x2 \"bbb\">"
+"]>"
+ "<?xml-stylesheet href=\""
+ TEST_SOURCE_DIR
+ "/XSLPI_target.xsl\" type=\"text/xml\"?>"
+ "<xsl:stylesheet "
+ " xmlns:xsl='http://www.w3.org/1999/XSL/Transform' "
+ " version='1.0'>"
+ "</xsl:stylesheet> ";
break;
default:
break;
}
return new Object[][]{
// Case 1: external reference not in the JDKCatalog
/**
* Case 1-1: default setting; no Config file; Catalog: continue
* Expect: pass without error
*/
{xmlFile, xsdOrXsl, null, null, null, null, null, null, false, expected},
/**
* Case 1-2: set CATALOG to strict in a Config file
* Expect: Exception since the external reference is not in the Catalog
* Sample Error Msg:
* org.xml.sax.SAXParseException; systemId: file:path/XSDImport_company.xsd;
* lineNumber: 10; columnNumber: 11;
* JAXP00090001: The CatalogResolver is enabled with the catalog "JdkCatalog.xml",
* but a CatalogException is returned.
*/
{xmlFile, xsdOrXsl, null, PropertyState.CONFIG_FILE, Properties.CONFIG_FILE_CATALOG_STRICT, null, null, null, true, errCode},
/**
* Case 1-3: set CATALOG back to continue through the System Property
* Expect: pass without error
*/
{xmlFile, xsdOrXsl, null, PropertyState.CONFIG_FILE_SYSTEM, Properties.CONFIG_FILE_CATALOG_STRICT, new Properties[]{Properties.CATALOG0}, null, null, false, expected},
/**
* Case 1-4: override the settings in Case 3 with the API property, and set Catalog to strict
* Expect: Exception since the external reference is not in the Catalog
*/
{xmlFile, xsdOrXsl, null, PropertyState.CONFIG_FILE_SYSTEM_API, Properties.CONFIG_FILE_CATALOG_STRICT, new Properties[]{Properties.CATALOG0}, new Properties[]{Properties.CATALOG2}, null, true, errCode},
/**
* Case 1-5: use Custom Catalog to resolve external references
* Expect: pass without error
*/
{xmlFile, xsdOrXsl, null, PropertyState.CONFIG_FILE_SYSTEM_API, Properties.CONFIG_FILE_CATALOG_STRICT, new Properties[]{Properties.CATALOG0}, new Properties[]{Properties.CATALOG2}, CustomCatalog.STRICT, false, expected},
};
}
// @Test(dataProvider = "configWCatalogForParsers", priority=0)
public void testDOM(String filename, Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc,
boolean expectError, String error) throws Exception {
DocumentBuilderFactory dbf = getDBF(fsp, state, config, sysProp, apiProp, cc);
process(filename, dbf, expectError, error);
}
// @Test(dataProvider = "configWCatalogForParsers")
public void testSAX(String filename, Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc,
boolean expectError, String error) throws Exception {
SAXParser parser = getSAXParser(fsp, state, config, sysProp, apiProp, cc);
process(filename, parser, expectError, error);
}
// @Test(dataProvider = "configWCatalogForParsers")
public void testStAX(String filename, Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc,
boolean expectError, String error) throws Exception {
XMLInputFactory xif = getXMLInputFactory(state, config, sysProp, apiProp, cc);
process(filename, xif, expectError, error);
}
// @Test(dataProvider = "validationOrTransform")
public void testSchema1(String filename, String xsd, Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc,
boolean expectError, String error) throws Exception {
SchemaFactory sf = getSchemaFactory(fsp, state, config, sysProp, apiProp, cc);
process(filename, sf, expectError, error);
}
// @Test(dataProvider = "validationOrTransform")
public void testSchema2(String filename, String xsd, Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc,
boolean expectError, String error) throws Exception {
testSchema1(filename, xsd, fsp, state, config, sysProp, apiProp, cc, expectError, error);
}
// @Test(dataProvider = "validationOrTransform")
public void testValidation(String filename, String xsd, Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc,
boolean expectError, String error) throws Exception {
SchemaFactory sf = getSchemaFactory(fsp, state, config, sysProp, apiProp, cc);
validate(filename, sf, expectError, error);
}
// @Test(dataProvider = "validationOrTransform")
public void testStylesheet(String filename, String xsl, Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc,
boolean expectError, String error) throws Exception {
TransformerFactory tf = getTransformerFactory(fsp, state, config, sysProp, apiProp, cc);
process(filename, tf, expectError, error);
}
// @Test(dataProvider = "validationOrTransform")
public void testTransform(String filename, String xsl, Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc,
boolean expectError, String error) throws Exception {
TransformerFactory tf = getTransformerFactory(fsp, state, config, sysProp, apiProp, cc);
transform(filename, xsl, tf, expectError, error);
}
// parameters in the same order as the test method
String filename; String xsd; String xsl; Properties fsp; PropertyState state;
Properties config; Properties[] sysProp; Properties[] apiProp; CustomCatalog cc;
boolean expectError; String error;
// Maps the DataProvider array to individual parameters
public void paramMap(Processor processor, String method, String index) {
int i = 0;
Object[][] params;
if (processor == Processor.VALIDATOR ||
processor == Processor.TRANSFORMER) {
params = getConfig(method);
i = 1;
} else {
params = getConfigs(processor);
}
Object[] param = params[Integer.parseInt(index)];
filename = (String)param[0];
if (processor == Processor.VALIDATOR) {
xsd = (String)param[i];
} else if (processor == Processor.TRANSFORMER) {
xsl = (String)param[i];
}
fsp = (Properties)param[i + 1];
state = (PropertyState)param[i + 2];
config = (Properties)param[i + 3];
sysProp = (Properties[])param[i + 4];
apiProp = (Properties[])param[i + 5];
cc = (CustomCatalog)param[i + 6];
expectError = (boolean)param[i + 7];
error = (String)param[i + 8];
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2023, 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package common.catalog;
/**
* @test @bug 8306055
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @modules java.xml/jdk.xml.internal
* @run driver common.catalog.DOMTest 0 // verifies default setting catalog.resolve=allow
* @run driver common.catalog.DOMTest 1 // verifies overriding with catalog.resolve=strict in a config file
* @run driver common.catalog.DOMTest 2 // verifies overriding with system property
* @run driver common.catalog.DOMTest 3 // verifies overriding with factory setting (catalog.resolve=strict)
* @run driver common.catalog.DOMTest 4 // verifies external DTD resolution with the JDK Catalog while resolve=strict in config file
* @run driver common.catalog.DOMTest 5 // verifies external DTD resolution with the JDK Catalog while resolve=strict in API setting
* @run driver common.catalog.DOMTest 6 // verifies external DTD resolution with a custom Catalog while resolve=strict in config file
* @run driver common.catalog.DOMTest 7 // verifies external DTD resolution with a custom Catalog while resolve=strict in API setting
* @run driver common.catalog.DOMTest 8 // verifies external parameter are resolved with a custom Catalog though resolve=strict in API setting
* @run driver common.catalog.DOMTest 9 // verifies XInclude are resolved with a custom Catalog though resolve=strict in API setting
* @summary verifies DOM's support of the JDK Catalog.
*/
public class DOMTest extends CatalogTestBase {
public static void main(String args[]) throws Exception {
new DOMTest().run(args[0]);
}
public void run(String index) throws Exception {
paramMap(Processor.DOM, null, index);
super.testDOM(filename, fsp, state, config, sysProp, apiProp, cc, expectError, error);
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2023, 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package common.catalog;
/**
* @test @bug 8306055
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @modules java.xml/jdk.xml.internal
* @run driver common.catalog.SAXTest 0 // verifies default setting catalog.resolve=allow
* @run driver common.catalog.SAXTest 1 // verifies overriding with catalog.resolve=strict in a config file
* @run driver common.catalog.SAXTest 2 // verifies overriding with system property
* @run driver common.catalog.SAXTest 3 // verifies overriding with factory setting (catalog.resolve=strict)
* @run driver common.catalog.SAXTest 4 // verifies external DTD resolution with the JDK Catalog while resolve=strict in config file
* @run driver common.catalog.SAXTest 5 // verifies external DTD resolution with the JDK Catalog while resolve=strict in API setting
* @run driver common.catalog.SAXTest 6 // verifies external DTD resolution with a custom Catalog while resolve=strict in config file
* @run driver common.catalog.SAXTest 7 // verifies external DTD resolution with a custom Catalog while resolve=strict in API setting
* @run driver common.catalog.SAXTest 8 // verifies external parameter are resolved with a custom Catalog though resolve=strict in API setting
* @run driver common.catalog.SAXTest 9 // verifies XInclude are resolved with a custom Catalog though resolve=strict in API setting
* @summary verifies DOM's support of the JDK Catalog.
*/
public class SAXTest extends CatalogTestBase {
public static void main(String args[]) throws Exception {
new SAXTest().run(args[0]);
}
public void run(String index) throws Exception {
paramMap(Processor.SAX, null, index);
super.testSAX(filename, fsp, state, config, sysProp, apiProp, cc, expectError, error);
}
}

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2023, 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package common.catalog;
/**
* @test @bug 8306632
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @modules java.xml/jdk.xml.internal
* @run driver common.catalog.SchemaTest SchemaTest1 0 // verifies default setting dtd.support=allow
* @run driver common.catalog.SchemaTest SchemaTest1 1 // verifies overriding with config file
* @run driver common.catalog.SchemaTest SchemaTest1 2 // verifies overriding with system property
* @run driver common.catalog.SchemaTest SchemaTest1 3 // verifies overriding with factory setting (DTD=deny)
* @run driver common.catalog.SchemaTest SchemaTest1 4 // verifies DTD=ignore
* @run driver common.catalog.SchemaTest SchemaTest2 0 // verifies default setting dtd.support=allow
* @run driver common.catalog.SchemaTest SchemaTest2 1 // verifies overriding with config file
* @run driver common.catalog.SchemaTest SchemaTest2 2 // verifies overriding with system property
* @run driver common.catalog.SchemaTest SchemaTest2 3 // verifies overriding with factory setting (DTD=deny)
* @run driver common.catalog.SchemaTest SchemaTest2 4 // verifies DTD=ignore
* @run driver common.catalog.SchemaTest Validation 0 // verifies default setting dtd.support=allow
* @run driver common.catalog.SchemaTest Validation 1 // verifies overriding with config file
* @run driver common.catalog.SchemaTest Validation 2 // verifies overriding with system property
* @run driver common.catalog.SchemaTest Validation 3 // verifies overriding with factory setting (DTD=deny)
* @run driver common.catalog.SchemaTest Validation 4 // verifies DTD=ignore
* @summary verifies Schema and Validation's support of the property jdk.xml.dtd.support.
*/
public class SchemaTest extends CatalogTestBase {
public static void main(String args[]) throws Exception {
new SchemaTest().run(args[0], args[1]);
}
public void run(String method, String index) throws Exception {
paramMap(Processor.VALIDATOR, method, index);
switch (method) {
case "SchemaTest1":
super.testSchema1(filename, xsd, fsp, state, config, sysProp, apiProp, cc, expectError, error);
break;
case "SchemaTest2":
super.testSchema2(filename, xsd, fsp, state, config, sysProp, apiProp, cc, expectError, error);
break;
case "Validation":
super.testValidation(filename, xsd, fsp, state, config, sysProp, apiProp, cc, expectError, error);
break;
}
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2023, 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package common.catalog;
/**
* @test @bug 8306055
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @modules java.xml/jdk.xml.internal
* @run driver common.catalog.StAXTest 0 // verifies default setting catalog.resolve=allow
* @run driver common.catalog.StAXTest 1 // verifies overriding with catalog.resolve=strict in a config file
* @run driver common.catalog.StAXTest 2 // verifies overriding with system property
* @run driver common.catalog.StAXTest 3 // verifies overriding with factory setting (catalog.resolve=strict)
* @run driver common.catalog.StAXTest 4 // verifies external DTD resolution with the JDK Catalog while resolve=strict in config file
* @run driver common.catalog.StAXTest 5 // verifies external DTD resolution with the JDK Catalog while resolve=strict in API setting
* @run driver common.catalog.StAXTest 6 // verifies external DTD resolution with a custom Catalog while resolve=strict in config file
* @run driver common.catalog.StAXTest 7 // verifies external DTD resolution with a custom Catalog while resolve=strict in API setting
* @run driver common.catalog.StAXTest 8 // verifies external parameter are resolved with a custom Catalog though resolve=strict in API setting
* @run driver common.catalog.StAXTest 9 // verifies XInclude are resolved with a custom Catalog though resolve=strict in API setting
* @summary verifies DOM's support of the JDK Catalog.
*/
public class StAXTest extends CatalogTestBase {
public static void main(String args[]) throws Exception {
new StAXTest().run(args[0]);
}
public void run(String index) throws Exception {
paramMap(Processor.STAX, null, index);
super.testStAX(filename, fsp, state, config, sysProp, apiProp, cc, expectError, error);
}
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2023, 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.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package common.catalog;
/**
* @test @bug 8306632
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @modules java.xml/jdk.xml.internal
* @run driver common.catalog.TransformTest Stylesheet 0 // verifies default setting dtd.support=allow
* @run driver common.catalog.TransformTest Stylesheet 1 // verifies overriding with config file
* @run driver common.catalog.TransformTest Stylesheet 2 // verifies overriding with system property
* @run driver common.catalog.TransformTest Stylesheet 3 // verifies overriding with factory setting (DTD=deny)
* @run driver common.catalog.TransformTest Stylesheet 4 // verifies DTD=ignore
* @run driver common.catalog.TransformTest Transform 0 // verifies default setting dtd.support=allow
* @run driver common.catalog.TransformTest Transform 1 // verifies overriding with config file
* @run driver common.catalog.TransformTest Transform 2 // verifies overriding with system property
* @run driver common.catalog.TransformTest Transform 3 // verifies overriding with factory setting (DTD=deny)
* @run driver common.catalog.TransformTest Transform 4 // verifies DTD=ignore
* @summary verifies Transform's support of the property jdk.xml.dtd.support.
*/
public class TransformTest extends CatalogTestBase {
public static void main(String args[]) throws Exception {
new TransformTest().run(args[0], args[1]);
}
public void run(String method, String index) throws Exception {
paramMap(Processor.TRANSFORMER, method, index);
switch (method) {
case "Stylesheet":
super.testStylesheet(filename, xsl, fsp, state, config, sysProp, apiProp, cc, expectError, error);
break;
case "Transform":
super.testTransform(filename, xsl, fsp, state, config, sysProp, apiProp, cc, expectError, error);
break;
}
}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<!-- Catalog for testing the CATALOG property
-->
<group id="dtds" prefer = "system" xml:base = "dtds/">
<systemSuffix systemIdSuffix="test.dtd" uri="test.dtd"/>
<system systemId="file:/externalParameterEntity" uri="paramEntity.dtd"/>
<system systemId="XSLDTD.dtd" uri="XSLDTD.dtd"/>
</group>
<group id="xsds" prefer = "system" xml:base = "xsds/">
<system systemId="XSDImport_person.xsd" uri="XSDImport_person.xsd"/>
<system systemId="XSDImport_product.xsd" uri="XSDImport_product.xsd"/>
<system systemId="XSDInclude_person.xsd" uri="XSDInclude_person.xsd"/>
<system systemId="XSDInclude_product.xsd" uri="XSDInclude_product.xsd"/>
<!-- file:/path/val_test.xsd -->
<systemSuffix systemIdSuffix="val_test.xsd" uri="val_test.xsd"/>
</group>
<group id="xi" prefer = "system" xml:base = "xinclude/">
<system systemId="XI_red.dtd" uri="XI_red.dtd"/>
<system systemId="XI_simple.xml" uri="XI_simple.xml"/>
<system systemId="XI_test2.xml" uri="XI_test2.xml"/>
<system systemId="XI_utf8.xml" uri="XI_utf8.xml"/>
</group>
<!-- additional catalogs can be added a NextCatalog besides registering
through the Feature.FILES (javax.xml.catalog.files) property -->
<!-- nextCatalog catalog="pathto/AnotherCatalog.xml"/-->
</catalog>

View File

@ -0,0 +1,108 @@
<?xml version="1.1" encoding="UTF-8"?>
<!-- Portions (C) International Organization for Standardization 1986
Permission to copy in any form is granted for use with
conforming SGML systems and applications as defined in
ISO 8879, provided this notice is included in all copies.
-->
<!-- Character entity set. Typical invocation:
<!ENTITY % HTMLlat1 PUBLIC
"-//W3C//ENTITIES Latin 1//EN//HTML">
%HTMLlat1;
-->
<!ENTITY nbsp "&#160;" >
<!ENTITY iexcl "&#161;" >
<!ENTITY cent "&#162;" >
<!ENTITY pound "&#163;" >
<!ENTITY curren "&#164;" >
<!ENTITY yen "&#165;" >
<!ENTITY brvbar "&#166;" >
<!ENTITY sect "&#167;" >
<!ENTITY uml "&#168;" >
<!ENTITY copy "&#169;" >
<!ENTITY ordf "&#170;" >
<!ENTITY laquo "&#171;" >
<!ENTITY not "&#172;" >
<!ENTITY shy "&#173;" >
<!ENTITY reg "&#174;" >
<!ENTITY macr "&#175;" >
<!ENTITY deg "&#176;" >
<!ENTITY plusmn "&#177;" >
<!ENTITY sup2 "&#178;" >
<!ENTITY sup3 "&#179;" >
<!ENTITY acute "&#180;" >
<!ENTITY micro "&#181;" >
<!ENTITY para "&#182;" >
<!ENTITY middot "&#183;" >
<!ENTITY cedil "&#184;" >
<!ENTITY sup1 "&#185;" >
<!ENTITY ordm "&#186;" >
<!ENTITY raquo "&#187;" >
<!ENTITY frac14 "&#188;" >
<!ENTITY frac12 "&#189;" >
<!ENTITY frac34 "&#190;" >
<!ENTITY iquest "&#191;" >
<!ENTITY Agrave "&#192;" >
<!ENTITY Aacute "&#193;" >
<!ENTITY Acirc "&#194;" >
<!ENTITY Atilde "&#195;" >
<!ENTITY Auml "&#196;" >
<!ENTITY Aring "&#197;" >
<!ENTITY AElig "&#198;" >
<!ENTITY Ccedil "&#199;" >
<!ENTITY Egrave "&#200;" >
<!ENTITY Eacute "&#201;" >
<!ENTITY Ecirc "&#202;" >
<!ENTITY Euml "&#203;" >
<!ENTITY Igrave "&#204;" >
<!ENTITY Iacute "&#205;" >
<!ENTITY Icirc "&#206;" >
<!ENTITY Iuml "&#207;" >
<!ENTITY ETH "&#208;" >
<!ENTITY Ntilde "&#209;" >
<!ENTITY Ograve "&#210;" >
<!ENTITY Oacute "&#211;" >
<!ENTITY Ocirc "&#212;" >
<!ENTITY Otilde "&#213;" >
<!ENTITY Ouml "&#214;" >
<!ENTITY times "&#215;" >
<!ENTITY Oslash "&#216;" >
<!ENTITY Ugrave "&#217;" >
<!ENTITY Uacute "&#218;" >
<!ENTITY Ucirc "&#219;" >
<!ENTITY Uuml "&#220;" >
<!ENTITY Yacute "&#221;" >
<!ENTITY THORN "&#222;" >
<!ENTITY szlig "&#223;" >
<!ENTITY agrave "&#224;" >
<!ENTITY aacute "&#225;" >
<!ENTITY acirc "&#226;" >
<!ENTITY atilde "&#227;" >
<!ENTITY auml "&#228;" >
<!ENTITY aring "&#229;" >
<!ENTITY aelig "&#230;" >
<!ENTITY ccedil "&#231;" >
<!ENTITY egrave "&#232;" >
<!ENTITY eacute "&#233;" >
<!ENTITY ecirc "&#234;" >
<!ENTITY euml "&#235;" >
<!ENTITY igrave "&#236;" >
<!ENTITY iacute "&#237;" >
<!ENTITY icirc "&#238;" >
<!ENTITY iuml "&#239;" >
<!ENTITY eth "&#240;" >
<!ENTITY ntilde "&#241;" >
<!ENTITY ograve "&#242;" >
<!ENTITY oacute "&#243;" >
<!ENTITY ocirc "&#244;" >
<!ENTITY otilde "&#245;" >
<!ENTITY ouml "&#246;" >
<!ENTITY divide "&#247;" >
<!ENTITY oslash "&#248;" >
<!ENTITY ugrave "&#249;" >
<!ENTITY uacute "&#250;" >
<!ENTITY ucirc "&#251;" >
<!ENTITY uuml "&#252;" >
<!ENTITY yacute "&#253;" >
<!ENTITY thorn "&#254;" >
<!ENTITY yuml "&#255;" >

View File

@ -0,0 +1,2 @@
<!ENTITY quantity "2">
<!ENTITY unitPrice "24.99">

View File

@ -0,0 +1,6 @@
<!ENTITY % bltin "&#42;">
<!ENTITY % pe "x">
<!ELEMENT top (#PCDATA)>

View File

@ -0,0 +1,4 @@
<!--
Comment in DTD
-->

View File

@ -0,0 +1,18 @@
<simple>
<test xmlns:xinclude="http://www.w3.org/2001/XInclude">
<latin1>
<firstElement/>
<xinclude:include href="XI_utf8.xml" parse="text"/>
<insideChildren/>
<another>
<deeper>text</deeper>
</another>
</latin1>
<test2>
<xinclude:include href="XI_test2.xml"/>
</test2>
<test3>
<!-- <xinclude:include href="XI_roottest.xml"/> -->
</test3>
</test>
</simple>

View File

@ -0,0 +1,10 @@
<?xml version="1.1"?>
<!-- comment before root -->
<!DOCTYPE red SYSTEM "XI_red.dtd">
<red xmlns:xinclude="http://www.w3.org/2001/XInclude">
<blue>
<xinclude:include href="XI_utf8.xml" parse="text"/>
</blue>
</red>
<!-- comment after root -->

View File

@ -0,0 +1,4 @@
<red>
value1 trjsagdkasgdhasdgashgdhsadgashdg
</red>

View File

@ -0,0 +1,12 @@
<?xml version="1.1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.person.org"
xmlns="http://www.person.org"
elementFormDefault="unqualified">
<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="SSN" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

View File

@ -0,0 +1,11 @@
<?xml version="1.1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.product.org"
xmlns="http://www.product.org"
elementFormDefault="unqualified">
<xsd:complexType name="ProductType">
<xsd:sequence>
<xsd:element name="Type" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

View File

@ -0,0 +1,12 @@
<?xml version="1.1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
xmlns="http://www.person.org"
elementFormDefault="qualified">
<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="SSN" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

View File

@ -0,0 +1,11 @@
<?xml version="1.1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
xmlns="http://www.product.org"
elementFormDefault="qualified">
<xsd:complexType name="ProductType">
<xsd:sequence>
<xsd:element name="Type" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

View File

@ -0,0 +1,16 @@
<?xml version="1.1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="test">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:anyType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:key name="key1">
<xsd:selector xpath="."/>
<xsd:field xpath="child"/>
</xsd:key>
</xsd:element>
</xsd:schema>

View File

@ -0,0 +1,36 @@
################################################################################
# XML Library (java.xml) Configuration File
#
# This file is in java.util.Properties format and typically located in the conf
# directory of the Java installation. It may contain key/value pairs for specifying
# the implementation class of a factory and/or properties that have corresponding
# system properties.
#
# This file can be replaced by specifying a filename with the java.xml.config.file
# system property. For example java -Djava.xml.config.file=myfile
################################################################################
# ---- Config File: for testing the CATALOG property ----
#
# strict: report error if not resolved by the JDK Catalog
jdk.xml.jdkCatalog.resolve=strict
# Enable Extension Functions
jdk.xml.enableExtensionFunctions=true
# Disallow overriding the default parser
jdk.xml.overrideDefaultParser=false
#
# Implementation specific limits:
#
jdk.xml.entityExpansionLimit=64000
jdk.xml.elementAttributeLimit=10000
jdk.xml.maxOccurLimit=5000
jdk.xml.totalEntitySizeLimit=100000
jdk.xml.maxGeneralEntitySizeLimit=0
jdk.xml.maxParameterEntitySizeLimit=1000000
jdk.xml.entityReplacementLimit=300000
jdk.xml.maxElementDepth=0
jdk.xml.maxXMLNameLimit=1000
jdk.xml.xpathExprGrpLimit=10
jdk.xml.xpathExprOpLimit=100
jdk.xml.xpathTotalOpLimit=10000

View File

@ -128,6 +128,11 @@ jdk.xml.overrideDefaultParser=false
#
# javax.xml.useCatalog=true
#
# Implementation Specific Properties - DTD
#
# This property instructs the parsers to: deny, ignore or allow DTD processing.
# The following setting would cause the parser to reject DTD by throwing an exception.
# jdk.xml.dtd.support=deny
#
# Implementation Specific Properties - Limits
#

View File

@ -17,15 +17,6 @@ import common.util.TestBase;
* The DTD property controls how DTDs are processed.
*/
public class DTDTestBase extends TestBase {
static final String SRC_DIR;
static {
String srcDir = System.getProperty("test.src", ".");
if (IS_WINDOWS) {
srcDir = srcDir.replace('\\', '/');
}
SRC_DIR = srcDir;
TEST_SOURCE_DIR = srcDir + "/../xmlfiles/";
}
public void testDOM(String filename, Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp,

View File

@ -67,13 +67,31 @@ public class TestBase {
ORACLE_JAXP_PROPERTY_PREFIX + "getEntityCountInfo";
public static final String CATALOG_FILE = CatalogFeatures.Feature.FILES.getPropertyName();
public static final boolean IS_WINDOWS = System.getProperty("os.name").contains("Windows");
public static String SRC_DIR = System.getProperty("test.src", ".");
public static String TEST_SOURCE_DIR;
public static String SRC_DIR;
public static String TEST_SOURCE_DIR, CONFIG_FILE_PATH, CATALOG_PATH;
static {
String srcDir = System.getProperty("test.src", ".");
if (IS_WINDOWS) {
srcDir = srcDir.replace('\\', '/');
}
SRC_DIR = srcDir;
if (IS_WINDOWS) {
CATALOG_PATH = "file:///" + SRC_DIR + "/../catalog/testcatalog/TestCatalog.xml";
} else {
CATALOG_PATH = "file://" + SRC_DIR + "/../catalog/testcatalog/TestCatalog.xml";
}
TEST_SOURCE_DIR = srcDir + "/../xmlfiles/";
CONFIG_FILE_PATH = SRC_DIR + "/../config/files/";
}
// configuration file system property
private static final String CONFIG_FILE = "java.xml.config.file";
// CATALOG Abbreviation: C
static final String C_FILE = CatalogFeatures.Feature.FILES.getPropertyName();
static final String C_RESOLVE = CatalogFeatures.Feature.RESOLVE.getPropertyName();
// Xerces Property
public static final String DISALLOW_DTD = "http://apache.org/xml/features/disallow-doctype-decl";
public static final String LOAD_EXTERNAL_DTD = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
@ -84,6 +102,7 @@ public class TestBase {
// Impl Specific Properties
public static final String SP_DTD = "jdk.xml.dtd.support";
public static final String SP_CATALOG = "jdk.xml.jdkCatalog.resolve";
public static final String OVERRIDE_PARSER = "jdk.xml.overrideDefaultParser";
// DTD/CATALOG constants
@ -97,7 +116,10 @@ public class TestBase {
// JAXP Configuration File(JCF) location
// DTD = deny
public static final String JCF_DTD2 = "../config/files/dtd2.properties";
public static final String JCF_DTD2 = "dtd2.properties";
// CATALOG=strict
public static final String CONFIG_CATALOG_STRICT = "catalog2.properties";
String xmlExternalEntity, xmlExternalEntityId;
@ -107,7 +129,9 @@ public class TestBase {
static enum SourceType { STREAM, SAX, STAX, DOM };
public static enum Properties {
CONFIG_FILE_DTD2(null, CONFIG_FILE, Type.FEATURE, getPath(JCF_DTD2)),
// config file: CATALOG = strict
CONFIG_FILE_CATALOG_STRICT(null, CONFIG_FILE, Type.FEATURE, getPath(CONFIG_FILE_PATH, CONFIG_CATALOG_STRICT)),
CONFIG_FILE_DTD2(null, CONFIG_FILE, Type.FEATURE, getPath(CONFIG_FILE_PATH, JCF_DTD2)),
FSP(XMLConstants.FEATURE_SECURE_PROCESSING, null, Type.FEATURE, "true"),
FSP_FALSE(XMLConstants.FEATURE_SECURE_PROCESSING, null, Type.FEATURE, "false"),
@ -115,6 +139,9 @@ public class TestBase {
DTD0(SP_DTD, "ditto", Type.PROPERTY, DTD_ALLOW),
DTD1(SP_DTD, "ditto", Type.PROPERTY, DTD_IGNORE),
DTD2(SP_DTD, "ditto", Type.PROPERTY, DTD_DENY),
CATALOG0(SP_CATALOG, "ditto", Type.PROPERTY, RESOLVE_CONTINUE),
CATALOG1(SP_CATALOG, "ditto", Type.PROPERTY, RESOLVE_IGNORE),
CATALOG2(SP_CATALOG, "ditto", Type.PROPERTY, RESOLVE_STRICT),
// StAX properties
SUPPORT_DTD(XMLInputFactory.SUPPORT_DTD, null, Type.FEATURE, "true"),
@ -181,11 +208,34 @@ public class TestBase {
CONFIG_FILE_SYSTEM_API,
}
public static enum CustomCatalog {
// continue processing if no match found
CONTINUE(CATALOG_PATH, "continue"),
// skip if no match found
IGNORE(CATALOG_PATH, "ignore"),
// throws CatalogException if no match found
STRICT(CATALOG_PATH, "strict");
String file, resolve;
CustomCatalog(String file, String resolve) {
this.file = file;
this.resolve = resolve;
}
public String file() {
return file;
}
public String resolve() {
return resolve;
}
}
protected void process(String filename, DocumentBuilderFactory dbf, boolean expectError,
String error) throws Exception {
//dbf.setAttribute(CatalogFeatures.Feature.RESOLVE.getPropertyName(), "continue");
DocumentBuilder builder = dbf.newDocumentBuilder();
File file = new File(getPath(filename));
File file = new File(getPath(TEST_SOURCE_DIR, filename));
try {
Document document = builder.parse(file);
Assert.assertTrue(!expectError);
@ -198,7 +248,7 @@ public class TestBase {
protected void process(String filename, SAXParser parser, boolean expectError,
String error) throws Exception {
File file = new File(getPath(filename));
File file = new File(getPath(TEST_SOURCE_DIR, filename));
try {
parser.parse(file, new DefaultHandler());
Assert.assertTrue(!expectError);
@ -211,7 +261,7 @@ public class TestBase {
protected void process(String filename, XMLInputFactory xif, boolean expectError,
String expected) throws Exception {
String xml = getPath(filename);
String xml = getPath(TEST_SOURCE_DIR, filename);
try {
InputStream entityxml = new FileInputStream(xml);
XMLStreamReader streamReader = xif.createXMLStreamReader(xml, entityxml);
@ -228,7 +278,7 @@ public class TestBase {
protected void process(String filename, SchemaFactory sf, boolean expectError,
String expected) throws Exception {
String xsd = getPath(filename);
String xsd = getPath(TEST_SOURCE_DIR, filename);
try {
Schema schema = sf.newSchema(new StreamSource(new File(xsd)));
Assert.assertTrue(!expectError);
@ -240,7 +290,7 @@ public class TestBase {
protected void process(String filename, TransformerFactory tf, boolean expectError,
String expected) throws Exception {
String xsl = getPath(filename);
String xsl = getPath(TEST_SOURCE_DIR, filename);
try {
SAXSource xslSource = new SAXSource(new InputSource(xsl));
xslSource.setSystemId(xsl);
@ -254,7 +304,7 @@ public class TestBase {
protected void transform(String xmlFile, String xsl, TransformerFactory tf,
boolean expectError, String expected) throws Exception {
String xmlSysId = getPath(xmlFile);
String xmlSysId = getPath(TEST_SOURCE_DIR, xmlFile);
try {
SAXSource xslSource = new SAXSource(new InputSource(new StringReader(xsl)));
//SAXSource xslSource = new SAXSource(new InputSource(xslSysId));
@ -264,14 +314,13 @@ public class TestBase {
transformer.transform(getSource(SourceType.STREAM, xmlSysId), new StreamResult(sw));
Assert.assertTrue(!expectError);
} catch (Exception e) {
e.printStackTrace();
processError(expectError, expected, e);
}
}
protected void validate(String filename, SchemaFactory sf, boolean expectError,
String expected) throws Exception {
String xml = getPath(filename);
String xml = getPath(TEST_SOURCE_DIR, filename);
try {
Schema schema = sf.newSchema();
Validator validator = schema.newValidator();
@ -309,6 +358,11 @@ public class TestBase {
*/
protected DocumentBuilderFactory getDBF(Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp) {
return getDBF(fsp, state, config, sysProp, apiProp, null);
}
protected DocumentBuilderFactory getDBF(Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc) {
setSystemProperty(config, state, sysProp);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultNSInstance();
@ -335,6 +389,10 @@ public class TestBase {
}
}
}
if (cc != null) {
dbf.setAttribute(C_FILE, cc.file());
dbf.setAttribute(C_RESOLVE, cc.resolve());
}
clearSystemProperty(state, sysProp);
@ -355,6 +413,11 @@ public class TestBase {
*/
public SAXParser getSAXParser(Properties fsp, PropertyState state, Properties config,
Properties[] sysProp, Properties[] apiProp) throws Exception {
return getSAXParser(fsp, state, config, sysProp, apiProp, null);
}
public SAXParser getSAXParser(Properties fsp, PropertyState state, Properties config,
Properties[] sysProp, Properties[] apiProp, CustomCatalog cc) throws Exception {
setSystemProperty(config, state, sysProp);
SAXParserFactory spf = SAXParserFactory.newDefaultNSInstance();
@ -387,12 +450,22 @@ public class TestBase {
}
}
if (cc != null) {
parser.setProperty(C_FILE, cc.file());
parser.setProperty(C_RESOLVE, cc.resolve());
}
clearSystemProperty(state, sysProp);
return parser;
}
protected XMLInputFactory getXMLInputFactory(PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp) {
return getXMLInputFactory(state, config, sysProp, apiProp, null);
}
protected XMLInputFactory getXMLInputFactory(PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc) {
setSystemProperty(config, state, sysProp);
XMLInputFactory factory = XMLInputFactory.newInstance();
@ -402,6 +475,11 @@ public class TestBase {
}
}
if (cc != null) {
factory.setProperty(C_FILE, cc.file());
factory.setProperty(C_RESOLVE, cc.resolve());
}
clearSystemProperty(state, sysProp);
return factory;
@ -410,6 +488,12 @@ public class TestBase {
protected SchemaFactory getSchemaFactory(Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp)
throws Exception {
return getSchemaFactory(fsp, state, config, sysProp, apiProp, null);
}
protected SchemaFactory getSchemaFactory(Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc)
throws Exception {
setSystemProperty(config, state, sysProp);
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
@ -427,6 +511,11 @@ public class TestBase {
}
}
if (cc != null) {
factory.setProperty(C_FILE, cc.file());
factory.setProperty(C_RESOLVE, cc.resolve());
}
clearSystemProperty(state, sysProp);
return factory;
@ -435,6 +524,12 @@ public class TestBase {
protected TransformerFactory getTransformerFactory(Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp)
throws Exception {
return getTransformerFactory(fsp, state, config, sysProp, apiProp, null);
}
protected TransformerFactory getTransformerFactory(Properties fsp, PropertyState state,
Properties config, Properties[] sysProp, Properties[] apiProp, CustomCatalog cc)
throws Exception {
setSystemProperty(config, state, sysProp);
TransformerFactory tf = TransformerFactory.newInstance();
//tf.setAttribute(JDK_ENTITY_COUNT_INFO, "yes");
@ -450,6 +545,10 @@ public class TestBase {
}
}
}
if (cc != null) {
tf.setAttribute(C_FILE, cc.file());
tf.setAttribute(C_RESOLVE, cc.resolve());
}
clearSystemProperty(state, sysProp);
@ -605,8 +704,8 @@ public class TestBase {
}
}
static String getPath(String file) {
String temp = TEST_SOURCE_DIR + file;
static String getPath(String base, String file) {
String temp = base + file;
if (IS_WINDOWS) {
temp = "/" + temp;
}

View File

@ -0,0 +1,6 @@
<?xml version="1.1"?>
<!-- comment before root 1 -->
<xinclude:include xmlns:xinclude="http://www.w3.org/2001/XInclude"
href="XI_simple.xml"/>
<!-- comment after root 1 -->

View File

@ -0,0 +1,6 @@
<!DOCTYPE top SYSTEM 'test.dtd'
[
<!ENTITY % pe0 "x">
<!ENTITY x1 "A">
]>
<top>123&x1;</top>

View File

@ -0,0 +1,12 @@
<?xml version='1.0' encoding ='utf-8'?>
<!DOCTYPE SupplierOrder [
<!ENTITY % paraEntity SYSTEM "file:/externalParameterEntity">
%paraEntity;
]>
<SupplierOrder>
value value1
<OrderId>10016</OrderId>
<LineItems>
<LineItem categoryId="BIRDS" itemId="EST-18" lineNo="0" productId="AV-CB-01" quantity="&quantity;" unitPrice="&unitPrice;"/>
</LineItems>
</SupplierOrder>