package husacct.validate.task.workspace.importing.xml; import husacct.validate.domain.validation.logicalmodule.LogicalModule; import husacct.validate.domain.validation.logicalmodule.LogicalModules; import java.util.Calendar; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import org.apache.log4j.Logger; import org.jdom2.Element; public abstract class XmlImportUtils { private Logger logger = Logger.getLogger(XmlImportUtils.class); protected LogicalModules getLogicalModules(Element logicalModulesElement) { Element logicalModuleFromElement = logicalModulesElement.getChild("logicalModuleFrom"); Element logicalModuleToElement = logicalModulesElement.getChild("logicalModuleTo"); LogicalModule logicalModuleFrom = new LogicalModule(logicalModuleFromElement.getChildText("logicalModulePath"), logicalModuleFromElement.getChildText("logicalModuleType")); LogicalModule logicalModuleTo = new LogicalModule(logicalModuleToElement.getChildText("logicalModulePath"), logicalModuleToElement.getChildText("logicalModuleType")); LogicalModules logicalModules = new LogicalModules(logicalModuleFrom, logicalModuleTo); return logicalModules; } protected Calendar getCalendar(String stringCalendar) { Calendar calendar = Calendar.getInstance(); try { calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(stringCalendar).toGregorianCalendar(); } catch (IllegalArgumentException e) { logger.error(String.format("%s is not a valid datetime, switching back to current datetime", stringCalendar)); } catch (DatatypeConfigurationException e) { logger.error(e.getMessage()); } return calendar; } }