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

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


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

    // Get hold of the page template
    PageTemplate template = null;
    try {
      template = getTargetTemplate(page, request);
      if (template == null)
        template = site.getDefaultTemplate();
    } catch (IllegalStateException e) {
      logger.warn(e.getMessage());
      DispatchUtils.sendInternalError(request, response);
      return true;
    }

    // Identify the stage composer and remove any existing content
    String stage = template.getStage();
    logger.trace("Removing existing pagelets from composer '{}'", stage);
    while (page.getComposer(stage) != null && page.getComposer(stage).size() > 0) {
      page.removePagelet(stage, 0);
    }
View Full Code Here


   */
  protected PageTemplate getTargetTemplate(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 a target 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");
    }

    // 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 '" + templateId + "' 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

   * {@inheritDoc}
   *
   * @see ch.entwine.weblounge.common.content.page.Page#getStage()
   */
  public Composer getStage() {
    PageTemplate t = null;
    if (StringUtils.isNotBlank(template)) {
      t = uri.getSite().getTemplate(template);
    } else {
      t = uri.getSite().getDefaultTemplate();
      logger.warn("Page {} has no template associated", uri);
    }
    if (t == null)
      throw new IllegalStateException("Page template '" + template + "' not found");
    String stage = t.getStage();
    if (StringUtils.isBlank(stage))
      throw new IllegalStateException("Page template '" + template + "' does not define a stage");

    Composer c = getComposer(stage);
    if (c == null) {
View Full Code Here

   *
   * @see ch.entwine.weblounge.common.content.page.Page#getPreview()
   */
  public Pagelet[] getPreview() {
    Site site = getURI().getSite();
    PageTemplate t = null;
    if (StringUtils.isNotBlank(template)) {
      t = site.getTemplate(template);
    } else {
      t = site.getDefaultTemplate();
      logger.warn("Page {} has no template associated, using site default '{}'", uri, t.getIdentifier());
    }
    if (preview == null && t == null) {
      logger.warn("Can't calculate the page preview due to missing page template '{}'", template);
      return new Pagelet[] {};
    } else if (preview == null && t.getStage() == null) {
      logger.warn("Can't calculate the page preview due to missing stage definition in page template '{}'", template);
      return new Pagelet[] {};
    } else if (preview == null) {
      this.preview = new ArrayList<Pagelet>();
      List<Pagelet> stage = composers.get(t.getStage());
      Set<PageletRenderer> previewRenderers = new HashSet<PageletRenderer>();
      if (stage != null) {
        for (Pagelet p : stage) {

          // Load the pagelet's module
View Full Code Here

    } catch (MalformedURLException e) {
      throw new IllegalStateException("Malformed renderer url in page template definition: " + rendererUrlNode);
    }

    // Create the page template
    PageTemplate template = null;
    if (className != null) {
      Class<? extends PageTemplate> c = null;
      try {
        c = (Class<? extends PageTemplate>) classLoader.loadClass(className);
        template = c.newInstance();
        template.setIdentifier(id);
        template.setRenderer(rendererUrl);
      } catch (ClassNotFoundException e) {
        throw new IllegalStateException("Implementation " + className + " for page template '" + id + "' not found", e);
      } catch (InstantiationException e) {
        throw new IllegalStateException("Error instantiating impelementation " + className + " for page template '" + id + "'", e);
      } catch (IllegalAccessException e) {
        throw new IllegalStateException("Access violation instantiating implementation " + className + " for page template '" + id + "'", e);
      } catch (Throwable t) {
        throw new IllegalStateException("Error loading implementation " + className + " for page template '" + id + "'", t);
      }
    } else {
      template = new PageTemplateImpl(id, rendererUrl);
    }

    // Composeable
    template.setComposeable(ConfigurationUtils.isTrue(XPathHelper.valueOf(node, "@composeable", xpath)));

    // Default
    template.setDefault(ConfigurationUtils.isTrue(XPathHelper.valueOf(node, "@default", xpath)));

    // Stage
    String stage = XPathHelper.valueOf(node, "ns:stage", xpath);
    if (stage != null)
      template.setStage(stage);

    // Layout
    String layout = XPathHelper.valueOf(node, "ns:layout", xpath);
    if (layout != null)
      template.setDefaultLayout(layout);

    // client revalidation time
    String recheck = XPathHelper.valueOf(node, "ns:recheck", xpath);
    if (recheck != null) {
      try {
        template.setClientRevalidationTime(ConfigurationUtils.parseDuration(recheck));
      } catch (NumberFormatException e) {
        throw new IllegalStateException("The page template revalidation time is malformed: '" + recheck + "'");
      } catch (IllegalArgumentException e) {
        throw new IllegalStateException("The page template revalidation time is malformed: '" + recheck + "'");
      }
    }

    // cache expiration time
    String valid = XPathHelper.valueOf(node, "ns:valid", xpath);
    if (valid != null) {
      try {
        template.setCacheExpirationTime(ConfigurationUtils.parseDuration(valid));
      } catch (NumberFormatException e) {
        throw new IllegalStateException("The page template valid time is malformed: '" + valid + "'", e);
      } catch (IllegalArgumentException e) {
        throw new IllegalStateException("The page template valid time is malformed: '" + valid + "'", e);
      }
    }

    // name
    String name = XPathHelper.valueOf(node, "m:name", xpath);
    template.setName(name);

    // scripts
    NodeList scripts = XPathHelper.selectList(node, "ns:includes/ns:script", xpath);
    for (int i = 0; i < scripts.getLength(); i++) {
      template.addHTMLHeader(ScriptImpl.fromXml(scripts.item(i)));
    }

    // links
    NodeList links = XPathHelper.selectList(node, "ns:includes/ns:link", xpath);
    for (int i = 0; i < links.getLength(); i++) {
      template.addHTMLHeader(LinkImpl.fromXml(links.item(i)));
    }

    return template;
  }
View Full Code Here

   * {@link ch.entwine.weblounge.common.impl.site.SiteImpl#getTemplate(java.lang.String)}
   * .
   */
  @Test
  public void testGetTemplate() throws Exception {
    PageTemplate d = site.getTemplate(defaultTemplateId);
    assertNotNull(d);
    assertEquals(defaultTemplateId, d.getIdentifier());
    assertEquals(new URL(defaultTemplateUrl), d.getRenderer());
    assertEquals(defaultTemplateRecheckTime, d.getClientRevalidationTime());
    assertEquals(defaultTemplateValidTime, d.getCacheExpirationTime());
    assertEquals(defaultTemplateStage, d.getStage());
    assertEquals(defaultTemplateName, d.getName());

    PageTemplate m = site.getTemplate(mobileTemplateId);
    assertNotNull(m);
    assertEquals(mobileTemplateId, m.getIdentifier());
    assertEquals(new URL(mobileTemplateUrl), m.getRenderer());
    assertEquals(Renderer.DEFAULT_RECHECK_TIME, m.getClientRevalidationTime());
    assertEquals(Renderer.DEFAULT_VALID_TIME, m.getCacheExpirationTime());
    assertEquals(PageTemplate.DEFAULT_STAGE, m.getStage());
    assertEquals(mobileTemplateName, m.getName());

    assertTrue(site.getTemplate("test") == null);
  }
View Full Code Here

 
  /**
   * Preliminary setup work.
   */
  protected void setupPrerequisites() {
    PageTemplate homeTemplate = new PageTemplateImpl();

    site = EasyMock.createNiceMock(Site.class);
    EasyMock.expect(site.getDefaultLanguage()).andReturn(german);   
    EasyMock.expect(site.getAdministrator()).andReturn(new SiteAdminImpl("admin"));   
    EasyMock.expect(site.getDefaultLanguage()).andReturn(german);
View Full Code Here

    }

    // Load the template
    String codeTemplate = StringUtils.trimToNull(request.getParameter(CODE_TEMPLATE));
    if (codeTemplate != null) {
      PageTemplate t = site.getTemplate(codeTemplate);
      if (t == null) {
        logger.warn("Template '{}' does not exist", codeTemplate);
      } else {
        logger.info("Setting template to '{}'", codeTemplate);
        setTemplate(t);
View Full Code Here

    addField(TEMPLATE, page.getTemplate(), false, false);
    addField(STATIONARY, page.isStationary(), false, false);

    // Determine the stage composer
    String stage = null;
    PageTemplate template = page.getURI().getSite().getTemplate(page.getTemplate());
    if (template != null) {
      stage = template.getStage();
    }

    // Pagelet elements and properties
    for (Composer composer : page.getComposers()) {
      String composerId = composer.getIdentifier();
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.