// written to its body. Thus we first write the output into a
// StringResponse and if not empty, we copy it to the original
// web response.
// Temporarily replace the web response with a String response
final Response webResponse = getResponse();
try
{
final StringResponse response = new StringResponse();
getRequestCycle().setResponse(response);
IHeaderResponse headerResponse = getHeaderResponse();
if (!response.equals(headerResponse.getResponse()))
{
getRequestCycle().setResponse(headerResponse.getResponse());
}
// In any case, first render the header section directly associated
// with the markup
super.onComponentTagBody(markupStream, openTag);
// Render all header sections of all components on the page
renderHeaderSections(getPage(), this);
getHeaderResponse().close();
// Automatically add <head> if necessary
CharSequence output = response.getBuffer();
if (output.length() > 0)
{
if (output.charAt(0) == '\r')
{
for (int i = 2; i < output.length(); i += 2)
{
char ch = output.charAt(i);
if (ch != '\r')
{
output = output.subSequence(i - 2, output.length());
break;
}
}
}
else if (output.charAt(0) == '\n')
{
for (int i = 1; i < output.length(); i++)
{
char ch = output.charAt(i);
if (ch != '\n')
{
output = output.subSequence(i - 1, output.length());
break;
}
}
}
}
if (output.length() > 0)
{
if (renderOpenAndCloseTags())
{
webResponse.write("<head>");
}
webResponse.write(output);
if (renderOpenAndCloseTags())
{
webResponse.write("</head>");
}
}
}
finally
{