private static synchronized void add(final TagType[] tagTypes) { for (int i=0; i<tagTypes.length; i++) add(tagTypes[i]); }
public static List<TagType> getList() { final ArrayList<TagType> list=new ArrayList<TagType>(); root.addTagTypesToList(list); return list; }
/** * Returns a list of all the currently registered tag types in order of lowest to highest <a href="TagType.html#Precedence">precedence</a>. * <br />(<a href="TagType.html#RegistrationRelated">registration related</a> method) * @return a list of all the currently registered tag types in order of lowest to highest <a href="TagType.html#Precedence">precedence</a>. */ public static final List<TagType> getRegisteredTagTypes() { return TagTypeRegister.getList(); }
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); }
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 final String getDebugInfo() { return root.appendDebugInfo(new StringBuilder(),0).toString(); }
private void removeTagType(final TagType tagType) { final int indexOfTagType=indexOfTagType(tagType); if (indexOfTagType==-1) return; if (tagTypes.length==1) { tagTypes=null; return; } final TagType[] newTagTypes=new TagType[tagTypes.length-1]; for (int i=0; i<indexOfTagType; i++) newTagTypes[i]=tagTypes[i]; for (int i=indexOfTagType; i<newTagTypes.length; i++) newTagTypes[i]=tagTypes[i+1]; tagTypes=newTagTypes; } }
/** * Deregisters this tag type. * <br />(<a href="TagType.html#RegistrationRelated">registration related</a> method) * * @see #register() */ public final void deregister() { getLogger().debug("Deregister tag type "+this); TagTypeRegister.remove(this); }
public String toString() { return appendDebugInfo(new StringBuilder(),0).toString(); }
private void addTagType(final TagType tagType) { final int indexOfTagType=indexOfTagType(tagType); if (indexOfTagType==-1) { if (tagTypes==null) { tagTypes=new TagType[] {tagType}; } else { final TagType[] newTagTypes=new TagType[tagTypes.length+1]; newTagTypes[0]=tagType; for (int i=0; i<tagTypes.length; i++) newTagTypes[i+1]=tagTypes[i]; tagTypes=newTagTypes; } } else { // tagType already exists in the list, just move it to the front for (int i=indexOfTagType; i>0; i--) tagTypes[i]=tagTypes[i-1]; tagTypes[0]=tagType; } }
private StringBuilder appendDebugInfo(final StringBuilder sb, final int level) { for (int i=0; i<level; i++) sb.append(" "); if (ch!=NULL_CHAR) sb.append(ch).append(' '); if (tagTypes!=null) { sb.append('('); for (TagType tagType : tagTypes) sb.append(tagType.getDescription()).append(", "); sb.setLength(sb.length()-2); sb.append(')'); } sb.append(Config.NewLine); if (children!=null) { final int childLevel=level+1; for (TagTypeRegister tagTypeRegister : children) tagTypeRegister.appendDebugInfo(sb,childLevel); } return sb; }
private void addTagTypesToList(final List<TagType> list) { if (tagTypes!=null) for (int i=tagTypes.length-1; i>=0; i--) list.add(tagTypes[i]); if (children!=null) for (TagTypeRegister tagTypeRegister : children) tagTypeRegister.addTagTypesToList(list); }
/** * Registers this tag type for recognition by the parser. * <br />(<a href="TagType.html#RegistrationRelated">registration related</a> method) * <p> * The order of registration affects the <a href="TagType.html#Precedence">precedence</a> of the tag type when a potential tag is being parsed. * * @see #deregister() */ public final void register() { getLogger().debug("Register tag type: "+this); TagTypeRegister.add(this); }