Examples of PrependingStringBuffer


Examples of org.apache.wicket.util.string.PrependingStringBuffer

  private static final Logger logger = LoggerFactory.getLogger(ServletWebRequest.class);

  @Override
  public String getPrefixToContextPath()
  {
    PrependingStringBuffer buffer = new PrependingStringBuffer();
    Url filterPrefixUrl = Url.parse(filterPrefix, getCharset());
    for (int i = 0; i < filterPrefixUrl.getSegments().size() - 1; ++i)
    {
      buffer.prepend("../");
    }
    return buffer.toString();
  }
View Full Code Here

Examples of org.apache.wicket.util.string.PrependingStringBuffer

   * @return form relative identification string
   */
  public static String getRootFormRelativeId(Component component)
  {
    String id = component.getId();
    final PrependingStringBuffer inputName = new PrependingStringBuffer(id.length());
    Component c = component;
    while (true)
    {
      inputName.prepend(id);
      c = c.getParent();
      if (c == null || (c instanceof Form<?> && ((Form<?>)c).isRootForm()) ||
        c instanceof Page)
      {
        break;
      }
      inputName.prepend(Component.PATH_SEPARATOR);
      id = c.getId();
    }

    /*
     * having input name "submit" causes problems with JavaScript, so we create a unique string
     * to replace it by prepending a path separator, as this identification can be assigned to
     * an submit form component name
     */
    if ("submit".equals(inputName.toString()))
    {
      inputName.prepend(Component.PATH_SEPARATOR);
    }
    return inputName.toString();
  }
View Full Code Here

Examples of org.apache.wicket.util.string.PrependingStringBuffer

      }
      else
      {
        // Add the actual URL. This will be relative to the Wicket
        // Servlet/Filter, with no leading '/'.
        PrependingStringBuffer prepender = new PrependingStringBuffer(url.toString());

        // Prepend prefix to the URL to make it relative to the current
        // request.
        prepender.prepend(requestCycle.getRequest().getRelativePathPrefixToWicketHandler());

        result = prepender.toString();
        // We need to special-case links to the home page if we're at the
        // same level.
        if (result.length() == 0)
        {
          result = "./";
View Full Code Here

Examples of org.apache.wicket.util.string.PrependingStringBuffer

      return relativePathPrefixToContextRoot = getHttpServletRequest().getContextPath() + "/";
    }

    // Prepend to get back to the wicket handler.
    String tmp = getRelativePathPrefixToWicketHandler();
    PrependingStringBuffer prepender = new PrependingStringBuffer(tmp);

    String path = WicketURLDecoder.PATH_INSTANCE.decode(getPath());

    if (path == null || path.length() == 0)
    {
      path = "";
    }

    // Now prepend to get back from the wicket handler to the root context.

    // Find the absolute path for the wicket filter/servlet
    String wicketPath = "";

    // We're running as a filter.
    // Note: do not call RequestUtils.decode() on getServletPath ... it is
    // already url-decoded (JIRA WICKET-1624)
    String servletPath = getServletPath();

    // We need to substitute the %3A (or the other way around) to be able to
    // get a good match, as parts of the path may have been escaped while
    // others arent
    if (servletPath.endsWith(path))
    {
      int len = servletPath.length() - path.length() - 1;
      if (len < 0)
      {
        len = 0;
      }
      wicketPath = servletPath.substring(0, len);
    }
    // We're running as a servlet
    else
    {
      wicketPath = servletPath;
    }

    for (int i = 0; i < wicketPath.length(); i++)
    {
      if (wicketPath.charAt(i) == '/')
      {
        prepender.prepend("../");
      }
    }
    return relativePathPrefixToContextRoot = prepender.toString();
  }
View Full Code Here

Examples of org.apache.wicket.util.string.PrependingStringBuffer

      return relativePathPrefixToWicketHandler;
    }

    boolean portletRequest = RequestContext.get().isPortletRequest();

    PrependingStringBuffer prepender = new PrependingStringBuffer();

    // For AJAX requests, we need to make the URLs relative to the
    // original page.
    if (!portletRequest && isAjax())
    {
      for (int i = 0; i < getRequestParameters().getUrlDepth(); i++)
      {
        prepender.prepend("../");
      }
      return relativePathPrefixToWicketHandler = prepender.toString();
    }

    String relativeUrl = getPath();

    /*
     * We might be serving an error page.
     *
     * In this case, the request will appear to be for something like "/ErrorPage", whereas the
     * URL in the user's browser will actually be something like
     * "/foo/page/where/the/error/actually/happened".
     *
     * We need to generate links and resource URLs relative to the URL in the browser window,
     * not the internal request for the error page.
     *
     * This original URL is available from request attributes, so we look in there and use that
     * for the relative path if it's available.
     */

    HttpServletRequest httpRequest = getHttpServletRequest();

    // This is in the Servlet 2.3 spec giving us the URI of the resource
    // that caused the error. Unfortunately, this includes the context path.
    String errorUrl = (String)httpRequest.getAttribute("javax.servlet.error.request_uri");

    // This gives us a context-relative path for RequestDispatcher.forward
    // stuff, with a leading slash.
    String forwardUrl = (String)httpRequest.getAttribute("javax.servlet.forward.servlet_path");

    if (forwardUrl != null && forwardUrl.length() > 0)
    {
      // If this is an error page, this will be /mount or /?wicket:foo
      relativeUrl = forwardUrl.substring(1);
    }
    else if (errorUrl != null)
    {
      // Strip off context path from front of URI.
      errorUrl = errorUrl.substring(httpRequest.getContextPath().length());

      String servletPath = httpRequest.getServletPath();
      if (!errorUrl.startsWith(servletPath))
      {
        prepender.prepend(servletPath.substring(1) + "/");
      }
      for (int i = servletPath.length() + 1; i < errorUrl.length(); i++)
      {
        if (errorUrl.charAt(i) == '?')
        {
          break;
        }
        if (errorUrl.charAt(i) == '/')
        {
          prepender.prepend("../");
        }
      }
      return relativePathPrefixToWicketHandler = prepender.toString();
    }
    else if (wicketRedirectUrl != null)
    {
      relativeUrl = wicketRedirectUrl;
    }

    int lastPathPos = -1;
    if (depthRelativeToWicketHandler == -1)
    {
      int depth = 0;
      int ajaxUrlDepth = isAjax() ? getRequestParameters().getUrlDepth() : -1;
      for (int i = 0; i < relativeUrl.length(); i++)
      {
        if (relativeUrl.charAt(i) == '?')
        {
          break;
        }
        if (relativeUrl.charAt(i) == '/')
        {
          depth++;
          lastPathPos = i;
          if (depth == ajaxUrlDepth)
          {
            return relativeUrl.substring(0, lastPathPos + 1);
          }
        }
      }
      depthRelativeToWicketHandler = depth;
    }

    if (portletRequest)
    {
      prepender.prepend("/");
      prepender.prepend(getHttpServletRequest().getServletPath());
      prepender.prepend(getHttpServletRequest().getContextPath());
    }
    else
    {
      for (int i = 0; i < depthRelativeToWicketHandler; i++)
      {
        prepender.prepend("../");
      }
    }

    return relativePathPrefixToWicketHandler = prepender.toString();
  }
View Full Code Here

Examples of org.apache.wicket.util.string.PrependingStringBuffer

   *
   * @return Colon separated path to this component in the component hierarchy
   */
  public final String getPath()
  {
    final PrependingStringBuffer buffer = new PrependingStringBuffer(32);
    for (Component c = this; c != null; c = c.getParent())
    {
      if (buffer.length() > 0)
      {
        buffer.prepend(PATH_SEPARATOR);
      }
      buffer.prepend(c.getId());
    }
    return buffer.toString();
  }
View Full Code Here

Examples of org.apache.wicket.util.string.PrependingStringBuffer

   */
  public String getInputName()
  {
    // TODO: keep this in sync with AbstractSubmitLink#getInputName
    String id = getId();
    final PrependingStringBuffer inputName = new PrependingStringBuffer(id.length());
    Component c = this;
    while (true)
    {
      inputName.prepend(id);
      c = c.getParent();
      if (c == null || (c instanceof Form && ((Form<?>)c).isRootForm()) || c instanceof Page)
      {
        break;
      }
      inputName.prepend(Component.PATH_SEPARATOR);
      id = c.getId();
    }

    // having input name "submit" causes problems with javascript, so we
    // create a unique string to replace it by prepending a path separator
    if (inputName.equals("submit"))
    {
      inputName.prepend(Component.PATH_SEPARATOR);
    }
    Form<?> form = findParent(Form.class);

    if (form != null)
    {
      return form.getInputNamePrefix() + inputName.toString();
    }
    else
    {
      return inputName.toString();
    }
  }
View Full Code Here

Examples of org.apache.wicket.util.string.PrependingStringBuffer

   *
   * @return Colon separated path to this component in the component hierarchy
   */
  public final String getPath()
  {
    final PrependingStringBuffer buffer = new PrependingStringBuffer(32);
    for (Component c = this; c != null; c = c.getParent())
    {
      if (buffer.length() > 0)
      {
        buffer.prepend(PATH_SEPARATOR);
      }
      buffer.prepend(c.getId());
    }
    return buffer.toString();
  }
View Full Code Here

Examples of org.apache.wicket.util.string.PrependingStringBuffer

    if (url.startsWith("/"))
    {
      url = url.substring(1);
    }

    PrependingStringBuffer buffer = new PrependingStringBuffer(url);
    for (int i = 0; i < getBaseUrl().getSegments().size() - 1; ++i)
    {
      buffer.prepend("../");
    }

    buffer.prepend(request.getPrefixToContextPath());

    return buffer.toString();
  }
View Full Code Here

Examples of org.apache.wicket.util.string.PrependingStringBuffer

  private static final Logger logger = LoggerFactory.getLogger(ServletWebRequest.class);

  @Override
  public String getPrefixToContextPath()
  {
    PrependingStringBuffer buffer = new PrependingStringBuffer();
    Url filterPrefixUrl = Url.parse(filterPrefix, getCharset());
    for (int i = 0; i < filterPrefixUrl.getSegments().size() - 1; ++i)
    {
      buffer.prepend("../");
    }
    return buffer.toString();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.