protected void writeDocument(PackageBodyOutput output)
throws IOException, ProtocolException {
MarinerRequestContext requestContext = context.getRequestContext();
ApplicationContext appContext =
ContextInternals.getApplicationContext(requestContext);
// If the accept headers indicate that WMLC is supported, create a
// WBXML producer. If not, default to WMLProducer.
WBSAXContentHandler handler = null;
WBSAXDocumentOutputter wbsaxOutputter;
WBSAXContentHandler producer;
// If the user has not asked to know the output style of this protocol,
// then we will not have calculated whether we will be generating WMLC.
// In this case we better generate it now as we are about to need it.
if (generateWMLC == null) {
calculateGenerateWMLC();
}
// Check that the outputs of calculateGenerateWMLC are available.
if (charsetCode == null || generateWMLC == null) {
throw new IllegalStateException(
"charsetCode and generateWMLC must be available");
}
EnvironmentContext envContext = context.getEnvironmentContext();
if (Boolean.TRUE.equals(generateWMLC)) {
// Generate binary WMLC.
envContext.setContentType("application/vnd.wap.wmlc");
producer = new WBXMLProducer(output.getOutputStream());
} else {
// For WML, the entity encoding is done now. The encoding writer
// is passed to the producer to do the encoding.
envContext.setContentType("text/vnd.wap.wml");
Writer out = output.getWriter();
Writer enc = new EncodingWriter(out, getCharacterEncoder());
producer = new WMLProducer(out, enc);
}
SerialisationURLListener urlListener = null;
final PackageResources pr = appContext.getPackageResources();
if (pr != null) {
// Force the packager to understand that only a subset of
// assets are likely to be included in the response
pr.initializeEncodedURLs();