if(params.containsKey("t")) {
Map<String, JSoupMapper> postMappings = new HashMap<String, JSoupMapper>();
if(params.containsKey("start")) {
// when start is set, we only take the replies; we are in a second or further page of the topic
postMappings.put(Namespaces.NS_SIOC + "container_of", new PHPBBPostIdMapper("div#pagecontent table td.gensmall a[name]"));
} else {
// otherwise we also take the initial title, creator and date for the topic
postMappings.put(Namespaces.NS_DC + "title", new CssTextLiteralMapper("div#pageheader a.titles"));
postMappings.put(Namespaces.NS_DC + "creator", new CssTextLiteralMapper(new CssSelectorMapper.Selector() {
@Override
public Elements select(Element node) {
final Element first = node.select("div#pagecontent table b.postauthor").first();
if (first != null)
return new Elements(first);
return new Elements();
}
}));
postMappings.put(Namespaces.NS_DC + "date", new PHPBBDateMapper("div#pagecontent table td.gensmall div") {
@Override
public Elements select(Element htmlDoc) {
final Elements sel = super.select(htmlDoc);
if (sel.size() > 0) {
final Element e = sel.get(1);
if (e != null)
return new Elements(e);
}
return new Elements();
}
});
postMappings.put(Namespaces.NS_SIOC + "has_container", new PHPBBForumHrefMapper("p.breadcrumbs a") {
@Override
public Elements select(Element htmlDoc) {
final Element select = super.select(htmlDoc).last();
return select != null ? new Elements(select) : new Elements();
}
});
postMappings.put(Namespaces.NS_SIOC + "container_of", new PHPBBPostIdMapper("div#pagecontent table td.gensmall a[name]"));
}
return postMappings;
} else
throw new RuntimeException("the requested resource does not seem to identify a PHPBB topic (t=... parameter missing)");