DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(is);
HashMap<String, Object> metadata = null;
HashMap<String, Show> showById = new HashMap<String, Show>();
Event event = new Event();
NodeList metadataNodes = dom.getElementsByTagName("metadata");
if (metadataNodes.getLength() != 0) {
metadata = new HashMap<String, Object>();
NodeList metadataNodeKids = metadataNodes.item(0).getChildNodes();
for (int i = 0; i < metadataNodeKids.getLength(); i++) {
Node metadataNodeKid = metadataNodeKids.item(i);
if (metadataNodeKid.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if (metadataNodeKid.getNodeName().equals("event")) {
event.setUrl(metadataNodeKid.getAttributes().getNamedItem("url").getTextContent());
event.setDescription(metadataNodeKid.getAttributes().getNamedItem("description").getTextContent());
}
if (metadataNodeKid.getNodeName().equals("stage")) {
StageMetadata stageMetadata = new StageMetadata();
stageMetadata.setUrl(metadataNodeKid.getAttributes().getNamedItem("url").getTextContent());
stageMetadata.setDescription(metadataNodeKid.getAttributes().getNamedItem("description").getTextContent());
metadata.put(metadataNodeKid.getAttributes().getNamedItem("id").getTextContent(), stageMetadata);
}
if (metadataNodeKid.getNodeName().equals("show")) {
ShowMetadata showMetadata = new ShowMetadata();
showMetadata.setUrl(metadataNodeKid.getAttributes().getNamedItem("url").getTextContent());
showMetadata.setDescription(metadataNodeKid.getAttributes().getNamedItem("description").getTextContent());
metadata.put(metadataNodeKid.getAttributes().getNamedItem("id").getTextContent(), showMetadata);
}
}
}
Node eventNode = dom.getDocumentElement();
event.setName(eventNode.getAttributes().getNamedItem("name").getTextContent());
if (eventNode.getAttributes().getNamedItem("shortName") != null) {
event.setShortName(eventNode.getAttributes().getNamedItem("shortName").getTextContent());
}
if (eventNode.getAttributes().getNamedItem("uri") != null) {
event.setUri(eventNode.getAttributes().getNamedItem("uri").getTextContent());
}
if (eventNode.getAttributes().getNamedItem("version") != null) {
event.setVersion(new Long(eventNode.getAttributes().getNamedItem("version").getTextContent()));
}
if (eventNode.getAttributes().getNamedItem("versionTime") != null) {
event.setVersionTime(Util.dateTime(eventNode.getAttributes().getNamedItem("versionTime").getTextContent()));
}
NodeList programKids = dom.getElementsByTagName("program").item(0).getChildNodes();
for (int i = 0; i < programKids.getLength(); i++) {
Node stageNode = programKids.item(i);
if (stageNode.getNodeType() != Node.ELEMENT_NODE && !stageNode.getNodeName().equals("stage")) {
continue;
}
Stage stage = event.addStage(stageNode.getAttributes().getNamedItem("name").getTextContent());
if (stageNode.getAttributes().getNamedItem("id") != null) {
StageMetadata stageMetadata = (StageMetadata) metadata.get(stageNode.getAttributes().getNamedItem("id").getTextContent());
stage.setMetadata(stageMetadata);
}
if (stageNode.getAttributes().getNamedItem("shortName") != null) {