Esempio n. 1
0
  private Node[] processIndexNode(
      final Node theNode,
      final Document theTargetDocument,
      final IndexEntryFoundListener theIndexEntryFoundListener) {
    theNode.normalize();

    boolean ditastyle = false;
    String textNode = null;

    final NodeList childNodes = theNode.getChildNodes();
    final StringBuilder textBuf = new StringBuilder();
    final List<Node> contents = new ArrayList<Node>();
    for (int i = 0; i < childNodes.getLength(); i++) {
      final Node child = childNodes.item(i);
      if (checkElementName(child)) {
        ditastyle = true;
        break;
      } else if (child.getNodeType() == Node.ELEMENT_NODE) {
        textBuf.append(XMLUtils.getStringValue((Element) child));
        contents.add(child);
      } else if (child.getNodeType() == Node.TEXT_NODE) {
        textBuf.append(child.getNodeValue());
        contents.add(child);
      }
    }
    textNode = IndexStringProcessor.normalizeTextValue(textBuf.toString());
    if (textNode.length() == 0) {
      textNode = null;
    }

    if (theNode.getAttributes().getNamedItem(elIndexRangeStartName) != null
        || theNode.getAttributes().getNamedItem(elIndexRangeEndName) != null) {
      ditastyle = true;
    }

    final ArrayList<Node> res = new ArrayList<Node>();
    if ((ditastyle)) {
      final IndexEntry[] indexEntries = indexDitaProcessor.processIndexDitaNode(theNode, "");

      for (final IndexEntry indexEntrie : indexEntries) {
        theIndexEntryFoundListener.foundEntry(indexEntrie);
      }

      final Node[] nodes = transformToNodes(indexEntries, theTargetDocument, null);
      for (final Node node : nodes) {
        res.add(node);
      }

    } else if (textNode != null) {
      final Node[] nodes =
          processIndexString(textNode, contents, theTargetDocument, theIndexEntryFoundListener);
      for (final Node node : nodes) {
        res.add(node);
      }
    } else {
      return new Node[0];
    }

    return (Node[]) res.toArray(new Node[res.size()]);
  }
  // Gets the specified XML Schema doc if one is mentioned in the file
  public static File getSchemaFile(Document xmlDoc) {
    /** @todo Must be an easier way of doing this... */
    logger.logComment("Getting schema file for: " + xmlDoc.getDocumentURI());

    NodeList nl = xmlDoc.getChildNodes();
    for (int j = 0; j < nl.getLength(); j++) {
      Node node = nl.item(j);
      logger.logComment("Type: " + node.getNodeType() + "Name: " + node.getNodeName());
      if (node.getNodeName().equals(XML_STYLESHEET_NODE)) {
        String nodeVal = node.getNodeValue();

        logger.logComment("Looking at: " + nodeVal);
        String xslFileName =
            nodeVal.substring(nodeVal.indexOf("href=\"") + 6, nodeVal.length() - 1);
        File xslFile = new File(xslFileName);
        return xslFile;
      }

      if (node.getAttributes().getLength() > 0) {
        logger.logComment("Attributes: " + node.getAttributes());
        if (node.getAttributes().getNamedItem(XML_SCHEMA_LOC_ATTR) != null) {
          String locString = node.getAttributes().getNamedItem(XML_SCHEMA_LOC_ATTR).getNodeValue();
          logger.logComment("Loc string: " + locString);
          String file = locString.split("\\s")[1];
          return new File(file);
        }
      }
    }
    logger.logError("No node found with name: " + XML_STYLESHEET_NODE);
    return null;
  }
Esempio n. 3
0
  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;
  }
Esempio n. 4
0
  public apiParser(String sdkfile) {
    System.out.println(sdkfile);
    File file = new File(sdkfile);
    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();

      Document doc = db.parse(file);
      NodeList apiList = doc.getElementsByTagName("n1:api");
      NodeList inputList = doc.getElementsByTagName("n1:input");
      NodeList typeList = doc.getElementsByTagName("n1:type");

      for (int i = 0; i < apiList.getLength(); i++) {
        Node api_node = apiList.item(i);
        String api_id = api_node.getAttributes().getNamedItem("id").getNodeValue();
        String api_name = api_node.getAttributes().getNamedItem("name").getNodeValue();
        String input_type_id =
            inputList.item(i).getAttributes().getNamedItem("type_ref").getNodeValue();

        // System.out.println(api_id + " : " + api_name + " : " + input_type_id);
        ArrayList<String> api_params = new ArrayList<String>();

        for (int j = 0; j < typeList.getLength(); j++) {

          if (input_type_id.equalsIgnoreCase(
              typeList.item(j).getAttributes().getNamedItem("id").getNodeValue())) {
            Element e1 = (Element) typeList.item(j);

            NodeList param_l = e1.getElementsByTagName("n1:param");

            for (int k = 0; k < param_l.getLength(); k++) {

              String param_name =
                  param_l.item(k).getAttributes().getNamedItem("name").getNodeValue();
              // String param_desc =
              // param_l.item(k).getAttributes().getNamedItem("desc").getNodeValue();
              api_params.add(param_name);
              // System.out.println(param_name +":"+param_desc);
            }

            break;
          }
        }
        apiRoom s_room = new apiRoom(api_id, api_name, api_params);
        apiRooms.add(s_room);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 5
0
 public static final Map parseFrame(Node node) {
   NodeList bones = node.getChildNodes();
   Map bone_infos = new HashMap();
   for (int i = 0; i < bones.getLength(); i++) {
     Node bone = bones.item(i);
     if (bone.getNodeName().equals("transform")) {
       String name = bone.getAttributes().getNamedItem("name").getNodeValue();
       float[] matrix = new float[16];
       matrix[0 * 4 + 0] = getAttrFloat(bone, "m00");
       matrix[0 * 4 + 1] = getAttrFloat(bone, "m01");
       matrix[0 * 4 + 2] = getAttrFloat(bone, "m02");
       matrix[0 * 4 + 3] = getAttrFloat(bone, "m03");
       matrix[1 * 4 + 0] = getAttrFloat(bone, "m10");
       matrix[1 * 4 + 1] = getAttrFloat(bone, "m11");
       matrix[1 * 4 + 2] = getAttrFloat(bone, "m12");
       matrix[1 * 4 + 3] = getAttrFloat(bone, "m13");
       matrix[2 * 4 + 0] = getAttrFloat(bone, "m20");
       matrix[2 * 4 + 1] = getAttrFloat(bone, "m21");
       matrix[2 * 4 + 2] = getAttrFloat(bone, "m22");
       matrix[2 * 4 + 3] = getAttrFloat(bone, "m23");
       matrix[3 * 4 + 0] = getAttrFloat(bone, "m30");
       matrix[3 * 4 + 1] = getAttrFloat(bone, "m31");
       matrix[3 * 4 + 2] = getAttrFloat(bone, "m32");
       matrix[3 * 4 + 3] = getAttrFloat(bone, "m33");
       bone_infos.put(name, matrix);
     }
   }
   return bone_infos;
 }
  /**
   * 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();
    }
  }
  // factory
  private static GenerationTarget createTarget(File templateFile, File root) {
    GenerationTarget target;

    // read XML document
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    try {
      DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
      Document doc = docBuilder.parse(templateFile);

      // get name
      NodeList nodes = doc.getElementsByTagName("templates");
      Node node = nodes.item(0);
      NamedNodeMap attrs = node.getAttributes();
      Node attr = attrs.getNamedItem("name");
      String templateName = attr.getNodeValue();
      target = new GenerationTarget(templateFile, root, templateName);

      // get class directives
      nodes = doc.getElementsByTagName("project");
      int nb = nodes.getLength();
      for (int i = 0; i < nb; i++) {
        node = nodes.item(i);
        createProjectDirective(target, node);
      }

    } catch (ParserConfigurationException ex) {
      target = null;
    } catch (IOException ex) {
      target = null;
    } catch (SAXException ex) {
      target = null;
    } // end try

    return target;
  }
Esempio n. 8
0
      public void onDocument(Document document, String xpath) throws XmlParserException {
        if (xpath.equals(XPATH_IPEAK)) {
          Node node = document.getFirstChild();

          // check whether we're getting the correct ipeak
          Node typeattribute = node.getAttributes().getNamedItem(PeakMLWriter.TYPE);
          if (typeattribute == null)
            throw new XmlParserException("Failed to locate the type attribute.");
          if (!typeattribute.getNodeValue().equals(PeakMLWriter.TYPE_BACKGROUNDION))
            throw new XmlParserException(
                "IPeak ("
                    + typeattribute.getNodeValue()
                    + ") is not of type: '"
                    + PeakMLWriter.TYPE_BACKGROUNDION
                    + "'");

          // parse this node as a mass chromatogram
          BackgroundIon<? extends Peak> backgroundion = parseBackgroundIon(node);
          if (backgroundion != null) peaks.add(backgroundion);

          //
          if (_listener != null && result.header != null && result.header.getNrPeaks() != 0)
            _listener.update((100. * index++) / result.header.getNrPeaks());
        } else if (xpath.equals(XPATH_HEADER)) {
          result.header = parseHeader(document.getFirstChild());
        }
      }
Esempio n. 9
0
 private static Address unmarshallAddress(Node addressNode) {
   Address address = new Address();
   NamedNodeMap addressNodeAttributes = addressNode.getAttributes();
   address.setCity(addressNodeAttributes.item(1).getNodeValue());
   address.setCountryCode(addressNodeAttributes.item(2).getNodeValue());
   address.setAddress(addressNodeAttributes.item(0).getNodeValue());
   return address;
 }
Esempio n. 10
0
 /**
  * Get a list of the names for all of the attributes for this node.
  *
  * @webref xml:method
  * @brief Returns a list of names of all attributes as an array
  */
 public String[] listAttributes() {
   NamedNodeMap nnm = node.getAttributes();
   String[] outgoing = new String[nnm.getLength()];
   for (int i = 0; i < outgoing.length; i++) {
     outgoing[i] = nnm.item(i).getNodeName();
   }
   return outgoing;
 }
Esempio n. 11
0
 /**
  * Gets an attribute value from a node.
  *
  * @param node The node to get the attribute value from.
  * @param attributeName The name of the wanted attribute.
  * @return The attribute value or <code>null</code> if there is no such attribute.
  */
 public static String getAttribute(Node node, String attributeName) {
   Node attributeNode = node.getAttributes().getNamedItem(attributeName);
   if (attributeNode == null) {
     return null;
   } else {
     return attributeNode.getNodeValue();
   }
 }
Esempio n. 12
0
 private void extractAttribute(
     Set<String> pReadAttributes, Set<String> pWriteAttributes, Node pParam) {
   Node mode = pParam.getAttributes().getNamedItem("mode");
   pReadAttributes.add(pParam.getTextContent().trim());
   if (mode == null || !mode.getNodeValue().equalsIgnoreCase("read")) {
     pWriteAttributes.add(pParam.getTextContent().trim());
   }
 }
 /**
  * parse plants.xml to get all plants information
  *
  * @param root
  * @return
  */
 public static ArrayList<Plants> getPlant(Node root) {
   ArrayList<Plants> p = new ArrayList<Plants>();
   String code = null;
   String common = null;
   String botanical = null;
   String light = null;
   String zone = null;
   String price = null;
   String available = null;
   root.getChildNodes();
   for (int i = 0; i < root.getChildNodes().getLength(); i++) {
     Node state = root.getChildNodes().item(i);
     if (state.getNodeType() == Node.ELEMENT_NODE) {
       code = state.getAttributes().getNamedItem("code").getNodeValue();
       NodeList plantNodes = state.getChildNodes();
       for (int j = 0; j < plantNodes.getLength(); j++) {
         Node plant = plantNodes.item(j);
         if (plant.getNodeType() == Node.ELEMENT_NODE) {
           // get the pointer point to the node list of plant
           NodeList plantChildren = plant.getChildNodes();
           int m = 0;
           for (int k = 0; k < plantChildren.getLength(); k++) {
             if (plantChildren.item(k).getNodeType() == Node.ELEMENT_NODE) {
               m++;
               NodeList textNodes = plantChildren.item(k).getChildNodes();
               for (int n = 0; n < textNodes.getLength(); n++) {
                 if (textNodes.item(n).getNodeType() == Node.TEXT_NODE) {
                   switch (m) {
                     case 1:
                       common = textNodes.item(n).getNodeValue();
                       break;
                     case 2:
                       botanical = textNodes.item(n).getNodeValue();
                       break;
                     case 3:
                       zone = textNodes.item(n).getNodeValue();
                       break;
                     case 4:
                       light = textNodes.item(n).getNodeValue();
                       break;
                     case 5:
                       price = textNodes.item(n).getNodeValue().substring(1);
                       break;
                     case 6:
                       available = textNodes.item(n).getNodeValue();
                       break;
                   }
                 }
               }
             }
           }
           p.add(new Plants(code, common, botanical, zone, light, price, available));
         }
       }
     }
   }
   return p;
 }
Esempio n. 14
0
 public static void traverseAMLforObjectNames(
     HashMap partialMap, Node currentNode, HashMap ObjDef_LinkId, HashMap ModelId_ModelType) {
   if (currentNode.hasChildNodes()) {
     for (int i = 0; i < currentNode.getChildNodes().getLength(); i++) {
       Node currentChild = currentNode.getChildNodes().item(i);
       if (currentChild.getNodeName().equals("Group")) {
         traverseAMLforObjectNames(partialMap, currentChild, ObjDef_LinkId, ModelId_ModelType);
       }
       if (currentChild.getNodeName().equals("Model")) {
         if (currentChild.hasAttributes()) {
           String mid = currentChild.getAttributes().getNamedItem("Model.ID").getNodeValue();
           String type = currentChild.getAttributes().getNamedItem("Model.Type").getNodeValue();
           ModelId_ModelType.put(mid, type);
         }
         // traverseAMLforObjectNames(partialMap, currentChild,
         // ObjDef_LinkId);
       }
       if (currentChild.getNodeName().equals("ObjDef")) {
         String id = currentChild.getAttributes().getNamedItem("ObjDef.ID").getNodeValue();
         NodeList currentChildren = currentChild.getChildNodes();
         String ObjName = "";
         for (int k = 0; k < currentChildren.getLength(); k++) {
           Node Child = currentChildren.item(k);
           if (!Child.getNodeName().equals("AttrDef")) {
             continue;
           } else if (!Child.getAttributes()
               .getNamedItem("AttrDef.Type")
               .getNodeValue()
               .equals("AT_NAME")) {
             continue;
           } else if (Child.hasChildNodes()) {
             for (int l = 0; l < Child.getChildNodes().getLength(); l++) {
               if (!(Child.getChildNodes().item(l).getNodeName().equals("AttrValue"))) {
                 continue;
               } else {
                 ObjName = getTextContent(Child.getChildNodes().item(l));
                 ObjName = ObjName.replaceAll("\n", "\\\\n");
                 break;
               }
             }
           }
         }
         partialMap.put(id, ObjName);
         for (int j = 0; j < currentChild.getAttributes().getLength(); j++) {
           if (currentChild.getAttributes().item(j).getNodeName().equals("LinkedModels.IdRefs")) {
             String links =
                 currentChild.getAttributes().getNamedItem("LinkedModels.IdRefs").getNodeValue();
             /*
              * if (links.indexOf(" ") > -1) {
              * Message.add("yes, yes, yes"); links =
              * links.substring(0, links.indexOf(" ")); }
              */
             ObjDef_LinkId.put(id, links);
           }
         }
       }
     }
   }
 }
Esempio n. 15
0
 private static IPeak parseIPeak(Node parent) throws XmlParserException {
   Node type = parent.getAttributes().getNamedItem(PeakMLWriter.TYPE);
   if (type == null) return null;
   else if (type.getNodeValue().equals(PeakMLWriter.TYPE_PEAKSET)) return parsePeakSet(parent);
   else if (type.getNodeValue().equals(PeakMLWriter.TYPE_BACKGROUNDION))
     return parseBackgroundIon(parent);
   else if (type.getNodeValue().equals(PeakMLWriter.TYPE_MASSCHROMATOGRAM))
     return parseMassChromatogram(parent);
   else return null;
 }
Esempio n. 16
0
 public String getAtributo(Node nodo, String nombreAtributo) {
   NamedNodeMap atts;
   atts = nodo.getAttributes();
   if (atts == null) return null;
   for (int i = 0; i < atts.getLength(); i++) {
     Node atributo = atts.item(i);
     if (atributo.getNodeName().equalsIgnoreCase(nombreAtributo)) return atributo.getNodeValue();
   }
   return null;
 }
Esempio n. 17
0
 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;
 }
Esempio n. 18
0
 private static final Skeleton parseSkeleton(Node skel_node) {
   Map name_to_bone_map = new HashMap();
   Map initial_pose =
       AnimationLoader.parseFrame(ConvertToBinary.getNodeByName("init_pose", skel_node));
   NodeList bone_list = ConvertToBinary.getNodeByName("bones", skel_node).getChildNodes();
   Map bone_parent_map = new HashMap();
   for (int i = 0; i < bone_list.getLength(); i++) {
     Node bone_node = bone_list.item(i);
     if (bone_node.getNodeName().equals("bone")) {
       String bone_name = bone_node.getAttributes().getNamedItem("name").getNodeValue();
       String bone_parent_name = bone_node.getAttributes().getNamedItem("parent").getNodeValue();
       // System.out.println("bone name = " + bone_name + " parent name = " + bone_parent_name);
       bone_parent_map.put(bone_name, bone_parent_name);
     }
   }
   Map bone_children_map = new HashMap();
   Iterator it = bone_parent_map.keySet().iterator();
   String root = null;
   while (it.hasNext()) {
     String name = (String) it.next();
     String parent = (String) bone_parent_map.get(name);
     if (bone_parent_map.get(parent) == null) {
       if (root != null) {
         System.out.println(
             "WARNING: Multiple roots in skeleton, root = "
                 + root
                 + ", additional root = "
                 + name);
         parent = root;
         bone_parent_map.put(name, parent);
       } else root = name;
     }
     List parent_children = (List) bone_children_map.get(parent);
     if (parent_children == null) {
       parent_children = new ArrayList();
       bone_children_map.put(parent, parent_children);
     }
     parent_children.add(name);
   }
   Bone bone_root = buildBone((byte) 0, bone_children_map, root, name_to_bone_map);
   return new Skeleton(bone_root, initial_pose, name_to_bone_map);
 }
Esempio n. 19
0
 private static Customer customerUnmarshaller(Node customerNode) {
   Customer customer = new Customer();
   NamedNodeMap customerAttributes = customerNode.getAttributes();
   customer.setFirstName(customerAttributes.item(0).getNodeValue());
   customer.setLastName(customerAttributes.item(1).getNodeValue());
   Node addressNode = customerNode.getFirstChild().getNextSibling();
   customer.setAddress(unmarshallAddress(addressNode));
   Node dataNode = customerNode.getFirstChild().getNextSibling().getNextSibling().getNextSibling();
   customer.setData(unmarshallData(dataNode));
   return customer;
 }
Esempio n. 20
0
    /** Возвращает имя метода. */
    public String getName() {

      /** Получаем атрибуты узла метода. */
      NamedNodeMap attributes = node.getAttributes();

      /** Получаем узел аттрибута. */
      Node nameAttrib = attributes.getNamedItem("name");

      /** Возвращаем значение атрибута. */
      return nameAttrib.getNodeValue();
    }
Esempio n. 21
0
  public static Map<String, String> getAttrList(Node node) {
    Map<String, String> map = new HashMap<String, String>();

    NamedNodeMap list = node.getAttributes();
    if (list != null)
      for (int i = 0; i < list.getLength(); i++) {
        Attr attr = (Attr) list.item(i);
        map.put(attr.getName(), attr.getValue());
      }

    return map;
  }
Esempio n. 22
0
 private Properties parseAttributes(Node n) {
   Properties attributes = new Properties();
   NamedNodeMap attributeNodes = n.getAttributes();
   if (attributeNodes != null) {
     for (int i = 0; i < attributeNodes.getLength(); i++) {
       Node attribute = attributeNodes.item(i);
       String value = attribute.getNodeValue();
       attributes.put(attribute.getNodeName(), value);
     }
   }
   return attributes;
 }
 /**
  * Runs the test case.
  *
  * @throws Throwable Any uncaught exception causes test to fail
  */
 public void runTest() throws Throwable {
   Document doc;
   NodeList elementList;
   Node testEmployee;
   NamedNodeMap attributes;
   int length;
   doc = (Document) load("staff", true);
   elementList = doc.getElementsByTagName("address");
   testEmployee = elementList.item(2);
   attributes = testEmployee.getAttributes();
   length = (int) attributes.getLength();
   assertEquals("length", 2, length);
 }
Esempio n. 24
0
  /**
   * 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();
    }
  }
  private static void createProjectDirective(GenerationTarget target, Node node) {
    NamedNodeMap attrs = node.getAttributes();
    Node attr = attrs.getNamedItem("file");
    String templateFile = attr.getNodeValue();

    attr = attrs.getNamedItem("baseName");
    String baseName = attr.getNodeValue();

    attr = attrs.getNamedItem("output");
    String pattern = attr.getNodeValue();

    ProjectDirective directive = new ProjectDirective(templateFile, baseName, pattern);
    target.directives.add(directive);
  }
Esempio n. 26
0
  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;
  }
 /**
  * Runs the test case.
  *
  * @throws Throwable Any uncaught exception causes test to fail
  */
 public void runTest() throws Throwable {
   Document doc;
   NodeList addressList;
   Node testNode;
   NamedNodeMap attributes;
   Attr streetAttr;
   boolean state;
   doc = (Document) load("staff", false);
   addressList = doc.getElementsByTagName("address");
   testNode = addressList.item(0);
   attributes = testNode.getAttributes();
   streetAttr = (Attr) attributes.getNamedItem("street");
   state = streetAttr.getSpecified();
   assertFalse("streetNotSpecified", state);
 }
Esempio n. 28
0
 /**
  * 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);
     }
   }
 }
 /**
  * Runs the test case.
  *
  * @throws Throwable Any uncaught exception causes test to fail
  */
 public void runTest() throws Throwable {
   Document doc;
   NodeList addressList;
   Node testNode;
   NamedNodeMap attributes;
   Attr domesticAttr;
   Element elementNode;
   String name;
   doc = (Document) load("staff", false);
   addressList = doc.getElementsByTagName("address");
   testNode = addressList.item(0);
   attributes = testNode.getAttributes();
   domesticAttr = (Attr) attributes.getNamedItem("domestic");
   elementNode = domesticAttr.getOwnerElement();
   name = elementNode.getNodeName();
   assertEquals("throw_Equals", "address", name);
 }
Esempio n. 30
0
  /**
   * Prints a XML node.
   *
   * @param out The PrintStream where to print the node.
   * @param prefix The prefix to put before every line.
   * @param node The node to print.
   * @throws IOException If printing failed.
   */
  private static void printNode(PrintStream out, String prefix, Node node) throws IOException {
    prefix = "";

    String name = node.getNodeName();

    boolean isText = name.equals("#text");
    boolean isComment = name.equals("#comment");
    boolean isCDATA = name.equals("#cdata-section");
    if (isText) {
      // This is a text tag
      String text = node.getNodeValue();
      text = RegainToolkit.replace(text, "<", "&lt;");
      text = RegainToolkit.replace(text, ">", "&gt;");
      text = RegainToolkit.replace(text, "--", "&minus;&minus;");
      out.print(text);
    } else if (isComment) {
      // This is a comment tag
      String comment = node.getNodeValue();
      out.print("<!--" + comment + "-->");
    } else if (isCDATA) {
      String text = node.getNodeValue();
      out.print("<![CDATA[" + text + "]]>");
    } else {
      // This is a normal tag
      out.print(prefix + "<" + name);
      if (node.hasAttributes()) {
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
          Node attrib = attributes.item(i);
          out.print(" " + attrib.getNodeName() + "=\"" + attrib.getNodeValue() + "\"");
        }
      }

      if (!node.hasChildNodes()) {
        out.print("/>");
      } else {
        out.print(">");
        NodeList childList = node.getChildNodes();
        String childPrefix = prefix + "  ";
        for (int i = 0; i < childList.getLength(); i++) {
          printNode(out, childPrefix, childList.item(i));
        }
        out.print(prefix + "</" + name + ">");
      }
    }
  }