Package org.apache.wicket.request.handler.resource

Examples of org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler


  @Test
  public void resourceReference()
  {
    PackageResourceReference resource = new PackageResourceReference(getClass(),
      "crypt/crypt.txt");
    Url url = mapper.mapHandler(new ResourceReferenceRequestHandler(resource));

    Request request = getRequest(url);

    IRequestHandler requestHandler = mapper.mapRequest(request);

    assertTrue(requestHandler instanceof RequestSettingRequestHandler);
    requestHandler = ((RequestSettingRequestHandler)requestHandler).getDelegateHandler();
    assertTrue(requestHandler instanceof ResourceReferenceRequestHandler);
    ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler)requestHandler;

    assertEquals(getClass(), handler.getResourceReference().getScope());
    assertEquals("crypt/crypt.txt", handler.getResourceReference().getName());
  }
View Full Code Here


  @Test
  public void urlResourceReference()
  {
    UrlResourceReference resource = new UrlResourceReference(
      Url.parse("http://wicket.apache.org/"));
    Url url = mapper.mapHandler(new ResourceReferenceRequestHandler(resource));

    assertEquals("http://wicket.apache.org/", url.toString(StringMode.FULL));
  }
View Full Code Here

  @Test
  public void resourceReferenceWithModifiedSegments()
  {
    PackageResourceReference resource = new PackageResourceReference(getClass(),
      "crypt/crypt.txt");
    Url url = mapper.mapHandler(new ResourceReferenceRequestHandler(resource));
    url.getSegments().remove(url.getSegments().size() - 1);
    url.getSegments().add("modified-crypt.txt");

    Request request = getRequest(url);

    IRequestHandler requestHandler = mapper.mapRequest(request);

    assertTrue(requestHandler instanceof RequestSettingRequestHandler);
    requestHandler = ((RequestSettingRequestHandler)requestHandler).getDelegateHandler();
    assertTrue(requestHandler instanceof ResourceReferenceRequestHandler);
    ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler)requestHandler;

    assertEquals(getClass(), handler.getResourceReference().getScope());
    assertEquals("crypt/modified-crypt.txt", handler.getResourceReference().getName());
  }
View Full Code Here

  @Test
  public void resourceReferenceWithMoreSegments()
  {
    PackageResourceReference resource = new PackageResourceReference(getClass(),
      "crypt/crypt.txt");
    Url url = mapper.mapHandler(new ResourceReferenceRequestHandler(resource));
    url.getSegments().remove(url.getSegments().size() - 1);
    url.getSegments().add("more");
    url.getSegments().add("more-crypt.txt");

    Request request = getRequest(url);

    IRequestHandler requestHandler = mapper.mapRequest(request);

    assertTrue(requestHandler instanceof RequestSettingRequestHandler);
    requestHandler = ((RequestSettingRequestHandler)requestHandler).getDelegateHandler();
    assertTrue(requestHandler instanceof ResourceReferenceRequestHandler);
    ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler)requestHandler;

    assertEquals(getClass(), handler.getResourceReference().getScope());
    assertEquals("crypt/more/more-crypt.txt", handler.getResourceReference().getName());
  }
View Full Code Here

  @Test
  public void resourceReferenceWithLessSegments()
  {
    PackageResourceReference resource = new PackageResourceReference(getClass(),
      "crypt/crypt.txt");
    Url url = mapper.mapHandler(new ResourceReferenceRequestHandler(resource));
    url.getSegments().remove(url.getSegments().size() - 1);
    url.getSegments().remove(url.getSegments().size() - 1);
    url.getSegments().add("less-crypt.txt");

    Request request = getRequest(url);

    IRequestHandler requestHandler = mapper.mapRequest(request);

    assertTrue(requestHandler instanceof RequestSettingRequestHandler);
    requestHandler = ((RequestSettingRequestHandler)requestHandler).getDelegateHandler();
    assertTrue(requestHandler instanceof ResourceReferenceRequestHandler);
    ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler)requestHandler;

    assertEquals(getClass(), handler.getResourceReference().getScope());
    assertEquals("less-crypt.txt", handler.getResourceReference().getName());
  }
View Full Code Here

          parameters = new PageParameters();
        }
        parameters.add(placeholder, url.getSegments().get(index));
      }
    }
    return new ResourceReferenceRequestHandler(resourceReference, parameters);
  }
View Full Code Here

    if ((requestHandler instanceof ResourceReferenceRequestHandler) == false)
    {
      return null;
    }

    ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler)requestHandler;

    // see if request handler addresses the resource we serve
    if (resourceReference.equals(handler.getResourceReference()) == false &&
      resourceReference.getResource().equals(handler.getResource()) == false)
    {
      return null;
    }

    Url url = new Url();

    // add mount path segments
    for (String segment : mountSegments)
    {
      url.getSegments().add(segment);
    }

    // replace placeholder parameters
    PageParameters parameters = new PageParameters(handler.getPageParameters());

    for (int index = 0; index < mountSegments.length; ++index)
    {
      String placeholder = getPlaceholder(mountSegments[index]);
View Full Code Here

      // only set the href attribute when the resource exists
      if (resourceReference != null)
      {
        // Set href to link to this link's linkClicked method

        ResourceReferenceRequestHandler handler = new ResourceReferenceRequestHandler(
          resourceReference);
        CharSequence url = getRequestCycle().urlFor(handler);

        // generate the href attribute
        tag.put(attribute, url);
View Full Code Here

  public ResourceReference startResourceReference(final ResourceReference reference,
    final PageParameters pageParameters)
  {
    request = new MockHttpServletRequest(application, hsession, servletContext);
    request.setURL(request.getContextPath() + request.getServletPath() + "/");
    IRequestHandler handler = new ResourceReferenceRequestHandler(reference, pageParameters);
    processRequest(request, handler);
    return reference;
  }
View Full Code Here

   *            parameters for the resource or {@code null} if none
   * @return {@link Url} for the reference
   */
  public Url mapUrlFor(ResourceReference reference, PageParameters params)
  {
    return mapUrlFor(new ResourceReferenceRequestHandler(reference, params));
  }
View Full Code Here

TOP

Related Classes of org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler

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.