Beispiel #1
0
  @Override
  public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
    Writer writer = null;
    try {
      writer = res.getWriter();

      // Get the section placed in the request context by ApplicationDataInterceptor
      RequestContext requestContext = ThreadLocalRequestContext.getRequestContext();
      Section section = (Section) requestContext.getValue("section");
      WebSite webSite = (WebSite) requestContext.getValue("webSite");

      // Get the collection property from the page definition
      String collectionName = requestContext.getPage().getProperty("collection");
      if (collectionName == null)
        throw new WebScriptException("collectionName property must be supplied");

      // Fetch the named collection
      AssetCollection collection =
          (AssetCollection) collectionFactory.getCollection(section.getId(), collectionName);

      // Use ROME library to output the colleciton as a syndication feed
      SyndFeed feed = new SyndFeedImpl();
      feed.setFeedType(FEED_TYPE);

      feed.setTitle(section.getTitle());
      feed.setLink(urlUtils.getWebsiteDomain(webSite) + urlUtils.getUrl(section));
      feed.setDescription(section.getDescription());

      List<SyndEntry> entries = new ArrayList<SyndEntry>();
      for (Asset asset : collection.getAssets()) {
        SyndEntry entry = new SyndEntryImpl();
        entry.setTitle(asset.getTitle());
        entry.setLink(urlUtils.getWebsiteDomain(webSite) + urlUtils.getUrl(asset));
        entry.setUri(urlUtils.getWebsiteDomain(webSite) + urlUtils.getShortUrl(asset));
        entry.setPublishedDate((Date) asset.getProperties().get(Asset.PROPERTY_PUBLISHED_TIME));
        SyndContent description = new SyndContentImpl();
        description.setType("text/html");
        description.setValue(asset.getDescription());
        entry.setDescription(description);
        entries.add(entry);
      }
      feed.setEntries(entries);

      SyndFeedOutput output = new SyndFeedOutput();
      output.output(feed, writer);
      writer.flush();
    } catch (IOException e) {
      log.error("Unable to output rss", e);
    } catch (FeedException e) {
      log.error("Unable to output rss", e);
    }
  }
 public List<String> getTags() {
   return delegate.getTags();
 }
 public long getSize() {
   return delegate.getSize();
 }
 public Map<String, List<Asset>> getRelatedAssets() {
   return delegate.getRelatedAssets();
 }
 public List<Asset> getRelatedAssets(String relationshipName) {
   return delegate.getRelatedAssets(relationshipName);
 }
 public Asset getRelatedAsset(String relationshipName) {
   return delegate.getRelatedAsset(relationshipName);
 }
 public Serializable getProperty(String name) {
   return delegate.getProperty(name);
 }
 @Override
 public Map<String, Rendition> getRenditions() {
   return delegate.getRenditions();
 }
 public String getName() {
   return delegate.getName();
 }
 public String getMimeType() {
   return delegate.getMimeType();
 }
 public String getId() {
   return delegate.getId();
 }
 public String getDescription() {
   return delegate.getDescription();
 }
 public ContentStream getContentAsInputStream() {
   return delegate.getContentAsInputStream();
 }
 public Section getContainingSection() {
   return delegate.getContainingSection();
 }
 public String getTitle() {
   return delegate.getTitle();
 }
 public Map<String, Serializable> getProperties() {
   return delegate.getProperties();
 }
 @Override
 public String getType() {
   return delegate.getType();
 }