Package ch.entwine.weblounge.common.site

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


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

    WebUrl url = request.getUrl();
    Site site = request.getSite();
    String path = url.getPath();
    String fileName = null;

    // Get hold of the content repository
    ContentRepository contentRepository = site.getContentRepository();
    if (contentRepository == null) {
      logger.warn("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


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

    WebUrl url = request.getUrl();
    Site site = request.getSite();
    String path = url.getPath();
    String fileName = null;

    // Get hold of the content repository
    ContentRepository contentRepository = site.getContentRepository();
    if (contentRepository == null) {
      logger.warn("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

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

    WebUrl url = request.getUrl();
    Site site = request.getSite();
    String path = url.getPath();
    String fileName = null;

    // This request handler can only be used with the prefix
    if (!path.startsWith(URI_PREFIX))
      return false;

    // Get hold of the content repository
    ContentRepository contentRepository = site.getContentRepository();
    if (contentRepository == null) {
      logger.warn("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

   *
   * @see ch.entwine.weblounge.dispatcher.RequestHandler#service(ch.entwine.weblounge.common.request.WebloungeRequest,
   *      ch.entwine.weblounge.common.request.WebloungeResponse)
   */
  public boolean service(WebloungeRequest request, WebloungeResponse response) {
    Site site = request.getSite();
    WebUrl url = request.getUrl();
    RequestFlavor flavor = request.getFlavor();
    String path = url.getPath();

    if (flavor == null || flavor.equals(ANY))
      flavor = RequestFlavor.HTML;

    // Is this request intended for the search handler?
    if (!path.startsWith(URI_PREFIX)) {
      logger.debug("Skipping request for {}, request path does not start with {}", URI_PREFIX);
      return false;
    }

    // Check the request flavor
    if (!HTML.equals(flavor)) {
      logger.debug("Skipping request for {}, flavor {} is not supported", path, request.getFlavor());
      return false;
    }

    // Check the request method. Only GET is supported right now.
    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("Search request handler does not support {} requests", requestMethod);
      DispatchUtils.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, request, response);
      return true;
    }

    int limit = 0;
    int offset = 0;
    String queryString = null;

    // Read the parameters
    try {
      limit = RequestUtils.getIntegerParameterWithDefault(request, PARAM_LIMIT, 0);
      offset = RequestUtils.getIntegerParameterWithDefault(request, PARAM_OFFSET, 0);
      queryString = RequestUtils.getRequiredParameter(request, PARAM_QUERY);
    } catch (IllegalStateException e) {
      logger.debug("Search request handler processing failed: {}", e.getMessage());
      DispatchUtils.sendBadRequest(request, response);
      return true;
    }

    // Load the content repository
    ContentRepository repository = site.getContentRepository();
    if (repository == null) {
      DispatchUtils.sendServiceUnavailable(request, response);
      return true;
    }

    // Create the search expression and the query
    SearchQuery q = new SearchQueryImpl(site);
    q.withText(true, queryString);
    q.withVersion(Resource.LIVE);
    q.withRececyPriority();
    q.withOffset(offset);
    q.withLimit(limit);
    q.withTypes(Page.TYPE);

    // Return the result
    SearchResult result = null;
    try {
      result = repository.find(q);
    } catch (ContentRepositoryException e) {
      logger.error("Error trying to access the content repository", e);
      throw new WebApplicationException(e);
    }

    // Load the target page used to render the search result
    Page page = null;
    try {
      page = getTargetPage(request);
      request.setAttribute(WebloungeRequest.PAGE, page);
    } catch (ContentRepositoryException e) {
      logger.error("Error loading target page at {}", url);
      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;
    }
View Full Code Here

   *           if the template cannot be found
   */
  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?
View Full Code Here

   */
  private void serveHTML(Action action, WebloungeRequest request,
      WebloungeResponse response) {

    WebUrl url = request.getUrl();
    Site site = request.getSite();

    // Load the target page used to render the action
    Page page = null;
    try {
      page = getTargetPage(action, request);
      request.setAttribute(WebloungeRequest.PAGE, page);
      // TODO: Check access rights with action configuration
    } catch (ContentRepositoryException e) {
      logger.error("Error loading target page for action {} at {}", action, url);
      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) {
      logger.warn(e.getMessage());
      DispatchUtils.sendInternalError(request, response);
    }

View Full Code Here

   *           if the template cannot be found
   */
  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?
View Full Code Here

  protected Page getTargetPage(Action action, 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, "/");
      }
    }

    // Check the action configuration
    else if (action instanceof HTMLAction) {
      HTMLAction htmlAction = (HTMLAction) action;
      if (htmlAction.getPageURI() != null) {
        target = htmlAction.getPageURI();
        targetForced = true;
      }
    }

    // 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 for action '{}'", action, target);
      return null;
    }
View Full Code Here

   *           if an error occurs while rendering
   */
  protected void includeJSP(WebloungeRequest request,
      WebloungeResponse response, URL renderer) throws RenderException {

    Site site = request.getSite();
    Language language = request.getLanguage();
    File jsp = null;

    try {
      if ("file".equals(renderer.getProtocol())) {
        // Find the best match for the template
        String[] filePaths = LanguageUtils.getLanguageVariants(renderer.toExternalForm(), language, site.getDefaultLanguage());
        for (String path : filePaths) {
          logger.trace("Looking for jsp {}", path);
          File f = new File(path);
          if (f.exists()) {
            logger.debug("Found jsp at {}", path);
            jsp = f;
            break;
          }
        }

        // Did we find a suitable JSP?
        if (jsp == null) {
          response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
          throw new RenderException(this, "No suitable java server page found for " + renderer + " and language '" + language.getIdentifier() + "'");
        }

        // Check readability
        if (!jsp.canRead()) {
          response.sendError(HttpServletResponse.SC_FORBIDDEN);
          throw new RenderException(this, "Java server page at " + jsp + " cannot be read");
        }

        // No directory listings allowed
        if (!jsp.isFile()) {
          response.sendError(HttpServletResponse.SC_FORBIDDEN);
          throw new RenderException(this, "Java server page at " + jsp + " is not a file");
        }

        renderer = jsp.toURI().toURL();
      }

      // Prepare a request to site resources
      String servletPath = "/weblounge-sites/" + site.getIdentifier();
      String requestPath = renderer.getPath();
      requestPath = requestPath.substring(servletPath.length());
      requestPath = UrlUtils.concat(Site.BUNDLE_PATH, requestPath);
      SiteRequestWrapper siteRequest = new SiteRequestWrapper(request, requestPath, false);

View Full Code Here

    if (request instanceof HttpServletRequest) {
      HttpServletRequest httpRequest = (HttpServletRequest) request;
      if (HEALTHCHECK_URI.equals(httpRequest.getRequestURI())) {
        Iterator<Site> si = sites.sites();
        while (si.hasNext()) {
          Site site = si.next();
          if (!site.isOnline()) {
            logger.trace("Site {} is marked as offline", site.getIdentifier());
            logger.trace("Reporting bad health to {}", httpRequest.getRemoteHost());
            ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_CONFLICT);
            return;
          }
        }
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.