コード例 #1
0
  private void addElementsToProperties(List elements, Properties props, String parentPath) {

    for (java.lang.Object o : elements) {
      Node ele = (Node) o;
      if (ele.getNodeType() != 1) { // text
        continue;
      }
      String contents = ele.getText().trim();

      String newParentPath = "";

      if (!StringUtils.isEmpty(parentPath)) {
        newParentPath = parentPath + ".";
      }
      newParentPath += ele.getName();

      if (!StringUtils.isEmpty(contents)) {
        props.setProperty(newParentPath, contents);
      }
      if (ele instanceof Element) {
        List children = ((Element) ele).content();

        addElementsToProperties(children, props, newParentPath);
      }
    }
  }
コード例 #2
0
ファイル: XMLWriter.java プロジェクト: dom4j/dom4j
  protected void writeNode(Node node) throws IOException {
    int nodeType = node.getNodeType();

    switch (nodeType) {
      case Node.ELEMENT_NODE:
        writeElement((Element) node);

        break;

      case Node.ATTRIBUTE_NODE:
        writeAttribute((Attribute) node);

        break;

      case Node.TEXT_NODE:
        writeNodeText(node);

        // write((Text) node);
        break;

      case Node.CDATA_SECTION_NODE:
        writeCDATA(node.getText());

        break;

      case Node.ENTITY_REFERENCE_NODE:
        writeEntity((Entity) node);

        break;

      case Node.PROCESSING_INSTRUCTION_NODE:
        writeProcessingInstruction((ProcessingInstruction) node);

        break;

      case Node.COMMENT_NODE:
        writeComment(node.getText());

        break;

      case Node.DOCUMENT_NODE:
        write((Document) node);

        break;

      case Node.DOCUMENT_TYPE_NODE:
        writeDocType((DocumentType) node);

        break;

      case Node.NAMESPACE_NODE:

        // Will be output with attributes
        // write((Namespace) node);
        break;

      default:
        throw new IOException("Invalid node type: " + node);
    }
  }
コード例 #3
0
ファイル: TagChecker.java プロジェクト: davidbkemp/nate
 private void getDescentantElements(Branch node) {
   String tagName = selector.getTagName();
   Iterator<Node> nodeIterator = node.nodeIterator();
   while (nodeIterator.hasNext()) {
     Node child = nodeIterator.next();
     if (child.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
       if (tagName.equals("*") || child.getName().equals(tagName)) {
         result.add((Branch) child);
       }
       getDescentantElements((Branch) child);
     }
   }
 }
コード例 #4
0
ファイル: SAXWriter.java プロジェクト: enenuki/phd
 /*  78:    */
 /*  79:    */ public void write(Node node) /*  80:    */ throws SAXException /*  81:    */ {
   /*  82:125 */ int nodeType = node.getNodeType();
   /*  83:127 */ switch (nodeType)
   /*  84:    */ {
       /*  85:    */ case 1:
       /*  86:129 */ write((Element) node);
       /*  87:    */
       /*  88:131 */ break;
       /*  89:    */ case 2:
       /*  90:134 */ write((Attribute) node);
       /*  91:    */
       /*  92:136 */ break;
       /*  93:    */ case 3:
       /*  94:139 */ write(node.getText());
       /*  95:    */
       /*  96:141 */ break;
       /*  97:    */ case 4:
       /*  98:144 */ write((CDATA) node);
       /*  99:    */
       /* 100:146 */ break;
       /* 101:    */ case 5:
       /* 102:149 */ write((Entity) node);
       /* 103:    */
       /* 104:151 */ break;
       /* 105:    */ case 7:
       /* 106:154 */ write((ProcessingInstruction) node);
       /* 107:    */
       /* 108:156 */ break;
       /* 109:    */ case 8:
       /* 110:159 */ write((Comment) node);
       /* 111:    */
       /* 112:161 */ break;
       /* 113:    */ case 9:
       /* 114:164 */ write((Document) node);
       /* 115:    */
       /* 116:166 */ break;
       /* 117:    */ case 10:
       /* 118:169 */ write((DocumentType) node);
       /* 119:    */
       /* 120:171 */ break;
       /* 121:    */ case 13:
       /* 122:    */ break;
       /* 123:    */ case 6:
       /* 124:    */ case 11:
       /* 125:    */ case 12:
       /* 126:    */ default:
       /* 127:180 */ throw new SAXException("Invalid node type: " + node);
       /* 128:    */ }
   /* 129:    */ }
コード例 #5
0
ファイル: TagChecker.java プロジェクト: davidbkemp/nate
 /**
  * Get child elements.
  *
  * @see <a href="http://www.w3.org/TR/css3-selectors/#child-combinators">Child combinators</a>
  */
 private void getChildElements() {
   String tag = selector.getTagName();
   for (Branch node : nodes) {
     Iterator<Node> nodeIterator = node.nodeIterator();
     while (nodeIterator.hasNext()) {
       Node child = nodeIterator.next();
       if (child.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) {
         continue;
       }
       if (tag.equals(child.getName()) || tag.equals(Selector.UNIVERSAL_TAG)) {
         result.add((Branch) child);
       }
     }
   }
 }
コード例 #6
0
  @Override
  public IQ handleIQ(IQ packet) throws UnauthorizedException {
    Log.debug("handling IQ packet " + packet);
    IQ reply = IQ.createResultIQ(packet);
    Element iq = packet.getChildElement();
    String method = iq.attributeValue("name");
    List<String> args = new ArrayList<String>();

    // TODO Don't look this up each time
    // We currently do this to avoid problems during development
    // from reloading Jive - later we probably want to move this to
    // constructor
    XMPPMethods methods = EJBUtil.defaultLookup(XMPPMethods.class);
    SimpleAnnotatedInvoker xmppInvoker =
        new SimpleAnnotatedInvoker(XMPPRemoted.class, methods, new PersonArgumentPrepender());

    for (Object argObj : iq.elements()) {
      Node arg = (Node) argObj;
      Log.debug("parsing expected arg node " + arg);
      if (arg.getNodeType() == Node.ELEMENT_NODE) {
        String argValue = arg.getText();
        Log.debug("Adding arg value" + argValue);
        args.add(argValue);
      }
    }

    try {
      Log.debug(
          "invoking method "
              + method
              + " with ("
              + args.size()
              + ") args "
              + Arrays.toString(args.toArray()));
      @SuppressWarnings("unused")
      String replyStr = xmppInvoker.invoke(method, args, packet.getFrom());
      // Don't do anything with this yet
    } catch (Exception e) {
      Log.debug("Caught exception during client method invocation", e);
    }
    return reply;
  }
コード例 #7
0
 /**
  * TODO 针对较小的UL合并行时做的调整
  *
  * @param element 当前节点
  * @throws Exception
  */
 @SuppressWarnings("unchecked")
 public void modifyUL(Element element, HashSet<String> hashSet, String enginId) throws Exception {
   List<Node> nodeList = element.content();
   Node nc;
   Element ec;
   String name;
   for (int m = 0; m < nodeList.size(); m++) {
     nc = nodeList.get(m);
     if (nc.getNodeType() == Node.ELEMENT_NODE) {
       name = nc.getName();
       ec = (Element) nc;
       // 如果该孩子节点标签不是BR,收集该孩子节点
       if (BR.equalsIgnoreCase(name)) {
         nodeList.remove(m--);
         element.setContent(nodeList);
       }
       modifyUL(ec, hashSet, enginId);
     }
   }
 }
コード例 #8
0
ファイル: Database.java プロジェクト: fedor4ever/linux_build
  private void processTarget(Element targetNode, Element outProjectNode)
      throws IOException, DocumentException {
    String targetName = targetNode.attributeValue("name");
    log("Processing target: " + targetName, Project.MSG_DEBUG);

    // Add documentation
    // Get comment element before the target element to extract target doc
    String commentText = "";
    List children = targetNode.selectNodes("preceding-sibling::node()");
    if (children.size() > 0) {
      // Scan past the text nodes, which are most likely whitespace
      int index = children.size() - 1;
      Node child = (Node) children.get(index);
      while (index > 0 && child.getNodeType() == Node.TEXT_NODE) {
        index--;
        child = (Node) children.get(index);
      }

      // Check if there is a comment node
      if (child.getNodeType() == Node.COMMENT_NODE) {
        Comment targetComment = (Comment) child;
        commentText = targetComment.getStringValue().trim();

        log(targetName + " comment: " + commentText, Project.MSG_DEBUG);
      } else {
        log("Target has no comment: " + targetName, Project.MSG_WARN);
      }

      Node previousNode = (Node) children.get(children.size() - 1);
    }

    if (!commentText.contains("Private:")) {
      Element outTargetNode = outProjectNode.addElement("target");

      addTextElement(outTargetNode, "name", targetNode.attributeValue("name"));
      addTextElement(outTargetNode, "ifDependency", targetNode.attributeValue("if"));
      addTextElement(outTargetNode, "unlessDependency", targetNode.attributeValue("unless"));
      addTextElement(outTargetNode, "description", targetNode.attributeValue("description"));
      addTextElement(outTargetNode, "tasks", String.valueOf(targetNode.elements().size()));

      // Add location
      Project project = getProject();
      Target antTarget = (Target) project.getTargets().get(targetName);

      if (antTarget == null) return;

      addTextElement(outTargetNode, "location", antTarget.getLocation().toString());

      // Add dependencies
      Enumeration dependencies = antTarget.getDependencies();
      while (dependencies.hasMoreElements()) {
        String dependency = (String) dependencies.nextElement();
        Element dependencyElement = addTextElement(outTargetNode, "dependency", dependency);
        dependencyElement.addAttribute("type", "direct");
      }

      callAntTargetVisitor(targetNode, outTargetNode, outProjectNode);

      // Process the comment text as MediaWiki syntax and convert to HTML
      insertDocumentation(outTargetNode, commentText);

      // Get names of all properties used in this target
      ArrayList properties = new ArrayList();
      Visitor visitor = new AntPropertyVisitor(properties);
      targetNode.accept(visitor);
      for (Iterator iterator = properties.iterator(); iterator.hasNext(); ) {
        String property = (String) iterator.next();
        addTextElement(outTargetNode, "propertyDependency", property);
      }

      // Add the raw XML content of the element
      String targetXml = targetNode.asXML();
      // Replace the CDATA end notation to avoid nested CDATA sections
      targetXml = targetXml.replace("]]>", "] ]>");

      addTextElement(outTargetNode, "source", targetXml, true);
    }
  }
コード例 #9
0
ファイル: Database.java プロジェクト: fedor4ever/linux_build
  private void processMacro(Element macroNode, Element outProjectNode, String antFile)
      throws IOException, DocumentException {
    String macroName = macroNode.attributeValue("name");
    log("Processing macro: " + macroName, Project.MSG_DEBUG);

    Element outmacroNode = outProjectNode.addElement("macro");
    addTextElement(outmacroNode, "name", macroNode.attributeValue("name"));
    addTextElement(outmacroNode, "description", macroNode.attributeValue("description"));

    // Add location
    // Project project = getProject();
    // Macro antmacro = (Macro) project.getTargets().get(macroName);
    // System.out.println(project.getMacroDefinitions());
    // System.out.println(macroName);
    // MacroInstance antmacro = (MacroInstance)
    // project.getMacroDefinitions().get("http://www.nokia.com/helium:" +
    // macroName);

    // Add the location with just the file path for now and a dummy line
    // number.
    // TODO - Later we should find the line number from the XML input.
    addTextElement(outmacroNode, "location", antFile + ":1:");

    List<Node> statements =
        macroNode.selectNodes(
            "//scriptdef[@name='"
                + macroName
                + "']/attribute | //macrodef[@name='"
                + macroName
                + "']/attribute");
    String usage = "";
    for (Node statement : statements) {
      String defaultval = statement.valueOf("@default");
      if (defaultval.equals("")) defaultval = "value";
      else defaultval = "<i>" + defaultval + "</i>";
      usage = usage + " " + statement.valueOf("@name") + "=\"" + defaultval + "\"";
    }

    String macroElements = "";
    statements =
        macroNode.selectNodes(
            "//scriptdef[@name='"
                + macroName
                + "']/element | //macrodef[@name='"
                + macroName
                + "']/element");
    for (Node statement : statements) {
      macroElements = "&lt;" + statement.valueOf("@name") + "/&gt;\n" + macroElements;
    }
    if (macroElements.equals(""))
      addTextElement(outmacroNode, "usage", "&lt;hlm:" + macroName + " " + usage + "/&gt;");
    else
      addTextElement(
          outmacroNode,
          "usage",
          "&lt;hlm:"
              + macroName
              + " "
              + usage
              + "&gt;\n"
              + macroElements
              + "&lt;/hlm:"
              + macroName
              + "&gt;");

    // Add dependencies
    // Enumeration dependencies = antmacro.getDependencies();
    // while (dependencies.hasMoreElements())
    // {
    // String dependency = (String) dependencies.nextElement();
    // Element dependencyElement = addTextElement(outmacroNode,
    // "dependency", dependency);
    // dependencyElement.addAttribute("type","direct");
    // }

    callAntTargetVisitor(macroNode, outmacroNode, outProjectNode);

    // Add documentation
    // Get comment element before the macro element to extract macro doc
    List children = macroNode.selectNodes("preceding-sibling::node()");
    if (children.size() > 0) {
      // Scan past the text nodes, which are most likely whitespace
      int index = children.size() - 1;
      Node child = (Node) children.get(index);
      while (index > 0 && child.getNodeType() == Node.TEXT_NODE) {
        index--;
        child = (Node) children.get(index);
      }

      // Check if there is a comment node
      String commentText = null;
      if (child.getNodeType() == Node.COMMENT_NODE) {
        Comment macroComment = (Comment) child;
        commentText = macroComment.getStringValue().trim();
        log(macroName + " comment: " + commentText, Project.MSG_DEBUG);
      } else {
        log("Macro has no comment: " + macroName, Project.MSG_WARN);
      }

      insertDocumentation(outmacroNode, commentText);

      Node previousNode = (Node) children.get(children.size() - 1);
    }

    // Get names of all properties used in this macro
    ArrayList properties = new ArrayList();
    Visitor visitor = new AntPropertyVisitor(properties);
    macroNode.accept(visitor);
    for (Iterator iterator = properties.iterator(); iterator.hasNext(); ) {
      String property = (String) iterator.next();
      addTextElement(outmacroNode, "propertyDependency", property);
    }
  }
コード例 #10
0
  @SuppressWarnings({"unchecked", "static-access"})
  public static List<AddItem> AnalysisXML(String path) {
    List<AddItem> addItemList = new ArrayList<>();

    FileInputStream inputStream = null;
    Document doc = null;
    try {
      inputStream = new FileInputStream(path);
      doc = new SAXReader().read(inputStream);
      Element root = doc.getRootElement();

      Element importElement = root.element("import-items");

      List<Element> addList = importElement.elements("add-item");
      if (addList.size() == 0) {
        System.out.println("no items");
        return null;
      }

      for (int i = 0; i < addList.size(); i++) {

        List<String> addComments = new ArrayList<>();
        List<PropertyItem> proItemList = new ArrayList<>();

        Element addElem = addList.get(i);
        AddItem addItem = new AddItem();

        addItem.setId(addElem.attributeValue("id"));
        addItem.setItemDescriptor(addElem.attributeValue("item-descriptor"));

        for (Iterator<Node> nodeIterator = addElem.nodeIterator(); nodeIterator.hasNext(); ) {

          Node node = nodeIterator.next();
          if (node != null) {
            if (node.getNodeType() == node.COMMENT_NODE) {
              addComments.add("<!--" + node.getText() + " -->");
            }
          }
        }

        addItem.setComment(addComments);

        for (Iterator<Element> elemIterator = addElem.elementIterator(); elemIterator.hasNext(); ) {

          PropertyItem proItem = new PropertyItem();

          Element elem = elemIterator.next();
          if (elem != null) {
            proItem.setName(elem.attributeValue("name"));
            proItem.setValue("<![CDATA[" + elem.getText() + "]]>");
            proItemList.add(proItem);
          }
        }
        addItem.setPropertyItems(proItemList);
        addItemList.add(addItem);
      }

    } catch (Exception e) {
      e.printStackTrace();

    } finally {

      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    return addItemList;
  }