本文整理汇总了Java中org.thymeleaf.dom.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于org.thymeleaf.dom包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processElement
import org.thymeleaf.dom.Node; //导入依赖的package包/类
@Override
protected ProcessorResult processElement(Arguments arguments, Element element) {
StringBuffer sb = new StringBuffer();
sb.append("<SCRIPT>\n");
sb.append(" var params = \n ");
sb.append(buildContentMap(arguments)).append(";\n ");
sb.append(getUncacheableDataFunction(arguments, element)).append(";\n");
sb.append("</SCRIPT>");
// Add contentNode to the document
Node contentNode = new Macro(sb.toString());
element.clearChildren();
element.getParent().insertAfter(element, contentNode);
element.getParent().removeChild(element);
// Return OK
return ProcessorResult.OK;
}
示例2: matchesSafely
import org.thymeleaf.dom.Node; //导入依赖的package包/类
@Override
protected boolean matchesSafely(HtmlElement item) {
Element element = item.getElement();
if(element!=null && element.hasChildren()) {
List<Node> children = element.getChildren();
for(Node child : children) {
if(child instanceof Comment) {
if(expectedText==null) {
return true;
} else {
if(expectedText.equals(((Comment)child).getContent())) {
return true;
}
}
}
}
}
return false;
}
示例3: matchesSafely
import org.thymeleaf.dom.Node; //导入依赖的package包/类
@Override
public boolean matchesSafely(HtmlElement item) {
StringBuilder text = new StringBuilder();
boolean fail = false;
Element element = item.getElement();
if(element!=null && element.hasChildren()) {
List<Node> children = element.getChildren();
for(Node child : children) {
if(child instanceof Text) {
text.append(((Text)child).getContent());
} else if(!(child instanceof Comment)) {
fail = true;
break;
}
}
}
return !fail && text.toString().equals(value);
}
示例4: querySelectorAll
import org.thymeleaf.dom.Node; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public Set<Node> querySelectorAll(String selectors) throws NodeSelectorException {
Assert.notNull(selectors, "selectors is null!");
List<List<Selector>> groups;
try {
Scanner scanner = new Scanner(selectors);
groups = scanner.scan();
} catch (ScannerException e) {
throw new NodeSelectorException(e);
}
Set<Node> results = new LinkedHashSet<Node>();
for (List<Selector> parts : groups) {
Set<Node> result = check(parts);
if (!result.isEmpty()) {
results.addAll(result);
}
}
return results;
}
示例5: getNextSiblingElement
import org.thymeleaf.dom.Node; //导入依赖的package包/类
/**
* Get the next sibling element.
*
* @param node The start node.
* @return The next sibling element or {@code null}.
*/
public static final Element getNextSiblingElement(Node node) {
List<Node> siblings = node.getParent().getChildren();
Node n = null;
int index = siblings.indexOf(node) + 1;
if(index>0 && index<siblings.size()) {
n = siblings.get(index);
while(!(n instanceof Element) && ++index < siblings.size()) {
n = siblings.get(index);
}
if(index==siblings.size()) {
n = null;
}
}
return (Element) n;
}
示例6: getPreviousSiblingElement
import org.thymeleaf.dom.Node; //导入依赖的package包/类
/**
* Get the previous sibling element.
*
* @param node The start node.
* @return The previous sibling element or {@code null}.
*/
public static final Element getPreviousSiblingElement(Node node) {
List<Node> siblings = node.getParent().getChildren();
Node n = null;
int index = siblings.indexOf(node) - 1;
if(index>=0) {
n = siblings.get(index);
while(!(n instanceof Element) && --index >= 0) {
n = siblings.get(index);
}
if(index<0) {
n = null;
}
}
return (Element) n;
}
示例7: addChildElements
import org.thymeleaf.dom.Node; //导入依赖的package包/类
/**
* Add child elements.
*
* @see <a href="http://www.w3.org/TR/css3-selectors/#child-combinators">Child combinators</a>
*/
private void addChildElements() {
for (Node node : nodes) {
if(node instanceof NestableNode) {
List<Node> nl = ((NestableNode) node).getChildren();
for (Node n : nl) {
if (!(n instanceof Element)) {
continue;
}
String tag = selector.getTagName();
if (tagEquals(tag, ((Element)n).getNormalizedName()) || tag.equals(Selector.UNIVERSAL_TAG)) {
result.add(n);
}
}
}
}
}
示例8: addEmptyElements
import org.thymeleaf.dom.Node; //导入依赖的package包/类
/**
* Add {@code :empty} elements.
*
* @see <a href="http://www.w3.org/TR/css3-selectors/#empty-pseudo"><code>:empty</code> pseudo-class</a>
*/
private void addEmptyElements() {
for (Node node : nodes) {
boolean empty = true;
if(node instanceof NestableNode) {
List<Node> nl = ((NestableNode) node).getChildren();
for (Node n : nl) {
if (n instanceof Element) {
empty = false;
break;
} else if (n instanceof Text) {
// TODO: Should we trim the text and see if it's length 0?
String value = ((Text) n).getContent();
if (value.length() > 0) {
empty = false;
break;
}
}
}
}
if (empty) {
result.add(node);
}
}
}
示例9: addFirstOfType
import org.thymeleaf.dom.Node; //导入依赖的package包/类
/**
* Add {@code :first-of-type} elements.
*
* @see <a href="http://www.w3.org/TR/css3-selectors/#first-of-type-pseudo"><code>:first-of-type</code> pseudo-class</a>
*/
private void addFirstOfType() {
for (Node node : nodes) {
Node n = DOMHelper.getPreviousSiblingElement(node);
while (n != null) {
if (DOMHelper.getNodeName(n).equals(DOMHelper.getNodeName(node))) {
break;
}
n = DOMHelper.getPreviousSiblingElement(n);
}
if (n == null) {
result.add(node);
}
}
}
示例10: addLastOfType
import org.thymeleaf.dom.Node; //导入依赖的package包/类
/**
* Add {@code :last-of-type} elements.
*
* @see <a href="http://www.w3.org/TR/css3-selectors/#last-of-type-pseudo"><code>:last-of-type</code> pseudo-class</a>
*/
private void addLastOfType() {
for (Node node : nodes) {
Node n = DOMHelper.getNextSiblingElement(node);
while (n != null) {
if (DOMHelper.getNodeName(n).equals(DOMHelper.getNodeName(node))) {
break;
}
n = DOMHelper.getNextSiblingElement(n);
}
if (n == null) {
result.add(node);
}
}
}
示例11: check
import org.thymeleaf.dom.Node; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Set<Node> check(Set<Node> nodes, Node root) throws NodeSelectorException {
Assert.notNull(nodes, "nodes is null!");
this.nodes = nodes;
result = new LinkedHashSet<Node>();
String value = specifier.getValue();
if ("nth-child".equals(value)) {
addNthChild();
} else if ("nth-last-child".equals(value)) {
addNthLastChild();
} else if ("nth-of-type".equals(value)) {
addNthOfType();
} else if ("nth-last-of-type".equals(value)) {
addNthLastOfType();
} else {
throw new NodeSelectorException("Unknown pseudo nth class: " + value);
}
return result;
}
示例12: addNthOfType
import org.thymeleaf.dom.Node; //导入依赖的package包/类
/**
* Add {@code :nth-of-type} elements.
*
* @see <a href="http://www.w3.org/TR/css3-selectors/#nth-of-type-pseudo"><code>:nth-of-type</code> pseudo-class</a>
*/
private void addNthOfType() {
for (Node node : nodes) {
int count = 1;
Node n = DOMHelper.getPreviousSiblingElement(node);
while (n != null) {
if (DOMHelper.getNodeName(n).equals(DOMHelper.getNodeName(node))) {
count++;
}
n = DOMHelper.getPreviousSiblingElement(n);
}
if (specifier.isMatch(count)) {
result.add(node);
}
}
}
示例13: addNthLastOfType
import org.thymeleaf.dom.Node; //导入依赖的package包/类
/**
* Add {@code nth-last-of-type} elements.
*
* @see <a href="http://www.w3.org/TR/css3-selectors/#nth-last-of-type-pseudo"><code>:nth-last-of-type</code> pseudo-class</a>
*/
private void addNthLastOfType() {
for (Node node : nodes) {
int count = 1;
Node n = DOMHelper.getNextSiblingElement(node);
while (n != null) {
if (DOMHelper.getNodeName(n).equals(DOMHelper.getNodeName(node))) {
count++;
}
n = DOMHelper.getNextSiblingElement(n);
}
if (specifier.isMatch(count)) {
result.add(node);
}
}
}
示例14: htmlFor
import org.thymeleaf.dom.Node; //导入依赖的package包/类
private static StringBuilder htmlFor(Element element, StringBuilder builder) {
startTag(element, builder);
for(Node node : element.getChildren()) {
if(node instanceof Element) {
builder = htmlFor((Element)node, builder);
} else if(node instanceof Text) {
builder.append(((Text)node).getContent());
} else if(node instanceof Comment) {
builder.append("<!--");
builder.append(((Comment)node).getContent());
builder.append("-->");
} else if(node instanceof CDATASection) {
builder.append("<![CDATA[");
builder.append(((CDATASection)node).getContent());
builder.append("]]>");
}
}
endTag(element, builder);
return builder;
}
示例15: checkRoot
import org.thymeleaf.dom.Node; //导入依赖的package包/类
@Test
public void checkRoot() throws NodeSelectorException {
Element root = (Element)nodeSelector.querySelector(":root");
Assert.assertEquals("html", root.getNormalizedName());
DOMNodeSelector subSelector = new DOMNodeSelector(nodeSelector.querySelector("div#scene1"));
Set<Node> subRoot = subSelector.querySelectorAll(":root");
Assert.assertEquals(1, subRoot.size());
NestableAttributeHolderNode node =(NestableAttributeHolderNode) subRoot.iterator().next();
Assert.assertEquals("scene1", node.getAttributeMap().get("id").getValue());
Assert.assertEquals((int) testDataMap.get("div#scene1 div.dialog div"), subSelector.querySelectorAll(":root div.dialog div").size());
Node meta = nodeSelector.querySelector(":root > head > meta");
Assert.assertEquals(meta, new DOMNodeSelector(meta).querySelector(":root"));
}