/** * Constructor * * @param filename the XML config file */ public LdapConfig(String filename) throws Exception { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.parse(filename); // -- root element Node node = document.getFirstChild(); while (node != null && node.getNodeType() != Node.ELEMENT_NODE) node = node.getNextSibling(); if (node == null || !node.getNodeName().equals("ldap")) throw new Exception("root element is different from 'ldap'"); this.ldapUrl = node.getAttributes().getNamedItem("url").getNodeValue(); node = node.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeName().equals("authentication")) handleAuthentication(node); else if (node.getNodeName().equals("plugins")) handlePlugins(node); else if (node.getNodeName().equals("services")) handleServices(node); else if (node.getNodeName().equals("users")) handleUsers(node); else if (node.getNodeName().equals("groups")) handleGroups(node); else Logging.getLogger().warning("unexepected node : " + node.getNodeName()); } node = node.getNextSibling(); } }
private List<Node> getChildNodes(Node parentNode, String tagName) { List<Node> nodeList = new ArrayList<Node>(); for (Node child = parentNode.getFirstChild(); child != null; child = child.getNextSibling()) { if (child.getNodeType() == Node.ELEMENT_NODE && tagName.equals(child.getNodeName())) { nodeList.add(child); } } return nodeList; }
private void setXmlEntry(Document doc, Node opSet) { NodeList targetNodes = findNodes(doc, opSet); NodeList valueNodes = getValueNodes(opSet); if (targetNodes == null) { return; } int targetNodesCount = targetNodes.getLength(); for (int i = 0; i < targetNodesCount; i++) { Node target = targetNodes.item(i); for (Node child; (child = target.getFirstChild()) != null; target.removeChild(child)) ; appendNodes(doc, target, valueNodes); } }
/** * Parse groups node * * @param node the groups node */ private void handleGroups(Node node) { this.groupsDn = node.getAttributes().getNamedItem("dn").getNodeValue(); node = node.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeName().equals("attribute")) handleMapping(this.groupsAttributes, node); else if (node.getNodeName().equals("mapping")) handleMapping(this.groupsMapping, node); else Logging.getLogger().warning("unexepected node : " + node.getNodeName()); } node = node.getNextSibling(); } }
/** * @param node * @param indent */ public static String toString(Node node, int indent) { StringBuffer str = new StringBuffer(); for (int i = 0; i < indent; ++i) str.append(" "); str.append(node); if (node.hasAttributes()) { NamedNodeMap attrs = node.getAttributes(); for (int j = 0; j < attrs.getLength(); ++j) { Node attr = attrs.item(j); // str.append(toString(attr,indent+2)); str.append(" "); str.append(attr); } } str.append("\n"); ++indent; for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { str.append(toString(child, indent)); // str.append("\n"); } return str.toString(); }
/** * @param list * @param parent * @exception NumberFormatException * @exception DicomException */ void addAttributesFromNodeToList(AttributeList list, Node parent) throws NumberFormatException, DicomException { if (parent != null) { Node node = parent.getFirstChild(); while (node != null) { String elementName = node.getNodeName(); NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { Node vrNode = attributes.getNamedItem("vr"); Node groupNode = attributes.getNamedItem("group"); Node elementNode = attributes.getNamedItem("element"); if (vrNode != null && groupNode != null && elementNode != null) { String vrString = vrNode.getNodeValue(); String groupString = groupNode.getNodeValue(); String elementString = elementNode.getNodeValue(); if (vrString != null && groupString != null && elementString != null) { byte[] vr = vrString.getBytes(); int group = Integer.parseInt(groupString, 16); int element = Integer.parseInt(elementString, 16); AttributeTag tag = new AttributeTag(group, element); if ((group % 2 == 0 && element == 0) || (group == 0x0008 && element == 0x0001) || (group == 0xfffc && element == 0xfffc)) { // System.err.println("ignoring group length or length to end or dataset trailing // padding "+tag); } else { if (vrString.equals("SQ")) { SequenceAttribute a = new SequenceAttribute(tag); // System.err.println("Created "+a); if (node.hasChildNodes()) { Node childNode = node.getFirstChild(); while (childNode != null) { String childNodeName = childNode.getNodeName(); // System.err.println("childNodeName = "+childNodeName); if (childNodeName != null && childNodeName.equals("Item")) { // should check item number, but ignore for now :( // System.err.println("Adding item to sequence"); AttributeList itemList = new AttributeList(); addAttributesFromNodeToList(itemList, childNode); a.addItem(itemList); } // else may be a #text element in between childNode = childNode.getNextSibling(); } } // System.err.println("Sequence Attribute is "+a); list.put(tag, a); } else { Attribute a = AttributeFactory.newAttribute(tag, vr); // System.err.println("Created "+a); if (node.hasChildNodes()) { Node childNode = node.getFirstChild(); while (childNode != null) { String childNodeName = childNode.getNodeName(); // System.err.println("childNodeName = "+childNodeName); if (childNodeName != null && childNodeName.equals("value")) { // should check value number, but ignore for now :( String value = childNode.getTextContent(); // System.err.println("Value value = "+value); if (value != null) { value = StringUtilities.removeLeadingOrTrailingWhitespaceOrISOControl( value); // just in case a.addValue(value); } } // else may be a #text element in between childNode = childNode.getNextSibling(); } } // System.err.println("Attribute is "+a); list.put(tag, a); } } } } } node = node.getNextSibling(); } } }
public boolean runTest(Test test) throws Exception { String filename = test.file.toString(); if (this.verbose) { System.out.println( "Running " + filename + " against " + this.host + ":" + this.port + " with " + this.browser); } this.document = parseDocument(filename); if (this.baseUrl == null) { NodeList links = this.document.getElementsByTagName("link"); if (links.getLength() != 0) { Element link = (Element) links.item(0); setBaseUrl(link.getAttribute("href")); } } if (this.verbose) { System.out.println("Base URL=" + this.baseUrl); } Node body = this.document.getElementsByTagName("body").item(0); Element resultContainer = document.createElement("div"); resultContainer.setTextContent("Result: "); Element resultElt = document.createElement("span"); resultElt.setAttribute("id", "result"); resultElt.setIdAttribute("id", true); resultContainer.appendChild(resultElt); body.insertBefore(resultContainer, body.getFirstChild()); Element executionLogContainer = document.createElement("div"); executionLogContainer.setTextContent("Execution Log:"); Element executionLog = document.createElement("div"); executionLog.setAttribute("id", "log"); executionLog.setIdAttribute("id", true); executionLog.setAttribute("style", "white-space: pre;"); executionLogContainer.appendChild(executionLog); body.appendChild(executionLogContainer); NodeList tableRows = document.getElementsByTagName("tr"); Element theadRow = (Element) tableRows.item(0); test.name = theadRow.getTextContent(); appendCellToRow(theadRow, "Result"); this.commandProcessor = new HtmlCommandProcessor(this.host, this.port, this.browser, this.baseUrl); String resultState; String resultLog; test.result = true; try { this.commandProcessor.start(); test.commands = new Command[tableRows.getLength() - 1]; for (int i = 1; i < tableRows.getLength(); i++) { Element stepRow = (Element) tableRows.item(i); Command command = executeStep(stepRow); appendCellToRow(stepRow, command.result); test.commands[i - 1] = command; if (command.error) { test.result = false; } if (command.failure) { test.result = false; // break; } } resultState = test.result ? "PASSED" : "FAILED"; resultLog = (test.result ? "Test Complete" : "Error"); this.commandProcessor.stop(); } catch (Exception e) { test.result = false; resultState = "ERROR"; resultLog = "Failed to initialize session\n" + e; e.printStackTrace(); } document.getElementById("result").setTextContent(resultState); Element log = document.getElementById("log"); log.setTextContent(log.getTextContent() + resultLog + "\n"); return test.result; }