Search in sources :

Example 61 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project knime-core by knime.

the class NodeDescription41Proxy method validate.

/**
 * Validate against the XML Schema. If violations are found they are reported via the logger as coding problems.
 *
 * @return <code>true</code> if the document is valid, <code>false</code> otherwise
 */
protected final boolean validate() {
    // this method has default visibility so that we can use it in testcases
    XmlOptions options = new XmlOptions(OPTIONS);
    List<XmlError> errors = new ArrayList<XmlError>();
    options.setErrorListener(errors);
    boolean valid = m_document.validate(options);
    if (!valid) {
        logger.coding(String.format(SCHEMA_VIOLATION_MSG, getNodeName()));
        for (XmlError err : errors) {
            logger.coding(err.toString());
        }
    }
    return validateInsertionIndices(valid);
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions) ArrayList(java.util.ArrayList) XmlError(org.apache.xmlbeans.XmlError)

Example 62 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project airavata by apache.

the class XMLUtil method validate.

/**
 * Validates a specified XmlObject along with logging errors if any.
 *
 * @param xmlObject
 */
public static void validate(XmlObject xmlObject) throws AiravataException {
    XmlOptions validateOptions = new XmlOptions();
    ArrayList errorList = new ArrayList();
    validateOptions.setErrorListener(errorList);
    boolean isValid = xmlObject.validate(validateOptions);
    if (isValid) {
        // Valid
        return;
    }
    // Error
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < errorList.size(); i++) {
        XmlError error = (XmlError) errorList.get(i);
        logger.warn("Message: " + error.getMessage());
        logger.warn("Location of invalid XML: " + error.getCursorLocation().xmlText());
        stringBuilder.append("Message:" + error.getMessage());
        stringBuilder.append("Location of invalid XML: " + error.getCursorLocation().xmlText());
    }
    throw new AiravataException(stringBuilder.toString());
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions) ArrayList(java.util.ArrayList) XmlError(org.apache.xmlbeans.XmlError) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 63 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project arctic-sea by 52North.

the class InsertSensorRequestDecoderTest method setUp.

@Before
public void setUp() throws DecodingException, IOException {
    DecoderRepository decoderRepository = new DecoderRepository();
    this.decoder = new InsertSensorRequestDecoder();
    this.decoder.setDecoderRepository(decoderRepository);
    SensorMLDecoderV101 sensorMLDecoder = new SensorMLDecoderV101();
    sensorMLDecoder.setXmlOptions(XmlOptions::new);
    sensorMLDecoder.setDecoderRepository(decoderRepository);
    SweCommonDecoderV101 sweCommonDecoder = new SweCommonDecoderV101();
    sweCommonDecoder.setXmlOptions(XmlOptions::new);
    sweCommonDecoder.setDecoderRepository(decoderRepository);
    GmlDecoderv311 gmlDecoderv311 = new GmlDecoderv311();
    decoderRepository.setDecoders(Arrays.asList(decoder, sensorMLDecoder, sweCommonDecoder, gmlDecoderv311));
    decoderRepository.init();
    final JsonNode json = JsonLoader.fromResource("/examples/sos/InsertSensorRequest.json");
    this.req = decoder.decode(json);
    assertThat(req, is(notNullValue()));
}
Also used : SensorMLDecoderV101(org.n52.svalbard.decode.SensorMLDecoderV101) SweCommonDecoderV101(org.n52.svalbard.decode.SweCommonDecoderV101) XmlOptions(org.apache.xmlbeans.XmlOptions) InsertSensorRequestDecoder(org.n52.svalbard.decode.json.InsertSensorRequestDecoder) JsonNode(com.fasterxml.jackson.databind.JsonNode) DecoderRepository(org.n52.svalbard.decode.DecoderRepository) GmlDecoderv311(org.n52.svalbard.decode.GmlDecoderv311) Before(org.junit.Before)

Aggregations

XmlOptions (org.apache.xmlbeans.XmlOptions)63 QName (javax.xml.namespace.QName)20 OutputStream (java.io.OutputStream)18 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)17 ArrayList (java.util.ArrayList)12 XmlError (org.apache.xmlbeans.XmlError)11 XmlException (org.apache.xmlbeans.XmlException)11 IOException (java.io.IOException)9 Beta (org.apache.poi.util.Beta)7 Before (org.junit.Before)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 XmlObject (org.apache.xmlbeans.XmlObject)4 PackageDocument (com.centurylink.mdw.bpm.PackageDocument)3 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)3 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)3 EncodingException (org.n52.svalbard.encode.exception.EncodingException)3 MDWProcessDefinition (com.centurylink.mdw.bpm.MDWProcessDefinition)2 ProcessDefinitionDocument (com.centurylink.mdw.bpm.ProcessDefinitionDocument)2 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)2 Attribute (com.centurylink.mdw.task.Attribute)2