use of org.geometerplus.fbreader.network.authentication.litres.LitResRecommendationsItem in project FBReaderJ by geometer.
the class OPDSFeedHandler method readCatalogItem.
private NetworkItem readCatalogItem(OPDSEntry entry) {
final OPDSNetworkLink opdsLink = (OPDSNetworkLink) myData.Link;
final UrlInfoCollection<UrlInfo> urlMap = new UrlInfoCollection<UrlInfo>();
boolean urlIsAlternate = false;
String litresRel = null;
for (ATOMLink link : entry.Links) {
final String href = ZLNetworkUtil.url(myBaseURL, link.getHref());
final MimeType mime = MimeType.get(link.getType());
final String rel = opdsLink.relation(link.getRel(), mime);
if (MimeType.IMAGE_PNG.weakEquals(mime) || MimeType.IMAGE_JPEG.weakEquals(mime)) {
if (REL_IMAGE_THUMBNAIL.equals(rel) || REL_THUMBNAIL.equals(rel)) {
urlMap.addInfo(new UrlInfo(UrlInfo.Type.Thumbnail, href, mime));
} else if (REL_COVER.equals(rel) || (rel != null && rel.startsWith(REL_IMAGE_PREFIX))) {
urlMap.addInfo(new UrlInfo(UrlInfo.Type.Image, href, mime));
}
} else if (MimeType.APP_ATOM_XML.weakEquals(mime)) {
final boolean hasCatalogUrl = urlMap.getInfo(UrlInfo.Type.Catalog) != null;
if (REL_ALTERNATE.equals(rel)) {
if (!hasCatalogUrl) {
urlMap.addInfo(new UrlInfo(UrlInfo.Type.Catalog, href, mime));
urlIsAlternate = true;
}
} else if (!hasCatalogUrl || rel == null || REL_SUBSECTION.equals(rel)) {
urlMap.addInfo(new UrlInfo(UrlInfo.Type.Catalog, href, mime));
urlIsAlternate = false;
}
} else if (MimeType.TEXT_HTML.weakEquals(mime)) {
if (REL_ACQUISITION.equals(rel) || REL_ACQUISITION_OPEN.equals(rel) || REL_ALTERNATE.equals(rel) || rel == null) {
urlMap.addInfo(new UrlInfo(UrlInfo.Type.HtmlPage, href, mime));
}
} else if (MimeType.APP_LITRES.weakEquals(mime)) {
urlMap.addInfo(new UrlInfo(UrlInfo.Type.Catalog, href, mime));
litresRel = rel;
}
}
if (urlMap.getInfo(UrlInfo.Type.Catalog) == null && urlMap.getInfo(UrlInfo.Type.HtmlPage) == null) {
return null;
}
if (urlMap.getInfo(UrlInfo.Type.Catalog) != null && !urlIsAlternate) {
urlMap.removeAllInfos(UrlInfo.Type.HtmlPage);
}
final CharSequence annotation;
if (entry.Summary != null) {
annotation = entry.Summary;
} else if (entry.Content != null) {
annotation = entry.Content;
} else {
annotation = null;
}
if (litresRel != null) {
if (REL_BOOKSHELF.equals(litresRel)) {
return new LitResBookshelfItem(opdsLink, entry.Title, annotation, urlMap);
} else if (REL_RECOMMENDATIONS.equals(litresRel)) {
return new LitResRecommendationsItem(opdsLink, entry.Title, annotation, urlMap);
} else if (REL_TOPUP.equals(litresRel)) {
return new TopUpItem(opdsLink, urlMap);
} else {
return null;
}
} else {
return new OPDSCatalogItem(opdsLink, entry.Title, annotation, urlMap);
}
}
Aggregations