org.springframework.util.xml.XmlValidationModeDetector Java Examples

The following examples show how to use org.springframework.util.xml.XmlValidationModeDetector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultDocumentLoader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create the {@link DocumentBuilderFactory} instance.
 * @param validationMode the type of validation: {@link XmlValidationModeDetector#VALIDATION_DTD DTD}
 * or {@link XmlValidationModeDetector#VALIDATION_XSD XSD})
 * @param namespaceAware whether the returned factory is to provide support for XML namespaces
 * @return the JAXP DocumentBuilderFactory
 * @throws ParserConfigurationException if we failed to build a proper DocumentBuilderFactory
 */
protected DocumentBuilderFactory createDocumentBuilderFactory(int validationMode, boolean namespaceAware)
		throws ParserConfigurationException {

	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	factory.setNamespaceAware(namespaceAware);

	if (validationMode != XmlValidationModeDetector.VALIDATION_NONE) {
		factory.setValidating(true);
		if (validationMode == XmlValidationModeDetector.VALIDATION_XSD) {
			// Enforce namespace aware for XSD...
			factory.setNamespaceAware(true);
			try {
				factory.setAttribute(SCHEMA_LANGUAGE_ATTRIBUTE, XSD_SCHEMA_LANGUAGE);
			}
			catch (IllegalArgumentException ex) {
				ParserConfigurationException pcex = new ParserConfigurationException(
						"Unable to validate using XSD: Your JAXP provider [" + factory +
						"] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? " +
						"Upgrade to Apache Xerces (or Java 1.5) for full XSD support.");
				pcex.initCause(ex);
				throw pcex;
			}
		}
	}

	return factory;
}
 
Example #2
Source File: DefaultDocumentLoader.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create the {@link DocumentBuilderFactory} instance.
 * @param validationMode the type of validation: {@link XmlValidationModeDetector#VALIDATION_DTD DTD}
 * or {@link XmlValidationModeDetector#VALIDATION_XSD XSD})
 * @param namespaceAware whether the returned factory is to provide support for XML namespaces
 * @return the JAXP DocumentBuilderFactory
 * @throws ParserConfigurationException if we failed to build a proper DocumentBuilderFactory
 */
protected DocumentBuilderFactory createDocumentBuilderFactory(int validationMode, boolean namespaceAware)
		throws ParserConfigurationException {

	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	factory.setNamespaceAware(namespaceAware);

	if (validationMode != XmlValidationModeDetector.VALIDATION_NONE) {
		factory.setValidating(true);
		if (validationMode == XmlValidationModeDetector.VALIDATION_XSD) {
			// Enforce namespace aware for XSD...
			factory.setNamespaceAware(true);
			try {
				factory.setAttribute(SCHEMA_LANGUAGE_ATTRIBUTE, XSD_SCHEMA_LANGUAGE);
			}
			catch (IllegalArgumentException ex) {
				ParserConfigurationException pcex = new ParserConfigurationException(
						"Unable to validate using XSD: Your JAXP provider [" + factory +
						"] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? " +
						"Upgrade to Apache Xerces (or Java 1.5) for full XSD support.");
				pcex.initCause(ex);
				throw pcex;
			}
		}
	}

	return factory;
}
 
Example #3
Source File: DefaultDocumentLoader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the {@link DocumentBuilderFactory} instance.
 * @param validationMode the type of validation: {@link XmlValidationModeDetector#VALIDATION_DTD DTD}
 * or {@link XmlValidationModeDetector#VALIDATION_XSD XSD})
 * @param namespaceAware whether the returned factory is to provide support for XML namespaces
 * @return the JAXP DocumentBuilderFactory
 * @throws ParserConfigurationException if we failed to build a proper DocumentBuilderFactory
 */
protected DocumentBuilderFactory createDocumentBuilderFactory(int validationMode, boolean namespaceAware)
		throws ParserConfigurationException {

	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	factory.setNamespaceAware(namespaceAware);

	if (validationMode != XmlValidationModeDetector.VALIDATION_NONE) {
		factory.setValidating(true);
		if (validationMode == XmlValidationModeDetector.VALIDATION_XSD) {
			// Enforce namespace aware for XSD...
			factory.setNamespaceAware(true);
			try {
				factory.setAttribute(SCHEMA_LANGUAGE_ATTRIBUTE, XSD_SCHEMA_LANGUAGE);
			}
			catch (IllegalArgumentException ex) {
				ParserConfigurationException pcex = new ParserConfigurationException(
						"Unable to validate using XSD: Your JAXP provider [" + factory +
						"] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? " +
						"Upgrade to Apache Xerces (or Java 1.5) for full XSD support.");
				pcex.initCause(ex);
				throw pcex;
			}
		}
	}

	return factory;
}
 
Example #4
Source File: DefaultDocumentLoader.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Create the {@link DocumentBuilderFactory} instance.
 * @param validationMode the type of validation: {@link XmlValidationModeDetector#VALIDATION_DTD DTD}
 * or {@link XmlValidationModeDetector#VALIDATION_XSD XSD})
 * @param namespaceAware whether the returned factory is to provide support for XML namespaces
 * @return the JAXP DocumentBuilderFactory
 * @throws ParserConfigurationException if we failed to build a proper DocumentBuilderFactory
 */
protected DocumentBuilderFactory createDocumentBuilderFactory(int validationMode, boolean namespaceAware)
		throws ParserConfigurationException {

	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	factory.setNamespaceAware(namespaceAware);

	if (validationMode != XmlValidationModeDetector.VALIDATION_NONE) {
		factory.setValidating(true);
		if (validationMode == XmlValidationModeDetector.VALIDATION_XSD) {
			// Enforce namespace aware for XSD...
			factory.setNamespaceAware(true);
			try {
				factory.setAttribute(SCHEMA_LANGUAGE_ATTRIBUTE, XSD_SCHEMA_LANGUAGE);
			}
			catch (IllegalArgumentException ex) {
				ParserConfigurationException pcex = new ParserConfigurationException(
						"Unable to validate using XSD: Your JAXP provider [" + factory +
						"] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? " +
						"Upgrade to Apache Xerces (or Java 1.5) for full XSD support.");
				pcex.initCause(ex);
				throw pcex;
			}
		}
	}

	return factory;
}
 
Example #5
Source File: DefaultDocumentLoader.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create the {@link DocumentBuilderFactory} instance.
 * @param validationMode the type of validation: {@link XmlValidationModeDetector#VALIDATION_DTD DTD}
 * or {@link XmlValidationModeDetector#VALIDATION_XSD XSD})
 * @param namespaceAware whether the returned factory is to provide support for XML namespaces
 * @return the JAXP DocumentBuilderFactory
 * @throws ParserConfigurationException if we failed to build a proper DocumentBuilderFactory
 */
protected DocumentBuilderFactory createDocumentBuilderFactory(int validationMode, boolean namespaceAware)
		throws ParserConfigurationException {

	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	factory.setNamespaceAware(namespaceAware);

	if (validationMode != XmlValidationModeDetector.VALIDATION_NONE) {
		factory.setValidating(true);
		if (validationMode == XmlValidationModeDetector.VALIDATION_XSD) {
			// Enforce namespace aware for XSD...
			factory.setNamespaceAware(true);
			try {
				factory.setAttribute(SCHEMA_LANGUAGE_ATTRIBUTE, XSD_SCHEMA_LANGUAGE);
			}
			catch (IllegalArgumentException ex) {
				ParserConfigurationException pcex = new ParserConfigurationException(
						"Unable to validate using XSD: Your JAXP provider [" + factory +
						"] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? " +
						"Upgrade to Apache Xerces (or Java 1.5) for full XSD support.");
				pcex.initCause(ex);
				throw pcex;
			}
		}
	}

	return factory;
}
 
Example #6
Source File: XmlNamedTemplateResolver.java    From spring-data-jpa-extra with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Void> doInTemplateResource(Resource resource, final NamedTemplateCallback callback)
        throws Exception {
    InputSource inputSource = new InputSource(resource.getInputStream());
    inputSource.setEncoding(encoding);
    Document doc = documentLoader.loadDocument(inputSource, entityResolver, errorHandler,
            XmlValidationModeDetector.VALIDATION_XSD, false);
    final List<Element> sqes = DomUtils.getChildElementsByTagName(doc.getDocumentElement(), "sql");

    return new Iterator<Void>() {
        int index = 0, total = sqes.size();

        @Override
        public boolean hasNext() {
            return index < total;
        }

        @Override
        public Void next() {
            Element sqle = sqes.get(index);
            callback.process(sqle.getAttribute("name"), sqle.getTextContent());
            index++;
            return null;
        }

        @Override
        public void remove() {
            //ignore
        }
    };
}