@Override public void parseDocument(Document doc, File f) { try { int id = Integer.parseInt(f.getName().replaceAll(".xml", "")); int entryId = 1; Node att; final ListContainer list = new ListContainer(id); for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) { if ("list".equalsIgnoreCase(n.getNodeName())) { att = n.getAttributes().getNamedItem("applyTaxes"); list.setApplyTaxes((att != null) && Boolean.parseBoolean(att.getNodeValue())); att = n.getAttributes().getNamedItem("useRate"); if (att != null) { try { list.setUseRate(Double.valueOf(att.getNodeValue())); if (list.getUseRate() <= 1e-6) { throw new NumberFormatException( "The value cannot be 0"); // threat 0 as invalid value } } catch (NumberFormatException e) { try { list.setUseRate(Config.class.getField(att.getNodeValue()).getDouble(Config.class)); } catch (Exception e1) { LOG.warn( "{}: Unable to parse {}", getClass().getSimpleName(), doc.getLocalName(), e1); list.setUseRate(1.0); } } catch (DOMException e) { LOG.warn("{}: Unable to parse {}", getClass().getSimpleName(), doc.getLocalName(), e); } } att = n.getAttributes().getNamedItem("maintainEnchantment"); list.setMaintainEnchantment((att != null) && Boolean.parseBoolean(att.getNodeValue())); for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) { if ("item".equalsIgnoreCase(d.getNodeName())) { Entry e = parseEntry(d, entryId++, list); list.getEntries().add(e); } else if ("npcs".equalsIgnoreCase(d.getNodeName())) { for (Node b = d.getFirstChild(); b != null; b = b.getNextSibling()) { if ("npc".equalsIgnoreCase(b.getNodeName())) { if (Util.isDigit(b.getTextContent())) { list.allowNpc(Integer.parseInt(b.getTextContent())); } } } } } } } _entries.put(id, list); } catch (Exception e) { LOG.error("{}: Error in file {}", getClass().getSimpleName(), f, e); } }
@Override public long extractIfmapMetadataTimestamp(Document document) { LOGGER.trace("extracting timestamp from XML"); Element root = document.getDocumentElement(); String time = null; try { time = root.getAttribute("ifmap-timestamp"); Calendar cal = DatatypeConverter.parseDateTime(time); long unixTime = cal.getTime().getTime(); LOGGER.trace("found timestamp '" + unixTime + "'"); return unixTime; } catch (IllegalArgumentException e) { LOGGER.error( "could not parse timestamp '" + time + "' in " + document.getLocalName() + "setting current local time as timestamp"); return System.currentTimeMillis(); } }