/* (non-Javadoc)
   * @see org.springframework.extensions.surf.mvc.AbstractWebFrameworkView#validateRequestContext(org.springframework.extensions.surf.RequestContext, javax.servlet.http.HttpServletRequest)
   */
  @Override
  protected void validateRequestContext(RequestContext rc, HttpServletRequest req)
      throws Exception {
    super.validateRequestContext(rc, req);

    String themeId = null;

    // test to see if this is a site page
    String siteId = rc.getUriTokens().get("site");
    if (siteId != null) {
      // find the site dashboard page - and look for a theme override
      Page dashboard = getObjectService().getPage("site/" + siteId + "/dashboard");
      if (dashboard != null) {
        themeId = dashboard.getProperty("theme");
      }
    } else {
      // examine current page directly for custom properties with a theme override
      // this allows a different theme per page
      themeId = rc.getPage().getProperty("theme");
    }

    // if themeId different to current theme then look it up
    if (themeId != null && themeId.length() != 0 && !rc.getThemeId().equals(themeId)) {
      Theme theme = getObjectService().getTheme(themeId);
      if (theme != null) {
        // found a valid theme - set it current ready for page rendering
        rc.setTheme(theme);
      }
    }
  }
Example #2
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);
    }
  }