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);
}
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());
}
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()));
}
Aggregations