org.odftoolkit.simple.table.TableTemplate Maven / Gradle / Ivy
Show all versions of simple-odf Show documentation
/*
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.table;
import java.util.HashMap;
import org.odftoolkit.odfdom.dom.element.table.TableBodyElement;
import org.odftoolkit.odfdom.dom.element.table.TableEvenColumnsElement;
import org.odftoolkit.odfdom.dom.element.table.TableEvenRowsElement;
import org.odftoolkit.odfdom.dom.element.table.TableFirstColumnElement;
import org.odftoolkit.odfdom.dom.element.table.TableFirstRowElement;
import org.odftoolkit.odfdom.dom.element.table.TableLastColumnElement;
import org.odftoolkit.odfdom.dom.element.table.TableLastRowElement;
import org.odftoolkit.odfdom.dom.element.table.TableOddColumnsElement;
import org.odftoolkit.odfdom.dom.element.table.TableOddRowsElement;
import org.odftoolkit.odfdom.dom.element.table.TableTableTemplateElement;
import org.w3c.dom.NodeList;
/**
* TableTemplate represents the table template feature in ODF documents.
*
* Besides the seven types of style (first row, first column, last row, last
* column, even/odd rows,even/odd columns and body) defined by
* table:table-template
in ODF 1.2, TableTemplate provide extension
* mechnism, which allows user to specify style value to additional cells. For
* example, in ODF 1.2 the four coner cells can only inherit styles from the
* colum or row they are existing, but through TableTemplate.ExtendedStyleType,
* they can reference any style defined in the document.
*
* TableTemplate provide method to get/set a set of references to table cell
* styles that specify the formatting to be used on a table.
*
*/
public class TableTemplate {
private TableTableTemplateElement mElement;
/**
* Extended style types supported by table template.
*
*/
public static enum ExtendedStyleType {
FIRSTROWSTARTCOLUM, FIRSTROWENDCOLUMN, LASTROWSTARTCOLUMN, LASTROWENDCOLUMN
}
HashMap extendedTableStyleMap;
HashMap extendedParagraphStyleMap;
/**
* Create an instance of TableTemplate
*/
protected TableTemplate() {
}
/**
* Create an instance of TableTemplate from an element
*
*
* @param tableTableTemplate
* - the element of table:table-template
*/
public TableTemplate(TableTableTemplateElement tableTableTemplate) {
mElement = tableTableTemplate;
}
/**
* Return the name of table template.
*
* Null will be returned if there is no table template name setting.
*
* @return the table template name.
*/
public String getTableName() {
return mElement.getTableNameAttribute();
}
/**
* Set the name of table template.
*
* If the parameter tableNameValue
is null, the table template
* name definition will be removed.
*
* @param tableNameValue
* - the table template name
*/
public void setTableName(String tableNameValue) {
mElement.setTableNameAttribute(tableNameValue);
}
/**
* get the value of table style specified by type.
*
* Null will be returned if there is no such extended style type setting.
*
* @param type
* - style type
* @return the style name referenced by this style type
*/
public String getExtendedTableStyleByType(ExtendedStyleType type) {
if (extendedTableStyleMap == null)
return null;
return extendedTableStyleMap.get(type);
}
/**
* get the value of paragraph style specified by type.
*
* Null will be returned if there is no such extended style type setting.
*
* @param type
* - extended style type
* @return the style name referenced by this style type
*/
public String getExtendedParagraphStyleByType(ExtendedStyleType type) {
if (extendedParagraphStyleMap == null)
return null;
return extendedParagraphStyleMap.get(type);
}
/**
* set the value of table style and paragraph style specified by type.
*
* @param type
* - extended style type
* @param tableStyle
* - table style name
* @param paraStyle
* - paragraph style name
*/
public void setExtendedStyleByType(ExtendedStyleType type,
String tableStyle, String paraStyle) {
if (extendedTableStyleMap == null) {
extendedTableStyleMap = new HashMap(5);
}
if (extendedParagraphStyleMap == null) {
extendedParagraphStyleMap = new HashMap(
5);
}
extendedTableStyleMap.put(type, tableStyle);
extendedParagraphStyleMap.put(type, paraStyle);
}
/**
* get the value of table style of body.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by table style of body.
*/
public String getTableBodyTableStyle() {
NodeList elements = mElement
.getElementsByTagName(TableBodyElement.ELEMENT_NAME.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableBodyElement) elements.item(0))
.getTableStyleNameAttribute();
}
return null;
}
/**
* get the value of paragraph style of body.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by paragraph style of body.
*/
public String getTableBodyParagraphStyle() {
NodeList elements = mElement
.getElementsByTagName(TableBodyElement.ELEMENT_NAME.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableBodyElement) elements.item(0))
.getTableParagraphStyleNameAttribute();
}
return null;
}
/**
* get the value of table style of even columns.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by table style of even columns.
*/
public String getTableEvenColumnsTableStyle() {
NodeList elements = mElement
.getElementsByTagName(TableEvenColumnsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableEvenColumnsElement) elements.item(0))
.getTableStyleNameAttribute();
}
return null;
}
/**
* get the value of paragraph style of even columns.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by paragraph style of even columns.
*/
public String getTableEvenColumnsParagraphStyle() {
NodeList elements = mElement
.getElementsByTagName(TableEvenColumnsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableEvenColumnsElement) elements.item(0))
.getTableParagraphStyleNameAttribute();
}
return null;
}
/**
* get the value of table style of even rows.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by table style of even rows.
*/
public String getTableEvenRowsTableStyle() {
NodeList elements = mElement
.getElementsByTagName(TableEvenRowsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableEvenRowsElement) elements.item(0))
.getTableStyleNameAttribute();
}
return null;
}
/**
* get the value of paragraph style of even rows.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by paragraph style of even rows.
*/
public String getTableEvenRowsParagraphStyle() {
NodeList elements = mElement
.getElementsByTagName(TableEvenRowsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableEvenRowsElement) elements.item(0))
.getTableParagraphStyleNameAttribute();
}
return null;
}
/**
* get the value of table style of first colum.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by table style of first column.
*/
public String getTableFirstColumnTableStyle() {
NodeList elements = mElement
.getElementsByTagName(TableFirstColumnElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableFirstColumnElement) elements.item(0))
.getTableStyleNameAttribute();
}
return null;
}
/**
* get the value of paragraph style of first column.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by paragraph style of first column.
*/
public String getTableFirstColumnParagraphStyle() {
NodeList elements = mElement
.getElementsByTagName(TableFirstColumnElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableFirstColumnElement) elements.item(0))
.getTableParagraphStyleNameAttribute();
}
return null;
}
/**
* get the value of table style of first row.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by table style of first row.
*/
public String getTableFirstRowTableStyle() {
NodeList elements = mElement
.getElementsByTagName(TableFirstRowElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableFirstRowElement) elements.item(0))
.getTableStyleNameAttribute();
}
return null;
}
/**
* get the value of paragraph style of first row.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by paragraph style of first row.
*/
public String getTableFirstRowParagraphStyle() {
NodeList elements = mElement
.getElementsByTagName(TableFirstRowElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableFirstRowElement) elements.item(0))
.getTableParagraphStyleNameAttribute();
}
return null;
}
/**
* get the value of table style of last column.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by table style of last column.
*/
public String getTableLastColumnTableStyle() {
NodeList elements = mElement
.getElementsByTagName(TableLastColumnElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableLastColumnElement) elements.item(0))
.getTableStyleNameAttribute();
}
return null;
}
/**
* get the value of paragraph style of last column.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by paragraph style of last column.
*/
public String getTableLastColumnParagraphStyle() {
NodeList elements = mElement
.getElementsByTagName(TableLastColumnElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableLastColumnElement) elements.item(0))
.getTableParagraphStyleNameAttribute();
}
return null;
}
/**
* get the value of table style of last row.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by table style of last row.
*/
public String getTableLastRowTableStyle() {
NodeList elements = mElement
.getElementsByTagName(TableLastRowElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableLastRowElement) elements.item(0))
.getTableStyleNameAttribute();
}
return null;
}
/**
* get the value of paragraph style of last row.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by paragraph style of last row.
*/
public String getTableLastRowParagraphStyle() {
NodeList elements = mElement
.getElementsByTagName(TableLastRowElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableLastRowElement) elements.item(0))
.getTableParagraphStyleNameAttribute();
}
return null;
}
/**
* get the value of table style of odd columns.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by table style of odd columns.
*/
public String getTableOddColumnsTableStyle() {
NodeList elements = mElement
.getElementsByTagName(TableOddColumnsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableOddColumnsElement) elements.item(0))
.getTableStyleNameAttribute();
}
return null;
}
/**
* get the value of paragraph style of odd columns.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by paragraph style of odd columns.
*/
public String getTableOddColumnsParagraphStyle() {
NodeList elements = mElement
.getElementsByTagName(TableOddColumnsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableOddColumnsElement) elements.item(0))
.getTableParagraphStyleNameAttribute();
}
return null;
}
/**
* get the value of table style of odd rows.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by table style of odd rows.
*/
public String getTableOddRowsTableStyle() {
NodeList elements = mElement
.getElementsByTagName(TableOddRowsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableOddRowsElement) elements.item(0))
.getTableStyleNameAttribute();
}
return null;
}
/**
* get the value of paragraph style of odd rows.
*
* Null will be returned if there is no such style setting.
*
* @return the style name referenced by paragraph style of odd rows.
*/
public String getTableOddRowsParagraphStyle() {
NodeList elements = mElement
.getElementsByTagName(TableOddRowsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
return ((TableOddRowsElement) elements.item(0))
.getTableParagraphStyleNameAttribute();
}
return null;
}
/**
* Set the value of table style and paragraph style of body.
*
* If the parameter tableStyleNameValue
is null, the table
* style name definition in body will be removed. If the parameter
* tableParagraphStyleNameValue
is null, the paragraph style
* name definition in body will be removed.
*
* @param tableStyleNameValue
* - table style name referenced by body
* @param tableParagraphStyleNameValue
* - paragraph style name referenced by body
*/
public void setTableBodyStyle(String tableStyleNameValue,
String tableParagraphStyleNameValue) {
NodeList elements = mElement
.getElementsByTagName(TableBodyElement.ELEMENT_NAME.getQName());
if (elements != null && elements.getLength() > 0) {
TableBodyElement ele = (TableBodyElement) elements.item(0);
ele.setTableStyleNameAttribute(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
} else {
TableBodyElement ele = mElement
.newTableBodyElement(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
}
}
/**
* Set the value of table style and paragraph style of even columns.
*
* If the parameter tableStyleNameValue
is null, the table
* style name definition in even columns will be removed. If the parameter
* tableParagraphStyleNameValue
is null, the paragraph style
* name definition in even columns will be removed.
*
* @param tableStyleNameValue
* - table style name referenced by even columns
* @param tableParagraphStyleNameValue
* - paragraph style name referenced by even columns
*/
public void setTableEvenColumnsStyle(String tableStyleNameValue,
String tableParagraphStyleNameValue) {
NodeList elements = mElement
.getElementsByTagName(TableEvenColumnsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
TableEvenColumnsElement ele = (TableEvenColumnsElement) elements
.item(0);
ele.setTableStyleNameAttribute(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
} else {
TableEvenColumnsElement ele = mElement
.newTableEvenColumnsElement(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
}
}
/**
* Set the value of table style and paragraph style of even rows.
*
* If the parameter tableStyleNameValue
is null, the table
* style name definition in even rows will be removed. If the parameter
* tableParagraphStyleNameValue
is null, the paragraph style
* name definition in even rows will be removed.
*
* @param tableStyleNameValue
* - table style name referenced by even rows
* @param tableParagraphStyleNameValue
* - paragraph style name referenced by even rows
*/
public void setTableEvenRowsStyle(String tableStyleNameValue,
String tableParagraphStyleNameValue) {
NodeList elements = mElement
.getElementsByTagName(TableEvenRowsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
TableEvenRowsElement ele = (TableEvenRowsElement) elements.item(0);
ele.setTableStyleNameAttribute(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
} else {
TableEvenRowsElement ele = mElement
.newTableEvenRowsElement(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
}
}
/**
* Set the value of table style and paragraph style of first column.
*
* If the parameter tableStyleNameValue
is null, the table
* style name definition in first column will be removed. If the parameter
* tableParagraphStyleNameValue
is null, the paragraph style
* name definition in first column will be removed.
*
* @param tableStyleNameValue
* - table style name referenced by first column
* @param tableParagraphStyleNameValue
* - paragraph style name referenced by first column
*/
public void setTableFirstColumnStyle(String tableStyleNameValue,
String tableParagraphStyleNameValue) {
NodeList elements = mElement
.getElementsByTagName(TableFirstColumnElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
TableFirstColumnElement ele = (TableFirstColumnElement) elements
.item(0);
ele.setTableStyleNameAttribute(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
} else {
TableFirstColumnElement ele = mElement
.newTableFirstColumnElement(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
}
}
/**
* Set the value of table style and paragraph style of first row.
*
* If the parameter tableStyleNameValue
is null, the table
* style name definition in first row will be removed. If the parameter
* tableParagraphStyleNameValue
is null, the paragraph style
* name definition in first row will be removed.
*
* @param tableStyleNameValue
* - table style name referenced by first row
* @param tableParagraphStyleNameValue
* - paragraph style name referenced by first row
*/
public void setTableFirstRowStyle(String tableStyleNameValue,
String tableParagraphStyleNameValue) {
NodeList elements = mElement
.getElementsByTagName(TableFirstRowElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
TableFirstRowElement ele = (TableFirstRowElement) elements.item(0);
ele.setTableStyleNameAttribute(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
} else {
TableFirstRowElement ele = mElement
.newTableFirstRowElement(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
}
}
/**
* Set the value of table style and paragraph style of last column.
*
* If the parameter tableStyleNameValue
is null, the table
* style name definition in last column will be removed. If the parameter
* tableParagraphStyleNameValue
is null, the paragraph style
* name definition in last column will be removed.
*
* @param tableStyleNameValue
* - table style name referenced by last column
* @param tableParagraphStyleNameValue
* - paragraph style name referenced by last column
*/
public void setTableLastColumnStyle(String tableStyleNameValue,
String tableParagraphStyleNameValue) {
NodeList elements = mElement
.getElementsByTagName(TableLastColumnElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
TableLastColumnElement ele = (TableLastColumnElement) elements
.item(0);
ele.setTableStyleNameAttribute(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
} else {
TableLastColumnElement ele = mElement
.newTableLastColumnElement(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
}
}
/**
* Set the value of table style and paragraph style of last row.
*
* If the parameter tableStyleNameValue
is null, the table
* style name definition in last row will be removed. If the parameter
* tableParagraphStyleNameValue
is null, the paragraph style
* name definition in last row will be removed.
*
* @param tableStyleNameValue
* - table style name referenced by last row
* @param tableParagraphStyleNameValue
* - paragraph style name referenced by last row
*/
public void setTableLastRowStyle(String tableStyleNameValue,
String tableParagraphStyleNameValue) {
NodeList elements = mElement
.getElementsByTagName(TableLastRowElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
TableLastRowElement ele = (TableLastRowElement) elements.item(0);
ele.setTableStyleNameAttribute(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
} else {
TableLastRowElement ele = mElement
.newTableLastRowElement(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
}
}
/**
* Set the value of table style and paragraph style of odd columns.
*
* If the parameter tableStyleNameValue
is null, the table
* style name definition in odd columns will be removed. If the parameter
* tableParagraphStyleNameValue
is null, the paragraph style
* name definition in odd columns will be removed.
*
* @param tableStyleNameValue
* - table style name referenced by odd columns
* @param tableParagraphStyleNameValue
* - paragraph style name referenced by odd columns
*/
public void setTableOddColumnsStyle(String tableStyleNameValue,
String tableParagraphStyleNameValue) {
NodeList elements = mElement
.getElementsByTagName(TableOddColumnsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
TableOddColumnsElement ele = (TableOddColumnsElement) elements
.item(0);
ele.setTableStyleNameAttribute(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
} else {
TableOddColumnsElement ele = mElement
.newTableOddColumnsElement(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
}
}
/**
* Set the value of table style and paragraph style of odd rows.
*
* If the parameter tableStyleNameValue
is null, the table
* style name definition in odd rows will be removed. If the parameter
* tableParagraphStyleNameValue
is null, the paragraph style
* name definition in odd rows will be removed.
*
* @param tableStyleNameValue
* - table style name referenced by odd rows
* @param tableParagraphStyleNameValue
* - paragraph style name referenced by odd rows
*/
public void setTableOddRowsStyle(String tableStyleNameValue,
String tableParagraphStyleNameValue) {
NodeList elements = mElement
.getElementsByTagName(TableOddRowsElement.ELEMENT_NAME
.getQName());
if (elements != null && elements.getLength() > 0) {
TableOddRowsElement ele = (TableOddRowsElement) elements.item(0);
ele.setTableStyleNameAttribute(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
} else {
TableOddRowsElement ele = mElement
.newTableOddRowsElement(tableStyleNameValue);
ele
.setTableParagraphStyleNameAttribute(tableParagraphStyleNameValue);
}
}
}