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;
}
}
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);
}
});
}
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);
}
});
}
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));
}
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));
}
Aggregations