public void generate() throws SAXException {
final Request request = ObjectModelHelper.getRequest(objectModel);
final AttributesImpl attr = new AttributesImpl();
this.contentHandler.startDocument();
this.contentHandler.startPrefixMapping(PREFIX, URI);
attribute(attr, "target", request.getRequestURI());
attribute(attr, "sitemap", request.getSitemapURI());
attribute(attr, "source", (this.source != null ? this.source : ""));
start("request", attr);
start("requestHeaders", attr);
Enumeration headers = request.getHeaderNames();
if ( headers != null ) {
while (headers.hasMoreElements()) {
String header = (String)headers.nextElement();
attribute(attr, "name", header);
start("header", attr);
data(request.getHeader(header));
end("header");
}
}
end("requestHeaders");
start("requestParameters", attr);
Enumeration parameters = request.getParameterNames();
while (parameters.hasMoreElements()) {
String parameter = (String)parameters.nextElement();
attribute(attr, "name", parameter);
start("parameter", attr);
String values[] = request.getParameterValues(parameter);
if (values != null) {
for (int x = 0; x < values.length; x++) {
start("value", attr);
if (form_encoding != null) {
try {
data(values[x], container_encoding, form_encoding);
} catch (UnsupportedEncodingException uee) {
throw new CascadingRuntimeException("The suggested encoding is not supported.", uee);
}
} else if (parameter.startsWith("xml:")) {
try {
parse(values[x]);
} catch (Exception e) {
throw new CascadingRuntimeException("Could not parse the xml parameter", e);
}
} else {
data(values[x]);
}
end("value");
}
}
end("parameter");
}
end("requestParameters");
if (generate_attributes) {
start("requestAttributes", attr);
Enumeration attributes = request.getAttributeNames();
while (attributes.hasMoreElements()) {
String attribute = (String)attributes.nextElement();
attribute(attr, "name", attribute);
start("attribute", attr);
Object value = request.getAttribute(attribute);
if (value != null) {
start("value", attr);
XMLUtils.valueOf(this.contentHandler, value);
end("value");
}
end("attribute");
}
end("requestAttributes");
}
this.start("configurationParameters", attr);
String[] confparams = super.parameters.getNames();
for (int i = 0; i < confparams.length; i++) {
attribute(attr, "name", confparams[i]);
start("parameter", attr);
data(super.parameters.getParameter(confparams[i], ""));
end("parameter");
}
end("configurationParameters");
start("remoteUser", attr);
if (request.getRemoteUser() != null) {
data(request.getRemoteUser());
}
end("remoteUser");
end("request");
this.contentHandler.endPrefixMapping(PREFIX);
this.contentHandler.endDocument();
}
|