/** * Configure schema validation as recommended by the JAXP 1.2 spec. * The <code>properties</code> object may contains information about * the schema local and language. * @param properties parser optional info */ private static void configureOldXerces(SAXParser parser, Properties properties) throws ParserConfigurationException, SAXNotSupportedException { String schemaLocation = (String)properties.get("schemaLocation"); String schemaLanguage = (String)properties.get("schemaLanguage"); try{ if (schemaLocation != null) { parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage); parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation); } } catch (SAXNotRecognizedException e){ log.info(parser.getClass().getName() + ": " + e.getMessage() + " not supported."); } }
/** * Configure schema validation as recommended by the JAXP 1.2 spec. The * <code>properties</code> object may contains information about the schema * local and language. * * @param properties * parser optional info */ private static void configureOldXerces(SAXParser parser, Properties properties) throws ParserConfigurationException, SAXNotSupportedException { String schemaLocation = (String) properties.get("schemaLocation"); String schemaLanguage = (String) properties.get("schemaLanguage"); try { if (schemaLocation != null) { parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage); parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation); } } catch (SAXNotRecognizedException e) { log.info(parser.getClass().getName() + ": " + e.getMessage() + " not supported."); } }
/** * Create a <code>SAXParser</code> based on the underlying * <code>Xerces</code> version. * @param properties parser specific properties/features * @return an XML Schema/DTD enabled <code>SAXParser</code> */ public static SAXParser newSAXParser(Properties properties) throws ParserConfigurationException, SAXException, SAXNotSupportedException { SAXParserFactory factory = (SAXParserFactory)properties.get("SAXParserFactory"); if (versionNumber == null){ versionNumber = getXercesVersion(); version = Float.parseFloat(versionNumber); } // Note: 2.2 is completely broken (with XML Schema). if (version > 2.1) { configureXerces(factory); return factory.newSAXParser(); } else { SAXParser parser = factory.newSAXParser(); configureOldXerces(parser,properties); return parser; } }
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 Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) { return getLexicalHandler(); } else if (name.equals(Properties.DTD_DECLARATION_HANDLER_PROPERTY)) { return getDeclHandler(); } else if (name.equals(FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY)) { return getExternalVocabularies(); } else if (name.equals(FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY)) { return getRegisteredEncodingAlgorithms(); } else if (name.equals(FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY)) { return getEncodingAlgorithmContentHandler(); } else if (name.equals(FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY)) { return getPrimitiveTypeContentHandler(); } else { throw new SAXNotRecognizedException(CommonResourceBundle.getInstance(). getString("message.propertyNotRecognized", new Object[]{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 static SAXParserFactory newSAXParserFactory(boolean disableSecurity) { SAXParserFactory factory = SAXParserFactory.newInstance(); String featureToSet = XMLConstants.FEATURE_SECURE_PROCESSING; try { boolean securityOn = !xmlSecurityDisabled(disableSecurity); factory.setFeature(featureToSet, securityOn); factory.setNamespaceAware(true); if (securityOn) { featureToSet = DISALLOW_DOCTYPE_DECL; factory.setFeature(featureToSet, true); featureToSet = EXTERNAL_GE; factory.setFeature(featureToSet, false); featureToSet = EXTERNAL_PE; factory.setFeature(featureToSet, false); featureToSet = LOAD_EXTERNAL_DTD; factory.setFeature(featureToSet, false); } } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) { LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support "+featureToSet+" feature!", new Object[]{factory.getClass().getName()}); } return factory; }
/** * Set a feature flag for the parser. * * <p>The only features recognized are namespaces and * namespace-prefixes.</p> * * @param name The feature name, as a complete URI. * @param value The requested feature value. * @exception SAXNotRecognizedException If the feature * can't be assigned or retrieved. * @exception SAXNotSupportedException If the feature * can't be assigned that value. * @see org.xml.sax.XMLReader#setFeature */ public void setFeature (String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { if (name.equals(NAMESPACES)) { checkNotParsing("feature", name); namespaces = value; if (!namespaces && !prefixes) { prefixes = true; } } else if (name.equals(NAMESPACE_PREFIXES)) { checkNotParsing("feature", name); prefixes = value; if (!prefixes && !namespaces) { namespaces = true; } } else if (name.equals(XMLNS_URIs)) { checkNotParsing("feature", name); uris = value; } else { throw new SAXNotRecognizedException("Feature: " + name); } }
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})); } }
private void setFeature(SAXParserFactory factory, String feature, boolean enable) { try { if (ADDITIONAL_FEATURE_X_INCLUDE_AWARE.equals(feature)) { factory.setXIncludeAware(enable); } else if (!ADDITIONAL_FEATURE_EXPAND_ENTITY_REFERENCES.equals(feature)) // Does not exist on SAXParserFactory { factory.setFeature(feature, enable); } debug(debugCounter+" SAXParserFactory "+feature+" "+enable); } catch (ParserConfigurationException | SAXNotSupportedException | SAXNotRecognizedException e) { logConfigurationFailure(factory.getClass().getName(), feature, e); } }
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})); } }
/** * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) */ @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (this.currentTag != null) { this.currentTag.startElement(uri, localName, qName, attributes); } else if (ROOTS.contains(localName)) { this.currentTag = new RootTag(); } else if (IMPORT.equals(localName)) { // TODO SLT: There's something fishy with the parser, with the currentTag getting hosed if you import twice try { parser.parseDictionary(new URL(baseDir, attributes.getValue(0))); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } } else { throw new SAXNotSupportedException("bad tag:" + localName); } }
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; }
@Override void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (NOUN.equals(localName)) { currentTag = new NounTag(this, attributes); } else if (ADJECTIVE.equals(localName)) { currentTag = new AdjectiveTag(this, attributes); } else if (ARTICLE.equals(localName)) { currentTag = new ArticleTag(this, attributes); } else if (IMPORT.equals(localName)) { try { parser.parseDictionary(new URL(baseDir, attributes.getValue(0))); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } } else { throw new SAXNotSupportedException("bad tag:" + localName); } }
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); }
/** * Return the SAXParserFactory we will use, creating one if necessary. * * @throws ParserConfigurationException * @throws SAXNotSupportedException * @throws SAXNotRecognizedException */ public SAXParserFactory getFactory() throws SAXNotRecognizedException, SAXNotSupportedException, ParserConfigurationException { if (factory == null) { factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(namespaceAware); // Preserve xmlns attributes if (namespaceAware) { factory.setFeature("http://xml.org/sax/features/namespace-prefixes", true); } factory.setValidating(validating); if (validating) { // Enable DTD validation factory.setFeature("http://xml.org/sax/features/validation", true); // Enable schema validation factory.setFeature("http://apache.org/xml/features/validation/schema", true); } } return (factory); }
/** * Return the SAXParserFactory we will use, creating one if necessary. * @throws ParserConfigurationException * @throws SAXNotSupportedException * @throws SAXNotRecognizedException */ public SAXParserFactory getFactory() throws SAXNotRecognizedException, SAXNotSupportedException, ParserConfigurationException { if (factory == null) { factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(namespaceAware); // Preserve xmlns attributes if (namespaceAware) { factory.setFeature( "http://xml.org/sax/features/namespace-prefixes", true); } factory.setValidating(validating); if (validating) { // Enable DTD validation factory.setFeature( "http://xml.org/sax/features/validation", true); // Enable schema validation factory.setFeature( "http://apache.org/xml/features/validation/schema", true); } } return (factory); }
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { if (LEXICAL_HANDLER_PROP.equals(name)) { lexicalHandler = (LexicalHandler) value; } else { super.setProperty(name, value); } }
/** * @see com.oxygenxml.translation.support.util.ParserCreator#createXMLReader() */ public XMLReader createXMLReader() throws SAXNotRecognizedException, SAXNotSupportedException, ParserConfigurationException, SAXException { XMLReaderWithGrammar bundle = access.newNonValidatingXMLReader(grammar); // Keep the grammar. grammar = bundle.getGrammarCache(); return bundle.getXmlReader(); }
/** * Configure schema validation as recommended by the Xerces spec. * Both DTD and Schema validation will be enabled simultaneously. * @param factory SAXParserFactory to be configured */ private static void configureXerces(SAXParserFactory factory) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { factory.setFeature(XERCES_DYNAMIC, true); factory.setFeature(XERCES_SCHEMA, true); }
@Test public void test01() throws SAXNotRecognizedException, SAXNotSupportedException { try { schemaFactory.getFeature(null); Assert.fail("exception expected"); } catch (NullPointerException e) { ; // expected } }
/** * Configure schema validation as recommended by the Xerces spec. Both DTD * and Schema validation will be enabled simultaneously. * * @param factory * SAXParserFactory to be configured */ private static void configureXerces(SAXParserFactory factory) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { factory.setFeature(XERCES_DYNAMIC, true); factory.setFeature(XERCES_SCHEMA, true); }
public void setFeature(final String name, final boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { if (name.equals(NAMESPACES)) { namespaces = value; } else if (name.equals(NAMESPACE_PREFIXES)) { namespacePrefixes = value; } else { throw new SAXNotRecognizedException(); } }
/** * SAXNotSupportedException thrown if property name is known but no value * assigned to this property. * * @throws Exception If any errors occur. */ @Test(expectedExceptions = SAXNotSupportedException.class) public void xrProperty02() throws Exception { SAXParserFactory spf = SAXParserFactory.newInstance(); XMLReader xmlReader = spf.newSAXParser().getXMLReader(); assertNull(xmlReader.getProperty(DOM_NODE)); }
/** * returns the particular property requested for in the underlying * implementation of org.xml.sax.XMLReader. */ public boolean getFeature(String name) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { if (name == null) { throw new NullPointerException(); } if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { return fSecureProcess; } // Check for valid name by creating a dummy XMLReader to get // feature value return newSAXParserImpl().getXMLReader().getFeature(name); }
@Test(expectedExceptions = NullPointerException.class) public void testGetNullFeature() throws SAXNotRecognizedException, SAXNotSupportedException { SchemaFactory sf = newSchemaFactory(); assertNotNull(sf); sf.getFeature(null); }
/** * 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); } } }
@Test public void test() throws SAXNotRecognizedException, SAXNotSupportedException { try { schemaFactory.setFeature(null, false); Assert.fail("exception expected"); } catch (NullPointerException e) { ; // as expected } }
public synchronized boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { if (name == null) { // TODO: Add localized error message. throw new NullPointerException(); } if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { return fSecurityManager.isSecureProcessing(); } return super.getFeature(name); }
@Override public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { if(name.equals(PREFIX_FEATURE)) { this.namespacePrefixes = value; return; } if(name.equals(NAMESPACE_FEATURE) && value) return; super.setFeature(name, value); }
@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); } }
@Test(expectedExceptions = NullPointerException.class) public void testGetNullFeature() throws SAXNotRecognizedException, SAXNotSupportedException { ValidatorHandler validatorHandler = getValidatorHandler(); assertNotNull(validatorHandler); validatorHandler.getFeature(null); }
public void testFeature() throws SAXNotRecognizedException, SAXNotSupportedException { ValidatorHandler validatorHandler = getValidatorHandler(); assertFalse(validatorHandler.getFeature(FEATURE_NAME), "The feature should be false by default."); validatorHandler.setFeature(FEATURE_NAME, true); assertTrue(validatorHandler.getFeature(FEATURE_NAME), "The feature should be false by default."); }
/** * 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})); } } }
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; }
public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) { return getLexicalHandler(); } else { throw new SAXNotRecognizedException("Property not recognized: " + name); } }