当前位置: 首页>>代码示例>>Java>>正文


Java Element类代码示例

本文整理汇总了Java中net.htmlparser.jericho.Element的典型用法代码示例。如果您正苦于以下问题:Java Element类的具体用法?Java Element怎么用?Java Element使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Element类属于net.htmlparser.jericho包,在下文中一共展示了Element类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseTag

import net.htmlparser.jericho.Element; //导入依赖的package包/类
private void parseTag(Tag tag, List<TemplateNode> result, Predicate<Element> filter) {
    if (tag instanceof StartTag) {
        StartTag startTag = (StartTag) tag;
        if (startTag.getStartTagType() == StartTagType.XML_PROCESSING_INSTRUCTION) {
            parseProcessingInstruction(startTag);
        } else if (startTag.getStartTagType() == StartTagType.NORMAL) {
            if (filter.test(tag.getElement())) {
                TemplateNode node = parseElement(tag.getElement());
                if (node != null) {
                    result.add(node);
                }
            } else {
                position = tag.getElement().getEnd();
            }
        }
    }
}
 
开发者ID:konsoletyper,项目名称:teavm-flavour,代码行数:18,代码来源:Parser.java

示例2: parseComponent

import net.htmlparser.jericho.Element; //导入依赖的package包/类
private TemplateNode parseComponent(Element elem) {
    int prefixLength = elem.getName().indexOf(':');
    String prefix = elem.getName().substring(0, prefixLength);
    String name = elem.getName().substring(prefixLength + 1);
    String fullName = prefix + ":" + name;
    ElementComponentMetadata componentMeta = resolveComponent(prefix, name);
    if (componentMeta == null) {
        error(elem.getStartTag().getNameSegment(), "Undefined component " + fullName);
        return null;
    }

    List<PostponedComponentParse> postponedList = new ArrayList<>();
    TemplateNode node = parseComponent(componentMeta, prefix, name, elem, postponedList,
            new MapSubstitutions(new HashMap<>()));
    completeComponentParsing(postponedList, componentMeta, elem);
    position = elem.getEnd();
    return node;
}
 
开发者ID:konsoletyper,项目名称:teavm-flavour,代码行数:19,代码来源:Parser.java

示例3: validateNestedComponents

import net.htmlparser.jericho.Element; //导入依赖的package包/类
private void validateNestedComponents(ComponentBinding component, ElementComponentMetadata metadata,
        Element elem, String prefix) {
    for (NestedComponent nestedMetadata : metadata.nestedComponents) {
        NestedComponentBinding nestedComponent = findNestedComponentBinding(component, nestedMetadata);

        String[] nameRules = nestedMetadata.metadata.nameRules;
        String name = nameRules.length == 1
                ? nameRules[0]
                : "{" + Arrays.stream(nameRules).collect(Collectors.joining("|")) + "}";

        if (nestedMetadata.required) {
            if (nestedComponent == null) {
                error(elem, "Nested component " + prefix + ":" + name + " required but none encountered");
            }
        } else if (!nestedMetadata.multiple) {
            if (nestedComponent.getComponents().size() > 1) {
                error(elem, "Nested component " + prefix + ":" + name + " should encounter only once");
            }
        }
    }
}
 
开发者ID:konsoletyper,项目名称:teavm-flavour,代码行数:22,代码来源:Parser.java

示例4: isValidTRTag

import net.htmlparser.jericho.Element; //导入依赖的package包/类
private static boolean isValidTRTag(Tag tag) {
	Element parentElement=tag.getElement().getParentElement();
	if (parentElement==null) return false; // ignore TR elements without a parent
	if (parentElement.getStartTag().getUserData()!=VALID_MARKER) return false; // ignore TR elements who's parent is not valid
	if(parentElement.getName()==HTMLElementName.TABLE){
		return true;
	}
	if(parentElement.getName()==HTMLElementName.TBODY
			||parentElement.getName()==HTMLElementName.THEAD){
		Element gradParent=parentElement.getParentElement();
		if(gradParent==null){
			return false;
		}
		if (gradParent.getStartTag().getUserData()!=VALID_MARKER) return false;
		return (gradParent.getName()==HTMLElementName.TABLE);
	}else{
		return false;
	}
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:20,代码来源:HTMLSanitiser.java

示例5: closest

import net.htmlparser.jericho.Element; //导入依赖的package包/类
/**
 * For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
 * @see {@link http://api.jquery.com/closest/} 
 */
public jerQuery closest(String selector) throws ParserException {
	TreeSet<Element> newSelectedElements = new TreeSet<Element>();
	jerQuery jq = findFromRoot(selector);
	for (Element e : getSelectedElements()) {
		Element parent = e;
		while (parent != null) {
			if (jq.getSelectedElements().contains(parent)) {
				newSelectedElements.add(parent);
				break;
			}
			parent = parent.getParentElement();
		}
	}
	return new jerQuery(new ArrayList<Element>(newSelectedElements), matcherRegistry, selectorMatcher, source, this);
}
 
开发者ID:utluiz,项目名称:jericho-selector,代码行数:20,代码来源:jerQuery.java

示例6: nthChildSelector

import net.htmlparser.jericho.Element; //导入依赖的package包/类
@Test
  public void nthChildSelector() throws Exception {
List<Element> elements = $(source, "body h1:nth-child(1)").getSelectedElements();
      assertEquals(1, elements.size());
      assertEquals("h1", elements.get(0).getName());
      
      elements = $(source, "body > *").getSelectedElements();
      assertEquals(7, elements.size());
      
      elements = $(source, "body > *:nth-child(7)").getSelectedElements();
      assertEquals(1, elements.size());
      assertEquals("button", elements.get(0).getName());
      
      elements = $(source, "html:nth-child(1)").getSelectedElements();
      assertEquals(1, elements.size());
      assertEquals("html", elements.get(0).getName());
  }
 
开发者ID:utluiz,项目名称:jericho-selector,代码行数:18,代码来源:TestPseudoSelectors.java

示例7: nthChildSelectorNoResults

import net.htmlparser.jericho.Element; //导入依赖的package包/类
@Test
  public void nthChildSelectorNoResults() throws Exception {
List<Element> elements = $(source, "body:nth-child(0)").getSelectedElements();
      assertEquals(0, elements.size());
      
elements = $(source, "body:nth-child()").getSelectedElements();
      assertEquals(0, elements.size());
      
elements = $(source, "body:nth-child(-1)").getSelectedElements();
      assertEquals(0, elements.size());
      
elements = $(source, "body:nth-child(6)").getSelectedElements();
      assertEquals(0, elements.size());
      
      elements = $(source, "html:nth-child()").getSelectedElements();
      assertEquals(0, elements.size());
      
      elements = $(source, "html:nth-child(2)").getSelectedElements();
      assertEquals(0, elements.size());
  }
 
开发者ID:utluiz,项目名称:jericho-selector,代码行数:21,代码来源:TestPseudoSelectors.java

示例8: nthLastChildSelectorNoResults

import net.htmlparser.jericho.Element; //导入依赖的package包/类
@Test
  public void nthLastChildSelectorNoResults() throws Exception {
List<Element> elements = $(source, "body:nth-last-child(0)").getSelectedElements();
      assertEquals(0, elements.size());
      
elements = $(source, "body:nth-last-child()").getSelectedElements();
      assertEquals(0, elements.size());
      
elements = $(source, "body:nth-last-child(-1)").getSelectedElements();
      assertEquals(0, elements.size());
      
elements = $(source, "body:nth-last-child(6)").getSelectedElements();
      assertEquals(0, elements.size());
      
      elements = $(source, "html:nth-last-child()").getSelectedElements();
      assertEquals(0, elements.size());
      
      elements = $(source, "html:nth-last-child(2)").getSelectedElements();
      assertEquals(0, elements.size());
  }
 
开发者ID:utluiz,项目名称:jericho-selector,代码行数:21,代码来源:TestPseudoSelectors.java

示例9: nthTypeSelector

import net.htmlparser.jericho.Element; //导入依赖的package包/类
@Test
   public void nthTypeSelector() throws Exception {
	List<Element> elements = $(source, "body > p:nth-of-type(1)").getSelectedElements();
       assertEquals(1, elements.size());
       assertEquals("my-text", elements.get(0).getAttributeValue("class"));
       
	elements = $(source, "body p:nth-of-type(2)").getSelectedElements();
       assertEquals("my-text-2", elements.get(0).getAttributeValue("class"));

       elements = $(source, "html:nth-of-type(1)").getSelectedElements();
       assertEquals("html", elements.get(0).getName());
       
       elements = $(source, "body:nth-of-type()").getSelectedElements();
       assertEquals(0, elements.size());
       
       elements = $(source, "body:nth-of-type(2)").getSelectedElements();
       assertEquals(0, elements.size());

       elements = $(source, "html:nth-of-type()").getSelectedElements();
       assertEquals(0, elements.size());

       elements = $(source, "html:nth-of-type(2)").getSelectedElements();
       assertEquals(0, elements.size());
}
 
开发者ID:utluiz,项目名称:jericho-selector,代码行数:25,代码来源:TestPseudoSelectors.java

示例10: nthLastTypeSelector

import net.htmlparser.jericho.Element; //导入依赖的package包/类
@Test
  public void nthLastTypeSelector() throws Exception {
List<Element> elements = $(source, "body > p:nth-last-of-type(1)").getSelectedElements();
      assertEquals(1, elements.size());
      assertEquals("my-text-2", elements.get(0).getAttributeValue("class"));
      
elements = $(source, "body p:nth-last-of-type(2)").getSelectedElements();
      assertEquals("my-text", elements.get(0).getAttributeValue("class"));
      
      elements = $(source, "html:nth-last-of-type(1)").getSelectedElements();
      assertEquals("html", elements.get(0).getName());
      
      elements = $(source, "body:nth-last-of-type()").getSelectedElements();
      assertEquals(0, elements.size());
      
      elements = $(source, "body:nth-last-of-type(2)").getSelectedElements();
      assertEquals(0, elements.size());

      elements = $(source, "html:nth-last-of-type()").getSelectedElements();
      assertEquals(0, elements.size());

      elements = $(source, "html:nth-last-of-type(2)").getSelectedElements();
      assertEquals(0, elements.size());
  }
 
开发者ID:utluiz,项目名称:jericho-selector,代码行数:25,代码来源:TestPseudoSelectors.java

示例11: lastType

import net.htmlparser.jericho.Element; //导入依赖的package包/类
@Test
  public void lastType() throws Exception {
List<Element> elements = $(source, "body button:last-of-type").getSelectedElements();
      assertEquals(1, elements.size());
      assertEquals("button", elements.get(0).getName());
      
      elements = $(source, "body > p:last-of-type").getSelectedElements();
      assertEquals(1, elements.size());
      assertEquals("p", elements.get(0).getName());
      assertEquals("my-text-2", elements.get(0).getAttributeValue("class"));
      
elements = $(source, "body p:last-of-type").getSelectedElements();
      assertEquals(2, elements.size());
      assertEquals("p", elements.get(0).getName());
      assertEquals("p2", elements.get(1).getAttributeValue("id"));
      
      elements = $(source, "html:last-of-type").getSelectedElements();
      assertEquals("html", elements.get(0).getName());
  }
 
开发者ID:utluiz,项目名称:jericho-selector,代码行数:20,代码来源:TestPseudoSelectors.java

示例12: onlyType

import net.htmlparser.jericho.Element; //导入依赖的package包/类
@Test
  public void onlyType() throws Exception {
List<Element> elements = $(source, "title:only-of-type").getSelectedElements();
      assertEquals(1, elements.size());
      assertEquals("title", elements.get(0).getName());
      
elements = $(source, "body > button:only-of-type").getSelectedElements();
      assertEquals(1, elements.size());
      assertEquals("button", elements.get(0).getName());
      
elements = $(source, "button p:only-of-type").getSelectedElements();
      assertEquals(0, elements.size());
      
      elements = $(source, "html:only-of-type").getSelectedElements();
      assertEquals(1, elements.size());
  }
 
开发者ID:utluiz,项目名称:jericho-selector,代码行数:17,代码来源:TestPseudoSelectors.java

示例13: nthChildSelectorOdd

import net.htmlparser.jericho.Element; //导入依赖的package包/类
@Test
  public void nthChildSelectorOdd() throws Exception {
List<Element> elements = $(source, "#ul3 li:nth-child(2n + 1)").getSelectedElements();
      assertEquals(3, elements.size());
      assertEquals("li3-1", elements.get(0).getAttributeValue("id"));
      assertEquals("li3-3", elements.get(1).getAttributeValue("id"));
      assertEquals("li3-5", elements.get(2).getAttributeValue("id"));
      
      elements = $(source, "#ul3 li:nth-child(odd)").getSelectedElements();
      assertEquals(3, elements.size());
      assertEquals("li3-1", elements.get(0).getAttributeValue("id"));
      assertEquals("li3-3", elements.get(1).getAttributeValue("id"));
      assertEquals("li3-5", elements.get(2).getAttributeValue("id"));
      
      elements = $(source, "#ul3 li:nth-child('odd')").getSelectedElements();
      assertEquals(3, elements.size());
      assertEquals("li3-1", elements.get(0).getAttributeValue("id"));
      assertEquals("li3-3", elements.get(1).getAttributeValue("id"));
      assertEquals("li3-5", elements.get(2).getAttributeValue("id"));
  }
 
开发者ID:utluiz,项目名称:jericho-selector,代码行数:21,代码来源:TestPseudoExpressionsSelectors.java

示例14: nthChildSelectorEven

import net.htmlparser.jericho.Element; //导入依赖的package包/类
@Test
  public void nthChildSelectorEven() throws Exception {
List<Element> elements = $(source, "#ul3 li:nth-child(2n+0)").getSelectedElements();
      assertEquals(3, elements.size());
      assertEquals("li3-2", elements.get(0).getAttributeValue("id"));
      assertEquals("li3-4", elements.get(1).getAttributeValue("id"));
      assertEquals("li3-6", elements.get(2).getAttributeValue("id"));
      
      elements = $(source, "#ul3 li:nth-child(2n)").getSelectedElements();
      assertEquals(3, elements.size());
      assertEquals("li3-2", elements.get(0).getAttributeValue("id"));
      assertEquals("li3-4", elements.get(1).getAttributeValue("id"));
      assertEquals("li3-6", elements.get(2).getAttributeValue("id"));
      
      elements = $(source, "#ul3 li:nth-child(even)").getSelectedElements();
      assertEquals(3, elements.size());
      assertEquals("li3-2", elements.get(0).getAttributeValue("id"));
      assertEquals("li3-4", elements.get(1).getAttributeValue("id"));
      assertEquals("li3-6", elements.get(2).getAttributeValue("id"));
      
      elements = $(source, "#ul3 li:nth-child('even')").getSelectedElements();
      assertEquals(3, elements.size());
      assertEquals("li3-2", elements.get(0).getAttributeValue("id"));
      assertEquals("li3-4", elements.get(1).getAttributeValue("id"));
      assertEquals("li3-6", elements.get(2).getAttributeValue("id"));
  }
 
开发者ID:utluiz,项目名称:jericho-selector,代码行数:27,代码来源:TestPseudoExpressionsSelectors.java

示例15: nthChildSelectorNumber

import net.htmlparser.jericho.Element; //导入依赖的package包/类
@Test
  public void nthChildSelectorNumber() throws Exception {
List<Element> elements = $(source, "#ul1 li:nth-child(1)").getSelectedElements();
      assertEquals(1, elements.size());
      assertEquals("li1-1", elements.get(0).getAttributeValue("id"));
      
      elements = $(source, "#ul1 li:nth-child(2)").getSelectedElements();
      assertEquals(1, elements.size());
      assertEquals("li1-2", elements.get(0).getAttributeValue("id"));
      
      elements = $(source, "#ul1 li:nth-child(3)").getSelectedElements();
      assertEquals(1, elements.size());
      assertEquals("li1-3", elements.get(0).getAttributeValue("id"));
      
      elements = $(source, "#ul1 li:nth-child(4)").getSelectedElements();
      assertEquals(0, elements.size());
      
      elements = $(source, "#ul1 li:nth-child(0)").getSelectedElements();
      assertEquals(0, elements.size());
  }
 
开发者ID:utluiz,项目名称:jericho-selector,代码行数:21,代码来源:TestPseudoExpressionsSelectors.java


注:本文中的net.htmlparser.jericho.Element类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。