Package ch.entwine.weblounge.common.site

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


    Site site = request.getSite();
    ComposerImpl composer = new ComposerImpl(id);
    JspWriter writer = pageContext.getOut();

    Action action = (Action) request.getAttribute(WebloungeRequest.ACTION);

    try {

      // Flush all input that has been written to the response so far.
      writer.flush();
View Full Code Here


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

    Action action = (Action) request.getAttribute(WebloungeRequest.ACTION);

    PageletRenderer renderer = null;

    try {
View Full Code Here

   *
   * @see org.apache.commons.pool.impl.GenericObjectPool#borrowObject()
   */
  @Override
  public Action borrowObject() throws Exception {
    Action action = super.borrowObject();
    logger.debug("Received request to borrow action '{}', {} remaining", action.getIdentifier(), this.getNumIdle());

    if (getNumActive() > reportedLimit + 10) {
      reportedLimit += 10;
      logger.debug("Action pool '{}' grew above {}", new Object[] {
          action,
View Full Code Here

   *
   * @see org.apache.commons.pool.impl.GenericObjectPool#invalidateObject(java.lang.Object)
   */
  @Override
  public void invalidateObject(Action obj) throws Exception {
    Action action = super.borrowObject();
    logger.debug("Invalidating action '{}'", action.getIdentifier());
    super.invalidateObject(obj);
  }
View Full Code Here

   */
  @Override
  public Action makeObject() throws Exception {
    logger.debug("Creating new action '{}'", blueprint.getIdentifier());
   
    Action action = blueprint.getClass().newInstance();
   
    // Module
    action.setModule(blueprint.getModule());
   
    // Site
    action.setSite(blueprint.getSite());

    // Identifier
    action.setIdentifier(blueprint.getIdentifier());

    // Path
    action.setPath(blueprint.getPath());

    // Includes
    for (HTMLHeadElement header : blueprint.getHTMLHeaders()) {
      action.addHTMLHeader(header);
    }

    // Options
    for (Map.Entry<String, Map<Environment, List<String>>> option : blueprint.getOptions().entrySet()) {
      for (Environment environment : option.getValue().keySet()) {
        List<String> values = option.getValue().get(environment);
        for (String value : values) {
          action.setOption(option.getKey(), value, environment);
        }
      }
    }
   
    // Recheck time
    action.setClientRevalidationTime(blueprint.getClientRevalidationTime());

    // Valid time
    action.setCacheExpirationTime(blueprint.getCacheExpirationTime());

    // Are we looking at an html action?
    if (blueprint instanceof HTMLAction) {
      HTMLAction htmlBlueprint = (HTMLAction)blueprint;
      HTMLAction htmlAction = (HTMLAction)action;

      // Page URI
      if (htmlBlueprint.getPageURI() != null) {
        ResourceURI uri = htmlBlueprint.getPageURI();
        htmlAction.setPageURI(new PageURIImpl(uri.getSite(), uri.getPath()));
      }

      // Default page template
      htmlAction.setDefaultTemplate(htmlBlueprint.getDefaultTemplate());
    }
   
    // Name
    action.setName(blueprint.getName());

    return action;
  }
View Full Code Here

   * Does the tag processing.
   *
   * @see javax.servlet.jsp.tagext.Tag#doEndTag()
   */
  public int doEndTag() throws JspException {
    Action action = (Action) request.getAttribute(WebloungeRequest.ACTION);
    if (action != null) {
      if (isRefreshEnabled(action)) {
        try {
          String tag = "<meta http-equiv=\"refresh\" content=\"" + getRefreshPeriod(action) + "\">";
          pageContext.getOut().print(tag);
View Full Code Here

    String identifier = XPathHelper.valueOf(config, "@id", xpath);
    if (identifier == null)
      throw new IllegalStateException("Unable to create actions without identifier");

    // class
    Action action = null;
    String className = XPathHelper.valueOf(config, "m:class", xpath);
    if (className != null) {
      try {
        Class<? extends Action> c = (Class<? extends Action>) classLoader.loadClass(className);
        action = c.newInstance();
        action.setIdentifier(identifier);
      } catch (ClassNotFoundException e) {
        throw new IllegalStateException("Implementation " + className + " for action handler '" + identifier + "' not found", e);
      } catch (InstantiationException e) {
        throw new IllegalStateException("Error instantiating impelementation " + className + " for action handler '" + identifier + "'", e);
      } catch (IllegalAccessException e) {
        throw new IllegalStateException("Access violation instantiating implementation " + className + " for action handler '" + identifier + "'", e);
      } catch (Throwable t) {
        throw new IllegalStateException("Error loading implementation " + className + " for action handler '" + identifier + "'", t);
      }
    } else {
      action = new HTMLActionSupport();
      action.setIdentifier(identifier);
    }

    // mountpoint
    String mountpoint = XPathHelper.valueOf(config, "m:mountpoint", xpath);
    if (mountpoint == null)
      throw new IllegalStateException("Action '" + identifier + " has no mountpoint");
    action.setPath(mountpoint);
    // TODO: handle /, /*

    // content url
    String targetUrl = XPathHelper.valueOf(config, "m:page", xpath);
    if (StringUtils.isNotBlank(targetUrl)) {
      if (!(action instanceof HTMLActionSupport))
        throw new IllegalStateException("Target page configuration for '" + action.getIdentifier() + "' requires subclassing HTMLActionSupport");
      ((HTMLActionSupport) action).setPageURI(targetUrl);
    }

    // template
    String targetTemplate = XPathHelper.valueOf(config, "m:template", xpath);
    if (StringUtils.isNotBlank(targetTemplate)) {
      if (!(action instanceof HTMLActionSupport))
        throw new IllegalStateException("Target template configuration for '" + action.getIdentifier() + "' requires subclassing HTMLActionSupport");
      ((HTMLActionSupport) action).setDefaultTemplate(targetTemplate);
    }

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

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

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

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

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

    // options
    Node optionsNode = XPathHelper.select(config, "m:options", xpath);
    OptionsHelper.fromXml(optionsNode, action, xpath);

View Full Code Here

    // Determine the editing state
    boolean isEditing = RequestUtils.isEditingState(request);

    // Check if the request is controlled by an action.
    Action action = (Action) request.getAttribute(WebloungeRequest.ACTION);

    // Get the renderer id that has been registered with the url. For this,
    // we first have to load the page data, then get the associated renderer
    // bundle.
    try {
View Full Code Here

      logger.debug("No action found to handle {}", url);
      return false;
    }

    // Match! Let's try to get an actual action from that pool
    Action action = null;
    try {
      action = (Action) pool.borrowObject();
    } catch (Throwable t) {
      logger.error("Error getting action from action pool", t);
      DispatchUtils.sendInternalError(request, response);
      return true;
    }

    // Make sure the action is returned to the pool no matter what
    try {

      // Check the request method. We won't handle just everything
      String requestMethod = request.getMethod().toUpperCase();
      if (!action.supportsMethod(requestMethod)) {
        if ("OPTIONS".equals(requestMethod)) {
          StringBuffer verbs = new StringBuffer();
          for (String verb : action.getMethods()) {
            if (verbs.length() > 0)
              verbs.append(",");
            verbs.append(verb);
          }
          logger.trace("Answering options request to {} with {}", action, verbs.toString());
          response.setHeader("Allow", verbs.toString());
          response.setContentLength(0);
          return true;
        } else {
          logger.debug("Action {} does not support {} requests", action, requestMethod);
          DispatchUtils.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, request, response);
          return true;
        }
      }

      // 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 && request.getVersion() == Resource.LIVE) {
        long expirationTime = action.getCacheExpirationTime();
        long revalidationTime = action.getClientRevalidationTime();

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

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

        processingMode = Mode.Cached;
      } else if (Http11Constants.METHOD_HEAD.equals(request.getMethod())) {
        // handle HEAD requests
        Http11Utils.startHeadResponse(response);
        processingMode = Mode.Head;
      } else if (request.getVersion() == Resource.WORK) {
        response.setCacheExpirationTime(0);
      }

      logger.debug("Action {} will handle {}", action, url);

      // Call the service method depending on the flavor
      switch (flavor) {
        case HTML:
          if (!action.supportsFlavor(flavor) && !(action instanceof HTMLAction))
            return false;
          serveHTML(action, request, response);
          break;
        case XML:
          if (!action.supportsFlavor(flavor) && !(action instanceof XMLAction))
            return false;
          serveXML(action, request, response);
          break;
        case JSON:
          if (!action.supportsFlavor(flavor) && !(action instanceof JSONAction))
            return false;
          serveJSON(action, request, response);
          break;
        default:
          if (action.supportsFlavor(RequestFlavor.HTML) || action instanceof HTMLAction)
            serveHTML(action, request, response);
          else if (action.supportsFlavor(RequestFlavor.XML) || action instanceof XMLAction)
            serveXML(action, request, response);
          else if (action.supportsFlavor(RequestFlavor.JSON) || action instanceof JSONAction)
            serveJSON(action, request, response);
          else
            serveGeneric(action, request, response);
      }
View Full Code Here

    // Add tag attributes
    for (Map.Entry<String, String> attribute : getStandardAttributes().entrySet()) {
      a.append(" ").append(attribute.getKey()).append("=\"").append(attribute.getValue()).append("\"");
    }

    Action action = module.getAction(actionId);
    if (action == null) {
      String msg = "Action '" + actionId + "' could not be found!";
      throw new JspException(msg);
    }

    a.append(" action=\"" + action.getPath() + "\">");

    try {
      pageContext.getOut().write(a.toString());
    } catch (IOException e) {
      throw new JspException(e);
View Full Code Here

TOP

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

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.