m_tokenIndex = 0;
m_contentIndex = 0;
}
public Map<String, String> extractMicroformat() {
XMLElement xe = new XMLElement();
String currentProperty = null;
Map<String, String> rval = new HashMap<String, String>();
htmlToken tok;
int balance = 0;
String currentContent = null;
while((tok = nextToken()) != null) {
int type = tok.getTokenType();
if(currentProperty != null) {
if(type == htmlToken.HTML_TAG) balance++;
if(type == htmlToken.HTML_ENDTAG) {
balance--;
if(balance == 0) {
if(rval.get(currentProperty) == null || rval.get(currentProperty).length() == 0 || currentContent.length() != 0) {
rval.put(currentProperty, currentContent);
}
currentProperty = null;
}
}
}
if(type == htmlToken.HTML_TAG || type == htmlToken.HTML_SINGLETAG) {
if(tok.getToken().startsWith("!")) continue;
try {
xe.reset();
xe.parseString("<" + tok.getToken() + "/>");
} catch(XMLParseException xpe) {
JConfig.log().logVerboseDebug("eBay's HTML still sucks.");
continue;
}
String itemprop = xe.getProperty("itemprop");
if(itemprop != null) {
String content = xe.getProperty("content");
if (content != null) {
if(rval.get(itemprop) == null || rval.get(itemprop).length() == 0 || content.length() != 0) {
rval.put(itemprop, content);
}
} else {
currentProperty = itemprop;
currentContent = "";
balance = 1;
}
} else if(xe.getTagName().equals("meta")) {
String property = xe.getProperty("property");
if(property != null && property.startsWith("og:")) {
itemprop = property.substring(3);
String content = xe.getProperty("content");
if (rval.get(itemprop) == null || rval.get(itemprop).length() == 0 || content.length() != 0) {
rval.put(itemprop, content);
}
}
}