/** * Internal method for the construction of an {@link EndTag} object of this type. * <br />(<a href="TagType.html#ImplementationAssistance">implementation assistance</a> method) * <p> * Intended for use from within the {@link #constructTagAt(Source,int) constructTagAt(Source, int pos)} method. * * @param source the {@link Source} document. * @param begin the character position in the source document where this tag {@linkplain Segment#getBegin() begins}. * @param end the character position in the source document where this tag {@linkplain Segment#getEnd() ends}. * @param name the {@linkplain Tag#getName() name} of the tag. * @return the new {@link EndTag} object. */ protected final EndTag constructEndTag(final Source source, final int begin, final int end, final String name) { return new EndTag(source,begin,end,this,name); } }
private Segment[] getEndTag(final int afterPos, final StartTag nextStartTag, final EndTag nextEndTag, final boolean checkForEmptyElementTag, final boolean isXMLTagName) { // returns null if no end tag exists in the rest of the file, otherwise the following two segments: // first is the matching end tag to this start tag. Must be present if array is returned. // second is the next occurrence after the returned end tag of a start tag of the same name. (null if none exists) if (nextEndTag==null) return null; // no end tag in the rest of the file final Segment[] returnArray={nextEndTag,nextStartTag}; if (nextStartTag==null || nextStartTag.begin>nextEndTag.begin) return returnArray; // no more start tags of the same name in rest of file, or they occur after the end tag that we found. This means we have found the matching end tag. final Segment[] getResult=nextStartTag.getEndTag(nextEndTag,checkForEmptyElementTag,isXMLTagName); // get the matching end tag to the interloping start tag if (getResult==null) return null; // no end tag in the rest of the file final EndTag nextStartTagsEndTag=(EndTag)getResult[0]; final EndTag nextNextEndTag=EndTag.getNext(source,nextStartTagsEndTag.end,nextEndTag.getName(),nextEndTag.getEndTagType()); // get end tag after the interloping start tag's end tag return getEndTag(nextStartTagsEndTag.end,(StartTag)getResult[1],nextNextEndTag,checkForEmptyElementTag,isXMLTagName); // recurse to see if this is the matching end tag } }
if (nextPos > 0 && nextPos < elem.getEndTag().getBegin()) { endPos = nextPos; while (nextTag != null && !nextTag.getName().equalsIgnoreCase(elem.getName())) { nextTag = elem.getSource().getNextEndTag(nextTag.getEnd()); if (nextTag.getName().equalsIgnoreCase(elem.getName())) { final String cfscript = elem.getSource().subSequence(elem.getStartTag().getEnd(), nextTag.getBegin()) .toString(); visitor.visitScript(parseScript(cfscript)); skipToPosition = nextTag.getEnd();
protected RULE_TYPE updateEndTagRuleState(EndTag endTag) { RULE_TYPE ruleType = getConfig().getElementRuleTypeCandidate(endTag.getName()); RuleType currentState = null; if (!currentState.ruleName.equalsIgnoreCase(endTag.getName())) { String character = Integer.toString(endTag.getBegin()); throw new OkapiBadFilterInputException("End tag " + endTag.getName() + " and start tag " + currentState.ruleName + " do not match at character number " + character);
if (endTag==null) return null; if (endTag.name.equals(name)) return endTag; endTag=(EndTag)endTag.getPreviousTag(endTagType); if (begin==-1) return null; final EndTag endTag=(EndTag)source.getTagAt(begin); if (endTag!=null && endTag.getEndTagType()==endTagType && name.equals(endTag.getName())) return endTag; } while ((begin-=1)>=0); } catch (IndexOutOfBoundsException ex) {
if (endTag==null) return null; if (endTag.name.equals(name)) return endTag; endTag=(EndTag)endTag.getNextTag(endTagType); if (begin==-1) return null; final EndTag endTag=(EndTag)source.getTagAt(begin); if (endTag!=null && endTag.getEndTagType()==endTagType && name.equals(endTag.getName())) return endTag; } while ((begin+=1)<source.end); } catch (IndexOutOfBoundsException ex) {
public ParserTag(StartTag tag) { setName(tag.getName()); setBegin(tag.getElement().getEnd()); setEnd(tag.getElement().getBegin()); setStartTagBegin(tag.getElement().getStartTag().getBegin()); setStartTagEnd(tag.getElement().getStartTag().getEnd()); if (tag.getElement().getEndTag() != null) { setEndTagBegin(tag.getElement().getEndTag().getBegin()); setEndTagEnd(tag.getElement().getEndTag().getEnd()); } else { setEndTagBegin(tag.getElement().getStartTag().getBegin()); setEndTagEnd(tag.getElement().getStartTag().getEnd()); } setAttributes(tag.getAttributes()); }
private String getClosingTagsBehindElement(Element element) { StringBuilder closingTags = new StringBuilder(); Element parent = element.getParentElement(); while (parent != null) { closingTags.append( (parent.getEndTag() == null) ? "" : ("</" + parent.getEndTag().getName() + ">") ); parent = parent.getParentElement(); } return closingTags.toString(); }
/** * Returns an XML representation of this end tag. * <p> * The tidying of the tag is carried out as follows: * <ul> * <li>if this end tag is a {@link EndTagType#NORMAL NORMAL} end tag then any {@linkplain CharacterReference#isWhiteSpace(char) white space} before the closing angle bracket is removed. * <li>otherwise the original {@linkplain Segment#toString() source text} of the entire tag is returned. * </ul> * * @return an XML representation of this end tag. * @see StartTag#tidy() */ public String tidy() { final String string=toString(); if (endTagType!=EndTagType.NORMAL) return string; if (!CharacterReference.isWhiteSpace(string.charAt(string.length()-2))) return string; int i=string.length()-3; while (i>0 && CharacterReference.isWhiteSpace(string.charAt(i))) i--; return string.substring(0,i+1)+'>'; }
while (nextTag != null && !nextTag.getName().equalsIgnoreCase(elem.getName())) { nextTag = elem.getSource().getNextEndTag(nextTag.getEnd()); if (nextTag.getName().equalsIgnoreCase(elem.getName())) { cfscript = elem.getSource().subSequence(elem.getStartTag().getEnd(), nextTag.getBegin()) .toString(); skipToPosition = nextTag.getEnd();
RULE_TYPE ruleType = getConfig().getElementRuleTypeCandidate(endTag.getName()); RuleType currentState = null; try { currentState = getRuleState().peekInlineRule(); if (currentState.ruleName.equalsIgnoreCase(endTag.getName())) { currentState = getRuleState().popInlineRule(); ruleType = currentState.ruleType; if (!currentState.ruleName.equalsIgnoreCase(endTag.getName())) { String character = Integer.toString(endTag.getBegin()); LOGGER.debug("End tag {} and start tag {} do not match at character number {}", endTag.getName(), currentState.ruleName, character);
public ParserTag(net.htmlparser.jericho.Tag tag) { setName(tag.getName()); setBegin(tag.getElement().getEnd()); setEnd(tag.getElement().getBegin()); setStartTagBegin(tag.getElement().getStartTag().getBegin()); setStartTagEnd(tag.getElement().getStartTag().getEnd()); if (tag.getElement().getEndTag() != null) { setEndTagBegin(tag.getElement().getEndTag().getBegin()); setEndTagEnd(tag.getElement().getEndTag().getEnd()); } else { setEndTagBegin(tag.getElement().getStartTag().getBegin()); setEndTagEnd(tag.getElement().getStartTag().getEnd()); } setAttributes(tag.getElement().getAttributes()); }
while (nextTag != null && !nextTag.getName().equalsIgnoreCase(elem.getName())) { nextTag = elem.getSource().getNextEndTag(nextTag.getEnd()); if (nextTag.getName().equalsIgnoreCase(elem.getName())) { cfscript = elem.getSource().subSequence(elem.getStartTag().getEnd(), nextTag.getBegin()) .toString(); skipToPosition = nextTag.getEnd();
private EndTag getOptionalEndTag(final HTMLElementTerminatingTagNameSets terminatingTagNameSets) { int pos=end; while (pos<source.end) { final Tag tag=Tag.getNextTag(source,pos); if (tag==null) break; Set<String> terminatingTagNameSet; if (tag instanceof EndTag) { if (tag.name==name) return (EndTag)tag; terminatingTagNameSet=terminatingTagNameSets.TerminatingEndTagNameSet; } else { terminatingTagNameSet=terminatingTagNameSets.NonterminatingElementNameSet; if (terminatingTagNameSet!=null && terminatingTagNameSet.contains(tag.name)) { Element nonterminatingElement=((StartTag)tag).getElement(); pos=nonterminatingElement.end; continue; } terminatingTagNameSet=terminatingTagNameSets.TerminatingStartTagNameSet; } if (terminatingTagNameSet!=null && terminatingTagNameSet.contains(tag.name)) return new EndTag(source,tag.begin,tag.begin,EndTagType.NORMAL,name); pos=tag.begin+1; } // Ran out of tags. The only legitimate case of this happening is if the HTML end tag is missing, in which case the end of the element is the end of the source document return new EndTag(source,source.end,source.end,EndTagType.NORMAL,name); }
return new EndTag(source,nextStartTag.begin,nextStartTag.begin,EndTagType.NORMAL,name);
addToDocumentPart(endTag.toString()); updateEndTagRuleState(endTag); if (getConfig().isRuleType(endTag.getName(), RULE_TYPE.PRESERVE_WHITESPACE)) { ruleState.popPreserverWhitespaceRule(); setPreserveWhitespace(ruleState.isPreserveWhitespaceState()); } else if (ruleState.peekPreserverWhitespaceRule().ruleName.equalsIgnoreCase(endTag.getName())) { ruleState.popPreserverWhitespaceRule(); setPreserveWhitespace(ruleState.isPreserveWhitespaceState()); eventBuilder.endCode(endTag.toString()); break; case INLINE_ELEMENT: eventBuilder.appendCodeOuterData(endTag.toString()); eventBuilder.appendCodeData(endTag.toString()); break; break; case GROUP_ELEMENT: endGroup(new GenericSkeleton(endTag.toString())); break; case EXCLUDED_ELEMENT: addToDocumentPart(endTag.toString()); break; case INCLUDED_ELEMENT: addToDocumentPart(endTag.toString()); break;