public void respond(RequestCycle requestCycle)
{
Application application = requestCycle.getApplication();
SharedResources sharedResources = application.getSharedResources();
final String resourceKey = getRequestParameters().getResourceKey();
Resource resource = sharedResources.get(resourceKey);
// try to lazily register
if (resource == null)
{
int ix = resourceKey.indexOf('/');
if (ix != -1)
{
String className = resourceKey.substring(0, ix);
IClassResolver resolver = application.getApplicationSettings().getClassResolver();
Class scope = null;
try
{
// First try to match mounted resources.
scope = Application.get().getSharedResources().getAliasClass(className);
// If that fails, resolve it as a fully qualified class
// name.
if (scope == null)
{
scope = resolver.resolveClass(className);
}
// get path component of resource key, replace '..' with escape sequence to
// prevent crippled urls in browser
final CharSequence escapeString = application.getResourceSettings()
.getParentFolderPlaceholder();
String path = resourceKey.substring(ix + 1);
if (Strings.isEmpty(escapeString) == false)
{
path = Strings.replaceAll(path, escapeString, "..").toString();
}
if (PackageResource.exists(scope, path, null, null))
{
resource = PackageResource.get(scope, path);
}
}
catch (Exception e)
{
// besides logging, ignore exception; after this an error
// will be returned that the resource could not be retrieved
log.error("unable to lazily register shared resource " + resourceKey, e);
}
}
}
// if resource is still null, it doesn't exist
if (resource == null)
{
String msg = "shared resource " + resourceKey + " not found or not allowed access";
Response response = requestCycle.getResponse();
if (response instanceof WebResponse)
{
((WebResponse)response).getHttpServletResponse().setStatus(
HttpServletResponse.SC_NOT_FOUND);
log.error(msg);
return;
}
else
{
throw new WicketRuntimeException(msg);
}
}
// set request parameters if there are any
if (requestParameters != null)
{
resource.setParameters(requestParameters.getParameters());
}
// let the resource handle the request
resource.onResourceRequested();
}