8265248: Implementation Specific Properties: change prefix, plus add existing properties

Reviewed-by: lancea, rriggs
This commit is contained in:
Joe Wang 2021-05-26 19:34:06 +00:00
parent c59484e715
commit 8c4719a588
60 changed files with 1994 additions and 1101 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, 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
@ -25,12 +25,13 @@
package com.sun.org.apache.xalan.internal.utils;
import com.sun.org.apache.xalan.internal.XalanConstants;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.SecuritySupport;
/**
* This is the base class for features and properties
*
* @LastModified: May 2021
*/
public abstract class FeaturePropertyBase {
@ -113,9 +114,9 @@ public abstract class FeaturePropertyBase {
int index = getIndex(propertyName);
if (index > -1) {
if (value) {
setValue(index, state, XalanConstants.FEATURE_TRUE);
setValue(index, state, JdkConstants.FEATURE_TRUE);
} else {
setValue(index, state, XalanConstants.FEATURE_FALSE);
setValue(index, state, JdkConstants.FEATURE_FALSE);
}
return true;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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
@ -25,8 +25,10 @@
package com.sun.org.apache.xalan.internal.utils;
import com.sun.org.apache.xalan.internal.XalanConstants;
import java.util.concurrent.CopyOnWriteArrayList;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty.ImplPropMap;
import jdk.xml.internal.JdkProperty.State;
import jdk.xml.internal.SecuritySupport;
import org.xml.sax.SAXException;
@ -41,51 +43,30 @@ import org.xml.sax.SAXException;
*/
public final class XMLSecurityManager {
/**
* States of the settings of a property, in the order: default value, value
* set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system
* properties, and jaxp api properties
*/
public static enum State {
//this order reflects the overriding order
DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"),
JAXPDOTPROPERTIES("jaxp.properties"), SYSTEMPROPERTY("system property"),
APIPROPERTY("property");
final String literal;
State(String literal) {
this.literal = literal;
}
String literal() {
return literal;
}
}
/**
* Limits managed by the security manager
*/
@SuppressWarnings("deprecation")
public static enum Limit {
ENTITY_EXPANSION_LIMIT("EntityExpansionLimit", XalanConstants.JDK_ENTITY_EXPANSION_LIMIT,
XalanConstants.SP_ENTITY_EXPANSION_LIMIT, 0, 64000),
MAX_OCCUR_NODE_LIMIT("MaxOccurLimit", XalanConstants.JDK_MAX_OCCUR_LIMIT,
XalanConstants.SP_MAX_OCCUR_LIMIT, 0, 5000),
ELEMENT_ATTRIBUTE_LIMIT("ElementAttributeLimit", XalanConstants.JDK_ELEMENT_ATTRIBUTE_LIMIT,
XalanConstants.SP_ELEMENT_ATTRIBUTE_LIMIT, 0, 10000),
TOTAL_ENTITY_SIZE_LIMIT("TotalEntitySizeLimit", XalanConstants.JDK_TOTAL_ENTITY_SIZE_LIMIT,
XalanConstants.SP_TOTAL_ENTITY_SIZE_LIMIT, 0, 50000000),
GENERAL_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit", XalanConstants.JDK_GENERAL_ENTITY_SIZE_LIMIT,
XalanConstants.SP_GENERAL_ENTITY_SIZE_LIMIT, 0, 0),
PARAMETER_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit", XalanConstants.JDK_PARAMETER_ENTITY_SIZE_LIMIT,
XalanConstants.SP_PARAMETER_ENTITY_SIZE_LIMIT, 0, 1000000),
MAX_ELEMENT_DEPTH_LIMIT("MaxElementDepthLimit", XalanConstants.JDK_MAX_ELEMENT_DEPTH,
XalanConstants.SP_MAX_ELEMENT_DEPTH, 0, 0),
MAX_NAME_LIMIT("MaxXMLNameLimit", XalanConstants.JDK_XML_NAME_LIMIT,
XalanConstants.SP_XML_NAME_LIMIT, 1000, 1000),
ENTITY_REPLACEMENT_LIMIT("EntityReplacementLimit", XalanConstants.JDK_ENTITY_REPLACEMENT_LIMIT,
XalanConstants.SP_ENTITY_REPLACEMENT_LIMIT, 0, 3000000);
ENTITY_EXPANSION_LIMIT("EntityExpansionLimit", JdkConstants.JDK_ENTITY_EXPANSION_LIMIT,
JdkConstants.SP_ENTITY_EXPANSION_LIMIT, 0, 64000),
MAX_OCCUR_NODE_LIMIT("MaxOccurLimit", JdkConstants.JDK_MAX_OCCUR_LIMIT,
JdkConstants.SP_MAX_OCCUR_LIMIT, 0, 5000),
ELEMENT_ATTRIBUTE_LIMIT("ElementAttributeLimit", JdkConstants.JDK_ELEMENT_ATTRIBUTE_LIMIT,
JdkConstants.SP_ELEMENT_ATTRIBUTE_LIMIT, 0, 10000),
TOTAL_ENTITY_SIZE_LIMIT("TotalEntitySizeLimit", JdkConstants.JDK_TOTAL_ENTITY_SIZE_LIMIT,
JdkConstants.SP_TOTAL_ENTITY_SIZE_LIMIT, 0, 50000000),
GENERAL_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit", JdkConstants.JDK_GENERAL_ENTITY_SIZE_LIMIT,
JdkConstants.SP_GENERAL_ENTITY_SIZE_LIMIT, 0, 0),
PARAMETER_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit", JdkConstants.JDK_PARAMETER_ENTITY_SIZE_LIMIT,
JdkConstants.SP_PARAMETER_ENTITY_SIZE_LIMIT, 0, 1000000),
MAX_ELEMENT_DEPTH_LIMIT("MaxElementDepthLimit", JdkConstants.JDK_MAX_ELEMENT_DEPTH,
JdkConstants.SP_MAX_ELEMENT_DEPTH, 0, 0),
MAX_NAME_LIMIT("MaxXMLNameLimit", JdkConstants.JDK_XML_NAME_LIMIT,
JdkConstants.SP_XML_NAME_LIMIT, 1000, 1000),
ENTITY_REPLACEMENT_LIMIT("EntityReplacementLimit", JdkConstants.JDK_ENTITY_REPLACEMENT_LIMIT,
JdkConstants.SP_ENTITY_REPLACEMENT_LIMIT, 0, 3000000);
final String key;
final String apiProperty;
@ -101,12 +82,36 @@ public final class XMLSecurityManager {
this.secureValue = secureValue;
}
public boolean equalsAPIPropertyName(String propertyName) {
return (propertyName == null) ? false : apiProperty.equals(propertyName);
/**
* Checks whether the specified name is a limit. Checks both the
* property and System Property which is now the new property name.
*
* @param name the specified name
* @return true if there is a match, false otherwise
*/
public boolean is(String name) {
// current spec: new property name == systemProperty
return (systemProperty != null && systemProperty.equals(name)) ||
// current spec: apiProperty is legacy
(apiProperty.equals(name));
}
public boolean equalsSystemPropertyName(String propertyName) {
return (propertyName == null) ? false : systemProperty.equals(propertyName);
/**
* Returns the state of a property name. By the specification as of JDK 17,
* the "jdk.xml." prefixed System property name is also the current API
* name. The URI-based qName is legacy.
*
* @param name the property name
* @return the state of the property name, null if no match
*/
public State getState(String name) {
if (systemProperty != null && systemProperty.equals(name)) {
return State.APIPROPERTY;
} else if (apiProperty.equals(name)) {
//the URI-style qName is legacy
return State.LEGACY_APIPROPERTY;
}
return null;
}
public String key() {
@ -117,7 +122,7 @@ public final class XMLSecurityManager {
return apiProperty;
}
String systemProperty() {
public String systemProperty() {
return systemProperty;
}
@ -135,12 +140,12 @@ public final class XMLSecurityManager {
*/
public static enum NameMap {
ENTITY_EXPANSION_LIMIT(XalanConstants.SP_ENTITY_EXPANSION_LIMIT,
XalanConstants.ENTITY_EXPANSION_LIMIT),
MAX_OCCUR_NODE_LIMIT(XalanConstants.SP_MAX_OCCUR_LIMIT,
XalanConstants.MAX_OCCUR_LIMIT),
ELEMENT_ATTRIBUTE_LIMIT(XalanConstants.SP_ELEMENT_ATTRIBUTE_LIMIT,
XalanConstants.ELEMENT_ATTRIBUTE_LIMIT);
ENTITY_EXPANSION_LIMIT(JdkConstants.SP_ENTITY_EXPANSION_LIMIT,
JdkConstants.ENTITY_EXPANSION_LIMIT),
MAX_OCCUR_NODE_LIMIT(JdkConstants.SP_MAX_OCCUR_LIMIT,
JdkConstants.MAX_OCCUR_LIMIT),
ELEMENT_ATTRIBUTE_LIMIT(JdkConstants.SP_ELEMENT_ATTRIBUTE_LIMIT,
JdkConstants.ELEMENT_ATTRIBUTE_LIMIT);
final String newName;
final String oldName;
@ -230,7 +235,11 @@ public final class XMLSecurityManager {
public boolean setLimit(String propertyName, State state, Object value) {
int index = getIndex(propertyName);
if (index > -1) {
setLimit(index, state, value);
State pState = state;
if (index != indexEntityCountInfo && state == State.APIPROPERTY) {
pState = (Limit.values()[index]).getState(propertyName);
}
setLimit(index, pState, value);
return true;
}
return false;
@ -259,14 +268,17 @@ public final class XMLSecurityManager {
//if it's explicitly set, it's treated as yes no matter the value
printEntityCountInfo = (String)value;
} else {
int temp = 0;
try {
int temp;
if (value instanceof Integer) {
temp = (Integer)value;
} else {
temp = Integer.parseInt((String) value);
if (temp < 0) {
temp = 0;
}
} catch (NumberFormatException e) {}
setLimit(index, state, temp); }
}
setLimit(index, state, temp);
}
}
/**
@ -279,7 +291,7 @@ public final class XMLSecurityManager {
public void setLimit(int index, State state, int value) {
if (index == indexEntityCountInfo) {
//if it's explicitly set, it's treated as yes no matter the value
printEntityCountInfo = XalanConstants.JDK_YES;
printEntityCountInfo = JdkConstants.JDK_YES;
} else {
//only update if it shall override
if (state.compareTo(states[index]) >= 0) {
@ -377,13 +389,14 @@ public final class XMLSecurityManager {
*/
public int getIndex(String propertyName) {
for (Limit limit : Limit.values()) {
if (limit.equalsAPIPropertyName(propertyName)) {
// see JDK-8265248, accept both the URL and jdk.xml as prefix
if (limit.is(propertyName)) {
//internally, ordinal is used as index
return limit.ordinal();
}
}
//special property to return entity count info
if (propertyName.equals(XalanConstants.JDK_ENTITY_COUNT_INFO)) {
if (ImplPropMap.ENTITYCOUNT.is(propertyName)) {
return indexEntityCountInfo;
}
return -1;
@ -399,7 +412,7 @@ public final class XMLSecurityManager {
}
public boolean printEntityCountInfo() {
return printEntityCountInfo.equals(XalanConstants.JDK_YES);
return printEntityCountInfo.equals(JdkConstants.JDK_YES);
}
/**
* Read from system properties, or those in jaxp.properties

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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
@ -25,9 +25,8 @@
package com.sun.org.apache.xalan.internal.utils;
import com.sun.org.apache.xalan.internal.XalanConstants;
import javax.xml.XMLConstants;
import jdk.xml.internal.JdkConstants;
/**
* This class manages security related properties
@ -40,9 +39,9 @@ public final class XMLSecurityPropertyManager extends FeaturePropertyBase {
*/
public static enum Property {
ACCESS_EXTERNAL_DTD(XMLConstants.ACCESS_EXTERNAL_DTD,
XalanConstants.EXTERNAL_ACCESS_DEFAULT),
JdkConstants.EXTERNAL_ACCESS_DEFAULT),
ACCESS_EXTERNAL_STYLESHEET(XMLConstants.ACCESS_EXTERNAL_STYLESHEET,
XalanConstants.EXTERNAL_ACCESS_DEFAULT);
JdkConstants.EXTERNAL_ACCESS_DEFAULT);
final String name;
final String defaultValue;
@ -94,9 +93,9 @@ public final class XMLSecurityPropertyManager extends FeaturePropertyBase {
*/
private void readSystemProperties() {
getSystemProperty(Property.ACCESS_EXTERNAL_DTD,
XalanConstants.SP_ACCESS_EXTERNAL_DTD);
JdkConstants.SP_ACCESS_EXTERNAL_DTD);
getSystemProperty(Property.ACCESS_EXTERNAL_STYLESHEET,
XalanConstants.SP_ACCESS_EXTERNAL_STYLESHEET);
JdkConstants.SP_ACCESS_EXTERNAL_STYLESHEET);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -23,7 +23,6 @@
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
@ -32,6 +31,7 @@ import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
import java.util.Iterator;
import javax.xml.XMLConstants;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.SecuritySupport;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
@ -41,7 +41,7 @@ import org.xml.sax.XMLReader;
* @author Morten Jorgensen
* @author Erwin Bolwidt <ejb@klomp.org>
* @author Gunnlaugur Briem <gthb@dimon.is>
* @LastModified: Sep 2017
* @LastModified: May 2021
*/
final class Import extends TopLevelElement {
@ -85,7 +85,7 @@ final class Import extends TopLevelElement {
docToLoad = SystemIDResolver.getAbsoluteURI(docToLoad, currLoadedDoc);
String accessError = SecuritySupport.checkAccess(docToLoad,
(String)xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET),
XalanConstants.ACCESS_EXTERNAL_ALL);
JdkConstants.ACCESS_EXTERNAL_ALL);
if (accessError != null) {
final ErrorMsg msg = new ErrorMsg(ErrorMsg.ACCESSING_XSLT_TARGET_ERR,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -23,7 +23,6 @@
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
@ -32,6 +31,7 @@ import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
import java.util.Iterator;
import javax.xml.XMLConstants;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.SecuritySupport;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
@ -41,7 +41,7 @@ import org.xml.sax.XMLReader;
* @author Morten Jorgensen
* @author Erwin Bolwidt <ejb@klomp.org>
* @author Gunnlaugur Briem <gthb@dimon.is>
* @LastModified: Sep 2017
* @LastModified: May 2021
*/
final class Include extends TopLevelElement {
@ -85,7 +85,7 @@ final class Include extends TopLevelElement {
docToLoad = SystemIDResolver.getAbsoluteURI(docToLoad, currLoadedDoc);
String accessError = SecuritySupport.checkAccess(docToLoad,
(String)xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET),
XalanConstants.ACCESS_EXTERNAL_ALL);
JdkConstants.ACCESS_EXTERNAL_ALL);
if (accessError != null) {
final ErrorMsg msg = new ErrorMsg(ErrorMsg.ACCESSING_XSLT_TARGET_ERR,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -21,7 +21,6 @@
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import com.sun.java_cup.internal.runtime.Symbol;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
@ -43,6 +42,7 @@ import java.util.StringTokenizer;
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
import jdk.xml.internal.ErrorHandlerProxy;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
@ -62,7 +62,7 @@ import org.xml.sax.helpers.AttributesImpl;
* @author G. Todd Miller
* @author Morten Jorgensen
* @author Erwin Bolwidt <ejb@klomp.org>
* @LastModified: July 2019
* @LastModified: May 2021
*/
public class Parser implements Constants, ContentHandler {
@ -502,22 +502,22 @@ public class Parser implements Constants, ContentHandler {
String lastProperty = "";
try {
XMLSecurityManager securityManager =
(XMLSecurityManager)_xsltc.getProperty(XalanConstants.SECURITY_MANAGER);
(XMLSecurityManager)_xsltc.getProperty(JdkConstants.SECURITY_MANAGER);
for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
lastProperty = limit.apiProperty();
reader.setProperty(lastProperty, securityManager.getLimitValueAsString(limit));
}
if (securityManager.printEntityCountInfo()) {
lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
reader.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
lastProperty = JdkConstants.JDK_DEBUG_LIMIT;
reader.setProperty(lastProperty, JdkConstants.JDK_YES);
}
} catch (SAXException se) {
XMLSecurityManager.printWarning(reader.getClass().getName(), lastProperty, se);
}
// try setting other JDK-impl properties, ignore if not supported
JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, JdkXmlUtils.CDATA_CHUNK_SIZE,
_xsltc.getProperty(JdkXmlUtils.CDATA_CHUNK_SIZE), false);
JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, JdkConstants.CDATA_CHUNK_SIZE,
_xsltc.getProperty(JdkConstants.CDATA_CHUNK_SIZE), false);
return(parse(reader, input));
}
@ -591,7 +591,7 @@ public class Parser implements Constants, ContentHandler {
path = SystemIDResolver.getAbsoluteURI(path);
String accessError = SecuritySupport.checkAccess(path,
(String)_xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET),
XalanConstants.ACCESS_EXTERNAL_ALL);
JdkConstants.ACCESS_EXTERNAL_ALL);
if (accessError != null) {
ErrorMsg msg = new ErrorMsg(ErrorMsg.ACCESSING_XSLT_TARGET_ERR,
SecuritySupport.sanitizePath(_target), accessError,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -21,7 +21,6 @@
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import com.sun.org.apache.bcel.internal.classfile.JavaClass;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
@ -46,6 +45,7 @@ import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
@ -58,7 +58,7 @@ import org.xml.sax.XMLReader;
* @author G. Todd Miller
* @author Morten Jorgensen
* @author John Howard (johnh@schemasoft.com)
* @LastModified: July 2019
* @LastModified: May 2021
*/
public final class XSLTC {
@ -140,11 +140,11 @@ public final class XSLTC {
/**
* protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
*/
private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
private String _accessExternalStylesheet = JdkConstants.EXTERNAL_ACCESS_DEFAULT;
/**
* protocols allowed for external DTD references in source file and/or stylesheet.
*/
private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
private String _accessExternalDTD = JdkConstants.EXTERNAL_ACCESS_DEFAULT;
private XMLSecurityManager _xmlSecurityManager;
@ -218,13 +218,13 @@ public final class XSLTC {
}
else if (name.equals(XMLConstants.ACCESS_EXTERNAL_DTD)) {
return _accessExternalDTD;
} else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
} else if (name.equals(JdkConstants.SECURITY_MANAGER)) {
return _xmlSecurityManager;
} else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
} else if (name.equals(JdkConstants.JDK_EXT_CLASSLOADER)) {
return _extensionClassLoader;
} else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) {
return _catalogFeatures;
} else if (JdkXmlUtils.CDATA_CHUNK_SIZE.equals(name)) {
} else if (JdkConstants.CDATA_CHUNK_SIZE.equals(name)) {
return _cdataChunkSize;
}
return null;
@ -241,16 +241,16 @@ public final class XSLTC {
}
else if (name.equals(XMLConstants.ACCESS_EXTERNAL_DTD)) {
_accessExternalDTD = (String)value;
} else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
} else if (name.equals(JdkConstants.SECURITY_MANAGER)) {
_xmlSecurityManager = (XMLSecurityManager)value;
} else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
} else if (name.equals(JdkConstants.JDK_EXT_CLASSLOADER)) {
_extensionClassLoader = (ClassLoader) value;
/* Clear the external extension functions HashMap if extension class
loader was changed */
_externalExtensionFunctions.clear();
} else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) {
_catalogFeatures = (CatalogFeatures)value;
} else if (JdkXmlUtils.CDATA_CHUNK_SIZE.equals(name)) {
} else if (JdkConstants.CDATA_CHUNK_SIZE.equals(name)) {
_cdataChunkSize = Integer.parseInt((String)value);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -20,7 +20,6 @@
package com.sun.org.apache.xalan.internal.xsltc.dom;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.DOMCache;
import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM;
@ -35,11 +34,12 @@ import com.sun.org.apache.xml.internal.dtm.ref.EmptyIterator;
import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
import java.io.FileNotFoundException;
import javax.xml.transform.stream.StreamSource;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.SecuritySupport;
/**
* @author Morten Jorgensen
* @LastModified: Sep 2017
* @LastModified: May 2021
*/
public final class LoadDocument {
@ -194,7 +194,7 @@ public final class LoadDocument {
throw new TransletException(e);
}
} else {
String accessError = SecuritySupport.checkAccess(uri, translet.getAllowedProtocols(), XalanConstants.ACCESS_EXTERNAL_ALL);
String accessError = SecuritySupport.checkAccess(uri, translet.getAllowedProtocols(), JdkConstants.ACCESS_EXTERNAL_ALL);
if (accessError != null) {
ErrorMsg msg = new ErrorMsg(ErrorMsg.ACCESSING_XSLT_TARGET_ERR,
SecuritySupport.sanitizePath(uri), accessError);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -20,7 +20,6 @@
package com.sun.org.apache.xalan.internal.xsltc.runtime;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.DOMCache;
import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM;
@ -44,6 +43,7 @@ import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Templates;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
@ -54,7 +54,7 @@ import org.w3c.dom.Document;
* @author Morten Jorgensen
* @author G. Todd Miller
* @author John Howard, JohnH@schemasoft.com
* @LastModified: Aug 2019
* @LastModified: May 2021
*/
public abstract class AbstractTranslet implements Translet {
@ -65,7 +65,7 @@ public abstract class AbstractTranslet implements Translet {
public String _encoding = "UTF-8";
public boolean _omitHeader = false;
public String _standalone = null;
//see OutputPropertiesFactory.ORACLE_IS_STANDALONE
//see JdkConstants.SP_XSLTC_IS_Standalone
public boolean _isStandalone = false;
public String _doctypePublic = null;
public String _doctypeSystem = null;
@ -114,7 +114,7 @@ public abstract class AbstractTranslet implements Translet {
/**
* protocols allowed for external references set by the stylesheet processing instruction, Document() function, Import and Include element.
*/
private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
private String _accessExternalStylesheet = JdkConstants.EXTERNAL_ACCESS_DEFAULT;
/************************************************************************
* Debugging

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -20,7 +20,6 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.xsltc.compiler.CompilerException;
import com.sun.org.apache.xalan.internal.xsltc.compiler.Parser;
import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader;
@ -36,6 +35,7 @@ import javax.xml.transform.Templates;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.TemplatesHandler;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlFeatures;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
@ -47,7 +47,7 @@ import org.xml.sax.SAXException;
* Implementation of a JAXP1.1 TemplatesHandler
* @author Morten Jorgensen
* @author Santiago Pericas-Geertsen
* @LastModified: July 2019
* @LastModified: May 2021
*/
public class TemplatesHandlerImpl
implements ContentHandler, TemplatesHandler, SourceLoader
@ -107,8 +107,8 @@ public class TemplatesHandlerImpl
(String)tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET));
xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD,
(String)tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_DTD));
xsltc.setProperty(XalanConstants.SECURITY_MANAGER,
tfactory.getAttribute(XalanConstants.SECURITY_MANAGER));
xsltc.setProperty(JdkConstants.SECURITY_MANAGER,
tfactory.getAttribute(JdkConstants.SECURITY_MANAGER));
if ("true".equals(tfactory.getAttribute(TransformerFactoryImpl.ENABLE_INLINING)))

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -23,7 +23,6 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.Translet;
@ -60,6 +59,7 @@ import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.URIResolver;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.SecuritySupport;
@ -68,7 +68,7 @@ import jdk.xml.internal.SecuritySupport;
* @author G. Todd Millerj
* @author Jochen Cordes <Jochen.Cordes@t-online.de>
* @author Santiago Pericas-Geertsen
* @LastModified: May 2020
* @LastModified: May 2021
*/
public final class TemplatesImpl implements Templates, Serializable {
static final long serialVersionUID = 673094361519270707L;
@ -149,7 +149,7 @@ public final class TemplatesImpl implements Templates, Serializable {
/**
* protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
*/
private transient String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
private transient String _accessExternalStylesheet = JdkConstants.EXTERNAL_ACCESS_DEFAULT;
/**
* @serialField _name String The Name of the main class

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -20,7 +20,7 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
import com.sun.org.apache.xalan.internal.XalanConstants;
import jdk.xml.internal.JdkConstants;
import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
@ -71,8 +71,11 @@ import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stax.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import jdk.xml.internal.JdkProperty;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.JdkProperty.ImplPropMap;
import jdk.xml.internal.JdkProperty.State;
import jdk.xml.internal.SecuritySupport;
import jdk.xml.internal.TransformErrorListener;
import org.xml.sax.InputSource;
@ -85,7 +88,7 @@ import org.xml.sax.XMLReader;
* @author G. Todd Miller
* @author Morten Jorgensen
* @author Santiago Pericas-Geertsen
* @LastModified: Aug 2019
* @LastModified: May 2021
*/
public class TransformerFactoryImpl
extends SAXTransformerFactory implements SourceLoader
@ -230,18 +233,18 @@ public class TransformerFactoryImpl
* protocols allowed for external references set by the stylesheet
* processing instruction, Import and Include element.
*/
private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
private String _accessExternalStylesheet = JdkConstants.EXTERNAL_ACCESS_DEFAULT;
/**
* protocols allowed for external DTD references in source file and/or stylesheet.
*/
private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
private String _accessExternalDTD = JdkConstants.EXTERNAL_ACCESS_DEFAULT;
private XMLSecurityPropertyManager _xmlSecurityPropertyMgr;
private XMLSecurityManager _xmlSecurityManager;
private final JdkXmlFeatures _xmlFeatures;
private ClassLoader _extensionClassLoader = null;
private JdkProperty<ClassLoader> _extensionClassLoader = null;
// Unmodifiable view of external extension function from xslt compiler
// It will be populated by user-specified extension functions during the
@ -257,7 +260,7 @@ public class TransformerFactoryImpl
String _catalogPrefer = null;
String _catalogResolve = null;
int _cdataChunkSize = JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT;
int _cdataChunkSize = JdkConstants.CDATA_CHUNK_SIZE_DEFAULT;
/**
* javax.xml.transform.sax.TransformerFactory implementation.
@ -282,6 +285,7 @@ public class TransformerFactoryImpl
_xmlSecurityManager = new XMLSecurityManager(true);
//Unmodifiable hash map with loaded external extension functions
_xsltcExtensionFunctions = null;
_extensionClassLoader = new JdkProperty<>(ImplPropMap.EXTCLSLOADER, null, State.DEFAULT);
}
public Map<String, Class<?>> getExternalExtensionsMap() {
@ -355,10 +359,10 @@ public class TransformerFactoryImpl
return Boolean.TRUE;
else
return Boolean.FALSE;
} else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
} else if (name.equals(JdkConstants.SECURITY_MANAGER)) {
return _xmlSecurityManager;
} else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
return _extensionClassLoader;
} else if (ImplPropMap.EXTCLSLOADER.is(name)) {
return (_extensionClassLoader == null) ? null : _extensionClassLoader.getValue();
} else if (JdkXmlUtils.CATALOG_FILES.equals(name)) {
return _catalogFiles;
} else if (JdkXmlUtils.CATALOG_DEFER.equals(name)) {
@ -369,7 +373,7 @@ public class TransformerFactoryImpl
return _catalogResolve;
} else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) {
return buildCatalogFeatures();
} else if (JdkXmlUtils.CDATA_CHUNK_SIZE.equals(name)) {
} else if (ImplPropMap.CDATACHUNKSIZE.is(name)) {
return _cdataChunkSize;
}
@ -486,9 +490,9 @@ public class TransformerFactoryImpl
return;
}
}
else if ( name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
else if (ImplPropMap.EXTCLSLOADER.is(name)) {
if (value instanceof ClassLoader) {
_extensionClassLoader = (ClassLoader) value;
_extensionClassLoader.setValue(name, (ClassLoader)value, State.APIPROPERTY);
return;
} else {
final ErrorMsg err
@ -511,13 +515,13 @@ public class TransformerFactoryImpl
_catalogResolve = (String) value;
cfBuilder = CatalogFeatures.builder().with(Feature.RESOLVE, _catalogResolve);
return;
} else if (JdkXmlUtils.CDATA_CHUNK_SIZE.equals(name)) {
} else if (ImplPropMap.CDATACHUNKSIZE.is(name)) {
_cdataChunkSize = JdkXmlUtils.getValue(value, _cdataChunkSize);
return;
}
if (_xmlSecurityManager != null &&
_xmlSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, value)) {
_xmlSecurityManager.setLimit(name, JdkProperty.State.APIPROPERTY, value)) {
return;
}
@ -558,6 +562,7 @@ public class TransformerFactoryImpl
* @throws NullPointerException If the <code>name</code> parameter is null.
*/
@Override
@SuppressWarnings("deprecation")
public void setFeature(String name, boolean value)
throws TransformerConfigurationException {
@ -578,9 +583,9 @@ public class TransformerFactoryImpl
// set external access restriction when FSP is explicitly set
if (value) {
_xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD,
FeaturePropertyBase.State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
FeaturePropertyBase.State.FSP, JdkConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
_xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_STYLESHEET,
FeaturePropertyBase.State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
FeaturePropertyBase.State.FSP, JdkConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
_accessExternalDTD = _xmlSecurityPropertyMgr.getValue(
Property.ACCESS_EXTERNAL_DTD);
_accessExternalStylesheet = _xmlSecurityPropertyMgr.getValue(
@ -589,20 +594,19 @@ public class TransformerFactoryImpl
if (value && _xmlFeatures != null) {
_xmlFeatures.setFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION,
JdkXmlFeatures.State.FSP, false);
JdkProperty.State.FSP, false);
}
}
else {
if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
if (name.equals(JdkConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
// for compatibility, in secure mode, useServicesMechanism is determined by the constructor
if (_isSecureMode) {
return;
}
}
if (_xmlFeatures != null &&
_xmlFeatures.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) {
if (name.equals(JdkXmlUtils.OVERRIDE_PARSER) ||
name.equals(JdkXmlFeatures.ORACLE_FEATURE_SERVICE_MECHANISM)) {
_xmlFeatures.setFeature(name, JdkProperty.State.APIPROPERTY, value)) {
if (ImplPropMap.OVERRIDEPARSER.is(name)) {
_overrideDefaultParser = _xmlFeatures.getFeature(
JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
}
@ -625,6 +629,7 @@ public class TransformerFactoryImpl
* @return 'true' if feature is supported, 'false' if not
*/
@Override
@SuppressWarnings("deprecation")
public boolean getFeature(String name) {
// All supported features should be listed here
String[] features = {
@ -638,7 +643,7 @@ public class TransformerFactoryImpl
StreamResult.FEATURE,
SAXTransformerFactory.FEATURE,
SAXTransformerFactory.FEATURE_XMLFILTER,
XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM
JdkConstants.ORACLE_FEATURE_SERVICE_MECHANISM
};
// feature name cannot be null
@ -966,8 +971,9 @@ public class TransformerFactoryImpl
if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true);
xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, _accessExternalStylesheet);
xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD);
xsltc.setProperty(XalanConstants.SECURITY_MANAGER, _xmlSecurityManager);
xsltc.setProperty(XalanConstants.JDK_EXTENSION_CLASSLOADER, _extensionClassLoader);
xsltc.setProperty(JdkConstants.SECURITY_MANAGER, _xmlSecurityManager);
xsltc.setProperty(JdkConstants.JDK_EXT_CLASSLOADER,
(_extensionClassLoader == null) ? null : _extensionClassLoader.getValue());
// set Catalog features
buildCatalogFeatures();

View File

@ -20,7 +20,6 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.DOMCache;
@ -81,8 +80,13 @@ import javax.xml.transform.stax.StAXResult;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import jdk.xml.internal.JdkConstants;
import static jdk.xml.internal.JdkConstants.SP_XSLTC_IS_STANDALONE;
import jdk.xml.internal.JdkProperty;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.JdkProperty.ImplPropMap;
import jdk.xml.internal.JdkProperty.State;
import jdk.xml.internal.SecuritySupport;
import jdk.xml.internal.TransformErrorListener;
import org.xml.sax.ContentHandler;
@ -95,7 +99,7 @@ import org.xml.sax.ext.LexicalHandler;
* @author Morten Jorgensen
* @author G. Todd Miller
* @author Santiago Pericas-Geertsen
* @LastModified: Feb 2021
* @LastModified: May 2021
*/
public final class TransformerImpl extends Transformer
implements DOMCache
@ -211,7 +215,7 @@ public final class TransformerImpl extends Transformer
/**
* protocols allowed for external DTD references in source file and/or stylesheet.
*/
private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
private String _accessExternalDTD = JdkConstants.EXTERNAL_ACCESS_DEFAULT;
private XMLSecurityManager _securityManager;
/**
@ -228,7 +232,10 @@ public final class TransformerImpl extends Transformer
// Catalog is enabled by default
boolean _useCatalog = true;
int _cdataChunkSize = JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT;
int _cdataChunkSize = JdkConstants.CDATA_CHUNK_SIZE_DEFAULT;
// OutputProperty/Impl-specific property: xsltcIsStandalone
JdkProperty<String> _xsltcIsStandalone;
/**
* This class wraps an ErrorListener into a MessageHandler in order to
@ -279,23 +286,23 @@ public final class TransformerImpl extends Transformer
_translet.setMessageHandler(new MessageHandler(_errorListener));
}
_properties = createOutputProperties(outputProperties);
String v = SecuritySupport.getJAXPSystemProperty(OutputPropertiesFactory.SP_IS_STANDALONE);
if (v != null) {
_properties.setProperty(OutputPropertiesFactory.JDK_IS_STANDALONE, v);
}
String isStandalone = SecuritySupport.getJAXPSystemProperty(
String.class, SP_XSLTC_IS_STANDALONE, "no");
_xsltcIsStandalone = new JdkProperty<>(ImplPropMap.XSLTCISSTANDALONE,
isStandalone, State.DEFAULT);
_propertiesClone = (Properties) _properties.clone();
_indentNumber = indentNumber;
_tfactory = tfactory;
_overrideDefaultParser = _tfactory.overrideDefaultParser();
_accessExternalDTD = (String)_tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_DTD);
_securityManager = (XMLSecurityManager)_tfactory.getAttribute(XalanConstants.SECURITY_MANAGER);
_securityManager = (XMLSecurityManager)_tfactory.getAttribute(JdkConstants.SECURITY_MANAGER);
_readerManager = XMLReaderManager.getInstance(_overrideDefaultParser);
_readerManager.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD);
_readerManager.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, _isSecureProcessing);
_readerManager.setProperty(XalanConstants.SECURITY_MANAGER, _securityManager);
_cdataChunkSize = JdkXmlUtils.getValue(_tfactory.getAttribute(JdkXmlUtils.CDATA_CHUNK_SIZE),
JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT);
_readerManager.setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE, _cdataChunkSize);
_readerManager.setProperty(JdkConstants.SECURITY_MANAGER, _securityManager);
_cdataChunkSize = JdkXmlUtils.getValue(_tfactory.getAttribute(JdkConstants.CDATA_CHUNK_SIZE),
JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
_readerManager.setProperty(JdkConstants.CDATA_CHUNK_SIZE, _cdataChunkSize);
_useCatalog = _tfactory.getFeature(XMLConstants.USE_CATALOG);
if (_useCatalog) {
@ -905,6 +912,9 @@ public final class TransformerImpl extends Transformer
public String getOutputProperty(String name)
throws IllegalArgumentException
{
if (ImplPropMap.XSLTCISSTANDALONE.is(name)) {
return _xsltcIsStandalone.getValue();
}
if (!validOutputProperty(name)) {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, name);
throw new IllegalArgumentException(err.toString());
@ -966,7 +976,12 @@ public final class TransformerImpl extends Transformer
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, name);
throw new IllegalArgumentException(err.toString());
}
_properties.setProperty(name, value);
if (ImplPropMap.XSLTCISSTANDALONE.is(name)) {
_xsltcIsStandalone.setValue(name, value, State.APIPROPERTY);
} else {
_properties.setProperty(name, value);
}
}
/**
@ -1037,11 +1052,9 @@ public final class TransformerImpl extends Transformer
}
}
}
else if (isStandaloneProperty(name)) {
if (value != null && value.equals("yes")) {
translet._isStandalone = true;
}
}
}
if (_xsltcIsStandalone.getValue().equals("yes")) {
translet._isStandalone = true;
}
}
@ -1101,11 +1114,6 @@ public final class TransformerImpl extends Transformer
handler.setIndentAmount(Integer.parseInt(value));
}
}
else if (isStandaloneProperty(name)) {
if (value != null && value.equals("yes")) {
handler.setIsStandalone(true);
}
}
else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
if (value != null) {
StringTokenizer e = new StringTokenizer(value);
@ -1144,6 +1152,10 @@ public final class TransformerImpl extends Transformer
if (doctypePublic != null || doctypeSystem != null) {
handler.setDoctype(doctypeSystem, doctypePublic);
}
if (_xsltcIsStandalone.getValue().equals("yes")) {
handler.setIsStandalone(true);
}
}
/**
@ -1219,20 +1231,10 @@ public final class TransformerImpl extends Transformer
name.equals(OutputKeys.OMIT_XML_DECLARATION) ||
name.equals(OutputKeys.STANDALONE) ||
name.equals(OutputKeys.VERSION) ||
isStandaloneProperty(name) ||
ImplPropMap.XSLTCISSTANDALONE.is(name) ||
name.charAt(0) == '{');
}
/**
* Checks whether the property requested is the isStandalone property. Both
* the new and legacy property names are supported.
* @param name the property name
* @return true if the property is "isStandalone", false otherwise
*/
private boolean isStandaloneProperty(String name) {
return (name.equals(OutputPropertiesFactory.JDK_IS_STANDALONE) ||
name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE));
}
/**
* Checks if a given output property is default (2nd layer only)
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -20,7 +20,6 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
@ -37,9 +36,9 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamSource;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@ -51,6 +50,8 @@ import org.xml.sax.XMLReader;
* @author Santiago Pericas-Geertsen
*
* Added Catalog Support for URI resolution
*
* @LastModified: May 2021
*/
@SuppressWarnings("deprecation") //org.xml.sax.helpers.XMLReaderFactory
public final class Util {
@ -103,13 +104,13 @@ public final class Util {
JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, XMLConstants.ACCESS_EXTERNAL_DTD,
xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD), true);
JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, JdkXmlUtils.CDATA_CHUNK_SIZE,
xsltc.getProperty(JdkXmlUtils.CDATA_CHUNK_SIZE), false);
JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, JdkConstants.CDATA_CHUNK_SIZE,
xsltc.getProperty(JdkConstants.CDATA_CHUNK_SIZE), false);
String lastProperty = "";
try {
XMLSecurityManager securityManager =
(XMLSecurityManager)xsltc.getProperty(XalanConstants.SECURITY_MANAGER);
(XMLSecurityManager)xsltc.getProperty(JdkConstants.SECURITY_MANAGER);
if (securityManager != null) {
for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
lastProperty = limit.apiProperty();
@ -117,8 +118,8 @@ public final class Util {
securityManager.getLimitValueAsString(limit));
}
if (securityManager.printEntityCountInfo()) {
lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
reader.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
lastProperty = JdkConstants.JDK_DEBUG_LIMIT;
reader.setProperty(lastProperty, JdkConstants.JDK_YES);
}
}
} catch (SAXException se) {

View File

@ -54,6 +54,7 @@ import java.util.Locale;
import java.util.StringTokenizer;
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMErrorHandler;
@ -70,7 +71,7 @@ import org.w3c.dom.ls.LSResourceResolver;
*
* @author Elena Litani, IBM
* @author Neeraj Bajaj, Sun Microsystems.
* @LastModified: Apr 2019
* @LastModified: May 2021
*/
public class DOMConfigurationImpl extends ParserConfigurationSettings
implements XMLParserConfiguration, DOMConfiguration {
@ -213,7 +214,7 @@ public class DOMConfigurationImpl extends ParserConfigurationSettings
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
//
// Data
@ -327,7 +328,7 @@ public class DOMConfigurationImpl extends ParserConfigurationSettings
NAMESPACE_GROWTH,
TOLERATE_DUPLICATES,
XMLConstants.USE_CATALOG,
JdkXmlUtils.OVERRIDE_PARSER
JdkConstants.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
@ -351,7 +352,7 @@ public class DOMConfigurationImpl extends ParserConfigurationSettings
setFeature(NAMESPACE_GROWTH, false);
setFeature(TOLERATE_DUPLICATES, false);
setFeature(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
setFeature(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
setFeature(JdkConstants.OVERRIDE_PARSER, JdkConstants.OVERRIDE_PARSER_DEFAULT);
// add default recognized properties
final String[] recognizedProperties = {
@ -376,7 +377,7 @@ public class DOMConfigurationImpl extends ParserConfigurationSettings
JdkXmlUtils.CATALOG_FILES,
JdkXmlUtils.CATALOG_PREFER,
JdkXmlUtils.CATALOG_RESOLVE,
JdkXmlUtils.CDATA_CHUNK_SIZE
JdkConstants.CDATA_CHUNK_SIZE
};
addRecognizedProperties(recognizedProperties);
@ -415,7 +416,7 @@ public class DOMConfigurationImpl extends ParserConfigurationSettings
setProperty(SECURITY_MANAGER, new XMLSecurityManager(true));
setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER,
setProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER,
new XMLSecurityPropertyManager());
// add message formatters
@ -455,7 +456,7 @@ public class DOMConfigurationImpl extends ParserConfigurationSettings
setProperty(f.getPropertyName(), null);
}
setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE, JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT);
setProperty(JdkConstants.CDATA_CHUNK_SIZE, JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
} // <init>(SymbolTable)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -30,7 +30,7 @@ import java.util.NoSuchElementException;
*
* @author Andy Clark, IBM
*
* @LastModified: Oct 2017
* @LastModified: May 2021
*/
public final class Constants {
@ -141,23 +141,6 @@ public final class Constants {
public static final String FEATURE_SECURE_PROCESSING = "http://javax.xml.XMLConstants/feature/secure-processing";
// Oracle Feature:
/**
* <p>Use Service Mechanism</p>
*
* <ul>
* <li>
* {@code true} instruct an object to use service mechanism to
* find a service implementation. This is the default behavior.
* </li>
* <li>
* {@code false} instruct an object to skip service mechanism and
* use the default implementation for that service.
* </li>
* </ul>
*/
public static final String ORACLE_FEATURE_SERVICE_MECHANISM = "http://www.oracle.com/feature/use-service-mechanism";
/** Document XML version property ("document-xml-version"). */
public static final String DOCUMENT_XML_VERSION_PROPERTY = "document-xml-version";
@ -180,157 +163,6 @@ public final class Constants {
public static final String JAXPAPI_PROPERTY_PREFIX =
"http://javax.xml.XMLConstants/property/";
/** Oracle JAXP property prefix ("http://www.oracle.com/xml/jaxp/properties/"). */
public static final String ORACLE_JAXP_PROPERTY_PREFIX =
"http://www.oracle.com/xml/jaxp/properties/";
public static final String XML_SECURITY_PROPERTY_MANAGER =
ORACLE_JAXP_PROPERTY_PREFIX + "xmlSecurityPropertyManager";
//System Properties corresponding to ACCESS_EXTERNAL_* properties
public static final String SP_ACCESS_EXTERNAL_DTD = "javax.xml.accessExternalDTD";
public static final String SP_ACCESS_EXTERNAL_SCHEMA = "javax.xml.accessExternalSchema";
//all access keyword
public static final String ACCESS_EXTERNAL_ALL = "all";
/**
* Default value when FEATURE_SECURE_PROCESSING (FSP) is set to true
*/
public static final String EXTERNAL_ACCESS_DEFAULT_FSP = "";
/**
* FEATURE_SECURE_PROCESSING (FSP) is true by default
*/
public static final String EXTERNAL_ACCESS_DEFAULT = ACCESS_EXTERNAL_ALL;
//
// Implementation limits: corresponding System Properties of the above
// API properties
//
/**
* JDK entity expansion limit; Note that the existing system property
* "entityExpansionLimit" with no prefix is still observed
*/
public static final String JDK_ENTITY_EXPANSION_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "entityExpansionLimit";
/**
* JDK element attribute limit; Note that the existing system property
* "elementAttributeLimit" with no prefix is still observed
*/
public static final String JDK_ELEMENT_ATTRIBUTE_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "elementAttributeLimit";
/**
* JDK maxOccur limit; Note that the existing system property
* "maxOccurLimit" with no prefix is still observed
*/
public static final String JDK_MAX_OCCUR_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "maxOccurLimit";
/**
* JDK total entity size limit
*/
public static final String JDK_TOTAL_ENTITY_SIZE_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "totalEntitySizeLimit";
/**
* JDK maximum general entity size limit
*/
public static final String JDK_GENERAL_ENTITY_SIZE_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "maxGeneralEntitySizeLimit";
/**
* JDK node count limit in entities that limits the total number of nodes
* in all of entity references.
*/
public static final String JDK_ENTITY_REPLACEMENT_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "entityReplacementLimit";
/**
* JDK maximum parameter entity size limit
*/
public static final String JDK_PARAMETER_ENTITY_SIZE_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "maxParameterEntitySizeLimit";
/**
* JDK maximum XML name limit
*/
public static final String JDK_XML_NAME_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "maxXMLNameLimit";
/**
* JDK maxElementDepth limit
*/
public static final String JDK_MAX_ELEMENT_DEPTH =
ORACLE_JAXP_PROPERTY_PREFIX + "maxElementDepth";
/**
* JDK property to allow printing out information from the limit analyzer
*/
public static final String JDK_ENTITY_COUNT_INFO =
ORACLE_JAXP_PROPERTY_PREFIX + "getEntityCountInfo";
//
// Implementation limits: API properties
//
/**
* JDK entity expansion limit; Note that the existing system property
* "entityExpansionLimit" with no prefix is still observed
*/
public static final String SP_ENTITY_EXPANSION_LIMIT = "jdk.xml.entityExpansionLimit";
/**
* JDK element attribute limit; Note that the existing system property
* "elementAttributeLimit" with no prefix is still observed
*/
public static final String SP_ELEMENT_ATTRIBUTE_LIMIT = "jdk.xml.elementAttributeLimit";
/**
* JDK maxOccur limit; Note that the existing system property
* "maxOccurLimit" with no prefix is still observed
*/
public static final String SP_MAX_OCCUR_LIMIT = "jdk.xml.maxOccurLimit";
/**
* JDK total entity size limit
*/
public static final String SP_TOTAL_ENTITY_SIZE_LIMIT = "jdk.xml.totalEntitySizeLimit";
/**
* JDK maximum general entity size limit
*/
public static final String SP_GENERAL_ENTITY_SIZE_LIMIT = "jdk.xml.maxGeneralEntitySizeLimit";
/**
* JDK node count limit in entities that limits the total number of nodes
* in all of entity references.
*/
public static final String SP_ENTITY_REPLACEMENT_LIMIT = "jdk.xml.entityReplacementLimit";
/**
* JDK maximum parameter entity size limit
*/
public static final String SP_PARAMETER_ENTITY_SIZE_LIMIT = "jdk.xml.maxParameterEntitySizeLimit";
/**
* JDK maximum XML name limit
*/
public static final String SP_XML_NAME_LIMIT = "jdk.xml.maxXMLNameLimit";
/**
* JDK maxElementDepth limit
*/
public static final String SP_MAX_ELEMENT_DEPTH = "jdk.xml.maxElementDepth";
//legacy System Properties
public final static String ENTITY_EXPANSION_LIMIT = "entityExpansionLimit";
public static final String ELEMENT_ATTRIBUTE_LIMIT = "elementAttributeLimit" ;
public final static String MAX_OCCUR_LIMIT = "maxOccurLimit";
/**
* A string "yes" that can be used for properties such as getEntityCountInfo
*/
public static final String JDK_YES = "yes";
//
// DOM features
//

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, 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
@ -34,6 +34,8 @@ import javax.xml.catalog.CatalogFeatures;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLResolver;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty;
import jdk.xml.internal.JdkXmlUtils;
/**
@ -59,7 +61,7 @@ public class PropertyManager {
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
HashMap<String, Object> supportedProps = new HashMap<>();
@ -144,7 +146,7 @@ public class PropertyManager {
supportedProps.put(f.getPropertyName(), null);
}
supportedProps.put(JdkXmlUtils.CDATA_CHUNK_SIZE, JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT);
supportedProps.put(JdkConstants.CDATA_CHUNK_SIZE, JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
}
private void initWriterProps(){
@ -166,7 +168,10 @@ public class PropertyManager {
}
public Object getProperty(String property){
return supportedProps.get(property);
/** Check to see if the property is managed by the security manager **/
String propertyValue = (fSecurityManager != null) ?
fSecurityManager.getLimitAsString(property) : null;
return propertyValue != null ? propertyValue : supportedProps.get(property);
}
public void setProperty(String property, Object value){
@ -198,19 +203,19 @@ public class PropertyManager {
supportedProps.put(Constants.SECURITY_MANAGER, fSecurityManager);
return;
}
if (property.equals(Constants.XML_SECURITY_PROPERTY_MANAGER)) {
if (property.equals(JdkConstants.XML_SECURITY_PROPERTY_MANAGER)) {
if (value == null) {
fSecurityPropertyMgr = new XMLSecurityPropertyManager();
} else {
fSecurityPropertyMgr = (XMLSecurityPropertyManager)value;
}
supportedProps.put(Constants.XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
supportedProps.put(JdkConstants.XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
return;
}
//check if the property is managed by security manager
if (fSecurityManager == null ||
!fSecurityManager.setLimit(property, XMLSecurityManager.State.APIPROPERTY, value)) {
!fSecurityManager.setLimit(property, JdkProperty.State.APIPROPERTY, value)) {
//check if the property is managed by security property manager
if (fSecurityPropertyMgr == null ||
!fSecurityPropertyMgr.setValue(property, XMLSecurityPropertyManager.State.APIPROPERTY, value)) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
@ -53,6 +53,7 @@ import javax.xml.XMLConstants;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.events.XMLEvent;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
@ -73,7 +74,7 @@ import jdk.xml.internal.SecuritySupport;
* @author Eric Ye, IBM
* @author Sunitha Reddy, SUN Microsystems
*
* @LastModified: Jan 2019
* @LastModified: May 2021
*/
public class XMLDocumentFragmentScannerImpl
extends XMLScanner
@ -169,12 +170,12 @@ public class XMLDocumentFragmentScannerImpl
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
/** access external dtd: file protocol
* For DOM/SAX, the secure feature is set to true by default
*/
final static String EXTERNAL_ACCESS_DEFAULT = Constants.EXTERNAL_ACCESS_DEFAULT;
final static String EXTERNAL_ACCESS_DEFAULT = JdkConstants.EXTERNAL_ACCESS_DEFAULT;
// recognized features and properties
@ -208,7 +209,7 @@ public class XMLDocumentFragmentScannerImpl
JdkXmlUtils.CATALOG_FILES,
JdkXmlUtils.CATALOG_PREFER,
JdkXmlUtils.CATALOG_RESOLVE,
JdkXmlUtils.CDATA_CHUNK_SIZE
JdkConstants.CDATA_CHUNK_SIZE
};
/** Property defaults. */
@ -221,7 +222,7 @@ public class XMLDocumentFragmentScannerImpl
null,
null,
null,
JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT
JdkConstants.CDATA_CHUNK_SIZE_DEFAULT
};
@ -627,8 +628,8 @@ public class XMLDocumentFragmentScannerImpl
fAccessExternalDTD = spm.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
fStrictURI = componentManager.getFeature(STANDARD_URI_CONFORMANT, false);
fChunkSize = JdkXmlUtils.getValue(componentManager.getProperty(JdkXmlUtils.CDATA_CHUNK_SIZE),
JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT);
fChunkSize = JdkXmlUtils.getValue(componentManager.getProperty(JdkConstants.CDATA_CHUNK_SIZE),
JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
resetCommon();
//fEntityManager.test();
@ -674,8 +675,8 @@ public class XMLDocumentFragmentScannerImpl
fAccessExternalDTD = spm.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
fSecurityManager = (XMLSecurityManager)propertyManager.getProperty(Constants.SECURITY_MANAGER);
fChunkSize = JdkXmlUtils.getValue(propertyManager.getProperty(JdkXmlUtils.CDATA_CHUNK_SIZE),
JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT);
fChunkSize = JdkXmlUtils.getValue(propertyManager.getProperty(JdkConstants.CDATA_CHUNK_SIZE),
JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
resetCommon();
} // reset(XMLComponentManager)
@ -2012,7 +2013,7 @@ public class XMLDocumentFragmentScannerImpl
String checkAccess(String systemId, String allowedProtocols) throws IOException {
String baseSystemId = fEntityScanner.getBaseSystemId();
String expandedSystemId = XMLEntityManager.expandSystemId(systemId, baseSystemId, fStrictURI);
return SecuritySupport.checkAccess(expandedSystemId, allowedProtocols, Constants.ACCESS_EXTERNAL_ALL);
return SecuritySupport.checkAccess(expandedSystemId, allowedProtocols, JdkConstants.ACCESS_EXTERNAL_ALL);
}
//

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -58,6 +58,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.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
import org.xml.sax.InputSource;
@ -90,7 +91,7 @@ import org.xml.sax.InputSource;
* @author K.Venugopal SUN Microsystems
* @author Neeraj Bajaj SUN Microsystems
* @author Sunitha Reddy SUN Microsystems
* @LastModified: Apr 2019
* @LastModified: May 2021
*/
public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
@ -178,10 +179,10 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
/** access external dtd: file protocol */
static final String EXTERNAL_ACCESS_DEFAULT = Constants.EXTERNAL_ACCESS_DEFAULT;
static final String EXTERNAL_ACCESS_DEFAULT = JdkConstants.EXTERNAL_ACCESS_DEFAULT;
// recognized features and properties
@ -220,7 +221,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
JdkXmlUtils.CATALOG_FILES,
JdkXmlUtils.CATALOG_PREFER,
JdkXmlUtils.CATALOG_RESOLVE,
JdkXmlUtils.CDATA_CHUNK_SIZE
JdkConstants.CDATA_CHUNK_SIZE
};
/** Property defaults. */
@ -236,7 +237,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
null,
null,
null,
JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT
JdkConstants.CDATA_CHUNK_SIZE_DEFAULT
};
private static final String XMLEntity = "[xml]".intern();
@ -1313,7 +1314,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
if (!fISCreatedByResolver) {
//let the not-LoadExternalDTD or not-SupportDTD process to handle the situation
if (fLoadExternalDTD) {
String accessError = SecuritySupport.checkAccess(expandedSystemId, fAccessExternalDTD, Constants.ACCESS_EXTERNAL_ALL);
String accessError = SecuritySupport.checkAccess(expandedSystemId, fAccessExternalDTD, JdkConstants.ACCESS_EXTERNAL_ALL);
if (accessError != null) {
fErrorReporter.reportError(this.getEntityScanner(),XMLMessageFormatter.XML_DOMAIN,
"AccessExternalEntity",
@ -1630,7 +1631,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
fStaxEntityResolver = (StaxEntityResolverWrapper)componentManager.getProperty(STAX_ENTITY_RESOLVER, null);
fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER, null);
fSecurityManager = (XMLSecurityManager)componentManager.getProperty(SECURITY_MANAGER, null);
entityExpansionIndex = fSecurityManager.getIndex(Constants.JDK_ENTITY_EXPANSION_LIMIT);
entityExpansionIndex = fSecurityManager.getIndex(JdkConstants.SP_ENTITY_EXPANSION_LIMIT);
//StAX Property
fSupportDTD = true;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -75,6 +75,7 @@ import java.util.Map;
import java.util.StringTokenizer;
import java.util.WeakHashMap;
import javax.xml.XMLConstants;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
@ -102,7 +103,7 @@ import org.xml.sax.InputSource;
* @xerces.internal
*
* @author Neil Graham, IBM
* @LastModified: Sep 2017
* @LastModified: May 2021
*/
public class XMLSchemaLoader implements XMLGrammarLoader, XMLComponent, XSElementDeclHelper,
@ -161,7 +162,7 @@ XSLoader, DOMConfiguration {
protected static final String SCHEMA_DV_FACTORY =
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
protected static final String OVERRIDE_PARSER = JdkXmlUtils.OVERRIDE_PARSER;
protected static final String OVERRIDE_PARSER = JdkConstants.OVERRIDE_PARSER;
// recognized features:
private static final String[] RECOGNIZED_FEATURES = {
@ -226,7 +227,7 @@ XSLoader, DOMConfiguration {
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
/** Property identifier: access to external dtd */
public static final String ACCESS_EXTERNAL_DTD = XMLConstants.ACCESS_EXTERNAL_DTD;
@ -253,7 +254,7 @@ XSLoader, DOMConfiguration {
JdkXmlUtils.CATALOG_FILES,
JdkXmlUtils.CATALOG_PREFER,
JdkXmlUtils.CATALOG_RESOLVE,
JdkXmlUtils.CDATA_CHUNK_SIZE
JdkConstants.CDATA_CHUNK_SIZE
};
// Data
@ -283,7 +284,7 @@ XSLoader, DOMConfiguration {
private final CMNodeFactory fNodeFactory = new CMNodeFactory(); //component mgr will be set later
private CMBuilder fCMBuilder;
private XSDDescription fXSDDescription = new XSDDescription();
private String faccessExternalSchema = Constants.EXTERNAL_ACCESS_DEFAULT;
private String faccessExternalSchema = JdkConstants.EXTERNAL_ACCESS_DEFAULT;
private WeakHashMap<Object, SchemaGrammar> fJAXPCache;
private Locale fLocale = Locale.getDefault();
@ -607,7 +608,7 @@ XSLoader, DOMConfiguration {
}
if (desc.isExternal() && !source.isCreatedByResolver()) {
String accessError = SecuritySupport.checkAccess(desc.getExpandedSystemId(), faccessExternalSchema, Constants.ACCESS_EXTERNAL_ALL);
String accessError = SecuritySupport.checkAccess(desc.getExpandedSystemId(), faccessExternalSchema, JdkConstants.ACCESS_EXTERNAL_ALL);
if (accessError != null) {
throw new XNIException(fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
"schema_reference.access",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -87,6 +87,7 @@ import java.util.Map;
import java.util.Stack;
import java.util.Vector;
import javax.xml.XMLConstants;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
/**
@ -111,7 +112,7 @@ import jdk.xml.internal.JdkXmlUtils;
* @author Elena Litani IBM
* @author Andy Clark IBM
* @author Neeraj Bajaj, Sun Microsystems, inc.
* @LastModified: Apr 2020
* @LastModified: May 2021
*/
public class XMLSchemaValidator
implements XMLComponent, XMLDocumentFilter, FieldActivator, RevalidationHandler, XSElementDeclHelper {
@ -263,9 +264,9 @@ public class XMLSchemaValidator
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
protected static final String OVERRIDE_PARSER = JdkXmlUtils.OVERRIDE_PARSER;
protected static final String OVERRIDE_PARSER = JdkConstants.OVERRIDE_PARSER;
protected static final String USE_CATALOG = XMLConstants.USE_CATALOG;
@ -323,7 +324,7 @@ public class XMLSchemaValidator
null,
null,
null,
JdkXmlUtils.OVERRIDE_PARSER_DEFAULT,
JdkConstants.OVERRIDE_PARSER_DEFAULT,
JdkXmlUtils.USE_CATALOG_DEFAULT
};
@ -346,13 +347,13 @@ public class XMLSchemaValidator
JdkXmlUtils.CATALOG_FILES,
JdkXmlUtils.CATALOG_PREFER,
JdkXmlUtils.CATALOG_RESOLVE,
JdkXmlUtils.CDATA_CHUNK_SIZE
JdkConstants.CDATA_CHUNK_SIZE
};
/** Property defaults. */
private static final Object[] PROPERTY_DEFAULTS =
{ null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT };
null, null, null, null, JdkConstants.CDATA_CHUNK_SIZE_DEFAULT };
// this is the number of valuestores of each kind
// we expect an element to have. It's almost

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -50,15 +50,15 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
import java.io.IOException;
import java.util.Locale;
import javax.xml.XMLConstants;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
/**
* @xerces.internal
*
* @author Rahul Srivastava, Sun Microsystems Inc.
*
* @LastModified: Sep 2017
* @LastModified: May 2021
*/
public class SchemaParsingConfig extends BasicParserConfiguration
implements XMLPullParserConfiguration {
@ -305,7 +305,7 @@ public class SchemaParsingConfig extends BasicParserConfiguration
LOAD_EXTERNAL_DTD, NOTIFY_BUILTIN_REFS,
NOTIFY_CHAR_REFS, GENERATE_SYNTHETIC_ANNOTATIONS,
XMLConstants.USE_CATALOG,
JdkXmlUtils.OVERRIDE_PARSER
JdkConstants.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
@ -320,7 +320,7 @@ public class SchemaParsingConfig extends BasicParserConfiguration
fFeatures.put(NOTIFY_CHAR_REFS, Boolean.FALSE);
fFeatures.put(GENERATE_SYNTHETIC_ANNOTATIONS, Boolean.FALSE);
fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
fFeatures.put(JdkConstants.OVERRIDE_PARSER, JdkConstants.OVERRIDE_PARSER_DEFAULT);
// add default recognized properties
final String[] recognizedProperties = {
@ -339,7 +339,7 @@ public class SchemaParsingConfig extends BasicParserConfiguration
JdkXmlUtils.CATALOG_FILES,
JdkXmlUtils.CATALOG_PREFER,
JdkXmlUtils.CATALOG_RESOLVE,
JdkXmlUtils.CDATA_CHUNK_SIZE
JdkConstants.CDATA_CHUNK_SIZE
};
addRecognizedProperties(recognizedProperties);
@ -371,7 +371,7 @@ public class SchemaParsingConfig extends BasicParserConfiguration
fValidationManager = new ValidationManager();
fProperties.put(VALIDATION_MANAGER, fValidationManager);
fProperties.put(JdkXmlUtils.CDATA_CHUNK_SIZE, JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT);
fProperties.put(JdkConstants.CDATA_CHUNK_SIZE, JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
fVersionDetector = new XMLVersionDetector();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -106,6 +106,7 @@ import javax.xml.catalog.CatalogFeatures;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
import org.w3c.dom.Document;
@ -130,7 +131,7 @@ import org.xml.sax.XMLReader;
* @author Neil Graham, IBM
* @author Pavani Mukthipudi, Sun Microsystems
*
* @LastModified: Apr 2019
* @LastModified: May 2021
*/
@SuppressWarnings("deprecation") //org.xml.sax.helpers.XMLReaderFactory
public class XSDHandler {
@ -225,7 +226,7 @@ public class XSDHandler {
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
protected static final boolean DEBUG_NODE_POOL = false;
@ -2214,7 +2215,7 @@ public class XSDHandler {
if ((!schemaSource.isCreatedByResolver()) &&
(referType == XSDDescription.CONTEXT_IMPORT || referType == XSDDescription.CONTEXT_INCLUDE
|| referType == XSDDescription.CONTEXT_REDEFINE)) {
String accessError = SecuritySupport.checkAccess(schemaId, fAccessExternalSchema, Constants.ACCESS_EXTERNAL_ALL);
String accessError = SecuritySupport.checkAccess(schemaId, fAccessExternalSchema, JdkConstants.ACCESS_EXTERNAL_ALL);
if (accessError != null) {
reportSchemaFatalError("schema_reference.access",
new Object[] { SecuritySupport.sanitizePath(schemaId), accessError },
@ -3665,9 +3666,9 @@ public class XSDHandler {
fAccessExternalSchema = fSecurityPropertyMgr.getValue(
XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA);
fOverrideDefaultParser = componentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER);
fSchemaParser.setFeature(JdkXmlUtils.OVERRIDE_PARSER, fOverrideDefaultParser);
fEntityManager.setFeature(JdkXmlUtils.OVERRIDE_PARSER, fOverrideDefaultParser);
fOverrideDefaultParser = componentManager.getFeature(JdkConstants.OVERRIDE_PARSER);
fSchemaParser.setFeature(JdkConstants.OVERRIDE_PARSER, fOverrideDefaultParser);
fEntityManager.setFeature(JdkConstants.OVERRIDE_PARSER, fOverrideDefaultParser);
// Passing the Catalog settings to the parser
fUseCatalog = componentManager.getFeature(XMLConstants.USE_CATALOG);
fSchemaParser.setFeature(XMLConstants.USE_CATALOG, fUseCatalog);
@ -3685,10 +3686,10 @@ public class XSDHandler {
componentManager.getProperty(f.getPropertyName()));
}
fSchemaParser.setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE,
componentManager.getProperty(JdkXmlUtils.CDATA_CHUNK_SIZE));
fEntityManager.setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE,
componentManager.getProperty(JdkXmlUtils.CDATA_CHUNK_SIZE));
fSchemaParser.setProperty(JdkConstants.CDATA_CHUNK_SIZE,
componentManager.getProperty(JdkConstants.CDATA_CHUNK_SIZE));
fEntityManager.setProperty(JdkConstants.CDATA_CHUNK_SIZE,
componentManager.getProperty(JdkConstants.CDATA_CHUNK_SIZE));
} // reset(XMLComponentManager)
@ -4013,8 +4014,7 @@ public class XSDHandler {
","+oldName:currSchema.fTargetNamespace+","+oldName;
int attGroupRefsCount = changeRedefineGroup(processedBaseName, componentType, newName, child, currSchema);
if (attGroupRefsCount > 1) {
reportSchemaError("src-redefine.7.1",
new Object []{attGroupRefsCount}, child);
reportSchemaError("src-redefine.7.1", new Object []{attGroupRefsCount}, child);
}
else if (attGroupRefsCount == 1) {
// return true;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -22,6 +22,8 @@ package com.sun.org.apache.xerces.internal.jaxp;
import com.sun.org.apache.xerces.internal.parsers.DOMParser;
import com.sun.org.apache.xerces.internal.util.SAXMessageFormatter;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
import java.util.HashMap;
import java.util.Map;
import javax.xml.XMLConstants;
@ -29,6 +31,7 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.validation.Schema;
import jdk.xml.internal.JdkProperty;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
@ -36,6 +39,7 @@ import org.xml.sax.SAXNotSupportedException;
/**
* @author Rajiv Mordani
* @author Edwin Goei
* @LastModified: May 2021
*/
public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
/** These are DocumentBuilderFactory attributes not DOM attributes */
@ -49,6 +53,10 @@ public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
*/
private boolean fSecureProcess = true;
// used to verify attributes
XMLSecurityManager fSecurityManager = new XMLSecurityManager(true);
XMLSecurityPropertyManager fSecurityPropertyMgr = new XMLSecurityPropertyManager();
/**
* Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder}
* using the currently configured parameters.
@ -104,6 +112,20 @@ public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
attributes = new HashMap<>();
}
//check if the property is managed by security manager
String pName;
if ((pName = fSecurityManager.find(name)) != null) {
// as the qName is deprecated, let the manager decide whether the
// value shall be changed
fSecurityManager.setLimit(name, JdkProperty.State.APIPROPERTY, value);
attributes.put(pName, fSecurityManager.getLimitAsString(pName));
// no need to create a DocumentBuilderImpl
return;
} else if ((pName = fSecurityPropertyMgr.find(name)) != null) {
attributes.put(pName, value);
return;
}
attributes.put(name, value);
// Test the attribute name by possibly throwing an exception
@ -122,6 +144,15 @@ public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
public Object getAttribute(String name)
throws IllegalArgumentException
{
//check if the property is managed by security manager
String pName;
if ((pName = fSecurityManager.find(name)) != null) {
return attributes.get(pName);
} else if ((pName = fSecurityPropertyMgr.find(name)) != null) {
return attributes.get(pName);
}
// See if it's in the attributes Map
if (attributes != null) {
Object val = attributes.get(name);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -45,6 +45,8 @@ 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 com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
@ -57,6 +59,7 @@ import org.xml.sax.SAXNotSupportedException;
/**
* @author Rajiv Mordani
* @author Edwin Goei
* @LastModified: May 2021
*/
public class DocumentBuilderImpl extends DocumentBuilder
implements JAXPConstants
@ -99,7 +102,7 @@ public class DocumentBuilderImpl extends DocumentBuilder
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
/** property identifier: access external dtd. */
public static final String ACCESS_EXTERNAL_DTD = XMLConstants.ACCESS_EXTERNAL_DTD;
@ -186,9 +189,9 @@ public class DocumentBuilderImpl extends DocumentBuilder
Boolean temp = features.get(XMLConstants.FEATURE_SECURE_PROCESSING);
if (temp != null && temp) {
fSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD,
State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
State.FSP, JdkConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
fSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_SCHEMA,
State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
State.FSP, JdkConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
}
}
}
@ -296,7 +299,7 @@ public class DocumentBuilderImpl extends DocumentBuilder
} else {
//check if the property is managed by security manager
if (fSecurityManager == null ||
!fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
!fSecurityManager.setLimit(name, JdkProperty.State.APIPROPERTY, val)) {
//check if the property is managed by security property manager
if (fSecurityPropertyMgr == null ||
!fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -43,6 +43,8 @@ import java.util.Locale;
import java.util.Map;
import javax.xml.XMLConstants;
import javax.xml.validation.Schema;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.HandlerBase;
@ -61,7 +63,7 @@ import org.xml.sax.helpers.DefaultHandler;
* @author Rajiv Mordani
* @author Edwin Goei
*
* @LastModified: Oct 2017
* @LastModified: May 2021
*/
@SuppressWarnings("deprecation")
public class SAXParserImpl extends javax.xml.parsers.SAXParser
@ -93,7 +95,7 @@ public class SAXParserImpl extends javax.xml.parsers.SAXParser
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
private final JAXPSAXParser xmlReader;
private String schemaLanguage = null; // null means DTD
@ -167,9 +169,9 @@ public class SAXParserImpl extends javax.xml.parsers.SAXParser
Boolean temp = features.get(XMLConstants.FEATURE_SECURE_PROCESSING);
if (temp != null && temp) {
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
XMLSecurityPropertyManager.State.FSP, JdkConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
XMLSecurityPropertyManager.State.FSP, JdkConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
}
}
}
@ -562,7 +564,7 @@ public class SAXParserImpl extends javax.xml.parsers.SAXParser
//check if the property is managed by security manager
if (fSecurityManager == null ||
!fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, value)) {
!fSecurityManager.setLimit(name, JdkProperty.State.APIPROPERTY, value)) {
//check if the property is managed by security property manager
if (fSecurityPropertyMgr == null ||
!fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, value)) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -45,6 +45,7 @@ import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
@ -62,7 +63,7 @@ import org.xml.sax.SAXException;
* <p>A validator helper for <code>DOMSource</code>s.</p>
*
* @author Michael Glavassevich, IBM
* @LastModified: Oct 2017
* @LastModified: May 2021
*/
final class DOMValidatorHelper implements ValidatorHelper, EntityState {
@ -382,7 +383,7 @@ final class DOMValidatorHelper implements ValidatorHelper, EntityState {
if (result.getNode() == null) {
try {
DocumentBuilderFactory factory = JdkXmlUtils.getDOMFactory(
fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
fComponentManager.getFeature(JdkConstants.OVERRIDE_PARSER));
DocumentBuilder builder = factory.newDocumentBuilder();
result.setNode(builder.newDocument());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, 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
@ -25,25 +25,21 @@
package com.sun.org.apache.xerces.internal.jaxp.validation;
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
import java.io.IOException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stax.StAXResult;
import javax.xml.transform.stax.StAXSource;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
import org.xml.sax.SAXException;
/**
@ -73,7 +69,7 @@ public final class StAXValidatorHelper implements ValidatorHelper {
if( identityTransformer1==null ) {
try {
SAXTransformerFactory tf = JdkXmlUtils.getSAXTransformFactory(
fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
fComponentManager.getFeature(JdkConstants.OVERRIDE_PARSER));
XMLSecurityManager securityManager =
(XMLSecurityManager)fComponentManager.getProperty(Constants.SECURITY_MANAGER);
@ -85,7 +81,7 @@ public final class StAXValidatorHelper implements ValidatorHelper {
}
}
if (securityManager.printEntityCountInfo()) {
tf.setAttribute(Constants.JDK_ENTITY_COUNT_INFO, "yes");
tf.setAttribute(JdkConstants.JDK_DEBUG_LIMIT, "yes");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -41,6 +41,7 @@ import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import org.xml.sax.SAXException;
@ -51,6 +52,7 @@ import org.xml.sax.SAXException;
*
* @author Michael Glavassevich, IBM
* @author Sunitha Reddy
* @LastModified: May 2021
*/
final class StreamValidatorHelper implements ValidatorHelper {
@ -139,7 +141,7 @@ final class StreamValidatorHelper implements ValidatorHelper {
if (result != null) {
try {
SAXTransformerFactory tf = JdkXmlUtils.getSAXTransformFactory(
fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
fComponentManager.getFeature(JdkConstants.OVERRIDE_PARSER));
identityTransformerHandler = tf.newTransformerHandler();
} catch (TransformerConfigurationException e) {
@ -207,16 +209,16 @@ final class StreamValidatorHelper implements ValidatorHelper {
config.setDocumentHandler(fSchemaValidator);
config.setDTDHandler(null);
config.setDTDContentModelHandler(null);
config.setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER,
fComponentManager.getProperty(Constants.XML_SECURITY_PROPERTY_MANAGER));
config.setProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER,
fComponentManager.getProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER));
config.setProperty(Constants.SECURITY_MANAGER,
fComponentManager.getProperty(Constants.SECURITY_MANAGER));
// Passing on the CatalogFeatures settings
JdkXmlUtils.catalogFeaturesConfig2Config(fComponentManager, config);
config.setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE,
fComponentManager.getProperty(JdkXmlUtils.CDATA_CHUNK_SIZE));
config.setProperty(JdkConstants.CDATA_CHUNK_SIZE,
fComponentManager.getProperty(JdkConstants.CDATA_CHUNK_SIZE));
fConfiguration = new SoftReference<>(config);
return config;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -70,6 +70,7 @@ import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.validation.TypeInfoProvider;
import javax.xml.validation.ValidatorHandler;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
import org.w3c.dom.TypeInfo;
import org.w3c.dom.ls.LSInput;
@ -94,7 +95,7 @@ import org.xml.sax.ext.EntityResolver2;
* @author Kohsuke Kawaguchi
* @author Michael Glavassevich, IBM
*
* @LastModified: Oct 2017
* @LastModified: May 2021
*/
final class ValidatorHandlerImpl extends ValidatorHandler implements
DTDHandler, EntityState, PSVIProvider, ValidatorHelper, XMLDocumentHandler {
@ -137,7 +138,7 @@ final class ValidatorHandlerImpl extends ValidatorHandler implements
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
//
// Data
@ -675,7 +676,7 @@ final class ValidatorHandlerImpl extends ValidatorHandler implements
XMLReader reader = saxSource.getXMLReader();
if( reader==null ) {
// create one now
reader = JdkXmlUtils.getXMLReader(fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER),
reader = JdkXmlUtils.getXMLReader(fComponentManager.getFeature(JdkConstants.OVERRIDE_PARSER),
fComponentManager.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
try {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -51,6 +51,9 @@ import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty;
import jdk.xml.internal.JdkProperty.ImplPropMap;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import org.w3c.dom.Node;
@ -66,6 +69,8 @@ import org.xml.sax.SAXParseException;
* {@link SchemaFactory} for XML Schema.
*
* @author Kohsuke Kawaguchi
*
* @LastModified: May 2021
*/
public final class XMLSchemaFactory extends SchemaFactory {
@ -94,7 +99,7 @@ public final class XMLSchemaFactory extends SchemaFactory {
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
//
@ -161,11 +166,11 @@ public final class XMLSchemaFactory extends SchemaFactory {
fXMLSchemaLoader.setProperty(f.getPropertyName(), null);
}
fXMLSchemaLoader.setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE, JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT);
fXMLSchemaLoader.setProperty(JdkConstants.CDATA_CHUNK_SIZE, JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
fXmlFeatures = new JdkXmlFeatures(fSecurityManager.isSecureProcessing());
fOverrideDefaultParser = fXmlFeatures.getFeature(
JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
fXMLSchemaLoader.setFeature(JdkXmlUtils.OVERRIDE_PARSER, fOverrideDefaultParser);
fXMLSchemaLoader.setFeature(JdkConstants.OVERRIDE_PARSER, fOverrideDefaultParser);
}
/**
@ -400,7 +405,11 @@ public final class XMLSchemaFactory extends SchemaFactory {
"property-not-supported", new Object [] {name}));
}
try {
return fXMLSchemaLoader.getProperty(name);
/** Check to see if the property is managed by the security manager **/
String propertyValue = (fSecurityManager != null) ?
fSecurityManager.getLimitAsString(name) : null;
return propertyValue != null ? propertyValue :
fXMLSchemaLoader.getProperty(name);
}
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
@ -417,6 +426,7 @@ public final class XMLSchemaFactory extends SchemaFactory {
}
}
@SuppressWarnings("deprecation")
public void setFeature(String name, boolean value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name == null) {
@ -443,9 +453,9 @@ public final class XMLSchemaFactory extends SchemaFactory {
fSecurityManager.setSecureProcessing(value);
if (value) {
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
XMLSecurityPropertyManager.State.FSP, JdkConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
XMLSecurityPropertyManager.State.FSP, JdkConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
}
fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
@ -455,16 +465,15 @@ public final class XMLSchemaFactory extends SchemaFactory {
fUseGrammarPoolOnly = value;
return;
}
else if (name.equals(Constants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
else if (name.equals(JdkConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
//in secure mode, let useServicesMechanism be determined by the constructor
if (System.getSecurityManager() != null)
return;
}
if ((fXmlFeatures != null) &&
fXmlFeatures.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) {
if (name.equals(JdkXmlUtils.OVERRIDE_PARSER)
|| name.equals(Constants.ORACLE_FEATURE_SERVICE_MECHANISM)
fXmlFeatures.setFeature(name, JdkProperty.State.APIPROPERTY, value)) {
if ((ImplPropMap.OVERRIDEPARSER.is(name))
|| name.equals(JdkXmlUtils.USE_CATALOG)) {
fXMLSchemaLoader.setFeature(name, value);
}
@ -498,13 +507,13 @@ public final class XMLSchemaFactory extends SchemaFactory {
fSecurityManager = XMLSecurityManager.convert(object, fSecurityManager);
fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
return;
} else if (name.equals(Constants.XML_SECURITY_PROPERTY_MANAGER)) {
} else if (name.equals(JdkConstants.XML_SECURITY_PROPERTY_MANAGER)) {
if (object == null) {
fSecurityPropertyMgr = new XMLSecurityPropertyManager();
} else {
fSecurityPropertyMgr = (XMLSecurityPropertyManager)object;
}
fXMLSchemaLoader.setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
fXMLSchemaLoader.setProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
return;
}
else if (name.equals(XMLGRAMMAR_POOL)) {
@ -515,7 +524,7 @@ public final class XMLSchemaFactory extends SchemaFactory {
try {
//check if the property is managed by security manager
if (fSecurityManager == null ||
!fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, object)) {
!fSecurityManager.setLimit(name, JdkProperty.State.APIPROPERTY, object)) {
//check if the property is managed by security property manager
if (fSecurityPropertyMgr == null ||
!fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, object)) {
@ -542,7 +551,7 @@ public final class XMLSchemaFactory extends SchemaFactory {
private void propagateFeatures(AbstractXMLSchema schema) {
schema.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,
(fSecurityManager != null && fSecurityManager.isSecureProcessing()));
schema.setFeature(JdkXmlUtils.OVERRIDE_PARSER, fOverrideDefaultParser);
schema.setFeature(JdkConstants.OVERRIDE_PARSER, fOverrideDefaultParser);
String[] features = fXMLSchemaLoader.getRecognizedFeatures();
for (int i = 0; i < features.length; ++i) {
boolean state = fXMLSchemaLoader.getFeature(features[i]);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -48,6 +48,8 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
import javax.xml.catalog.CatalogFeatures;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty;
import jdk.xml.internal.JdkXmlUtils;
import org.w3c.dom.ls.LSResourceResolver;
import org.xml.sax.ErrorHandler;
@ -56,6 +58,7 @@ import org.xml.sax.ErrorHandler;
* <p>An implementation of XMLComponentManager for a schema validator.</p>
*
* @author Michael Glavassevich, IBM
* @LastModified: May 2021
*/
final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettings implements
XMLComponentManager {
@ -138,7 +141,7 @@ final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettin
/** Property identifier: security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
/** Property identifier: symbol table. */
private static final String SYMBOL_TABLE =
@ -265,7 +268,7 @@ final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettin
SCHEMA_ELEMENT_DEFAULT,
SCHEMA_AUGMENT_PSVI,
XMLConstants.USE_CATALOG,
JdkXmlUtils.OVERRIDE_PARSER
JdkConstants.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
fFeatures.put(DISALLOW_DOCTYPE_DECL_FEATURE, Boolean.FALSE);
@ -273,7 +276,7 @@ final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettin
fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.FALSE);
fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE);
fFeatures.put(XMLConstants.USE_CATALOG, grammarContainer.getFeature(XMLConstants.USE_CATALOG));
fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, grammarContainer.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
fFeatures.put(JdkConstants.OVERRIDE_PARSER, grammarContainer.getFeature(JdkConstants.OVERRIDE_PARSER));
addRecognizedParamsAndSetDefaults(fEntityManager, grammarContainer);
addRecognizedParamsAndSetDefaults(fErrorReporter, grammarContainer);
@ -307,7 +310,7 @@ final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettin
//pass on properties set on SchemaFactory
fSecurityPropertyMgr = (XMLSecurityPropertyManager)
grammarContainer.getProperty(Constants.XML_SECURITY_PROPERTY_MANAGER);
grammarContainer.getProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER);
setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
//initialize Catalog properties
@ -315,8 +318,8 @@ final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettin
setProperty(f.getPropertyName(), grammarContainer.getProperty(f.getPropertyName()));
}
setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE,
grammarContainer.getProperty(JdkXmlUtils.CDATA_CHUNK_SIZE));
setProperty(JdkConstants.CDATA_CHUNK_SIZE,
grammarContainer.getProperty(JdkConstants.CDATA_CHUNK_SIZE));
}
/**
@ -379,9 +382,9 @@ final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettin
if (value) {
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
XMLSecurityPropertyManager.State.FSP, JdkConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
fSecurityPropertyMgr.setValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
XMLSecurityPropertyManager.State.FSP, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
XMLSecurityPropertyManager.State.FSP, JdkConstants.EXTERNAL_ACCESS_DEFAULT_FSP);
setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
}
@ -456,7 +459,7 @@ final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettin
}
//check if the property is managed by security manager
if (fInitSecurityManager == null ||
!fInitSecurityManager.setLimit(propertyId, XMLSecurityManager.State.APIPROPERTY, value)) {
!fInitSecurityManager.setLimit(propertyId, JdkProperty.State.APIPROPERTY, value)) {
//check if the property is managed by security property manager
if (fSecurityPropertyMgr == null ||
!fSecurityPropertyMgr.setValue(propertyId, XMLSecurityPropertyManager.State.APIPROPERTY, value)) {

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -41,6 +40,8 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException;
import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
import java.io.CharConversionException;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty;
import org.w3c.dom.Node;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
@ -59,7 +60,7 @@ import org.xml.sax.helpers.LocatorImpl;
*
* @author Arnaud Le Hors, IBM
* @author Andy Clark, IBM
*
* @LastModified: May 2021
*/
public class DOMParser
extends AbstractDOMParser {
@ -79,7 +80,7 @@ public class DOMParser
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
// recognized features:
private static final String[] RECOGNIZED_FEATURES = {
@ -546,13 +547,13 @@ public class DOMParser
setProperty0(Constants.SECURITY_MANAGER, securityManager);
return;
}
if (propertyId.equals(Constants.XML_SECURITY_PROPERTY_MANAGER)) {
if (propertyId.equals(JdkConstants.XML_SECURITY_PROPERTY_MANAGER)) {
if (value == null) {
securityPropertyManager = new XMLSecurityPropertyManager();
} else {
securityPropertyManager = (XMLSecurityPropertyManager)value;
}
setProperty0(Constants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
setProperty0(JdkConstants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
return;
}
@ -563,7 +564,7 @@ public class DOMParser
if (securityPropertyManager == null) {
securityPropertyManager = new XMLSecurityPropertyManager();
setProperty0(Constants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
setProperty0(JdkConstants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
}
int index = securityPropertyManager.getIndex(propertyId);
@ -576,7 +577,7 @@ public class DOMParser
securityPropertyManager.setValue(index, XMLSecurityPropertyManager.State.APIPROPERTY, (String)value);
} else {
//check if the property is managed by security manager
if (!securityManager.setLimit(propertyId, XMLSecurityManager.State.APIPROPERTY, value)) {
if (!securityManager.setLimit(propertyId, JdkProperty.State.APIPROPERTY, value)) {
//fall back to the default configuration to handle the property
setProperty0(propertyId, value);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -50,6 +50,7 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
/**
@ -88,7 +89,7 @@ import jdk.xml.internal.JdkXmlUtils;
* @author Arnaud Le Hors, IBM
* @author Andy Clark, IBM
* @author Neil Graham, IBM
*
* @LastModified: May 2021
*/
public class DTDConfiguration
extends BasicParserConfiguration
@ -188,7 +189,7 @@ public class DTDConfiguration
/** Property identifier: Security property manager. */
protected static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
/** Property identifier: Security manager. */
private static final String SECURITY_MANAGER = Constants.SECURITY_MANAGER;
@ -311,7 +312,7 @@ public class DTDConfiguration
//NOTIFY_CHAR_REFS, // from XMLDocumentFragmentScannerImpl
//WARN_ON_DUPLICATE_ENTITYDEF, // from XMLEntityManager
XMLConstants.USE_CATALOG,
JdkXmlUtils.OVERRIDE_PARSER
JdkConstants.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
@ -325,7 +326,7 @@ public class DTDConfiguration
//setFeature(NOTIFY_CHAR_REFS, false); // from XMLDocumentFragmentScannerImpl
//setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false); // from XMLEntityManager
fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
fFeatures.put(JdkConstants.OVERRIDE_PARSER, JdkConstants.OVERRIDE_PARSER_DEFAULT);
// add default recognized properties
final String[] recognizedProperties = {
@ -348,7 +349,7 @@ public class DTDConfiguration
JdkXmlUtils.CATALOG_FILES,
JdkXmlUtils.CATALOG_PREFER,
JdkXmlUtils.CATALOG_RESOLVE,
JdkXmlUtils.CDATA_CHUNK_SIZE
JdkConstants.CDATA_CHUNK_SIZE
};
addRecognizedProperties(recognizedProperties);
@ -433,7 +434,7 @@ public class DTDConfiguration
setProperty(f.getPropertyName(), null);
}
setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE, JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT);
setProperty(JdkConstants.CDATA_CHUNK_SIZE, JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
} // <init>(SymbolTable,XMLGrammarPool)
//

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -49,6 +49,7 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
/**
@ -62,6 +63,7 @@ import jdk.xml.internal.JdkXmlUtils;
* include the replacement text of internal entities, and supply default attribute values".
*
* @author Elena Litani, IBM
* @LastModified: May 2021
*/
public class NonValidatingConfiguration
extends BasicParserConfiguration
@ -162,7 +164,7 @@ public class NonValidatingConfiguration
/** Property identifier: Security property manager. */
protected static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
/** Property identifier: Security manager. */
private static final String SECURITY_MANAGER = Constants.SECURITY_MANAGER;
@ -295,7 +297,7 @@ public class NonValidatingConfiguration
//NOTIFY_CHAR_REFS, // from XMLDocumentFragmentScannerImpl
//WARN_ON_DUPLICATE_ENTITYDEF // from XMLEntityManager
XMLConstants.USE_CATALOG,
JdkXmlUtils.OVERRIDE_PARSER
JdkConstants.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
@ -311,7 +313,7 @@ public class NonValidatingConfiguration
//setFeature(NOTIFY_CHAR_REFS, false); // from XMLDocumentFragmentScannerImpl
//setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false); // from XMLEntityManager
fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
fFeatures.put(JdkConstants.OVERRIDE_PARSER, JdkConstants.OVERRIDE_PARSER_DEFAULT);
// add default recognized properties
final String[] recognizedProperties = {
@ -331,7 +333,7 @@ public class NonValidatingConfiguration
JdkXmlUtils.CATALOG_FILES,
JdkXmlUtils.CATALOG_PREFER,
JdkXmlUtils.CATALOG_RESOLVE,
JdkXmlUtils.CDATA_CHUNK_SIZE
JdkConstants.CDATA_CHUNK_SIZE
};
addRecognizedProperties(recognizedProperties);
@ -395,7 +397,7 @@ public class NonValidatingConfiguration
setProperty(f.getPropertyName(), null);
}
setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE, JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT);
setProperty(JdkConstants.CDATA_CHUNK_SIZE, JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
} // <init>(SymbolTable,XMLGrammarPool)
//

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -27,6 +26,8 @@ import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
@ -38,6 +39,7 @@ import org.xml.sax.SAXNotSupportedException;
* @author Arnaud Le Hors, IBM
* @author Andy Clark, IBM
*
* @LastModified: May 2021
*/
public class SAXParser
extends AbstractSAXParser {
@ -140,13 +142,13 @@ public class SAXParser
super.setProperty(Constants.SECURITY_MANAGER, securityManager);
return;
}
if (name.equals(Constants.XML_SECURITY_PROPERTY_MANAGER)) {
if (name.equals(JdkConstants.XML_SECURITY_PROPERTY_MANAGER)) {
if (value == null) {
securityPropertyManager = new XMLSecurityPropertyManager();
} else {
securityPropertyManager = (XMLSecurityPropertyManager)value;
}
super.setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
super.setProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
return;
}
@ -157,7 +159,7 @@ public class SAXParser
if (securityPropertyManager == null) {
securityPropertyManager = new XMLSecurityPropertyManager();
super.setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
super.setProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
}
int index = securityPropertyManager.getIndex(name);
@ -170,7 +172,7 @@ public class SAXParser
securityPropertyManager.setValue(index, XMLSecurityPropertyManager.State.APIPROPERTY, (String)value);
} else {
//check if the property is managed by security manager
if (!securityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, value)) {
if (!securityManager.setLimit(name, JdkProperty.State.APIPROPERTY, value)) {
//fall back to the default configuration to handle the property
super.setProperty(name, value);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -68,6 +68,7 @@ import java.util.List;
import java.util.Locale;
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
/**
@ -77,7 +78,7 @@ import jdk.xml.internal.JdkXmlUtils;
* @author Neil Graham, IBM
* @author Michael Glavassevich, IBM
*
* @LastModified: Oct 2017
* @LastModified: May 2021
*/
public class XML11Configuration extends ParserConfigurationSettings
implements XMLPullParserConfiguration, XML11Configurable {
@ -295,7 +296,7 @@ public class XML11Configuration extends ParserConfigurationSettings
/** Property identifier: Security property manager. */
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
/** Property identifier: Security manager. */
private static final String SECURITY_MANAGER = Constants.SECURITY_MANAGER;
@ -508,8 +509,8 @@ public class XML11Configuration extends ParserConfigurationSettings
PARSER_SETTINGS,
XMLConstants.FEATURE_SECURE_PROCESSING,
XMLConstants.USE_CATALOG,
JdkXmlUtils.RESET_SYMBOL_TABLE,
JdkXmlUtils.OVERRIDE_PARSER
JdkConstants.RESET_SYMBOL_TABLE,
JdkConstants.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
// set state for default features
@ -535,8 +536,8 @@ public class XML11Configuration extends ParserConfigurationSettings
fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
fFeatures.put(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
fFeatures.put(JdkXmlUtils.RESET_SYMBOL_TABLE, JdkXmlUtils.RESET_SYMBOL_TABLE_DEFAULT);
fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
fFeatures.put(JdkConstants.RESET_SYMBOL_TABLE, JdkConstants.RESET_SYMBOL_TABLE_DEFAULT);
fFeatures.put(JdkConstants.OVERRIDE_PARSER, JdkConstants.OVERRIDE_PARSER_DEFAULT);
// add default recognized properties
final String[] recognizedProperties =
@ -573,7 +574,7 @@ public class XML11Configuration extends ParserConfigurationSettings
JdkXmlUtils.CATALOG_FILES,
JdkXmlUtils.CATALOG_PREFER,
JdkXmlUtils.CATALOG_RESOLVE,
JdkXmlUtils.CDATA_CHUNK_SIZE
JdkConstants.CDATA_CHUNK_SIZE
};
addRecognizedProperties(recognizedProperties);
@ -644,7 +645,7 @@ public class XML11Configuration extends ParserConfigurationSettings
fProperties.put(f.getPropertyName(), null);
}
setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE, JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT);
setProperty(JdkConstants.CDATA_CHUNK_SIZE, JdkConstants.CDATA_CHUNK_SIZE_DEFAULT);
fConfigUpdated = false;
} // <init>(SymbolTable,XMLGrammarPool)
@ -1582,7 +1583,7 @@ public class XML11Configuration extends ParserConfigurationSettings
* and RESET_SYMBOL_TABLE feature is set to true
*/
private void resetSymbolTable() {
if (fFeatures.get(JdkXmlUtils.RESET_SYMBOL_TABLE) && !fSymbolTableProvided) {
if (fFeatures.get(JdkConstants.RESET_SYMBOL_TABLE) && !fSymbolTableProvided) {
if (fSymbolTableJustInitialized) {
// Skip symbol table reallocation for the first parsing process
fSymbolTableJustInitialized = false;

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -29,6 +28,7 @@ import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
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 org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXNotRecognizedException;
@ -49,7 +49,7 @@ import org.xml.sax.SAXNotRecognizedException;
*
* @author Arnaud Le Hors, IBM
* @author Andy Clark, IBM
*
* @LastModified: May 2021
*/
public abstract class XMLParser {
@ -134,7 +134,7 @@ public abstract class XMLParser {
}
if (securityPropertyManager == null) {
securityPropertyManager = new XMLSecurityPropertyManager();
fConfiguration.setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
fConfiguration.setProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
}
reset();

View File

@ -1,8 +1,7 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@ -20,156 +19,167 @@
*/
package com.sun.org.apache.xerces.internal.util;
import com.sun.org.apache.xerces.internal.impl.Constants;
import jdk.xml.internal.JdkConstants;
/**
* This class is a container for parser settings that relate to
* security, or more specifically, it is intended to be used to prevent denial-of-service
* attacks from being launched against a system running Xerces.
* Any component that is aware of a denial-of-service attack that can arise
* from its processing of a certain kind of document may query its Component Manager
* for the property (http://apache.org/xml/properties/security-manager)
* whose value will be an instance of this class.
* If no value has been set for the property, the component should proceed in the "usual" (spec-compliant)
* manner. If a value has been set, then it must be the case that the component in
* question needs to know what method of this class to query. This class
* will provide defaults for all known security issues, but will also provide
* setters so that those values can be tailored by applications that care.
*
* @author Neil Graham, IBM
* This class is a container for parser settings that relate to security, or
* more specifically, it is intended to be used to prevent denial-of-service
* attacks from being launched against a system running Xerces. Any component
* that is aware of a denial-of-service attack that can arise from its
* processing of a certain kind of document may query its Component Manager for
* the property (http://apache.org/xml/properties/security-manager) whose value
* will be an instance of this class. If no value has been set for the property,
* the component should proceed in the "usual" (spec-compliant) manner. If a
* value has been set, then it must be the case that the component in question
* needs to know what method of this class to query. This class will provide
* defaults for all known security issues, but will also provide setters so that
* those values can be tailored by applications that care.
*
* @author Neil Graham, IBM
* @LastModified: May 2021
*/
public final class SecurityManager {
//
// Constants
//
// default value for entity expansion limit
private final static int DEFAULT_ENTITY_EXPANSION_LIMIT = 64000;
/** Default value of number of nodes created. **/
/**
* Default value of number of nodes created. *
*/
private final static int DEFAULT_MAX_OCCUR_NODE_LIMIT = 5000;
//
// Data
//
private final static int DEFAULT_ELEMENT_ATTRIBUTE_LIMIT = 10000;
private final static int DEFAULT_ELEMENT_ATTRIBUTE_LIMIT = 10000;
/** Entity expansion limit. **/
/**
* Entity expansion limit. *
*/
private int entityExpansionLimit;
/** W3C XML Schema maxOccurs limit. **/
/**
* W3C XML Schema maxOccurs limit. *
*/
private int maxOccurLimit;
private int fElementAttributeLimit;
private int fElementAttributeLimit;
// default constructor. Establishes default values for
// all known security holes.
/**
* Default constructor. Establishes default values
* for known security vulnerabilities.
* Default constructor. Establishes default values for known security
* vulnerabilities.
*/
public SecurityManager() {
entityExpansionLimit = DEFAULT_ENTITY_EXPANSION_LIMIT;
maxOccurLimit = DEFAULT_MAX_OCCUR_NODE_LIMIT ;
fElementAttributeLimit = DEFAULT_ELEMENT_ATTRIBUTE_LIMIT;
//We are reading system properties only once ,
//at the time of creation of this object ,
readSystemProperties();
maxOccurLimit = DEFAULT_MAX_OCCUR_NODE_LIMIT;
fElementAttributeLimit = DEFAULT_ELEMENT_ATTRIBUTE_LIMIT;
//We are reading system properties only once ,
//at the time of creation of this object ,
readSystemProperties();
}
/**
* <p>Sets the number of entity expansions that the
* parser should permit in a document.</p>
* <p>
* Sets the number of entity expansions that the parser should permit in a
* document.</p>
*
* @param limit the number of entity expansions
* permitted in a document
* @param limit the number of entity expansions permitted in a document
*/
public void setEntityExpansionLimit(int limit) {
entityExpansionLimit = limit;
}
/**
* <p>Returns the number of entity expansions
* that the parser permits in a document.</p>
* <p>
* Returns the number of entity expansions that the parser permits in a
* document.</p>
*
* @return the number of entity expansions
* permitted in a document
* @return the number of entity expansions permitted in a document
*/
public int getEntityExpansionLimit() {
return entityExpansionLimit;
}
/**
* <p>Sets the limit of the number of content model nodes
* that may be created when building a grammar for a W3C
* XML Schema that contains maxOccurs attributes with values
* other than "unbounded".</p>
* <p>
* Sets the limit of the number of content model nodes that may be created
* when building a grammar for a W3C XML Schema that contains maxOccurs
* attributes with values other than "unbounded".</p>
*
* @param limit the maximum value for maxOccurs other
* than "unbounded"
* @param limit the maximum value for maxOccurs other than "unbounded"
*/
public void setMaxOccurNodeLimit(int limit){
public void setMaxOccurNodeLimit(int limit) {
maxOccurLimit = limit;
}
/**
* <p>Returns the limit of the number of content model nodes
* that may be created when building a grammar for a W3C
* XML Schema that contains maxOccurs attributes with values
* other than "unbounded".</p>
* <p>
* Returns the limit of the number of content model nodes that may be
* created when building a grammar for a W3C XML Schema that contains
* maxOccurs attributes with values other than "unbounded".</p>
*
* @return the maximum value for maxOccurs other
* than "unbounded"
* @return the maximum value for maxOccurs other than "unbounded"
*/
public int getMaxOccurNodeLimit(){
public int getMaxOccurNodeLimit() {
return maxOccurLimit;
}
public int getElementAttrLimit(){
return fElementAttributeLimit;
public int getElementAttrLimit() {
return fElementAttributeLimit;
}
public void setElementAttrLimit(int limit) {
fElementAttributeLimit = limit;
}
private void readSystemProperties() {
try {
String value = System.getProperty(JdkConstants.ENTITY_EXPANSION_LIMIT);
if (value != null && !value.equals("")) {
entityExpansionLimit = Integer.parseInt(value);
if (entityExpansionLimit < 0) {
entityExpansionLimit = DEFAULT_ENTITY_EXPANSION_LIMIT;
}
} else {
entityExpansionLimit = DEFAULT_ENTITY_EXPANSION_LIMIT;
}
} catch (Exception ex) {
}
public void setElementAttrLimit(int limit){
fElementAttributeLimit = limit;
try {
String value = System.getProperty(JdkConstants.MAX_OCCUR_LIMIT);
if (value != null && !value.equals("")) {
maxOccurLimit = Integer.parseInt(value);
if (maxOccurLimit < 0) {
maxOccurLimit = DEFAULT_MAX_OCCUR_NODE_LIMIT;
}
} else {
maxOccurLimit = DEFAULT_MAX_OCCUR_NODE_LIMIT;
}
} catch (Exception ex) {
}
private void readSystemProperties(){
try {
String value = System.getProperty(Constants.ENTITY_EXPANSION_LIMIT);
if(value != null && !value.equals("")){
entityExpansionLimit = Integer.parseInt(value);
if (entityExpansionLimit < 0)
entityExpansionLimit = DEFAULT_ENTITY_EXPANSION_LIMIT;
}
else
entityExpansionLimit = DEFAULT_ENTITY_EXPANSION_LIMIT;
}catch(Exception ex){}
try {
String value = System.getProperty(Constants.MAX_OCCUR_LIMIT);
if(value != null && !value.equals("")){
maxOccurLimit = Integer.parseInt(value);
if (maxOccurLimit < 0)
maxOccurLimit = DEFAULT_MAX_OCCUR_NODE_LIMIT;
}
else
maxOccurLimit = DEFAULT_MAX_OCCUR_NODE_LIMIT;
}catch(Exception ex){}
try {
String value = System.getProperty(Constants.ELEMENT_ATTRIBUTE_LIMIT);
if(value != null && !value.equals("")){
fElementAttributeLimit = Integer.parseInt(value);
if ( fElementAttributeLimit < 0)
fElementAttributeLimit = DEFAULT_ELEMENT_ATTRIBUTE_LIMIT;
}
else
fElementAttributeLimit = DEFAULT_ELEMENT_ATTRIBUTE_LIMIT;
}catch(Exception ex){}
try {
String value = System.getProperty(JdkConstants.ELEMENT_ATTRIBUTE_LIMIT);
if (value != null && !value.equals("")) {
fElementAttributeLimit = Integer.parseInt(value);
if (fElementAttributeLimit < 0) {
fElementAttributeLimit = DEFAULT_ELEMENT_ATTRIBUTE_LIMIT;
}
} else {
fElementAttributeLimit = DEFAULT_ELEMENT_ATTRIBUTE_LIMIT;
}
} catch (Exception ex) {
}
}
} // class SecurityManager

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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
@ -25,11 +25,11 @@
package com.sun.org.apache.xerces.internal.utils;
import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.Limit;
import java.util.Formatter;
import java.util.HashMap;
import java.util.Map;
import jdk.xml.internal.JdkConstants;
/**
* A helper for analyzing entity expansion limits
@ -43,9 +43,9 @@ public final class XMLLimitAnalyzer {
* Map old property names with the new ones
*/
public static enum NameMap {
ENTITY_EXPANSION_LIMIT(Constants.SP_ENTITY_EXPANSION_LIMIT, Constants.ENTITY_EXPANSION_LIMIT),
MAX_OCCUR_NODE_LIMIT(Constants.SP_MAX_OCCUR_LIMIT, Constants.MAX_OCCUR_LIMIT),
ELEMENT_ATTRIBUTE_LIMIT(Constants.SP_ELEMENT_ATTRIBUTE_LIMIT, Constants.ELEMENT_ATTRIBUTE_LIMIT);
ENTITY_EXPANSION_LIMIT(JdkConstants.SP_ENTITY_EXPANSION_LIMIT, JdkConstants.ENTITY_EXPANSION_LIMIT),
MAX_OCCUR_NODE_LIMIT(JdkConstants.SP_MAX_OCCUR_LIMIT, JdkConstants.MAX_OCCUR_LIMIT),
ELEMENT_ATTRIBUTE_LIMIT(JdkConstants.SP_ELEMENT_ATTRIBUTE_LIMIT, JdkConstants.ELEMENT_ATTRIBUTE_LIMIT);
final String newName;
final String oldName;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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
@ -25,9 +25,11 @@
package com.sun.org.apache.xerces.internal.utils;
import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.util.SecurityManager;
import java.util.concurrent.CopyOnWriteArrayList;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty.State;
import jdk.xml.internal.JdkProperty.ImplPropMap;
import jdk.xml.internal.SecuritySupport;
import org.xml.sax.SAXException;
@ -37,51 +39,30 @@ import org.xml.sax.SAXException;
*/
public final class XMLSecurityManager {
/**
* States of the settings of a property, in the order: default value, value
* set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system
* properties, and jaxp api properties
*/
public static enum State {
//this order reflects the overriding order
DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"),
JAXPDOTPROPERTIES("jaxp.properties"), SYSTEMPROPERTY("system property"),
APIPROPERTY("property");
final String literal;
State(String literal) {
this.literal = literal;
}
String literal() {
return literal;
}
}
/**
* Limits managed by the security manager
*/
@SuppressWarnings("deprecation")
public static enum Limit {
ENTITY_EXPANSION_LIMIT("EntityExpansionLimit",
Constants.JDK_ENTITY_EXPANSION_LIMIT, Constants.SP_ENTITY_EXPANSION_LIMIT, 0, 64000),
JdkConstants.JDK_ENTITY_EXPANSION_LIMIT, JdkConstants.SP_ENTITY_EXPANSION_LIMIT, 0, 64000),
MAX_OCCUR_NODE_LIMIT("MaxOccurLimit",
Constants.JDK_MAX_OCCUR_LIMIT, Constants.SP_MAX_OCCUR_LIMIT, 0, 5000),
JdkConstants.JDK_MAX_OCCUR_LIMIT, JdkConstants.SP_MAX_OCCUR_LIMIT, 0, 5000),
ELEMENT_ATTRIBUTE_LIMIT("ElementAttributeLimit",
Constants.JDK_ELEMENT_ATTRIBUTE_LIMIT, Constants.SP_ELEMENT_ATTRIBUTE_LIMIT, 0, 10000),
JdkConstants.JDK_ELEMENT_ATTRIBUTE_LIMIT, JdkConstants.SP_ELEMENT_ATTRIBUTE_LIMIT, 0, 10000),
TOTAL_ENTITY_SIZE_LIMIT("TotalEntitySizeLimit",
Constants.JDK_TOTAL_ENTITY_SIZE_LIMIT, Constants.SP_TOTAL_ENTITY_SIZE_LIMIT, 0, 50000000),
JdkConstants.JDK_TOTAL_ENTITY_SIZE_LIMIT, JdkConstants.SP_TOTAL_ENTITY_SIZE_LIMIT, 0, 50000000),
GENERAL_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit",
Constants.JDK_GENERAL_ENTITY_SIZE_LIMIT, Constants.SP_GENERAL_ENTITY_SIZE_LIMIT, 0, 0),
JdkConstants.JDK_GENERAL_ENTITY_SIZE_LIMIT, JdkConstants.SP_GENERAL_ENTITY_SIZE_LIMIT, 0, 0),
PARAMETER_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit",
Constants.JDK_PARAMETER_ENTITY_SIZE_LIMIT, Constants.SP_PARAMETER_ENTITY_SIZE_LIMIT, 0, 1000000),
JdkConstants.JDK_PARAMETER_ENTITY_SIZE_LIMIT, JdkConstants.SP_PARAMETER_ENTITY_SIZE_LIMIT, 0, 1000000),
MAX_ELEMENT_DEPTH_LIMIT("MaxElementDepthLimit",
Constants.JDK_MAX_ELEMENT_DEPTH, Constants.SP_MAX_ELEMENT_DEPTH, 0, 0),
JdkConstants.JDK_MAX_ELEMENT_DEPTH, JdkConstants.SP_MAX_ELEMENT_DEPTH, 0, 0),
MAX_NAME_LIMIT("MaxXMLNameLimit",
Constants.JDK_XML_NAME_LIMIT, Constants.SP_XML_NAME_LIMIT, 1000, 1000),
JdkConstants.JDK_XML_NAME_LIMIT, JdkConstants.SP_XML_NAME_LIMIT, 1000, 1000),
ENTITY_REPLACEMENT_LIMIT("EntityReplacementLimit",
Constants.JDK_ENTITY_REPLACEMENT_LIMIT, Constants.SP_ENTITY_REPLACEMENT_LIMIT, 0, 3000000);
JdkConstants.JDK_ENTITY_REPLACEMENT_LIMIT, JdkConstants.SP_ENTITY_REPLACEMENT_LIMIT, 0, 3000000);
final String key;
final String apiProperty;
@ -97,12 +78,36 @@ public final class XMLSecurityManager {
this.secureValue = secureValue;
}
public boolean equalsAPIPropertyName(String propertyName) {
return (propertyName == null) ? false : apiProperty.equals(propertyName);
/**
* Checks whether the specified name is a limit. Checks both the
* property and System Property which is now the new property name.
*
* @param name the specified name
* @return true if there is a match, false otherwise
*/
public boolean is(String name) {
// current spec: new property name == systemProperty
return (systemProperty != null && systemProperty.equals(name)) ||
// current spec: apiProperty is legacy
(apiProperty.equals(name));
}
public boolean equalsSystemPropertyName(String propertyName) {
return (propertyName == null) ? false : systemProperty.equals(propertyName);
/**
* Returns the state of a property name. By the specification as of JDK 17,
* the "jdk.xml." prefixed System property name is also the current API
* name. The URI-based qName is legacy.
*
* @param name the property name
* @return the state of the property name, null if no match
*/
public State getState(String name) {
if (systemProperty != null && systemProperty.equals(name)) {
return State.APIPROPERTY;
} else if (apiProperty.equals(name)) {
//the URI-style qName is legacy
return State.LEGACY_APIPROPERTY;
}
return null;
}
public String key() {
@ -113,7 +118,7 @@ public final class XMLSecurityManager {
return apiProperty;
}
String systemProperty() {
public String systemProperty() {
return systemProperty;
}
@ -131,9 +136,9 @@ public final class XMLSecurityManager {
*/
public static enum NameMap {
ENTITY_EXPANSION_LIMIT(Constants.SP_ENTITY_EXPANSION_LIMIT, Constants.ENTITY_EXPANSION_LIMIT),
MAX_OCCUR_NODE_LIMIT(Constants.SP_MAX_OCCUR_LIMIT, Constants.MAX_OCCUR_LIMIT),
ELEMENT_ATTRIBUTE_LIMIT(Constants.SP_ELEMENT_ATTRIBUTE_LIMIT, Constants.ELEMENT_ATTRIBUTE_LIMIT);
ENTITY_EXPANSION_LIMIT(JdkConstants.SP_ENTITY_EXPANSION_LIMIT, JdkConstants.ENTITY_EXPANSION_LIMIT),
MAX_OCCUR_NODE_LIMIT(JdkConstants.SP_MAX_OCCUR_LIMIT, JdkConstants.MAX_OCCUR_LIMIT),
ELEMENT_ATTRIBUTE_LIMIT(JdkConstants.SP_ELEMENT_ATTRIBUTE_LIMIT, JdkConstants.ELEMENT_ATTRIBUTE_LIMIT);
final String newName;
final String oldName;
@ -228,6 +233,24 @@ public final class XMLSecurityManager {
return secureProcessing;
}
/**
* Finds a limit's new name with the given property name.
* @param propertyName the property name specified
* @return the limit's new name if found, null otherwise
*/
public String find(String propertyName) {
for (Limit limit : Limit.values()) {
if (limit.is(propertyName)) {
// current spec: new property name == systemProperty
return limit.systemProperty();
}
}
//ENTITYCOUNT's new name is qName
if (ImplPropMap.ENTITYCOUNT.is(propertyName)) {
return ImplPropMap.ENTITYCOUNT.qName();
}
return null;
}
/**
* Set limit by property name and state
@ -240,7 +263,11 @@ public final class XMLSecurityManager {
public boolean setLimit(String propertyName, State state, Object value) {
int index = getIndex(propertyName);
if (index > -1) {
setLimit(index, state, value);
State pState = state;
if (index != indexEntityCountInfo && state == State.APIPROPERTY) {
pState = (Limit.values()[index]).getState(propertyName);
}
setLimit(index, pState, value);
return true;
}
return false;
@ -269,8 +296,8 @@ public final class XMLSecurityManager {
printEntityCountInfo = (String)value;
} else {
int temp;
if (Integer.class.isAssignableFrom(value.getClass())) {
temp = ((Integer)value).intValue();
if (value instanceof Integer) {
temp = (Integer)value;
} else {
temp = Integer.parseInt((String) value);
if (temp < 0) {
@ -291,7 +318,7 @@ public final class XMLSecurityManager {
public void setLimit(int index, State state, int value) {
if (index == indexEntityCountInfo) {
//if it's explicitly set, it's treated as yes no matter the value
printEntityCountInfo = Constants.JDK_YES;
printEntityCountInfo = JdkConstants.JDK_YES;
} else {
//only update if it shall override
if (state.compareTo(states[index]) >= 0) {
@ -379,13 +406,14 @@ public final class XMLSecurityManager {
*/
public int getIndex(String propertyName) {
for (Limit limit : Limit.values()) {
if (limit.equalsAPIPropertyName(propertyName)) {
// see JDK-8265248, accept both the URL and jdk.xml as prefix
if (limit.is(propertyName)) {
//internally, ordinal is used as index
return limit.ordinal();
}
}
//special property to return entity count info
if (propertyName.equals(Constants.JDK_ENTITY_COUNT_INFO)) {
if (ImplPropMap.ENTITYCOUNT.is(propertyName)) {
return indexEntityCountInfo;
}
return -1;
@ -464,7 +492,7 @@ public final class XMLSecurityManager {
}
public void debugPrint(XMLLimitAnalyzer limitAnalyzer) {
if (printEntityCountInfo.equals(Constants.JDK_YES)) {
if (printEntityCountInfo.equals(JdkConstants.JDK_YES)) {
limitAnalyzer.debugPrint(this);
}
}
@ -480,7 +508,7 @@ public final class XMLSecurityManager {
}
public boolean printEntityCountInfo() {
return printEntityCountInfo.equals(Constants.JDK_YES);
return printEntityCountInfo.equals(JdkConstants.JDK_YES);
}
/**
@ -557,20 +585,20 @@ public final class XMLSecurityManager {
* @param securityManager an instance of XMLSecurityManager
* @return an instance of the new security manager XMLSecurityManager
*/
static public XMLSecurityManager convert(Object value, XMLSecurityManager securityManager) {
public static XMLSecurityManager convert(Object value, XMLSecurityManager securityManager) {
if (value == null) {
if (securityManager == null) {
securityManager = new XMLSecurityManager(true);
}
return securityManager;
}
if (XMLSecurityManager.class.isAssignableFrom(value.getClass())) {
if (value instanceof XMLSecurityManager) {
return (XMLSecurityManager)value;
} else {
if (securityManager == null) {
securityManager = new XMLSecurityManager(true);
}
if (SecurityManager.class.isAssignableFrom(value.getClass())) {
if (value instanceof SecurityManager) {
SecurityManager origSM = (SecurityManager)value;
securityManager.setLimit(Limit.MAX_OCCUR_NODE_LIMIT, State.APIPROPERTY, origSM.getMaxOccurNodeLimit());
securityManager.setLimit(Limit.ENTITY_EXPANSION_LIMIT, State.APIPROPERTY, origSM.getEntityExpansionLimit());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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
@ -25,8 +25,8 @@
package com.sun.org.apache.xerces.internal.utils;
import com.sun.org.apache.xerces.internal.impl.Constants;
import javax.xml.XMLConstants;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.SecuritySupport;
/**
@ -50,9 +50,9 @@ public final class XMLSecurityPropertyManager {
*/
public static enum Property {
ACCESS_EXTERNAL_DTD(XMLConstants.ACCESS_EXTERNAL_DTD,
Constants.EXTERNAL_ACCESS_DEFAULT),
JdkConstants.EXTERNAL_ACCESS_DEFAULT),
ACCESS_EXTERNAL_SCHEMA(XMLConstants.ACCESS_EXTERNAL_SCHEMA,
Constants.EXTERNAL_ACCESS_DEFAULT);
JdkConstants.EXTERNAL_ACCESS_DEFAULT);
final String name;
final String defaultValue;
@ -66,6 +66,10 @@ public final class XMLSecurityPropertyManager {
return (propertyName == null) ? false : name.equals(propertyName);
}
public String propertyName() {
return name;
}
String defaultValue() {
return defaultValue;
}
@ -92,6 +96,19 @@ public final class XMLSecurityPropertyManager {
readSystemProperties();
}
/**
* Finds the property with the given name.
* @param propertyName the property name specified
* @return the property name if found, null otherwise
*/
public String find(String propertyName) {
for (Property property : Property.values()) {
if (property.equalsName(propertyName)) {
return property.propertyName();
}
}
return null;
}
/**
* Set limit by property name and state
@ -194,9 +211,9 @@ public final class XMLSecurityPropertyManager {
*/
private void readSystemProperties() {
getSystemProperty(Property.ACCESS_EXTERNAL_DTD,
Constants.SP_ACCESS_EXTERNAL_DTD);
JdkConstants.SP_ACCESS_EXTERNAL_DTD);
getSystemProperty(Property.ACCESS_EXTERNAL_SCHEMA,
Constants.SP_ACCESS_EXTERNAL_SCHEMA);
JdkConstants.SP_ACCESS_EXTERNAL_SCHEMA);
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -78,6 +78,7 @@ import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogManager;
import javax.xml.catalog.CatalogResolver;
import javax.xml.transform.Source;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlUtils;
import org.xml.sax.InputSource;
@ -127,7 +128,7 @@ import org.xml.sax.InputSource;
*
*
* @see XIncludeNamespaceSupport
* @LastModified: Nov 2017
* @LastModified: May 2021
*/
public class XIncludeHandler
implements XMLComponent, XMLDocumentFilter, XMLDTDFilter {
@ -246,7 +247,7 @@ public class XIncludeHandler
/** property identifier: XML security property manager. */
protected static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
JdkConstants.XML_SECURITY_PROPERTY_MANAGER;
/** Recognized features. */
private static final String[] RECOGNIZED_FEATURES =
@ -561,7 +562,7 @@ public class XIncludeHandler
}
fSecurityPropertyMgr = (XMLSecurityPropertyManager)
componentManager.getProperty(Constants.XML_SECURITY_PROPERTY_MANAGER);
componentManager.getProperty(JdkConstants.XML_SECURITY_PROPERTY_MANAGER);
//Use Catalog
fUseCatalog = componentManager.getFeature(XMLConstants.USE_CATALOG);

View File

@ -20,7 +20,6 @@
package com.sun.org.apache.xml.internal.serializer;
import com.sun.org.apache.xerces.internal.impl.Constants;
import java.util.Properties;
import javax.xml.transform.OutputKeys;
import jdk.xml.internal.SecuritySupport;
@ -71,7 +70,7 @@ import jdk.xml.internal.SecuritySupport;
* @see SerializerFactory
* @see Method
* @see Serializer
* @LastModified: Feb 2021
* @LastModified: May 2021
*/
public final class OutputPropertiesFactory
{
@ -166,33 +165,6 @@ public final class OutputPropertiesFactory
public static final int S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL_LEN =
S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL.length();
/**
* This non-standard, Oracle-impl only property key is used as if
* OutputKeys.STANDALONE is specified but without writing it out in the declaration;
* It can be used to reverse the change by Xalan patch 1495.
* Since Xalan patch 1495 can cause incompatible behavior, this property is
* added for application to neutralize the effect of Xalan patch 1495
*/
/**
* <p>Is Standalone</p>
*
* <ul>
* <li>
* <code>yes</code> to indicate the output is intended to be used as standalone
* </li>
* <li>
* <code>no</code> has no effect.
* </li>
* </ul>
*/
public static final String ORACLE_IS_STANDALONE = "http://www.oracle.com/xml/is-standalone";
// standardized property, refer to the definition in java.xml module-info
public static final String JDK_IS_STANDALONE = Constants.ORACLE_JAXP_PROPERTY_PREFIX +
"xsltcIsStandalone";
// Corresponding System property
public static final String SP_IS_STANDALONE = "jdk.xml.xsltcIsStandalone";
//************************************************************
//* PRIVATE CONSTANTS
@ -220,8 +192,7 @@ public final class OutputPropertiesFactory
"media-type",
"{http://xml.apache.org/xalan}indent-amount",
"{http://xml.apache.org/xalan}content-handler",
"{http://xml.apache.org/xalan}entities",
JDK_IS_STANDALONE
"{http://xml.apache.org/xalan}entities"
};
private static final String[] PROP_XML_VALUE = {
@ -234,8 +205,7 @@ public final class OutputPropertiesFactory
"text/xml",
"0",
"com.sun.org.apache.xml.internal.serializer.ToXMLStream",
"com/sun/org/apache/xml/internal/serializer/XMLEntities",
"no"
"com/sun/org/apache/xml/internal/serializer/XMLEntities"
};
private static final String[] PROP_HTML = {

View File

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -43,6 +42,7 @@ import org.xml.sax.ext.DeclHandler;
* it is not a public API.
*
* @xsl.usage internal
* @LastModified: May 2021
*/
public interface SerializationHandler
extends
@ -148,8 +148,8 @@ public interface SerializationHandler
/**
* Specify if the output will be treated as a standalone property
* @param isStandalone true if the http://www.oracle.com/xml/is-standalone is set to yes
* @see OutputPropertiesFactory ORACLE_IS_STANDALONE
* @param b true if the property "jdk.xml.xsltcIsStandalone" is set to yes
* @see JdkConstants.SP_XSLTC_IS_Standalone
*/
public void setIsStandalone(boolean b);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -42,7 +42,7 @@ import org.xml.sax.ext.Locator2;
* It contains a number of common fields and methods.
*
* @xsl.usage internal
* @LastModified: Aug 2019
* @LastModified: May 2021
*/
public abstract class SerializerBase
implements SerializationHandler, SerializerConstants
@ -679,9 +679,9 @@ public abstract class SerializerBase
}
/**
* Sets the isStandalone property
* @param isStandalone true if the ORACLE_IS_STANDALONE is set to yes
* @see OutputPropertiesFactory ORACLE_IS_STANDALONE
* Sets the implementation specific property "isStandalone".
* @param isStandalone the value of the property
* @see JdkConstants.SP_XSLTC_IS_Standalone
*/
public void setIsStandalone(boolean isStandalone) {
m_isStandalone = isStandalone;

View File

@ -42,6 +42,7 @@ import javax.xml.transform.ErrorListener;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import jdk.xml.internal.JdkConstants;
import org.w3c.dom.Node;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
@ -52,7 +53,7 @@ import org.xml.sax.SAXException;
* serializers (xml, html, text ...) that write output to a stream.
*
* @xsl.usage internal
* @LastModified: Jan 2021
* @LastModified: May 2021
*/
abstract public class ToStream extends SerializerBase {
@ -494,11 +495,10 @@ abstract public class ToStream extends SerializerBase {
setIndentAmount(Integer.parseInt(val));
} else if (OutputKeys.INDENT.equals(name)) {
m_doIndent = val.endsWith("yes");
} else if ((DOMConstants.NS_IS_STANDALONE)
} else if ((DOMConstants.S_JDK_PROPERTIES_NS + JdkConstants.S_IS_STANDALONE)
.equals(name)) {
m_isStandalone = val.endsWith("yes");
}
break;
case 'l':
if (OutputPropertiesFactory.S_KEY_LINE_SEPARATOR.equals(name)) {

View File

@ -21,13 +21,13 @@
package com.sun.org.apache.xml.internal.serializer.dom3;
import com.sun.org.apache.xerces.internal.impl.Constants;
import static jdk.xml.internal.JdkConstants.S_IS_STANDALONE;
/**
* DOM Constants used by the DOM Level 3 LSSerializer implementation.
*
* @xsl.usage internal
* @LastModified: Jan 2021
* @LastModified: May 2021
*/
public final class DOMConstants {
//
@ -120,25 +120,9 @@ public final class DOMConstants {
// The xerces serializer specific 'omit-xml-declaration' property used in LSSerializer
public static final String S_XML_VERSION = "xml-version";
/**
* Indicates that the serializer should treat the output as a standalone document.
* The JDK specific standalone property controls whether a newline should be
* added after the XML header.
*
* @see similar property ORACLE_IS_STANDALONE in OutputPropertiesFactory.
*/
public static final String S_IS_STANDALONE = "isStandalone";
// Fully-qualified property name with the JDK Impl prefix
public static final String FQ_IS_STANDALONE =
Constants.ORACLE_JAXP_PROPERTY_PREFIX + S_IS_STANDALONE;
// The property with namespace as the internal DOMConfiguration format
public static final String NS_IS_STANDALONE = S_JDK_PROPERTIES_NS + S_IS_STANDALONE;
// Corresponding System property
public static final String SP_IS_STANDALONE = "jdk.xml.isStandalone";
//
public static final String S_XSL_VALUE_ENTITIES = "com/sun/org/apache/xml/internal/serializer/XMLEntities";

View File

@ -21,7 +21,6 @@
package com.sun.org.apache.xml.internal.serializer.dom3;
import com.sun.org.apache.xerces.internal.impl.Constants;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
@ -39,10 +38,13 @@ import com.sun.org.apache.xml.internal.serializer.Encodings;
import com.sun.org.apache.xml.internal.serializer.Serializer;
import com.sun.org.apache.xml.internal.serializer.ToXMLStream;
import com.sun.org.apache.xml.internal.serializer.OutputPropertiesFactory;
import com.sun.org.apache.xml.internal.serializer.SerializerFactory;
import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
import com.sun.org.apache.xml.internal.serializer.utils.Utils;
import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty;
import jdk.xml.internal.JdkProperty.ImplPropMap;
import jdk.xml.internal.JdkProperty.State;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMError;
import org.w3c.dom.DOMErrorHandler;
@ -68,7 +70,7 @@ import org.w3c.dom.ls.LSSerializerFilter;
* @version $Id:
*
* @xsl.usage internal
* @LastModified: Jan 2021
* @LastModified: May 2021
*/
final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
@ -99,6 +101,9 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
// The encoding to use during serialization.
private String fEncoding;
// The isStandalone property
private JdkProperty<Boolean> fIsStandalone;
// ************************************************************************
// DOM Level 3 DOM Configuration parameter names
// ************************************************************************
@ -167,6 +172,7 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
// ************************************************************************
// Recognized parameters for which atleast one value can be set
@SuppressWarnings("deprecation")
private String fRecognizedParameters [] = {
DOMConstants.DOM_CANONICAL_FORM,
DOMConstants.DOM_CDATA_SECTIONS,
@ -187,7 +193,8 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
DOMConstants.DOM_FORMAT_PRETTY_PRINT,
DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS,
DOMConstants.DOM_XMLDECL,
DOMConstants.FQ_IS_STANDALONE,
JdkConstants.FQ_IS_STANDALONE,
JdkConstants.SP_IS_STANDALONE,
DOMConstants.DOM_ERROR_HANDLER
};
@ -358,9 +365,12 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "no");
// JDK specific property isStandalone
String p = SecuritySupport.getJAXPSystemProperty(DOMConstants.SP_IS_STANDALONE);
boolean isStandalone = SecuritySupport.getJAXPSystemProperty(
Boolean.class, JdkConstants.SP_IS_STANDALONE, "false");
fIsStandalone = new JdkProperty<>(ImplPropMap.ISSTANDALONE, isStandalone, State.DEFAULT);
// the system property is true only if it is "true" and false otherwise
if (p != null && p.equals("true")) {
if (isStandalone) {
fFeatures |= IS_STANDALONE;
fDOMConfigProperties.setProperty(DOMConstants.NS_IS_STANDALONE,
DOMConstants.DOM3_EXPLICIT_TRUE);
@ -382,6 +392,7 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
* @param name A String containing the DOMConfiguration parameter name.
* @param value An Object specifying the value of the corresponding parameter.
*/
@SuppressWarnings("deprecation")
public boolean canSetParameter(String name, Object value) {
if (value instanceof Boolean){
if ( name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)
@ -396,7 +407,8 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
|| name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)
|| name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)
|| name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)
|| name.equalsIgnoreCase(DOMConstants.FQ_IS_STANDALONE)){
|| name.equalsIgnoreCase(JdkConstants.FQ_IS_STANDALONE)
|| name.equalsIgnoreCase(JdkConstants.SP_IS_STANDALONE)){
// both values supported
return true;
}
@ -454,7 +466,7 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
return ((fFeatures & PRETTY_PRINT) != 0) ? Boolean.TRUE : Boolean.FALSE;
} else if (name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)) {
return ((fFeatures & XMLDECL) != 0) ? Boolean.TRUE : Boolean.FALSE;
} else if (name.equalsIgnoreCase(DOMConstants.FQ_IS_STANDALONE)) {
} else if (ImplPropMap.ISSTANDALONE.is(name)) {
return ((fFeatures & IS_STANDALONE) != 0) ? Boolean.TRUE : Boolean.FALSE;
} else if (name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
return ((fFeatures & ELEM_CONTENT_WHITESPACE) != 0) ? Boolean.TRUE : Boolean.FALSE;
@ -517,13 +529,13 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
public void setParameter(String name, Object value) throws DOMException {
// If the value is a boolean
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
boolean bValue = ((Boolean) value);
if (name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS)) {
fFeatures = state ? fFeatures | COMMENTS : fFeatures
fFeatures = bValue ? fFeatures | COMMENTS : fFeatures
& ~COMMENTS;
// comments
if (state) {
if (bValue) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
@ -531,10 +543,10 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
+ DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)) {
fFeatures = state ? fFeatures | CDATA : fFeatures
fFeatures = bValue ? fFeatures | CDATA : fFeatures
& ~CDATA;
// cdata-sections
if (state) {
if (bValue) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
@ -542,10 +554,10 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
+ DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES)) {
fFeatures = state ? fFeatures | ENTITIES : fFeatures
fFeatures = bValue ? fFeatures | ENTITIES : fFeatures
& ~ENTITIES;
// entities
if (state) {
if (bValue) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
@ -553,10 +565,10 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
+ DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES)) {
fFeatures = state ? fFeatures | NAMESPACES : fFeatures
fFeatures = bValue ? fFeatures | NAMESPACES : fFeatures
& ~NAMESPACES;
// namespaces
if (state) {
if (bValue) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
@ -565,10 +577,10 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
}
} else if (name
.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS)) {
fFeatures = state ? fFeatures | NAMESPACEDECLS
fFeatures = bValue ? fFeatures | NAMESPACEDECLS
: fFeatures & ~NAMESPACEDECLS;
// namespace-declarations
if (state) {
if (bValue) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
@ -576,10 +588,10 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
+ DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA)) {
fFeatures = state ? fFeatures | SPLITCDATA : fFeatures
fFeatures = bValue ? fFeatures | SPLITCDATA : fFeatures
& ~SPLITCDATA;
// split-cdata-sections
if (state) {
if (bValue) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_SPLIT_CDATA, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
@ -587,10 +599,10 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
+ DOMConstants.DOM_SPLIT_CDATA, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)) {
fFeatures = state ? fFeatures | WELLFORMED : fFeatures
fFeatures = bValue ? fFeatures | WELLFORMED : fFeatures
& ~WELLFORMED;
// well-formed
if (state) {
if (bValue) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
@ -599,10 +611,10 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
}
} else if (name
.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)) {
fFeatures = state ? fFeatures | DISCARDDEFAULT
fFeatures = bValue ? fFeatures | DISCARDDEFAULT
: fFeatures & ~DISCARDDEFAULT;
// discard-default-content
if (state) {
if (bValue) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_DISCARD_DEFAULT_CONTENT, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
@ -610,31 +622,32 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
+ DOMConstants.DOM_DISCARD_DEFAULT_CONTENT, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)) {
fFeatures = state ? fFeatures | PRETTY_PRINT : fFeatures
fFeatures = bValue ? fFeatures | PRETTY_PRINT : fFeatures
& ~PRETTY_PRINT;
if (state) {
if (bValue) {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_INDENT,DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, Integer.toString(4));
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_INDENT,DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)) {
fFeatures = state ? fFeatures | XMLDECL : fFeatures
fFeatures = bValue ? fFeatures | XMLDECL : fFeatures
& ~XMLDECL;
if (state) {
if (bValue) {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "no");
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "yes");
}
} else if (name.equalsIgnoreCase(DOMConstants.FQ_IS_STANDALONE)) {
fFeatures = state ? fFeatures | IS_STANDALONE : fFeatures & ~IS_STANDALONE;
fDOMConfigProperties.setProperty(DOMConstants.NS_IS_STANDALONE, state ? "yes" : "no");
} else if (ImplPropMap.ISSTANDALONE.is(name)) {
fIsStandalone.setValue(name, bValue, State.APIPROPERTY);
fFeatures = fIsStandalone.getValue() ? fFeatures | IS_STANDALONE : fFeatures & ~IS_STANDALONE;
fDOMConfigProperties.setProperty(DOMConstants.NS_IS_STANDALONE,
fIsStandalone.getValue() ? DOMConstants.DOM3_EXPLICIT_TRUE : DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fFeatures = state ? fFeatures | ELEM_CONTENT_WHITESPACE : fFeatures
fFeatures = bValue ? fFeatures | ELEM_CONTENT_WHITESPACE : fFeatures
& ~ELEM_CONTENT_WHITESPACE;
// element-content-whitespace
if (state) {
if (bValue) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
@ -643,7 +656,7 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
// false is not supported
if (!state) {
if (!bValue) {
// Here we have to add the Xalan specific DOM Message Formatter
String msg = Utils.messages.createMessage(
MsgKey.ER_FEATURE_NOT_SUPPORTED,
@ -661,7 +674,7 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
// || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
) {
// true is not supported
if (state) {
if (bValue) {
String msg = Utils.messages.createMessage(
MsgKey.ER_FEATURE_NOT_SUPPORTED,
new Object[] { name });
@ -688,7 +701,7 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
} */
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)) {
if (state) {
if (bValue) {
fFeatures &= ~ENTITIES;
fFeatures &= ~CDATA;
fFeatures &= ~SCHEMAVALIDATE;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -20,11 +20,11 @@
package com.sun.org.apache.xml.internal.utils;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
import java.util.HashMap;
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
@ -37,7 +37,7 @@ import org.xml.sax.XMLReader;
* Creates XMLReader objects and caches them for re-use.
* This class follows the singleton pattern.
*
* @LastModified: Sep 2017
* @LastModified: May 2021
*/
public class XMLReaderManager {
@ -61,7 +61,7 @@ public class XMLReaderManager {
/**
* protocols allowed for external DTD references in source file and/or stylesheet.
*/
private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
private String _accessExternalDTD = JdkConstants.EXTERNAL_ACCESS_DEFAULT;
private XMLSecurityManager _xmlSecurityManager;
@ -136,7 +136,7 @@ public class XMLReaderManager {
JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, XMLConstants.ACCESS_EXTERNAL_DTD,
_accessExternalDTD, true);
JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, JdkXmlUtils.CDATA_CHUNK_SIZE,
JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, JdkConstants.CDATA_CHUNK_SIZE,
_cdataChunkSize, false);
String lastProperty = "";
@ -148,8 +148,8 @@ public class XMLReaderManager {
_xmlSecurityManager.getLimitValueAsString(limit));
}
if (_xmlSecurityManager.printEntityCountInfo()) {
lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
reader.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
lastProperty = JdkConstants.JDK_DEBUG_LIMIT;
reader.setProperty(lastProperty, JdkConstants.JDK_YES);
}
}
} catch (SAXException se) {
@ -221,7 +221,7 @@ public class XMLReaderManager {
public Object getProperty(String name) {
if (name.equals(XMLConstants.ACCESS_EXTERNAL_DTD)) {
return _accessExternalDTD;
} else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
} else if (name.equals(JdkConstants.SECURITY_MANAGER)) {
return _xmlSecurityManager;
}
return null;
@ -233,11 +233,11 @@ public class XMLReaderManager {
public void setProperty(String name, Object value) {
if (name.equals(XMLConstants.ACCESS_EXTERNAL_DTD)) {
_accessExternalDTD = (String)value;
} else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
} else if (name.equals(JdkConstants.SECURITY_MANAGER)) {
_xmlSecurityManager = (XMLSecurityManager)value;
} else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) {
_catalogFeatures = (CatalogFeatures)value;
} else if (JdkXmlUtils.CDATA_CHUNK_SIZE.equals(name)) {
} else if (JdkConstants.CDATA_CHUNK_SIZE.equals(name)) {
_cdataChunkSize = JdkXmlUtils.getValue(value, _cdataChunkSize);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -25,7 +25,7 @@ import javax.xml.transform.TransformerException;
import com.sun.org.apache.xml.internal.utils.PrefixResolver;
import com.sun.org.apache.xml.internal.utils.PrefixResolverDefault;
import com.sun.org.apache.xpath.internal.objects.XObject;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.JdkConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@ -54,6 +54,7 @@ import org.w3c.dom.traversal.NodeIterator;
* decide when to discard the cache.
*
* @see <a href="http://www.w3.org/TR/xpath">XPath Specification</a>
* @LastModified: May 2021
* */
public class CachedXPathAPI
{
@ -73,7 +74,7 @@ public class CachedXPathAPI
*/
public CachedXPathAPI()
{
xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
xpathSupport = new XPathContext(JdkConstants.OVERRIDE_PARSER_DEFAULT);
}
/**
@ -328,7 +329,7 @@ public class CachedXPathAPI
XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
// Execute the XPath, and have it return the result
XPathContext xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
XPathContext xpathSupport = new XPathContext(JdkConstants.OVERRIDE_PARSER_DEFAULT);
int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
return xpath.execute(xpathSupport, ctxtNode, prefixResolver);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -25,7 +25,7 @@ import javax.xml.transform.TransformerException;
import com.sun.org.apache.xml.internal.utils.PrefixResolver;
import com.sun.org.apache.xml.internal.utils.PrefixResolverDefault;
import com.sun.org.apache.xpath.internal.objects.XObject;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.JdkConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@ -49,6 +49,7 @@ import org.w3c.dom.traversal.NodeIterator;
* methods.
*
* @see <a href="http://www.w3.org/TR/xpath">XPath Specification</a>
* @LastModified: May 2021
* */
public class XPathAPI
{
@ -221,7 +222,7 @@ public class XPathAPI
// (Changed from: XPathContext xpathSupport = new XPathContext();
// because XPathContext is weak in a number of areas... perhaps
// XPathContext should be done away with.)
XPathContext xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
XPathContext xpathSupport = new XPathContext(JdkConstants.OVERRIDE_PARSER_DEFAULT);
// Create an object to resolve namespace prefixes.
// XPath namespaces are resolved from the input context node's document element
@ -276,7 +277,7 @@ public class XPathAPI
XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
// Execute the XPath, and have it return the result
XPathContext xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
XPathContext xpathSupport = new XPathContext(JdkConstants.OVERRIDE_PARSER_DEFAULT);
int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
return xpath.execute(xpathSupport, ctxtNode, prefixResolver);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -20,7 +20,6 @@
package com.sun.org.apache.xpath.internal.jaxp;
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.res.XSLMessages;
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
import javax.xml.XMLConstants;
@ -28,12 +27,16 @@ import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;
import javax.xml.xpath.XPathFunctionResolver;
import javax.xml.xpath.XPathVariableResolver;
import jdk.xml.internal.JdkConstants;
import jdk.xml.internal.JdkProperty;
import jdk.xml.internal.JdkXmlFeatures;
/**
* The XPathFactory builds XPaths.
*
* @author Ramesh Mandava
*
* @LastModified: May 2021
*/
public class XPathFactoryImpl extends XPathFactory {
@ -153,6 +156,7 @@ public class XPathFactoryImpl extends XPathFactory {
* @throws NullPointerException if <code>name</code> is
* <code>null</code>.
*/
@SuppressWarnings("deprecation")
public void setFeature(String name, boolean value)
throws XPathFactoryConfigurationException {
@ -176,20 +180,20 @@ public class XPathFactoryImpl extends XPathFactory {
_isNotSecureProcessing = !value;
if (value && _featureManager != null) {
_featureManager.setFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION,
JdkXmlFeatures.State.FSP, false);
JdkProperty.State.FSP, false);
}
// all done processing feature
return;
}
if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
if (name.equals(JdkConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
// for compatibility, in secure mode, useServicesMechanism is determined by the constructor
if (_isSecureMode)
return;
}
if (_featureManager != null &&
_featureManager.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) {
_featureManager.setFeature(name, JdkProperty.State.APIPROPERTY, value)) {
return;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, 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
@ -36,49 +36,9 @@ import com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl;
* Factory that creates new {@code javax.xml.datatype} {@code Object}s that map XML to/from Java {@code Object}s.
* <p id="DatatypeFactory.newInstance">
* A new instance of the {@code DatatypeFactory} is created through the {@link #newInstance()} method
* that uses the following implementation resolution mechanisms to determine an implementation:
* <ol>
* <li>
* If the system property specified by {@link #DATATYPEFACTORY_PROPERTY}, "{@code javax.xml.datatype.DatatypeFactory}",
* exists, a class with the name of the property value is instantiated.
* Any Exception thrown during the instantiation process is wrapped as a {@link DatatypeConfigurationException}.
* </li>
* <li>
* <p>
* Use the configuration file "jaxp.properties". The file is in standard
* {@link java.util.Properties} format and typically located in the
* {@code conf} directory of the Java installation. It contains the fully qualified
* name of the implementation class with the key being the system property
* defined above.
* <p>
* The jaxp.properties file is read only once by the JAXP implementation
* and its values are then cached for future use. If the file does not exist
* when the first attempt is made to read from it, no further attempts are
* made to check for its existence. It is not possible to change the value
* of any property in jaxp.properties after it has been read for the first time.
* </li>
* <li>
* <p>
* Use the service-provider loading facility, defined by the {@link java.util.ServiceLoader} class, to attempt
* to locate and load an implementation of the service using the {@linkplain
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}:
* the service-provider loading facility will use the {@linkplain
* java.lang.Thread#getContextClassLoader() current thread's context class loader}
* to attempt to load the service. If the context class
* loader is null, the {@linkplain
* ClassLoader#getSystemClassLoader() system class loader} will be used.
* <p>
* In case of {@link java.util.ServiceConfigurationError service
* configuration error}, a {@link javax.xml.datatype.DatatypeConfigurationException}
* will be thrown.
* </li>
* <li>
* <p>
* The final mechanism is to attempt to instantiate the {@code Class} specified by
* {@link #DATATYPEFACTORY_IMPLEMENTATION_CLASS}.
* Any Exception thrown during the instantiation process is wrapped as a {@link DatatypeConfigurationException}.
* </li>
* </ol>
* that uses the
* <a href="../../../module-summary.html#LookupMechanism">JAXP Lookup Mechanism</a>
* to determine the {@code DatatypeFactory} implementation class to load.
*
* @author Joseph Fialli
* @author Jeff Suttor
@ -152,9 +112,9 @@ public abstract class DatatypeFactory {
/**
* Obtain a new instance of a {@code DatatypeFactory}.
*
* <p>The implementation resolution mechanisms are <a href="#DatatypeFactory.newInstance">defined</a> in this
* {@code Class}'s documentation.
* This method uses the
* <a href="../../../module-summary.html#LookupMechanism">JAXP Lookup Mechanism</a>
* to determine the {@code DatatypeFactory} implementation class to load.
*
* @return New instance of a {@code DatatypeFactory}
*

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* @LastModified: Sep 2017
* Copyright (c) 2011, 2021, 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
@ -24,17 +23,14 @@
* questions.
*/
package com.sun.org.apache.xalan.internal;
import jdk.xml.internal.SecuritySupport;
package jdk.xml.internal;
/**
* Commonly used constants.
*
* @author Huizhe Wang, Oracle
*
* This class holds constants shared across XML components. Historically, there
* had been a component boundary within which some constants were duplicated for
* each component, such as Xerces and Xalan.
*/
public final class XalanConstants {
public final class JdkConstants {
//
// Constants
@ -46,77 +42,120 @@ public final class XalanConstants {
//
// Implementation limits: API properties
//
/** Oracle JAXP property prefix ("http://www.oracle.com/xml/jaxp/properties/"). */
/**
* Oracle JAXP property prefix.
*
* @deprecated Use {@code jdk.xml.} instead. Refer to specifications in
* the module summary.
*/
@Deprecated (since="17")
public static final String ORACLE_JAXP_PROPERTY_PREFIX =
"http://www.oracle.com/xml/jaxp/properties/";
/**
* JDK entity expansion limit; Note that the existing system property
* "entityExpansionLimit" with no prefix is still observed
* JDK entity expansion limit. Note that the existing system property
* "entityExpansionLimit" with no prefix is still observed.
*
* @deprecated Use {@link #SP_ENTITY_EXPANSION_LIMIT} instead.
*/
@Deprecated (since="17")
public static final String JDK_ENTITY_EXPANSION_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "entityExpansionLimit";
/**
* JDK element attribute limit; Note that the existing system property
* "elementAttributeLimit" with no prefix is still observed
* JDK element attribute limit. Note that the existing system property
* "elementAttributeLimit" with no prefix is still observed.
*
* @deprecated Use {@link #SP_ELEMENT_ATTRIBUTE_LIMIT} instead.
*/
@Deprecated (since="17")
public static final String JDK_ELEMENT_ATTRIBUTE_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "elementAttributeLimit";
/**
* JDK maxOccur limit; Note that the existing system property
* JDK maxOccur limit. Note that the existing system property
* "maxOccurLimit" with no prefix is still observed
*
* @deprecated Use {@link #SP_ENTITY_EXPANSION_LIMIT} instead.
*/
@Deprecated (since="17")
public static final String JDK_MAX_OCCUR_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "maxOccurLimit";
/**
* JDK total entity size limit
* JDK total entity size limit.
*
* @deprecated Use {@link #SP_TOTAL_ENTITY_SIZE_LIMIT} instead.
*/
@Deprecated (since="17")
public static final String JDK_TOTAL_ENTITY_SIZE_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "totalEntitySizeLimit";
/**
* JDK maximum general entity size limit
* JDK maximum general entity size limit.
*
* @deprecated Use {@link #SP_GENERAL_ENTITY_SIZE_LIMIT} instead.
*/
@Deprecated (since="17")
public static final String JDK_GENERAL_ENTITY_SIZE_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "maxGeneralEntitySizeLimit";
/**
* JDK node count limit in entities that limits the total number of nodes
* in all of entity references.
*
* @deprecated Use {@link #SP_ENTITY_REPLACEMENT_LIMIT} instead.
*/
@Deprecated (since="17")
public static final String JDK_ENTITY_REPLACEMENT_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "entityReplacementLimit";
/**
* JDK maximum parameter entity size limit
* JDK maximum parameter entity size limit.
*
* @deprecated Use {@link #SP_PARAMETER_ENTITY_SIZE_LIMIT} instead.
*/
@Deprecated (since="17")
public static final String JDK_PARAMETER_ENTITY_SIZE_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "maxParameterEntitySizeLimit";
/**
* JDK maximum XML name limit
* JDK maximum XML name limit.
*
* @deprecated Use {@link #SP_XML_NAME_LIMIT} instead.
*/
@Deprecated (since="17")
public static final String JDK_XML_NAME_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "maxXMLNameLimit";
/**
* JDK maxElementDepth limit
* JDK maxElementDepth limit.
*
* @deprecated Use {@link #SP_MAX_ELEMENT_DEPTH} instead.
*/
@Deprecated (since="17")
public static final String JDK_MAX_ELEMENT_DEPTH =
ORACLE_JAXP_PROPERTY_PREFIX + "maxElementDepth";
/**
* JDK property indicating whether the parser shall print out entity
* count information
* count information.
* Value: a string "yes" means print, "no" or any other string means not.
*
* @deprecated Use {@link #JDK_DEBUG_LIMIT} instead.
*/
@Deprecated (since="17")
public static final String JDK_ENTITY_COUNT_INFO =
ORACLE_JAXP_PROPERTY_PREFIX + "getEntityCountInfo";
public static final String JDK_DEBUG_LIMIT = "jdk.xml.getEntityCountInfo";
//
// Implementation limits: corresponding System Properties of the above
// API properties
// API properties.
//
// Note: as of JDK 17, properties and System properties now share the same
// name with a prefix "jdk.xml.".
//
/**
* JDK entity expansion limit; Note that the existing system property
@ -175,6 +214,8 @@ public final class XalanConstants {
* for extension functions loading during translation process
*/
public static final String JDK_EXTENSION_CLASSLOADER = "jdk.xml.transform.extensionClassLoader";
// spec-compatible name with a prefix "jdk.xml"
public static final String JDK_EXT_CLASSLOADER = "jdk.xml.extensionClassLoader";
//legacy System Properties
public final static String ENTITY_EXPANSION_LIMIT = "entityExpansionLimit";
@ -192,21 +233,24 @@ public final class XalanConstants {
*
* <ul>
* <li>
* {@code true} instruct an object to use service mechanism to
* find a service implementation. This is the default behavior.
* </li>
* <li>
* {@code false} instruct an object to skip service mechanism and
* use the default implementation for that service.
* </li>
* </ul>
*/
public static final String ORACLE_FEATURE_SERVICE_MECHANISM = "http://www.oracle.com/feature/use-service-mechanism";
* {@code true} instruct an object to use service mechanism to
* find a service implementation. This is the default behavior.
* </li>
* <li>
* {@code false} instruct an object to skip service mechanism and
* use the default implementation for that service.
* </li>
* </ul>
* @deprecated Use {@link jdk.xml.internal.JdkXmlUtils#OVERRIDE_PARSER} instead.
*/
@Deprecated (since="17")
public static final String ORACLE_FEATURE_SERVICE_MECHANISM =
"http://www.oracle.com/feature/use-service-mechanism";
//System Properties corresponding to ACCESS_EXTERNAL_* properties
public static final String SP_ACCESS_EXTERNAL_STYLESHEET = "javax.xml.accessExternalStylesheet";
public static final String SP_ACCESS_EXTERNAL_DTD = "javax.xml.accessExternalDTD";
public static final String SP_ACCESS_EXTERNAL_SCHEMA = "javax.xml.accessExternalSchema";
//all access keyword
public static final String ACCESS_EXTERNAL_ALL = "all";
@ -222,8 +266,7 @@ public final class XalanConstants {
public static final String EXTERNAL_ACCESS_DEFAULT = ACCESS_EXTERNAL_ALL;
public static final String XML_SECURITY_PROPERTY_MANAGER =
ORACLE_JAXP_PROPERTY_PREFIX + "xmlSecurityPropertyManager";
"jdk.xml.xmlSecurityPropertyManager";
/**
* Values for a feature
@ -231,4 +274,104 @@ public final class XalanConstants {
public static final String FEATURE_TRUE = "true";
public static final String FEATURE_FALSE = "false";
} // class Constants
/**
* For DOM Serializer.
*
* Indicates that the serializer should treat the output as a standalone document.
* The JDK specific standalone property controls whether a newline should be
* added after the XML header.
*
* @see similar property xsltcIsStandalone for XSLTC.
*/
public static final String S_IS_STANDALONE = "isStandalone";
/**
* Fully-qualified property name with the JDK Impl prefix.
*
* @deprecated Use {@link #SP_IS_STANDALONE} instead.
*/
@Deprecated (since="17")
public static final String FQ_IS_STANDALONE = ORACLE_JAXP_PROPERTY_PREFIX + S_IS_STANDALONE;
// Corresponding System property
public static final String SP_IS_STANDALONE = "jdk.xml.isStandalone";
/**
* For XSLTC.
*
* Instructs the processor to act as if OutputKeys.STANDALONE is specified
* but without writing it out in the declaration.
* This property may be used to mitigate the effect of Xalan patch 1495 that
* has caused incompatible behaviors.
*/
/**
* <p>Is Standalone</p>
*
* <ul>
* <li>
* <code>yes</code> to indicate the output is intended to be used as standalone
* </li>
* <li>
* <code>no</code> has no effect.
* </li>
* </ul>
*
* @deprecated Use {@link #SP_XSLTC_IS_STANDALONE} instead.
*/
@Deprecated (since="17")
public static final String ORACLE_IS_STANDALONE = "http://www.oracle.com/xml/is-standalone";
/**
* This property was added to align with those that used ORACLE_JAXP_PROPERTY_PREFIX
* as prefix.
* @deprecated Use {@link #SP_XSLTC_IS_STANDALONE} instead.
*/
@Deprecated (since="17")
public static final String JDK_IS_STANDALONE = ORACLE_JAXP_PROPERTY_PREFIX +
"xsltcIsStandalone";
// Corresponding System property
public static final String SP_XSLTC_IS_STANDALONE = "jdk.xml.xsltcIsStandalone";
/**
* Feature enableExtensionFunctions
*/
public static final String ORACLE_ENABLE_EXTENSION_FUNCTION =
ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions";
public static final String SP_ENABLE_EXTENSION_FUNCTION =
"javax.xml.enableExtensionFunctions";
// This is the correct name by the spec
public static final String SP_ENABLE_EXTENSION_FUNCTION_SPEC =
"jdk.xml.enableExtensionFunctions";
/**
* Reset SymbolTable feature System property name is identical to feature
* name
*/
public final static String RESET_SYMBOL_TABLE = "jdk.xml.resetSymbolTable";
/**
* Default value of RESET_SYMBOL_TABLE. This will read the System property
*/
public static final boolean RESET_SYMBOL_TABLE_DEFAULT
= SecuritySupport.getJAXPSystemProperty(Boolean.class, RESET_SYMBOL_TABLE, "false");
/**
* jdk.xml.overrideDefaultParser: enables the use of a 3rd party's parser
* implementation to override the system-default parser.
*/
public static final String OVERRIDE_PARSER = "jdk.xml.overrideDefaultParser";
public static final boolean OVERRIDE_PARSER_DEFAULT = SecuritySupport.getJAXPSystemProperty(
Boolean.class, OVERRIDE_PARSER, "false");
/**
* instructs the parser to return the data in a CData section in a single chunk
* when the property is zero or unspecified, or in multiple chunks when it is
* greater than zero. The parser shall split the data by linebreaks, and any
* chunks that are larger than the specified size to ones that are equal to
* or smaller than the size.
*/
public final static String CDATA_CHUNK_SIZE = "jdk.xml.cdataChunkSize";
public static final int CDATA_CHUNK_SIZE_DEFAULT
= SecuritySupport.getJAXPSystemProperty(Integer.class, CDATA_CHUNK_SIZE, "0");
}

View File

@ -0,0 +1,254 @@
/*
* Copyright (c) 2021, 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 static jdk.xml.internal.JdkConstants.FQ_IS_STANDALONE;
import static jdk.xml.internal.JdkConstants.JDK_DEBUG_LIMIT;
import static jdk.xml.internal.JdkConstants.JDK_ENTITY_COUNT_INFO;
import static jdk.xml.internal.JdkConstants.JDK_EXTENSION_CLASSLOADER;
import static jdk.xml.internal.JdkConstants.JDK_EXT_CLASSLOADER;
import static jdk.xml.internal.JdkConstants.JDK_IS_STANDALONE;
import static jdk.xml.internal.JdkConstants.ORACLE_IS_STANDALONE;
import static jdk.xml.internal.JdkConstants.SP_IS_STANDALONE;
import static jdk.xml.internal.JdkConstants.SP_XSLTC_IS_STANDALONE;
import static jdk.xml.internal.JdkConstants.ORACLE_ENABLE_EXTENSION_FUNCTION;
import static jdk.xml.internal.JdkConstants.ORACLE_FEATURE_SERVICE_MECHANISM;
import static jdk.xml.internal.JdkConstants.SP_ENABLE_EXTENSION_FUNCTION;
import static jdk.xml.internal.JdkConstants.SP_ENABLE_EXTENSION_FUNCTION_SPEC;
import static jdk.xml.internal.JdkConstants.CDATA_CHUNK_SIZE;
import static jdk.xml.internal.JdkConstants.OVERRIDE_PARSER;
import static jdk.xml.internal.JdkConstants.RESET_SYMBOL_TABLE;
/**
* Represents a JDK Implementation Specific Property. This class holds the name
* and value of a property along with a state indicating the means through which
* the property has been set. The value may change only if the setter has a state
* that represents an equal or higher overriding order.
*
* @param <T> the type of the property value.
*/
public final class JdkProperty<T> {
private ImplPropMap pName;
private T pValue;
private State pState = State.DEFAULT;
/**
* Constructs a JDkProperty.
* @param name the name of the property
* @param value the initial value
* @param state the state of the property
*/
public JdkProperty(ImplPropMap name, T value, State state) {
this.pName = name;
this.pValue = value;
this.pState = state;
}
/**
* Returns the property value.
* @return the property value
*/
public T getValue() {
return pValue;
}
/**
* Sets the property value. The value is set only if the setter has a higher
* overriding order.
* @param name the property name
* @param value the value
* @param state the state of the specified property
* @return true if the value is set successfully (because the setter has a
* higher order); false otherwise.
*/
public boolean setValue(String name, T value, State state) {
State pState1;
if ((pState1 = pName.getState(name)) != null) {
if (pState1.compareTo(this.pState) >= 0) {
this.pState = pState1;
pValue = value;
return true;
}
}
return false;
}
/**
* Properties Name Map that includes Implementation-Specific Features and
* Properties except the limits that are defined in XMLSecurityManager.
* The purpose of the map is to provide a map between the new property names
* with a prefix "jdk.xml" as defined in the module summary and legacy names
* with URL style prefixes. The new names are the same as those of their
* System Properties.
*/
@SuppressWarnings("deprecation")
public static enum ImplPropMap {
ISSTANDALONE("isStandalone", FQ_IS_STANDALONE, SP_IS_STANDALONE, true, null, null),
XSLTCISSTANDALONE("xsltcIsStandalone", JDK_IS_STANDALONE, SP_XSLTC_IS_STANDALONE,
true, ORACLE_IS_STANDALONE, null),
CDATACHUNKSIZE("cdataChunkSize", CDATA_CHUNK_SIZE, CDATA_CHUNK_SIZE, false, null, null),
EXTCLSLOADER("extensionClassLoader", JDK_EXT_CLASSLOADER, null,
true, JDK_EXTENSION_CLASSLOADER, null),
ENABLEEXTFUNC("enableExtensionFunctions", ORACLE_ENABLE_EXTENSION_FUNCTION,
SP_ENABLE_EXTENSION_FUNCTION_SPEC, true, null, SP_ENABLE_EXTENSION_FUNCTION),
OVERRIDEPARSER("overrideDefaultParser", OVERRIDE_PARSER, OVERRIDE_PARSER,
false, ORACLE_FEATURE_SERVICE_MECHANISM, ORACLE_FEATURE_SERVICE_MECHANISM),
RESETSYMBOLTABLE("resetSymbolTable", RESET_SYMBOL_TABLE, RESET_SYMBOL_TABLE,
false, null, null),
ENTITYCOUNT("getEntityCountInfo", JDK_DEBUG_LIMIT, null, true, JDK_ENTITY_COUNT_INFO, null)
;
private final String name;
private final String qName;
private final String spName;
private final boolean differ;
private final String oldQName;
private final String oldSPName;
/**
* Constructs an instance.
* @param name the property name
* @param qName the qualified property name
* @param spName the corresponding System Property
* @param differ a flag indicating whether qName and spName are the same
* @param oldName the legacy property name, null if N/A
* @param oldSPName the legacy System Property name, null if N/A
*/
ImplPropMap(String name, String qName, String spName, boolean differ,
String oldQName, String oldSPName) {
this.name = name;
this.qName = qName;
this.spName = spName;
this.differ = differ;
this.oldQName = oldQName;
this.oldSPName = oldSPName;
}
/**
* Checks whether the specified name is the property. Checks both the
* property and System Property if they differ. Checks also the legacy
* name if applicable.
*
* @param name the specified name
* @return true if there is a match, false otherwise
*/
public boolean is(String name) {
// current spec calls for using a name same as spName
return (spName != null && spName.equals(name)) ||
// check qName only if it differs from spName
(differ && qName.equals(name)) ||
// check the legacy name if applicable
(oldQName != null && oldQName.equals(name));
}
/**
* Returns the value indicating whether the qName and spName are different.
* @return the value indicating whether the qName and spName are different
*/
public boolean isNameDiffer() {
return differ;
}
/**
* Returns the state of a property name. By the specification as of JDK 17,
* the "jdk.xml." prefixed System property name is also the current API
* name. Both the URI-based qName and old name if any are legacy.
*
* @param name the property name
* @return the state of the property name, null if no match
*/
public State getState(String name) {
if ((spName != null && spName.equals(name)) ||
(spName == null && qName.equals(name))) {
return State.APIPROPERTY;
} else if ((differ && qName.equals(name)) ||
(oldQName != null && oldQName.equals(name))) {
//both the URI-style qName and an old name if any are legacy
return State.LEGACY_APIPROPERTY;
}
return null;
}
/**
* Returns the qualified name of the property.
*
* @return the qualified name of the property
*/
public String qName() {
return qName;
}
/**
* Returns the legacy name of the property.
*
* @return the legacy name of the property
*/
public String qNameOld() {
return oldQName;
}
/**
* Returns the name of the corresponding System Property.
*
* @return the name of the System Property
*/
public String systemProperty() {
return spName;
}
/**
* Returns the name of the legacy System Property.
*
* @return the name of the legacy System Property
*/
public String systemPropertyOld() {
return oldSPName;
}
}
/**
* Represents the state of the settings of a property. The states are in
* descending order: the default value, value set by FEATURE_SECURE_PROCESSING (FSP),
* in jaxp.properties, by legacy or new system property, and on factories
* using legacy or new property names.
*/
public static enum State {
//this order reflects the overriding order
DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"), JAXPDOTPROPERTIES("jaxp.properties"),
LEGACY_SYSTEMPROPERTY("legacy system property"), SYSTEMPROPERTY("system property"),
LEGACY_APIPROPERTY("legacy property"), APIPROPERTY("property");
final String literal;
State(String literal) {
this.literal = literal;
}
public String literal() {
return literal;
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, 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
@ -26,9 +26,9 @@
package jdk.xml.internal;
import javax.xml.XMLConstants;
import static jdk.xml.internal.JdkXmlUtils.OVERRIDE_PARSER;
import jdk.xml.internal.JdkProperty.ImplPropMap;
import jdk.xml.internal.JdkProperty.State;
import static jdk.xml.internal.JdkXmlUtils.SP_USE_CATALOG;
import static jdk.xml.internal.JdkXmlUtils.RESET_SYMBOL_TABLE;
/**
* This class manages JDK's XML Features. Previously added features and properties
@ -41,19 +41,6 @@ public class JdkXmlFeatures {
public static final String XML_FEATURE_MANAGER =
ORACLE_JAXP_PROPERTY_PREFIX + "XmlFeatureManager";
public static final String ORACLE_FEATURE_SERVICE_MECHANISM =
"http://www.oracle.com/feature/use-service-mechanism";
/**
* Feature enableExtensionFunctions
*/
public static final String ORACLE_ENABLE_EXTENSION_FUNCTION =
ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions";
public static final String SP_ENABLE_EXTENSION_FUNCTION =
"javax.xml.enableExtensionFunctions";
// This is the correct name by the spec
public static final String SP_ENABLE_EXTENSION_FUNCTION_SPEC =
"jdk.xml.enableExtensionFunctions";
public static final String CATALOG_FEATURES = "javax.xml.catalog.catalogFeatures";
public final static String PROPERTY_USE_CATALOG = XMLConstants.USE_CATALOG;
@ -64,35 +51,33 @@ public class JdkXmlFeatures {
* FSP: extension function is enforced by FSP. When FSP is on, extension
* function is disabled.
*/
ENABLE_EXTENSION_FUNCTION(ORACLE_ENABLE_EXTENSION_FUNCTION, SP_ENABLE_EXTENSION_FUNCTION_SPEC,
ORACLE_ENABLE_EXTENSION_FUNCTION, SP_ENABLE_EXTENSION_FUNCTION,
true, false, true, true),
ENABLE_EXTENSION_FUNCTION(ImplPropMap.ENABLEEXTFUNC, null, null, true,
null, null, true, false, true, true),
/**
* The {@link javax.xml.XMLConstants.USE_CATALOG} feature.
* FSP: USE_CATALOG is not enforced by FSP.
*/
USE_CATALOG(PROPERTY_USE_CATALOG, SP_USE_CATALOG,
null, null,
true, false, true, false),
USE_CATALOG(null, PROPERTY_USE_CATALOG, SP_USE_CATALOG, false,
null, null, true, false, true, false),
/**
* Feature resetSymbolTable
* FSP: RESET_SYMBOL_TABLE_FEATURE is not enforced by FSP.
*/
RESET_SYMBOL_TABLE_FEATURE(RESET_SYMBOL_TABLE, RESET_SYMBOL_TABLE,
null, null,
false, false, true, false),
RESET_SYMBOL_TABLE_FEATURE(ImplPropMap.RESETSYMBOLTABLE, null, null, false,
null, null, false, false, true, false),
/**
* Feature overrideDefaultParser
* FSP: not enforced by FSP.
*/
JDK_OVERRIDE_PARSER(OVERRIDE_PARSER, OVERRIDE_PARSER,
ORACLE_FEATURE_SERVICE_MECHANISM, ORACLE_FEATURE_SERVICE_MECHANISM,
false, false, true, false);
JDK_OVERRIDE_PARSER(ImplPropMap.OVERRIDEPARSER, null, null, false,
null, null, false, false, true, false);
private final ImplPropMap implMap;
private final String name;
private final String nameSP;
private final boolean differ;
private final String nameOld;
private final String nameOldSP;
private final boolean valueDefault;
@ -102,6 +87,9 @@ public class JdkXmlFeatures {
/**
* Constructs an XmlFeature instance.
* @param implMap the Implementation specific properties map. When the
* map is specified, there is no need to repeat or enter other name
* parameters.
* @param name the name of the feature
* @param nameSP the name of the System Property
* @param nameOld the name of the corresponding legacy property
@ -112,12 +100,22 @@ public class JdkXmlFeatures {
* FSP (Feature_Secure_Processing) enforced
* with a System property
*/
XmlFeature(String name, String nameSP, String nameOld, String nameOldSP,
boolean value, boolean valueEnforced, boolean hasSystem, boolean enforced) {
this.name = name;
this.nameSP = nameSP;
this.nameOld = nameOld;
this.nameOldSP = nameOldSP;
XmlFeature(ImplPropMap implMap, String name, String nameSP, boolean differ,
String nameOld, String nameOldSP, boolean value, boolean valueEnforced,
boolean hasSystem, boolean enforced) {
this.implMap = implMap;
if (implMap != null) {
this.name = implMap.qName();
this.nameSP = implMap.systemProperty();
this.nameOld = implMap.qNameOld();
this.nameOldSP = implMap.systemPropertyOld();
} else {
this.name = name;
this.nameSP = nameSP;
this.nameOld = nameOld;
this.nameOldSP = nameOldSP;
}
this.differ = differ;
this.valueDefault = value;
this.valueEnforced = valueEnforced;
this.hasSystem = hasSystem;
@ -131,6 +129,9 @@ public class JdkXmlFeatures {
* otherwise
*/
boolean equalsPropertyName(String propertyName) {
if (implMap != null) {
return implMap.is(propertyName);
}
return name.equals(propertyName) ||
(nameOld != null && nameOld.equals(propertyName));
}
@ -194,28 +195,23 @@ public class JdkXmlFeatures {
return enforced;
}
}
/**
* States of the settings of a property, in the order: default value, value
* set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system
* properties, and jaxp api properties
*/
public static enum State {
//this order reflects the overriding order
DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"),
JAXPDOTPROPERTIES("jaxp.properties"), SYSTEMPROPERTY("system property"),
APIPROPERTY("property");
final String literal;
State(String literal) {
this.literal = literal;
/**
* Returns the state of a property name. By the specification as of JDK 17,
* the "jdk.xml." prefixed System property name is also the current API
* name. Both the URI-based qName and old name if any are legacy.
*
* @param name the property name
* @return the state of the property name, null if no match
*/
public State getState(String name) {
if (implMap != null) {
return implMap.getState(name);
} else if (this.name.equals(name)) {
return State.APIPROPERTY;
}
return null;
}
String literal() {
return literal;
}
}
/**
@ -272,10 +268,18 @@ public class JdkXmlFeatures {
* false otherwise.
*/
public boolean setFeature(String propertyName, State state, Object value) {
int index = getIndex(propertyName);
if (index > -1) {
setFeature(index, state, value);
return true;
State pState = state;
XmlFeature f = findByName(propertyName);
// if the feature is managed by JdkXmlFeatures
if (f != null) {
// if it's set from an API, get the correct state
if (state == State.APIPROPERTY) {
pState = f.getState(propertyName);
}
if (pState != null) {
setFeature(f.ordinal(), pState, value);
return true;
}
}
return false;
}
@ -342,6 +346,21 @@ public class JdkXmlFeatures {
}
}
/**
* Finds the feature by string name.
*
* @param propertyName property name
* @return the feature if found; null otherwise
*/
public XmlFeature findByName(String propertyName) {
for (XmlFeature feature : XmlFeature.values()) {
if (feature.equalsPropertyName(propertyName)) {
return feature;
}
}
return null;
}
/**
* Get the index by property name
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, 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
@ -40,6 +40,7 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.sax.SAXTransformerFactory;
import static jdk.xml.internal.JdkConstants.OVERRIDE_PARSER;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
@ -73,25 +74,7 @@ public class JdkXmlUtils {
public final static String CATALOG_PREFER = CatalogFeatures.Feature.PREFER.getPropertyName();
public final static String CATALOG_RESOLVE = CatalogFeatures.Feature.RESOLVE.getPropertyName();
/**
* Reset SymbolTable feature System property name is identical to feature
* name
*/
public final static String RESET_SYMBOL_TABLE = "jdk.xml.resetSymbolTable";
/**
* jdk.xml.overrideDefaultParser: enables the use of a 3rd party's parser
* implementation to override the system-default parser.
*/
public static final String OVERRIDE_PARSER = "jdk.xml.overrideDefaultParser";
public static final boolean OVERRIDE_PARSER_DEFAULT = SecuritySupport.getJAXPSystemProperty(
Boolean.class, OVERRIDE_PARSER, "false");
/**
* Values for a feature
*/
public static final String FEATURE_TRUE = "true";
public static final String FEATURE_FALSE = "false";
/**
* Default value of USE_CATALOG. This will read the System property
@ -99,18 +82,6 @@ public class JdkXmlUtils {
public static final boolean USE_CATALOG_DEFAULT
= SecuritySupport.getJAXPSystemProperty(Boolean.class, SP_USE_CATALOG, "true");
/**
* Default value of RESET_SYMBOL_TABLE. This will read the System property
*/
public static final boolean RESET_SYMBOL_TABLE_DEFAULT
= SecuritySupport.getJAXPSystemProperty(Boolean.class, RESET_SYMBOL_TABLE, "false");
/**
* JDK features (will be consolidated in the next major feature revamp
*/
public final static String CDATA_CHUNK_SIZE = "jdk.xml.cdataChunkSize";
public static final int CDATA_CHUNK_SIZE_DEFAULT
= SecuritySupport.getJAXPSystemProperty(Integer.class, CDATA_CHUNK_SIZE, "0");
/**
* The system-default factory

View File

@ -47,85 +47,94 @@
*
* <tbody>
* <tr>
* <th scope="row" style="font-weight:normal" id="DATA">
* {@link javax.xml.datatype.DatatypeFactory DatatypeFactory}
* </th>
* <td style="text-align:center">{@link javax.xml.datatype.DatatypeFactory#newInstance() newInstance()}</td>
* <td style="text-align:center">{@code javax.xml.datatype.DatatypeFactory}</td>
* <td style="text-align:center"><a href="#JaxpProperties">jaxp.properties</a></td>
* <td style="text-align:center">{@link javax.xml.datatype.DatatypeFactory#newDefaultInstance() newDefaultInstance()}</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="DOM">
* {@link javax.xml.parsers.DocumentBuilderFactory DocumentBuilderFactory}
* </th>
* <td>{@link javax.xml.parsers.DocumentBuilderFactory#newInstance() newInstance()}</td>
* <td>{@code javax.xml.parsers.DocumentBuilderFactory}</td>
* <td><a href="#JaxpProperties">jaxp.properties</a></td>
* <td>{@link javax.xml.parsers.DocumentBuilderFactory#newDefaultInstance() newDefaultInstance()}</td>
* <td style="text-align:center">{@link javax.xml.parsers.DocumentBuilderFactory#newInstance() newInstance()}</td>
* <td style="text-align:center">{@code javax.xml.parsers.DocumentBuilderFactory}</td>
* <td style="text-align:center"><a href="#JaxpProperties">jaxp.properties</a></td>
* <td style="text-align:center">{@link javax.xml.parsers.DocumentBuilderFactory#newDefaultInstance() newDefaultInstance()}</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="SAX">
* {@link javax.xml.parsers.SAXParserFactory SAXParserFactory}
* </th>
* <td>{@link javax.xml.parsers.SAXParserFactory#newInstance() newInstance()}</td>
* <td>{@code javax.xml.parsers.SAXParserFactory}</td>
* <td><a href="#JaxpProperties">jaxp.properties</a></td>
* <td>{@link javax.xml.parsers.SAXParserFactory#newDefaultInstance() newDefaultInstance()}</td>
* <td style="text-align:center">{@link javax.xml.parsers.SAXParserFactory#newInstance() newInstance()}</td>
* <td style="text-align:center">{@code javax.xml.parsers.SAXParserFactory}</td>
* <td style="text-align:center"><a href="#JaxpProperties">jaxp.properties</a></td>
* <td style="text-align:center">{@link javax.xml.parsers.SAXParserFactory#newDefaultInstance() newDefaultInstance()}</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="StAXEvent">
* {@link javax.xml.stream.XMLEventFactory XMLEventFactory}
* </th>
* <td>{@link javax.xml.stream.XMLEventFactory#newFactory() newFactory()}</td>
* <td>{@code javax.xml.stream.XMLEventFactory}</td>
* <td>
* <td style="text-align:center">{@link javax.xml.stream.XMLEventFactory#newFactory() newFactory()}</td>
* <td style="text-align:center">{@code javax.xml.stream.XMLEventFactory}</td>
* <td style="text-align:center">
* <a href="#StAXProperties">stax.properties</a> and then
* <a href="#JaxpProperties">jaxp.properties</a>
* </td>
* <td>{@link javax.xml.stream.XMLEventFactory#newDefaultFactory() newDefaultFactory()}</td>
* <td style="text-align:center">{@link javax.xml.stream.XMLEventFactory#newDefaultFactory() newDefaultFactory()}</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="StAXInput">
* {@link javax.xml.stream.XMLInputFactory XMLInputFactory}
* </th>
* <td>{@link javax.xml.stream.XMLInputFactory#newFactory() newFactory()}</td>
* <td>{@code javax.xml.stream.XMLInputFactory}</td>
* <td>
* <td style="text-align:center">{@link javax.xml.stream.XMLInputFactory#newFactory() newFactory()}</td>
* <td style="text-align:center">{@code javax.xml.stream.XMLInputFactory}</td>
* <td style="text-align:center">
* <a href="#StAXProperties">stax.properties</a> and then
* <a href="#JaxpProperties">jaxp.properties</a>
* </td>
* <td>{@link javax.xml.stream.XMLInputFactory#newDefaultFactory() newDefaultFactory()}</td>
* <td style="text-align:center">{@link javax.xml.stream.XMLInputFactory#newDefaultFactory() newDefaultFactory()}</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="StAXOutput">
* {@link javax.xml.stream.XMLOutputFactory XMLOutputFactory}
* </th>
* <td>{@link javax.xml.stream.XMLOutputFactory#newFactory() newFactory()}</td>
* <td>{@code javax.xml.stream.XMLOutputFactory}</td>
* <td>
* <td style="text-align:center">{@link javax.xml.stream.XMLOutputFactory#newFactory() newFactory()}</td>
* <td style="text-align:center">{@code javax.xml.stream.XMLOutputFactory}</td>
* <td style="text-align:center">
* <a href="#StAXProperties">stax.properties</a> and then
* <a href="#JaxpProperties">jaxp.properties</a>
* </td>
* <td>{@link javax.xml.stream.XMLOutputFactory#newDefaultFactory() newDefaultFactory()}</td>
* <td style="text-align:center">{@link javax.xml.stream.XMLOutputFactory#newDefaultFactory() newDefaultFactory()}</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="XSLT">
* {@link javax.xml.transform.TransformerFactory TransformerFactory}
* </th>
* <td>{@link javax.xml.transform.TransformerFactory#newInstance() newInstance()}</td>
* <td>{@code javax.xml.transform.TransformerFactory}</td>
* <td><a href="#JaxpProperties">jaxp.properties</a></td>
* <td>{@link javax.xml.transform.TransformerFactory#newDefaultInstance() newDefaultInstance()}</td>
* <td style="text-align:center">{@link javax.xml.transform.TransformerFactory#newInstance() newInstance()}</td>
* <td style="text-align:center">{@code javax.xml.transform.TransformerFactory}</td>
* <td style="text-align:center"><a href="#JaxpProperties">jaxp.properties</a></td>
* <td style="text-align:center">{@link javax.xml.transform.TransformerFactory#newDefaultInstance() newDefaultInstance()}</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="Validation">
* {@link javax.xml.validation.SchemaFactory SchemaFactory}
* </th>
* <td>{@link javax.xml.validation.SchemaFactory#newInstance(java.lang.String) newInstance(schemaLanguage)}</td>
* <td>{@code javax.xml.validation.SchemaFactory:}<i>schemaLanguage</i>[1]</td>
* <td><a href="#JaxpProperties">jaxp.properties</a></td>
* <td>{@link javax.xml.validation.SchemaFactory#newDefaultInstance() newDefaultInstance()}</td>
* <td style="text-align:center">{@link javax.xml.validation.SchemaFactory#newInstance(java.lang.String) newInstance(schemaLanguage)}</td>
* <td style="text-align:center">{@code javax.xml.validation.SchemaFactory:}<i>schemaLanguage</i>[1]</td>
* <td style="text-align:center"><a href="#JaxpProperties">jaxp.properties</a></td>
* <td style="text-align:center">{@link javax.xml.validation.SchemaFactory#newDefaultInstance() newDefaultInstance()}</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="XPath">
* {@link javax.xml.xpath.XPathFactory XPathFactory}
* </th>
* <td>{@link javax.xml.xpath.XPathFactory#newInstance(java.lang.String) newInstance(uri)}</td>
* <td>{@link javax.xml.xpath.XPathFactory#DEFAULT_PROPERTY_NAME DEFAULT_PROPERTY_NAME} + ":uri"[2]</td>
* <td><a href="#JaxpProperties">jaxp.properties</a></td>
* <td>{@link javax.xml.xpath.XPathFactory#newDefaultInstance() newDefaultInstance()}</td>
* <td style="text-align:center">{@link javax.xml.xpath.XPathFactory#newInstance(java.lang.String) newInstance(uri)}</td>
* <td style="text-align:center">{@link javax.xml.xpath.XPathFactory#DEFAULT_PROPERTY_NAME DEFAULT_PROPERTY_NAME} + ":uri"[2]</td>
* <td style="text-align:center"><a href="#JaxpProperties">jaxp.properties</a></td>
* <td style="text-align:center">{@link javax.xml.xpath.XPathFactory#newDefaultInstance() newDefaultInstance()}</td>
* </tr>
* </tbody>
* </table>
@ -231,22 +240,13 @@
* specific features and properties which the implementation currently supports
* can be found at the end of this note.
*
* <h3>Naming Convention</h3>
* <h3 id="NamingConvention">Naming Convention</h3>
* The names of the features and properties are fully qualified, composed of a
* prefix and name.
*
* <h4>Prefix</h4>
* The prefix for JDK properties is defined as:
* <pre>
* {@code http://www.oracle.com/xml/jaxp/properties/}
* </pre>
*
* The prefix for features:
* <pre>
* {@code http://www.oracle.com/xml/jaxp/features/}
* </pre>
*
* The prefix for System Properties:
* The prefix for JDK features and properties, as well as their corresponding
* System Properties if any, is defined as:
* <pre>
* {@code jdk.xml.}
* </pre>
@ -259,7 +259,7 @@
* An example of a property that indicates whether an XML document is standalone
* would thus have a format:
* <pre>
* {@code http://www.oracle.com/xml/jaxp/properties/isStandalone}
* {@code jdk.xml.isStandalone}
* </pre>
* and a corresponding System Property:
* <pre>
@ -267,9 +267,9 @@
* </pre>
*
* <h3>System Properties</h3>
* A property may have a corresponding System Property that has the same name
* except for the prefix as shown above. A System Property should be set prior
* to the creation of a processor and may be cleared afterwards.
* A property may have a corresponding System Property with the same name.
* A System Property should be set prior to the creation of a processor and
* may be cleared afterwards.
*
* <h3>jaxp.properties</h3>
* A system property can be specified in the <a href="#JaxpProperties">jaxp.properties</a>
@ -282,13 +282,15 @@
* <h3 id="ScopeAndOrder">Scope and Order</h3>
* The {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature
* (hereafter referred to as secure processing) is required for XML processors
* including DOM, SAX, Schema Validation, XSLT, and XPath. Any properties flagged
* including DOM, SAX, Schema Validation, XSLT, and XPath. When secure processing
* is set to true, security related features and properties, such as those flagged
* as {@code "security: yes"} (hereafter referred to as security properties) in
* table <a href="#Properties">Implementation Specific Properties</a>
* are enforced when secure processing is set to true. Such enforcement includes
* setting security features to true and limits to the defined values shown in
* the table. The property values will not be affected, however, when setting
* secure processing to false.
* table <a href="#Features">Implementation Specific Features</a> and
* <a href="#Properties">Properties</a>,
* are enforced. Such enforcement includes setting security properties and features
* to more restrictive values and limits as shown in {@code "Value"}'s
* subcolumn {@code "Enforced"} in the tables. When secure processing
* is set to false, however, the property values will not be affected.
* <p>
* When the Java Security Manager is present, secure processing is set to true
* and can not be turned off. The security properties are therefore enforced.
@ -316,30 +318,43 @@
* <th scope="col">ID</th>
* <th scope="col">Name</th>
* <th scope="col">How to set the property</th>
* <th scope="col">How to set the feature</th>
* </tr>
* </thead>
*
* <tbody>
* <tr>
* <th scope="row" style="font-weight:normal" id="DOM">DOM</th>
* <td>DOM Parser</td>
* <td style="text-align:center">DOM Parser</td>
* <td>
* {@code DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();}<br>
* {@code dbf.setAttribute(name, value);}
* </td>
* <td>
* {@code DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();}<br>
* {@code dbf.setFeature(name, value);}
* </td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="SAX">SAX</th>
* <td>SAX Parser</td>
* <td style="text-align:center">SAX Parser</td>
* <td>
* {@code SAXParserFactory spf = SAXParserFactory.newInstance();}<br>
* {@code SAXParser parser = spf.newSAXParser();}<br>
* {@code parser.setProperty(name, value);}
* </td>
* <td>
* {@code SAXParserFactory spf = SAXParserFactory.newInstance();}<br>
* {@code spf.setFeature(name, value);}<br>
* </td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="StAX">StAX</th>
* <td>StAX Parser</td>
* <td style="text-align:center">StAX Parser</td>
* <td>
* {@code XMLInputFactory xif = XMLInputFactory.newInstance();}<br>
* {@code xif.setProperty(name, value);}
* </td>
* <td>
* {@code XMLInputFactory xif = XMLInputFactory.newInstance();}<br>
* {@code xif.setProperty(name, value);}
@ -347,35 +362,57 @@
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="Validation">Validation</th>
* <td>XML Validation API</td>
* <td style="text-align:center">XML Validation API</td>
* <td>
* {@code SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);}<br>
* {@code schemaFactory.setProperty(name, value);}
* </td>
* <td>
* {@code SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);}<br>
* {@code schemaFactory.setFeature(name, value);}
* </td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="Transform">Transform</th>
* <td>XML Transform API</td>
* <td style="text-align:center">XML Transform API</td>
* <td>
* {@code TransformerFactory factory = TransformerFactory.newInstance();}<br>
* {@code factory.setAttribute(name, value);}
* </td>
* <td>
* {@code TransformerFactory factory = TransformerFactory.newInstance();}<br>
* {@code factory.setFeature(name, value);}
* </td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="XSLTCSerializer">XSLTC Serializer</th>
* <td>XSLTC Serializer</td>
* <td style="text-align:center">XSLTC Serializer</td>
* <td>
* {@code Transformer transformer = TransformerFactory.newInstance().newTransformer();}<br>
* {@code transformer.setOutputProperty(name, value);}
* </td>
* <td>
* </td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="DOMLS">DOMLS</th>
* <td>DOM Load and Save</td>
* <td style="text-align:center">DOM Load and Save</td>
* <td>
* {@code LSSerializer serializer = domImplementation.createLSSerializer();} <br>
* {@code serializer.getDomConfig().setParameter(name, value);}
* </td>
* <td>
* </td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="XPATH">XPath</th>
* <td style="text-align:center">XPath</td>
* <td>
* </td>
* <td>
* {@code XPathFactory factory = XPathFactory.newInstance();} <br>
* {@code factory.setFeature(name, value);}
* </td>
* </tr>
* </tbody>
* </table>
@ -392,120 +429,132 @@
* <caption>Implementation Specific Properties</caption>
* <thead>
* <tr>
* <th scope="col" rowspan="2">Name [1]</th>
* <th scope="col" rowspan="2">Full Name (<a href="#NamingConvention">prefix + name</a>)
* <a href="#Note1">[1]</a></th>
* <th scope="col" rowspan="2">Description</th>
* <th scope="col" rowspan="2">System Property [2]</th>
* <th scope="col" rowspan="2">jaxp.properties [2]</th>
* <th scope="col" colspan="3" style="text-align:center">Value [3]</th>
* <th scope="col" rowspan="2">Security [4]</th>
* <th scope="col" rowspan="2">Supported Processor [5]</th>
* <th scope="col" rowspan="2">Since [6]</th>
* <th scope="col" rowspan="2">System Property <a href="#Note2">[2]</a></th>
* <th scope="col" rowspan="2">jaxp.properties <a href="#Note2">[2]</a></th>
* <th scope="col" colspan="4" style="text-align:center">Value <a href="#Note3">[3]</a></th>
* <th scope="col" rowspan="2">Security <a href="#Note4">[4]</a></th>
* <th scope="col" rowspan="2">Supported Processor <a href="#Note5">[5]</a></th>
* <th scope="col" rowspan="2">Since <a href="#Note6">[6]</a></th>
* </tr>
* <tr>
* <th scope="col">Type</th>
* <th scope="col">Value</th>
* <th scope="col">Default</th>
* <th scope="col">Enforced</th>
* </tr>
* </thead>
*
* <tbody>
*
* <tr>
* <th scope="row" style="font-weight:normal" id="EELimit">entityExpansionLimit</th>
* <td id="EELimit">{@systemProperty jdk.xml.entityExpansionLimit}</td>
* <td>Limits the number of entity expansions.
* </td>
* <td rowspan="9">yes</td>
* <td rowspan="9">yes</td>
* <td rowspan="9">Integer</td>
* <th scope="row" style="font-weight:normal" rowspan="9">
* <td style="text-align:center" rowspan="9">yes</td>
* <td style="text-align:center" rowspan="9">yes</td>
* <td style="text-align:center" rowspan="9">Integer</td>
* <td rowspan="9">
* A positive integer. A value less than or equal to 0 indicates no limit.
* If the value is not an integer, a NumberFormatException is thrown.
* </th>
* <th scope="row" style="font-weight:normal">64000</th>
* <td rowspan="9">Yes</td>
* <td rowspan="9">
* </td>
* <td style="text-align:center">64000</td>
* <td style="text-align:center">64000</td>
* <td style="text-align:center" rowspan="9">Yes</td>
* <td style="text-align:center" rowspan="9">
* <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 rowspan="9">8</td>
* <td style="text-align:center" rowspan="9">8</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="EALimit">elementAttributeLimit</th>
* <td id="EALimit">{@systemProperty jdk.xml.elementAttributeLimit}</td>
* <td>Limits the number of attributes an element can have.
* </td>
* <th scope="row" style="font-weight:normal">10000</th>
* <td style="text-align:center">10000</td>
* <td style="text-align:center">10000</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="OccurLimit">maxOccurLimit</th>
* <td id="OccurLimit">{@systemProperty jdk.xml.maxOccurLimit}</td>
* <td>Limits the number of content model nodes that may be created when building
* a grammar for a W3C XML Schema that contains maxOccurs attributes with values
* other than "unbounded".
* </td>
* <th scope="row" style="font-weight:normal">5000</th>
* <td style="text-align:center">5000</td>
* <td style="text-align:center">5000</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="SizeLimit">totalEntitySizeLimit</th>
* <td id="SizeLimit">{@systemProperty jdk.xml.totalEntitySizeLimit}</td>
* <td>Limits the total size of all entities that include general and parameter
* entities. The size is calculated as an aggregation of all entities.
* </td>
* <th scope="row" style="font-weight:normal">5x10^7</th>
* <td style="text-align:center">5x10^7</td>
* <td style="text-align:center">5x10^7</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="GELimit">maxGeneralEntitySizeLimit</th>
* <td id="GELimit">{@systemProperty jdk.xml.maxGeneralEntitySizeLimit}</td>
* <td>Limits the maximum size of any general entities.
* </td>
* <th scope="row" style="font-weight:normal">0</th>
* <td style="text-align:center">0</td>
* <td style="text-align:center">0</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="PELimit">maxParameterEntitySizeLimit</th>
* <td id="PELimit">{@systemProperty jdk.xml.maxParameterEntitySizeLimit}</td>
* <td>Limits the maximum size of any parameter entities, including the result
* of nesting multiple parameter entities.
* </td>
* <th scope="row" style="font-weight:normal">10^6</th>
* <td style="text-align:center">10^6</td>
* <td style="text-align:center">10^6</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="ERLimit">entityReplacementLimit</th>
* <td id="ERLimit">{@systemProperty jdk.xml.entityReplacementLimit}</td>
* <td>Limits the total number of nodes in all entity references.
* </td>
* <th scope="row" style="font-weight:normal">3x10^6</th>
* <td style="text-align:center">3x10^6</td>
* <td style="text-align:center">3x10^6</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="ElementDepth">maxElementDepth</th>
* <td id="ElementDepth">{@systemProperty jdk.xml.maxElementDepth}</td>
* <td>Limits the maximum element depth.
* </td>
* <th scope="row" style="font-weight:normal">0</th>
* <td style="text-align:center">0</td>
* <td style="text-align:center">0</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="NameLimit">maxXMLNameLimit</th>
* <td id="NameLimit">{@systemProperty jdk.xml.maxXMLNameLimit}</td>
* <td>Limits the maximum size of XML names, including element name, attribute
* name and namespace prefix and URI.
* </td>
* <th scope="row" style="font-weight:normal">1000</th>
* <td style="text-align:center">1000</td>
* <td style="text-align:center">1000</td>
* </tr>
*
* <tr>
* <th scope="row" style="font-weight:normal" id="ISSTANDALONE">isStandalone</th>
* <td>indicates that the serializer should treat the output as a
* <td id="ISSTANDALONE">{@systemProperty jdk.xml.isStandalone}</td>
* <td>Indicates that the serializer should treat the output as a
* standalone document. The property can be used to ensure a newline is written
* after the XML declaration. Unlike the property
* {@link org.w3c.dom.ls.LSSerializer#getDomConfig() xml-declaration}, this property
* does not have an effect on whether an XML declaration should be written out.
* </td>
* <td>yes</td>
* <td>yes</td>
* <td>boolean</td>
* <th scope="row" style="font-weight:normal">true/false</th>
* <th scope="row" style="font-weight:normal">false</th>
* <td>No</td>
* <td><a href="#DOMLS">DOMLS</a></td>
* <td>17</td>
* <td style="text-align:center">yes</td>
* <td style="text-align:center">yes</td>
* <td style="text-align:center">boolean</td>
* <td style="text-align:center">true/false</td>
* <td style="text-align:center">false</td>
* <td style="text-align:center">N/A</td>
* <td style="text-align:center">No</td>
* <td style="text-align:center"><a href="#DOMLS">DOMLS</a></td>
* <td style="text-align:center">17</td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="XSLTCISSTANDALONE">xsltcIsStandalone</th>
* <td>indicates that the <a href="#XSLTCSerializer">XSLTC serializer</a> should
* <td id="XSLTCISSTANDALONE">{@systemProperty jdk.xml.xsltcIsStandalone}</td>
* <td>Indicates that the <a href="#XSLTCSerializer">XSLTC serializer</a> should
* treat the output as a standalone document. The property can be used to ensure
* a newline is written after the XML declaration. Unlike the property
* {@link javax.xml.transform.OutputKeys#OMIT_XML_DECLARATION OMIT_XML_DECLARATION},
@ -516,25 +565,145 @@
* except that it is for the <a href="#XSLTCSerializer">XSLTC Serializer</a>
* and its value is a String.
* </td>
* <td>yes</td>
* <td>yes</td>
* <td>String</td>
* <th scope="row" style="font-weight:normal">yes/no</th>
* <th scope="row" style="font-weight:normal">no</th>
* <td>No</td>
* <td><a href="#XSLTCSerializer">XSLTC Serializer</a></td>
* <td>17</td>
* <td style="text-align:center">yes</td>
* <td style="text-align:center">yes</td>
* <td style="text-align:center">String</td>
* <td style="text-align:center">yes/no</td>
* <td style="text-align:center">no</td>
* <td style="text-align:center">N/A</td>
* <td style="text-align:center">No</td>
* <td style="text-align:center"><a href="#XSLTCSerializer">XSLTC Serializer</a></td>
* <td style="text-align:center">17</td>
* </tr>
* <tr>
* <td id="cdataChunkSize">{@systemProperty jdk.xml.cdataChunkSize}</td>
* <td>Instructs the parser to return the data in a CData section in a single chunk
* when the property is zero or unspecified, or in multiple chunks when it is greater
* than zero. The parser shall split the data by linebreaks, and any chunks that are
* larger than the specified size to ones that are equal to or smaller than the size.
* </td>
* <td style="text-align:center">yes</td>
* <td style="text-align:center">yes</td>
* <td style="text-align:center">Integer</td>
* <td>A positive integer. A value less than
* or equal to 0 indicates that the property is not specified. If the value is not
* an integer, a NumberFormatException is thrown.</td>
* <td style="text-align:center">0</td>
* <td style="text-align:center">N/A</td>
* <td style="text-align:center">No</td>
* <td style="text-align:center"><a href="#SAX">SAX</a><br><a href="#StAX">StAX</a></td>
* <td style="text-align:center">9</td>
* </tr>
* <tr>
* <td id="extensionClassLoader">jdk.xml.extensionClassLoader</td>
* <td>Sets a non-null ClassLoader instance to be used for loading XSLTC java
* extension functions.
* </td>
* <td style="text-align:center">no</td>
* <td style="text-align:center">no</td>
* <td style="text-align:center">Object</td>
* <td>A reference to a ClassLoader object. Null if the value is not specified.</td>
* <td style="text-align:center">null</td>
* <td style="text-align:center">N/A</td>
* <td style="text-align:center">No</td>
* <td style="text-align:center"><a href="#Transform">Transform</a></td>
* <td style="text-align:center">9</td>
* </tr>
* </tbody>
* </table>
* <p>
* <b>[1]</b> The name of a property. The fully-qualified name, prefix + name,
* should be used when setting the property.
* <p>
* The table below lists the Implementation Specific Features currently supported
* by the JDK. More features may be added in the future if necessary.
*
* <table class="striped" id="Features">
* <caption>Implementation Specific Features</caption>
* <thead>
* <tr>
* <th scope="col" rowspan="2">Full Name (<a href="#NamingConvention">prefix + name</a>)
* <a href="#Note1">[1]</a></th>
* <th scope="col" rowspan="2">Description</th>
* <th scope="col" rowspan="2">System Property <a href="#Note2">[2]</a></th>
* <th scope="col" rowspan="2">jaxp.properties <a href="#Note2">[2]</a></th>
* <th scope="col" colspan="4" style="text-align:center">Value <a href="#Note3">[3]</a></th>
* <th scope="col" rowspan="2">Security <a href="#Note4">[4]</a></th>
* <th scope="col" rowspan="2">Supported Processor <a href="#Note5">[5]</a></th>
* <th scope="col" rowspan="2">Since <a href="#Note6">[6]</a></th>
* </tr>
* <tr>
* <th scope="col">Type</th>
* <th scope="col">Value</th>
* <th scope="col">Default</th>
* <th scope="col">Enforced</th>
* </tr>
* </thead>
* <tbody>
* <tr>
* <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="3">yes</td>
* <td style="text-align:center" rowspan="3">yes</td>
* <td style="text-align:center" rowspan="3">Boolean</td>
* <td>
* true or false. True indicates that extension functions are allowed; False otherwise.
* </td>
* <td style="text-align:center">true</td>
* <td style="text-align:center">false</td>
* <td style="text-align:center">Yes</td>
* <td style="text-align:center">
* <a href="#Transform">Transform</a><br>
* <a href="#XPAth">XPath</a>
* </td>
* <td style="text-align:center">8</td>
* </tr>
* <tr>
* <td id="ORParser">{@systemProperty jdk.xml.overrideDefaultParser}</td>
* <td>Enables the use of a 3rd party's parser implementation to override the
* system-default parser for the JDK's Transform, Validation and XPath implementations.
* </td>
* <td>
* true or false. True enables the use of 3rd party's parser implementations
* to override the system-default implementation during XML Transform, Validation
* or XPath operation. False disables the use of 3rd party's parser
* implementations.
* </td>
* <td style="text-align:center">false</td>
* <td style="text-align:center">false</td>
* <td style="text-align:center">Yes</td>
* <td style="text-align:center">
* <a href="#Transform">Transform</a><br>
* <a href="#Validation">Validation</a><br>
* <a href="#XPAth">XPath</a>
* </td>
* <td style="text-align:center">9</td>
* </tr>
* <tr>
* <td id="symbolTable">{@systemProperty jdk.xml.resetSymbolTable}</td>
* <td>Instructs the parser to reset its internal symbol table during each parse operation.
* </td>
* <td>
* true or false. True indicates that the SymbolTable associated with a parser needs to be
* reallocated during each parse operation.<br>
* False indicates that the parser's SymbolTable instance shall be reused
* during subsequent parse operations.
* </td>
* <td style="text-align:center">false</td>
* <td style="text-align:center">N/A</td>
* <td style="text-align:center">No</td>
* <td style="text-align:center">
* <a href="#SAX">SAX</a>
* </td>
* <td style="text-align:center">9</td>
* </tr>
* </tbody>
* </table>
* <p id="Note1">
* <b>[1]</b> The full name of a property should be used to set the property.
* <p id="Note2">
* <b>[2]</b> A value "yes" indicates there is a corresponding System Property
* for the property, "no" otherwise.
*
* <p>
* <p id="Note3">
* <b>[3]</b> The value must be exactly as listed in this table, case-sensitive.
* The value of the corresponding System Property is the String representation of
* the property value. If the type is boolean, the system property is true only
@ -544,17 +713,99 @@
* is Integer, the value of the System Property is the String representation of
* the value (e.g. "64000" for {@code entityExpansionLimit}).
*
* <p>
* <p id="Note4">
* <b>[4]</b> A value "yes" indicates the property is a Security Property. Refer
* to the <a href="#ScopeAndOrder">Scope and Order</a> on how secure processing
* may affect the value of a Security Property.
* <p>
* <p id="Note5">
* <b>[5]</b> One or more processors that support the property. The values of the
* field are IDs described in table <a href="#Processor">Processors</a>.
* <p>
* <p id="Note6">
* <b>[6]</b> Indicates the initial release the property is introduced.
*
* <h3>Legacy Property Names (deprecated)</h3>
* JDK releases prior to JDK 17 support the use of URI style prefix for properties.
* These legacy property names are <b>deprecated</b> as of JDK 17 and may be removed
* in future releases. If both new and legacy properties are set, the new property
* names take precedence regardless of how and where they are set. The overriding order
* as defined in <a href="#ScopeAndOrder">Scope and Order</a> thus becomes, in
* descending order:
*
* <ul>
* <li>The default value;</li>
* <li>Value set by FEATURE_SECURE_PROCESSING;</li>
* <li>Value set in jaxp.properties;</li>
* <li>Value set as System Property;</li>
* <li>Value set on factories or processors using <b>legacy property names</b>;</li>
* <li>Value set on factories or processors using new property names.</li>
* </ul>
* <p>
* The following table lists the properties and their corresponding legacy names.
*
* <table class="striped" id="LegacyProperties">
* <caption>Legacy Property Names (deprecated since 17)</caption>
* <thead>
* <tr>
* <th>Property</th>
* <th>Legacy Property Name(s)</th>
* </tr>
* </thead>
* <tbody>
* <tr>
* <td>{@systemProperty jdk.xml.entityExpansionLimit}</td>
* <td>{@code http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit}</td>
* </tr>
* <tr>
* <td>{@systemProperty jdk.xml.elementAttributeLimit}</td>
* <td>{@code http://www.oracle.com/xml/jaxp/properties/elementAttributeLimit}</td>
* </tr>
* <tr>
* <td>{@systemProperty jdk.xml.maxOccurLimit}</td>
* <td>{@code http://www.oracle.com/xml/jaxp/properties/maxOccurLimit}</td>
* </tr>
* <tr>
* <td>{@systemProperty jdk.xml.totalEntitySizeLimit}</td>
* <td>{@code http://www.oracle.com/xml/jaxp/properties/totalEntitySizeLimit}</td>
* </tr>
* <tr>
* <td>{@systemProperty jdk.xml.maxGeneralEntitySizeLimit}</td>
* <td>{@code http://www.oracle.com/xml/jaxp/properties/maxGeneralEntitySizeLimit}</td>
* </tr>
* <tr>
* <td>{@systemProperty jdk.xml.maxParameterEntitySizeLimit}</td>
* <td>{@code http://www.oracle.com/xml/jaxp/properties/maxParameterEntitySizeLimit}</td>
* </tr>
* <tr>
* <td>{@systemProperty jdk.xml.entityReplacementLimit}</td>
* <td>{@code http://www.oracle.com/xml/jaxp/properties/entityReplacementLimit}</td>
* </tr>
* <tr>
* <td>{@systemProperty jdk.xml.maxElementDepth}</td>
* <td>{@code http://www.oracle.com/xml/jaxp/properties/maxElementDepth}</td>
* </tr>
* <tr>
* <td>{@systemProperty jdk.xml.maxXMLNameLimit}</td>
* <td>{@code http://www.oracle.com/xml/jaxp/properties/maxXMLNameLimit}</td>
* </tr>
* <tr>
* <td>{@systemProperty jdk.xml.isStandalone}</td>
* <td>{@code http://www.oracle.com/xml/jaxp/properties/isStandalone}</td>
* </tr>
* <tr>
* <td>{@systemProperty jdk.xml.xsltcIsStandalone}</td>
* <td>{@code http://www.oracle.com/xml/is-standalone}<br>
* {@code http://www.oracle.com/xml/jaxp/properties/xsltcIsStandalone}</td>
* </tr>
* <tr>
* <td>{@code jdk.xml.extensionClassLoader}</td>
* <td>{@code jdk.xml.transform.extensionClassLoader}</td>
* </tr>
* <tr>
* <td>{@systemProperty jdk.xml.enableExtensionFunctions}</td>
* <td>{@code http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions}</td>
* </tr>
* </tbody>
* </table>
*
* @uses javax.xml.datatype.DatatypeFactory
* @uses javax.xml.parsers.DocumentBuilderFactory

View File

@ -0,0 +1,347 @@
/*
* Copyright (c) 2021, 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;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.Limit;
import java.util.EnumSet;
import java.util.Set;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.XMLInputFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.validation.SchemaFactory;
import javax.xml.xpath.XPathFactory;
import jdk.xml.internal.JdkProperty.ImplPropMap;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
import org.xml.sax.XMLReader;
/*
* @test
* @bug 8265248
* @modules java.xml/com.sun.org.apache.xerces.internal.utils
* @modules java.xml/jdk.xml.internal
* @run testng common.ImplPropertyTest
* @summary Verifies Implementation-specific Features and Properties as specified
* in the java.xml module summary.
*/
public class ImplPropertyTest {
private final DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultInstance();
private final XMLInputFactory xif = XMLInputFactory.newDefaultFactory();
private final SchemaFactory sf = SchemaFactory.newDefaultInstance();
private final XPathFactory xf = XPathFactory.newDefaultInstance();
// as in the Processors table in java.xml module summary
private enum Processor {
DOM,
SAX,
XMLREADER,
StAX,
VALIDATION,
TRANSFORM,
XSLTC,
DOMLS,
XPATH
};
/**
* Verifies both the new and legacy property names. This test runs two cases:
* a. sets legacy property first;
* b. sets new property first. Note the new property name is the same as that
* of the System property as of JDK 17.
* In both test cases, the expected return value shall be equal to the value
* set with the new property name.
* @throws Exception if the test fails
*/
@Test
public void testLimits() throws Exception {
// Supported processors for Limits
Set<Processor> pLimit = EnumSet.of(Processor.DOM, Processor.SAX, Processor.XMLREADER,
Processor.StAX, Processor.VALIDATION, Processor.TRANSFORM);
for (Limit limit : Limit.values()) {
for (Processor p : pLimit) {
testProperties(p, limit.apiProperty(), 100, limit.systemProperty(), 200, true);
}
}
}
// Supported processor for isStandalone: DOMLS
@Test
public void testIsStandalone() throws Exception {
testProperties(Processor.DOMLS, ImplPropMap.ISSTANDALONE.qName(), true,
ImplPropMap.ISSTANDALONE.systemProperty(), false, true);
}
// Supported processor for xsltcIsStandalone: XSLTC Serializer
@Test
public void testXSLTCIsStandalone() throws Exception {
testProperties(Processor.XSLTC, ImplPropMap.XSLTCISSTANDALONE.qName(), "no",
ImplPropMap.XSLTCISSTANDALONE.systemProperty(), "yes", true);
testProperties(Processor.XSLTC, ImplPropMap.XSLTCISSTANDALONE.qNameOld(), "no",
ImplPropMap.XSLTCISSTANDALONE.systemProperty(), "yes", true);
}
// Supported processor for cdataChunkSize: SAX and StAX
@Test
public void testCData() throws Exception {
// Supported processors for CDATA
Set<Processor> pCData = EnumSet.of(Processor.SAX, Processor.XMLREADER,
Processor.StAX);
ImplPropMap CDATA = ImplPropMap.CDATACHUNKSIZE;
for (Processor p : pCData) {
testProperties(p, CDATA.qName(), 100, CDATA.systemProperty(), 200, false);
}
}
// Supported processor for extensionClassLoader: Transform
@Test
public void testExtensionClassLoader() throws Exception {
ImplPropMap ECL = ImplPropMap.EXTCLSLOADER;
TestCL cl1 = new TestCL("testClassLoader1");
TestCL cl2 = new TestCL("testClassLoader2");
testProperties(Processor.TRANSFORM, ECL.qNameOld(), cl1, ECL.qName(), cl2, true);
}
// Supported processor for feature enableExtensionFunctions: Transform, XPath
@Test
public void testEnableExtensionFunctions() throws Exception {
Set<Processor> pEEF = EnumSet.of(Processor.TRANSFORM, Processor.XPATH);
ImplPropMap EEF = ImplPropMap.ENABLEEXTFUNC;
for (Processor p : pEEF) {
testFeatures(p, EEF.qName(), true, EEF.systemProperty(), false, EEF.isNameDiffer());
}
}
// Supported processor for feature overrideDefaultParser: Transform, Validation, XPath
@Test
public void testOverrideDefaultParser() throws Exception {
Set<Processor> pEEF = EnumSet.of(Processor.TRANSFORM, Processor.VALIDATION, Processor.XPATH);
ImplPropMap ODP = ImplPropMap.OVERRIDEPARSER;
for (Processor p : pEEF) {
testFeatures(p, ODP.qName(), true, ODP.systemProperty(), false, ODP.isNameDiffer());
}
}
// Supported processor for feature resetSymbolTable: SAX
@Test
public void testResetSymbolTable() throws Exception {
ImplPropMap RST = ImplPropMap.RESETSYMBOLTABLE;
testFeatures(Processor.SAX, RST.qName(), true, RST.systemProperty(), false, RST.isNameDiffer());
}
/**
* Tests properties. Two assertions:
* (1) verifies the old property is still supported;
* (2) verifies the new property name takes preference.
*
* @param processor the processor to be tested
* @param name1 the old property name
* @param value1 the value to be set with name1
* @param name2 the new property name
* @param value2 the value to be set with name2
* @param differ a flag indicating whether name1 and name2 differ
* @throws Exception if the test fails
*/
private void testProperties(Processor processor, String name1, Object value1,
String name2, Object value2, boolean differ)
throws Exception {
Object ret1 = null;
Object ret2 = null;
switch (processor) {
case DOM:
dbf.setAttribute(name1, value1);
ret1 = dbf.getAttribute(name1);
if (differ) {
dbf.setAttribute(name2, value2);
dbf.setAttribute(name1, value1);
ret2 = dbf.getAttribute(name2);
}
break;
case SAX:
SAXParser sp = SAXParserFactory.newDefaultInstance().newSAXParser();
sp.setProperty(name1, value1);
ret1 = sp.getProperty(name1);
if (differ) {
sp.setProperty(name2, value2);
sp.setProperty(name1, value1);
ret2 = sp.getProperty(name2);
}
break;
case XMLREADER:
XMLReader reader = SAXParserFactory.newDefaultInstance().newSAXParser().getXMLReader();
reader.setProperty(name1, value1);
ret1 = reader.getProperty(name1);
if (differ) {
reader.setProperty(name2, value2);
reader.setProperty(name1, value1);
ret2 = reader.getProperty(name2);
}
break;
case StAX:
xif.setProperty(name1, value1);
ret1 = xif.getProperty(name1);
if (differ) {
xif.setProperty(name2, value2);
xif.setProperty(name1, value1);
ret2 = xif.getProperty(name2);
}
break;
case VALIDATION:
sf.setProperty(name1, value1);
ret1 = sf.getProperty(name1);
if (differ) {
sf.setProperty(name2, value2);
sf.setProperty(name1, value1);
ret2 = sf.getProperty(name2);
}
break;
case TRANSFORM:
TransformerFactory tf = TransformerFactory.newDefaultInstance();
tf.setAttribute(name1, value1);
ret1 = tf.getAttribute(name1);
if (differ) {
tf.setAttribute(name2, value2);
tf.setAttribute(name1, value1);
ret2 = tf.getAttribute(name2);
}
break;
case XSLTC:
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(name1, (String)value1);
ret1 = transformer.getOutputProperty(name1);
if (differ) {
transformer.setOutputProperty(name2, (String)value2);
transformer.setOutputProperty(name1, (String)value1);
ret2 = transformer.getOutputProperty(name2);
}
break;
case DOMLS:
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
LSSerializer serializer = impl.createLSSerializer();
DOMConfiguration domConfig = serializer.getDomConfig();
domConfig.setParameter(name1, value1);
ret1 = domConfig.getParameter(name1);
if (differ) {
domConfig.setParameter(name2, value2);
domConfig.setParameter(name1, value1);
ret2 = domConfig.getParameter(name2);
}
break;
case XPATH:
break;
}
if ((value1 instanceof Integer) && ret1 instanceof String) {
ret1 = Integer.parseInt((String)ret1);
ret2 = Integer.parseInt((String)ret2);
}
// name1 is set, expected return value: value1 (set with the old name)
Assert.assertEquals(ret1, value1);
if (differ) {
// if both are set, expected value: value2 (set with the new name)
Assert.assertEquals(ret2, value2);
}
}
private void testFeatures(Processor processor, String name1, boolean value1,
String name2, boolean value2, boolean differ)
throws Exception {
boolean ret1 = false, ret2 = false;
switch (processor) {
case DOM:
dbf.setFeature(name1, value1);
Assert.assertEquals(dbf.getFeature(name1), value1);
if (differ) {
dbf.setFeature(name2, value2);
dbf.setFeature(name1, value1);
Assert.assertEquals(dbf.getFeature(name2), value2);
}
return;
case SAX:
SAXParserFactory spf = SAXParserFactory.newDefaultInstance();
spf.setFeature(name1, value1);
Assert.assertEquals(spf.getFeature(name1), value1);
if (differ) {
spf.setFeature(name2, value2);
spf.setFeature(name1, value1);
Assert.assertEquals(spf.getFeature(name2), value2);
}
return;
case VALIDATION:
sf.setFeature(name1, value1);
Assert.assertEquals(sf.getFeature(name1), value1);
if (differ) {
sf.setFeature(name2, value2);
sf.setFeature(name1, value1);
Assert.assertEquals(sf.getFeature(name2), value2);
}
return;
case TRANSFORM:
TransformerFactory tf = TransformerFactory.newDefaultInstance();
tf.setFeature(name1, value1);
Assert.assertEquals(tf.getFeature(name1), value1);
if (differ) {
tf.setFeature(name2, value2);
tf.setFeature(name1, value1);
Assert.assertEquals(tf.getFeature(name2), value2);
}
return;
case XPATH:
xf.setFeature(name1, value1);
Assert.assertEquals(xf.getFeature(name1), value1);
if (differ) {
xf.setFeature(name2, value2);
xf.setFeature(name1, value1);
Assert.assertEquals(xf.getFeature(name2), value2);
}
return;
}
Assert.fail("Failed setting features for : " + processor);
}
class TestCL extends ClassLoader {
String name;
public TestCL(String name) {
this.name = name;
}
public Class<?> loadClass(String name) throws ClassNotFoundException {
throw new ClassNotFoundException( name );
}
}
}