| ################################################################## |
| ## |
| ## 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. |
| ## |
| ################################################################## |
| |
| ## Template to create the Java class representing an ODF element |
| ## |
| ## Documentation of template development can be found in local file |
| ## TemplateHelp.html. |
| ## |
| #set ($element = ${model.getElement($context)}) |
| #set ($oldelement = ${oldmodel.getElement($context)}) |
| #set ($NS = ${element.getNamespace()}) |
| #set ($classname = "${model.camelCase($element)}Element") |
| ## |
| ## Set child element and child attributes |
| #set ($children = ${element.getChildElements().withoutMultiples()}) |
| #set ($attributes = ${element.getAttributes().withoutMultiples()}) |
| ## |
| ## Determine whether element is stylable. Set base class OdfElement, OdfStylableElement, or... |
| #if ($odfmodel.isStylable($element)) |
| #set ($stylable = true) |
| #set ($baseclassname = "OdfStylableElement") |
| #set ($elementStyleFamily=${odfmodel.getStyleFamilies($element)}) |
| #set ($useOdfStyleableShapeElement = false) |
| #foreach($f in $elementStyleFamily) |
| #if (${f.getQName()}=="draw:graphic" || ${f.getQName()}=="presentation:presentation") |
| #set ($useOdfStyleableShapeElement = true) |
| #end |
| #end |
| #if ($useOdfStyleableShapeElement) |
| #set ($baseclassname = "OdfStyleableShapeElement") |
| #end |
| #set ($baseHasMandatoryAttr = false) |
| #set ($firstfamily = ${model.camelCase($model.extractLocalname($odfmodel.getStyleFamilies($element).get(0)))}) |
| #else |
| #set ($stylable = false) |
| #set ($baseclassname = "OdfElement") |
| #set ($baseHasMandatoryAttr = false) |
| #end |
| ## |
| ## ...or configured base class |
| #if (${javamodel.getBaseclassOf($element)}) |
| #set ($base = ${javamodel.getBaseclassOf($element)}) |
| ## Configured manually generated base class? |
| #if ($base == "container") |
| #set ($_specialbase = true) |
| #set ($baseclassname = "OdfContainerElementBase") |
| #set ($baseimport = "org.odftoolkit.odfdom.pkg.$baseclassname") |
| #set ($baseHasMandatoryAttr = false) |
| #end |
| #if ($base == "style") |
| #set ($_specialbase = true) |
| #set ($baseclassname = "OdfStyleBase") |
| #set ($baseimport = "org.odftoolkit.odfdom.dom.element.$baseclassname") |
| #set ($baseHasMandatoryAttr = false) |
| #end |
| #if ($base == "styleproperties") |
| #set ($_specialbase = true) |
| #set ($baseclassname = "OdfStylePropertiesBase") |
| #set ($baseimport = "org.odftoolkit.odfdom.dom.element.$baseclassname") |
| #set ($baseHasMandatoryAttr = false) |
| #end |
| ## Configured automatic generated base class. If so, remove all attributes defined in base class |
| #if (!$_specialbase) |
| #set ($baseclassname = "${model.camelCase($base)}ElementBase") |
| #if ($base.getNamespace() != $NS) |
| #set ($baseimport = "org.odftoolkit.odfdom.dom.element.${base.getNamespace()}.$baseclassname") |
| #end |
| #set ($attributes = $attributes.without($base.getBaseAttributes())) |
| #set ($baseElement = ${model.getElement($base.getQName())}) |
| #set ($bAttributes = ${baseElement.getAttributes().withoutMultiples()}) |
| #foreach ($bAttribute in $bAttributes) |
| #if (${baseElement.isMandatory($bAttribute)}) |
| #set ($baseHasMandatoryAttr = true) |
| #end |
| #end |
| #end |
| #end |
| ## |
| ## Test if this element has mandatory (non optional) attributes |
| #set ($hasMandatoryAttr = false) |
| #foreach ($attribute in $attributes) |
| #if (${element.isMandatory($attribute)}) |
| #set ($hasMandatoryAttr = true) |
| #set ($mandatoryAttr = $attribute) |
| #end |
| #end |
| ## |
| ## Begin Code |
| #include('copyright.txt') |
| /* |
| * This file is automatically generated. |
| * Don't edit manually. |
| */ |
| package org.odftoolkit.odfdom.dom.element.${NS}; |
| |
| ## |
| ## --------------------------------------------------- |
| ## Imports |
| ## --------------------------------------------------- |
| ## |
| #if ($stylable) |
| import org.odftoolkit.odfdom.dom.element.OdfStylableElement; |
| import org.odftoolkit.odfdom.dom.element.OdfStyleableShapeElement; |
| import org.odftoolkit.odfdom.dom.style.OdfStyleFamily; |
| #else |
| import org.odftoolkit.odfdom.pkg.OdfElement; |
| #end |
| #if ($base == "styleproperties") |
| import org.odftoolkit.odfdom.dom.style.props.OdfStyleProperty; |
| import org.odftoolkit.odfdom.dom.style.props.OdfStylePropertiesSet; |
| #end |
| import org.odftoolkit.odfdom.pkg.OdfFileDom; |
| import org.odftoolkit.odfdom.pkg.OdfName; |
| import org.odftoolkit.odfdom.dom.OdfDocumentNamespace; |
| #foreach ($child in $children) |
| #if ($child == "*") |
| #set ($anychild = true) |
| #else |
| #set ($childNS = ${child.getNamespace()}) |
| #set ($childClassname = "${model.camelCase($child)}Element") |
| #if ($childNS != $NS) |
| import org.odftoolkit.odfdom.dom.element.${childNS}.$childClassname; |
| #end |
| #end |
| #end |
| ## |
| #foreach ($child in $attributes) |
| #if ($child == "*") |
| #set ($anyattribute = true) |
| #else |
| #set ($childNS = ${child.getNamespace()}) |
| #set ($childClassname = "${model.camelCase($child)}Attribute") |
| import org.odftoolkit.odfdom.dom.attribute.${childNS}.$childClassname; |
| #end |
| #end |
| ## |
| ## If there is a base class which is not in the current package |
| #if ($baseimport) |
| import ${baseimport}; |
| #end |
| |
| ## |
| ## --------------------------------------------------- |
| ## Class |
| ## --------------------------------------------------- |
| ## |
| /** |
| * DOM implementation of OpenDocument element {@odf.element ${context}}. |
| * |
| #if ($anychild) |
| * This class can have any org.w3c.dom.Element child element. |
| #end |
| #if ($anyattribute) |
| * This class can have any org.w3c.dom.Attribute attribute. |
| #end |
| */ |
| public class $classname extends $baseclassname { |
| |
| public static final OdfName ELEMENT_NAME = OdfName.newName(OdfDocumentNamespace.${NS.toUpperCase()}, "${element.getLocalName()}"); |
| |
| /** |
| * Create the instance of <code>$classname</code> |
| * |
| * @param ownerDoc The type is <code>OdfFileDom</code> |
| */ |
| public $classname(OdfFileDom ownerDoc) { |
| #if (($stylable && ($useOdfStyleableShapeElement == false))) |
| super(ownerDoc, ELEMENT_NAME, OdfStyleFamily.${firstfamily}, OdfName.newName(OdfDocumentNamespace.${NS.toUpperCase()}, "style-name")); |
| #else |
| super(ownerDoc, ELEMENT_NAME); |
| #end |
| } |
| |
| /** |
| * Get the element name |
| * |
| * @return return <code>OdfName</code> the name of element {@odf.element ${context}}. |
| */ |
| public OdfName getOdfName() { |
| return ELEMENT_NAME; |
| } |
| ## --------------------------------------------------- |
| ## Only for base = styleproperties |
| ## --------------------------------------------------- |
| #if ($base == "styleproperties") |
| #foreach ($attribute in $attributes) |
| #if ($attribute != "*") |
| #set($propertyName = ${attribute.getLocalName()}) |
| #if (${element.getLocalName()}=="graphic-properties" && $propertyName =="shadow") |
| #set($propertyName = ${attribute.getQName()}) |
| #end |
| |
| public final static OdfStyleProperty ${model.camelCase($propertyName)} = |
| OdfStyleProperty.get(OdfStylePropertiesSet.${model.camelCase($element.getLocalName())}, OdfName.newName(OdfDocumentNamespace.${model.firstWord($attribute).toUpperCase()}, "${attribute.getLocalName()}")); |
| #end |
| #end |
| #end |
| ## |
| ## --------------------------------------------------- |
| ## Add init method if this element or the base |
| ## element has mandatory attributes |
| ## TODO: NO caller use this method. |
| ## --------------------------------------------------- |
| ## |
| ## --------------------------------------------------- |
| ## Attribute getters and setters |
| ## --------------------------------------------------- |
| ## |
| #foreach ($attr in $attributes) |
| #set($attri = ${model.getAttribute($attr.getQName())}) |
| #set ($valueObject = "String") |
| #set ($simpleValue = "") |
| #set ($dataTypes = ${attri.getDatatypes().withoutMultiples()}) |
| #set ($valueTypes = ${javamodel.getValuetypes($dataTypes)}) |
| #foreach ($valueType in $valueTypes) |
| #set ($valueObject = $valueType) |
| #end |
| ## use attri get all of the values. |
| #set($values = ${attri.getValues().withoutMultiples()}) |
| #if ($values.size() ==2 && $dataTypes.size()==0) |
| #set ($trueFlag = false) |
| #set ($falseFlag = false) |
| #foreach ($value in $values) |
| #if ($value==true) |
| #set ($trueFlag = true) |
| #end |
| #if ($value==false) |
| #set ($falseFlag = true) |
| #end |
| #end |
| #if ($trueFlag and $falseFlag) |
| #set ($hasdatatype = true) |
| #set ($valueObject = "Boolean") |
| #end |
| #end |
| #if ($valueObject != "String" && $valueObject != "Double" && $valueObject != "Integer" && $valueObject != "Boolean") |
| #set ($valueObject = "String") |
| #end |
| #if ($valueObject != "String") |
| #set ($simpleValue = ${javamodel.getPrimitiveType($valueObject)}) |
| #end |
| #if ($attr != "*") |
| #set ($attribute = ${attr.withMultiples()}) |
| #set ($aNS = ${attribute.getNamespace()}) |
| #set ($aClassname = "${model.camelCase($attribute)}Attribute") |
| #set ($aParam = "${model.javaCase($attribute)}Value") |
| |
| /** |
| * Receives the value of the ODFDOM attribute representation <code>$aClassname</code> , See {@odf.attribute ${attribute.getQName()}} |
| * |
| #if (${element.isMandatory($attribute)}) |
| * Attribute is mandatory. |
| * |
| #end |
| * @return - the <code>$valueObject</code> , the value or <code>null</code>, if the attribute is not set and no default value defined. |
| */ |
| public $valueObject get${aClassname}() { |
| $aClassname attr = ($aClassname) getOdfAttribute(OdfDocumentNamespace.${aNS.toUpperCase()}, "${attribute.getLocalName()}"); |
| if (attr != null) { |
| #if ($simpleValue!="") |
| return ${valueObject}.valueOf(attr.${simpleValue}Value()); |
| #else |
| return ${valueObject}.valueOf(attr.getValue()); |
| #end |
| } |
| #if ($odfmodel.getDefaultAttributeValue($attribute, $element)) |
| #set ($defaultValue = ${model.escapeLiteral($odfmodel.getDefaultAttributeValue($attribute, $element))}) |
| #set ($defaultValueSet = $odfmodel.getDefaultAttributeValues($attribute)) |
| #if ($defaultValueSet.size()>1) |
| #set ($constant = $model.constantCase($defaultValue)) |
| #if ($valueObject == "String") |
| return ${aClassname}.DEFAULT_VALUE_${model.escapeKeyword($constant)}; |
| #else |
| return ${valueObject}.valueOf(${aClassname}.DEFAULT_VALUE_${model.escapeKeyword($constant)}); |
| #end |
| #else |
| #if ($valueObject == "String") |
| return ${aClassname}.DEFAULT_VALUE; |
| #else |
| return ${valueObject}.valueOf(${aClassname}.DEFAULT_VALUE); |
| #end |
| #end |
| #else |
| return null; |
| #end |
| } |
| |
| /** |
| * Sets the value of ODFDOM attribute representation <code>$aClassname</code> , See {@odf.attribute ${attribute.getQName()}} |
| * |
| * @param $aParam The type is <code>$valueObject</code> |
| */ |
| public void set${aClassname}($valueObject $aParam) { |
| $aClassname attr = new ${aClassname}((OdfFileDom) this.ownerDocument); |
| setOdfAttribute(attr); |
| #if ($valueObject == "String") |
| attr.setValue($aParam); |
| #else |
| attr.set${model.camelCase($simpleValue)}Value($aParam.${simpleValue}Value()); |
| #end |
| } |
| #end |
| #end |
| |
| ## |
| ## --------------------------------------------------- |
| ## Methods for child element creation |
| ## --------------------------------------------------- |
| ## |
| #foreach($ch in $children) |
| #if ($ch != "*") |
| #set ($child = ${ch.withMultiples()}) |
| #set ($cClassname = "${model.camelCase($child)}Element") |
| #set ($cVar = ${model.javaCase($child)}) |
| #set ($ch_attributes = ${child.getAttributes().withoutMultiples()}) |
| ##set has parameter flag |
| #set ($hasParams = false) |
| #foreach ($ch_attribute in $ch_attributes) |
| #if (${child.isMandatory($ch_attribute)}) |
| #set ($hasParams = true) |
| #end |
| #end |
| #if ($hasParams) |
| /** |
| * Create child element {@odf.element ${child}}. |
| * |
| #set ($seperateFlag="") |
| #set ($params="") |
| #foreach ($ch_attr in $ch_attributes) |
| #if (${child.isMandatory($ch_attr)}) |
| #set($ch_attri = ${model.getAttribute($ch_attr.getQName())}) |
| #set ($ch_ValueObject = "String") |
| #set ($ch_SimpleValue = "") |
| #set ($ch_DataTypes = ${ch_attri.getDatatypes().withoutMultiples()}) |
| #set ($ch_ValueTypes = ${javamodel.getValuetypes($ch_DataTypes)}) |
| #foreach ($ch_ValueType in $ch_ValueTypes) |
| #set ($ch_ValueObject = $ch_ValueType) |
| #end |
| ## use ch_attri get all of the values. |
| #set($ch_Values = ${ch_attri.getValues().withoutMultiples()}) |
| #if ($ch_Values.size() ==2 && $ch_DataTypes.size()==0) |
| #set ($trueFlag = false) |
| #set ($falseFlag = false) |
| #foreach ($ch_Value in $ch_Values) |
| #if ($ch_Value==true) |
| #set ($trueFlag = true) |
| #end |
| #if ($ch_Value==false) |
| #set ($falseFlag = true) |
| #end |
| #end |
| #if ($trueFlag and $falseFlag) |
| #set ($ch_Hasdatatype = true) |
| #set ($ch_ValueObject = "Boolean") |
| #end |
| #end |
| #if ($ch_ValueObject != "String" && $ch_ValueObject != "Double" && $ch_ValueObject != "Integer" && $ch_ValueObject != "Boolean") |
| #set ($ch_ValueObject = "String") |
| #end |
| #if ($ch_ValueObject != "String") |
| #set ($ch_SimpleValue = ${javamodel.getPrimitiveType($ch_ValueObject)}) |
| #end |
| #if ($ch_attr != "*") |
| #set ($attribute = ${ch_attr.withMultiples()}) |
| #set ($aNS = ${attribute.getNamespace()}) |
| #set ($aClassname = "${model.camelCase($attribute)}Attribute") |
| #set ($aParam = "${model.javaCase($attribute)}Value") |
| * @param $aParam the <code>$ch_ValueObject</code> value of <code>$aClassname</code>, see {@odf.attribute ${attribute.getQName()}} at specification |
| #if ($ch_SimpleValue!="") |
| #set ($params="${params}${seperateFlag}${ch_SimpleValue} ${aParam}") |
| #else |
| #set ($params="${params}${seperateFlag}${ch_ValueObject} ${aParam}") |
| #end |
| #set ($seperateFlag=", ") |
| #end |
| #end |
| #end |
| ## Compare element from old and new Spec. A direct comparison is not possible (both encapsulate different RelaxNG Expressions) |
| ## but we can compare by name |
| #if (!$oldelement || !${oldelement.getChildElements().containsName($child)}) |
| * Child element is new in Odf 1.2 |
| * |
| #end |
| #if (${element.isMandatory($child)}) |
| * Child element is mandatory. |
| * |
| #end |
| * @return the element {@odf.element ${child}} |
| */ |
| public $cClassname new${cClassname}($params) { |
| $cClassname $cVar = ((OdfFileDom) this.ownerDocument).newOdfElement(${cClassname}.class); |
| #foreach ($ch_attr in $ch_attributes) |
| #if ($ch_attr != "*" && ${child.isMandatory($ch_attr)}) |
| #set ($aClassname = "${model.camelCase($ch_attr)}Attribute") |
| #set ($aParam = "${model.javaCase($ch_attr)}Value") |
| ${cVar}.set$aClassname($aParam); |
| #end |
| #end |
| this.appendChild($cVar); |
| return $cVar; |
| } |
| |
| #else |
| /** |
| * Create child element {@odf.element ${child}}. |
| * |
| ## Compare element from old and new Spec. A direct comparison is not possible (both encapsulate different RelaxNG Expressions) |
| ## but we can compare by name |
| #if (!$oldelement || !${oldelement.getChildElements().containsName($child)}) |
| * Child element is new in Odf 1.2 |
| * |
| #end |
| #if (${element.isMandatory($child)}) |
| * Child element is mandatory. |
| * |
| #end |
| * @return the element {@odf.element ${child}} |
| */ |
| public $cClassname new${cClassname}() { |
| $cClassname $cVar = ((OdfFileDom) this.ownerDocument).newOdfElement(${cClassname}.class); |
| this.appendChild($cVar); |
| return $cVar; |
| } |
| |
| #end |
| #end |
| #end |
| ## |
| ## ----------------------------------------------------- |
| ## New: newTextNode |
| ## ----------------------------------------------------- |
| ## |
| #if ($element.canHaveText()) |
| /** |
| * Add text content. Only elements which are allowed to have text content offer this method. |
| */ |
| public void newTextNode(String content) { |
| if (content != null && !content.equals("")) { |
| this.appendChild(this.getOwnerDocument().createTextNode(content)); |
| } |
| } |
| #end |
| } |