final String pageHeader,
final String pageFooter)
{
final MasterPageFactoryKey key =
new MasterPageFactoryKey(template, pageHeader, pageFooter);
final OfficeMasterPage cached = (OfficeMasterPage) masterPages.get(key);
if (cached != null)
{
return cached;
}
final String targetName = (masterPages.isEmpty()) ? "Standard" : template;
OfficeMasterPage predef = predefinedStyles.getMasterPage(template);
if (predef == null)
{
// This is a 'magic' name ..
// todo: It could be that this should be called 'Standard' instead
predef = predefinedStyles.getMasterPage
(MasterPageFactory.DEFAULT_PAGE_NAME);
}
if (predef != null)
{
try
{
// derive
final OfficeMasterPage derived = (OfficeMasterPage) predef.clone();
return setupMasterPage(derived, targetName, pageHeader, pageFooter,
key);
}
catch (CloneNotSupportedException cne)
{
throw new IllegalStateException
("Implementation error: Unable to derive page");
}
}
final OfficeMasterPage masterPage = new OfficeMasterPage();
masterPage.setNamespace(OfficeNamespaces.STYLE_NS);
masterPage.setType("master-page");
return setupMasterPage(masterPage, targetName, pageHeader, pageFooter, key);
}