incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liud...@apache.org
Subject svn commit: r1406034 - in /incubator/odf/trunk/simple/src: main/java/org/odftoolkit/simple/ main/java/org/odftoolkit/simple/style/ test/java/org/odftoolkit/simple/ test/java/org/odftoolkit/simple/style/
Date Tue, 06 Nov 2012 03:22:58 GMT
Author: liudali
Date: Tue Nov  6 03:22:57 2012
New Revision: 1406034

URL: http://svn.apache.org/viewvc?rev=1406034&view=rev
Log:
Fix for ODFTOOLKIT-336 "Add new APIs to set page style when inserting page break in TextDocument", patch provided by Kejia Ye
https://issues.apache.org/jira/browse/ODFTOOLKIT-336

Added:
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/MasterPage.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/PageLayoutProperties.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/style/PageLayoutPropertiesTest.java
Modified:
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/TextDocument.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/StyleTypeDefinitions.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/TextDocumentTest.java

Modified: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/TextDocument.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/TextDocument.java?rev=1406034&r1=1406033&r2=1406034&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/TextDocument.java (original)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/TextDocument.java Tue Nov  6 03:22:57 2012
@@ -79,6 +79,7 @@ import org.odftoolkit.simple.common.fiel
 import org.odftoolkit.simple.common.field.VariableContainer;
 import org.odftoolkit.simple.common.field.VariableField;
 import org.odftoolkit.simple.common.field.VariableField.VariableType;
+import org.odftoolkit.simple.style.MasterPage;
 import org.odftoolkit.simple.style.TOCStyle;
 import org.odftoolkit.simple.text.AbstractParagraphContainer;
 import org.odftoolkit.simple.text.Footer;
@@ -681,7 +682,44 @@ public class TextDocument extends Docume
 			throw new RuntimeException(breakAttribute + "Break appends failed.", e);
 		}
 	}
-	
+
+	/**
+	 * Appends a new page break to this document after the reference paragraph,
+	 * and the master page style will be applied to the new page.
+	 * 
+	 * @param refParagraph
+	 *            the reference paragraph after where the page break inserted.
+	 * @param master
+	 *            the master page style applied to the new page.
+	 * @since 0.8
+	 */
+
+	public void addPageBreak(Paragraph refParagraph, MasterPage master) {
+		TextPElement pEle = null;
+		try {
+			OdfContentDom contentDocument = getContentDom();
+			OdfOfficeAutomaticStyles styles = contentDocument
+					.getAutomaticStyles();
+			OdfStyle style = styles.newStyle(OdfStyleFamily.Paragraph);
+			style.setStyleMasterPageNameAttribute(master.getName());
+
+			if (refParagraph == null) {
+				pEle = getContentRoot().newTextPElement();
+			} else {
+				OfficeTextElement contentRoot = getContentRoot();
+				pEle = contentRoot.newTextPElement();
+				OdfElement refEle = refParagraph.getOdfElement();
+				contentRoot.insertBefore(pEle, refEle.getNextSibling());
+			}
+			pEle.setStyleName(style.getStyleNameAttribute());
+		} catch (Exception e) {
+			Logger.getLogger(TextDocument.class.getName()).log(Level.SEVERE,
+					null, e);
+			throw new RuntimeException("PageBreak with mater page - "
+					+ master.getName() + " - appends failed.", e);
+		}
+	}
+
 	/**
 	 * Creates a new paragraph and append text.
 	 * 

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/MasterPage.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/MasterPage.java?rev=1406034&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/MasterPage.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/MasterPage.java Tue Nov  6 03:22:57 2012
@@ -0,0 +1,735 @@
+/* 
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+ */
+
+package org.odftoolkit.simple.style;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.odftoolkit.odfdom.dom.OdfDocumentNamespace;
+import org.odftoolkit.odfdom.dom.attribute.style.StylePageLayoutNameAttribute;
+import org.odftoolkit.odfdom.dom.element.OdfStylableElement;
+import org.odftoolkit.odfdom.dom.element.OdfStyleBase;
+import org.odftoolkit.odfdom.dom.element.style.StyleMasterPageElement;
+import org.odftoolkit.odfdom.dom.element.style.StylePageLayoutElement;
+import org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles;
+import org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeMasterStyles;
+import org.odftoolkit.odfdom.incubator.doc.style.OdfStylePageLayout;
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.odfdom.type.Color;
+import org.odftoolkit.odfdom.type.Percent;
+import org.odftoolkit.simple.Document;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AdjustmentStyle;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.LineStyle;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.PrintOrientation;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.WritingMode;
+
+/**
+ * This class represents the master page style settings. It provides methods to
+ * access page layout styles. More functions will be added latter.
+ * 
+ * <p>
+ * This class is a corresponding high level class for element
+ * "style:master-page". It provides methods to access the attributes and
+ * children of "style:master-page".
+ * 
+ * @since 0.8
+ */
+public class MasterPage {
+
+	/**
+	 * This class is the style handler for master page. It provides methods to
+	 * get the readable element and the writable element of a page layout style.
+	 * It also provides method to get the readable element and the writable
+	 * element of page layout properties .
+	 * 
+	 */
+	class StyleHandlerImpl {
+
+		private OdfStylePageLayout mWritableStyleElement;
+		private OdfStyleBase mStyleElement;
+		private PageLayoutProperties mPageLayoutProperties;
+		private PageLayoutProperties mWritablePageLayoutProperties;
+		private OdfStylableElement mOdfElement; // master page style element
+		private Document mDocument;
+
+		/**
+		 * Constructor of StyleHandlerImpl
+		 * 
+		 * @param element
+		 *            - the instance of master page element in an ODF document
+		 * 
+		 */
+		public StyleHandlerImpl(OdfStylableElement element) {
+			mOdfElement = element;
+			mDocument = ((Document) ((OdfFileDom) mOdfElement
+					.getOwnerDocument()).getDocument());
+		}
+
+		/**
+		 * Return the page layout properties definition for this component, only
+		 * for read function.
+		 * <p>
+		 * Null will be returned if there is no style definition.
+		 * <p>
+		 * Null will be returned if there is no explicit page layout properties
+		 * definition for this component.
+		 * <p>
+		 * Note if you try to write style properties to the returned object,
+		 * errors will be met with.
+		 * 
+		 * @return the page layout properties definition for this component,
+		 *         only for read function
+		 */
+		public PageLayoutProperties getPageLayoutPropertiesForRead() {
+			if (mWritablePageLayoutProperties != null)
+				return mWritablePageLayoutProperties;
+			else if (mPageLayoutProperties != null)
+				return mPageLayoutProperties;
+
+			OdfStyleBase style = getPageLayoutElementForRead();
+			if (style == null) {
+				Logger.getLogger(DefaultStyleHandler.class.getName()).log(
+						Level.FINE, "No style definition is found!", "");
+				return null;
+			}
+			mPageLayoutProperties = PageLayoutProperties
+					.getPageLayoutProperties(style);
+			if (mPageLayoutProperties != null)
+				return mPageLayoutProperties;
+			else {
+				Logger
+						.getLogger(DefaultStyleHandler.class.getName())
+						.log(
+								Level.FINE,
+								"No explicit pageLayout properties definition is found!",
+								"");
+				return null;
+			}
+		}
+
+		/**
+		 * Return the page layout properties definition for this component, for
+		 * read and write function.
+		 * <p>
+		 * An empty style definition will be created if there is no style
+		 * definition.
+		 * <p>
+		 * An empty page layout properties definition will be created if there
+		 * is no explicit page layout properties definition.
+		 * 
+		 * @return the page layout properties definition for this component, for
+		 *         read and write function
+		 * @throws Exception
+		 *             if the corresponding <code>StylePageLayoutElement</code>
+		 *             cannot be accessed for write.
+		 */
+		public PageLayoutProperties getPageLayoutPropertiesForWrite()
+				throws Exception {
+			if (mWritablePageLayoutProperties != null)
+				return mWritablePageLayoutProperties;
+			OdfStylePageLayout style = getPageLayoutElementForWrite();
+			mWritablePageLayoutProperties = PageLayoutProperties
+					.getOrCreatePageLayoutProperties(style);
+			return mWritablePageLayoutProperties;
+		}
+
+		/**
+		 * Return the style element for this component, only for read function.
+		 * This method will invode <code>getusedStyleName</code> to get the
+		 * style name, and then find the readable style element by name.
+		 * <p>
+		 * Null will be returned if there is no style definition.
+		 * <p>
+		 * Note if you try to write style properties to the returned object,
+		 * errors will be met with.
+		 * 
+		 * @return the style element
+		 * @see #getUsedPageLayoutStyleName()
+		 */
+		public OdfStyleBase getPageLayoutElementForRead() {
+			// Return current used style
+			if (getCurrentUsedStyle() != null)
+				return getCurrentUsedStyle();
+
+			String styleName = getUsedPageLayoutStyleName();
+			mStyleElement = getReadableStyleElementByName(styleName);
+			return mStyleElement;
+		}
+
+		/**
+		 * Return the style element for this component, for read and write
+		 * functions. This method will invode <code>getusedStyleName</code> to
+		 * get the style name, and then find the writable style element by name.
+		 * <p>
+		 * An empty style definition will be created if there is no style
+		 * definition.
+		 * 
+		 * @return the style element
+		 * @throws Exception
+		 *             if the corresponding <code>StylePageLayoutElement</code>
+		 *             cannot be accessed for write.
+		 * @see #getUsedPageLayoutStyleName()
+		 */
+		public OdfStylePageLayout getPageLayoutElementForWrite()
+				throws Exception {
+			if (mWritableStyleElement != null)
+				return mWritableStyleElement;
+
+			String styleName = getUsedPageLayoutStyleName();
+			mWritableStyleElement = getWritableStyleElementByName(styleName,
+					false);
+			return mWritableStyleElement;
+		}
+
+		/**
+		 * Return a readable style element by style name.
+		 * <p>
+		 * If the style name is null, the default style will be returned.
+		 * 
+		 * @param styleName
+		 *            - the style name
+		 * @return a readable style element
+		 */
+		protected OdfStyleBase getReadableStyleElementByName(String styleName) {
+
+			// TODO: get from default page layout style element
+			if (styleName == null || (styleName.equals("")))
+				;
+
+			OdfStylePageLayout styleElement = mOdfElement.getAutomaticStyles()
+					.getPageLayout(styleName);
+
+			return styleElement;
+		}
+
+		/**
+		 * Return a writable page layout style element by style name.
+		 * <p>
+		 * If the style is shared, a copied style element would be returned.
+		 * <p>
+		 * If the style name is null, the default style will be copied.
+		 * 
+		 * @param styleName
+		 *            - the style name
+		 * @return a writable style element
+		 * @throws Exception
+		 *             if the corresponding StyleElement cannot be accessed for
+		 *             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;
+		}
+
+		private String newUniquePageLayoutName() {
+			String unique_name;
+			OdfOfficeAutomaticStyles styles = mOdfElement.getAutomaticStyles();
+			do {
+				unique_name = String.format("a%06x",
+						(int) (Math.random() * 0xffffff));
+			} while (styles.getPageLayout(unique_name) != null);
+			return unique_name;
+		}
+
+		private OdfStyleBase getCurrentUsedStyle() {
+			if (mWritableStyleElement != null)
+				return mWritableStyleElement;
+			else
+				return mStyleElement;
+		}
+
+		/**
+		 * Return the referenced style name by this master page.
+		 * 
+		 * @return - the referenced style name by this master page.
+		 */
+		public String getUsedPageLayoutStyleName() {
+			return mOdfElement
+					.getAttribute(StylePageLayoutNameAttribute.ATTRIBUTE_NAME
+							.getQName());
+		}
+	}
+
+	private StyleMasterPageElement mStyleMasterPageElement;
+	private StyleHandlerImpl mStyleHandler;
+
+	/**
+	 * Constructor of MasterPage
+	 * 
+	 * @param styleMasterPageElement
+	 *            - the instance of style:master-page element in an ODF document
+	 */
+	MasterPage(StyleMasterPageElement styleMasterPageElement) {
+		mStyleMasterPageElement = styleMasterPageElement;
+	}
+
+	/**
+	 * Return a master page according to its name and its document.
+	 * <p>
+	 * If there is no existing master page defined by this name in the document,
+	 * a new master with this name will be created and returned.
+	 * 
+	 * @param doc
+	 *            - the document to which the master page belongs.
+	 * @param name
+	 *            - the name of the master page
+	 * @return a master page
+	 * @throws Exception
+	 *             if the style DOM cannot be initialized
+	 */
+	public static MasterPage getOrCreateMasterPage(Document doc, String name)
+			throws Exception {
+		OdfOfficeMasterStyles officeMasterStyles = doc.getOfficeMasterStyles();
+		StyleMasterPageElement master = officeMasterStyles.getMasterPage(name);
+		if (master == null) {
+			master = doc.getStylesDom().newOdfElement(
+					StyleMasterPageElement.class);
+			master.setStyleNameAttribute(name);
+			officeMasterStyles.appendChild(master);
+		}
+		return new MasterPage(master);
+	}
+
+	/**
+	 * Get the style handler of this master page.
+	 * <p>
+	 * The style handler is an instance of StyleHandlerImpl
+	 * 
+	 * @return an instance of StyleHandlerImpl
+	 * @see StyleHandlerImpl
+	 */
+	StyleHandlerImpl getPageLayoutStyleHandler() {
+		if (mStyleHandler != null)
+			return mStyleHandler;
+		else {
+			mStyleHandler = new StyleHandlerImpl(mStyleMasterPageElement);
+			return mStyleHandler;
+		}
+
+	}
+
+	/**
+	 * Get the name of this master page.
+	 * <p>
+	 * This represents the attribute <code>style:name</code> of
+	 * <code>style:master-page</code>.
+	 * 
+	 * @return the style name of this master page.
+	 */
+	public String getName() {
+		return mStyleMasterPageElement.getStyleNameAttribute();
+	}
+
+	/**
+	 * Get the top margin of the <code>PageLayoutProperties</code> referenced by
+	 * this master page.
+	 * 
+	 * @return the top margin (in Millimeter)
+	 */
+	public double getMarginTop() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getMarginTop();
+	}
+
+	/**
+	 * Get the right margin of the <code>PageLayoutProperties</code> referenced
+	 * by this master page.
+	 * 
+	 * @return the right margin (in Millimeter)
+	 */
+	public double getMarginRight() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getMarginRight();
+	}
+
+	/**
+	 * Get the left margin of the <code>PageLayoutProperties</code> referenced
+	 * by this master page.
+	 * 
+	 * @return the left margin (in Millimeter)
+	 */
+	public double getMarginLeft() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getMarginLeft();
+	}
+
+	/**
+	 * Get the bottom margin of the <code>PageLayoutProperties</code> referenced
+	 * by this master page.
+	 * 
+	 * @return the bottom margin (in Millimeter)
+	 */
+	public double getMarginBottom() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getMarginBottom();
+	}
+
+	/**
+	 * Set the margins of the <code>PageLayoutProperties</code> referenced by
+	 * this master page.
+	 * <p>
+	 * If the margin size is set to zero, the corresponding margin definition
+	 * will be removed.
+	 * 
+	 * @param marginTop
+	 *            the size of the top margin (in Millimeter)
+	 * @param marginBottom
+	 *            the size of the bottom margin (in Millimeter)
+	 * @param marginLeft
+	 *            the size of the left margin (in Millimeter)
+	 * @param marginRight
+	 *            the size of the right margin (in Millimeter)
+	 * @throws Exception
+	 *             if the corresponding <code>StylePageLayoutElement</code>
+	 *             cannot be accessed for write.
+	 * 
+	 */
+	public void setMargins(double marginTop, double marginBottom,
+			double marginLeft, double marginRight) throws Exception {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForWrite();
+		properties.setMarginTop(marginTop);
+		properties.setMarginBottom(marginBottom);
+		properties.setMarginLeft(marginLeft);
+		properties.setMarginRight(marginRight);
+	}
+
+	/**
+	 * Get the page width of the the <code>PageLayoutProperties</code>
+	 * referenced by this master page.
+	 * 
+	 * @return the size of page width (in Millimeter)
+	 */
+	public double getPageWidth() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getPageWidth();
+	}
+
+	/**
+	 * Set the page width of the <code>PageLayoutProperties</code> referenced by
+	 * this master page.
+	 * <p>
+	 * If the size is set to zero, the page width definition will be removed.
+	 * 
+	 * @param pageWidth
+	 *            the size of the page width (in Millimeter)
+	 * @throws Exception
+	 *             if the corresponding <code>StylePageLayoutElement</code>
+	 *             cannot be accessed for write.
+	 */
+	public void setPageWidth(double pageWidth) throws Exception {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForWrite();
+		properties.setPageWidth(pageWidth);
+	}
+
+	/**
+	 * Get the page height of the the <code>PageLayoutProperties</code>
+	 * referenced by this master page.
+	 * 
+	 * @return the size of page height (in Millimeter)
+	 */
+	public double getPageHeight() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getPageHeight();
+	}
+
+	/**
+	 * Set the page height of the <code>PageLayoutProperties</code> referenced
+	 * by this master page.
+	 * <p>
+	 * If the size is set to zero, the page height definition will be removed.
+	 * 
+	 * @param pageHeight
+	 *            the size of the page height (in Millimeter)
+	 * @throws Exception
+	 *             if the corresponding <code>StylePageLayoutElement</code>
+	 *             cannot be accessed for write.
+	 */
+	public void setPageHeight(double pageHeight) throws Exception {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForWrite();
+		properties.setPageHeight(pageHeight);
+	}
+
+	/**
+	 * Get the number format of the the <code>PageLayoutProperties</code>
+	 * referenced by this master page.
+	 * 
+	 * @return the value of number format
+	 */
+	public String getNumberFormat() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getNumberFormat();
+	}
+
+	/**
+	 * Set the number format of the <code>PageLayoutProperties</code> referenced
+	 * by this master page.
+	 * 
+	 * @param format
+	 *            specify the number format. The values of the style:num-format
+	 *            attribute are 1, i, I, string, an empty string, a or A.
+	 * @throws Exception
+	 *             if the corresponding <code>StylePageLayoutElement</code>
+	 *             cannot be accessed for write.
+	 */
+	public void setNumberFormat(String format) throws Exception {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForWrite();
+		properties.setNumberFormat(format);
+	}
+
+	/**
+	 * Get the print orientation of the the <code>PageLayoutProperties</code>
+	 * referenced by this master page.
+	 * 
+	 * @return the value of print orientation
+	 */
+	public String getPrintOrientation() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getPrintOrientation();
+	}
+
+	/**
+	 * Set the print orientation of the <code>PageLayoutProperties</code>
+	 * referenced by this master page.
+	 * <p>
+	 * If the parameter <code>orientation</code> is null, the print orientation
+	 * definition will be removed.
+	 * 
+	 * @param orientation
+	 *            - the print orientation
+	 * @throws Exception
+	 *             if the corresponding <code>StylePageLayoutElement</code>
+	 *             cannot be accessed for write.
+	 */
+	public void setPrintOrientation(PrintOrientation orientation)
+			throws Exception {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForWrite();
+		properties.setPrintOrientation(orientation);
+	}
+
+	/**
+	 * Get the writing mode of the the <code>PageLayoutProperties</code>
+	 * referenced by this master page.
+	 * 
+	 * @return the value of writing mode
+	 */
+	public String getWritingMode() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getWritingMode();
+	}
+
+	/**
+	 * Set the writing mode of the <code>PageLayoutProperties</code> referenced
+	 * by this master page.
+	 * 
+	 * @param mode
+	 *            - writing mode
+	 * @throws Exception
+	 *             if the corresponding <code>StylePageLayoutElement</code>
+	 *             cannot be accessed for write.
+	 */
+	public void setWritingMode(WritingMode mode) throws Exception {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForWrite();
+		properties.setWritingMode(mode);
+	}
+
+	/**
+	 * Get the footnote max height of the the <code>PageLayoutProperties</code>
+	 * referenced by this master page.
+	 * 
+	 * @return the value of footnote max height
+	 */
+	public double getFootnoteMaxHeight() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getFootnoteMaxHeight();
+	}
+
+	/**
+	 * Set the footnote max height of the <code>PageLayoutProperties</code>
+	 * referenced by this master page.
+	 * 
+	 * @param height
+	 *            - the max height of a footnote area
+	 *@throws Exception
+	 *             if the corresponding <code>StylePageLayoutElement</code>
+	 *             cannot be accessed for write.
+	 */
+	public void setFootnoteMaxHeight(double height) throws Exception {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForWrite();
+		properties.setFootnoteMaxHeight(height);
+	}
+
+	/**
+	 * Get the way in which a footnote separator line aligned to a page, which
+	 * is set by the <code>PageLayoutProperties</code> referenced by this master
+	 * page.
+	 * 
+	 * @return the adjustment of a footnote separator line
+	 */
+	public String getFootnoteSepAdjustment() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getFootnoteSepAdjustment();
+	}
+
+	/**
+	 * Get the color of a footnote separator which is set by the
+	 * <code>PageLayoutProperties</code> referenced by this master page.
+	 * 
+	 * @return the color of a footnote separator line
+	 */
+	public String getFootnoteSepColor() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getFootnoteSepColor();
+	}
+
+	/**
+	 * Get the distance between a footnote separator and the footnote area,
+	 * which is set by the <code>PageLayoutProperties</code> referenced by this
+	 * master page.
+	 * 
+	 * @return the distance after a footnote separator line
+	 */
+	public double getFootnoteSepDistanceAfterSep() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getFootnoteSepDistanceAfterSep();
+	}
+
+	/**
+	 * Get the distance between the text area and the footnote separator, which
+	 * is set by the <code>PageLayoutProperties</code> referenced by this master
+	 * page.
+	 * 
+	 * @return the distance before a footnote separator line
+	 */
+	public double getFootnoteSepDistanceBeforeSep() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getFootnoteSepDistanceBeforeSep();
+	}
+
+	/**
+	 * Get the line style of a footnote separator which is set by the
+	 * <code>PageLayoutProperties</code> referenced by this master page.
+	 * 
+	 * @return the line style of a footnote separator line
+	 */
+	public String getFootnoteSepLineStyle() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getFootnoteSepLineStyle();
+	}
+
+	/**
+	 * Get the real width of a footnote separator which is set by the
+	 * <code>PageLayoutProperties</code> referenced by this master page.
+	 * 
+	 * @return the real width of a footnote separator line
+	 */
+	public double getFootnoteSepWidth() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getFootnoteSepWidth();
+	}
+
+	/**
+	 * Get the thickness of a footnote separator which is set by the
+	 * <code>PageLayoutProperties</code> referenced by this master page.
+	 * 
+	 * @return the thickness of a footnote separator line
+	 */
+	public double getFootnoteSepThickness() {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForRead();
+		return properties.getFootnoteSepThickness();
+	}
+
+	/**
+	 * Set the foot note separator properties of the
+	 * <code>PageLayoutProperties</code> referenced by this master page.
+	 * 
+	 * @throws Exception
+	 *             if the corresponding <code>StylePageLayoutElement</code>
+	 *             cannot be accessed for write.
+	 * @see PageLayoutProperties#setFootnoteSepProperties(AdjustmentStyle,
+	 *      Color, double, double, LineStyle, Percent, double)
+	 * 
+	 */
+	public void setFootnoteSepProperties(AdjustmentStyle adjustment,
+			Color color, double distanceAfterSep, double distanceBeforeSep,
+			LineStyle lineStyle, Percent width, double thickness)
+			throws Exception {
+		PageLayoutProperties properties = getPageLayoutStyleHandler()
+				.getPageLayoutPropertiesForWrite();
+		properties.setFootnoteSepProperties(adjustment, color,
+				distanceAfterSep, distanceBeforeSep, lineStyle, width,
+				thickness);
+	}
+
+}

Added: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/PageLayoutProperties.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/PageLayoutProperties.java?rev=1406034&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/PageLayoutProperties.java (added)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/PageLayoutProperties.java Tue Nov  6 03:22:57 2012
@@ -0,0 +1,985 @@
+/* 
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+ */
+
+package org.odftoolkit.simple.style;
+
+import org.odftoolkit.odfdom.dom.attribute.fo.FoBorderAttribute;
+import org.odftoolkit.odfdom.dom.attribute.fo.FoBorderBottomAttribute;
+import org.odftoolkit.odfdom.dom.attribute.fo.FoBorderLeftAttribute;
+import org.odftoolkit.odfdom.dom.attribute.fo.FoBorderRightAttribute;
+import org.odftoolkit.odfdom.dom.attribute.fo.FoBorderTopAttribute;
+import org.odftoolkit.odfdom.dom.attribute.fo.FoMarginBottomAttribute;
+import org.odftoolkit.odfdom.dom.attribute.fo.FoMarginLeftAttribute;
+import org.odftoolkit.odfdom.dom.attribute.fo.FoMarginRightAttribute;
+import org.odftoolkit.odfdom.dom.attribute.fo.FoMarginTopAttribute;
+import org.odftoolkit.odfdom.dom.attribute.fo.FoPageHeightAttribute;
+import org.odftoolkit.odfdom.dom.attribute.fo.FoPageWidthAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StyleBorderLineWidthAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StyleBorderLineWidthBottomAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StyleBorderLineWidthLeftAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StyleBorderLineWidthRightAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StyleBorderLineWidthTopAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StyleColorAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StyleDistanceAfterSepAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StyleDistanceBeforeSepAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StyleNumFormatAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StylePrintOrientationAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StyleRelWidthAttribute;
+import org.odftoolkit.odfdom.dom.attribute.style.StyleWidthAttribute;
+import org.odftoolkit.odfdom.dom.element.OdfStyleBase;
+import org.odftoolkit.odfdom.dom.element.OdfStylePropertiesBase;
+import org.odftoolkit.odfdom.dom.element.style.StyleFootnoteSepElement;
+import org.odftoolkit.odfdom.dom.element.style.StylePageLayoutPropertiesElement;
+import org.odftoolkit.odfdom.dom.style.props.OdfStylePropertiesSet;
+import org.odftoolkit.odfdom.type.Color;
+import org.odftoolkit.odfdom.type.Length;
+import org.odftoolkit.odfdom.type.Percent;
+import org.odftoolkit.odfdom.type.Length.Unit;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AdjustmentStyle;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.LineStyle;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.WritingMode;
+
+/**
+ * This class represents the page layout style settings. It provides methods to
+ * access borders, margins,number format, page width, page height and etc. More
+ * functions will be added latter.
+ * 
+ * <p>
+ * This class is a corresponded high level class for element
+ * "style:page-layout-properties". It provides methods to access the attributes
+ * and children of "style:page-layout-properties".
+ * 
+ * @since 0.8
+ */
+public class PageLayoutProperties {
+	// fo:background-color
+
+	// fo:border, style:border-line-width
+	// fo:border-bottom, style:border-line-width-bottom
+	// fo:border-left, style:border-line-width-left
+	// fo:border-right, style:border-line-width-right
+	// fo:border-top, style:border-line-width-top
+
+	// fo:margin
+	// fo:margin-bottom
+	// fo:margin-left
+	// fo:margin-right
+	// fo:margin-top
+
+	// fo:padding
+	// fo:padding-bottom
+	// fo:padding-left
+	// fo:padding-right
+	// fo:padding-top
+
+	// fo:page-height
+	// fo:page-width
+
+	// style:layout-grid-base-height
+	// style:layout-grid-base-width
+	// style:layout-grid-color
+	// style:layout-grid-display
+	// style:layout-grid-lines
+	// style:layout-grid-mode
+	// style:layout-grid-print
+	// style:layout-grid-ruby-below
+	// style:layout-grid-ruby-height
+	// style:layout-grid-snap-to
+	// style:layout-grid-standard-mode
+
+	// style:num-format
+	// style:num-letter-sync
+	// style:num-prefix
+	// style:num-suffix
+
+	// style:print
+	// style:print-orientation
+	// style:first-page-number
+	// style:footnote-max-height
+	// style:paper-tray-name
+	// style:print-page-order
+	// style:register-truth-ref-style-name
+	// style:scale-to
+	// style:scale-to-pages
+	// style:shadow
+	// style:table-centering
+	// style:writing-mode
+
+	// the default size as used for left-, right-margin and indention
+	private static final String DEFAULT_LENGTH = "0in";
+	private static final String DEFAULT_PERCENT = "0%";
+	StylePageLayoutPropertiesElement mElement;
+	StyleFootnoteSepElement mFootnoteSepElement;
+	BorderPropertiesImpl mBorderPropertiesHandler;
+
+	/**
+	 * Create an instance of PageLayoutProperties
+	 */
+	protected PageLayoutProperties() {
+	}
+
+	/**
+	 * Create an instance of PageLayoutProperties from an element
+	 * <style:page-layout-properties>
+	 * 
+	 * @param pageLayoutProperties
+	 *            - the element of style:page-layout-properties
+	 */
+	protected PageLayoutProperties(
+			StylePageLayoutPropertiesElement pageLayoutProperties) {
+		mElement = pageLayoutProperties;
+		mFootnoteSepElement = (StyleFootnoteSepElement) pageLayoutProperties
+				.getElementsByTagName(
+						StyleFootnoteSepElement.ELEMENT_NAME.getQName())
+				.item(0);
+		mBorderPropertiesHandler = new BorderPropertiesImpl(mElement);
+	}
+
+	/**
+	 * Set the border style.
+	 * <p>
+	 * The first parameter <code>bordersType</code> describes which borders you
+	 * want to apply the style to, e.g. up border, bottom border, left border,
+	 * right border or four borders.
+	 * <p>
+	 * The border style information will be removed if the parameter
+	 * <code>bordersType</code> is NONE.
+	 * 
+	 * @param bordersType
+	 *            - the type of the borders
+	 * @param border
+	 *            - the border style description
+	 */
+	public void setBorders(StyleTypeDefinitions.CellBordersType bordersType,
+			Border border) {
+		switch (bordersType) {
+		case BOTTOM:
+			setBottomBorder(border);
+			break;
+		case LEFT:
+			setLeftBorder(border);
+			break;
+		case RIGHT:
+			setRightBorder(border);
+			break;
+		case TOP:
+			setTopBorder(border);
+			break;
+		case ALL_FOUR:
+			setBorder(border);
+			break;
+		case LEFT_RIGHT:
+			setLeftBorder(border);
+			setRightBorder(border);
+			break;
+		case TOP_BOTTOM:
+			setTopBorder(border);
+			setBottomBorder(border);
+			break;
+		case NONE:
+			mElement
+					.removeAttribute(StyleBorderLineWidthAttribute.ATTRIBUTE_NAME
+							.getQName());
+			mElement.removeAttribute(FoBorderAttribute.ATTRIBUTE_NAME
+					.getQName());
+			mElement
+					.removeAttribute(StyleBorderLineWidthBottomAttribute.ATTRIBUTE_NAME
+							.getQName());
+			mElement.removeAttribute(FoBorderBottomAttribute.ATTRIBUTE_NAME
+					.getQName());
+			mElement
+					.removeAttribute(StyleBorderLineWidthTopAttribute.ATTRIBUTE_NAME
+							.getQName());
+			mElement.removeAttribute(FoBorderTopAttribute.ATTRIBUTE_NAME
+					.getQName());
+			mElement
+					.removeAttribute(StyleBorderLineWidthLeftAttribute.ATTRIBUTE_NAME
+							.getQName());
+			mElement.removeAttribute(FoBorderLeftAttribute.ATTRIBUTE_NAME
+					.getQName());
+			mElement
+					.removeAttribute(StyleBorderLineWidthRightAttribute.ATTRIBUTE_NAME
+							.getQName());
+			mElement.removeAttribute(FoBorderRightAttribute.ATTRIBUTE_NAME
+					.getQName());
+		}
+	}
+
+	/**
+	 * Return the border setting for all four borders.
+	 * <p>
+	 * Null will be returned if there is no border setting for all four borders.
+	 * 
+	 * @return the border setting
+	 */
+	public Border getBorder() {
+		return mBorderPropertiesHandler.getBorder();
+	}
+
+	/**
+	 * Return the border setting for the top border.
+	 * <p>
+	 * Null will be returned if there is no border setting for the top border.
+	 * 
+	 * @return the border setting
+	 */
+	public Border getTopBorder() {
+		return mBorderPropertiesHandler.getTopBorder();
+	}
+
+	/**
+	 * Return the border setting for the left border.
+	 * <p>
+	 * Null will be returned if there is no border setting for the left border.
+	 * 
+	 * @return the border setting
+	 */
+	public Border getLeftBorder() {
+		return mBorderPropertiesHandler.getLeftBorder();
+	}
+
+	/**
+	 * Return the border setting for the right border.
+	 * <p>
+	 * Null will be returned if there is no border setting for the right border.
+	 * 
+	 * @return the border setting
+	 */
+	public Border getRightBorder() {
+		return mBorderPropertiesHandler.getRightBorder();
+	}
+
+	// fo:border-bottom
+	// style:border-line-width-bottom
+	/**
+	 * Return the border setting for the bottom border.
+	 * <p>
+	 * Null will be returned if there is no border setting for the bottom
+	 * border.
+	 * 
+	 * @return the border setting
+	 */
+	public Border getBottomBorder() {
+		return mBorderPropertiesHandler.getBottomBorder();
+	}
+
+	// fo:border
+	// style:border-line-width
+	/**
+	 * Set the border definition for all four borders.
+	 * <p>
+	 * If the parameter <code>border</code> is null, the border definition for
+	 * all four borders will be removed.
+	 * <p>
+	 * If the line type in the border definition is NONE, the border definition
+	 * for all four borders will be removed.
+	 * 
+	 * @param border
+	 *            - the border setting
+	 */
+	public void setBorder(Border border) {
+		mBorderPropertiesHandler.setBorder(border);
+	}
+
+	// fo:border-bottom
+	// style:border-line-width-bottom
+	/**
+	 * Set the border definition for the bottom border.
+	 * <p>
+	 * If the parameter <code>border</code> is null, the border definition for
+	 * the bottom border will be removed.
+	 * <p>
+	 * If the line type in the border definition is NONE, the border definition
+	 * for the bottom border will be removed.
+	 * 
+	 * @param border
+	 *            - the border setting
+	 */
+	public void setBottomBorder(Border border) {
+		mBorderPropertiesHandler.setBottomBorder(border);
+	}
+
+	// fo:border-top
+	// style:border-line-width-top
+	/**
+	 * Set the border definition for the top border.
+	 * <p>
+	 * If the parameter <code>border</code> is null, the border definition for
+	 * the top border will be removed.
+	 * <p>
+	 * If the line type in the border definition is NONE, the border definition
+	 * for the top border will be removed.
+	 * 
+	 * @param border
+	 *            - the border setting
+	 */
+	public void setTopBorder(Border border) {
+		mBorderPropertiesHandler.setTopBorder(border);
+	}
+
+	// fo:border-left
+	// style:border-line-width-left
+	/**
+	 * Set the border definition for the left border.
+	 * <p>
+	 * If the parameter <code>border</code> is null, the border definition for
+	 * the left border will be removed.
+	 * <p>
+	 * If the line type in the border definition is NONE, the border definition
+	 * for the left border will be removed.
+	 * 
+	 * @param border
+	 *            - the border setting
+	 */
+	public void setLeftBorder(Border border) {
+		mBorderPropertiesHandler.setLeftBorder(border);
+	}
+
+	// fo:border-right
+	// style:border-line-width-right
+	/**
+	 * Set the border definition for the right border.
+	 * <p>
+	 * If the parameter <code>border</code> is null, the border definition for
+	 * the right border will be removed.
+	 * <p>
+	 * If the line type in the border definition is NONE, the border definition
+	 * for the right border will be removed.
+	 * 
+	 * @param border
+	 *            - the border setting
+	 */
+	public void setRightBorder(Border border) {
+		mBorderPropertiesHandler.setRightBorder(border);
+	}
+
+	/**
+	 * Set the left margin of this <code>PageLayoutProperties</code>
+	 * <p>
+	 * If the size is set to zero, the left margin definition will be removed.
+	 * 
+	 * @param marginLeft
+	 *            the size of the left margin (in Millimeter)
+	 */
+	public void setMarginLeft(double marginLeft) {
+		if (marginLeft == 0) {
+			mElement.removeAttribute(FoMarginLeftAttribute.ATTRIBUTE_NAME
+					.getQName());
+		} else {
+			mElement.setFoMarginLeftAttribute(getInchValue(marginLeft));
+		}
+	}
+
+	/**
+	 * Returns the provided Millimeter value as Inch value
+	 * 
+	 * @param value
+	 *            the value to set the attribute value to (in Millimeter)
+	 */
+	private static String getInchValue(double value) {
+		// build the string for mm
+		final String mmValueString = value + Unit.MILLIMETER.abbr();
+		// convert the length to inch
+		final String inchValueString = Length.mapToUnit(mmValueString,
+				Unit.INCH);
+
+		// return the value
+		return inchValueString;
+	}
+
+	/**
+	 * Get the size of the left margin of this <code>PageLayoutProperties</code>
+	 * <p>
+	 * If the size is set to zero, the left margin definition will be removed.
+	 * 
+	 * @return the size of the left margin (in Millimeter)
+	 */
+	public double getMarginLeft() {
+		// get the value
+		String valueString = mElement.getFoMarginLeftAttribute();
+		// check if a value was returned
+		if (valueString == null) {
+			// if not use the default length
+			valueString = DEFAULT_LENGTH;
+		}
+		// return the converted value
+		return Length.parseDouble(valueString, Unit.MILLIMETER);
+	}
+
+	/**
+	 * Set the right margin of this <code>PageLayoutProperties</code>
+	 * <p>
+	 * If the size is set to zero, the right margin definition will be removed.
+	 * 
+	 * @param marginRight
+	 *            the size of the right margin (in Millimeter)
+	 */
+	public void setMarginRight(double marginRight) {
+		if (marginRight == 0) {
+			mElement.removeAttribute(FoMarginRightAttribute.ATTRIBUTE_NAME
+					.getQName());
+		} else {
+			mElement.setFoMarginRightAttribute(getInchValue(marginRight));
+		}
+	}
+
+	/**
+	 * Get the size of the right margin of this
+	 * <code>PageLayoutProperties</code>
+	 * 
+	 * @return the size of the right margin (in Millimeter)
+	 */
+	public double getMarginRight() {
+		// get the value
+		String valueString = mElement.getFoMarginRightAttribute();
+		// check if a value was returned
+		if (valueString == null) {
+			// if not use the default length
+			valueString = DEFAULT_LENGTH;
+		}
+		// return the converted value
+		return Length.parseDouble(valueString, Unit.MILLIMETER);
+	}
+
+	/**
+	 * Set the top margin of this <code>PageLayoutProperties</code>
+	 * <p>
+	 * If the size is set to zero, the top margin definition will be removed.
+	 * 
+	 * @param marginTop
+	 *            the size of the right margin (in Millimeter)
+	 */
+	public void setMarginTop(double marginTop) {
+		if (marginTop == 0) {
+			mElement.removeAttribute(FoMarginTopAttribute.ATTRIBUTE_NAME
+					.getQName());
+		} else {
+			mElement.setFoMarginTopAttribute(getInchValue(marginTop));
+		}
+	}
+
+	/**
+	 * Get the size of the top margin of this <code>PageLayoutProperties</code>
+	 * 
+	 * @return the size of the top margin (in Millimeter)
+	 */
+	public double getMarginTop() {
+		// get the value
+		String valueString = mElement.getFoMarginTopAttribute();
+		// check if a value was returned
+		if (valueString == null) {
+			// if not use the default length
+			valueString = DEFAULT_LENGTH;
+		}
+		// return the converted value
+		return Length.parseDouble(valueString, Unit.MILLIMETER);
+	}
+
+	/**
+	 * Set the bottom margin of this <code>PageLayoutProperties</code>
+	 * <p>
+	 * If the size is set to zero, the bottom margin definition will be removed.
+	 * 
+	 * @param marginBottom
+	 *            the size of the bottom margin (in Millimeter)
+	 */
+	public void setMarginBottom(double marginBottom) {
+		if (marginBottom == 0) {
+			mElement.removeAttribute(FoMarginBottomAttribute.ATTRIBUTE_NAME
+					.getQName());
+		} else {
+			mElement.setFoMarginBottomAttribute(getInchValue(marginBottom));
+		}
+	}
+
+	/**
+	 * Get the size of the bottom margin of this
+	 * <code>PageLayoutProperties</code>
+	 * 
+	 * @return the size of the bottom margin (in Millimeter)
+	 */
+	public double getMarginBottom() {
+		// get the value
+		String valueString = mElement.getFoMarginBottomAttribute();
+		// check if a value was returned
+		if (valueString == null) {
+			// if not use the default length
+			valueString = DEFAULT_LENGTH;
+		}
+		// return the converted value
+		return Length.parseDouble(valueString, Unit.MILLIMETER);
+	}
+
+	/**
+	 * Get the number format of this <code>PageLayoutProperties</code>
+	 * 
+	 * @return the number format
+	 */
+	public String getNumberFormat() {
+		return mElement.getStyleNumFormatAttribute();
+	}
+
+	/**
+	 * Set the number format of this <code>PageLayoutProperties</code>
+	 * <p>
+	 * If the parameter <code>format</code> is null, the definition will be
+	 * removed.
+	 * 
+	 * @param format
+	 *            specify the number format. The values of the style:num-format
+	 *            attribute are 1, i, I, string, an empty string, a or A.
+	 */
+	public void setNumberFormat(String format) {
+		if (format == null) {
+			mElement.removeAttribute(StyleNumFormatAttribute.ATTRIBUTE_NAME
+					.getQName());
+		} else {
+			mElement.setStyleNumFormatAttribute(format);
+		}
+	}
+
+	/**
+	 * Get the page width of this <code>PageLayoutProperties</code>
+	 * 
+	 * @return the size of page width (in Millimeter)
+	 */
+	public double getPageWidth() {
+		// get the value
+		String valueString = mElement.getFoPageWidthAttribute();
+		// check if a value was returned
+		if (valueString == null) {
+			// if not use the default length
+			valueString = DEFAULT_LENGTH;
+		}
+		// return the converted value
+		return Length.parseDouble(valueString, Unit.MILLIMETER);
+	}
+
+	/**
+	 * Set the page width of this <code>PageLayoutProperties</code>
+	 * <p>
+	 * If the size is set to zero, the page width definition will be removed.
+	 * 
+	 * @param pageWidth
+	 *            the size of the page width (in Millimeter)
+	 */
+	public void setPageWidth(double pageWidth) {
+		if (pageWidth == 0) {
+			mElement.removeAttribute(FoPageWidthAttribute.ATTRIBUTE_NAME
+					.getQName());
+		} else {
+			mElement.setFoPageWidthAttribute(getInchValue(pageWidth));
+		}
+	}
+
+	/**
+	 * Get the page height of this <code>PageLayoutProperties</code>
+	 * 
+	 * @return the size of page height (in Millimeter)
+	 */
+	public double getPageHeight() {
+		// get the value
+		String valueString = mElement.getFoPageHeightAttribute();
+		// check if a value was returned
+		if (valueString == null) {
+			// if not use the default length
+			valueString = DEFAULT_LENGTH;
+		}
+		// return the converted value
+		return Length.parseDouble(valueString, Unit.MILLIMETER);
+	}
+
+	/**
+	 * Set the page height of this <code>PageLayoutProperties</code>
+	 * <p>
+	 * If the size is set to zero, the page height definition will be removed.
+	 * 
+	 * @param pageHeight
+	 *            the size of the page height (in Millimeter)
+	 */
+	public void setPageHeight(double pageHeight) {
+		if (pageHeight == 0) {
+			mElement.removeAttribute(FoPageHeightAttribute.ATTRIBUTE_NAME
+					.getQName());
+		} else {
+			mElement.setFoPageHeightAttribute(getInchValue(pageHeight));
+		}
+	}
+
+	/**
+	 * Get the print orientation of this <code>PageLayoutProperties</code>
+	 * 
+	 * @return the print orientation
+	 */
+	public String getPrintOrientation() {
+		return mElement.getStylePrintOrientationAttribute();
+	}
+
+	/**
+	 * Set the print orientation of this <code>PageLayoutProperties</code>
+	 * <p>
+	 * If the parameter <code>orientation</code> is null, the print orientation
+	 * definition will be removed.
+	 * 
+	 * @param orientation
+	 *            - the print orientation
+	 */
+	public void setPrintOrientation(
+			StyleTypeDefinitions.PrintOrientation orientation) {
+		if (orientation == null) {
+			mElement
+					.removeAttribute(StylePrintOrientationAttribute.ATTRIBUTE_NAME
+							.getQName());
+		} else {
+			mElement.setStylePrintOrientationAttribute(orientation.toString());
+		}
+	}
+
+	/**
+	 * Get the way in which a footnote separator line is aligned on a page.
+	 * <p>
+	 * If there is no <code>style:footnote-sep</code> element, the default value
+	 * "left" will be returned.
+	 * 
+	 * @return the adjustment value of footnote separator line.
+	 */
+	public String getFootnoteSepAdjustment() {
+		if (mFootnoteSepElement == null) {
+			return AdjustmentStyle.LEFT.toString();
+		} else {
+			return mFootnoteSepElement.getStyleAdjustmentAttribute();
+		}
+	}
+
+	/**
+	 * Get the color of footnote separator line.
+	 * <p>
+	 * If there is no <code>style:footnote-sep</code> element, the null value
+	 * will be returned.
+	 * 
+	 * @return the color of footnote separator line.
+	 */
+	public String getFootnoteSepColor() {
+		if (mFootnoteSepElement == null) {
+			return null;
+		} else {
+			return mFootnoteSepElement.getStyleColorAttribute();
+		}
+	}
+
+	/**
+	 * Get the distance between a footnote separator line and the footnote text.
+	 * <p>
+	 * If there is no <code>style:footnote-sep</code> element, null will be
+	 * returned.
+	 * 
+	 * @return the distance after a footnote separator line.
+	 */
+	public double getFootnoteSepDistanceAfterSep() {
+		if (mFootnoteSepElement == null) {
+			return 0;
+		} else {
+			String value = mFootnoteSepElement
+					.getStyleDistanceAfterSepAttribute();
+			if (value == null)
+				value = DEFAULT_LENGTH;
+			return Length.parseDouble(value, Unit.MILLIMETER);
+		}
+	}
+
+	/**
+	 * Get the distance between the text area and a footnote separator line.
+	 * <p>
+	 * If there is no <code>style:footnote-sep</code> element, null will be
+	 * returned.
+	 * 
+	 * @return the distance before a footnote separator line.
+	 */
+	public double getFootnoteSepDistanceBeforeSep() {
+		if (mFootnoteSepElement == null) {
+			return 0;
+		} else {
+			String value = mFootnoteSepElement
+					.getStyleDistanceBeforeSepAttribute();
+			if (value == null)
+				value = DEFAULT_LENGTH;
+			return Length.parseDouble(value, Unit.MILLIMETER);
+		}
+	}
+
+	/**
+	 * Get the line style of a footnote separator line.
+	 * <p>
+	 * If there is no <code>style:footnote-sep</code> element, the default value
+	 * "NONE" will be returned.
+	 * 
+	 * @return the line style of a footnote separator line.
+	 */
+	public String getFootnoteSepLineStyle() {
+		if (mFootnoteSepElement == null) {
+			return LineStyle.NONE.toString();
+		} else {
+			return mFootnoteSepElement.getStyleLineStyleAttribute();
+		}
+	}
+
+	/**
+	 * Get the width of a footnote separator line.
+	 * <p>
+	 * If there is no <code>style:footnote-sep</code> element, the default value
+	 * 0 will be returned.
+	 * 
+	 * @return the width a footnote separator line.
+	 */
+	public double getFootnoteSepWidth() {
+		if (mFootnoteSepElement == null) {
+			return 0;
+		} else {
+			String value = mFootnoteSepElement.getStyleRelWidthAttribute();
+			if (value == null)
+				value = DEFAULT_PERCENT;
+			return Percent.valueOf(value).doubleValue();
+		}
+	}
+
+	/**
+	 * Get the thickness of a footnote separator line.
+	 * <p>
+	 * If there is no <code>style:footnote-sep</code> element, the default value
+	 * 0 will be returned.
+	 * 
+	 * @return the thickness a footnote separator line.
+	 */
+	public double getFootnoteSepThickness() {
+		if (mFootnoteSepElement == null) {
+			return 0;
+		} else {
+			String value = mFootnoteSepElement.getStyleWidthAttribute();
+			if (value == null)
+				value = DEFAULT_LENGTH;
+			return Length.parseDouble(value, Unit.MILLIMETER);
+		}
+	}
+
+	/**
+	 * Set the formatting of footnote separator of this
+	 * <code>PageLayoutProperties</code>
+	 * <p>
+	 * If the parameter <code>adjustment</code> is null, the adjustment
+	 * definition will be set as left. <br>
+	 * If the parameter <code>lineStyle</code> is null, the line style
+	 * definition will be set as NONE. <br>
+	 * If other parameters, like <code>color,
+	 * distanceAfterSep, distanceBeforeSep, width or thickness</code> is null,
+	 * the corresponding definition will be removed.
+	 * 
+	 * @param adjustment
+	 *            - specifies how a footnote separator line is aligned on a
+	 *            page.
+	 * 
+	 * @param color
+	 *            - specifies the color of a column or footnote separator line
+	 * 
+	 * @param distanceAfterSep
+	 *            - specifies the space between a footnote separator line and
+	 *            the footnote text.
+	 * 
+	 * @param distanceBeforeSep
+	 *            - specifies the space between the body text area and a
+	 *            footnote separator line.
+	 * 
+	 * @param lineStyle
+	 *            - specifies the style of a footnote separator line.
+	 * 
+	 * @param width
+	 *            - specifies the length of the footnote separator line as a
+	 *            percentage of the body text area.
+	 * 
+	 * @param thickness
+	 *            - specifies the width or thickness of a line.
+	 */
+	public void setFootnoteSepProperties(AdjustmentStyle adjustment,
+			Color color, double distanceAfterSep, double distanceBeforeSep,
+			StyleTypeDefinitions.LineStyle lineStyle, Percent width,
+			double thickness) {
+		if (mFootnoteSepElement == null) {
+			mFootnoteSepElement = mElement.newStyleFootnoteSepElement();
+		}
+
+		// style:adjustment
+		if (adjustment != null) {
+			mFootnoteSepElement.setStyleAdjustmentAttribute(adjustment
+					.toString());
+		} else {
+			mFootnoteSepElement
+					.setStyleAdjustmentAttribute(AdjustmentStyle.LEFT
+							.toString());
+		}
+
+		// style:color
+		if (color != null) {
+			mFootnoteSepElement.setStyleColorAttribute(color.toString());
+		} else {
+			mFootnoteSepElement
+					.removeAttribute(StyleColorAttribute.ATTRIBUTE_NAME
+							.getQName());
+		}
+
+		// style:distance-after-sep
+		if (distanceAfterSep == 0) {
+			mFootnoteSepElement
+					.removeAttribute(StyleDistanceAfterSepAttribute.ATTRIBUTE_NAME
+							.getQName());
+		} else {
+			mFootnoteSepElement
+					.setStyleDistanceAfterSepAttribute(getInchValue(distanceAfterSep));
+		}
+
+		// style:distance-before-sep
+		if (distanceBeforeSep == 0) {
+			mFootnoteSepElement
+					.removeAttribute(StyleDistanceBeforeSepAttribute.ATTRIBUTE_NAME
+							.getQName());
+		} else {
+			mFootnoteSepElement
+					.setStyleDistanceBeforeSepAttribute(getInchValue(distanceBeforeSep));
+		}
+
+		// style:line-style
+		if (lineStyle == null) {
+			mFootnoteSepElement.setStyleLineStyleAttribute(LineStyle.NONE
+					.toString());
+		} else {
+			mFootnoteSepElement
+					.setStyleLineStyleAttribute(lineStyle.toString());
+		}
+
+		// style:rel-width
+		if (width == null) {
+			mFootnoteSepElement
+					.removeAttribute(StyleRelWidthAttribute.ATTRIBUTE_NAME
+							.getQName());
+		} else {
+			mFootnoteSepElement.setStyleRelWidthAttribute(width.toString());
+		}
+
+		// style:width
+		if (thickness == 0) {
+			mFootnoteSepElement
+					.removeAttribute(StyleWidthAttribute.ATTRIBUTE_NAME
+							.getQName());
+		} else {
+			mFootnoteSepElement.setStyleWidthAttribute(getInchValue(thickness));
+		}
+	}
+
+	/**
+	 * Set the writing mode of this <code>PageLayoutProperties</code>
+	 * <p>
+	 * If the parameter <code>mode</code> is null, the default value of writing
+	 * node "page" will be set.
+	 * 
+	 * @param mode
+	 *            - specifies a writing mode.
+	 */
+	public void setWritingMode(WritingMode mode) {
+		if (mode == null) {
+			mElement.setStyleWritingModeAttribute(WritingMode.PAGE.toString());
+		} else {
+			mElement.setStyleWritingModeAttribute(mode.toString());
+		}
+	}
+
+	/**
+	 * Get the writing mode of this <code>PageLayoutProperties</code>
+	 * 
+	 * @return the value of writing mode
+	 */
+	public String getWritingMode() {
+		return WritingMode.enumValueOf(mElement.getStyleWritingModeAttribute())
+				.toString();
+	}
+
+	/**
+	 * Set the max height of a footnote area on a page.
+	 * <p>
+	 * If the value of this attribute is set to 0, there is no limit to the
+	 * amount of space that the footnote can occupy.
+	 * 
+	 * @param height
+	 *            - the max height which a footnote area can occupy
+	 */
+	public void setFootnoteMaxHeight(double height) {
+		mElement.setStyleFootnoteMaxHeightAttribute(getInchValue(height));
+	}
+
+	/**
+	 * Get the max height of a footnote area on a page.
+	 * 
+	 * @return the value of max height of footnote area.
+	 */
+	public double getFootnoteMaxHeight() {
+		String valueString = mElement.getStyleFootnoteMaxHeightAttribute();
+		// check if a value was returned
+		if (valueString == null) {
+			// if not use the default length
+			valueString = DEFAULT_LENGTH;
+		}
+		// return the converted value
+		return Length.parseDouble(valueString, Unit.MILLIMETER);
+	}
+
+	/**
+	 * Return an instance of
+	 * <code>PageLayoutProperties</p> to represent the "style:page-layout-properties" in a style element.
+	 * <p>If there is no "style:page-layout-properties" defined in the style element, a new "style:page-layout-properties" element will be created.
+	 * 
+	 * @param style
+	 *            - a style element
+	 * @return an instance of <code>PageLayoutProperties</p>
+	 */
+	public static PageLayoutProperties getOrCreatePageLayoutProperties(
+			OdfStyleBase style) {
+		OdfStylePropertiesBase properties = style
+				.getOrCreatePropertiesElement(OdfStylePropertiesSet.PageLayoutProperties);
+		return new PageLayoutProperties(
+				(StylePageLayoutPropertiesElement) properties);
+	}
+
+	/**
+	 * Return an instance of
+	 * <code>PageLayoutProperties</p> to represent the "style:page-layout-properties" in a style element.
+	 * <p>If there is no "style:page-layout-properties" defined in the style element, null will be returned.
+	 * 
+	 * @param style
+	 *            - a style element
+	 * @return an instance of <code>PageLayoutProperties</p>;Null if there is no
+	 *         "style:page-layout-properties" defined
+	 */
+	public static PageLayoutProperties getPageLayoutProperties(
+			OdfStyleBase style) {
+		OdfStylePropertiesBase properties = style
+				.getPropertiesElement(OdfStylePropertiesSet.PageLayoutProperties);
+		if (properties != null)
+			return new PageLayoutProperties(
+					(StylePageLayoutPropertiesElement) properties);
+		else
+			return null;
+	}
+}

Modified: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/StyleTypeDefinitions.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/StyleTypeDefinitions.java?rev=1406034&r1=1406033&r2=1406034&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/StyleTypeDefinitions.java (original)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/StyleTypeDefinitions.java Tue Nov  6 03:22:57 2012
@@ -90,7 +90,25 @@ public class StyleTypeDefinitions {
 			return fontStyle;
 		}
 	}
-	
+
+	/**
+	 * Common used font adjustment style from users perspective
+	 */
+	public static enum AdjustmentStyle {
+		CENTER("center"), LEFT("left"), RIGHT("right");
+
+		private String adjustment = "left";
+
+		AdjustmentStyle(String value) {
+			this.adjustment = value;
+		}
+
+		public String toString() {
+			return adjustment;
+		}
+
+	}
+
 	/**
 	 * Common used font text line position from users perspective.
 	 * <p>Currently, only support underline and strike through.
@@ -817,4 +835,59 @@ public class StyleTypeDefinitions {
 		}
 	}
 
+	public static enum PrintOrientation {
+		LANDSCAPE("landscape"), PORTRAIT("portrait");
+
+		private String printOrientaiton;
+
+		PrintOrientation(String orientation) {
+			this.printOrientaiton = orientation;
+		}
+
+		public static PrintOrientation enumValueOf(String aValue) {
+			if ((aValue == null) || (aValue.length() == 0))
+				return PORTRAIT;
+
+			for (PrintOrientation aIter : values()) {
+				if (aValue.equals(aIter.toString())) {
+					return aIter;
+				}
+			}
+			return PORTRAIT;
+		}
+
+		@Override
+		public String toString() {
+			return printOrientaiton;
+		}
+	}
+
+	public static enum WritingMode {
+		LRTB("lr-tb"), RLTB("rl-tb"), TBRL("tb-rl"), TBLR("tb-lr"), LR("lr"), RL(
+				"rl"), TB("tb"), PAGE("page");
+
+		private String mode;
+
+		WritingMode(String mode) {
+			this.mode = mode;
+		}
+
+		public static WritingMode enumValueOf(String aValue) {
+			if ((aValue == null) || (aValue.length() == 0))
+				return PAGE;
+
+			for (WritingMode aIter : values()) {
+				if (aValue.equals(aIter.toString())) {
+					return aIter;
+				}
+			}
+			return PAGE;
+		}
+
+		@Override
+		public String toString() {
+			return mode;
+		}
+	}
+
 }

Modified: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/TextDocumentTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/TextDocumentTest.java?rev=1406034&r1=1406033&r2=1406034&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/TextDocumentTest.java (original)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/TextDocumentTest.java Tue Nov  6 03:22:57 2012
@@ -30,18 +30,32 @@ import junit.framework.Assert;
 import org.junit.Test;
 import org.odftoolkit.odfdom.dom.OdfContentDom;
 import org.odftoolkit.odfdom.dom.element.office.OfficeAnnotationElement;
+import org.odftoolkit.odfdom.dom.element.style.StyleFootnoteSepElement;
+import org.odftoolkit.odfdom.dom.element.style.StyleMasterPageElement;
+import org.odftoolkit.odfdom.dom.element.style.StylePageLayoutPropertiesElement;
 import org.odftoolkit.odfdom.dom.element.style.StyleParagraphPropertiesElement;
 import org.odftoolkit.odfdom.dom.element.text.TextPElement;
 import org.odftoolkit.odfdom.dom.style.OdfStyleFamily;
+import org.odftoolkit.odfdom.dom.style.props.OdfStylePropertiesSet;
 import org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles;
 import org.odftoolkit.odfdom.incubator.doc.style.OdfStyle;
+import org.odftoolkit.odfdom.incubator.doc.style.OdfStylePageLayout;
 import org.odftoolkit.odfdom.incubator.doc.text.OdfTextParagraph;
 import org.odftoolkit.odfdom.pkg.OdfElement;
+import org.odftoolkit.odfdom.type.Color;
+import org.odftoolkit.odfdom.type.Length;
+import org.odftoolkit.odfdom.type.Percent;
+import org.odftoolkit.odfdom.type.Length.Unit;
 import org.odftoolkit.simple.Document.OdfMediaType;
 import org.odftoolkit.simple.chart.Chart;
 import org.odftoolkit.simple.chart.ChartType;
 import org.odftoolkit.simple.chart.DataSet;
 import org.odftoolkit.simple.common.field.VariableField;
+import org.odftoolkit.simple.style.MasterPage;
+import org.odftoolkit.simple.style.NumberFormat;
+import org.odftoolkit.simple.style.StyleTypeDefinitions;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AdjustmentStyle;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.PrintOrientation;
 import org.odftoolkit.simple.table.TableContainer;
 import org.odftoolkit.simple.text.Paragraph;
 import org.odftoolkit.simple.utils.ResourceUtilities;
@@ -83,6 +97,164 @@ public class TextDocumentTest {
 	}
 	
 	@Test
+	public void testAddPagebreakWithMasterPage() {
+		try {
+
+			TextDocument newDoc = TextDocument.newTextDocument();
+
+			// create a new master page
+			Paragraph paragraph = newDoc
+					.addParagraph("before page break - original Landscape");
+			MasterPage master1 = MasterPage.getOrCreateMasterPage(newDoc,
+					"Landscape");
+			master1.setPageWidth(279.4);
+			master1.setPageHeight(215.9);
+			master1.setNumberFormat(NumberFormat.HINDU_ARABIC_NUMBER.toString());
+			master1.setPrintOrientation(PrintOrientation.LANDSCAPE);
+			master1.setFootnoteMaxHeight(0);
+			master1.setWritingMode(StyleTypeDefinitions.WritingMode.LRTB);
+			master1.setMargins(20, 20, 20, 20);
+			master1.setFootnoteSepProperties(AdjustmentStyle.LEFT, Color
+					.valueOf("#000000"), 1, 1, null, Percent.valueOf("25%"),
+					0.18);
+			newDoc.addPageBreak(paragraph, master1);
+			newDoc.addParagraph("after page break - original Landscape");
+			validMasterPageApplied(newDoc, paragraph, master1);
+			newDoc
+					.save(ResourceUtilities
+							.newTestOutputFile("AddPageBreakWithMasterPageOutput1.odt"));
+
+			// modify the master page
+			paragraph = newDoc
+					.addParagraph("before page break - modified Landscape");
+			MasterPage master2 = MasterPage.getOrCreateMasterPage(newDoc,
+					"Landscape");
+			master2.setPageWidth(100);
+			master2.setPageHeight(300);
+			master2.setNumberFormat(null);
+			master2.setPrintOrientation(null);
+			master2.setMargins(20, 20, 0, 0);
+			newDoc.addPageBreak(paragraph, master2);
+			newDoc.addParagraph("after page break - modified Landscape");
+			validMasterPageApplied(newDoc, paragraph, master2);
+
+			// apply existing master page
+			paragraph = newDoc.addParagraph("before page break - Standard");
+			MasterPage master3 = MasterPage.getOrCreateMasterPage(newDoc,
+					"Standard");
+			newDoc.addPageBreak(paragraph, master3);
+			newDoc.addParagraph("after page break - Standard");
+			newDoc.addParagraph("end page");
+			newDoc
+					.save(ResourceUtilities
+							.newTestOutputFile("AddPageBreakWithMasterPageOutput2.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(TextDocumentTest.class.getName()).log(
+					Level.SEVERE, null, e);
+			Assert.fail();
+		}
+	}
+
+	private void validMasterPageApplied(TextDocument newDoc,
+			Paragraph paragraph, MasterPage masterPage) throws Exception {
+		Node paragraphNode = paragraph.getOdfElement().getNextSibling();
+		Assert.assertTrue(paragraphNode instanceof TextPElement);
+
+		// check paragraph style
+		OdfOfficeAutomaticStyles styles = newDoc.getContentDom()
+				.getAutomaticStyles();
+		OdfStyle style = styles.getStyle(((TextPElement) paragraphNode)
+				.getStyleName(), OdfStyleFamily.Paragraph);
+		Assert.assertNotNull(style);
+
+		// check master page style
+		String masterName = style.getStyleMasterPageNameAttribute();
+		StyleMasterPageElement master = newDoc.getOfficeMasterStyles()
+				.getMasterPage(masterName);
+		Assert.assertEquals(masterPage.getName(), masterName);
+		Assert.assertNotNull(master);
+
+		// check page layout style
+		String pageLayoutName = master.getStylePageLayoutNameAttribute();
+		OdfStylePageLayout pageLayout = master.getAutomaticStyles()
+				.getPageLayout(pageLayoutName);
+		Assert.assertNotNull(pageLayout);
+
+		// check page layout properties
+		StylePageLayoutPropertiesElement properties = (StylePageLayoutPropertiesElement) pageLayout
+				.getPropertiesElement(OdfStylePropertiesSet.PageLayoutProperties);
+		Assert.assertNotNull(properties);
+		// page width
+		checkDoubleValue(masterPage.getPageWidth(), properties
+				.getFoPageWidthAttribute());
+		// page height
+		checkDoubleValue(masterPage.getPageHeight(), properties
+				.getFoPageHeightAttribute());
+		// footnote max height
+		checkDoubleValue(masterPage.getFootnoteMaxHeight(), properties
+				.getStyleFootnoteMaxHeightAttribute());
+		// margins
+		checkDoubleValue(masterPage.getMarginTop(), properties
+				.getFoMarginTopAttribute());
+		checkDoubleValue(masterPage.getMarginBottom(), properties
+				.getFoMarginBottomAttribute());
+		checkDoubleValue(masterPage.getMarginLeft(), properties
+				.getFoMarginLeftAttribute());
+		checkDoubleValue(masterPage.getMarginRight(), properties
+				.getFoMarginRightAttribute());
+		// writing mode
+		checkStringValue(masterPage.getWritingMode(), properties
+				.getStyleWritingModeAttribute());
+		// number format
+		checkStringValue(masterPage.getNumberFormat(), properties
+				.getStyleNumFormatAttribute());
+		// print orientation
+		checkStringValue(masterPage.getPrintOrientation(), properties
+				.getStylePrintOrientationAttribute());
+
+		// check footnote separator line
+		StyleFootnoteSepElement footnoteSep = (StyleFootnoteSepElement) properties
+				.getElementsByTagName("style:footnote-sep").item(0);
+		Assert.assertNotNull(footnoteSep);
+		checkStringValue(masterPage.getFootnoteSepAdjustment(), footnoteSep
+				.getStyleAdjustmentAttribute());
+		checkStringValue(masterPage.getFootnoteSepColor(), footnoteSep
+				.getStyleColorAttribute());
+		checkStringValue(masterPage.getFootnoteSepLineStyle(), footnoteSep
+				.getStyleLineStyleAttribute());
+		checkDoubleValue(masterPage.getFootnoteSepDistanceAfterSep(),
+				footnoteSep.getStyleDistanceAfterSepAttribute());
+		checkDoubleValue(masterPage.getFootnoteSepDistanceBeforeSep(),
+				footnoteSep.getStyleDistanceBeforeSepAttribute());
+		checkDoubleValue(masterPage.getFootnoteSepThickness(), footnoteSep
+				.getStyleWidthAttribute());
+		checkDoubleValue(masterPage.getFootnoteSepWidth(), footnoteSep
+				.getStyleRelWidthAttribute());
+	}
+
+	private void checkStringValue(String expected, String actual) {
+		if (expected == null) {
+			Assert.assertNull(actual);
+		} else if (expected.equals("page")) {
+			Assert.assertTrue(actual == null || actual.equals(expected));
+		} else {
+			Assert.assertEquals(expected, actual);
+		}
+	}
+
+	private void checkDoubleValue(double expected, String actual) {
+		double value = 0;
+		if (actual != null) {
+			if (Percent.isValid(actual)) {
+				value = Percent.valueOf(actual).doubleValue();
+			} else {
+				value = Length.parseDouble(actual, Unit.MILLIMETER);
+			}
+		}
+		Assert.assertEquals(expected, value);
+	}
+
+	@Test
 	public void testAddComment() {
 		try {
 			// test new creation document.

Added: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/style/PageLayoutPropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/style/PageLayoutPropertiesTest.java?rev=1406034&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/style/PageLayoutPropertiesTest.java (added)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/style/PageLayoutPropertiesTest.java Tue Nov  6 03:22:57 2012
@@ -0,0 +1,192 @@
+/* 
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+ */
+package org.odftoolkit.simple.style;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+import org.odftoolkit.odfdom.type.Color;
+import org.odftoolkit.odfdom.type.Percent;
+import org.odftoolkit.simple.TextDocument;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AdjustmentStyle;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.LineStyle;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.PrintOrientation;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.WritingMode;
+
+public class PageLayoutPropertiesTest {
+
+	@Test
+	public void testGetSetMargins() {
+
+		try {
+			TextDocument newDoc = TextDocument.newTextDocument();
+			MasterPage master = MasterPage.getOrCreateMasterPage(newDoc,
+					"TestMaster");
+			master.setMargins(10, 20, 0, -5);
+			Assert.assertEquals(9.9996, master.getMarginTop());
+			Assert.assertEquals(19.9992, master.getMarginBottom());
+			Assert.assertEquals(0.0, master.getMarginLeft());
+			Assert.assertEquals(-5.0011, master.getMarginRight());
+
+		} catch (Exception e) {
+			Logger.getLogger(PageLayoutPropertiesTest.class.getName()).log(
+					Level.SEVERE, null, e);
+			Assert.fail();
+		}
+
+	}
+
+	@Test
+	public void testGetSetPageSize() {
+		try {
+			TextDocument newDoc = TextDocument.newTextDocument();
+			MasterPage master = MasterPage.getOrCreateMasterPage(newDoc,
+					"TestMaster");
+			master.setPageWidth(100);
+			master.setPageHeight(300);
+			Assert.assertEquals(100.0009, master.getPageWidth());
+			Assert.assertEquals(300.0003, master.getPageHeight());
+
+			master.setPageWidth(0);
+			master.setPageHeight(-100);
+			Assert.assertEquals(0.0, master.getPageWidth());
+			Assert.assertEquals(-100.0009, master.getPageHeight());
+
+		} catch (Exception e) {
+			Logger.getLogger(PageLayoutPropertiesTest.class.getName()).log(
+					Level.SEVERE, null, e);
+			Assert.fail();
+		}
+	}
+
+	@Test
+	public void testGetSetNumFormat() {
+		try {
+			TextDocument newDoc = TextDocument.newTextDocument();
+			MasterPage master = MasterPage.getOrCreateMasterPage(newDoc,
+					"TestMaster");
+			master.setNumberFormat(NumberFormat.HINDU_ARABIC_NUMBER.toString());
+			Assert.assertEquals(NumberFormat.HINDU_ARABIC_NUMBER.toString(),
+					master.getNumberFormat());
+			master.setNumberFormat("");
+			Assert.assertEquals("", master.getNumberFormat());
+			master.setNumberFormat(null);
+			Assert.assertNull(master.getNumberFormat());
+
+		} catch (Exception e) {
+			Logger.getLogger(PageLayoutPropertiesTest.class.getName()).log(
+					Level.SEVERE, null, e);
+			Assert.fail();
+		}
+	}
+
+	@Test
+	public void testGetSetWritingMode() {
+		try {
+			TextDocument newDoc = TextDocument.newTextDocument();
+			MasterPage master = MasterPage.getOrCreateMasterPage(newDoc,
+					"TestMaster");
+			master.setWritingMode(WritingMode.LRTB);
+			Assert.assertEquals(WritingMode.LRTB.toString(), master
+					.getWritingMode());
+			master.setNumberFormat(null);
+			Assert.assertNull(master.getNumberFormat());
+
+		} catch (Exception e) {
+			Logger.getLogger(PageLayoutPropertiesTest.class.getName()).log(
+					Level.SEVERE, null, e);
+			Assert.fail();
+		}
+	}
+
+	@Test
+	public void testGetSetPrintOrientation() {
+		try {
+			TextDocument newDoc = TextDocument.newTextDocument();
+			MasterPage master = MasterPage.getOrCreateMasterPage(newDoc,
+					"TestMaster");
+			master.setPrintOrientation(PrintOrientation.LANDSCAPE);
+			Assert.assertEquals(PrintOrientation.LANDSCAPE.toString(), master
+					.getPrintOrientation());
+			master.setPrintOrientation(null);
+			Assert.assertNull(master.getPrintOrientation());
+
+		} catch (Exception e) {
+			Logger.getLogger(PageLayoutPropertiesTest.class.getName()).log(
+					Level.SEVERE, null, e);
+			Assert.fail();
+		}
+	}
+	
+	@Test
+	public void testGetSetMax() {
+		try {
+			TextDocument newDoc = TextDocument.newTextDocument();
+			MasterPage master = MasterPage.getOrCreateMasterPage(newDoc,
+					"TestMaster");
+			master.setFootnoteMaxHeight(10);
+			Assert.assertEquals(9.9996, master
+					.getFootnoteMaxHeight());
+			master.setFootnoteMaxHeight(0);
+			Assert.assertEquals(0.0,master.getFootnoteMaxHeight());
+
+		} catch (Exception e) {
+			Logger.getLogger(PageLayoutPropertiesTest.class.getName()).log(
+					Level.SEVERE, null, e);
+			Assert.fail();
+		}
+	}
+
+	@Test
+	public void testGetSetFootnoteSep() {
+		try {
+			TextDocument newDoc = TextDocument.newTextDocument();
+			MasterPage master = MasterPage.getOrCreateMasterPage(newDoc,
+					"TestMaster");
+			master.setFootnoteSepProperties(AdjustmentStyle.CENTER, Color.AQUA,
+					10, 10, LineStyle.DASH_BOLD, Percent.valueOf("15%"), 10);
+			Assert.assertEquals(AdjustmentStyle.CENTER.toString(),master.getFootnoteSepAdjustment());
+			Assert.assertEquals(Color.AQUA.toString(), master.getFootnoteSepColor());
+			Assert.assertEquals(9.9996, master.getFootnoteSepDistanceAfterSep());
+			Assert.assertEquals(9.9996, master.getFootnoteSepDistanceBeforeSep());
+			Assert.assertEquals(LineStyle.DASH_BOLD.toString(), master.getFootnoteSepLineStyle());
+			Assert.assertEquals(0.15, master.getFootnoteSepWidth());
+			Assert.assertEquals(9.9996, master.getFootnoteSepThickness());
+			
+			master.setFootnoteSepProperties(null, null, 0, 0, null, null, 0);
+			Assert.assertEquals(AdjustmentStyle.LEFT.toString(),master.getFootnoteSepAdjustment());
+			Assert.assertNull(master.getFootnoteSepColor());
+			Assert.assertEquals(0.0,master.getFootnoteSepDistanceAfterSep());
+			Assert.assertEquals(0.0,master.getFootnoteSepDistanceBeforeSep());
+			Assert.assertEquals(LineStyle.NONE.toString(),master.getFootnoteSepLineStyle());
+			Assert.assertEquals(0.0, master.getFootnoteSepWidth());
+			Assert.assertEquals(0.0,master.getFootnoteSepThickness());
+			
+
+		} catch (Exception e) {
+			Logger.getLogger(PageLayoutPropertiesTest.class.getName()).log(
+					Level.SEVERE, null, e);
+			Assert.fail();
+		}
+	}
+}



Mime
View raw message