| Method from com.opensymphony.module.sitemesh.html.tokenizer.Parser Detail: |
public int getAttributeCount() {
return attributes == null ? 0 : attributes.size() / 2;
}
|
public String getAttributeName(int index) {
return (String) attributes.get(index * 2);
}
|
public String getAttributeValue(int index) {
return (String) attributes.get(index * 2 + 1);
}
|
public String getAttributeValue(String name) {
// todo: optimize
if (attributes == null) {
return null;
}
final int len = attributes.size();
for (int i = 0; i < len; i+=2) {
if (name.equalsIgnoreCase((String) attributes.get(i))) {
return (String) attributes.get(i + 1);
}
}
return null;
}
|
public String getContents() {
return new String(input, position, length);
}
|
public String getName() {
return name;
}
|
public int getType() {
return type;
}
|
public boolean hasAttribute(String name) {
return getAttributeValue(name) != null;
}
|
public void parsedAttribute(String name,
String value,
boolean quoted) {
attributes.add(name);
if (quoted) {
attributes.add(value.substring(1, value.length() - 1));
} else {
attributes.add(value);
}
}
|
public void parsedTag(int type,
String name,
int start,
int length) {
this.type = type;
this.name = name;
this.position = start;
this.length = length;
handler.tag((Tag) this);
attributes.clear();
}
|
public void parsedText(int position,
int length) {
this.position = position;
this.length = length;
handler.text((Text) this);
}
|
protected void reportError(String message,
int line,
int column) {
// System.out.println(message);
handler.warning(message, line, column);
}
|
public void start() {
try {
while (true) {
int token;
if (pushbackToken == -1) {
token = yylex();
} else {
token = pushbackToken;
pushbackToken = -1;
}
if (token == 0) {
// EOF
return;
} else if (token == Parser.TEXT) {
// Got some text
parsedText(position(), length());
} else if (token == Parser.LT) {
// Token "< " - start of tag
parseTag(Tag.OPEN);
} else if (token == Parser.LT_OPEN_MAGIC_COMMENT) {
// Token "< !--[" - start of open magic comment
parseTag(Tag.OPEN_MAGIC_COMMENT);
} else if (token == Parser.LT_CLOSE_MAGIC_COMMENT) {
// Token "< ![" - start of close magic comment
parseTag(Tag.CLOSE_MAGIC_COMMENT);
} else {
reportError("Unexpected token from lexer, was expecting TEXT or LT", line(), column());
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
|
public void writeTo(CharArray out) {
out.append(input, position, length);
}
|