Package org.apache.wicket.request

Examples of org.apache.wicket.request.Url

The Url class takes care of encoding and decoding of the segments and parameters. @author Matej Knopp @author Igor Vaynberg

  }

  @Override
  public IRequestHandler mapRequest(Request request)
  {
    Url url = request.getUrl();

    if (canBeHandled(url))
    {
      final int segmentsSize = url.getSegments().size();

      // extract the PageParameters from URL if there are any
      PageParameters pageParameters = extractPageParameters(request, segmentsSize,
          pageParametersEncoder);

      String className = url.getSegments().get(2);
      StringBuilder name = new StringBuilder(segmentsSize * 2);

      for (int i = 3; i < segmentsSize; ++i)
      {
        String segment = url.getSegments().get(i);

        // ignore invalid segments
        if (segment.indexOf('/') > -1)
        {
          return null;
View Full Code Here


    if (requestHandler instanceof ResourceReferenceRequestHandler)
    {
      ResourceReferenceRequestHandler referenceRequestHandler = (ResourceReferenceRequestHandler)requestHandler;
      ResourceReference reference = referenceRequestHandler.getResourceReference();

      Url url;

      if (reference instanceof ResourceBundleReference)
      {
        // unwrap the bundle to render the url for the actual reference
        reference = ((ResourceBundleReference)reference).getBundleReference();
      }

      if (reference instanceof MetaInfStaticResourceReference)
      {
        url = ((MetaInfStaticResourceReference)reference).mapHandler(referenceRequestHandler);
        // if running on Servlet 3.0 engine url is not null
        if (url != null)
        {
          return url;
        }
        // otherwise it has to be served by the standard wicket way
      }
      else if (reference instanceof UrlResourceReference)
      {
        UrlResourceReference urlReference = (UrlResourceReference)reference;
        url = urlReference.getUrl();
        return url;
      }

      if (reference.canBeRegistered())
      {
        ResourceReferenceRegistry resourceReferenceRegistry = getContext().getResourceReferenceRegistry();
        resourceReferenceRegistry.registerResourceReference(reference);
      }

      url = new Url();

      List<String> segments = url.getSegments();
      segments.add(getContext().getNamespace());
      segments.add(getContext().getResourceIdentifier());
      segments.add(getClassName(reference.getScope()));

      // setup resource parameters
View Full Code Here

  }

  @Override
  public int getCompatibilityScore(Request request)
  {
    Url url = request.getUrl();

    int score = -1;
    if (canBeHandled(url))
    {
      score = 1;
View Full Code Here

    super.renderHead(component, response);

    CoreLibrariesContributor.contributeAjax(component.getApplication(), response);

    RequestCycle requestCycle = component.getRequestCycle();
    Url baseUrl = requestCycle.getUrlRenderer().getBaseUrl();
    CharSequence ajaxBaseUrl = Strings.escapeMarkup(baseUrl.toString());
    response.render(JavaScriptHeaderItem.forScript("Wicket.Ajax.baseUrl=\"" + ajaxBaseUrl +
      "\";", "wicket-ajax-base-url"));

    renderExtraHeaderContributors(component, response);
  }
View Full Code Here

  @Override
  public IRequestHandler mapRequest(Request request)
  {
    if (matches(request))
    {
      Url url = request.getUrl();
      PageComponentInfo info = getPageComponentInfo(url);
      if (info != null && info.getPageInfo().getPageId() != null)
      {
        Integer renderCount = info.getComponentInfo() != null ? info.getComponentInfo()
          .getRenderCount() : null;
View Full Code Here

      info = new PageComponentInfo(pageInfo, componentInfo);
    }

    if (info != null)
    {
      Url url = new Url();
      url.getSegments().add(getContext().getNamespace());
      url.getSegments().add(getContext().getPageIdentifier());
      encodePageComponentInfo(url, info);
      return url;
    }
    else
    {
View Full Code Here

   * @return {@code true} if the conditions match
   */
  private boolean matches(final Request request)
  {
    boolean matches = false;
    Url url = request.getUrl();
    Url baseUrl = request.getClientUrl();
    String namespace = getContext().getNamespace();
    String pageIdentifier = getContext().getPageIdentifier();

    if (urlStartsWith(url, namespace, pageIdentifier))
    {
View Full Code Here

    // buffered web response for page
    BufferedWebResponse response = new BufferedWebResponse(originalResponse);

    // keep the original base URL
    Url originalBaseUrl = requestCycle.getUrlRenderer().setBaseUrl(targetUrl);

    try
    {
      requestCycle.setResponse(response);
      requestablePage.renderPage();
View Full Code Here

   * TODO: simplify the code below. See WICKET-3347
   */
  @Override
  public void respond(RequestCycle requestCycle)
  {
    Url currentUrl = requestCycle.getUrlRenderer().getBaseUrl();
    Url targetUrl = requestCycle.mapUrlFor(getRenderPageRequestHandler());

    //
    // the code below is little hairy but we have to handle 3 redirect policies,
    // 3 rendering strategies and two kind of requests (ajax and normal)
    //

    // try to get an already rendered buffered response for current URL
    BufferedWebResponse bufferedResponse = getAndRemoveBufferedResponse(currentUrl);

    boolean isAjax = isAjax(requestCycle);

    boolean shouldPreserveClientUrl = ((WebRequest)requestCycle.getRequest()).shouldPreserveClientUrl();

    if (bufferedResponse != null)
    {
      logger.warn("The Buffered response should be handled by BufferedResponseRequestHandler");
      // if there is saved response for this URL render it
      bufferedResponse.writeTo((WebResponse)requestCycle.getResponse());
    }
    else if (getRedirectPolicy() == RedirectPolicy.NEVER_REDIRECT ||
      (isOnePassRender() && isAjax == false && getRedirectPolicy() != RedirectPolicy.ALWAYS_REDIRECT) //
      ||
      (!isAjax //
        &&
        (targetUrl.equals(currentUrl) && !getPageProvider().isNewPageInstance() && !getPage().isPageStateless()) //
      || (targetUrl.equals(currentUrl) && isRedirectToRender()) //
      ) //
      || shouldPreserveClientUrl) //
    {
      // if the policy is never to redirect
      // or one pass render mode is on
      // or the targetUrl matches current url and the page is not stateless
      // or the targetUrl matches current url, page is stateless but it's redirect-to-render
      // or the request determines that the current url should be preserved
      // just render the page
      BufferedWebResponse response = renderPage(currentUrl, requestCycle);
      if (response != null)
      {
        response.writeTo((WebResponse)requestCycle.getResponse());
      }
    }
    else if (getRedirectPolicy() == RedirectPolicy.ALWAYS_REDIRECT //
      ||
      isRedirectToRender() //
      || (isAjax && targetUrl.equals(currentUrl)))
    {
      // if target URL is different
      // and render policy is always-redirect or it's redirect-to-render
      redirectTo(targetUrl, requestCycle);
    }
    else if (!targetUrl.equals(currentUrl) //
      &&
      (getPageProvider().isNewPageInstance() || (isSessionTemporary() && getPage().isPageStateless())))
    {
      // if target URL is different and session is temporary and page is stateless
      // this is special case when page is stateless but there is no session so we can't
      // render it to buffer

      // alternatively if URLs are different and we have a page class and not an instance we
      // can redirect to the url which will instantiate the instance of us

      // note: if we had session here we would render the page to buffer and then redirect to
      // URL generated *after* page has been rendered (the statelessness may change during
      // render). this would save one redirect because now we have to render to URL generated
      // *before* page is rendered, render the page, get URL after render and if the URL is
      // different (meaning page is not stateless), save the buffer and redirect again (which
      // is pretty much what the next step does)
      redirectTo(targetUrl, requestCycle);
    }
    else
    {
      if (isRedirectToBuffer() == false && logger.isDebugEnabled())
      {
        String details = String.format(
          "redirect strategy: '%s', isAjax: '%s', redirect policy: '%s', "
            + "current url: '%s', target url: '%s', is new: '%s', is stateless: '%s', is temporary: '%s'",
          Application.get().getRequestCycleSettings().getRenderStrategy(), isAjax,
          getRedirectPolicy(), currentUrl, targetUrl,
          getPageProvider().isNewPageInstance(), getPage().isPageStateless(),
          isSessionTemporary());
        logger.debug("Falling back to Redirect_To_Buffer render strategy because none of the conditions " +
          "matched. Details: " + details);
      }

      // force creation of possible stateful page to get the final target url
      getPage();

      Url beforeRenderUrl = requestCycle.mapUrlFor(getRenderPageRequestHandler());

      // redirect to buffer
      BufferedWebResponse response = renderPage(beforeRenderUrl, requestCycle);

      if (response == null)
      {
        return;
      }

      // the url might have changed after page has been rendered (e.g. the
      // stateless flag might have changed because stateful components
      // were added)
      final Url afterRenderUrl = requestCycle.mapUrlFor(getRenderPageRequestHandler());

      if (beforeRenderUrl.getSegments().equals(afterRenderUrl.getSegments()) == false)
      {
        // the amount of segments is different - generated relative URLs
        // will not work, we need to rerender the page. This can happen
        // with IRequestHandlers that produce different URLs with
        // different amount of segments for stateless and stateful pages
View Full Code Here

   *
   */
  @Test
  public void decode1()
  {
    Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME);
    IRequestHandler handler = encoder.mapRequest(getRequest(url));

    assertTrue(handler instanceof RenderPageRequestHandler);
    IRequestablePage page = ((RenderPageRequestHandler)handler).getPage();
    assertEquals(PAGE_CLASS_NAME, page.getClass().getName());
View Full Code Here

TOP

Related Classes of org.apache.wicket.request.Url

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.