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

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

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

Element.getEndTag介绍

[英]Returns the end tag of the element.

If the element has no end tag this method returns null.
[中]返回元素的结束标记。
如果元素没有结束标记,则此方法返回null

代码示例

代码示例来源: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: pl.edu.icm.synat/synat-portal-core

  1. private CharSequence getStartTagHTML(StartTag startTag) {
  2. // tidies and filters out non-approved attributes
  3. StringBuilder sb = new StringBuilder();
  4. sb.append('<').append(startTag.getName());
  5. for (Attribute attribute : startTag.getAttributes()) {
  6. if (allowedAttributes.contains(attribute.getKey().toLowerCase())) {
  7. sb.append(' ').append(attribute.getName());
  8. if (attribute.getValue() != null) {
  9. sb.append("=\"");
  10. sb.append(CharacterReference.encode(attribute.getValue()));
  11. sb.append('"');
  12. }
  13. }
  14. }
  15. if (startTag.getElement().getEndTag() == null &&
  16. !HTMLElements.getEndTagOptionalElementNames().contains(startTag.getName())) {
  17. sb.append(" /");
  18. }
  19. sb.append('>');
  20. return sb;
  21. }

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

  1. /**
  2. * Returns the {@linkplain Element element} that is ended by this end tag.
  3. * <p>
  4. * Returns <code>null</code> if this end tag is not properly matched to any {@linkplain StartTag start tag} in the source document.
  5. * <p>
  6. * This method is much less efficient than the {@link StartTag#getElement()} method.
  7. * <p>
  8. * IMPLEMENTATION NOTE: The explanation for why this method is relatively inefficient lies in the fact that more than one
  9. * {@linkplain StartTagType start tag type} can have the same
  10. * {@linkplain StartTagType#getCorrespondingEndTagType() corresponding end tag type}, so it is not possible to know for certain
  11. * which type of start tag this end tag is matched to (see {@link EndTagType#getCorrespondingStartTagType()} for more explanation).
  12. * Because of this uncertainty, the implementation of this method must check every start tag preceding this end tag, calling its
  13. * {@link StartTag#getElement()} method to see whether it is terminated by this end tag.
  14. *
  15. * @return the {@linkplain Element element} that is ended by this end tag.
  16. */
  17. public Element getElement() {
  18. if (element!=Element.NOT_CACHED) return element;
  19. int pos=begin;
  20. while (pos!=0) {
  21. StartTag startTag=source.getPreviousStartTag(pos-1);
  22. if (startTag==null) break;
  23. Element foundElement=startTag.getElement(); // this automatically sets foundElement.getEndTag().element cache
  24. if (foundElement.getEndTag()==this) return foundElement; // no need to set element as it was already done in previous statement
  25. pos=startTag.begin;
  26. }
  27. return element=null;
  28. }

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

  1. attributes.appendTidy(sb,getNextTag());
  2. } catch (IOException ex) {throw new RuntimeException(ex);} // never happens
  3. if (startTagType==StartTagType.NORMAL && getElement().getEndTag()==null && !HTMLElements.getEndTagOptionalElementNames().contains(name)) sb.append(" /");
  4. sb.append(startTagType.getClosingDelimiter());
  5. return sb.toString();

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

  1. List<StartTag> tags = sourceHtml.getAllStartTags(FORMULA_TAG_NAME);
  2. for (StartTag tag : tags) {
  3. EndTag endTag = tag.getElement().getEndTag();
  4. if (endTag == null) {
  5. logger.warn("Formula element without end tag in " + source);
  6. if (texElement.getEndTag() == null) {
  7. logger.warn("Tex element without end tag in " + source);
  8. continue;
  9. outputDocument.replace(texElement.getContent(), unescapedContent);
  10. outputDocument.replace(texElement.getEndTag(), TEX_SCRIPT_TAG_END);

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

  1. private boolean processTag(Tag tag, OutputDocument outputDocument) {
  2. String elementName = tag.getName().toLowerCase();
  3. if (!allowedTags.contains(elementName)) {
  4. return false;
  5. }
  6. if (tag.getTagType() == StartTagType.NORMAL) {
  7. Element element = tag.getElement();
  8. if (HTMLElements.getEndTagRequiredElementNames().contains(elementName)) {
  9. if (element.getEndTag() == null) {
  10. return false;
  11. }
  12. } else if (HTMLElements.getEndTagOptionalElementNames().contains(elementName) && element.getEndTag() == null) {
  13. outputDocument.insert(element.getEnd(), getEndTagHTML(elementName));
  14. }
  15. outputDocument.replace(tag, getStartTagHTML(element.getStartTag()));
  16. return true;
  17. }
  18. if (tag.getTagType() == EndTagType.NORMAL) {
  19. if (tag.getElement() == null) {
  20. return false;
  21. }
  22. outputDocument.replace(tag, getEndTagHTML(elementName));
  23. return true;
  24. }
  25. return false;
  26. }

代码示例来源:origin: Netbreeze-GmbH/boilerpipe

  1. outputDocument.remove(element.getEndTag());

代码示例来源:origin: com.github.cfparser/cfml.parsing

  1. if (nextPos > 0 && nextPos < elem.getEndTag().getBegin()) {
  2. endPos = nextPos;
  3. if (elem.getEndTag() != null) {
  4. final String cfscript = elem.getContent().toString();
  5. visitor.visitScript(parseScript(cfscript));

代码示例来源:origin: com.github.cfparser/cfml.parsing

  1. public ParserTag(StartTag tag) {
  2. setName(tag.getName());
  3. setBegin(tag.getElement().getEnd());
  4. setEnd(tag.getElement().getBegin());
  5. setStartTagBegin(tag.getElement().getStartTag().getBegin());
  6. setStartTagEnd(tag.getElement().getStartTag().getEnd());
  7. if (tag.getElement().getEndTag() != null) {
  8. setEndTagBegin(tag.getElement().getEndTag().getBegin());
  9. setEndTagEnd(tag.getElement().getEndTag().getEnd());
  10. } else {
  11. setEndTagBegin(tag.getElement().getStartTag().getBegin());
  12. setEndTagEnd(tag.getElement().getStartTag().getEnd());
  13. }
  14. setAttributes(tag.getAttributes());
  15. }

代码示例来源:origin: com.github.cfparser/cfml.parsing

  1. public ParserTag(net.htmlparser.jericho.Tag tag) {
  2. setName(tag.getName());
  3. setBegin(tag.getElement().getEnd());
  4. setEnd(tag.getElement().getBegin());
  5. setStartTagBegin(tag.getElement().getStartTag().getBegin());
  6. setStartTagEnd(tag.getElement().getStartTag().getEnd());
  7. if (tag.getElement().getEndTag() != null) {
  8. setEndTagBegin(tag.getElement().getEndTag().getBegin());
  9. setEndTagEnd(tag.getElement().getEndTag().getEnd());
  10. } else {
  11. setEndTagBegin(tag.getElement().getStartTag().getBegin());
  12. setEndTagEnd(tag.getElement().getStartTag().getEnd());
  13. }
  14. setAttributes(tag.getElement().getAttributes());
  15. }

代码示例来源:origin: aria42/nlp-utils

  1. public static int[] getCharOffsets(String html) {
  2. int[] res = new int[html.length()];
  3. Source source = new Source(html);
  4. List<Element> elems = source.getAllElements();
  5. for (int i=0; i < res.length; ++i) {
  6. res[i] = i;
  7. }
  8. for (Element elem : elems) {
  9. StartTag startTag = elem.getStartTag();
  10. Span startSpan = getSpan(startTag);
  11. EndTag stopTag = elem.getEndTag();
  12. Span stopSpan = getSpan(stopTag);
  13. for (int i=startSpan.getStart(); i < startSpan.getStop(); ++i) {
  14. res[i] -= (startSpan.getLength() - (startSpan.getStop()-i));
  15. }
  16. for (int i=startSpan.getStop(); i < stopSpan.getStart(); ++i) {
  17. res[i] -= startSpan.getLength();
  18. }
  19. for (int i=stopSpan.getStart(); i < stopSpan.getStop(); ++i) {
  20. res[i] -= (stopSpan.getLength() - (stopSpan.getStop()-i)) ;
  21. }
  22. for (int i=stopSpan.getStop(); i < html.length(); ++i) {
  23. res[i] -= (startSpan.getLength() + stopSpan.getLength());
  24. }
  25. }
  26. return res;
  27. }

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

  1. scanElement(elem, context);
  2. String cfscript = elem.getContent().toString();
  3. if (elem.getEndTag() == null) {

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

  1. assert index<end;
  2. final StartTag startTag=element.getStartTag();
  3. final EndTag endTag=element.getEndTag();
  4. appendIndent(depth);
  5. appendTag(startTag,depth,end);

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

  1. scanElement(elem, context);
  2. String cfscript = elem.getContent().toString();
  3. if (elem.getEndTag() == null) {

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

  1. final EndTag endTag=element.getEndTag();
  2. if (endTag==null) {
  3. assert index<=end;

相关文章