![JAR search and dependency download from the Maven repository](/logo.png)
org.odftoolkit.odfdom.dom.element.text.TextSElement Maven / Gradle / Ivy
Show all versions of odfdom-java Show documentation
/**
* **********************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
*
*
Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
*
*
Use is subject to license terms.
*
*
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. You can also obtain a copy of the License at
* http://odftoolkit.org/docs/license.txt
*
*
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.
*
*
**********************************************************************
*/
/*
* This file is automatically generated.
* Don't edit manually.
*/
package org.odftoolkit.odfdom.dom.element.text;
import org.odftoolkit.odfdom.dom.DefaultElementVisitor;
import org.odftoolkit.odfdom.dom.OdfDocumentNamespace;
import org.odftoolkit.odfdom.dom.attribute.text.TextCAttribute;
import org.odftoolkit.odfdom.pkg.ElementVisitor;
import org.odftoolkit.odfdom.pkg.OdfElement;
import org.odftoolkit.odfdom.pkg.OdfFileDom;
import org.odftoolkit.odfdom.pkg.OdfName;
import org.w3c.dom.Node;
/** DOM implementation of OpenDocument element {@odf.element text:s}. */
public class TextSElement extends OdfElement {
public static final OdfName ELEMENT_NAME = OdfName.newName(OdfDocumentNamespace.TEXT, "s");
/**
* Create the instance of TextSElement
*
* @param ownerDoc The type is OdfFileDom
*/
public TextSElement(OdfFileDom ownerDoc) {
super(ownerDoc, ELEMENT_NAME);
}
/**
* Get the element name
*
* @return return OdfName
the name of element {@odf.element text:s}.
*/
public OdfName getOdfName() {
return ELEMENT_NAME;
}
/**
* Receives the value of the ODFDOM attribute representation TextCAttribute
, See
* {@odf.attribute text:c}
*
* @return - the Integer
, the value or null
, if the attribute is not
* set and no default value defined.
*/
public Integer getTextCAttribute() {
TextCAttribute attr = (TextCAttribute) getOdfAttribute(OdfDocumentNamespace.TEXT, "c");
if (attr != null && !attr.getValue().isEmpty()) {
return Integer.valueOf(attr.intValue());
}
return Integer.valueOf(TextCAttribute.DEFAULT_VALUE);
}
/**
* Sets the value of ODFDOM attribute representation TextCAttribute
, See
* {@odf.attribute text:c}
*
* @param textCValue The type is Integer
*/
public void setTextCAttribute(Integer textCValue) {
TextCAttribute attr = new TextCAttribute((OdfFileDom) this.ownerDocument);
setOdfAttribute(attr);
attr.setIntValue(textCValue.intValue());
}
/**
* Accept an visitor instance to allow the visitor to do some operations. Refer to visitor design
* pattern to get a better understanding.
*
* @param visitor an instance of DefaultElementVisitor
*/
@Override
public void accept(ElementVisitor visitor) {
if (visitor instanceof DefaultElementVisitor) {
DefaultElementVisitor defaultVisitor = (DefaultElementVisitor) visitor;
defaultVisitor.visit(this);
} else {
visitor.visit(this);
}
}
@Override
public boolean isComponentRoot() {
return true;
}
@Override
/** @return the repeation of this element, the default is in ODF always 1 */
public int getRepetition() {
Integer repeated = getTextCAttribute();
if (repeated == null) {
repeated = 1;
}
return repeated;
}
@Override
/** @return if this element is repeatable, by having a repeatable attribute */
public boolean isRepeatable() {
return true;
}
@Override
/** @repetition the repetition number of this attribute */
public void setRepetition(int repetition) {
setTextCAttribute(repetition);
}
/**
* Splitting the element at the given position into two halves
*
* @param posStart The split position. Counting is starting with zero. The start of the second
* half.
* @return the new created second element (or if posStart was less than 1 the original element)
*/
@Override
public TextSElement split(int posStart) {
TextSElement newElement = this;
// 0 would not leave anything left on the left side, would not change anything!
if (posStart > 0) {
newElement = (TextSElement) this.cloneNode(true);
int repeated = getTextCAttribute();
if (repeated > 1) {
if (posStart > 1) {
this.setTextCAttribute(posStart);
} else {
this.removeAttributeNS(OdfDocumentNamespace.TEXT.getUri(), "c");
}
// any higher value one for repeated write out.
// 1 is the default and has not to be written out
if (repeated - posStart > 1) {
newElement.setTextCAttribute(repeated - posStart);
} else {
newElement.removeAttributeNS(OdfDocumentNamespace.TEXT.getUri(), "c");
}
}
Node nextNodeSibling = this.getNextSibling();
OdfElement parent = (OdfElement) this.getParentNode();
if (nextNodeSibling == null) {
parent.appendChild(newElement);
} else {
parent.insertBefore(newElement, nextNodeSibling);
}
}
return newElement;
}
}