Example #1
0
  private void recursivelyAddFormElements(
      Map<String, FormElement> formElementMap, NodeList nodeList, String uri) {
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node element = nodeList.item(i);
      if (hasChildElements(element)) {

        if (element.hasAttributes()) { // repeat group
          String localUri = uri + SLASH + element.getNodeName();
          FormElement formElement =
              new FormElementBuilder()
                  .setName(localUri)
                  .setLabel(localUri)
                  .setType(FieldTypeConstants.REPEAT_GROUP)
                  .setChildren(new ArrayList<FormElement>())
                  .createFormElement();
          formElementMap.put(formElement.getName(), formElement);
          recursivelyAddGroup(
              formElementMap,
              element.getChildNodes(),
              uri + SLASH + element.getNodeName(),
              formElement.getChildren(),
              formElement);
        } else {
          recursivelyAddFormElements(
              formElementMap, element.getChildNodes(), uri + SLASH + element.getNodeName());
        }
      } else if (element.getNodeType() == Node.ELEMENT_NODE) {
        String localUri = uri + SLASH + element.getNodeName();
        FormElement formElement =
            new FormElementBuilder().setName(localUri).setLabel(localUri).createFormElement();
        formElementMap.put(formElement.getName(), formElement);
      }
    }
  }
  /**
   * @return a <code>Map</code> of of textual values keyed off the values of any lang or xml:lang
   *     attributes specified on an attribute. If no such attribute exists, then the key {@link
   *     ApplicationResourceBundle#DEFAULT_KEY} will be used (i.e. this represents the default
   *     Locale).
   * @param list a list of nodes representing textual elements such as description or display-name
   */
  protected Map<String, String> getTextMap(List<Node> list) {

    if (list != null && !list.isEmpty()) {
      int len = list.size();
      HashMap<String, String> names = new HashMap<String, String>(len, 1.0f);
      for (int i = 0; i < len; i++) {
        Node node = list.get(i);
        String textValue = getNodeText(node);
        if (textValue != null) {
          if (node.hasAttributes()) {
            NamedNodeMap attributes = node.getAttributes();
            String lang = getNodeText(attributes.getNamedItem("lang"));
            if (lang == null) {
              lang = getNodeText(attributes.getNamedItem("xml:lang"));
            }
            if (lang != null) {
              names.put(lang, textValue);
            } else {
              names.put(ApplicationResourceBundle.DEFAULT_KEY, textValue);
            }
          } else {
            names.put(ApplicationResourceBundle.DEFAULT_KEY, textValue);
          }
        }
      }

      return names;
    }

    return null;
  }
Example #3
0
  //	 This method recursively traverses the XML Tree (starting from currElement)
  public void traverseXML(Node currNode) {
    // If it's an Element, spit out the Name
    if (currNode.getNodeType() == Node.ELEMENT_NODE) {
      System.out.print(currNode.getNodeName() + ": ");
      // If it's a "Text" node, take the value
      // These will come one after another and therefore appear in the right order
    } else if (currNode.getNodeType() == Node.TEXT_NODE) {
      System.out.println(currNode.getNodeValue().trim());
    }

    // Display any attributes
    if (currNode.hasAttributes()) {
      NamedNodeMap attributes = currNode.getAttributes();
      for (int i = 0; i < attributes.getLength(); i++) {
        Node attr = attributes.item(i);
        System.out.println("  " + attr.getNodeName() + ": " + attr.getNodeValue());
      }
    }

    // Check any children
    if (currNode.hasChildNodes()) {
      // Get the list of children
      NodeList children = currNode.getChildNodes();
      // Go through all the chilrden
      for (int i = 0; i < children.getLength(); i++) {
        // Search each Node
        Node n = children.item(i);
        traverseXML(n);
      }
    }
  }
Example #4
0
 private void createAndCacheNamespaces(Ruby ruby, Node node) {
   if (node == null) return;
   if (node.hasAttributes()) {
     NamedNodeMap nodeMap = node.getAttributes();
     for (int i = 0; i < nodeMap.getLength(); i++) {
       Node n = nodeMap.item(i);
       if (n instanceof Attr) {
         Attr attr = (Attr) n;
         String attrName = attr.getName();
         // not sure, but need to get value always before document is referred.
         // or lose attribute value
         String attrValue = attr.getValue();
         if (isNamespace(attrName)) {
           String prefix = getLocalNameForNamespace(attrName);
           prefix = prefix != null ? prefix : "";
           nsCache.put(ruby, prefix, attrValue, node, this);
         }
       }
     }
   }
   NodeList children = node.getChildNodes();
   for (int i = 0; i < children.getLength(); i++) {
     createAndCacheNamespaces(ruby, children.item(i));
   }
 }
  public static Component fromXML(Node componentN) {

    String name = componentN.getNodeName();
    if (!name.equals("component"))
      throw new RuntimeException("did not get component element, but " + name);

    String type = getAttribute(componentN, "type");
    String nTerminalS = getAttribute(componentN, "nTerminal");
    String cTerminalS = getAttribute(componentN, "cTerminal");

    boolean isNTerminal = Boolean.parseBoolean(nTerminalS);
    boolean isCTerminal = Boolean.parseBoolean(cTerminalS);

    Set<String> pdbccIds = new HashSet<String>();

    NodeList valList = componentN.getChildNodes();
    int numChildren = valList.getLength();

    for (int e = 0; e < numChildren; e++) {
      Node pdbccN = valList.item(e);

      if (!pdbccN.hasAttributes()) continue;

      if (pdbccN.getNodeName().equals("pdbccID")) {
        String id = getAttribute(pdbccN, "id");
        pdbccIds.add(id);
      }
    }

    Component c = Component.of(pdbccIds, isNTerminal, isCTerminal);
    return c;
  }
Example #6
0
 private void readPositionalFieldNode(Node node, PositionalRecordDescriptor recordDescriptorIn)
     throws MetadataReaderException {
   PositionalFieldDescriptor positionalFieldDescriptor = new PositionalFieldDescriptor();
   if (node.hasAttributes()) {
     NamedNodeMap attributes = node.getAttributes();
     for (int i = 0; i < attributes.getLength(); i++) {
       Node attr = attributes.item(i);
       if (attr.getNodeName().equals("name")) {
         String fieldName = attr.getNodeValue();
         Method getter;
         try {
           getter =
               ReflectUtil.getGetterFromFieldName(fieldName, recordDescriptorIn.getRecordClazz());
         } catch (SecurityException e) {
           throw new MetadataReaderException(e);
         } catch (NoSuchMethodException e) {
           throw new MetadataReaderException(
               "Getter method not found for field name: " + fieldName, e);
         }
         positionalFieldDescriptor.setGetter(getter);
       } else if (attr.getNodeName().equals("decorator-class")) {
         String decoratorClazzName = attr.getNodeValue();
         FieldDecorator<?> decorator;
         try {
           Object decoratorObj = Class.forName(decoratorClazzName).newInstance();
           if (FieldDecorator.class.isInstance(decoratorObj)) {
             decorator = (FieldDecorator<?>) decoratorObj;
           } else {
             throw new MetadataReaderException(
                 "Decorator class must be a subtype of " + FieldDecorator.class);
           }
         } catch (ClassNotFoundException e) {
           throw new MetadataReaderException(
               "Decorator class not found on classpath: " + decoratorClazzName, e);
         } catch (Exception e) {
           throw new MetadataReaderException(
               "Error while instantiating decorator class: " + decoratorClazzName, e);
         }
         positionalFieldDescriptor.setDecorator(decorator);
       } else if (attr.getNodeName().equals("initial-position")) {
         int initialPosition = Integer.parseInt(attr.getNodeValue());
         positionalFieldDescriptor.setInitialPosition(initialPosition);
       } else if (attr.getNodeName().equals("final-position")) {
         int finalPosition = Integer.parseInt(attr.getNodeValue());
         positionalFieldDescriptor.setFinalPosition(finalPosition);
       } else if (attr.getNodeName().equals("padding-align")) {
         PaddingAlign paddingAlign = PaddingAlign.valueOf(attr.getNodeValue());
         positionalFieldDescriptor.setPaddingAlign(paddingAlign);
       } else if (attr.getNodeName().equals("padding-character")) {
         String paddingCharacter = attr.getNodeValue();
         positionalFieldDescriptor.setPaddingCharacter(paddingCharacter.charAt(0));
       } else if (attr.getNodeName().equals("trim-on-read")) {
         boolean trimOnRead = Boolean.valueOf(attr.getNodeValue());
         positionalFieldDescriptor.setTrimOnRead(trimOnRead);
       }
     }
   }
   recordDescriptorIn.getFieldDescriptors().add(positionalFieldDescriptor);
 }
Example #7
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);
           }
         }
       }
     }
   }
 }
Example #8
0
 public static String getAttribute(Node node, String attrName) {
   String attrValue = ""; // $NON-NLS-1$
   if (node != null && node.hasAttributes()) {
     NamedNodeMap attrs = node.getAttributes();
     Node attribute = attrs.getNamedItem(attrName);
     if (attribute != null) attrValue = attribute.getNodeValue();
   }
   return attrValue;
 }
Example #9
0
  public static String getAttributeValue(Node node, String name) {
    if (node.hasAttributes()) {
      NamedNodeMap map = node.getAttributes();
      Node attribute = map.getNamedItem(name);

      if (attribute != null) return attribute.getNodeValue().trim();
    }

    return null;
  }
Example #10
0
  public static HashMap<String, String> getAttributes(Node node) {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    if (node.hasAttributes()) {
      NamedNodeMap nodeMap = node.getAttributes();
      for (int i = 0; i < nodeMap.getLength(); i++) {
        Node attribute = nodeMap.item(i);
        hashMap.put(attribute.getNodeName(), attribute.getNodeValue());
      }
    }

    return hashMap;
  }
Example #11
0
  /**
   * @param expression
   * @param attribute
   * @return
   * @throws CciDistPortalExceptionC
   */
  public String getSiblingAttributeValue(String expression, String attribute)
      throws CciDistPortalExceptionC {
    NodeList nodeList = getNodeList(expression);
    if (nodeList != null) {
      Node node = nodeList.item(0);

      if (node != null
          && node.hasAttributes()
          && node.getAttributes().getNamedItem(attribute) != null) {
        return node.getAttributes().getNamedItem(attribute).getTextContent();
      }
    }
    return "";
  }
  private static String getAttribute(Node node, String attr) {
    if (!node.hasAttributes()) return null;

    NamedNodeMap atts = node.getAttributes();

    if (atts == null) return null;

    Node att = atts.getNamedItem(attr);
    if (att == null) return null;

    String value = att.getTextContent();

    return value;
  }
Example #13
0
 private void readDelimitedFieldNode(Node node, DelimitedRecordDescriptor recordDescriptorIn)
     throws MetadataReaderException {
   DelimitedFieldDescriptor delimitedFieldDescriptor = new DelimitedFieldDescriptor();
   if (node.hasAttributes()) {
     NamedNodeMap attributes = node.getAttributes();
     for (int i = 0; i < attributes.getLength(); i++) {
       Node attr = attributes.item(i);
       if (attr.getNodeName().equals("name")) {
         String fieldName = attr.getNodeValue();
         Method getter;
         try {
           getter =
               ReflectUtil.getGetterFromFieldName(fieldName, recordDescriptorIn.getRecordClazz());
         } catch (SecurityException e) {
           throw new MetadataReaderException(e);
         } catch (NoSuchMethodException e) {
           throw new MetadataReaderException(
               "Getter method not found for field name: " + fieldName, e);
         }
         delimitedFieldDescriptor.setGetter(getter);
       } else if (attr.getNodeName().equals("decorator-class")) {
         String decoratorClazzName = attr.getNodeValue();
         FieldDecorator<?> decorator;
         try {
           Object decoratorObj = Class.forName(decoratorClazzName).newInstance();
           if (FieldDecorator.class.isInstance(decoratorObj)) {
             decorator = (FieldDecorator<?>) decoratorObj;
           } else {
             throw new MetadataReaderException(
                 "Decorator class must be a subtype of " + FieldDecorator.class);
           }
         } catch (ClassNotFoundException e) {
           throw new MetadataReaderException(
               "Decorator class not found on classpath: " + decoratorClazzName, e);
         } catch (Exception e) {
           throw new MetadataReaderException(
               "Error while instantiating decorator class: " + decoratorClazzName, e);
         }
         delimitedFieldDescriptor.setDecorator(decorator);
       } else if (attr.getNodeName().equals("position-index")) {
         int positionIndex = Integer.parseInt(attr.getNodeValue());
         delimitedFieldDescriptor.setPositionIndex(positionIndex);
       }
     }
   }
   recordDescriptorIn.getFieldDescriptors().add(delimitedFieldDescriptor);
 }
Example #14
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 + ">");
      }
    }
  }
  /**
   * A single node is read, the namespace attributes are extracted and stored.
   *
   * @param node to examine
   * @param attributesOnly, if true no recursion happens
   */
  private void examineNode(Node node, boolean attributesOnly) {

    if (node.hasAttributes()) {
      NamedNodeMap attributes = node.getAttributes();
      for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        storeAttribute((Attr) attribute);
      }
    }

    if (!attributesOnly && node.hasChildNodes()) {
      NodeList children = node.getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) examineNode(child, false);
      }
    }
  }
Example #16
0
  /*
   * processAttributes:
   * 	This method gets all of the attributes for a given soda element.
   *
   * Intput:
   * 	map: This is the soda element's map.
   *  node: This is the xml node for the given element.
   *
   * Output:
   * 	returns a SodaHash object filled with the node's attributes if it has any.  If there are
   * 	no attributes then an empty SodaHash is returned.
   *
   */
  private SodaHash processAttributes(SodaHash map, Node node) {
    int len = node.getAttributes().getLength();

    if (node.hasAttributes()) {
      for (int i = 0; i <= len - 1; i++) {
        Node tmp = node.getAttributes().item(i);
        String name = tmp.getNodeName();
        String value = tmp.getNodeValue();
        String accessor = findElementAccessor((SodaElements) map.get("type"), name);
        map.put(name, value);

        if (accessor != null) {
          map.put("how", accessor);
        }
      }
    }

    return map;
  }
  public List<Configuration> getConfigObjFromXml(String featureManifestXml)
      throws PhrescoException {
    List<Configuration> configs = new ArrayList<Configuration>();
    try {
      File featureManifestXmlFile = new File(featureManifestXml);

      Configuration config = null;
      if (featureManifestXmlFile.isFile()) {
        config = new Configuration(featureManifestXmlFile.getName(), FEATURES);
      } else {
        return Collections.emptyList();
      }

      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
      Document doc = dBuilder.parse(featureManifestXmlFile);
      doc.getDocumentElement().normalize();

      NodeList nList = doc.getElementsByTagName(CONFIG_TAG);
      Properties properties = new Properties();
      for (int temp = 0; temp < nList.getLength(); temp++) {
        Node nNode = nList.item(temp);
        // get attributes
        if (nNode.hasAttributes()) {
          NamedNodeMap attributes = nNode.getAttributes();
          Node name = attributes.getNamedItem(NAME);
          if (name != null) {
            Element eElement = (Element) nNode;
            String defaultValue = getTagValue(DEFAULT_VALUE, eElement);
            String currentValue = getTagValue(CURRENT_VALUE, eElement);
            String value = StringUtils.isNotEmpty(currentValue) ? currentValue : defaultValue;
            properties.put(name.getNodeValue(), value);
          }
        }
      }
      config.setProperties(properties);
      configs.add(config);
    } catch (Exception e) {
      throw new PhrescoException(e);
    }
    return configs;
  }
Example #18
0
  private void parseValues(String name, NodeList nodeList) {
    MAttr attr = null;
    for (int count = 0; count < nodeList.getLength(); count++) {
      Node tempNode = nodeList.item(count);
      if (tempNode.getNodeType() == Node.ELEMENT_NODE && tempNode.hasAttributes()) {

        if (attr == null) {
          if (tempNode.getNodeName().equals("enum")) {
            attr = new MAttr(MAttrType.ENUM);
          } else if (tempNode.getNodeName().equals("flag")) {
            attr = new MAttr(MAttrType.FLAG);
          }
          if (attr == null) {
            return;
          }
          attrMap.put(name, attr);
        }

        NamedNodeMap attributes = tempNode.getAttributes();
        Node nameNode = attributes.getNamedItem("name");
        if (nameNode != null) {
          Node valueNode = attributes.getNamedItem("value");
          if (valueNode != null) {
            try {
              long key;
              String nodeValue = valueNode.getNodeValue();
              if (nodeValue.startsWith("0x")) {
                nodeValue = nodeValue.substring(2);
                key = Long.parseLong(nodeValue, 16);
              } else {
                key = Long.parseLong(nodeValue);
              }
              attr.getValues().put(key, nameNode.getNodeValue());
            } catch (NumberFormatException e) {
              LOG.debug("Failed parse manifest number", e);
            }
          }
        }
      }
    }
  }
 /**
  * @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();
 }
Example #20
0
 private RecordDescriptor readFFPojoNode(Node node) throws MetadataReaderException {
   RecordDescriptor recordDescriptor = null;
   Class<?> recordClazz = null;
   if (node.hasAttributes()) {
     NamedNodeMap attributes = node.getAttributes();
     for (int i = 0; i < attributes.getLength(); i++) {
       Node attr = attributes.item(i);
       if (attr.getNodeName().equals("class")) {
         String recordClazzName = attr.getNodeValue();
         try {
           recordClazz = Class.forName(recordClazzName);
         } catch (ClassNotFoundException e) {
           throw new MetadataReaderException(
               "Record class not found on classpath: " + recordClazzName, e);
         }
       }
     }
   }
   if (node.hasChildNodes()) {
     NodeList childNodes = node.getChildNodes();
     for (int i = 0; i < childNodes.getLength(); i++) {
       Node childNode = childNodes.item(i);
       if (childNode.getNodeType() == Node.ELEMENT_NODE) {
         if (childNode.getNodeName().equals("positional")) {
           PositionalRecordDescriptor positionalRecordDescriptor =
               new PositionalRecordDescriptor();
           positionalRecordDescriptor.setRecordClazz(recordClazz);
           readPositionalNode(childNode, positionalRecordDescriptor);
           recordDescriptor = positionalRecordDescriptor;
         } else if (childNode.getNodeName().equals("delimited")) {
           DelimitedRecordDescriptor delimitedRecordDescriptor = new DelimitedRecordDescriptor();
           delimitedRecordDescriptor.setRecordClazz(recordClazz);
           readDelimitedNode(childNode, delimitedRecordDescriptor);
           recordDescriptor = delimitedRecordDescriptor;
         }
       }
     }
   }
   return recordDescriptor;
 }
Example #21
0
 private void readDelimitedNode(Node node, DelimitedRecordDescriptor recordDescriptorIn)
     throws MetadataReaderException {
   if (node.hasAttributes()) {
     NamedNodeMap attributes = node.getAttributes();
     for (int i = 0; i < attributes.getLength(); i++) {
       Node attr = attributes.item(i);
       if (attr.getNodeName().equals("delimiter")) {
         String delimiter = attr.getNodeValue();
         recordDescriptorIn.setDelimiter(delimiter);
       }
     }
   }
   if (node.hasChildNodes()) {
     NodeList childNodes = node.getChildNodes();
     for (int i = 0; i < childNodes.getLength(); i++) {
       Node childNode = childNodes.item(i);
       if (childNode.getNodeType() == Node.ELEMENT_NODE) {
         readDelimitedFieldNode(childNode, recordDescriptorIn);
       }
     }
   }
 }
Example #22
0
 private void parseAttrList(NodeList nodeList) {
   for (int count = 0; count < nodeList.getLength(); count++) {
     Node tempNode = nodeList.item(count);
     if (tempNode.getNodeType() == Node.ELEMENT_NODE
         && tempNode.hasAttributes()
         && tempNode.hasChildNodes()) {
       String name = null;
       NamedNodeMap nodeMap = tempNode.getAttributes();
       for (int i = 0; i < nodeMap.getLength(); i++) {
         Node node = nodeMap.item(i);
         if (node.getNodeName().equals("name")) {
           name = node.getNodeValue();
           break;
         }
       }
       if (name != null && tempNode.getNodeName().equals("attr")) {
         parseValues(name, tempNode.getChildNodes());
       } else {
         parseAttrList(tempNode.getChildNodes());
       }
     }
   }
 }
Example #23
0
  /*
   * parse:
   * 	This method parses all the xml nodes into a SodaEvents object.
   *
   * Input:
   * 	node:  This is a node list from the soda xml test.
   *
   * Output:
   * 	returns a SodaEvents object.
   */
  private SodaEvents parse(NodeList node) throws Exception {
    SodaHash data = null;
    SodaEvents dataList = null;
    boolean err = false;
    int len = 0;

    dataList = new SodaEvents();

    len = node.getLength();
    for (int i = 0; i <= len - 1; i++) {
      Node child = node.item(i);
      String name = child.getNodeName();

      if (name.startsWith("#")) {
        continue;
      }

      if (!sodaTypes.isValid(name)) {
        if (this.reporter == null) {
          System.err.printf("Error: Invalid Soda Element: '%s'!\n", name);
        } else {
          this.reporter.ReportError(String.format("Error: Invalid Soda Element: '%s'!", name));
        }

        err = true;
        break;
      }

      data = new SodaHash();
      data.put("do", name);
      data.put("type", SodaElements.valueOf(name.toUpperCase()));

      if (child.hasAttributes()) {
        data = processAttributes(data, child);
      }

      if (name.contains("javascript")) {
        String tmp = child.getTextContent();
        if (!tmp.isEmpty()) {
          data.put("content", tmp);
        }
      }

      if (child.hasChildNodes()) {
        if (name.contains("execute")) {
          String[] list = processArgs(child.getChildNodes());
          data.put("args", list);
        } else {
          SodaEvents tmp = parse(child.getChildNodes());
          if (tmp != null) {
            data.put("children", tmp);
          } else {
            err = true;
            break;
          }
        }
      }

      if (!data.isEmpty()) {
        dataList.add(data);
      } else {
        System.out.printf("Note: No data found.\n");
      }
    }

    if (err) {
      dataList = null;
    }

    return dataList;
  }
 /** @see org.w3c.dom.Node#hasAttributes() */
 public boolean hasAttributes() {
   return m_attributeNode.hasAttributes();
 }
Example #25
0
  public CardProfile(String xmlFile) {
    super(xmlFile);
    String xpString;
    NodeList nl;
    Node node;
    node = document.getDocumentElement();
    currElement = (Element) node;

    if (node.hasAttributes()) {
      Node attr;
      NamedNodeMap map = node.getAttributes();
      attr = map.getNamedItem("UniqueID");
      if (attr != null) UniqueID = attr.getNodeValue();
      attr = map.getNamedItem("ProfileVersion");
      if (attr != null) ProfileVersion = attr.getNodeValue();
    }

    try {
      xpString = "Description";
      nl = xPathNode.getNodeList(xpString, node);
      if (nl.getLength() > 0) {
        Description = new cpDescription(nl.item(0));
      }
    } catch (Exception e) {
      // e.printStackTrace();
      log.error("Description " + e.getMessage());
    }

    try {
      xpString = "Revisions";
      nl = xPathNode.getNodeList(xpString, node);
      if (nl.getLength() > 0) {
        Revisions = new cpRevisions(nl.item(0));
      }
    } catch (Exception e) {
      // e.printStackTrace();
      log.error("Revisions " + e.getMessage());
    }

    try {
      xpString = "CardManufacturerProduct";
      nl = xPathNode.getNodeList(xpString, node);
      if (nl.getLength() > 0) {
        CardManufacturerProduct = new cpCardManufacturerProduct(nl.item(0));
      }
    } catch (Exception e) {
      // e.printStackTrace();
      log.error("CardManufacturerProduct " + e.getMessage());
    }

    try {
      xpString = "CardInfo";
      nl = xPathNode.getNodeList(xpString, node);
      if (nl.getLength() > 0) {
        CardInfo = new cpCardInfo(nl.item(0));
      }
    } catch (Exception e) {
      // e.printStackTrace();
      log.error("CardInfo " + e.getMessage());
    }

    try {
      xpString = "ConflictRules";
      nl = xPathNode.getNodeList(xpString, node);
      if (nl.getLength() > 0) ConflictRules = new cpConflictRules(nl.item(0));
    } catch (Exception e) {
      // e.printStackTrace();
      log.error("Attribute " + e.getMessage());
    }

    try {
      xpString = "LoadFileInstances";
      nl = xPathNode.getNodeList(xpString, node);
      if (nl.getLength() > 0) LoadFileInstances = new cpLoadFileInstances(nl.item(0));
    } catch (Exception e) {
      // e.printStackTrace();
      log.error("LoadFileInstances " + e.getMessage());
    }

    try {
      xpString = "ApplicationInstances";
      nl = xPathNode.getNodeList(xpString, node);
      if (nl.getLength() > 0) ApplicationInstances = new cpApplicationInstances(nl.item(0));
    } catch (Exception e) {
      // e.printStackTrace();
      log.error("ApplicationInstances " + e.getMessage());
    }
  }