Package ch.entwine.weblounge.common.content

Examples of ch.entwine.weblounge.common.content.ResourceURI


        logger.debug("Content repository is offline");
        response.invalidate();
        return SKIP_BODY;
      }
     
      ResourceURI pageURI = new PageURIImpl(request.getSite(), null, resourceid);
      Page page = (Page) repository.get(pageURI);
      if (page == null) {
        logger.warn("Unable to link to non-existing page {}", pageURI);
        return SKIP_BODY;
      }
View Full Code Here


      return SKIP_BODY;
    }

    // Create the resource uri, either from the id or the path. If none is
    // specified, and we are not in jsp compilation mode, issue a warning
    ResourceURI uri = null;
    if (StringUtils.isNotBlank(videoId)) {
      uri = new MovieResourceURIImpl(site, null, videoId);
    } else if (StringUtils.isNotBlank(videoResourcePath)) {
      uri = new MovieResourceURIImpl(site, videoResourcePath);
    } else {
View Full Code Here

   *          the success code
   * @return the <code>resultCode</code> if success else <code>SKIP_BODY</code>
   */
  private int setResource(ResourceSearchResultItem searchResultItem,
      int resultCode) {
    ResourceURI uri = searchResultItem.getResourceURI();

    // Try to load the resource from the content repository
    try {
      if (!repository.exists(uri)) {
        logger.warn("Non existing resource {} requested on {}", uri, request.getUrl());
View Full Code Here

   *
   * @see ch.entwine.weblounge.common.content.PageSearchResultItem#getPage()
   */
  public Page getPage() {
    if (resource == null) {
      ResourceURI pageURI = new PageURIImpl(uri.getSite(), uri.getPath(), uri.getIdentifier(), uri.getVersion());
      resource = new LazyPageImpl(pageURI, pageXml, headerXml, previewXml);
    }
    return (Page) resource;
  }
View Full Code Here

      return SKIP_BODY;
    }

    // Create the file uri, either from the id or the path. If none is
    // specified, issue a warning
    ResourceURI uri = null;
    if (StringUtils.isNotBlank(fileId)) {
      uri = new FileResourceURIImpl(site, null, fileId);
    } else if (StringUtils.isNotBlank(filePath)) {
      uri = new FileResourceURIImpl(site, filePath, null);
    } else {
View Full Code Here

   *
   * @see ch.entwine.weblounge.common.content.FileSearchResultItem#getFileResource()
   */
  public FileResource getFileResource() {
    if (resource == null) {
      ResourceURI uri = new FileResourceURIImpl(url.getSite(), url.getPath(), id);
      resource = new LazyFileResourceImpl(uri, fileXml, headerXml, previewXml);
    }
    return (FileResource) resource;
  }
View Full Code Here

        return;
      }
      imagePreviewGenerator = previewGenerators.get(0);
    }

    ResourceURI uri = resource.getURI();
    Site site = uri.getSite();
    String html = null;
    try {
      URL pageURL = new URL(UrlUtils.concat(site.getHostname(environment).toExternalForm(), PAGE_HANDLER_PREFIX, uri.getIdentifier()));
      html = render(pageURL, site, environment, language, resource.getVersion());
      if (StringUtils.isBlank(html)) {
        logger.warn("Error rendering preview of page " + uri.getPath());
        return;
      }
      html = HTMLUtils.escapeHtml(HTMLUtils.unescape(html));
    } catch (ServletException e) {
      logger.warn("Error rendering page " + uri.getPath(), e);
      throw new IOException(e);
    }

    // Try to convert html to xhtml
    HtmlCleaner cleaner = new HtmlCleaner();
    CleanerProperties xhtmlProperties = cleaner.getProperties();
    TagNode xhtmlNode = cleaner.clean(html);
    if (xhtmlNode == null) {
      logger.warn("Error creating well-formed document from page {}", resource);
      return;
    }

    File xhtmlFile = null;
    is = new ByteArrayInputStream(html.getBytes("UTF-8"));

    // Write the resource content to disk. This step is needed, as the preview
    // generator can only handle files.
    try {
      xhtmlFile = File.createTempFile("xhtml", ".xml");
      Serializer xhtmlSerializer = new SimpleXmlSerializer(xhtmlProperties);
      xhtmlSerializer.writeToFile(xhtmlNode, xhtmlFile.getAbsolutePath(), "UTF-8");
    } catch (IOException e) {
      logger.error("Error creating temporary copy of file content at " + xhtmlFile, e);
      FileUtils.deleteQuietly(xhtmlFile);
      throw e;
    } finally {
      IOUtils.closeQuietly(is);
    }

    File imageFile = File.createTempFile("xhtml-preview", "." + PREVIEW_FORMAT);
    FileOutputStream imageFos = null;

    // Render the page and write back to client
    try {
      int screenshotWidth = DEFAULT_SCREENSHOT_WIDTH;
      int screenshotHeight = DEFAULT_SCREENSHOT_HEIGHT;
      if (style != null && style.getWidth() > 0 && style.getHeight() > 0) {
        screenshotHeight = (int) ((float) screenshotWidth / (float) style.getWidth() * style.getHeight());
      }

      // Create the renderer. Due to a synchronization bug in the software,
      // this needs to be synchronized
      Java2DRenderer renderer = null;
      try {
        synchronized (this) {
          renderer = new Java2DRenderer(xhtmlFile, screenshotWidth, screenshotHeight);
        }
      } catch (Throwable t) {
        if (isRenderingEnvironmentSane) {
          logger.warn("Error creating Java 2D renderer for previews: {}" + t.getMessage());
          logger.warn("Page preview rendering will be switched off");
          isRenderingEnvironmentSane = false;
        }
        logger.debug("Error creating Java 2D renderer for preview of page {}: {}" + uri.getPath(), t.getMessage());
        return;
      }

      // Configure the renderer
      renderer.getSharedContext().setBaseURL(site.getHostname().toExternalForm());
View Full Code Here

        return;
      }
    }

    // Find the relevant metadata to start the request
    ResourceURI uri = resource.getURI();
    long version = resource.getVersion();
    Site site = uri.getSite();

    // Create the url
    URL pageURL = new URL(UrlUtils.concat(site.getHostname(environment).toExternalForm(), PAGE_HANDLER_PREFIX, uri.getIdentifier()));
    if (version == Resource.WORK) {
      pageURL = new URL(UrlUtils.concat(pageURL.toExternalForm(), "work_" + language.getIdentifier() + ".html"));
    } else {
      pageURL = new URL(UrlUtils.concat(pageURL.toExternalForm(), "index_" + language.getIdentifier() + ".html"));
    }
View Full Code Here

   * {@link ch.entwine.weblounge.contentrepository.impl.index.ContentRepositoryIndex#getRevisions(ch.entwine.weblounge.common.content.ResourceURI)}
   * .
   */
  @Test
  public void testGetRevisions() {
    ResourceURI uri1 = new PageURIImpl(site, "/weblounge");
    ResourceURI uri2Live = new PageURIImpl(site, "/etc/weblounge");
    ResourceURI uri2Work = new PageURIImpl(site, "/etc/weblounge", Resource.WORK);

    Page page1 = new PageImpl(uri1);
    page1.setTemplate(template.getIdentifier());

    Page page2Live = new PageImpl(uri2Live);
View Full Code Here

      String id = UUID.randomUUID().toString();
      Page p = new PageImpl(new PageURIImpl(site, path, id));
      p.setTemplate("home");
      p.setTitle("title", english);
      pages.add(p);
      ResourceURI uri = idx.add(p);
      assertEquals(id, uri.getIdentifier());
      assertEquals(path, uri.getPath());
      assertEquals(i + 1, idx.getResourceCount());
    }

    // Test if everything can be found
    for (Page p : pages) {
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.content.ResourceURI

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.