コード例 #1
1
ファイル: HTMLFragment.java プロジェクト: EchNet/postal
 public void toXhtml(ContentHandler contentHandler, LexicalHandler lexicalHandler)
     throws PageTemplateException, SAXException {
   if (dom == null) {
     parseFragment();
   }
   SAXWriter writer = new SAXWriter(contentHandler, lexicalHandler);
   for (Iterator i = dom.nodeIterator(); i.hasNext(); ) {
     Node node = (Node) i.next();
     writer.write(node);
   }
 }
コード例 #2
0
ファイル: HTMLFragment.java プロジェクト: EchNet/postal
 public void toXhtml(Writer writer) throws PageTemplateException, IOException {
   if (dom == null) {
     parseFragment();
   }
   for (Iterator i = dom.nodeIterator(); i.hasNext(); ) {
     Node node = (Node) i.next();
     node.write(writer);
   }
 }
コード例 #3
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;
  }