Example usage for javax.xml.validation Validator reset

List of usage examples for javax.xml.validation Validator reset

Introduction

In this page you can find the example usage for javax.xml.validation Validator reset.

Prototype

public abstract void reset();

Source Link

Document

Reset this Validator to its original configuration.

Usage

From source file:com.honnix.jaxo.core.internal.pool.ValidatorObjectFactory.java

@Override
public void passivateObject(Validator validator) throws Exception {
    validator.reset();
}

From source file:ar.com.tadp.xml.rinzo.core.resources.validation.XMLStringValidator.java

private void saxSchemaValidate(String fileName, String fileContent,
        Collection<DocumentStructureDeclaration> schemaDefinitions) {
    try {/*w w w.  j  a  v a2 s  .  c  o  m*/
        Validator validator;
        Map<Collection<DocumentStructureDeclaration>, Validator> schemaValidatorsCache = XMLEditorPlugin
                .getDefault().getSchemaValidatorsCache();

        validator = schemaValidatorsCache.get(schemaDefinitions);
        if (validator == null) {
            StreamSource[] sources = new StreamSource[schemaDefinitions.size()];
            int pos = 0;
            Map<String, String> fileLocations = DocumentCache.getInstance().getAllLocations(schemaDefinitions,
                    fileName);
            for (Map.Entry<String, String> fileLocation : fileLocations.entrySet()) {
                StreamSource streamSource = new StreamSource(fileLocation.getValue());
                streamSource.setPublicId(fileLocation.getKey());
                sources[pos++] = streamSource;
            }
            validator = this.createValidator(sources);
            schemaValidatorsCache.put(schemaDefinitions, validator);
        }

        validator.reset();
        validator.setErrorHandler(this.errorHandler);
        validator.validate(new StreamSource(new StringReader(fileContent)));
    } catch (SAXParseException saxE) {
        try {
            this.errorHandler.error(saxE);
        } catch (SAXException e) {
        }
    } catch (Exception exception) {
        //Do nothing because the errorHandler informs the error
    }
}

From source file:eu.artist.postmigration.eubt.executiontrace.abstractor.SOAPTraceAbstractor.java

/**
 * Validates soap trace (i.e., list of soap responses) against schema and
 * stores the result/*from  w  w  w .  j a v  a  2s .co  m*/
 * 
 * @param soapResponseTrace trace that contains soap responses
 * @return map of soap responses and their respective validation result
 * @throws EUBTException in case the schema location could not be found
 */
private LinkedMap<SOAPResponse, String> validateSoapTrace(final SOAPTrace soapResponseTrace)
        throws EUBTException {
    final LinkedMap<SOAPResponse, String> validationResults = new LinkedMap<SOAPResponse, String>();

    final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Validator validator;
    try {
        final Schema schema = schemaFactory.newSchema(new URL(schemaLocation));
        validator = schema.newValidator();
    } catch (SAXException | IOException e) {
        throw new EUBTException("Failed to create Schema from Schema location " + schemaLocation
                + ". Detailed Exception: " + e.getMessage());
    }
    // for each soap response
    for (final Response response : soapResponseTrace.getResponses()) {
        String validationResult = VALIDATION_INVALID;
        final SOAPResponse soapResponse = (SOAPResponse) response;
        final SOAPEnvelope soapEnvelope = (SOAPEnvelope) soapResponse.getData();
        final OMElement bodyContent = soapEnvelope.getBody().getFirstElement();

        // create some invalid content
        //         SOAP12Factory factory = new SOAP12Factory();
        //         OMElement invalidElement = factory.createOMElement(new QName("blah"));
        //         OMNamespace invalidNamespace = factory.createOMNamespace("http://notMyNamespace.com", "invNS");
        //         OMAttribute invalidAttribute = factory.createOMAttribute("someAttribute", invalidNamespace, "attributeValue");
        //         bodyContent.addChild(invalidElement);
        //         bodyContent.addAttribute(invalidAttribute);

        // validate soap body content -> will cause an exception if not valid
        try {
            validator.validate(bodyContent.getSAXSource(true));
            // validation succeeded
            validationResult = VALIDATION_VALID;
            Debug.debug(this, "Successfully validated SOAP body content " + bodyContent);
        } catch (final IOException e) {
            throw new EUBTException("Failed to validate SOAP body content " + bodyContent
                    + ". Detailed Exception: " + e.getMessage());
        } catch (final SAXException e) {
            // validation failed
            Debug.debug(this, "Failed to validate soap SOAP content " + bodyContent + ". Detailed Exception: "
                    + e.getMessage());
        }
        // finished validating, store result
        validationResults.put(soapResponse, validationResult);
        validator.reset();
    } // for each soap response

    return validationResults;
}