// need to know the type of product to get products for
String productTypeName = req.getParameter("channel");
String productTypeId = req.getParameter("id");
String topN = req.getParameter("topn");
ProductType type = null;
int top = 20;
if (topN != null) {
top = Integer.valueOf(topN).intValue();
}
String requestUrl = req.getRequestURL().toString();
String base = requestUrl.substring(0, requestUrl.lastIndexOf('/'));
Metadata channelMet = new Metadata();
channelMet.addMetadata("ProductType", productTypeName);
channelMet.addMetadata("ProductTypeId", productTypeId);
channelMet.addMetadata("TopN", String.valueOf(topN));
channelMet.addMetadata("BaseUrl", base);
List products = null;
try {
if (productTypeName.equals("ALL")) {
products = fm.getTopNProducts(top);
} else {
try {
type = fm.getProductTypeById(productTypeId);
} catch (RepositoryManagerException e) {
LOG.log(Level.SEVERE,
"Unable to obtain product type from product type id: ["
+ productTypeId + "]: Message: " + e.getMessage());
return;
}
products = fm.getTopNProducts(top, type);
}
} catch (CatalogException e) {
e.printStackTrace();
LOG
.log(Level.WARNING,
"Exception getting products from Catalog: Message: "
+ e.getMessage());
return;
}
if (products != null && products.size() > 0) {
String channelDesc = null;
if (!productTypeName.equals("ALL")) {
channelDesc = type.getDescription();
} else {
channelDesc = "ALL";
}
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document doc = factory.newDocumentBuilder().newDocument();
Element rss = XMLUtils.addNode(doc, doc, "rss");
XMLUtils.addAttribute(doc, rss, "version", "2.0");
XMLUtils
.addAttribute(doc, rss, "xmlns:cas", (String) NS_MAP.get("cas"));
Element channel = XMLUtils.addNode(doc, rss, "channel");
XMLUtils.addNode(doc, channel, "title", productTypeName);
XMLUtils.addNode(doc, channel, "link", RSSUtils.getChannelLink(
this.conf.getChannelLink(), channelMet));
XMLUtils.addNode(doc, channel, "description", channelDesc);
String buildPubDate = dateFormatter.format(new Date());
XMLUtils.addNode(doc, channel, "language", "en-us");
XMLUtils.addNode(doc, channel, "copyright", COPYRIGHT_BOILER_PLATE);
XMLUtils.addNode(doc, channel, "pubDate", buildPubDate);
XMLUtils.addNode(doc, channel, "category", productTypeName);
XMLUtils.addNode(doc, channel, "generator", "CAS File Manager");
XMLUtils.addNode(doc, channel, "lastBuildDate", buildPubDate);
for (Iterator i = products.iterator(); i.hasNext();) {
Product p = (Product) i.next();
String productTypeIdStr = p.getProductType().getProductTypeId();
ProductType productType = null;
try {
productType = fm.getProductTypeById(productTypeIdStr);
} catch (RepositoryManagerException e) {
e.printStackTrace();