/**
   * 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();
    }
  }
Esempio n. 2
0
  /**
   * Reads in a decision stored in XML.
   *
   * @param decN - the XML element.
   */
  public void fromXML(Element decN) {
    this.fromXML = true;

    RationaleDB db = RationaleDB.getHandle();

    String rid = decN.getAttribute("rid");
    id = Integer.parseInt(rid.substring(2));

    name = decN.getAttribute("name");

    type = DecisionType.fromString(decN.getAttribute("type"));

    devPhase = Phase.fromString(decN.getAttribute("phase"));

    status = DecisionStatus.fromString(decN.getAttribute("status"));

    Node child = decN.getFirstChild();
    importHelper(child);

    Node nextNode = child.getNextSibling();
    while (nextNode != null) {
      importHelper(nextNode);
      nextNode = nextNode.getNextSibling();
    }

    db.addPatternDecisionFromXML(this);
  }
Esempio n. 3
0
  /**
   * Method getStrFromNode
   *
   * @param xpathnode
   * @return the string for the node.
   */
  public static String getStrFromNode(Node xpathnode) {

    if (xpathnode.getNodeType() == Node.TEXT_NODE) {

      // we iterate over all siblings of the context node because eventually,
      // the text is "polluted" with pi's or comments
      StringBuffer sb = new StringBuffer();

      for (Node currentSibling = xpathnode.getParentNode().getFirstChild();
          currentSibling != null;
          currentSibling = currentSibling.getNextSibling()) {
        if (currentSibling.getNodeType() == Node.TEXT_NODE) {
          sb.append(((Text) currentSibling).getData());
        }
      }

      return sb.toString();
    } else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
      return ((Attr) xpathnode).getNodeValue();
    } else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
      return ((ProcessingInstruction) xpathnode).getNodeValue();
    }

    return null;
  }
Esempio n. 4
0
  /**
   * Returns a sibling element that matches a given definition, or <tt>null</tt> if no match is
   * found.
   *
   * @param sibling the sibling DOM element to begin the search
   * @param target the node to search for
   * @return the matching element, or <tt>null</tt> if not found
   */
  public static Element findSibling(Element sibling, XmlNode target) {
    String xmlName = target.getLocalName();
    String xmlNamespace = target.getNamespace();

    Node node = sibling;
    if (node == null) {
      return null;
    }

    while ((node = node.getNextSibling()) != null) {
      if (node.getNodeType() != Node.ELEMENT_NODE) {
        continue;
      }
      Element element = (Element) node;
      if (!element.getLocalName().equals(xmlName)) {
        continue;
      }
      if (target.isNamespaceAware()) {
        String ns = element.getNamespaceURI();
        if (ns == null) {
          if (xmlNamespace != null) {
            continue;
          }
        } else {
          if (!ns.equals(xmlNamespace)) {
            continue;
          }
        }
      }
      return element;
    }
    return null;
  }
Esempio n. 5
0
  // Helper method for getEquivalentLogical
  private Node getSibling(final Node n, final boolean lookLeft) {
    if (n == null) {
      return null;
    }

    if (isNodeVisible(n)) {
      return null;
    }

    final Node sibling;
    if (lookLeft) {
      sibling = n.getPreviousSibling();
    } else {
      sibling = n.getNextSibling();
    }

    if (sibling == null) {
      // If this node has no logical siblings at or below it's "level", it might have one above
      if (n == root_) {
        return null;
      }
      return getSibling(n.getParent(), lookLeft);
    }
    return getEquivalentLogical(sibling, lookLeft);
  }
Esempio n. 6
0
 private void setValue(Node node, String value) {
   Node child = null;
   for (child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
     if (child.getNodeType() == Node.TEXT_NODE) {
       child.setNodeValue(value);
       break;
     }
   }
 }
Esempio n. 7
0
  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;
  }
Esempio n. 8
0
 /**
  * Remove a child from this node.
  *
  * @param node the child to remove
  */
 void removeChild(Node node) {
   assert this == node.getParentNode();
   if (firstChild == node) {
     firstChild = node.getNextSibling();
     if (lastChild == node) {
       lastChild = null;
     }
   } else {
     Node prev = firstChild;
     Node next = firstChild.getNextSibling();
     while (next != node) {
       prev = next;
       next = next.getNextSibling();
     }
     prev.setNextSibling(node.getNextSibling());
     if (lastChild == node) {
       lastChild = prev;
     }
   }
 }
Esempio n. 9
0
 // Get the text value of a child element with a specified name.
 private static String getChildText(Element el, String childName) {
   String value = "";
   Node child = el.getFirstChild();
   while (child != null) {
     if ((child.getNodeType() == Node.ELEMENT_NODE) && child.getNodeName().equals(childName)) {
       return child.getTextContent();
     }
     child = child.getNextSibling();
   }
   return value;
 }
Esempio n. 10
0
 private static String getValue(Node node) {
   String textValue = "";
   Node child = null;
   if (node != null)
     for (child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
       if (child.getNodeType() == Node.TEXT_NODE) {
         textValue = child.getNodeValue();
         break;
       }
     }
   return textValue.trim();
 }
Esempio n. 11
0
 private void appendNodeText(StringBuffer sb, Node node) {
   if (node.getNodeType() == Node.TEXT_NODE) {
     sb.append(" " + node.getTextContent());
   } else if (node.getNodeType() == Node.ELEMENT_NODE) {
     if (!node.getNodeName().equals("pt-age")) {
       Node child = node.getFirstChild();
       while (child != null) {
         appendNodeText(sb, child);
         child = child.getNextSibling();
       }
     }
   }
 }
Esempio n. 12
0
 /**
  * Insert a new child before a pre-existing child and return the newly inserted child.
  *
  * @param child the new child
  * @param sibling the existing child before which to insert (must be a child of this node) or
  *     <code>null</code> to append
  * @return <code>child</code>
  */
 public Node insertBefore(Node child, Node sibling) {
   assert sibling == null || this == sibling.getParentNode();
   if (sibling == null) {
     return appendChild(child);
   }
   child.detach();
   child.setParentNode(this);
   if (firstChild == sibling) {
     child.setNextSibling(sibling);
     firstChild = child;
   } else {
     Node prev = firstChild;
     Node next = firstChild.getNextSibling();
     while (next != sibling) {
       prev = next;
       next = next.getNextSibling();
     }
     prev.setNextSibling(child);
     child.setNextSibling(next);
   }
   return child;
 }
Esempio n. 13
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();
    }
  }
Esempio n. 14
0
  /**
   * Moves the TreeWalker to the next sibling of the current node, and returns the new node. If the
   * current node has no visible next sibling, returns <code>null</code>, and retains the current
   * node.
   *
   * @return The new node, or <code>null</code> if the current node has no next sibling in the
   *     TreeWalker's logical view.
   */
  @JsxFunction
  public Node nextSibling() {
    if (currentNode_ == root_) {
      return null;
    }

    final Node newNode = getEquivalentLogical(currentNode_.getNextSibling(), false);

    if (newNode != null) {
      currentNode_ = newNode;
    }

    return newNode;
  }
Esempio n. 15
0
  private Node getSibling(final Node node, final boolean lookLeft) {
    if (node == null) {
      return null;
    }

    final Node sibling;
    if (lookLeft) {
      sibling = node.getPreviousSibling();
    } else {
      sibling = node.getNextSibling();
    }

    return sibling;
  }
Esempio n. 16
0
  @Override
  public boolean equals(Object node1, Node node2) {
    if (node1 == node2) return true;
    NodeInfo n1 = (NodeInfo) node1;
    Node n2 = node2;

    while (true) {
      if (!shallowEquals(n1, n2)) return false;
      if (n1 == null) {
        assert n2 == null;
        return true;
      }
      NodeInfo n1Child = new NodeInfoSequence(n1, Axis.CHILD).findNext();
      Node n2Child = null;
      if (n2.getNodeType() == Node.DOCUMENT_NODE || n2.getNodeType() == Node.ELEMENT_NODE)
        n2Child = n2.getFirstChild(); // the jdk's dom impl returns non-null child for attribute etc
      if (!shallowEquals(n1Child, n2Child)) return false;
      if (n1Child == null) {
        assert n2Child == null;

        if (n1 == node1 && n2 == node2) return true;

        while (true) {
          NodeInfo n1Sibling = new NodeInfoSequence(n1, Axis.FOLLOWING_SIBLING).findNext();
          Node n2Sibling = n2.getNextSibling();
          if (!shallowEquals(n1Sibling, n2Sibling)) return false;
          if (n1Sibling == null) {
            assert n2Sibling == null;
            NodeInfo n1Parent = new NodeInfoSequence(n1, Axis.ANCESTOR).findNext();
            Node n2Parent = n2.getParentNode();

            if (n1Parent == null && n2Parent == null) return true;
            if (n1Parent == node1 && n2Parent == node2) return true;
            assert n1Parent != null && n2Parent != null;
            n1 = n1Parent;
            n2 = n2Parent;
          } else {
            assert n2Sibling != null;
            n1 = n1Sibling;
            n2 = n2Sibling;
            break;
          }
        }
      } else {
        n1 = n1Child;
        n2 = n2Child;
      }
    }
  }
Esempio n. 17
0
  public AxisName(Node node, XmlQuery xq) throws WCPSException {
    while ((node != null) && node.getNodeName().equals("#" + WCPSConstants.MSG_TEXT)) {
      node = node.getNextSibling();
    }

    if (node != null && node.getNodeName().equals(WCPSConstants.MSG_AXIS)) {
      log.trace(node.getNodeName());
      String axis = node.getTextContent();
      this.name = axis;
      log.trace("  " + WCPSConstants.MSG_AXIS + " " + WCPSConstants.MSG_NAME + ": " + name);
    } else {
      throw new WCPSException(
          ExceptionCode.InvalidRequest, WCPSConstants.ERRTXT_COULD_NOT_FIND_AXIS + " !");
    }
  }
Esempio n. 18
0
  /** @deprecated use immediateChildrenByTagName( Element parent, String tagName ) */
  public static NodeList getImmediateChildElementsByTagName(Element parent, String tagName)
      throws DOMException {
    final List nodes = new ArrayList();
    for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling())
      if (child instanceof Element && ((Element) child).getTagName().equals(tagName))
        nodes.add(child);
    return new NodeList() {
      public int getLength() {
        return nodes.size();
      }

      public Node item(int i) {
        return (Node) nodes.get(i);
      }
    };
  }
Esempio n. 19
0
  /**
   * Helper method to get the first uncle node in document order (preorder traversal) from the given
   * node.
   */
  private Node getFirstUncleNode(final Node n) {
    if (n == root_ || n == null) {
      return null;
    }

    final Node parent = n.getParent();
    if (parent == null) {
      return null;
    }

    final Node uncle = getEquivalentLogical(parent.getNextSibling(), false);
    if (uncle != null) {
      return uncle;
    }

    return getFirstUncleNode(parent);
  }
Esempio n. 20
0
  public FieldName(Node node, XmlQuery xq, CoverageInfo covInfo) throws WCPSException {
    while ((node != null) && node.getNodeName().equals("#" + WcpsConstants.MSG_TEXT)) {
      node = node.getNextSibling();
    }

    if (node == null) {
      throw new WCPSException("FieldNameType parsing error.");
    }

    String nodeName = node.getNodeName();
    log.trace(nodeName);

    if (nodeName.equals(WcpsConstants.MSG_NAME)) {
      this.name = node.getTextContent();
      log.trace("Found field name: " + name);
      String coverageName = covInfo.getCoverageName();
      try {
        covMeta = xq.getMetadataSource().read(coverageName);
      } catch (Exception ex) {
        log.error(ex.getMessage());
        throw new WCPSException(ex.getMessage(), ex);
      }
      try {
        nameIndex = covMeta.getRangeIndexByName(name).toString();
      } catch (PetascopeException ex1) {
        boolean wrongFieldSubset = true;
        log.debug("Range field subset " + name + " does not seem by-label: trying by-index.");

        if (MiscUtil.isInteger(name)) {
          try {
            // range subsetting might have been done via range field /index/ (instead of label):
            // check this is a valid index
            nameIndex = name;
            name = covMeta.getRangeNameByIndex(Integer.parseInt(name));
            wrongFieldSubset = false; // indeed subset was by-index
          } catch (PetascopeException ex2) {
            log.debug("Range field subset " + nameIndex + " is neither a valid index.");
          }
        }
        if (wrongFieldSubset) {
          log.error("Illegal range field selection: " + name);
          throw new WCPSException(ex1.getExceptionCode(), ex1.getExceptionText());
        }
      }
    }
  }
Esempio n. 21
0
 /**
  * Append the children of another node to this node removing them from the other node .
  *
  * @param parent the other node whose children to append to this one
  */
 public void appendChildren(Node parent) {
   Node child = parent.getFirstChild();
   if (child == null) {
     return;
   }
   ParentNode another = (ParentNode) parent;
   if (firstChild == null) {
     firstChild = child;
   } else {
     lastChild.setNextSibling(child);
   }
   lastChild = another.lastChild;
   do {
     child.setParentNode(this);
   } while ((child = child.getNextSibling()) != null);
   another.firstChild = null;
   another.lastChild = null;
 }
Esempio n. 22
0
 /**
  * Returns the child text from a DOM node.
  *
  * @param node the node to parse
  * @return the node text, or <tt>null</tt> if the node did not contain any text
  */
 public static String getText(Node node) {
   StringBuilder s = null;
   Node child = node.getFirstChild();
   while (child != null) {
     if (child.getNodeType() == Node.TEXT_NODE) {
       if (s == null) {
         s = new StringBuilder();
       }
       s.append(((Text) child).getTextContent());
     } else if (child.getNodeType() == Node.CDATA_SECTION_NODE) {
       if (s == null) {
         s = new StringBuilder();
       }
       s.append(((CDATASection) child).getData());
     }
     child = child.getNextSibling();
   }
   return s == null ? null : s.toString();
 }
Esempio n. 23
0
  /** used for cut and paste. */
  public void addObjectFromClipboard(String a_value) throws CircularIncludeException {
    Reader reader = new StringReader(a_value);
    Document document = null;
    try {
      document = UJAXP.getDocument(reader);
    } catch (Exception e) {
      e.printStackTrace();
      return;
    } // try-catch

    Element root = document.getDocumentElement();
    if (!root.getNodeName().equals("clipboard")) {
      return;
    } // if

    Node child;
    for (child = root.getFirstChild(); child != null; child = child.getNextSibling()) {
      if (!(child instanceof Element)) {
        continue;
      } // if
      Element element = (Element) child;

      IGlyphFactory factory = GlyphFactory.getFactory();

      if (XModule.isMatch(element)) {
        EModuleInvoke module = (EModuleInvoke) factory.createXModule(element);
        addModule(module);
        continue;
      } // if

      if (XContour.isMatch(element)) {
        EContour contour = (EContour) factory.createXContour(element);
        addContour(contour);
        continue;
      } // if

      if (XInclude.isMatch(element)) {
        EIncludeInvoke include = (EIncludeInvoke) factory.createXInclude(element);
        addInclude(include);
        continue;
      } // if
    } // while
  }
Esempio n. 24
0
 public Node insertBetween(Node child, Node prev, Node next) {
   assert prev == null || this == prev.getParentNode();
   assert next == null || this == next.getParentNode();
   assert prev != null || next == firstChild;
   assert next != null || prev == lastChild;
   assert prev == null || next == null || prev.getNextSibling() == next;
   if (next == null) {
     return appendChild(child);
   }
   child.detach();
   child.setParentNode(this);
   child.setNextSibling(next);
   if (prev == null) {
     firstChild = child;
   } else {
     prev.setNextSibling(child);
   }
   return child;
 }
Esempio n. 25
0
  /**
   * Finds the Nth matching child of a DOM element.
   *
   * @param parent the parent DOM node
   * @param target the node to search for
   * @param offset the occurrence of the matching node
   * @return the matching element, or <tt>null</tt> if no match is found
   */
  public static Element findChild(Node parent, XmlNode target, int offset) {
    Node node = parent;
    if (node != null) {
      node = node.getFirstChild();
    }
    if (node == null) {
      return null;
    }

    String xmlName = target.getLocalName();
    String xmlNamespace = target.getNamespace();

    int count = 0;
    do {
      if (node.getNodeType() != Node.ELEMENT_NODE) {
        continue;
      }
      Element element = (Element) node;
      if (!element.getLocalName().equals(xmlName)) {
        continue;
      }
      if (target.isNamespaceAware()) {
        String ns = element.getNamespaceURI();
        if (ns == null) {
          if (xmlNamespace != null && xmlNamespace.length() != 0) {
            continue;
          }
        } else {
          if (!ns.equals(xmlNamespace)) {
            continue;
          }
        }
      }
      if (count == offset) {
        return element;
      }
      ++count;

    } while ((node = node.getNextSibling()) != null);

    return null;
  }
Esempio n. 26
0
  /**
   * Moves the TreeWalker to the next visible node in document order relative to the current node,
   * and returns the new node. If the current node has no next node, or if the search for nextNode
   * attempts to step upward from the TreeWalker's root node, returns <code>null</code>, and retains
   * the current node.
   *
   * @return The new node, or <code>null</code> if the current node has no next node in the
   *     TreeWalker's logical view.
   */
  @JsxFunction
  public Node nextNode() {
    final Node leftChild = getEquivalentLogical(currentNode_.getFirstChild(), false);
    if (leftChild != null) {
      currentNode_ = leftChild;
      return leftChild;
    }
    final Node rightSibling = getEquivalentLogical(currentNode_.getNextSibling(), false);
    if (rightSibling != null) {
      currentNode_ = rightSibling;
      return rightSibling;
    }

    final Node uncle = getFirstUncleNode(currentNode_);
    if (uncle != null) {
      currentNode_ = uncle;
      return uncle;
    }

    return null;
  }
    public int visitParagraphEnd(Paragraph paragraph) {
      if (mFieldDepth > 0) {
        // The field code that is being converted continues onto another paragraph. We
        // need to copy the remaining content from this paragraph onto the next paragraph.
        Node nextParagraph = paragraph.getNextSibling();

        // Skip ahead to the next available paragraph.
        while (nextParagraph != null && nextParagraph.getNodeType() != NodeType.PARAGRAPH)
          nextParagraph = nextParagraph.getNextSibling();

        // Copy all of the nodes over. Keep a list of these nodes so we know not to remove them.
        while (paragraph.hasChildNodes()) {
          mNodesToSkip.add(paragraph.getLastChild());
          ((Paragraph) nextParagraph).prependChild(paragraph.getLastChild());
        }

        paragraph.remove();
      }

      return VisitorAction.CONTINUE;
    }
 /**
  * @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();
 }
Esempio n. 29
0
  /**
   * Construct a Query from an XML document in the form described on the RSNA MIRC wiki.
   *
   * @param queryDoc the MIRCquery XML DOM object.
   */
  public Query(Document queryDoc) {
    super();
    Element root = queryDoc.getDocumentElement();
    unknown = root.getAttribute("unknown").trim().equals("yes");
    bgcolor = root.getAttribute("bgcolor").trim();
    display = root.getAttribute("display").trim();
    icons = root.getAttribute("icons").trim();
    orderby = root.getAttribute("orderby").trim();
    firstresult = StringUtil.getInt(root.getAttribute("firstresult"));
    if (firstresult <= 0) firstresult = 1;
    maxresults = StringUtil.getInt(root.getAttribute("maxresults"));
    if (maxresults <= 0) maxresults = 1;

    StringBuffer sb = new StringBuffer();
    Node child = root.getFirstChild();
    while (child != null) {
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        String dbname = child.getNodeName();
        String text = getTextContent(child);
        if (!text.equals("")) {
          this.put(dbname, text);
          containsNonFreetextQueries = true;
        }
        if (dbname.equals("temp")) isTempQuery = true;
      } else if (child.getNodeType() == Node.TEXT_NODE) {
        sb.append(" " + child.getTextContent());
      }
      child = child.getNextSibling();
    }
    String freetext = sb.toString().replaceAll("\\s+", " ").trim();
    isBlankQuery = freetext.equals("");
    isSpecialQuery = root.getAttribute("special").trim().equals("yes");
    this.put("freetext", freetext);
    setAgeRange(root);
    // log();
  }
Esempio n. 30
0
  public void parseStartup(File file) {
    Logger.getLogger(com.bombdiggity.amazon.ec2.install.Installer.class)
        .info((new StringBuilder("InstallParser.parseStartup: ")).append(file).toString());
    try {
      Document doc = loadFile(file);
      if (doc != null) {
        XPathFactory factory = XMLUtils.newXPathFactory();
        XPath xpath = factory.newXPath();
        String rootXPath = "/Startup/Commands/*";
        Element root = doc.getDocumentElement();
        XPathExpression rootExp = xpath.compile(rootXPath);
        NodeList streamList = (NodeList) rootExp.evaluate(root, XPathConstants.NODESET);
        if (streamList != null) {
          for (int i = 0; i < streamList.getLength(); i++) {
            Node streamNode = streamList.item(i);
            Element streamElem = (Element) streamNode;
            if (streamElem.getNodeName().toLowerCase().equals("install")) {
              String packageName = null;
              String folderPath = null;
              for (Node child = streamNode.getFirstChild();
                  child != null;
                  child = child.getNextSibling())
                if (child.getNodeName().toLowerCase().equals("package"))
                  packageName = XMLUtils.getNodeValue(child).trim();
                else if (child.getNodeName().toLowerCase().equals("folder"))
                  folderPath = XMLUtils.getNodeValue(child).trim();

              if (packageName != null) InstallCommands.installPackage(session, packageName);
              else if (folderPath != null) InstallCommands.installFolder(session, folderPath);
              else
                Logger.getLogger(com.bombdiggity.amazon.ec2.install.InstallParser.class)
                    .error("StartupParser.loadFile: <Install>: <Package> or <Folder> required");
            } else if (streamElem.getNodeName().toLowerCase().equals("download")) {
              String url = null;
              String method = "get";
              String data = null;
              String destination = "/opt";
              String action = null;
              List headers = new ArrayList();
              for (Node child = streamNode.getFirstChild();
                  child != null;
                  child = child.getNextSibling())
                if (child.getNodeName().toLowerCase().equals("url"))
                  url = XMLUtils.getNodeValue(child).trim();
                else if (child.getNodeName().toLowerCase().equals("method"))
                  method = XMLUtils.getNodeValue(child).toLowerCase().trim();
                else if (child.getNodeName().toLowerCase().equals("data"))
                  data = XMLUtils.getNodeValue(child).trim();
                else if (child.getNodeName().toLowerCase().equals("destination"))
                  destination = XMLUtils.getNodeValue(child).trim();
                else if (child.getNodeName().toLowerCase().equals("action"))
                  action = XMLUtils.getNodeValue(child).toLowerCase().trim();
                else if (child.getNodeName().toLowerCase().equals("header")) {
                  Node nameNode = XMLUtils.getNodeByTagName((Element) child, "Name");
                  Node valueNode = XMLUtils.getNodeByTagName((Element) child, "Value");
                  if (nameNode != null && valueNode != null) {
                    Map namePair = new HashMap();
                    namePair.put(
                        XMLUtils.getNodeValue(nameNode).trim(),
                        XMLUtils.getNodeValue(valueNode).trim());
                    headers.add(namePair);
                  } else {
                    Logger.getLogger(com.bombdiggity.amazon.ec2.install.InstallParser.class)
                        .error(
                            "StartupParser.loadFile: <Download/Header>: <Name> and <Value> required");
                  }
                }

              if (url != null && destination != null)
                InstallCommands.downloadFile(
                    session, url, method, data, headers, destination, action);
              else
                Logger.getLogger(com.bombdiggity.amazon.ec2.install.InstallParser.class)
                    .error("StartupParser.loadFile: <Download>: <URL> and <Destination> required");
            } else if (streamElem.getNodeName().toLowerCase().equals("s3fetch")) {
              String awsAccessKeyId = null;
              String awsSecretAccessKey = null;
              String bucket = null;
              String key = null;
              String destination = null;
              String action = null;
              for (Node child = streamNode.getFirstChild();
                  child != null;
                  child = child.getNextSibling())
                if (child.getNodeName().toLowerCase().equals("awsaccesskeyid"))
                  awsAccessKeyId = XMLUtils.getNodeValue(child).trim();
                else if (child.getNodeName().toLowerCase().equals("awssecretaccesskey"))
                  awsSecretAccessKey = XMLUtils.getNodeValue(child).trim();
                else if (child.getNodeName().toLowerCase().equals("bucket"))
                  bucket = XMLUtils.getNodeValue(child).trim();
                else if (child.getNodeName().toLowerCase().equals("key"))
                  key = XMLUtils.getNodeValue(child).trim();
                else if (child.getNodeName().toLowerCase().equals("destination"))
                  destination = XMLUtils.getNodeValue(child).trim();
                else if (child.getNodeName().toLowerCase().equals("action"))
                  action = XMLUtils.getNodeValue(child).toLowerCase().trim();

              if (awsAccessKeyId != null
                  && awsSecretAccessKey != null
                  && bucket != null
                  && key != null
                  && destination != null)
                InstallCommands.fetchFile(
                    session, awsAccessKeyId, awsSecretAccessKey, bucket, key, destination, action);
              else
                Logger.getLogger(com.bombdiggity.amazon.ec2.install.InstallParser.class)
                    .error(
                        "StartupParser.loadFile: <Fetch>: <AWSAccessKeyId>, <AWSSecretAccessKey>, <Bucket>, <Key> and <Destination> required");
            } else if (streamElem.getNodeName().toLowerCase().equals("runscript")) {
              String script = null;
              List params = new ArrayList();
              for (Node child = streamNode.getFirstChild();
                  child != null;
                  child = child.getNextSibling())
                if (child.getNodeName().toLowerCase().equals("script"))
                  script = XMLUtils.getNodeValue(child).trim();
                else if (child.getNodeName().toLowerCase().equals("param")) {
                  String param = XMLUtils.getNodeValue(child).trim();
                  params.add(param);
                }

              if (script != null) InstallCommands.runScript(session, script, params);
              else
                Logger.getLogger(com.bombdiggity.amazon.ec2.install.InstallParser.class)
                    .error("StartupParser.loadFile: <RunScript>: <Script> required");
            }
          }
        }
      }
    } catch (Exception e) {
      Logger.getLogger(com.bombdiggity.amazon.ec2.install.InstallParser.class)
          .error(
              (new StringBuilder("InstallParser.parseStartup: ")).append(e.toString()).toString());
      e.printStackTrace();
    }
  }