net.htmlparser.jericho.Element.getParentElement()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(302)

本文整理了Java中net.htmlparser.jericho.Element.getParentElement()方法的一些代码示例,展示了Element.getParentElement()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getParentElement()方法的具体详情如下:
包路径:net.htmlparser.jericho.Element
类名称:Element
方法名:getParentElement

Element.getParentElement介绍

[英]Returns the parent of this element in the document element hierarchy.

The Source#fullSequentialParse() method must be called (either explicitly or implicitly) immediately after construction of the Source object if this method is to be used. An IllegalStateException is thrown if a full sequential parse has not been performed or if it was performed after this element was found.

This method returns null for a top-level element, as well as any element formed from a TagType#isServerTag(), regardless of whether it is nested inside a normal element.

See the Source#getChildElements() method for more details.
[中]返回文档元素层次结构中此元素的父级。
如果要使用Source#fullSequentialParse()方法,则必须在构造Source对象后立即(显式或隐式)调用该方法。如果未执行完整的顺序分析,或者在找到此元素后执行,则会抛出IllegalStateException
此方法返回{$0$}的null,以及由TagType#isServerTag()形成的任何元素,而不管它是否嵌套在普通元素中。
有关详细信息,请参阅源代码#getChildElements()方法。

代码示例

代码示例来源:origin: net.htmlparser.jericho/jericho-html

  1. /**
  2. * Returns the nesting depth of this element in the document element hierarchy.
  3. * <p>
  4. * The {@link Source#fullSequentialParse()} method must be called (either explicitly or implicitly) after construction of the <code>Source</code> object if this method is to be used.
  5. * An <code>IllegalStateException</code> is thrown if a full sequential parse has not been performed or if it was performed after this element was found.
  6. * <p>
  7. * A <a href="Source.html#TopLevelElement">top-level element</a> has a nesting depth of <code>0</code>.
  8. * <p>
  9. * An element formed from a {@linkplain TagType#isServerTag() server tag} always have a nesting depth of <code>0</code>,
  10. * regardless of whether it is nested inside a normal element.
  11. * <p>
  12. * See the {@link Source#getChildElements()} method for more details.
  13. *
  14. * @return the nesting depth of this element in the document element hierarchy.
  15. * @throws IllegalStateException if a {@linkplain Source#fullSequentialParse() full sequential parse} has not been performed or if it was performed after this element was found.
  16. * @see #getParentElement()
  17. */
  18. public int getDepth() {
  19. if (depth==-1) {
  20. getParentElement();
  21. if (depth==-1) depth=0;
  22. }
  23. return depth;
  24. }

代码示例来源:origin: cflint/CFLint

  1. public static Element getNamedParent(final Element elem, final String tagName) {
  2. Element parentElem = elem.getParentElement();
  3. while (parentElem != null && !parentElem.getName().equals(tagName)) {
  4. parentElem = parentElem.getParentElement();
  5. }
  6. return parentElem;
  7. }

代码示例来源:origin: cflint/CFLint

  1. public static Element getNamedParent(final Element elem, final String tagName) {
  2. Element parentElem = elem.getParentElement();
  3. while (parentElem != null && !parentElem.getName().equals(tagName)) {
  4. parentElem = parentElem.getParentElement();
  5. }
  6. return parentElem;
  7. }

代码示例来源:origin: pl.edu.icm.synat/synat-portal-core

  1. private String getClosingTagsBehindElement(Element element) {
  2. StringBuilder closingTags = new StringBuilder();
  3. Element parent = element.getParentElement();
  4. while (parent != null) {
  5. closingTags.append( (parent.getEndTag() == null) ? "" : ("</" + parent.getEndTag().getName() + ">") );
  6. parent = parent.getParentElement();
  7. }
  8. return closingTags.toString();
  9. }

代码示例来源:origin: cflint/CFLint

  1. /**
  2. * Returns the previous sibling of a given element
  3. *
  4. * @param element
  5. * The Jericho HTML element object
  6. * @return the previous sibling of the given element.
  7. */
  8. public static Element getPreviousSibling(final Element element) {
  9. if (element.getParentElement() != null) {
  10. final List<Element> parentElements = element.getParentElement().getChildElements();
  11. final int idx = parentElements.indexOf(element);
  12. if (idx > 0) {
  13. return parentElements.get(idx - 1);
  14. }
  15. } else if (element.getSource() != null) {
  16. final List<Element> parentElements = element.getSource().getChildElements();
  17. final int idx = parentElements.indexOf(element);
  18. if (idx > 0) {
  19. return parentElements.get(idx - 1);
  20. }
  21. }
  22. return null;
  23. }

代码示例来源:origin: cflint/CFLint

  1. /**
  2. * Returns the previous sibling of a given element
  3. *
  4. * @param element
  5. * The Jericho HTML element object
  6. * @return the previous sibling of the given element.
  7. */
  8. public static Element getPreviousSibling(final Element element) {
  9. if (element.getParentElement() != null) {
  10. final List<Element> parentElements = element.getParentElement().getChildElements();
  11. final int idx = parentElements.indexOf(element);
  12. if (idx > 0) {
  13. return parentElements.get(idx - 1);
  14. }
  15. } else if (element.getSource() != null) {
  16. final List<Element> parentElements = element.getSource().getChildElements();
  17. final int idx = parentElements.indexOf(element);
  18. if (idx > 0) {
  19. return parentElements.get(idx - 1);
  20. }
  21. }
  22. return null;
  23. }

代码示例来源:origin: cflint/CFLint

  1. elem = elem.getParentElement();

代码示例来源:origin: cflint/CFLint

  1. elem = elem.getParentElement();

代码示例来源:origin: cflint/CFLint

  1. @Override
  2. public void element(final Element element, final Context context, final BugList bugs) {
  3. if (element.getName().equals(CF.CFARGUMENT)) {
  4. final String name = element.getAttributeValue(CF.NAME) != null
  5. ? element.getAttributeValue(CF.NAME) : "";
  6. ArgInfo argInfo = new ArgInfo();
  7. argInfo.casedName=name;
  8. argInfo.argumentLineNo=context.startLine();
  9. argInfo.argumentOffset=element.getAttributeValue(CF.NAME) != null
  10. ? element.getAttributes().get(CF.NAME).getValueSegment().getBegin() : element.getBegin();
  11. argInfo.type=element.getAttributeValue(CF.TYPE);
  12. currentArgs.put(name.toLowerCase(), argInfo);
  13. final String code = element.getParentElement().toString();
  14. if (isUsed(code, name.toLowerCase())) {
  15. argInfo.used=true;
  16. }
  17. }
  18. }

代码示例来源:origin: cflint/CFLint

  1. @Override
  2. public void element(final Element element, final Context context, final BugList bugs) {
  3. if (element.getName().equals(CF.CFARGUMENT)) {
  4. final String name = element.getAttributeValue(CF.NAME) != null
  5. ? element.getAttributeValue(CF.NAME) : "";
  6. ArgInfo argInfo = new ArgInfo();
  7. argInfo.casedName=name;
  8. argInfo.argumentLineNo=context.startLine();
  9. argInfo.argumentOffset=element.getAttributeValue(CF.NAME) != null
  10. ? element.getAttributes().get(CF.NAME).getValueSegment().getBegin() : element.getBegin();
  11. argInfo.type=element.getAttributeValue(CF.TYPE);
  12. currentArgs.put(name.toLowerCase(), argInfo);
  13. final String code = element.getParentElement().toString();
  14. if (isUsed(code, name.toLowerCase())) {
  15. argInfo.used=true;
  16. }
  17. }
  18. }

代码示例来源:origin: org.zaproxy/zap

  1. while ((element = element.getParentElement()) != null) {
  2. context.addParentTag(element.getName());

代码示例来源:origin: cflint/CFLint

  1. @Override
  2. public void element(final Element element, final Context context, final BugList bugs) {
  3. if (element.getName().equals(CF.CFARGUMENT)) {
  4. final String name = element.getAttributeValue(CF.NAME);
  5. final boolean required = CFTool.toBoolean(element.getAttributeValue(CF.REQUIRED));
  6. final String defaultExpr = element.getAttributeValue(CF.DEFAULT);
  7. final String code = element.getParentElement().toString();
  8. final boolean checked = isCheck(code, name);
  9. if (!required && defaultExpr == null && !checked) {
  10. element.getSource().getRow(element.getBegin());
  11. element.getSource().getColumn(element.getBegin());
  12. context.addMessage("ARG_DEFAULT_MISSING", name);
  13. }
  14. }
  15. }

代码示例来源:origin: cflint/CFLint

  1. @Override
  2. public void element(final Element element, final Context context, final BugList bugs) {
  3. if (element.getName().equals(CF.CFARGUMENT)) {
  4. final String name = element.getAttributeValue(CF.NAME);
  5. final boolean required = CFTool.toBoolean(element.getAttributeValue(CF.REQUIRED));
  6. final String defaultExpr = element.getAttributeValue(CF.DEFAULT);
  7. final String code = element.getParentElement().toString();
  8. final boolean checked = isCheck(code, name);
  9. if (!required && defaultExpr == null && !checked) {
  10. element.getSource().getRow(element.getBegin());
  11. element.getSource().getColumn(element.getBegin());
  12. context.addMessage("ARG_DEFAULT_MISSING", name);
  13. }
  14. }
  15. }

相关文章