Package ch.entwine.weblounge.common.site

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


   *      java.util.Dictionary)
   */
  public void execute(String name, Dictionary<String, Serializable> ctx)
      throws JobException {

    Site site = (Site) ctx.get(Site.class.getName());

    // Make sure the site is ready to accept content
    if (site.getContentRepository().isReadOnly()) {
      logger.warn("Unable to publish e-mail messages to site '{}': repository is read only", site);
      return;
    }

    WritableContentRepository repository = (WritableContentRepository)site.getContentRepository();

    // Extract the configuration from the job properties
    String provider = (String) ctx.get(OPT_PROVIDER);
    Account account = null;
    try {
View Full Code Here


    // Don't do work if not needed (which is the case during precompilation)
    if (RequestUtils.isPrecompileRequest(request))
      return SKIP_BODY;

    Site site = request.getSite();

    if (pageId == null) {
      PageListTag pageListTag = (PageListTag) findAncestorWithClass(this, PageListTag.class);
      if (pageListTag != null) {
        page = pageListTag.getPage();
        pagePreview = pageListTag.getPagePreview();
        pageUrl = pageListTag.getPageUrl();
      } else if (RequestUtils.isMockRequest(request)) {
        // Skip body, if this is a mock-request
        return SKIP_BODY;
      } else {
        throw new JspException("Page preview tag on " + request.getUrl() + " requires either a page id or embedding inside a PageListTag");
      }
    } else {
      ContentRepository contentRepository = null;
      contentRepository = site.getContentRepository();
      if (contentRepository == null) {
        logger.debug("Content repository is offline");
        response.invalidate();
        return SKIP_BODY;
      }

      ResourceURI pageURI = new PageURIImpl(site, null, pageId);

      try {
        page = (Page) contentRepository.get(pageURI);
        if (page == null) {
          logger.error("No data available for page {}", pageURI);
          return EVAL_PAGE;
        }
      } catch (SecurityException e) {
        throw new JspException("Security exception while trying to load " + pageUrl, e);
      } catch (ContentRepositoryException e) {
        throw new JspException("Exception while trying to load " + pageUrl, e);
      }

      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());
View Full Code Here

   * @return <code>true</code> if the pagelet could be handled
   */
  public boolean handlePagelet(int index) {
    JspWriter writer = pageContext.getOut();

    Site site = request.getSite();
    String stage = pagePreview.getIdentifier();

    try {

      // Flush all input that has been written to the response so far.
      pageContext.getOut().flush();

      // Render the pagelet
      Renderer renderer = null;
      Pagelet pagelet = pagePreview.getPagelets()[index];
      try {
        request.setAttribute(WebloungeRequest.PAGE, page);
        request.setAttribute(WebloungeRequest.PAGELET, pagelet);
        request.setAttribute(WebloungeRequest.COMPOSER, pagePreview);

        pageContext.setAttribute(PagePreviewTagVariables.PAGELET, pagelet);

        if (render) {

          String moduleId = pagelet.getModule();
          String rendererId = pagelet.getIdentifier();

          // Check access rights
          // TODO: Check access
          // Permission p = SystemPermission.READ;
          // if (!pagelet.checkOne(p, user.getRoleClosure()) &&
          // !pagelet.check(p, user)) {
          // logger.debug("Skipping pagelet " + i + " in composer " + composer_
          // +
          // " due to insufficient rights");
          // continue p;
          // }

          // Check publishing dates
          // TODO: Fix this. pagelet.isPublished() currently returns false,
          // as both from and to dates are null (see PublishingCtx)
          // if (!(request.getVersion() == Resource.WORK) &&
          // !pagelet.isPublished()) {
          // logger.debug("Skipping pagelet " + index + " in composer " + stage
          // + " since it is not yet published");
          // return false;
          // }

          // Select the renderer's module
          Module m = site.getModule(moduleId);
          if (m == null) {
            logger.warn("Unable to load renderer '" + rendererId + "' for " + pageUrl + ": module '" + moduleId + "' not found!");
            return false;
          }

View Full Code Here

    }

    logger.debug("Serving {}", httpRequest.getRequestURI());

    // Get the site dispatcher
    Site site = securityService.getSite();
    if (site == null) {
      site = getSiteByRequest(httpRequest);
      securityService.setSite(site);
    }

    boolean isSpecialRequest = StringUtils.isNotBlank(httpRequest.getHeader("X-Weblounge-Special"));

    // See if a site dispatcher was found, and if so, if it's enabled
    if (site == null) {
      String serverName = httpRequest.getScheme() + "://" + httpRequest.getServerName();
      if (httpRequest.getServerPort() != 80)
        serverName += ":" + httpRequest.getServerPort();
      if (!wellknownFiles.contains(httpRequest.getRequestURI()) && !missingSiteWarnings.contains(serverName)) {
        missingSiteWarnings.add(serverName);
        logger.warn("No site found to handle {}", serverName);
      }
      httpResponse.sendError(SC_NOT_FOUND);
      return;
    } else if (!site.isOnline() && !isSpecialRequest) {
      if (site.getContentRepository() == null) {
        if (!missingRepositoryWarnings.contains(site.getIdentifier())) {
          logger.warn("No content repository connected to site '{}'", site);
          missingRepositoryWarnings.add(site.getIdentifier());
        } else {
          logger.debug("No content repository connected to site '{}'", site);
        }
      } else {
        logger.debug("Ignoring request for disabled site '{}'", site);
      }
      httpResponse.sendError(SC_SERVICE_UNAVAILABLE);
      return;
    }

    // Make sure the response is buffered
    httpResponse = new BufferedHttpServletResponse(httpResponse);

    // Get the servlet that is responsible for the site's content
    Servlet siteServlet = sites.getSiteServlet(site);

    // Get the response cache, if available
    ResponseCache cache = caches.get(site.getIdentifier());

    // Wrap for caching
    if (cache != null) {
      httpResponse = cache.createCacheableResponse(httpRequest, httpResponse);
    }
View Full Code Here

   * @return the target site or <code>null</code>
   */
  private Site getSiteByRequest(HttpServletRequest request) {
    if (sites == null)
      return null;
    Site site = sites.findSiteByRequest(request);
    return site;
  }
View Full Code Here

   * @param response
   *          the weblounge response
   */
  public boolean service(WebloungeRequest request, WebloungeResponse response) {

    Site site = request.getSite();
    WebUrl url = request.getUrl();
    String path = request.getRequestURI();
    String feedType = null;
    String feedVersion = null;

    // Currently, we only support feeds mapped to our well-known uri
    if (!path.startsWith(URI_PREFIX) || !(path.length() > URI_PREFIX.length()))
      return false;

    // Check for feed type and version
    String feedURI = path.substring(URI_PREFIX.length());
    String[] feedURIParts = feedURI.split("/");
    if (feedURIParts.length == 0) {
      logger.debug("Feed request {} does not include feed type", path);
      return false;
    } else if (feedURIParts.length == 1) {
      logger.debug("Feed request {} does not include feed version", path);
      return false;
    }

    // Check the request method. This handler only supports GET
    String requestMethod = request.getMethod().toUpperCase();
    if ("OPTIONS".equals(requestMethod)) {
      String verbs = "OPTIONS,GET";
      logger.trace("Answering options request to {} with {}", url, verbs);
      response.setHeader("Allow", verbs);
      response.setContentLength(0);
      return true;
    } else if (!"GET".equals(requestMethod)) {
      logger.debug("Feed request handler does not support {} requests", url, requestMethod);
      DispatchUtils.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, request, response);
      return true;
    }

    feedType = feedURIParts[0];
    feedVersion = feedURIParts[1];

    // Check for explicit no cache instructions
    boolean noCache = request.getParameter(ResponseCache.NOCACHE_PARAM) != null;

    // Check if the page is already part of the cache. If so, our task is
    // already done!
    if (!noCache) {
      long expirationTime = Renderer.DEFAULT_VALID_TIME;
      long revalidationTime = Renderer.DEFAULT_RECHECK_TIME;

      // Create the set of tags that identify the request output
      CacheTagSet cacheTags = createPrimaryCacheTags(request);

      // Check if the page is already part of the cache
      if (response.startResponse(cacheTags.getTags(), expirationTime, revalidationTime)) {
        logger.debug("Feed handler answered request for {} from cache", request.getUrl());
        return true;
      }
    }

    try {

      // Compile the feed
      SyndFeed feed = createFeed(feedType, feedVersion, site, request, response);
      if (feed == null)
        return true;

      // Set the response type
      String characterEncoding = "utf-8";
      if (feedType.startsWith("atom"))
        response.setContentType("application/atom+xml; charset=" + characterEncoding);
      else if (feedType.startsWith("rss"))
        response.setContentType("application/rss+xml; charset=" + characterEncoding);

      // Set the character encoding
      feed.setEncoding(response.getCharacterEncoding());

      // Set the modification date
      response.setModificationDate(feed.getPublishedDate());

      // Write the feed back to the response

      SyndFeedOutput output = new SyndFeedOutput();
      Writer responseWriter = new OutputStreamWriter(response.getOutputStream(), characterEncoding);
      output.output(feed, responseWriter);
      response.getOutputStream().flush();
      return true;

    } catch (ContentRepositoryException e) {
      logger.error("Error loading articles for feeds from {}: {}", site.getIdentifier(), e.getMessage());
      DispatchUtils.sendInternalError(request, response);
      return true;
    } catch (FeedException e) {
      logger.error("Error creating {} feed: {}", feedType, e.getMessage());
      DispatchUtils.sendInternalError(request, response);
View Full Code Here

    // we first have to load the page data, then get the associated renderer
    // bundle.
    try {
      Page page = null;
      ResourceURI pageURI = null;
      Site site = request.getSite();

      // Check if a page was passed as an attribute
      if (request.getAttribute(WebloungeRequest.PAGE) != null) {
        page = (Page) request.getAttribute(WebloungeRequest.PAGE);
        pageURI = page.getURI();
      }

      // Load the page from the content repository
      else {
        ContentRepository contentRepository = site.getContentRepository();
        if (contentRepository == null) {
          logger.debug("No content repository found for site '{}'", site);
          return false;
        } else if (contentRepository.isIndexing()) {
          logger.debug("Content repository of site '{}' is currently being indexed", site);
View Full Code Here

   * @return the target page
   */
  protected ResourceURI getPageURIForAction(Action action,
      WebloungeRequest request) {
    ResourceURI target = null;
    Site site = request.getSite();

    // Check if a target-page parameter was passed
    if (request.getParameter(HTMLAction.TARGET_PAGE) != null) {
      String targetUrl = request.getParameter(HTMLAction.TARGET_PAGE);
      try {
View Full Code Here

   * @throws IllegalStateException
   *           if the template cannot be found
   */
  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

  protected Page getTargetPage(WebloungeRequest request)
      throws ContentRepositoryException {

    ResourceURI target = null;
    Page page = null;
    Site site = request.getSite();
    boolean targetForced = false;

    // Check if a target-page parameter was passed
    String targetPage = request.getParameter(HTMLAction.TARGET_PAGE);
    if (targetPage != null) {
      targetForced = true;
      try {
        String decocedTargetUrl = null;
        String encoding = request.getCharacterEncoding();
        if (encoding == null)
          encoding = "utf-8";
        decocedTargetUrl = URLDecoder.decode(targetPage, encoding);
        target = new PageURIImpl(site, decocedTargetUrl);
      } catch (UnsupportedEncodingException e) {
        logger.warn("Error while decoding target url {}: {}", targetPage, e.getMessage());
        target = new PageURIImpl(site, "/");
      }
    }

    // Nothing found, let's choose the site's homepage
    if (target == null) {
      target = new PageURIImpl(site, "/");
    }

    // We are about to render the action output in the composers of the target
    // page. This is why we have to make sure that this target page exists,
    // otherwise the user will get a 404.
    ContentRepository contentRepository = site.getContentRepository();
    if (contentRepository == null) {
      logger.warn("Content repository not available to read target page {}", target);
      return null;
    }
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.