All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.odftoolkit.odfdom.changes.Row Maven / Gradle / Ivy

Go to download

ODFDOM is an OpenDocument Format (ODF) framework. Its purpose is to provide an easy common way to create, access and manipulate ODF files, without requiring detailed knowledge of the ODF specification. It is designed to provide the ODF developer community with an easy lightwork programming API portable to any object-oriented language. The current reference implementation is written in Java.

There is a newer version: 1.0.0-BETA1
Show newest version
/*
 * Copyright 2012 The Apache Software Foundation.
 *
 * Licensed 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.odfdom.changes;

import org.odftoolkit.odfdom.pkg.OdfElement;
import org.w3c.dom.Node;

/**
 * A MultiCoomponent uses a single XML element to represent multiple components. This container can
 * be used for spreadsheet row and cell components using repeated elements via an attribute.
 *
 * @author svante.schubertATgmail.com
 */
public class Row extends Component {

  public Row(OdfElement componentElement, Component parent) {
    super(componentElement, parent);
  }

  /**
   * A multiple components can be represented by a single XML element
   *
   * @return the number of components the elements represents
   */
  @Override
  public int repetition() {
    return mRootElement.getRepetition();
  }

  // CELL ONLY
  //	Map mInnerCellStyle = null;
  //
  //	/** The inner style of a cell will be temporary saved at the cell.
  //	 Whenever the cell content is deleted, the style is being merged/applied to the cell style */
  //	public Map getInternalCellStyle(){
  //		return mInnerCellStyle;
  //	}
  //
  //
  //	/** The inner style of a cell will be temporary saved at the cell.
  //	 Whenever the cell content is deleted, the style is being merged/applied to the cell style */
  //	public void setInternalCellStyle(Map newStyles){
  //		mInnerCellStyle = newStyles;
  //	}
  //
  /** Adds the given component to the root element */
  @Override
  public void addChild(int index, Component c) {
    mRootElement.insert(c.getRootElement(), index);
    // 2DO: Svante: ARE THE ABOVE AND THE BELOW EQUIVALENT?
    //		OdfElement rootElement = c.getRootElement();
    //		if (index >= 0) {
    //			mRootElement.insertBefore(rootElement, ((OdfElement) mRootElement).receiveNode(index));
    //		} else {
    //			mRootElement.appendChild(rootElement);
    //		}
  }

  /** @return either a text node of size 1 or an element being the root element of a component */
  @Override
  public Node getChildNode(int index) {
    return ((OdfElement) mRootElement).receiveNode(index);
  }

  /**
   * Removes a component from the text element container. Removes either an element representing a
   * component or text node of size 1
   */
  @Override
  public Node remove(int index) {
    Node node = (Node) this.getChildNode(index);
    return mRootElement.removeChild(node);
  }

  /**
   * All children of the root element will be traversed. If it is a text node the size is added, if
   * it is an element and a component a size of one is added, if it is a marker, for known text
   * marker elements (text:span, text:bookmark) the children are recursive checked
   *
   * @return the number of child components
   */
  @Override
  public int size() {
    return mRootElement.countDescendantComponents();
  }
  //	DELETE ME!!
  //	/**
  //	 * Inserts a component at the given position as child
  //	 *
  //	 * @param position of the component, a -1 is going to append the element
  //	 */
  //	public TableCellComponent createChildComponent(int position) {
  //		OdfTableRow tableRow = OdfTableRow.getInstance((TableTableRowElement) mRootElement);
  //		OdfElement cellElement = tableRow.getCellByIndex(position).getOdfElement();
  //		if(position > -1 && cellElement == null){
  //			// create the missing element and all its precessors
  //			System.out.println("yeah!");
  //		}
  //		TableCellComponent c = (TableCellComponent) cellElement.getComponent();
  //		if(c == null){
  //			(TableCellComponent) Component.createChildComponent(position, this, cellElement);
  //		}
  //		return c;
  //	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy