Search in sources :

Example 16 with ResourceReference

use of org.apache.wicket.request.resource.ResourceReference in project wicket by apache.

the class UrlResourceReferenceMapper method mapHandler.

@Override
public Url mapHandler(IRequestHandler requestHandler) {
    Url url = null;
    if (requestHandler instanceof ResourceReferenceRequestHandler) {
        ResourceReferenceRequestHandler resourceReferenceRequestHandler = (ResourceReferenceRequestHandler) requestHandler;
        ResourceReference resourceReference = resourceReferenceRequestHandler.getResourceReference();
        while (resourceReference instanceof ResourceBundleReference) {
            // unwrap the bundle to render the url for the actual reference
            resourceReference = ((ResourceBundleReference) resourceReference).getBundleReference();
        }
        if (resourceReference instanceof UrlResourceReference) {
            UrlResourceReference urlResourceReference = (UrlResourceReference) resourceReference;
            url = urlResourceReference.getUrl();
        }
    }
    return url;
}
Also used : ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) UrlResourceReference(org.apache.wicket.request.resource.UrlResourceReference) ResourceBundleReference(org.apache.wicket.resource.bundles.ResourceBundleReference) UrlResourceReference(org.apache.wicket.request.resource.UrlResourceReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference) Url(org.apache.wicket.request.Url)

Example 17 with ResourceReference

use of org.apache.wicket.request.resource.ResourceReference in project wicket by apache.

the class HeaderResponseTest method before.

/**
 * Prepare
 */
@Before
public void before() {
    final Response realResponse = new StringResponse();
    headerResponse = new HeaderResponse() {

        @Override
        protected Response getRealResponse() {
            return realResponse;
        }
    };
    reference = new ResourceReference("testReference") {

        private static final long serialVersionUID = 1L;

        @Override
        public IResource getResource() {
            return null;
        }
    };
    RequestCycle requestCycle = mock(RequestCycle.class);
    when(requestCycle.urlFor(any(IRequestHandler.class))).thenReturn(RESOURCE_NAME);
    when(requestCycle.find(any())).thenReturn(Optional.empty());
    Request request = mock(Request.class);
    when(request.getCharset()).thenReturn(Charset.defaultCharset());
    when(requestCycle.getRequest()).thenReturn(request);
    UrlRenderer urlRenderer = mock(UrlRenderer.class);
    when(urlRenderer.renderContextRelativeUrl((any(String.class)))).thenReturn(RESOURCE_NAME);
    when(requestCycle.getUrlRenderer()).thenReturn(urlRenderer);
    ThreadContext.setRequestCycle(requestCycle);
}
Also used : HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) StringResponse(org.apache.wicket.response.StringResponse) Response(org.apache.wicket.request.Response) HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) IRequestHandler(org.apache.wicket.request.IRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) Request(org.apache.wicket.request.Request) StringResponse(org.apache.wicket.response.StringResponse) ResourceReference(org.apache.wicket.request.resource.ResourceReference) UrlRenderer(org.apache.wicket.request.UrlRenderer) IResource(org.apache.wicket.request.resource.IResource) Before(org.junit.Before)

Example 18 with ResourceReference

use of org.apache.wicket.request.resource.ResourceReference in project wicket by apache.

the class RequestCycleUrlForTest method urlForResourceReference.

/**
 * ResourceReference with IStaticCacheableResource should not have the jsessionid encoded in the url
 *
 * @throws Exception
 */
@Test
public void urlForResourceReference() throws Exception {
    final IStaticCacheableResource resource = mock(IStaticCacheableResource.class);
    ResourceReference reference = new ResourceReference("dummy") {

        @Override
        public IResource getResource() {
            return resource;
        }
    };
    ResourceReferenceRequestHandler handler = new ResourceReferenceRequestHandler(reference);
    CharSequence url = requestCycle.urlFor(handler);
    assertEquals("./" + RES_REF_URL, url);
}
Also used : IStaticCacheableResource(org.apache.wicket.request.resource.caching.IStaticCacheableResource) ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) ResourceReference(org.apache.wicket.request.resource.ResourceReference) Test(org.junit.Test)

Example 19 with ResourceReference

use of org.apache.wicket.request.resource.ResourceReference in project wicket by apache.

the class ContextRelativeResourceCachingTest method init.

private void init(ContextRelativeResource resource, String mountPath) {
    final IResourceVersion resourceVersion = new StaticResourceVersion("123");
    final IResourceCachingStrategy strategy = new FilenameWithVersionResourceCachingStrategy("-version-", resourceVersion);
    tester.getApplication().getSharedResources().add(SHARED_NAME, resource);
    tester.getApplication().getResourceSettings().setCachingStrategy(strategy);
    final ResourceReference resourceReference = new SharedResourceReference(SHARED_NAME);
    tester.getApplication().mountResource(mountPath, resourceReference);
}
Also used : SharedResourceReference(org.apache.wicket.request.resource.SharedResourceReference) StaticResourceVersion(org.apache.wicket.request.resource.caching.version.StaticResourceVersion) IResourceVersion(org.apache.wicket.request.resource.caching.version.IResourceVersion) SharedResourceReference(org.apache.wicket.request.resource.SharedResourceReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference)

Example 20 with ResourceReference

use of org.apache.wicket.request.resource.ResourceReference in project webanno by webanno.

the class ActionBarLink method onBeforeRender.

@Override
protected void onBeforeRender() {
    // the embedding component/page
    if (!hasBeenRendered()) {
        ResourceReference _imageRes = imageRes;
        if (_imageRes == null) {
            _imageRes = new UrlResourceReference(Url.parse(getString("icon"))).setContextRelative(true);
        }
        Image image = new Image("image", _imageRes);
        try {
            // The getString method throws an MissingResourceException if the property is
            // not available. In this case, we simply do not set a tooltip
            getString("tooltip");
            image.add(new AttributeModifier("title", new StringResourceModel("tooltip", ActionBarLink.this)));
        } catch (MissingResourceException e) {
        // Nothing to do
        }
        link.add(image);
    }
    super.onBeforeRender();
}
Also used : UrlResourceReference(org.apache.wicket.request.resource.UrlResourceReference) MissingResourceException(java.util.MissingResourceException) UrlResourceReference(org.apache.wicket.request.resource.UrlResourceReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference) Image(org.apache.wicket.markup.html.image.Image) AttributeModifier(org.apache.wicket.AttributeModifier) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Aggregations

ResourceReference (org.apache.wicket.request.resource.ResourceReference)46 IResource (org.apache.wicket.request.resource.IResource)10 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)8 SharedResourceReference (org.apache.wicket.request.resource.SharedResourceReference)7 Test (org.junit.Test)7 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)6 HeaderItem (org.apache.wicket.markup.head.HeaderItem)5 Url (org.apache.wicket.request.Url)5 JavaScriptResourceReference (org.apache.wicket.request.resource.JavaScriptResourceReference)5 JavaScriptLibrarySettings (org.apache.wicket.settings.JavaScriptLibrarySettings)5 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)4 Page (org.apache.wicket.Page)3 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)3 JavaScriptHeaderItem (org.apache.wicket.markup.head.JavaScriptHeaderItem)3 Image (org.apache.wicket.markup.html.image.Image)3 Properties (java.util.Properties)2 Application (org.apache.wicket.Application)2 StringResourceModel (org.apache.wicket.model.StringResourceModel)2 ByteArrayResource (org.apache.wicket.request.resource.ByteArrayResource)2 CssResourceReference (org.apache.wicket.request.resource.CssResourceReference)2