-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathvelocity-macros.vm
More file actions
143 lines (133 loc) · 5.73 KB
/
Copy pathvelocity-macros.vm
File metadata and controls
143 lines (133 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
## see https://velocity.apache.org/engine/2.3/user-guide.html#velocimacros
## For highlighting use VisualStudioCode plugin - https://marketplace.visualstudio.com/items?itemName=Quidgest.vscode-velocity
## Using .vm file suffix instead of .vtl suffix for the above plugin
##
##
## Addes the functionality of ODF repetition
#macro( add_repeated_methods $elementClassName $repetitionAttribute)
#set ($attrClassName = "${xmlModel.camelCase($repetitionAttribute)}Attribute")
#set ($attrNamespacePrefix = ${repetitionAttribute.getNamespacePrefix()})
@Override
/** @return the repeation of this element, the default is in ODF always 1 */
public int getRepetition() {
Integer repeated = get${attrClassName}();
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) {
set${attrClassName}(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 ${elementClassName} split(int posStart) {
${elementClassName} newElement = this;
// 0 would not leave anything left on the left side, would not change anything!
if (posStart > 0) {
newElement = (${elementClassName}) this.cloneNode(true);
int repeated = get${attrClassName}();
if (repeated > 1) {
if (posStart > 1) {
this.set${attrClassName}(posStart);
} else {
this.removeAttributeNS(OdfDocumentNamespace.${attrNamespacePrefix.toUpperCase()}.getUri(), "${repetitionAttribute.getLocalName()}");
}
// any higher value one for repeated write out.
// 1 is the default and has not to be written out
if (repeated - posStart > 1) {
newElement.set${attrClassName}(repeated - posStart);
} else {
newElement.removeAttributeNS(OdfDocumentNamespace.${attrNamespacePrefix.toUpperCase()}.getUri(), "${repetitionAttribute.getLocalName()}");
}
}
Node nextNodeSibling = this.getNextSibling();
OdfElement parent = (OdfElement) this.getParentNode();
if (nextNodeSibling == null) {
parent.appendChild(newElement);
} else {
parent.insertBefore(newElement, nextNodeSibling);
}
}
return newElement;
}
#end
## Add is Component Root functionality
#macro( add_isComponentRoot_method )
## /**
## * Marks this element as the root of a semantic component known to the user.
## */
@Override
public boolean isComponentRoot() {
return true;
}
#end
## Add special split funcationality for ParagraphBase
#macro( add_paragraphBase_split_method )
/**
* Splitting the element at the given position into two halves
*
* <p>If the paragraph does have an automatic style with a master-page, which results into a page
* break before the paragraph, this page break will be removed for the new second half. For
* paragraph containing template styles the follow-up style should be chosen.
*
* @param posStart The logical position of the first character (or other paragraph child
* component) that will be moved to the beginning of the new paragraph.
* @return the new created second text container
*/
@Override
public OdfElement split(int posStart) {
TextParagraphElementBase newSecondElement = (TextParagraphElementBase) super.split(posStart);
OdfStyle autoStyle = newSecondElement.getAutomaticStyle();
if (autoStyle != null) {
OdfStylePropertiesBase paragraphProps =
autoStyle.getPropertiesElement(OdfStylePropertiesSet.ParagraphProperties);
if (autoStyle.getStyleMasterPageNameAttribute() != null || paragraphProps != null) {
StyleStyleElement newStyle = newSecondElement.getOrCreateUnqiueAutomaticStyle();
if (autoStyle.getStyleMasterPageNameAttribute() != null) {
newStyle.removeAttributeNS(OdfDocumentNamespace.STYLE.getUri(), "master-page-name");
}
// overwrite the paragraph properties from the source one, with the cloned element's
paragraphProps = newStyle.getPropertiesElement(OdfStylePropertiesSet.ParagraphProperties);
// no paragraph page break should be inherited
if (paragraphProps != null) {
paragraphProps.removeAttributeNS(OdfDocumentNamespace.FO.getUri(), "break-before");
paragraphProps.removeAttributeNS(OdfDocumentNamespace.FO.getUri(), "break-after");
}
}
}
return newSecondElement;
}
#end
## Removes all the content from the element (typically cell, which holds content by attribute)
#macro( add_removeContent_method)
/** Removes all the content from the element */
@Override
public void removeContent() {
super.removeContent();
this.removeAttributeNS(OdfDocumentNamespace.OFFICE.getUri(), "value");
this.removeAttributeNS(OdfDocumentNamespace.OFFICE.getUri(), "value-type");
this.removeAttributeNS(OdfDocumentNamespace.OFFICE.getUri(), "time-value");
this.removeAttributeNS(OdfDocumentNamespace.OFFICE.getUri(), "date-value");
this.removeAttributeNS(OdfDocumentNamespace.OFFICE.getUri(), "boolean-value");
this.removeAttributeNS("urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0", "value-type");
this.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "formula");
}
#end
## Add table cell border helper functionality
#macro( add_tableCellHelper_methods )
#include('java-odfdom-table-cell-helper.txt')
#end