Search in sources :

Example 16 with IResource

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

the class RequestCycle method renderUrl.

private String renderUrl(Url url, IRequestHandler handler) {
    if (url != null) {
        boolean shouldEncodeStaticResource = Application.exists() && Application.get().getResourceSettings().isEncodeJSessionId();
        String renderedUrl = getUrlRenderer().renderUrl(url);
        if (handler instanceof ResourceReferenceRequestHandler) {
            ResourceReferenceRequestHandler rrrh = (ResourceReferenceRequestHandler) handler;
            IResource resource = rrrh.getResource();
            if (resource != null && !(resource instanceof IStaticCacheableResource) || shouldEncodeStaticResource) {
                renderedUrl = getOriginalResponse().encodeURL(renderedUrl);
            }
        } else if (handler instanceof ResourceRequestHandler) {
            ResourceRequestHandler rrh = (ResourceRequestHandler) handler;
            IResource resource = rrh.getResource();
            if (resource != null && !(resource instanceof IStaticCacheableResource) || shouldEncodeStaticResource) {
                renderedUrl = getOriginalResponse().encodeURL(renderedUrl);
            }
        } else {
            renderedUrl = getOriginalResponse().encodeURL(renderedUrl);
        }
        return renderedUrl;
    } else {
        return null;
    }
}
Also used : IStaticCacheableResource(org.apache.wicket.request.resource.caching.IStaticCacheableResource) ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) ResourceRequestHandler(org.apache.wicket.request.handler.resource.ResourceRequestHandler) IResource(org.apache.wicket.request.resource.IResource)

Example 17 with IResource

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

the class AjaxDownloadPage method initDownloadInSameWindow.

private void initDownloadInSameWindow() {
    IResource resource = new ExampleResource("downloaded via ajax in same browser window").setContentDisposition(ContentDisposition.ATTACHMENT);
    final AjaxDownloadBehavior download = new AjaxDownloadBehavior(resource) {

        @Override
        protected void onBeforeDownload(AjaxRequestTarget target) {
            downloadingContainer.setVisible(true);
            target.add(downloadingContainer);
        }

        @Override
        protected void onDownloadSuccess(AjaxRequestTarget target) {
            downloadingContainer.setVisible(false);
            target.add(downloadingContainer);
        }

        @Override
        protected void onDownloadFailed(AjaxRequestTarget target) {
            downloadingContainer.setVisible(false);
            target.add(downloadingContainer);
            target.appendJavaScript("alert('Download failed');");
        }

        @Override
        protected void onDownloadCompleted(AjaxRequestTarget target) {
            downloadingContainer.setVisible(false);
            target.add(downloadingContainer);
        }
    };
    download.setLocation(AjaxDownloadBehavior.Location.SameWindow);
    add(download);
    add(new AjaxLink<Void>("downloadInSameWindow") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            download.initiate(target);
        }
    });
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IResource(org.apache.wicket.request.resource.IResource) AjaxDownloadBehavior(org.apache.wicket.extensions.ajax.AjaxDownloadBehavior)

Example 18 with IResource

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

the class AjaxDownloadPage method initDownloadInNewWindow.

private void initDownloadInNewWindow() {
    IResource resource = new ExampleResource("downloaded via ajax in a new browser window").setContentDisposition(ContentDisposition.INLINE);
    final AjaxDownloadBehavior download = new AjaxDownloadBehavior(resource) {

        @Override
        protected void onBeforeDownload(AjaxRequestTarget target) {
            downloadingContainer.setVisible(true);
            target.add(downloadingContainer);
        }

        @Override
        protected void onDownloadSuccess(AjaxRequestTarget target) {
            downloadingContainer.setVisible(false);
            target.add(downloadingContainer);
        }

        @Override
        protected void onDownloadFailed(AjaxRequestTarget target) {
            downloadingContainer.setVisible(false);
            target.add(downloadingContainer);
            target.appendJavaScript("alert('Download failed');");
        }

        @Override
        protected void onDownloadCompleted(AjaxRequestTarget target) {
            downloadingContainer.setVisible(false);
            target.add(downloadingContainer);
        }
    };
    download.setLocation(AjaxDownloadBehavior.Location.NewWindow);
    add(download);
    add(new AjaxLink<Void>("downloadInNewWindow") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            download.initiate(target);
        }
    });
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IResource(org.apache.wicket.request.resource.IResource) AjaxDownloadBehavior(org.apache.wicket.extensions.ajax.AjaxDownloadBehavior)

Example 19 with IResource

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

the class AnnotationsRoleAuthorizationStrategyTest method allowsResourceWithRequiredRole.

@Test
public void allowsResourceWithRequiredRole() throws Exception {
    AnnotationsRoleAuthorizationStrategy strategy = new AnnotationsRoleAuthorizationStrategy(roles("role1"));
    IResource resource = Mockito.mock(RestrictedResource.class);
    assertTrue(strategy.isResourceAuthorized(resource, null));
}
Also used : IResource(org.apache.wicket.request.resource.IResource) Test(org.junit.Test)

Example 20 with IResource

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

the class AnnotationsRoleAuthorizationStrategyTest method allowsUnprotectedResourceWithoutRole.

@Test
public void allowsUnprotectedResourceWithoutRole() throws Exception {
    AnnotationsRoleAuthorizationStrategy strategy = new AnnotationsRoleAuthorizationStrategy(roles());
    IResource resource = Mockito.mock(UnrestrictedResource.class);
    assertTrue(strategy.isResourceAuthorized(resource, null));
}
Also used : IResource(org.apache.wicket.request.resource.IResource) Test(org.junit.Test)

Aggregations

IResource (org.apache.wicket.request.resource.IResource)24 ResourceReference (org.apache.wicket.request.resource.ResourceReference)10 Test (org.junit.Test)7 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 AjaxDownloadBehavior (org.apache.wicket.extensions.ajax.AjaxDownloadBehavior)4 Application (org.apache.wicket.Application)3 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)3 IStaticCacheableResource (org.apache.wicket.request.resource.caching.IStaticCacheableResource)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 Page (org.apache.wicket.Page)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)2 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)2 ResourceUrl (org.apache.wicket.request.resource.caching.ResourceUrl)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BootstrapSettings (de.agilecoders.wicket.core.settings.BootstrapSettings)1 IBootstrapSettings (de.agilecoders.wicket.core.settings.IBootstrapSettings)1 SingleThemeProvider (de.agilecoders.wicket.core.settings.SingleThemeProvider)1