public void skipToPos(final int pos) { if (pos<this.pos) return; // can't go backwards this.pos=pos; nextTag=source.getNextTag(pos); }
/** * Returns the {@link EndTag} of the specified {@linkplain EndTagType type} beginning at or immediately following the specified position in the source document. * <p> * See the {@link Tag} class documentation for more details about the behaviour of this method. * <p> * This is exactly equivalent to <code>(EndTag)</code>{@link #getNextTag(int,TagType) getNextTag}<code>(pos,endTagType)</code>, * but can be used to avoid the explicit cast to an {@link EndTag} object. * * @param pos the position in the source document from which to start the search, may be out of bounds. * @param endTagType the <code>EndTagType</code> to search for, must not be <code>null</code>. * @return the {@link EndTag} of the specified {@linkplain EndTagType type} beginning at or immediately following the specified position in the source document, or <code>null</code> if none exists or the specified position is out of bounds. */ public EndTag getNextEndTag(final int pos, final EndTagType endTagType) { if (endTagType==null) throw new IllegalArgumentException("endTagType argument must not be null"); return (EndTag)getNextTag(pos,endTagType); }
/** * Returns the {@link StartTag} of the specified {@linkplain StartTagType type} beginning at or immediately following the specified position in the source document. * <p> * See the {@link Tag} class documentation for more details about the behaviour of this method. * <p> * This is exactly equivalent to <code>(StartTag)</code>{@link #getNextTag(int,TagType) getNextTag}<code>(pos,startTagType)</code>, * but can be used to avoid the explicit cast to a {@link StartTag} object. * * @param pos the position in the source document from which to start the search, may be out of bounds. * @param startTagType the <code>StartTagType</code> to search for, must not be <code>null</code>. * @return the {@link StartTag} of the specified {@linkplain StartTagType type} beginning at or immediately following the specified position in the source document, or <code>null</code> if none exists or the specified position is out of bounds. */ public StartTag getNextStartTag(final int pos, final StartTagType startTagType) { if (startTagType==null) throw new IllegalArgumentException("startTagType argument must not be null"); return (StartTag)getNextTag(pos,startTagType); }
public NodeIterator(final Segment segment) { this.segment=segment; source=segment.source; if (segment==source) source.fullSequentialParse(); pos=segment.begin; nextTag=source.getNextTag(pos); if (nextTag!=null && nextTag.begin>=segment.end) nextTag=null; }
public ParserTag getNextTag(int i) { Tag tag = fSource.getNextTag(i); return makeParserTag(tag); }
Tag getNextNonServerTag(int pos) { while (true) { final Tag tag=getNextTag(pos); if (tag==null) return null; if (!tag.getTagType().isServerTag()) return tag; pos=tag.end; } }
private void appendSegmentRemovingTags(final int begin, final int end) throws IOException { int index=begin; while (true) { Tag tag=source.getNextTag(index); if (tag==null || tag.begin>=end) break; appendSegment(index,tag.begin); index=tag.end; } appendSegment(index,end); }
protected int getEnd(final Source source, int pos) { // Make sure there are no interloping unescaped server tags or server comment tags Tag nextServerCommonTag=source.getNextTag(pos,StartTagTypeServerCommon.INSTANCE); Tag nextServerCommonCommentTag=source.getNextTag(pos,StartTagTypeServerCommonComment.INSTANCE); while (true) { int potentialEnd=super.getEnd(source,pos); if (potentialEnd==-1) return -1; do { int skipToPos=pos; if (nextServerCommonTag!=null && nextServerCommonTag.getEnd()<=potentialEnd) { skipToPos=nextServerCommonTag.getEnd()+1; } if (nextServerCommonCommentTag!=null && nextServerCommonCommentTag.getEnd()<=potentialEnd) { skipToPos=Math.max(skipToPos,nextServerCommonCommentTag.getEnd()+1); } if (skipToPos==pos) return potentialEnd; pos=skipToPos; if (nextServerCommonTag!=null && nextServerCommonTag.getEnd()<=pos) nextServerCommonTag=source.getNextTag(pos,StartTagTypeServerCommon.INSTANCE); if (nextServerCommonCommentTag!=null && nextServerCommonCommentTag.getEnd()<=pos) nextServerCommonCommentTag=source.getNextTag(pos,StartTagTypeServerCommonComment.INSTANCE); } while (pos<potentialEnd); } } }
public void appendTo(final Appendable appendable) throws IOException { this.appendable=appendable; if (segment instanceof Source) ((Source)segment).fullSequentialParse(); nextTag=segment.source.getNextTag(segment.begin); index=segment.begin; appendContent(segment.end,segment.getChildElements(),0); }
/** * Indicates whether the source document is likely to be <a target="_blank" href="http://www.w3.org/TR/REC-xml/">XML</a>. * <p> * The algorithm used to determine this is designed to be relatively inexpensive and to provide an accurate result in * most normal situations. * An exact determination of whether the source document is XML would require a much more complex analysis of the text. * <p> * The algorithm is as follows: * <ol class="HalfSeparated"> * <li>If the document begins with an {@linkplain StartTagType#XML_DECLARATION XML declaration}, it is an XML document. * <li>If the document contains a {@linkplain StartTagType#DOCTYPE_DECLARATION document type declaration} that contains the text * "<code>xhtml</code>", it is an <a target="_blank" href="http://www.w3.org/TR/xhtml1/">XHTML</a> document, and hence * also an XML document. * <li>If none of the above conditions are met, assume the document is normal HTML, and therefore not an XML document. * </ol> * * @return <code>true</code> if the source document is likely to be <a target="_blank" href="http://www.w3.org/TR/REC-xml/">XML</a>, otherwise <code>false</code>. */ public boolean isXML() { final Tag xmlDeclarationTag=getTagAt(0); if (xmlDeclarationTag!=null && xmlDeclarationTag.getTagType()==StartTagType.XML_DECLARATION) return true; final Tag doctypeTag=getNextTag(0,StartTagType.DOCTYPE_DECLARATION); // if document has a DOCTYPE declaration and it contains the text "xhtml", it is an XML document: if (doctypeTag!=null && getParseText().indexOf("xhtml",doctypeTag.begin,doctypeTag.end)!=-1) return true; return false; }
if (searchName==null) return (StartTag)source.getNextTag(pos,searchStartTagType); if (source.wasFullSequentialParseCalled() && isXMLTagName) {
private void parseSegment(int limit, List<TemplateNode> result, Predicate<Element> filter) { while (position < limit) { Tag tag = source.getNextTag(position); if (tag == null || tag.getBegin() > limit) { if (position < limit) { DOMText text = new DOMText(parseText(position, limit)); text.setLocation(new Location(position, limit)); result.add(text); } position = limit; break; } if (position < tag.getBegin()) { DOMText text = new DOMText(parseText(position, tag.getBegin())); text.setLocation(new Location(position, tag.getBegin())); result.add(text); } position = tag.getEnd(); parseTag(tag, result, filter); } }
private void parseSegment(int limit, List<TemplateNode> result, Predicate<Element> filter) { while (position < limit) { Tag tag = source.getNextTag(position); if (tag == null || tag.getBegin() > limit) { if (position < limit) { DOMText text = new DOMText(parseText(position, limit)); text.setLocation(new Location(position, limit)); result.add(text); } position = limit; break; } if (position < tag.getBegin()) { DOMText text = new DOMText(parseText(position, tag.getBegin())); text.setLocation(new Location(position, tag.getBegin())); result.add(text); } position = tag.getEnd(); parseTag(tag, result, filter); } }