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