*/
@Override
public void decorate(Element decoratorhtml, Element contenthead) {
// If the decorator has no HEAD, then we can just use the content HEAD
Element decoratorhead = findElement(decoratorhtml, HTML_ELEMENT_HEAD);
if (decoratorhead == null) {
if (contenthead != null) {
decoratorhtml.insertChild(0, new Text(LINE_SEPARATOR));
decoratorhtml.insertChild(1, contenthead);
Element contenttitle = findElement(contenthead, HTML_ELEMENT_TITLE);
if (contenttitle != null) {
Element resultingtitle = new Element(HTML_ELEMENT_TITLE);
extractTitle(contenthead, contenttitle, CONTENT_TITLE, resultingtitle);
contenthead.insertChild(0, new Text(LINE_SEPARATOR));
contenthead.insertChild(1, resultingtitle);
}
}
return;
}
// Merge the content and decorator titles into a single title element
Element decoratortitle = findElement(decoratorhead, HTML_ELEMENT_TITLE);
Element contenttitle = null;
if (contenthead != null) {
contenttitle = findElement(contenthead, HTML_ELEMENT_TITLE);
}
Element resultingtitle = null;
if (decoratortitle != null || contenttitle != null) {
resultingtitle = new Element(HTML_ELEMENT_TITLE);
if (decoratortitle != null) {
extractTitle(decoratorhead, decoratortitle, DECORATOR_TITLE, resultingtitle);
}
if (contenttitle != null) {
extractTitle(contenthead, contenttitle, CONTENT_TITLE, resultingtitle);