/** * Retrieves default values from xml. * * @param list the configuration list */ private static void parseDefaults(NodeList list) { for (int i = 0; i < list.getLength(); ++i) { NamedNodeMap mapping = list.item(i).getAttributes(); String attribute = mapping.getNamedItem("attribute").getNodeValue(); String value = mapping.getNamedItem("value").getNodeValue(); try { Default field = Default.fromString(attribute); DEFAULTS.put(field, value); } catch (IllegalArgumentException exc) { logger.warn("Unrecognized default attribute: " + attribute); } } }
private static Category parseCategory(Node n) { NamedNodeMap atts = n.getAttributes(); String name = atts.getNamedItem("name").getNodeValue(); String desc = atts.getNamedItem("description").getNodeValue(); Category cat = new Category(name, desc); NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { parseNode(children.item(i), cat); } return cat; }
/** * Populates LOCALES list with contents of xml. * * @param list the configuration list */ private static void parseLocales(NodeList list) { for (int i = 0; i < list.getLength(); ++i) { Node node = list.item(i); NamedNodeMap attributes = node.getAttributes(); String label = ((Attr) attributes.getNamedItem("label")).getValue(); String code = ((Attr) attributes.getNamedItem("isoCode")).getValue(); String dictLocation = ((Attr) attributes.getNamedItem("dictionaryUrl")).getValue(); try { LOCALES.add(new Locale(label, code, new URL(dictLocation))); } catch (MalformedURLException exc) { logger.warn( "Unable to parse dictionary location of " + label + " (" + dictLocation + ")", exc); } } }
private static Command parseCommand(Node n) { NamedNodeMap atts = n.getAttributes(); String name = atts.getNamedItem("name").getNodeValue(); String desc = atts.getNamedItem("description").getNodeValue(); String command = atts.getNamedItem("command").getNodeValue(); Command com = new Command(name, desc, command); NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (!child.getNodeName().equals("Argument")) continue; NamedNodeMap childAtts = child.getAttributes(); String childName = childAtts.getNamedItem("name").getNodeValue(); String childDesc = childAtts.getNamedItem("description").getNodeValue(); String childVal = ""; if (childAtts.getNamedItem("default") != null) childVal = childAtts.getNamedItem("default").getNodeValue(); Argument arg = new Argument(childName, childDesc, childVal); com.addArgument(arg); } return com; }
/** * Metodo per la lettura e il salvataggio in DB dei dati relativi alla prima configurazione del * cinema multisala * * @throws Exception */ public static void readInitialConfig() throws Exception { // Lettura del file config.xml MySQLAccess msa = new MySQLAccess(); msa.readDB(); Document config = loadDocument(CONFIG_FILE); // Creazione della lista di sale NodeList cinemaHalls = findCinemaHall(config); for (int i = 0; i < cinemaHalls.getLength(); i++) { NamedNodeMap attr = cinemaHalls.item(i).getAttributes(); String[] s = attr.getNamedItem("id").toString().split("\""); // ID della sala i char id = s[1].toCharArray()[0]; s = attr.getNamedItem("name").toString().split("\""); // Nome sala i String name = s[1]; s = attr.getNamedItem("specialseat").toString().split("\""); // Numero posti speciali int specialSeats = Integer.parseInt(s[1]); NodeList rows = readRows((Element) cinemaHalls.item(i)); // Numero file della sala i int n_rows = rows.getLength(); // Numero posti totali int seats = 0; for (int j = 0; j < n_rows; j++) { // Numero posti della fila j int r_seats = Integer.parseInt(rows.item(j).getTextContent().toString().trim()); seats += r_seats; } // Invoca l'inserimento in DB msa.insertCinemaHall(id, name, n_rows, seats, specialSeats); for (int j = 0; j < n_rows; j++) { NamedNodeMap r_attr = rows.item(j).getAttributes(); s = r_attr.getNamedItem("number").toString().split("\""); int number = Integer.parseInt(s[1]); // Numero posti della fila j int r_seats = Integer.parseInt(rows.item(j).getTextContent().toString().trim()); msa.insertRow(id, number, r_seats); } } msa.closeDB(); }
public String getString(String name, String defaultValue) { NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { Node attr = attrs.getNamedItem(name); if (attr != null) { return attr.getNodeValue(); } } return defaultValue; }
/** Возвращает имя метода. */ public String getName() { /** Получаем атрибуты узла метода. */ NamedNodeMap attributes = node.getAttributes(); /** Получаем узел аттрибута. */ Node nameAttrib = attributes.getNamedItem("name"); /** Возвращаем значение атрибута. */ return nameAttrib.getNodeValue(); }
private static void parseXML() { try { Document doc = DocumentBuilderFactory.newInstance() .newDocumentBuilder() .parse(CommandBuilder.class.getResourceAsStream("/CommandMap.xml")); NodeList nodes = doc.getElementsByTagName("CommandMap"); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); NamedNodeMap atts = n.getAttributes(); String rootCommand = atts.getNamedItem("rootCommand").getNodeValue(); rootNode = new Category(rootCommand, ""); NodeList children = n.getChildNodes(); for (int p = 0; p < children.getLength(); p++) { parseNode(children.item(p), rootNode); } } } catch (Exception e) { e.printStackTrace(); } }
/** * @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(); } } }