private AtmosphereConfig parse(AtmosphereConfig config, Document document) {
Element element = document.getDocumentElement();
NodeList atmosphereHandlers = element.getElementsByTagName("atmosphere-handler");
for (int i = 0; i < atmosphereHandlers.getLength(); i++) {
AtmosphereHandlerConfig atmoHandler = new AtmosphereHandlerConfig();
Node root = atmosphereHandlers.item(i);
// parse Attributes
for (int j = 0; j < root.getAttributes().getLength(); j++) {
Node attribute = root.getAttributes().item(j);
if (attribute.getNodeName().equals("support-session")) {
atmoHandler.setSupportSession(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("context-root")) {
atmoHandler.setContextRoot(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("class-name")) {
atmoHandler.setClassName(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("broadcaster")) {
atmoHandler.setBroadcaster(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("broadcasterCache")) {
atmoHandler.setBroadcasterCache(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("broadcastFilterClasses")) {
String[] values = attribute.getNodeValue().split(",");
for (String value : values) {
atmoHandler.getBroadcastFilterClasses().add(value);
}
} else if (attribute.getNodeName().equals("comet-support")) {
atmoHandler.setCometSupport(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("interceptorClasses")) {
String[] values = attribute.getNodeValue().split(",");
for (String value : values) {
atmoHandler.getAtmosphereInterceptorClasses().add(value);
}
}
}
NodeList list = root.getChildNodes();
for (int j = 0; j < list.getLength(); j++) {
Node n = list.item(j);
if (n.getNodeName().equals("property")) {
String param = n.getAttributes().getNamedItem("name").getNodeValue();
String value = n.getAttributes().getNamedItem("value").getNodeValue();
atmoHandler.getProperties().add(new AtmosphereHandlerProperty(param, value));
} else if (n.getNodeName().equals("applicationConfig")) {
String param = null;
String value = null;
for (int k = 0; k < n.getChildNodes().getLength(); k++) {
Node n2 = n.getChildNodes().item(k);
if (n2.getNodeName().equals("param-name")) {
param = n2.getFirstChild().getNodeValue();
} else if (n2.getNodeName().equals("param-value")) {
if (n2 != null) {
value = n2.getFirstChild().getNodeValue();
}
}
}
if (param != null) {
atmoHandler.getApplicationConfig().add(new ApplicationConfiguration(param, value));
}
} else if (n.getNodeName().equals("frameworkConfig")) {
String param = null;
String value = null;
for (int k = 0; k < n.getChildNodes().getLength(); k++) {
Node n2 = n.getChildNodes().item(k);
if (n2.getNodeName().equals("param-name")) {
param = n2.getFirstChild().getNodeValue();
} else if (n2.getNodeName().equals("param-value")) {
if (n2 != null) {
value = n2.getFirstChild().getNodeValue();
}
}
}
if (param != null) {
atmoHandler.getFrameworkConfig().add(
new FrameworkConfiguration(param, value));
}
}