From 83b182a05a2f9704db89241bdb3c679928c17c37 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Sun, 16 Dec 2018 10:34:06 +0800 Subject: [PATCH] 1 1 --- pom.xml | 2 +- .../java/com/xenoamess/x8l/ContentNode.java | 59 ++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8bdac78..d70cbc4 100644 --- a/pom.xml +++ b/pom.xml @@ -5,5 +5,5 @@ 4.0.0 com.xenoamess x8l - 0.27 + 0.28 \ No newline at end of file diff --git a/src/main/java/com/xenoamess/x8l/ContentNode.java b/src/main/java/com/xenoamess/x8l/ContentNode.java index 036c7d0..5bc0d66 100644 --- a/src/main/java/com/xenoamess/x8l/ContentNode.java +++ b/src/main/java/com/xenoamess/x8l/ContentNode.java @@ -6,6 +6,7 @@ import java.io.Writer; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; public class ContentNode extends TreeNode { @@ -24,8 +25,10 @@ public void addAttribute(String key, String value) { if (value == null) { value = ""; } + if (!this.attributes.containsKey(key)) { + attributesKeyList.add(key); + } attributes.put(key, value); - attributesKeyList.add(key); } @@ -114,4 +117,58 @@ public void output(Writer writer) { e.printStackTrace(); } } + + public List getTextNodesFromChildren() { + return this.getTextNodesFromChildren(0); + } + + public List getTextNodesFromChildren(int maxSize) { + List res = new ArrayList(); + for (TreeNode au : this.children) { + if (au instanceof TextNode) { + res.add((TextNode) au); + if (res.size() == maxSize) { + return res; + } + } + } + return res; + } + + public List getContentNodesFromChildren() { + return this.getContentNodesFromChildren(0); + } + + public List getContentNodesFromChildren(int maxSize) { + List res = new ArrayList(); + for (TreeNode au : this.children) { + if (au instanceof ContentNode) { + res.add((ContentNode) au); + if (res.size() == maxSize) { + return res; + } + } + } + return res; + } + + + public List getCommentNodesFromChildren() { + return this.getCommentNodesFromChildren(0); + } + + public List getCommentNodesFromChildren(int maxSize) { + List res = new ArrayList(); + for (TreeNode au : this.children) { + if (au instanceof CommentNode) { + res.add((CommentNode) au); + if (res.size() == maxSize) { + return res; + } + } + } + return res; + } + + }