* write.
*/
protected OdfStylePageLayout getWritableStyleElementByName(
String styleName, boolean isShared) throws Exception {
boolean createNew = isShared;
OdfStylePageLayout pageLayout = null;
OdfOfficeAutomaticStyles styles = mOdfElement.getAutomaticStyles();
if (styleName == null || (styleName.equals(""))) {
createNew = true;
// TODO: get default page layout style
} else {
styles = mOdfElement.getAutomaticStyles();
pageLayout = styles.getPageLayout(styleName);
if (pageLayout == null || pageLayout.getStyleUserCount() > 1) {
createNew = true;
}
}
// if style name is null or this style are used by many users,
// should create a new one.
if (createNew) {
OdfStylePageLayout newPageLayout = null;
if (pageLayout != null) {
newPageLayout = (OdfStylePageLayout) pageLayout
.cloneNode(true);
}
newPageLayout = (OdfStylePageLayout) mDocument.getStylesDom()
.newOdfElement(StylePageLayoutElement.class);
String newname = newUniquePageLayoutName();
newPageLayout.setStyleNameAttribute(newname);
styles.appendChild(newPageLayout);
mOdfElement.setAttributeNS(OdfDocumentNamespace.STYLE.getUri(),
"style:page-layout-name", newname);
newPageLayout.addStyleUser(mOdfElement);
return newPageLayout;
}
return pageLayout;
}