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
143
144
145
146
147
148
149
150
151
152
153
154
|
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lxslt="http://xml.apache.org/xslt"
xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
extension-element-prefixes="redirect">
<xsl:output method="text" />
<xsl:variable name="prefixVal">
<xsl:value-of select="//elements/@prefix"/>
</xsl:variable>
<xsl:template name="capfirst">
<xsl:param name="str"/>
<xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:value-of select="concat(translate(substring($str, 1, 1),
$lcletters, $ucletters), substring($str, 2))"/>
</xsl:template>
<xsl:template name="capall">
<xsl:param name="str"/>
<xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:value-of select="translate($str,
$lcletters, $ucletters)"/>
</xsl:template>
<xsl:template name="makeClassName">
<xsl:param name="propstr"/>
<xsl:choose>
<xsl:when test="contains($propstr, '-')">
<xsl:call-template name="capfirst">
<xsl:with-param name="str" select="substring-before($propstr, '-')"/>
</xsl:call-template>
<xsl:call-template name="makeClassName">
<xsl:with-param name="propstr" select="substring-after($propstr, '-')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="capfirst">
<xsl:with-param name="str" select="$propstr"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="attributes"><xsl:apply-templates/></xsl:template>
<xsl:template match="includeAttributes">
<xsl:variable name="attr-ref">
<xsl:value-of select="@ref"/>
</xsl:variable>
<xsl:for-each select="/elements/commonAttributes">
<xsl:choose>
<xsl:when test="@ref = $attr-ref">
<xsl:apply-templates/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template match="attribute">"<xsl:apply-templates/>"<xsl:if test="not(position()=last())">, </xsl:if></xsl:template>
<xsl:template match="elements">
<xsl:apply-templates select="element"/>
</xsl:template>
<xsl:template match="tagname">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="element">
<xsl:variable name="name">
<xsl:apply-templates select="tagname"/>
</xsl:variable>
<xsl:variable name="classname">
<xsl:choose>
<xsl:when test="class-name">
<xsl:value-of select="class-name"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="makeClassName">
<xsl:with-param name="propstr" select="$name"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<redirect:write select="concat('@org/apache/fop@/{$prefixVal}/', $classname, '.java')">
package org.apache.fop.<xsl:value-of select="$prefixVal"/>;
import org.apache.fop.fo.*;
import org.apache.fop.layout.Area;
import org.apache.fop.layout.FontState;
import org.apache.fop.apps.FOPException;
import org.w3c.dom.Element;
public class <xsl:value-of select="$classname"/> extends <xsl:call-template name="capall"><xsl:with-param name="str" select="$prefixVal"/></xsl:call-template>Obj {
/**
* inner class for making <xsl:apply-templates select="tagname"/> objects.
*/
public static class Maker extends FObj.Maker {
/**
* make a <xsl:apply-templates select="tagname"/> object.
*
* @param parent the parent formatting object
* @param propertyList the explicit properties of this object
*
* @return the <xsl:apply-templates select="tagname"/> object
*/
public FObj make(FObj parent,
PropertyList propertyList) throws FOPException {
return new <xsl:value-of select="$classname"/>(parent, propertyList);
}
}
/**
* returns the maker for this object.
*
* @return the maker for <xsl:apply-templates select="tagname"/> objects
*/
public static FObj.Maker maker() {
return new <xsl:value-of select="$classname"/>.Maker();
}
/**
* constructs a <xsl:apply-templates select="tagname"/> object (called by Maker).
*
* @param parent the parent formatting object
* @param propertyList the explicit properties of this object
*/
protected <xsl:value-of select="$classname"/>(FObj parent, PropertyList propertyList) {
super(parent, propertyList);
this.name = "<xsl:value-of select="//@prefix"/>:<xsl:value-of select="$name"/>";
tagName = "<xsl:value-of select="$name"/>";
props = new String[] {<xsl:apply-templates select="attributes"/>};
}
<xsl:if test="@addText">
protected void addCharacters(char data[], int start, int length) {
this.children.addElement(new String(data, start, length - start));
}
</xsl:if>
}
</redirect:write>
</xsl:template>
</xsl:stylesheet>
|