public ExpirationConfiguration loadExpirationConfiguration(File file) { log.debug("loadExpirationConfiguration(File)"); ExpirationConfiguration result = null; int defaultConfiguration = -1; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(file); doc.getDocumentElement().normalize(); log.debug("Root element " + doc.getDocumentElement().getNodeName()); String defaultUnits = ""; Node defaultDurationNode = doc.getElementsByTagName("expirations") .item(0) .getAttributes() .getNamedItem("defaultDuration"); Node defaultUnitNode = doc.getElementsByTagName("expirations") .item(0) .getAttributes() .getNamedItem("defaultUnits"); if (defaultDurationNode != null) { defaultConfiguration = Integer.parseInt(defaultDurationNode.getTextContent()); } if (defaultUnitNode != null) { defaultUnits = defaultUnitNode.getTextContent(); } result = new ExpirationConfiguration(defaultConfiguration, defaultUnits); NodeList nodeLst = doc.getElementsByTagName("expiration"); for (int x = 0; x < nodeLst.getLength(); x++) { Node item = nodeLst.item(x); String aa = item.getAttributes().getNamedItem("assigningAuthority").getTextContent(); String units = item.getAttributes().getNamedItem("unit").getTextContent(); String duration = item.getTextContent(); Expiration expItem = new Expiration(aa, units, Integer.parseInt(duration)); result.getExpirations().add(expItem); } } catch (Exception e) { log.error("unable to load PCConfiguration file", e); e.printStackTrace(); } return result; }
public ExpirationConfiguration loadExpirationConfiguration(String fileName) { ExpirationConfiguration result = null; log.debug("loadExpirationConfiguration"); log.debug("fileName = " + fileName); try { File file = new File(fileName); result = loadExpirationConfiguration(file); } catch (Exception e) { log.error("unable to load PCConfiguration file", e); e.printStackTrace(); } return result; }