}
private StyleMasterPageElement getMasterPage(boolean pFirstPage) throws Exception {
String pageStyleName = pFirstPage ? "First_20_Page" : "Standard";
OfficeDocumentStylesElement rootElement = getStylesDom().getRootElement();
OfficeMasterStylesElement masterStyles = OdfElement.findFirstChildNode(OfficeMasterStylesElement.class,
rootElement);
if (masterStyles == null) {
masterStyles = rootElement.newOfficeMasterStylesElement();
}
StyleMasterPageElement masterPageEle = null;
NodeList lastMasterPages = masterStyles.getElementsByTagNameNS(OdfDocumentNamespace.STYLE.getUri(),
"master-page");
if (lastMasterPages != null && lastMasterPages.getLength() > 0) {
for (int i = 0; i < lastMasterPages.getLength(); i++) {
StyleMasterPageElement masterPage = (StyleMasterPageElement) lastMasterPages.item(i);
String styleName = masterPage.getStyleNameAttribute();
if (pageStyleName.equals(styleName)) {
masterPageEle = masterPage;
break;
}
}
}
if (masterPageEle == null) {
OdfStylePageLayout layout = OdfElement.findFirstChildNode(OdfStylePageLayout.class, getStylesDom()
.getAutomaticStyles());
masterPageEle = masterStyles.newStyleMasterPageElement(pageStyleName, layout.getStyleNameAttribute());
}
return masterPageEle;
}