Package ch.entwine.weblounge.common.site

Examples of ch.entwine.weblounge.common.site.Site


    if (StringUtils.isBlank(siteIdentifier))
      throw new IllegalArgumentException("Site identifier must not be null");
    if (repository == null)
      throw new IllegalArgumentException("Content repository must not be null");

    Site site = findSiteByIdentifier(siteIdentifier);
    if (site != null) {
      try {
        repository.connect(site);
        logger.info("Site '{}' connected to content repository at {}", site, repository);
        site.setContentRepository(repository);
      } catch (ContentRepositoryException e) {
        logger.warn("Error connecting content repository " + repository + " to site '" + site + "'", e);
        throw e;
      }
    }
View Full Code Here


      }
    }

    // Tell the site to no longer use it
    if (siteIdentifier != null) {
      Site site = findSiteByIdentifier(siteIdentifier);
      repositoriesBySite.remove(siteIdentifier);

      // Tell the repository to clean up
      if (site != null && site.getContentRepository() != null) {
        try {
          site.setContentRepository(null);
          repository.disconnect();
        } catch (ContentRepositoryException e) {
          logger.warn("Error disconnecting content repository " + repository, e);
        }
      }
View Full Code Here

     *
     * @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
     */
    @Override
    public Object addingService(final ServiceReference reference) {
      final Site site = (Site) super.addingService(reference);
      Thread daemonThread = new Thread(new Runnable() {
        @Override
        public void run() {
          siteManager.addSite(site, reference);
        }
View Full Code Here

     * @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference,
     *      java.lang.Object)
     */
    @Override
    public void removedService(ServiceReference reference, Object service) {
      final Site site = (Site) service;
      Thread daemonThread = new Thread(new Runnable() {
        @Override
        public void run() {
          siteManager.removeSite(site);
        }
View Full Code Here

    // be surfing on another site
    HttpSession session = getSession(false);
    if (session == null)
      return;

    Site oldSite = (Site) session.getAttribute(SITE);
    if (!site.equals(oldSite)) {
      clearSession();
    }
  }
View Full Code Here

  /** The action mountpoint */
  private static final String ACTION_MOUNTPOINT = "/my/action/";

  @Before
  public void setUp() {
    Site site = EasyMock.createNiceMock(Site.class);
    WebUrl url = new WebUrlImpl(site, REQUEST_PATH);

    request = EasyMock.createNiceMock(WebloungeRequest.class);
    EasyMock.expect(request.getUrl()).andReturn(url).anyTimes();

View Full Code Here

      }
      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());
      renderer.getSharedContext().setInteractive(false);

      // Make sure the renderer is using a user agent that will correctly
      // resolve urls
      WebloungeUserAgent agent = userAgents.get(site.getIdentifier());
      if (agent == null) {
        agent = new WebloungeUserAgent(site.getHostname().getURL());
        userAgents.put(site.getIdentifier(), agent);
      }
      renderer.getSharedContext().setUserAgentCallback(agent);

      // Render the page to an image
      BufferedImage img = renderer.getImage();
View Full Code Here

    }

    // 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

   * @see ch.entwine.weblounge.common.scheduler.JobWorker#execute(java.lang.String,
   *      java.util.Dictionary)
   */
  public void execute(String name, Dictionary<String, Serializable> ctx)
      throws JobException {
    Site site = (Site)ctx.get(Site.class.getName());
    if (site != null)
      logger.info("Site '" + site + "' started");
    else
      logger.warn("Site not found in context");
  }
View Full Code Here

    try {
      ServiceReference[] refs = bundleCtx.getServiceReferences(siteClass, null);
      if (refs == null || refs.length == 0)
        return null;
      for (ServiceReference ref : refs) {
        Site s = (Site) bundleCtx.getService(ref);
        if (s == site)
          return ref.getBundle();
      }
      return null;
    } catch (InvalidSyntaxException e) {
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.site.Site

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.