public static synchronized void remove(final TagType tagType) { TagTypeRegister cursor=root; final String startDelimiter=tagType.getStartDelimiter(); for (int i=0; i<startDelimiter.length(); i++) { final char ch=startDelimiter.charAt(i); final TagTypeRegister child=cursor.getChild(ch); if (child==null) return; cursor=child; } cursor.removeTagType(tagType); // clean up any unrequired children: while (cursor!=root && cursor.tagTypes==null && cursor.children==null) { cursor.parent.removeChild(cursor); cursor=cursor.parent; } }
public static synchronized void add(final TagType tagType) { TagTypeRegister cursor=root; final String startDelimiter=tagType.getStartDelimiter(); for (int i=0; i<startDelimiter.length(); i++) { final char ch=startDelimiter.charAt(i); TagTypeRegister child=cursor.getChild(ch); if (child==null) { child=new TagTypeRegister(); child.parent=cursor; child.ch=ch; cursor.addChild(child); } cursor=child; } cursor.addTagType(tagType); }
private void processStartTag( StartTag tag ) { if( "<".equals( tag.getTagType().getStartDelimiter() ) ) { stack.push( new Level( tag ) ); writer.write( "<" ); writer.write( tag.getNameSegment().toString() ); Attributes attributes = tag.getAttributes(); if( !attributes.isEmpty() ) { for( Attribute attribute : attributes ) { processAttribute( attribute ); } } if( tag.toString().trim().endsWith( "/>" ) || tag.isEmptyElementTag() ) { stack.pop(); writer.write( "/>" ); } else { writer.write( ">" ); } } else { writer.write( tag.toString() ); } }
private void processStartTag( StartTag tag ) { if( "<".equals( tag.getTagType().getStartDelimiter() ) ) { Element e = document.createElement( tag.getNameSegment().toString() ); stack.push( new Level( tag ) ); writer.write( "<" ); writer.write( tag.getNameSegment().toString() ); Attributes attributes = tag.getAttributes(); if( !attributes.isEmpty() ) { for( Attribute attribute : attributes ) { processAttribute( attribute ); } } if( tag.toString().trim().endsWith( "/>" ) || tag.isEmptyElementTag() ) { stack.pop(); writer.write( "/>" ); } else { writer.write( ">" ); } } else { writer.write( tag.toString() ); } }
static final Tag getPreviousTagUncached(final Source source, final int pos, final TagType tagType, final int breakAtPos) { // returns null if pos is out of range. if (tagType==null) return getPreviousTagUncached(source,pos,breakAtPos); final String startDelimiter=tagType.getStartDelimiter(); try { final ParseText parseText=source.getParseText(); int begin=pos; do { begin=parseText.lastIndexOf(startDelimiter,begin,breakAtPos); // parseText.lastIndexOf and indexOf return -1 if pos is out of range. if (begin==-1) return null; final Tag tag=getTagAt(source,begin,false); if (tag!=null && tag.getTagType()==tagType) return tag; } while ((begin-=1)>=0); } catch (IndexOutOfBoundsException ex) { // this should never happen during a get previous operation so rethrow it: throw ex; } return null; }
static final Tag getNextTagUncached(final Source source, final int pos, final TagType tagType, final int breakAtPos) { // returns null if pos is out of range. if (tagType==null) return getNextTagUncached(source,pos,breakAtPos); final String startDelimiter=tagType.getStartDelimiter(); try { final ParseText parseText=source.getParseText(); int begin=pos; do { begin=parseText.indexOf(startDelimiter,begin,breakAtPos); // parseText.lastIndexOf and indexOf return -1 if pos is out of range. if (begin==-1) return null; final Tag tag=getTagAt(source,begin,false); if (tag!=null && tag.getTagType()==tagType) return tag; } while ((begin+=1)<source.end); } catch (IndexOutOfBoundsException ex) { // this should only happen when the end of file is reached in the middle of a tag. // we don't have to do anything to handle it as there are no more tags anyway. } return null; }