Package ch.entwine.weblounge.common.content.page

Examples of ch.entwine.weblounge.common.content.page.PageTemplate


          HTMLAction htmlAction = (HTMLAction) action;
          logger.debug("Action handler found");

          if (targetPage != null) {
            String templateId = targetPage.getTemplate();
            PageTemplate template = site.getTemplate(templateId);
            if (template != null && id.equalsIgnoreCase(template.getStage())) {
              template.setEnvironment(request.getEnvironment());
              if (htmlAction.startStage(request, response, composer) == HTMLAction.SKIP_COMPOSER) {
                return EVAL_PAGE;
              }
            }
          }
View Full Code Here


      }
    }

    // templates
    NodeList templateNodes = XPathHelper.selectList(config, "ns:templates/ns:template", xpathProcessor);
    PageTemplate firstTemplate = null;
    for (int i = 0; i < templateNodes.getLength(); i++) {
      PageTemplate template = PageTemplateImpl.fromXml(templateNodes.item(i), xpathProcessor);
      boolean isDefault = ConfigurationUtils.isDefault(templateNodes.item(i));
      if (isDefault && site.getDefaultTemplate() != null) {
        logger.warn("Site '{}' defines more than one default templates", site.getIdentifier());
      } else if (isDefault) {
        site.setDefaultTemplate(template);
        logger.debug("Site '{}' uses default template '{}'", site.getIdentifier(), template.getIdentifier());
      } else {
        site.addTemplate(template);
        logger.debug("Added template '{}' to site '{}'", template.getIdentifier(), site.getIdentifier());
      }
      if (firstTemplate == null)
        firstTemplate = template;
    }
View Full Code Here

    // the fields are not present.
    String title = getSubject(message);
    String author = getAuthor(message);

    // Collect default settings
    PageTemplate template = site.getDefaultTemplate();
    if (template == null)
      throw new IllegalStateException("Missing default template in site '" + site + "'");
    String stage = template.getStage();
    if (StringUtils.isBlank(stage))
      throw new IllegalStateException("Missing stage definition in template '" + template.getIdentifier() + "'");

    // Standard fields
    page.setTitle(title, language);
    page.setTemplate(template.getIdentifier());
    page.setPublished(new UserImpl(site.getAdministrator()), message.getReceivedDate(), null);

    // TODO: Translate e-mail "from" into site user and throw if no such
    // user can be found
    page.setCreated(site.getAdministrator(), message.getSentDate());
View Full Code Here

  protected boolean isStage(String composer, WebloungeRequest request) {
    if (composer == null)
      throw new IllegalArgumentException("Composer may not be null!");

    String stage = PageTemplate.DEFAULT_STAGE;
    PageTemplate template = (PageTemplate) request.getAttribute(WebloungeRequest.TEMPLATE);
    if (template != null)
      stage = template.getStage();
    return composer.equalsIgnoreCase(stage);
  }
View Full Code Here

  protected boolean isStage(String composer, WebloungeRequest request) {
    if (composer == null)
      throw new IllegalArgumentException("Composer may not be null!");

    String stage = PageTemplate.DEFAULT_STAGE;
    PageTemplate template = (PageTemplate) request.getAttribute(WebloungeRequest.TEMPLATE);
    if (template != null)
      stage = template.getStage();
    return composer.equalsIgnoreCase(stage);
  }
View Full Code Here

      pageUrl = new WebUrlImpl(site, page.getURI().getPath());
      response.addTag(CacheTag.Url, pageUrl.getPath());
      response.addTag(CacheTag.Resource, page.getURI().getIdentifier());
    }

    PageTemplate template = site.getTemplate(page.getTemplate());
    if (template == null) {
      logger.error("No page template found for {}", page);
      return EVAL_PAGE;
    }
    template.setEnvironment(request.getEnvironment());

    String stage = template.getStage();
    if (stage == null) {
      logger.error("No stage defined for page template '{}' on {}", template, request.getUrl());
      return EVAL_PAGE;
    }
View Full Code Here

      DispatchUtils.sendInternalError(request, response);
      return;
    }

    // Get hold of the page template
    PageTemplate template = null;
    try {
      template = getTargetTemplate(action, page, request);
      if (template == null)
        template = site.getDefaultTemplate();
    } catch (IllegalStateException e) {
View Full Code Here

   */
  protected PageTemplate getTargetTemplate(Action action, Page page,
      WebloungeRequest request) throws IllegalStateException {

    Site site = request.getSite();
    PageTemplate template = null;
    String templateId = null;

    // Does the request specify an ad-hoc template?
    if (request.getAttribute(WebloungeRequest.TEMPLATE) != null) {
      templateId = (String) request.getAttribute(WebloungeRequest.TEMPLATE);
      template = site.getTemplate(templateId);
      if (template == null)
        throw new IllegalStateException("Page template '" + templateId + "' specified by request attribute was not found");
    }

    // Does the request specify an ad-hoc template?
    if (template == null && request.getParameter(HTMLAction.TARGET_TEMPLATE) != null) {
      templateId = request.getParameter(HTMLAction.TARGET_TEMPLATE);
      template = site.getTemplate(templateId);
      if (template == null)
        throw new IllegalStateException("Page template '" + templateId + "' specified by request parameter was not found");
    }

    // See if the action handler specifies a template
    if (template == null && action instanceof HTMLAction) {
      HTMLAction htmlAction = (HTMLAction) action;
      template = htmlAction.getTemplate();
      if (template == null)
        logger.debug("Action '{}' did not define a page template", action.getIdentifier());
    }

    // See if the action handler specifies a default template
    if (template == null && action instanceof HTMLAction) {
      HTMLAction htmlAction = (HTMLAction) action;
      template = htmlAction.getDefaultTemplate();
      if (template == null)
        logger.debug("Action '{}' did not define a default page template", action.getIdentifier());
    }

    // By default, the page will have to deliver on the template
    if (template == null && page != null) {
      template = site.getTemplate(page.getTemplate());
      if (template == null)
        throw new IllegalStateException("Page template '" + page.getTemplate() + "' for page '" + page + "' was not found");
    }

    // Did we end up finding a template?
    if (template == null)
      return null;

    template.setEnvironment(request.getEnvironment());
    return template;
  }
View Full Code Here

      // Store the page in the request
      request.setAttribute(WebloungeRequest.PAGE, page);

      // Get hold of the page template
      PageTemplate template = null;
      try {
        template = getPageTemplate(page, request);
        template.setEnvironment(request.getEnvironment());
      } catch (IllegalStateException e) {
        logger.debug(e.getMessage());
        DispatchUtils.sendInternalError(request, response);
        return true;
      }

      // Does the template support the requested flavor?
      if (!template.supportsFlavor(contentFlavor)) {
        logger.warn("Template '{}' does not support requested flavor {}", template, contentFlavor);
        DispatchUtils.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, request, response);
        return true;
      }

      // Suggest a last modified data. Note that this may not be the final date
      // as the page may contain content embedded from other pages that feature
      // more recent modification dates
      response.setModificationDate(page.getLastModified());

      // Set the content type
      String characterEncoding = response.getCharacterEncoding();
      if (StringUtils.isNotBlank(characterEncoding))
        response.setContentType("text/html; charset=" + characterEncoding.toLowerCase());
      else
        response.setContentType("text/html");

      // Add the template's HTML header elements to the response if it's not
      // only used in editing mode
      for (HTMLHeadElement header : template.getHTMLHeaders()) {
        if (!HTMLInclude.Use.Editor.equals(header.getUse()))
          response.addHTMLHeader(header);
      }

      // Select the actual renderer by method and have it render the
      // request. Since renderers are being pooled by the bundle, we
      // have to return it after the request has finished.
      try {
        logger.debug("Rendering {} using page template '{}'", path, template);
        template.render(request, response);
      } catch (Throwable t) {
        String params = RequestUtils.dumpParameters(request);
        String msg = "Error rendering template '" + template + "' on '" + path + "' " + params;
        Throwable o = t.getCause();
        if (o != null) {
View Full Code Here

  protected PageTemplate getPageTemplate(Page page, WebloungeRequest request)
      throws IllegalStateException {
    Site site = request.getSite();

    // Has a template been defined already (e. g. by an action handler)?
    PageTemplate template = (PageTemplate) request.getAttribute(WebloungeRequest.TEMPLATE);

    // Apparently not...
    if (template == null) {
      String templateId = page.getTemplate();
      template = site.getTemplate(templateId);
      if (template == null) {
        logger.warn("Page {} specified a non-existing template '{}'", page.getURI(), templateId);
        template = site.getDefaultTemplate();
      }
    }

    template.setEnvironment(request.getEnvironment());
    return template;
  }
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.content.page.PageTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.