_scriptBlock.append("\n");
}
public void updateDocument(Document document)
{
Element root = document.getRootElement();
// This can happen due to a catastrophic rendering error, such as a missing page template.
if (root == null) return;
// This only applies when the document is an HTML document. This may need to change in the
// future, perhaps configurable, to allow for html and xhtml and perhaps others. Does SVG
// use stylesheets?
if (!root.getName().equals("html")) return;
int stylesheets = _includedStylesheets.size();
if (stylesheets > 0)
{
Element head = root.find("head");
if (head == null) head = root.elementAt(0, "head");
for (int i = 0; i < stylesheets; i++)
_includedStylesheets.get(i).add(head, i);
}
Element body = root.find("body");
if (body == null) return;
for (int i = 0; i < _scripts.size(); i++)
{
String scriptURL = _scripts.get(i);
body.elementAt(i, "script", "src", scriptURL, "type", "text/javascript");
}
if (_scriptBlock.length() > 0)
{
Element e = body.element("script", "type", "text/javascript");
e.raw("\n<!--\n");
// This assumes that Prototype and tapestry.js is available.
e.text("Tapestry.onDOMLoaded(function() {\n");
e.text(_scriptBlock.toString());
e.text("});\n");
e.raw("// -->\n");
}
}