use of org.alfresco.repo.audit.model._3.Audit in project alfresco-repository by Alfresco.
the class AuditModelRegistryImpl method unmarshallModel.
/**
* Unmarshalls the Audit model from a stream.
*/
private static Audit unmarshallModel(InputStream is, final String source) {
final Schema schema;
final JAXBContext jaxbCtx;
final Unmarshaller jaxbUnmarshaller;
try {
SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
schema = sf.newSchema(ResourceUtils.getURL(AUDIT_SCHEMA_LOCATION));
jaxbCtx = JAXBContext.newInstance("org.alfresco.repo.audit.model._3");
jaxbUnmarshaller = jaxbCtx.createUnmarshaller();
jaxbUnmarshaller.setSchema(schema);
jaxbUnmarshaller.setEventHandler(new ValidationEventHandler() {
public boolean handleEvent(ValidationEvent ve) {
if (ve.getSeverity() == ValidationEvent.FATAL_ERROR || ve.getSeverity() == ValidationEvent.ERROR) {
ValidationEventLocator locator = ve.getLocator();
logger.error("Invalid Audit XML: \n" + " Source: " + source + "\n" + " Location: Line " + locator.getLineNumber() + " column " + locator.getColumnNumber() + "\n" + " Error: " + ve.getMessage());
}
return false;
}
});
} catch (Throwable e) {
throw new AlfrescoRuntimeException("Failed to load Alfresco Audit Schema from " + AUDIT_SCHEMA_LOCATION, e);
}
try {
// Unmarshall with validation
@SuppressWarnings("unchecked") JAXBElement<Audit> auditElement = (JAXBElement<Audit>) jaxbUnmarshaller.unmarshal(is);
Audit audit = auditElement.getValue();
// Done
return audit;
} catch (Throwable e) {
// Dig out a SAXParseException, if there is one
Throwable saxError = ExceptionStackUtil.getCause(e, SAXParseException.class);
if (saxError != null) {
e = saxError;
}
throw new AuditModelException("Failed to read Audit model XML: \n" + " Source: " + source + "\n" + " Error: " + e.getMessage());
} finally {
try {
is.close();
} catch (IOException e) {
}
}
}
Aggregations