Example usage for org.springframework.util.xml XmlValidationModeDetector VALIDATION_NONE

List of usage examples for org.springframework.util.xml XmlValidationModeDetector VALIDATION_NONE

Introduction

In this page you can find the example usage for org.springframework.util.xml XmlValidationModeDetector VALIDATION_NONE.

Prototype

int VALIDATION_NONE

To view the source code for org.springframework.util.xml XmlValidationModeDetector VALIDATION_NONE.

Click Source Link

Document

Indicates that the validation should be disabled.

Usage

From source file:org.eclipse.gemini.blueprint.test.provisioning.internal.MavenPackagedArtifactFinder.java

/**
 * Returns the <tt>groupId</tt> setting in a <tt>pom.xml</tt> file.
 * // w  ww  . j a  v  a 2s  . c o m
 * @return a <tt>pom.xml</tt> <tt>groupId</tt>.
 */
String getGroupIdFromPom(Resource pomXml) {
    try {
        DocumentLoader docLoader = new DefaultDocumentLoader();
        Document document = docLoader.loadDocument(new InputSource(pomXml.getInputStream()), null, null,
                XmlValidationModeDetector.VALIDATION_NONE, false);

        String groupId = DomUtils.getChildElementValueByTagName(document.getDocumentElement(), GROUP_ID_ELEM);
        // no groupId specified, try the parent definition
        if (groupId == null) {
            if (log.isTraceEnabled())
                log.trace("No groupId defined; checking for the parent definition");
            Element parent = DomUtils.getChildElementByTagName(document.getDocumentElement(), "parent");
            if (parent != null)
                return DomUtils.getChildElementValueByTagName(parent, GROUP_ID_ELEM);
        } else {
            return groupId;
        }
    } catch (Exception ex) {
        throw (RuntimeException) new RuntimeException(
                new ParserConfigurationException("error parsing resource=" + pomXml).initCause(ex));
    }

    throw new IllegalArgumentException(
            "no groupId or parent/groupId defined by resource [" + pomXml.getDescription() + "]");

}

From source file:org.eclipse.gemini.blueprint.test.provisioning.internal.LocalFileSystemMavenRepository.java

/**
 * Returns the <code>localRepository</code> settings as indicated by the
 * <code>settings.xml</code> file.
 * /*from  w w  w.j a  va2  s  . c o m*/
 * @return local repository as indicated by a Maven settings.xml file
 */
String getMavenSettingsLocalRepository(Resource m2Settings) {
    // no file found, return null to continue the discovery process
    if (!m2Settings.exists())
        return null;

    try {
        DocumentLoader docLoader = new DefaultDocumentLoader();
        Document document = docLoader.loadDocument(new InputSource(m2Settings.getInputStream()), null, null,
                XmlValidationModeDetector.VALIDATION_NONE, false);

        return (DomUtils.getChildElementValueByTagName(document.getDocumentElement(), LOCAL_REPOSITORY_ELEM));
    } catch (Exception ex) {
        throw (RuntimeException) new RuntimeException(
                new ParserConfigurationException("error parsing resource=" + m2Settings).initCause(ex));
    }
}

From source file:org.springframework.beans.factory.xml.DefaultDocumentLoader.java

/**
 * 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
 *///from ww  w  .j a va 2  s.  co m
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;
}

From source file:org.springframework.data.hadoop.admin.util.HadoopWorkflowDescriptorUtils.java

/**
 * replace the "property-placeholder" element in beans XML with absolute path 
 * where the uploaded file exist in the server.
 *  //  w  w  w.j a v a 2s. c o m
 * @param workflowDescriptor spring's XML file
 * @param workflowProperty properties used in spring's XML file
 * 
 * @return whether "property-placeholder" appears in the beans XML. 
 *          true - it appears
 *          false - no
 * 
 * @throws SpringHadoopAdminWorkflowException
 */
public boolean replacePropertyPlaceHolder(File workflowDescriptor, File workflowProperty)
        throws SpringHadoopAdminWorkflowException {
    boolean result = false;
    String parentFolder = workflowDescriptor.getParentFile().getAbsolutePath();
    parentFolder = parentFolder + File.separator;
    try {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(workflowDescriptor));
        InputSource inputSource = new InputSource(bis);
        Document doc = this.documentLoader.loadDocument(inputSource, getEntityResolver(), this.errorHandler,
                XmlValidationModeDetector.VALIDATION_NONE, true);
        NodeList nodes = doc.getElementsByTagNameNS(springContextNameSpace, placePlaceHolderTagName);
        logger.debug("number of nodes:" + nodes.getLength());
        for (int i = 0, j = nodes.getLength(); i < j; i++) {
            Node node = nodes.item(i);
            if (node instanceof Element) {
                Element e = (Element) node;
                String newValue = workflowProperty.getAbsolutePath().replace("\\", "/");
                newValue = HadoopWorkflowUtils.fileURLPrefix + newValue;
                e.setAttribute("location", newValue);
                result = true;
                logger.debug("new location after replaced:" + newValue);
            }
        }
        if (result) {
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            DOMSource source = new DOMSource(doc);
            StreamResult out = new StreamResult(new File(workflowDescriptor.getAbsolutePath()));
            transformer.transform(source, out);
        }
    } catch (Exception e) {
        logger.warn(replacePropertyPlaceHolderFaiure);
        throw new SpringHadoopAdminWorkflowException(replacePropertyPlaceHolderFaiure, e);
    }
    return result;
}