1 21 package au.id.jericho.lib.html; 22 23 import java.util.*; 24 25 37 public class StartTagTypeGenericImplementation extends StartTagType { 38 final boolean nameCharAfterPrefixAllowed; 39 40 53 protected StartTagTypeGenericImplementation(final String description, final String startDelimiter, final String closingDelimiter, final EndTagType correspondingEndTagType, final boolean isServerTag) { 54 this(description,startDelimiter,closingDelimiter,correspondingEndTagType,isServerTag,false,false); 55 } 56 57 69 protected StartTagTypeGenericImplementation(final String description, final String startDelimiter, final String closingDelimiter, final EndTagType correspondingEndTagType, final boolean isServerTag, final boolean hasAttributes, final boolean isNameAfterPrefixRequired) { 70 super(description,startDelimiter,closingDelimiter,correspondingEndTagType,isServerTag,hasAttributes,isNameAfterPrefixRequired); 71 nameCharAfterPrefixAllowed=(getNamePrefix().length()==0 || !Character.isLetter(getNamePrefix().charAt(getNamePrefix().length()-1))); 72 } 73 74 114 protected Tag constructTagAt(final Source source, final int pos) { 115 final ParseText parseText=source.getParseText(); 116 final int nameBegin=pos+1; 117 String name=getNamePrefix(); 118 int nameEnd=nameBegin+getNamePrefix().length(); 119 if (isNameAfterPrefixRequired()) { 120 final int extendedNameEnd=source.findNameEnd(nameEnd); 121 if (extendedNameEnd==-1) return null; 122 name=parseText.substring(nameBegin,extendedNameEnd); 123 nameEnd=extendedNameEnd; 124 } else if (!nameCharAfterPrefixAllowed && Tag.isXMLNameChar(parseText.charAt(nameEnd))) { 125 return null; 126 } 127 int end; 128 Attributes attributes=null; 129 if (hasAttributes()) { 130 attributes=parseAttributes(source,pos,name); 133 if (attributes==null) return null; end=findEnd(source,attributes.getEnd()); } else { 136 end=findEnd(source,nameEnd); 137 if (end==-1) { 138 if (source.isLoggingEnabled()) source.log(source.getRowColumnVector(pos).appendTo(new StringBuffer (200).append("StartTag ").append(name).append(" at ")).append(" not recognised as type '").append(getDescription()).append("' because it has no closing delimiter").toString()); 139 return null; 140 } 141 } 142 return constructStartTag(source,pos,end,name,attributes); 143 } 144 145 159 protected int findEnd(final Source source, final int pos) { 160 final int delimiterBegin=source.getParseText().indexOf(getClosingDelimiter(),pos); 161 return (delimiterBegin==-1 ? -1 : delimiterBegin+getClosingDelimiter().length()); 162 } 163 } 164 | Popular Tags |