|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
The SitemapOutputComponents are responsible for taking the results of a
pipeline to the end user. Current examples are the Serializer and the
Reader. The Sitemap will terminate the pipeline when it encounters the
first instance of a SitemapOutputComponent
. Just like the
SitemapModelComponent
, all implementations of this contract
must be pooled for the same reasons. The sitemap will query the output
component for the mime type and whether the sitemap should set the content
length in the response. It will then provide the output component the
java.io.OutputStream
so you can send the bytes directly to the
user.
It should be noted that there is no way to access any of the request, response, or context objects within a component that just implements this interface like the Serializer. The idea is to keep things simple. All your response attributes should have been already set, and the only responsibility at this point in time is to give the user what he wants--the rendered object (page/image/etc.).
Method Summary | |
String |
getMimeType()
Obtain the media type for the results being serialized. |
void |
setOutputStream(OutputStream out)
Set the OutputStream where the requested resource should
be serialized. |
boolean |
shouldSetContentLength()
Test if the component needs the content length set. |
Method Detail |
public void setOutputStream(OutputStream out) throws IOException
OutputStream
where the requested resource should
be serialized.
out
- The OutputStream
target for the rendered results.
IOException
- if the stream can't be used.public String getMimeType()
Content-Type
header
in the response, unless it was overwritten in the sitemap.
It helps responsible browsers to identify how to show the
information to the user.
Example content type value: text/html; charset=utf-8
.
Warning:Microsoft Internet Explorer is a poor netizen and does not always respect this information. I am talking about Microsoft's InternetExplorer. It will first try to use the file extension of the resource to determine the mime type, and then if that fails it will fall back to respecting the mime type. For that reason it is essential that you also practice good netizen habits and make the file extension and the mime type agree. One example is the PDF document. In order for Microsoft to treat a result set as a PDF document you must have the url end with ".pdf" as well as set the mime type to "application/pdf". Internet Explorer will fail if you try to send the document "badhabit.xml?view=pdf" rendered as a PDF document. It is because the file extension ".xml" will be remapped to "text/xml" even if you set the mime type correctly.
You may have some incorrectly configured servers that will work for one browser and not the other because the mime-type and file extension do not agree. The world would be much simpler if all browsers blindly accepted the mime type. Just be aware of this issue when you are creating your sitemap and serializing your results.
public boolean shouldSetContentLength()
Most types of documents don't really care what the content length is, so it is usually safe to leave the results of this method to false. It should be noted that the Adobe Acrobat Reader plugin for Microsoft Internet Explorer has a bug that wasn't fixed until version 7. The bug prevents the PDF document from displaying correctly. It will look like an empty document or something similar. So the general rule of thumb for explicitly setting the content length is:
true
if the content length needs to be set.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |