in extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/jsf/resources/deprecated/ResourceHandlerImpl.java [254:381]
public void handleResourceRequest(FacesContext facesContext) throws IOException
{
//try
//{
String resourceBasePath = getResourceHandlerSupport()
.calculateResourceBasePath(facesContext);
if (resourceBasePath == null)
{
// No base name could be calculated, so no further
//advance could be done here. HttpServletResponse.SC_NOT_FOUND
//cannot be returned since we cannot extract the
//resource base name
return;
}
// We neet to get an instance of HttpServletResponse, but sometimes
// the response object is wrapped by several instances of
// ServletResponseWrapper (like ResponseSwitch).
// Since we are handling a resource, we can expect to get an
// HttpServletResponse.
Object response = facesContext.getExternalContext().getResponse();
//TODO merge the servlet response determination in
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
if (httpServletResponse == null)
{
throw new IllegalStateException("Could not obtain an instance of HttpServletResponse.");
}
if (isResourceIdentifierExcluded(facesContext, resourceBasePath))
{
httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
String resourceName = null;
if (resourceBasePath.startsWith(ResourceHandler.RESOURCE_IDENTIFIER))
{
resourceName = resourceBasePath
.substring(ResourceHandler.RESOURCE_IDENTIFIER.length() + 1);
}
else
{
//Does not have the conditions for be a resource call
httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
String libraryName = facesContext.getExternalContext()
.getRequestParameterMap().get("ln");
Resource resource = null;
if (libraryName != null)
{
//log.info("libraryName=" + libraryName);
resource = facesContext.getApplication().getResourceHandler().createResource(resourceName, libraryName);
}
else
{
resource = facesContext.getApplication().getResourceHandler().createResource(resourceName);
}
if (resource == null)
{
httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
if (!resource.userAgentNeedsUpdate(facesContext))
{
httpServletResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
httpServletResponse.setContentType(resource.getContentType());
Map<String, String> headers = resource.getResponseHeaders();
for (Map.Entry<String, String> entry : headers.entrySet())
{
httpServletResponse.setHeader(entry.getKey(), entry.getValue());
}
//serve up the bytes (taken from trinidad ResourceServlet)
try
{
InputStream in = resource.getInputStream();
OutputStream out = httpServletResponse.getOutputStream();
byte[] buffer = new byte[_BUFFER_SIZE];
try
{
int count = pipeBytes(in, out, buffer);
//set the content lenght
httpServletResponse.setContentLength(count);
}
finally
{
try
{
in.close();
}
finally
{
out.close();
}
}
}
catch (IOException e)
{
//TODO: Log using a localized message (which one?)
if (log.isLoggable(Level.SEVERE))
log.severe("Error trying to load resource " + resourceName
+ " with library " + libraryName + " :"
+ e.getMessage());
httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
// }
// catch (Throwable ex)
// {
// handle the Throwable accordingly. Maybe generate an error page.
// FIXME we are creating a html error page for a non html request here
// shouln't we do something better? -=Jakob Korherr=-
//ErrorPageWriter.handleThrowable(facesContext, ex);
// throw new FacesException(ex);
// }
}