use of com.agiletec.aps.system.common.entity.parse.EntityHandler in project entando-core by entando.
the class ApsEntityManager method createEntityFromXml.
/**
* Create and populate the entity as specified by its type and XML
* definition.
*
* @param entityTypeCode The Entity Type code.
* @param xml The XML of the associated entity.
* @return The populated entity.
* @throws ApsSystemException If errors detected while retrieving the
* entity.
*/
protected IApsEntity createEntityFromXml(String entityTypeCode, String xml) throws ApsSystemException {
try {
IApsEntity entityPrototype = this.getEntityPrototype(entityTypeCode);
SAXParserFactory parseFactory = SAXParserFactory.newInstance();
SAXParser parser = parseFactory.newSAXParser();
InputSource is = new InputSource(new StringReader(xml));
EntityHandler handler = this.getEntityHandler();
handler.initHandler(entityPrototype, this.getXmlAttributeRootElementName(), this.getCategoryManager());
parser.parse(is, handler);
return entityPrototype;
} catch (ParserConfigurationException | SAXException | IOException t) {
logger.error("Error detected while creating the entity. typecode: {} - xml: {}", entityTypeCode, xml, t);
throw new ApsSystemException("Error detected while creating the entity", t);
}
}
Aggregations