下面列出了怎么用org.xml.sax.SAXNotSupportedException的API类实例代码及写法,或者点击链接到github查看源代码。
public void setProperty(String name, Object object)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name == null) {
throw new NullPointerException();
}
try {
fComponentManager.setProperty(name, object);
}
catch (XMLConfigurationException e) {
final String identifier = e.getIdentifier();
final String key = e.getType() == Status.NOT_RECOGNIZED ?
"property-not-recognized" : "property-not-supported";
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fComponentManager.getLocale(),
key, new Object [] {identifier}));
}
fConfigurationChanged = true;
}
public boolean getFeature(String name)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Features.NAMESPACES_FEATURE)) {
return true;
} else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) {
return _namespacePrefixesFeature;
} else if (name.equals(Features.EXTERNAL_GENERAL_ENTITIES)) {
return true;
} else if (name.equals(Features.EXTERNAL_PARAMETER_ENTITIES)) {
return true;
} else if (name.equals(Features.STRING_INTERNING_FEATURE)) {
return _stringInterningFeature;
} else {
throw new SAXNotRecognizedException(
"Feature not supported: " + name);
}
}
@Override
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
if (NAMESPACES_FEATURE_NAME.equals(name)) {
return this.namespacesFeature;
}
else if (NAMESPACE_PREFIXES_FEATURE_NAME.equals(name)) {
return this.namespacePrefixesFeature;
}
else if (IS_STANDALONE_FEATURE_NAME.equals(name)) {
if (this.isStandalone != null) {
return this.isStandalone;
}
else {
throw new SAXNotSupportedException("startDocument() callback not completed yet");
}
}
else {
return super.getFeature(name);
}
}
private void setSchemaValidatorProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
try {
fSAXParser.fSchemaValidator.setProperty(name, value);
}
// This should never be thrown from the schema validator.
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
if (e.getType() == Status.NOT_RECOGNIZED) {
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
"property-not-recognized", new Object [] {identifier}));
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
"property-not-supported", new Object [] {identifier}));
}
}
}
public void setFeature(String name, boolean value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Features.NAMESPACES_FEATURE)) {
if (value == false) {
throw new SAXNotSupportedException(name + ":" + value);
}
} else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) {
_namespacePrefixesFeature = value;
} else if (name.equals(Features.STRING_INTERNING_FEATURE) ||
name.equals(FastInfosetReader.STRING_INTERNING_PROPERTY)) {
setStringInterning(value);
} else {
throw new SAXNotRecognizedException(
CommonResourceBundle.getInstance().getString("message.featureNotSupported") + name);
}
}
/**
* The dyn:evaluate function evaluates a string as an XPath expression and returns
* the resulting value, which might be a boolean, number, string, node set, result
* tree fragment or external object. The sole argument is the string to be evaluated.
* <p>
* If the expression string passed as the second argument is an invalid XPath
* expression (including an empty string), this function returns an empty node set.
* <p>
* You should only use this function if the expression must be constructed dynamically,
* otherwise it is much more efficient to use the expression literally.
*
* @param myContext The ExpressionContext passed by the extension processor
* @param xpathExpr The XPath expression string
*
* @return The evaluation result
*/
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
throws SAXNotSupportedException
{
if (myContext instanceof XPathContext.XPathExpressionContext)
{
XPathContext xctxt = null;
try
{
xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
xctxt.getNamespaceContext(),
XPath.SELECT);
return dynamicXPath.execute(xctxt, myContext.getContextNode(),
xctxt.getNamespaceContext());
}
catch (TransformerException e)
{
return new XNodeSet(xctxt.getDTMManager());
}
}
else
throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
public void setProperty0(String propertyId, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
try {
fConfiguration.setProperty(propertyId, value);
}
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
if (e.getType() == Status.NOT_RECOGNIZED) {
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
"property-not-recognized", new Object [] {identifier}));
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
"property-not-supported", new Object [] {identifier}));
}
}
}
public boolean getFeature(String name)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name == null) {
throw new NullPointerException();
}
try {
return fComponentManager.getFeature(name);
}
catch (XMLConfigurationException e) {
final String identifier = e.getIdentifier();
final String key = e.getType() == Status.NOT_RECOGNIZED ?
"feature-not-recognized" : "feature-not-supported";
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fComponentManager.getLocale(),
key, new Object [] {identifier}));
}
}
public Object getProperty(String name)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name == null) {
throw new NullPointerException();
}
//Support current-element-node; return current node if DOMSource is used.
if (CURRENT_ELEMENT_NODE.equals(name)) {
return (fDOMValidatorHelper != null) ? fDOMValidatorHelper.getCurrentElement() : null;
}
try {
return fComponentManager.getProperty(name);
}
catch (XMLConfigurationException e) {
final String identifier = e.getIdentifier();
final String key = e.getType() == Status.NOT_RECOGNIZED ?
"property-not-recognized" : "property-not-supported";
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fComponentManager.getLocale(),
key, new Object [] {identifier}));
}
}
public void setProperty(String name, Object object)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name == null) {
throw new NullPointerException();
}
try {
fComponentManager.setProperty(name, object);
}
catch (XMLConfigurationException e) {
final String identifier = e.getIdentifier();
final String key = e.getType() == Status.NOT_RECOGNIZED ?
"property-not-recognized" : "property-not-supported";
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fComponentManager.getLocale(),
key, new Object [] {identifier}));
}
fConfigurationChanged = true;
}
public boolean getFeature(String name)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name == null) {
throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(),
"FeatureNameNull", null));
}
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
return (fSecurityManager != null && fSecurityManager.isSecureProcessing());
}
try {
return fXMLSchemaLoader.getFeature(name);
}
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
if (e.getType() == Status.NOT_RECOGNIZED) {
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(),
"feature-not-recognized", new Object [] {identifier}));
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(),
"feature-not-supported", new Object [] {identifier}));
}
}
}
public boolean getFeature(String name)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name == null) {
throw new NullPointerException();
}
try {
return fComponentManager.getFeature(name);
}
catch (XMLConfigurationException e) {
final String identifier = e.getIdentifier();
final String key = e.getType() == Status.NOT_RECOGNIZED ?
"feature-not-recognized" : "feature-not-supported";
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fComponentManager.getLocale(),
key, new Object [] {identifier}));
}
}
public boolean getFeature(String name)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name == null) {
throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(),
"FeatureNameNull", null));
}
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
return (fSecurityManager != null && fSecurityManager.isSecureProcessing());
}
try {
return fXMLSchemaLoader.getFeature(name);
}
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
if (e.getType() == Status.NOT_RECOGNIZED) {
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(),
"feature-not-recognized", new Object [] {identifier}));
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(),
"feature-not-supported", new Object [] {identifier}));
}
}
}
private void setSchemaValidatorProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
try {
fSAXParser.fSchemaValidator.setProperty(name, value);
}
// This should never be thrown from the schema validator.
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
if (e.getType() == Status.NOT_RECOGNIZED) {
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
"property-not-recognized", new Object [] {identifier}));
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
"property-not-supported", new Object [] {identifier}));
}
}
}
public synchronized Object getProperty(String name)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name == null) {
// TODO: Add localized error message.
throw new NullPointerException();
}
if (fSAXParser != null && JAXP_SCHEMA_LANGUAGE.equals(name)) {
// JAXP 1.2 support
return fSAXParser.schemaLanguage;
}
/** Check to see if the property is managed by the security manager **/
String propertyValue = (fSecurityManager != null) ?
fSecurityManager.getLimitAsString(name) : null;
if (propertyValue != null) {
return propertyValue;
} else {
propertyValue = (fSecurityPropertyMgr != null) ?
fSecurityPropertyMgr.getValue(name) : null;
if (propertyValue != null) {
return propertyValue;
}
}
return super.getProperty(name);
}
public void setProperty(String name, Object object)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name == null) {
throw new NullPointerException();
}
try {
fComponentManager.setProperty(name, object);
}
catch (XMLConfigurationException e) {
final String identifier = e.getIdentifier();
final String key = e.getType() == Status.NOT_RECOGNIZED ?
"property-not-recognized" : "property-not-supported";
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fComponentManager.getLocale(),
key, new Object [] {identifier}));
}
}
/**
* This implementation throws a {@code SAXNotRecognizedException} exception
* for any feature outside of the "http://xml.org/sax/features/" namespace
* and accepts a {@code false} value for any feature within.
*/
@Override
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.startsWith("http://xml.org/sax/features/")) {
if (value) {
throw new SAXNotSupportedException(name);
}
}
else {
throw new SAXNotRecognizedException(name);
}
}
/**
* Throws a {@code SAXNotRecognizedException} exception when the given property does not signify a lexical
* handler. The property name for a lexical handler is {@code http://xml.org/sax/properties/lexical-handler}.
*/
@Override
@Nullable
public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
if ("http://xml.org/sax/properties/lexical-handler".equals(name)) {
return this.lexicalHandler;
}
else {
throw new SAXNotRecognizedException(name);
}
}
/**
* Throws a {@code SAXNotRecognizedException} exception when the given property does not signify a lexical
* handler. The property name for a lexical handler is {@code http://xml.org/sax/properties/lexical-handler}.
*/
@Override
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
if ("http://xml.org/sax/properties/lexical-handler".equals(name)) {
this.lexicalHandler = (LexicalHandler) value;
}
else {
throw new SAXNotRecognizedException(name);
}
}
@Override
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
if (NAMESPACES_FEATURE_NAME.equals(name)) {
this.namespacesFeature = value;
}
else if (NAMESPACE_PREFIXES_FEATURE_NAME.equals(name)) {
this.namespacePrefixesFeature = value;
}
else {
super.setFeature(name, value);
}
}
@Override
public synchronized void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
if (XMLConstants.ACCESS_EXTERNAL_DTD.equals(name) || ENT_EXP_LIMIT_PROP.equals(name)) {
throw new SAXNotRecognizedException(name+" property is not recognised by test SAX parser intentionally.");
} else {
super.setProperty(name, value);
}
}
/**
* Configure the parser to allow access to DTDs on the file system.
*/
private static void enableFileAccess(SAXParser parser) throws SAXNotSupportedException {
try {
parser.setProperty("http://javax.xml.XMLConstants/property/accessExternalDTD", "file");
} catch (SAXNotRecognizedException ignore) {
// property requires >= JAXP 1.5
}
}
@Override
public synchronized void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(name)) {
throw new SAXNotRecognizedException(name+" feature is not recognised by test SAX parser intentionally.");
} else {
super.setFeature(name, value);
}
}
public void setProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) {
if (value instanceof LexicalHandler) {
setLexicalHandler((LexicalHandler)value);
} else {
throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY);
}
} else {
throw new SAXNotRecognizedException("Property not recognized: " + name);
}
}
/**
* Query the state of a feature.
*
* Query the current state of any feature in a SAX2 parser. The
* parser might not recognize the feature.
*
* @param featureId The unique identifier (URI) of the feature
* being set.
* @return The current state of the feature.
* @exception org.xml.sax.SAXNotRecognizedException If the
* requested feature is not known.
* @exception SAXNotSupportedException If the
* requested feature is known but not supported.
*/
public boolean getFeature(String featureId)
throws SAXNotRecognizedException, SAXNotSupportedException {
try {
// http://xml.org/sax/features/use-entity-resolver2
// controls whether the methods of an object implementing
// org.xml.sax.ext.EntityResolver2 will be used by the parser.
//
if (featureId.equals(USE_ENTITY_RESOLVER2)) {
return fUseEntityResolver2;
}
//
// Default handling
//
return fConfiguration.getFeature(featureId);
}
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
if (e.getType() == Status.NOT_RECOGNIZED) {
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
"feature-not-recognized", new Object [] {identifier}));
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
"feature-not-supported", new Object [] {identifier}));
}
}
}
/**
* Sets the XMLReader instance with the specified property if the the
* property is supported, ignores error if not, issues a warning if so
* requested.
*
* @param reader an XMLReader instance
* @param property the name of the property
* @param value the value of the property
* @param warn a flag indicating whether a warning should be issued
*/
public static void setXMLReaderPropertyIfSupport(XMLReader reader, String property,
Object value, boolean warn) {
try {
reader.setProperty(property, value);
} catch (SAXNotRecognizedException | SAXNotSupportedException e) {
if (warn) {
XMLSecurityManager.printWarning(reader.getClass().getName(),
property, e);
}
}
}
/**
* Set the state of any feature in a SAX2 parser. The parser
* might not recognize the feature, and if it does recognize
* it, it might not be able to fulfill the request.
*
* @param featureId The unique identifier (URI) of the feature.
* @param state The requested state of the feature (true or false).
*
* @exception SAXNotRecognizedException If the
* requested feature is not known.
* @exception SAXNotSupportedException If the
* requested feature is known, but the requested
* state is not supported.
*/
public void setFeature(String featureId, boolean state)
throws SAXNotRecognizedException, SAXNotSupportedException {
try {
// http://xml.org/sax/features/use-entity-resolver2
// controls whether the methods of an object implementing
// org.xml.sax.ext.EntityResolver2 will be used by the parser.
//
if (featureId.equals(USE_ENTITY_RESOLVER2)) {
if (state != fUseEntityResolver2) {
fUseEntityResolver2 = state;
// Refresh EntityResolver wrapper.
setEntityResolver(getEntityResolver());
}
return;
}
//
// Default handling
//
fConfiguration.setFeature(featureId, state);
}
catch (XMLConfigurationException e) {
String identifier = e.getIdentifier();
if (e.getType() == Status.NOT_RECOGNIZED) {
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
"feature-not-recognized", new Object [] {identifier}));
}
else {
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
"feature-not-supported", new Object [] {identifier}));
}
}
}
public void setFeature(String name, boolean value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name == null) {
throw new NullPointerException();
}
try {
fComponentManager.setFeature(name, value);
}
catch (XMLConfigurationException e) {
final String identifier = e.getIdentifier();
final String key;
if (e.getType() == Status.NOT_ALLOWED) {
//for now, the identifier can only be (XMLConstants.FEATURE_SECURE_PROCESSING)
throw new SAXNotSupportedException(
SAXMessageFormatter.formatMessage(fComponentManager.getLocale(),
"jaxp-secureprocessing-feature", null));
} else if (e.getType() == Status.NOT_RECOGNIZED) {
key = "feature-not-recognized";
} else {
key = "feature-not-supported";
}
throw new SAXNotRecognizedException(
SAXMessageFormatter.formatMessage(fComponentManager.getLocale(),
key, new Object [] {identifier}));
}
fConfigurationChanged = true;
}
/**
* This implementation throws a {@code SAXNotRecognizedException} exception
* for any feature outside of the "http://xml.org/sax/features/" namespace
* and returns {@code false} for any feature within.
*/
@Override
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.startsWith("http://xml.org/sax/features/")) {
return false;
}
else {
throw new SAXNotRecognizedException(name);
}
}
private void setFeatures( Map<String, Boolean> features)
throws SAXNotSupportedException, SAXNotRecognizedException {
if (features != null) {
for (Map.Entry<String, Boolean> entry : features.entrySet()) {
domParser.setFeature(entry.getKey(), entry.getValue());
}
}
}