Sfoglia il codice sorgente

Add keep properties as compound; handle enumeration types in subproperties; add corresponding properties; handle enumeration plus base property type; update dtd


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193944 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-0_17_0
Karen Lease 23 anni fa
parent
commit
bc77d284c5

+ 76
- 3
src/codegen/enumgen.xsl Vedi File

@@ -25,24 +25,97 @@
</xsl:choose>
</xsl:variable>
<xsl:variable name="bEnum">
<xsl:call-template name="isEnum"/>
<xsl:call-template name="hasEnum"/>
</xsl:variable>
<xsl:if test="$bEnum='true'">
<xsl:variable name="bSubpropEnum">
<xsl:call-template name="hasSubpropEnum"/>
</xsl:variable>

<xsl:if test="$bEnum='true' or contains($bSubpropEnum, 'true')">
<redirect:write select="concat('@org/apache/fop@/fo/properties/', $classname, '.java')">
package org.apache.fop.fo.properties;

<!-- Handle enumeration values -->
public interface <xsl:value-of select="$classname"/>
<xsl:if test="use-generic">
<xsl:if test="use-generic and $bEnum='true'">
extends <xsl:value-of select="use-generic"/>.Enums
</xsl:if>{
<xsl:for-each select="enumeration/value">
public final static int <xsl:value-of select="@const"/> = <xsl:number/>;
</xsl:for-each>
<xsl:if test="contains($bSubpropEnum, 'true')">
<xsl:call-template name="genSubpropEnum"/>
</xsl:if>
}
</redirect:write>
</xsl:if>
</xsl:template>

<xsl:template name="genSubpropEnum">
<xsl:param name="prop" select="."/>
<xsl:choose>
<xsl:when test="$prop/compound/subproperty/enumeration">
<xsl:for-each select="compound/subproperty[enumeration]">
public interface <xsl:value-of select="name"/> {
<xsl:for-each select="enumeration/value">
public final static int <xsl:value-of select="@const"/> = <xsl:number/>;
</xsl:for-each>
}
</xsl:for-each>
</xsl:when>
<xsl:when test="$prop/use-generic">
<xsl:call-template name="inhspenums">
<xsl:with-param name="prop" select="key('genericref', $prop/use-generic)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$prop/compound/subproperty/use-generic">
<!-- generate "interface <subprop> extends <gensubprop>.Enums" -->
<xsl:for-each select="$prop/compound/subproperty[use-generic]">
<xsl:variable name="bSpEnum">
<xsl:call-template name="hasEnum">
<xsl:with-param name="prop"
select="key('genericref', use-generic)"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$bSpEnum='true'">
public interface <xsl:value-of select="name"/> extends <xsl:value-of select="use-generic"/>.Enums { }
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="inhspenums">
<xsl:param name="prop"/>
<xsl:variable name="generic_name">
<xsl:choose>
<xsl:when test="$prop/class-name">
<xsl:value-of select="$prop/class-name"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="makeClassName">
<xsl:with-param name="propstr" select="$prop/name"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- generate "interface <subprop> extends <genprop>.<subprop>" -->
<xsl:for-each select="$prop/compound/subproperty[enumeration]">
<xsl:variable name="spname">
<xsl:call-template name="makeClassName">
<xsl:with-param name="propstr" select="name"/>
</xsl:call-template>
</xsl:variable>
public interface <xsl:value-of select="$spname"/> extends <xsl:value-of select="$generic_name"/>.Enums.<xsl:value-of select="$spname"/> {
}
</xsl:for-each>
<xsl:if test="$prop/use-generic">
<xsl:call-template name="inhspenums">
<xsl:with-param name="prop" select="key('genericref', $prop/use-generic)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

+ 204
- 14
src/codegen/foproperties.xml Vedi File

@@ -20,23 +20,36 @@
<property type="generic">
<name>generic-keep</name>
<class-name>GenericKeep</class-name>
<datatype>Number</datatype>
<keyword-equiv match="auto" eval="true">0</keyword-equiv>
<keyword-equiv match="always" eval="true">-1</keyword-equiv>
<!-- <compound>
<subproperty>
<datatype>Keep</datatype> <!-- CompoundDatatype -->
<compound>
<subproperty set-by-shorthand="true">
<name>within-page</name>
<datatype>Number</datatype>
<datatype>Number</datatype>
<default>auto</default>
<enumeration>
<value const="AUTO">auto</value>
<value const="ALWAYS">always</value>
</enumeration>
</subproperty>
<subproperty>
<subproperty set-by-shorthand="true">
<name>within-line</name>
<datatype>Number</datatype>
<datatype>Number</datatype>
<default>auto</default>
<enumeration>
<value const="AUTO">auto</value>
<value const="ALWAYS">always</value>
</enumeration>
</subproperty>
<subproperty>
<subproperty set-by-shorthand="true">
<name>within-column</name>
<datatype>Number</datatype>
<datatype>Number</datatype>
<default>auto</default>
<enumeration>
<value const="AUTO">auto</value>
<value const="ALWAYS">always</value>
</enumeration>
</subproperty>
</compound>-->
</compound>
</property>
<property type="generic">
<name>conditional-length-template</name>
@@ -49,7 +62,11 @@
</subproperty>
<subproperty>
<name>conditionality</name>
<datatype>String</datatype> <!-- NCName or Enum ??? -->
<datatype>Enum</datatype>
<enumeration>
<value const="DISCARD">discard</value>
<value const="RETAIN">retain</value>
</enumeration>
</subproperty>
</compound>
</property>
@@ -91,8 +108,12 @@
<default>medium</default>
</subproperty>
<subproperty>
<datatype>Enum</datatype>
<name>conditionality</name>
<datatype>String</datatype> <!-- NCName or Enum ??? -->
<enumeration>
<value const="DISCARD">discard</value>
<value const="RETAIN">retain</value>
</enumeration>
</subproperty>
</compound>
</property>
@@ -164,11 +185,18 @@
<subproperty>
<name>precedence</name>
<datatype>Number</datatype>
<enumeration>
<value const="FORCE">force</value>
</enumeration>
<default>0</default>
</subproperty>
<subproperty>
<name>conditionality</name>
<datatype>String</datatype> <!-- NCName or Enum ??? -->
<datatype>Enum</datatype>
<enumeration>
<value const="DISCARD">discard</value>
<value const="RETAIN">retain</value>
</enumeration>
<default>discard</default>
</subproperty>
</compound>
@@ -186,6 +214,14 @@
<inherited>true</inherited>
<datatype>Length</datatype>
<default>0pt</default>
<corresponding use-if-specified="true">
<propval>margin-<wmrel2abs dir="START"/></propval>
<propexpr>
<propval>margin-<wmrel2abs dir="START"/></propval>+
<propval>padding-<wmrel2abs dir="START"/></propval>+
<propval>border-<wmrel2abs dir="START"/>-width</propval>
</propexpr>
</corresponding>
</property>
<property>
<name>font-style</name>
@@ -258,6 +294,14 @@
<inherited>true</inherited>
<datatype>Length</datatype>
<default>0pt</default>
<corresponding use-if-specified="true">
<propval>margin-<wmrel2abs dir="END"/></propval>
<propexpr>
<propval>margin-<wmrel2abs dir="END"/></propval>+
<propval>padding-<wmrel2abs dir="END"/></propval>+
<propval>border-<wmrel2abs dir="END"/>-width</propval>
</propexpr>
</corresponding>
</property>
<property>
<name>color</name>
@@ -456,37 +500,61 @@
<name>padding-before</name>
<use-generic>GenericCondPadding</use-generic>
<default subproperty="conditionality">retain</default>
<corresponding use-if-specified="true">
<propval>padding-<wmrel2abs dir="BEFORE"/></propval>
</corresponding>
</property>
<property>
<name>padding-after</name>
<use-generic>GenericCondPadding</use-generic>
<default subproperty="conditionality">retain</default>
<corresponding use-if-specified="true">
<propval>padding-<wmrel2abs dir="AFTER"/></propval>
</corresponding>
</property>
<property>
<name>padding-start</name>
<use-generic>GenericCondPadding</use-generic>
<default subproperty="conditionality">discard</default>
<corresponding use-if-specified="true">
<propval>padding-<wmrel2abs dir="START"/></propval>
</corresponding>
</property>
<property>
<name>padding-end</name>
<use-generic>GenericCondPadding</use-generic>
<default subproperty="conditionality">discard</default>
<corresponding use-if-specified="true">
<propval>padding-<wmrel2abs dir="END"/></propval>
</corresponding>
</property>
<property>
<name>padding-top</name>
<use-generic>GenericPadding</use-generic>
<corresponding>
<propval>padding-<wmabs2rel dir="TOP"/></propval>
</corresponding>
</property>
<property>
<name>padding-left</name>
<use-generic>GenericPadding</use-generic>
<corresponding>
<propval>padding-<wmabs2rel dir="LEFT"/></propval>
</corresponding>
</property>
<property>
<name>padding-bottom</name>
<use-generic>GenericPadding</use-generic>
<corresponding>
<propval>padding-<wmabs2rel dir="BOTTOM"/></propval>
</corresponding>
</property>
<property>
<name>padding-right</name>
<use-generic>GenericPadding</use-generic>
<corresponding>
<propval>padding-<wmabs2rel dir="RIGHT"/></propval>
</corresponding>
</property>
<property>
<name>external-destination</name>
@@ -505,116 +573,188 @@
<inherited>false</inherited>
<use-generic>GenericColor</use-generic>
<default>black</default>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="BEFORE"/>-color</propval>
</corresponding>
</property>
<property>
<name>border-before-style</name>
<use-generic>GenericBorderStyle</use-generic>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="BEFORE"/>-style</propval>
</corresponding>
</property>
<property>
<name>border-before-width</name>
<use-generic>GenericCondBorderWidth</use-generic>
<default subproperty="conditionality">retain</default>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="BEFORE"/>-width</propval>
</corresponding>
</property>
<property>
<name>border-after-color</name>
<inherited>false</inherited>
<use-generic>GenericColor</use-generic>
<default>black</default>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="AFTER"/>-color</propval>
</corresponding>
</property>
<property>
<name>border-after-style</name>
<use-generic>GenericBorderStyle</use-generic>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="AFTER"/>-style</propval>
</corresponding>
</property>
<property>
<name>border-after-width</name>
<use-generic>GenericCondBorderWidth</use-generic>
<default subproperty="conditionality">retain</default>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="AFTER"/>-width</propval>
</corresponding>
</property>
<property>
<name>border-start-color</name>
<inherited>false</inherited>
<use-generic>GenericColor</use-generic>
<default>black</default>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="START"/>-color</propval>
</corresponding>
</property>
<property>
<name>border-start-style</name>
<use-generic>GenericBorderStyle</use-generic>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="START"/>-style</propval>
</corresponding>
</property>
<property>
<name>border-start-width</name>
<use-generic>GenericCondBorderWidth</use-generic>
<default subproperty="conditionality">discard</default>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="START"/>-width</propval>
</corresponding>
</property>
<property>
<name>border-end-color</name>
<inherited>false</inherited>
<use-generic>GenericColor</use-generic>
<default>black</default>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="END"/>-color</propval>
</corresponding>
</property>
<property>
<name>border-end-style</name>
<use-generic>GenericBorderStyle</use-generic>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="END"/>-style</propval>
</corresponding>
</property>
<property>
<name>border-end-width</name>
<use-generic>GenericCondBorderWidth</use-generic>
<default subproperty="conditionality">discard</default>
<corresponding use-if-specified="true">
<propval>border-<wmrel2abs dir="END"/>-width</propval>
</corresponding>
</property>
<property>
<name>border-top-color</name>
<inherited>false</inherited>
<use-generic>GenericColor</use-generic>
<default>black</default>
<corresponding>
<propval>border-<wmabs2rel dir="TOP"/>-color</propval>
</corresponding>
</property>
<property>
<name>border-top-style</name>
<use-generic>GenericBorderStyle</use-generic>
<corresponding>
<propval>border-<wmabs2rel dir="TOP"/>-style</propval>
</corresponding>
</property>
<property>
<name>border-top-width</name>
<use-generic>GenericBorderWidth</use-generic>
<corresponding>
<propval>border-<wmabs2rel dir="TOP"/>-width</propval>
</corresponding>
</property>
<property>
<name>border-bottom-color</name>
<inherited>false</inherited>
<use-generic>GenericColor</use-generic>
<corresponding>
<propval>border-<wmabs2rel dir="BOTTOM"/>-color</propval>
</corresponding>
<default>black</default>
</property>
<property>
<name>border-bottom-style</name>
<use-generic>GenericBorderStyle</use-generic>
<corresponding>
<propval>border-<wmabs2rel dir="BOTTOM"/>-style</propval>
</corresponding>
</property>
<property>
<name>border-bottom-width</name>
<use-generic>GenericBorderWidth</use-generic>
<corresponding>
<propval>border-<wmabs2rel dir="BOTTOM"/>-width</propval>
</corresponding>
</property>
<property>
<name>border-left-color</name>
<inherited>false</inherited>
<use-generic>GenericColor</use-generic>
<default>black</default>
<corresponding>
<propval>border-<wmabs2rel dir="LEFT"/>-color</propval>
</corresponding>
</property>
<property>
<name>border-left-style</name>
<use-generic>GenericBorderStyle</use-generic>
<corresponding>
<propval>border-<wmabs2rel dir="LEFT"/>-style</propval>
</corresponding>
</property>
<property>
<name>border-left-width</name>
<use-generic>GenericBorderWidth</use-generic>
<corresponding>
<propval>border-<wmabs2rel dir="LEFT"/>-width</propval>
</corresponding>
</property>
<property>
<name>border-right-color</name>
<inherited>false</inherited>
<use-generic>GenericColor</use-generic>
<default>black</default>
<corresponding>
<propval>border-<wmabs2rel dir="RIGHT"/>-color</propval>
</corresponding>
</property>
<property>
<name>border-right-style</name>
<use-generic>GenericBorderStyle</use-generic>
<corresponding>
<propval>border-<wmabs2rel dir="RIGHT"/>-style</propval>
</corresponding>
</property>
<property>
<name>border-right-width</name>
<use-generic>GenericBorderWidth</use-generic>
<corresponding>
<propval>border-<wmabs2rel dir="RIGHT"/>-width</propval>
</corresponding>
</property>
<property>
<name>border-color</name>
@@ -1042,6 +1182,56 @@
<default>none</default>
</property>

<property>
<name>writing-mode</name>
<inherited>true</inherited>
<datatype>Enum</datatype>
<default>lr-tb</default>
<enumeration>
<value const="LR_TB">lr-tb</value>
<value const="RL_TB">rl-tb</value>
<value const="TB_RL">tb-rl</value>
</enumeration>
</property>
<property>
<name>block-progression-dimension</name>
<inherited>false</inherited>
<datatype>LengthRange</datatype>
<corresponding use-if-specified="true">
<propval><wmrel2abs dir="BLOCKPROGDIM"/></propval>
</corresponding>>
<compound>
<subproperty set-by-shorthand="true">
<name>minimum</name>
<datatype>Length</datatype>
<default>auto</default>
<auto-ok/>
<percent-ok base="CONTAINING_BOX"/>
<corresponding>
<propval>min-<wmrel2abs dir="BLOCKPROGDIM"/></propval>
</corresponding>>
</subproperty>
<subproperty set-by-shorthand="true">
<name>optimum</name>
<datatype>Length</datatype>
<default>auto</default>
<auto-ok/>
<percent-ok base="CONTAINING_BOX"/>
</subproperty>
<subproperty set-by-shorthand="true">
<name>maximum</name>
<datatype>Length</datatype>
<auto-ok/>
<default>auto</default>
<percent-ok base="CONTAINING_BOX"/>
<corresponding>
<propval>max-<wmrel2abs dir="BLOCKPROGDIM"/></propval>
</corresponding>>
</subproperty>
</compound>
</property>

</generic-property-list>
</property-list>


+ 86
- 4
src/codegen/properties.dtd Vedi File

@@ -1,3 +1,4 @@
<!-- $Id$ -->
<!--
DTD for foproperties.xml and svgproperties.xml
-->
@@ -22,7 +23,7 @@ DTD for foproperties.xml and svgproperties.xml
<!-- Define a single property in the current namespace -->
<!ELEMENT property (name, (use-generic | datatype), class-name?, inherited?,
default?, enumeration?, datatype-conversion*, compound?,
keyword-equiv*, percent-ok?, auto-ok? ) >
keyword-equiv*, percent-ok?, auto-ok?, derive?, corresponding? ) >
<!-- If type is set to "ref", then this is not a new property definition,
but rather a reference to a property allready defined (should be in
@@ -111,6 +112,12 @@ DTD for foproperties.xml and svgproperties.xml
<!-- This gives the default value for a property if it is not specified on
a given FO. (The spec calls this the "initial" value.)

It may also be used to specify a default value for a particular
component of a compound property. This is used to give each component
its initial value if components are only partially specified in the
FO file.

NOTE: It should be an expression which can be parsed to give a legal
value for the property! This can't be checked by the generating
script, so if there is a problem, it will only be seen at runtime.
@@ -120,10 +127,17 @@ DTD for foproperties.xml and svgproperties.xml
case), it will only make one Property object with the default value
and return it on each call. Context-dependent default values include
those specified with relative units (eg. 1em).

The "subproperty" attribute can be used on properties which are
based on generic property specifications to specify a default value
for a particular component. For example, the border-end-width property
is based on GenericCondBorderWidth and specifies a specific default
for the "conditionality" component.
-->
<!ELEMENT default (#PCDATA) >
<!ELEMENT default
<!ATTLIST default
contextdep (true | false) "false"
subproperty CDATA #IMPLIED
>

@@ -144,7 +158,23 @@ DTD for foproperties.xml and svgproperties.xml
and not to a ColorType, the datatype-conversion just uses it to
directly initialize a ColorType object.
-->
<!ELEMENT datatype-conversion >
<!ELEMENT datatype-conversion (#PCDATA) >

<!-- The attribute from-type gives a possible property datatype, such as
Number or String. The varname gives the name of a variable which can
be used in the content of the datatype-conversion element. If the type
of the variable is not the same as from-type, it may be specified with
the attribute vartype.

An example of usage is from the line-height property. This should be
a Length object, but may be specified as a Number, which is interpreted
as though it were a percentage of the current font-size.
-->
<!ATTLIST datatype-conversion
from-type CDATA #REQUIRED
vartype CDATA #IMPLIED
varname CDATA #REQUIRED
>

<!-- The compound element indicates that the property is a "compound"
property as defined in the XSL specification. It is specified as one
@@ -160,7 +190,8 @@ DTD for foproperties.xml and svgproperties.xml
property, the optimum component has the name optimum and the datatype
Length.
-->
<!ELEMENT subproperty (name, datatype) >
<!ELEMENT subproperty (name, datatype, auto-ok?, default?, corresponding?,
enumeration?, keyword-equiv? ) >

<!-- This element which may be repeated, specifies keyword shorthands for
non-enumerated properties. For example, the border-width family of
@@ -228,3 +259,54 @@ DTD for foproperties.xml and svgproperties.xml
<!ATTLIST if
match CDATA #REQUIRED
>

<!-- This element indicates that the value of the property is the same as
that of a "corresponding" absolute or writing-mode-relative property.
if the "use-if-specified" attribute has the value "true", then the
corresponding property value takes precedence over the property on
which it is specified. To be conformant to the specification, all the
the "absolute" versions of properties have precedence.
Example: if a get() call is made on padding-end for a FO using lr-tb
writing-mode, then the padding-right property will be used if it is
specified, even if padding-end is actually specified.
However, if a get() is made on padding-right, the value of padding-end
will only be used if padding-right isn't specified on the FO.
-->

<!ELEMENT corresponding (propval, propexpr?) >
<!ATTLIST corresponding
use-if-specified (true|false) "false"
>

<!-- If the value must be calculated using several other properties, the
propexpr element may be used. Then only example I know of are the
indent properties which are calculated based on the margin-* values
if those are specified, plus the corresponding padding and border-width
values.
-->
<!ELEMENT propexpr (propval | #PCDATA)+ >

<!-- The name of the corresponding property is given in the propval element.
The conversion between absolute and relative property names is
made using wmrel2abs or wm2bs2rel elements, intermixed with text.
For example, for the property "padding-left", the corresponding
property is "padding-start" if the inline progression direction is
left to right. This is expressed in the properties file with the
expression "padding-<wmabs2rel dir='LEFT'/>". The wmabs2rel element
is replaced by the writing-mode relative direction which corresponds
to the absolute direction LEFT using the writing-mode in effect for the
flow object where this property is specified.
-->
<!ELEMENT propval (wmrel2abs | wmabs2rel | #PCDATA)+ >

<!ELEMENT wmrel2abs EMPTY>
<!ATTLIST wmrel2abs
dir (BEFORE | AFTER | START | END | BLOCKPROGDIM | INLINEPROGDIM)
#REQUIRED
>

<!ELEMENT wmabs2rel EMPTY>
<!ATTLIST wmabs2rel
dir (TOP | BOTTOM | LEFT | RIGHT | HEIGHT | WIDTH ) #REQUIRED
>


+ 166
- 63
src/codegen/properties.xsl Vedi File

@@ -37,6 +37,16 @@
}
</xsl:template>

<xsl:template match="enumeration">
public Property checkEnumValues(String value) {
<xsl:for-each select="value">
if (value.equals("<xsl:value-of select="."/>")) { return s_prop<xsl:value-of select="@const"/>; }
</xsl:for-each>
return super.checkEnumValues(value);
}
</xsl:template>


<!-- Look for keyword equivalents. Value is the new expression -->
<xsl:template match="keyword-equiv[1]">
protected String checkValueKeywords(String value) {
@@ -193,14 +203,27 @@ public class <xsl:value-of select="$classname"/> extends <xsl:value-of select="

<!-- If has enumerated values and is a generic class, create a nested
interface defining the enumeration constants -->
<xsl:if test="enumeration/value and @type='generic'">
<xsl:if test=".//enumeration and @type='generic'">
public interface Enums {
<xsl:for-each select="enumeration/value">
int <xsl:value-of select="@const"/> = <xsl:number/>;
</xsl:for-each>
<xsl:for-each select="compound/subproperty[enumeration]">
<xsl:variable name="spname">
<xsl:call-template name="makeClassName">
<xsl:with-param name="propstr" select="name"/>
</xsl:call-template>
</xsl:variable>
public interface <xsl:value-of select="$spname"/> {
<xsl:for-each select="enumeration/value">
int <xsl:value-of select="@const"/> = <xsl:number/>;
</xsl:for-each>
}
</xsl:for-each>
}
</xsl:if>


<!-- Handle enumeration values -->
<xsl:for-each select="enumeration/value">
protected final static EnumProperty s_prop<xsl:value-of select="@const"/> = new EnumProperty(<xsl:if test="../../@type='generic'">Enums.</xsl:if><xsl:value-of select="@const"/>);
@@ -208,22 +231,43 @@ public class <xsl:value-of select="$classname"/> extends <xsl:value-of select="


<!-- Look for compound properties -->
<xsl:if test="compound">
<xsl:if test="compound">
<xsl:variable name="enumclass">
<xsl:choose>
<xsl:when test="@type='generic'">Enums</xsl:when>
<xsl:otherwise><xsl:value-of select="$eclassname"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:for-each select="compound/subproperty">
<xsl:variable name="spname">
<xsl:call-template name="makeClassName">
<xsl:with-param name="propstr" select="name"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="sp_superclass">
<xsl:choose>
<xsl:when test="use-generic">
<xsl:value-of select="use-generic"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="datatype"/><xsl:text>Property.Maker</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:choose>
<xsl:when test='*[local-name(.)!="name" and local-name(.)!="datatype"]'>
<xsl:when test='*[local-name(.)!="name" and local-name(.)!="datatype" and local-name(.)!="use-generic" and local-name(.)!="default"]'>
static private class SP_<xsl:value-of select="$spname"/>Maker
extends <xsl:value-of select="datatype"/>Property.Maker {
SP_<xsl:value-of select="$spname"/>Maker(String sPropName) {
extends <xsl:value-of select="$sp_superclass"/>
<xsl:if test="enumeration"> implements <xsl:value-of select="$enumclass"/>.<xsl:value-of select="$spname"/></xsl:if> {
SP_<xsl:value-of select="$spname"/>Maker(String sPropName) {
super(sPropName);
}
<xsl:apply-templates select="percent-ok|auto-ok|keyword-equiv|datatype-conversion"/>
}
<xsl:for-each select="enumeration/value">
protected final static EnumProperty s_prop<xsl:value-of select="@const"/> = new EnumProperty(<xsl:value-of select="@const"/>);
</xsl:for-each>

<xsl:apply-templates select="percent-ok|auto-ok|keyword-equiv|datatype-conversion|enumeration"/>
}
final private static Property.Maker s_<xsl:value-of select="$spname"/>Maker =
new SP_<xsl:value-of select="$spname"/>Maker(
@@ -231,7 +275,7 @@ public class <xsl:value-of select="$classname"/> extends <xsl:value-of select="
</xsl:when>
<xsl:otherwise>
final private static Property.Maker s_<xsl:value-of select="$spname"/>Maker =
new <xsl:value-of select="datatype"/>Property.Maker(
new <xsl:value-of select="$sp_superclass"/>(
"<xsl:value-of select='../../name'/>.<xsl:value-of select='name'/>");
</xsl:otherwise>
</xsl:choose>
@@ -244,9 +288,22 @@ public class <xsl:value-of select="$classname"/> extends <xsl:value-of select="

protected <xsl:value-of select="$classname"/>(String name) {
super(name);
<xsl:if test="compound">
m_shorthandMaker= getSubpropMaker("<xsl:value-of select='compound/subproperty[@set-by-shorthand="true"]/name'/>");
</xsl:if>
}

<xsl:if test="compound">
Property.Maker m_shorthandMaker;

public Property checkEnumValues(String value) {
return m_shorthandMaker.checkEnumValues(value);
}

protected boolean isCompoundMaker() {
return true;
}

protected Property.Maker getSubpropMaker(String subprop) {
<xsl:for-each select="compound/subproperty">
<xsl:variable name="spname">
@@ -262,36 +319,16 @@ public class <xsl:value-of select="$classname"/> extends <xsl:value-of select="

protected Property setSubprop(Property baseProp, String subpropName,
Property subProp) {
<xsl:value-of select="datatype"/> val =
((<xsl:value-of select="$propclass"/>)baseProp).get<xsl:value-of select="datatype"/>();
<xsl:for-each select="compound/subproperty">
<xsl:variable name="spname">
<xsl:call-template name="makeClassName">
<xsl:with-param name="propstr" select="name"/>
</xsl:call-template>
</xsl:variable>
if (subpropName.equals("<xsl:value-of select='name'/>"))
val.set<xsl:value-of select='$spname'/>(subProp.get<xsl:value-of select='datatype'/>(), false);
else
</xsl:for-each>
return super.setSubprop(baseProp, subpropName, subProp);
<xsl:value-of select="datatype"/> val = baseProp.get<xsl:value-of select="datatype"/>();
// Do some type checking???
// Check if one of our subproperties???
val.setComponent(subpropName, subProp, false);
return baseProp;
}

public Property getSubpropValue(Property baseProp, String subpropName) {
<xsl:value-of select="datatype"/> val =
((<xsl:value-of select="$propclass"/>)baseProp).get<xsl:value-of select="datatype"/>();
<xsl:for-each select="compound/subproperty">
<xsl:variable name="spname">
<xsl:call-template name="makeClassName">
<xsl:with-param name="propstr" select="name"/>
</xsl:call-template>
</xsl:variable>
if (subpropName.equals("<xsl:value-of select='name'/>"))
return new <xsl:value-of select='datatype'/>Property(
val.get<xsl:value-of select='$spname'/>());
</xsl:for-each>
return super.getSubpropValue(baseProp, subpropName);
<xsl:value-of select="datatype"/> val = baseProp.get<xsl:value-of select="datatype"/>();
return val.getComponent(subpropName);
}
<xsl:choose>
<!-- some subproperty default is context dependent; don't cache default! -->
@@ -323,7 +360,7 @@ public class <xsl:value-of select="$classname"/> extends <xsl:value-of select="
// set default for subprop <xsl:value-of select="."/>
subProp = getSubpropMaker("<xsl:value-of select='.'/>").make(pList,
getDefaultFor<xsl:value-of select='$spname'/>(), fo);
p.set<xsl:value-of select='$spname'/>(subProp.get<xsl:value-of select='../datatype'/>(), true);
p.setComponent("<xsl:value-of select='.'/>", subProp, true);
</xsl:for-each>
return new <xsl:value-of select="$propclass"/>(p);
}
@@ -338,6 +375,8 @@ public class <xsl:value-of select="$classname"/> extends <xsl:value-of select="
protected String getDefaultFor<xsl:value-of select='$spname'/>() {
<xsl:choose><xsl:when test="default">
return "<xsl:value-of select='default'/>";
</xsl:when><xsl:when test="use-generic and key('genericref', use-generic)/default">
return "<xsl:value-of select='key(&apos;genericref&apos;, use-generic)/default'/>";
</xsl:when><xsl:otherwise>
return "";
</xsl:otherwise>
@@ -346,43 +385,30 @@ public class <xsl:value-of select="$classname"/> extends <xsl:value-of select="
</xsl:for-each>

/** Set the appropriate components when the "base" property is set. */
protected Property convertProperty(Property p, PropertyList pList,FObj fo)
public Property convertProperty(Property p, PropertyList pList,FObj fo)
throws FOPException
{
<xsl:variable name="spdt">
<xsl:call-template name="check-subprop-datatype">
<xsl:with-param name="dtlist"
select="compound/subproperty[@set-by-shorthand='true']/datatype"/>
</xsl:call-template>
</xsl:variable>
<!--
Property sub= getSubpropMaker("<xsl:value-of select='compound/subproperty[@set-by-shorthand="true"]/name'/>").convertProperty(p,pList,fo);
if (sub != null) {
<xsl:value-of select='$spdt'/> spval=sub.get<xsl:value-of select='$spdt'/>();
-->
<xsl:value-of select='$spdt'/> spval=p.get<xsl:value-of select='$spdt'/>();
if (spval == null) {
// NOTE: must convert to the component datatype, not compound!
Property pconv = convertPropertyDatatype(p, pList, fo);
if (pconv != null) {
spval=pconv.get<xsl:value-of select='$spdt'/>();
}
if (p instanceof <xsl:value-of select="$propclass"/>) return p;
if (! (p instanceof EnumProperty)) {
// delegate to the subprop maker to do conversions
p = m_shorthandMaker.convertProperty(p,pList,fo);
}
if (spval != null) {
if (p != null) {
Property prop = makeCompound(pList, fo);
<xsl:value-of select='datatype'/> pval = prop.get<xsl:value-of select='datatype'/>();

<xsl:value-of select="datatype"/> pval = prop.get<xsl:value-of select="datatype"/>();
<xsl:for-each select="compound/subproperty[@set-by-shorthand='true']">
<xsl:variable name="spname"><xsl:call-template name="makeClassName">
<xsl:with-param name="propstr" select="name"/>
</xsl:call-template></xsl:variable>
pval.set<xsl:value-of select='$spname'/>(spval, false);
pval.setComponent("<xsl:value-of select='name'/>", p, false);
</xsl:for-each>
return prop;
}
else return null;
<!--
else {
// throw some kind of exception!
throw new FOPException("Can't convert value to <xsl:value-of select='$spdt'/> type");
}
-->
}

</xsl:if> <!-- property/compound -->
@@ -399,14 +425,16 @@ public class <xsl:value-of select="$classname"/> extends <xsl:value-of select="
</xsl:if>

<!-- Handle enumerated values -->
<!--
<xsl:if test="enumeration/value">
protected Property findConstant(String value) {
public Property checkEnumValues(String value) {
<xsl:for-each select="enumeration/value">
if (value.equals("<xsl:value-of select="."/>")) { return s_prop<xsl:value-of select="@const"/>; }
</xsl:for-each>
return super.findConstant(value);
return super.checkEnumValues(value);
}
</xsl:if>
-->

<!-- Currently only works for Enum values -->
<xsl:if test="derive">
@@ -424,12 +452,86 @@ public class <xsl:value-of select="$classname"/> extends <xsl:value-of select="
return computedProperty;
}
</xsl:if>
<xsl:apply-templates select="percent-ok|auto-ok|default|keyword-equiv|datatype-conversion"/>

<!-- If any corresponding element at property or subproperty levels -->
<xsl:if test=".//corresponding">
<xsl:if test=".//corresponding/@use-if-specified='true'">
public boolean isCorrespondingForced(PropertyList propertyList) {
StringBuffer sbExpr=new StringBuffer();
<xsl:for-each select=".//corresponding/propval">
sbExpr.setLength(0);
<xsl:apply-templates select="."/>
if (propertyList.getExplicit(sbExpr.toString()) != null) return true;
</xsl:for-each>
return false;
}
</xsl:if>
public Property compute(PropertyList propertyList) throws FOPException {
FObj parentFO = propertyList.getParentFObj();
StringBuffer sbExpr=new StringBuffer();
Property p=null;
<xsl:choose><xsl:when test="corresponding/propexpr">
<xsl:apply-templates select="corresponding/propval"/>
// Make sure the property is set before calculating it!
if (propertyList.getExplicit(sbExpr.toString()) == null) return p;
sbExpr.setLength(0);
<xsl:apply-templates select="corresponding/propexpr"/>
p= make(propertyList, sbExpr.toString(), propertyList.getParentFObj());
</xsl:when><xsl:otherwise>
<xsl:apply-templates select="corresponding/propval"/>
p= propertyList.getExplicit(sbExpr.toString());
</xsl:otherwise></xsl:choose>
if (p != null) {
p = convertProperty(p, propertyList, parentFO );
}
<xsl:if test="compound">
else p= makeCompound(propertyList, parentFO);
Property subprop;
<xsl:for-each select="compound/subproperty/corresponding">
sbExpr.setLength(0);
<xsl:choose><xsl:when test="propexpr">
<xsl:apply-templates select="propexpr"/>
subprop= getSubpropMaker("<xsl:value-of select='../name'/>").
make(propertyList, sbExpr.toString(), parentFO);
</xsl:when><xsl:otherwise>
<xsl:apply-templates select="propval"/>
subprop= propertyList.getExplicit(sbExpr.toString());
</xsl:otherwise></xsl:choose>
setSubprop(p, "<xsl:value-of select='../name'/>", subprop);
</xsl:for-each>
</xsl:if>
return p;
}
</xsl:if>

<xsl:apply-templates select="percent-ok|auto-ok|default|keyword-equiv|datatype-conversion|enumeration"/>
}
</redirect:write>
</xsl:if> <!-- need to create a class -->
</xsl:template>

<xsl:template match="corresponding/propexpr/propval">
sbExpr.append("_fop-property-value("); <!-- Note: interpreted by property parser -->
<xsl:apply-templates/>
sbExpr.append(")");
</xsl:template>


<xsl:template match="corresponding//text()">
<xsl:variable name="tval" select='normalize-space(.)'/>
<xsl:if test="$tval != ''">sbExpr.append("<xsl:value-of select='$tval'/>");</xsl:if>
</xsl:template>

<xsl:template match="propval/wmrel2abs">
sbExpr.append(propertyList.wmRelToAbs(PropertyList.<xsl:value-of select="@dir"/>));
</xsl:template>

<xsl:template match="propval/wmabs2rel">
sbExpr.append(propertyList.wmAbsToRel(PropertyList.<xsl:value-of select="@dir"/>));
</xsl:template>

<!-- avoid unwanted output to placeholder file -->
<xsl:template match="localname"/>

@@ -451,4 +553,5 @@ public class <xsl:value-of select="$classname"/> extends <xsl:value-of select="
<xsl:value-of select='$dt'/>
</xsl:template>


</xsl:stylesheet>

+ 28
- 5
src/codegen/propinc.xsl Vedi File

@@ -58,22 +58,45 @@
</xsl:template>

<!-- return a boolean value -->
<xsl:template name="isEnum">
<xsl:template name="hasEnum">
<xsl:param name="prop" select="."/>
<xsl:choose>
<xsl:when test="$prop/datatype">
<xsl:value-of select="boolean($prop/datatype='Enum')"/>
<xsl:when test="$prop/enumeration">true</xsl:when>
<xsl:when test="$prop/use-generic">
<!-- If no datatype child, then the prop must use the same datatype as
its template. -->
<xsl:call-template name="hasEnum">
<xsl:with-param name="prop"
select="key('genericref', $prop/use-generic)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- return a boolean value -->
<xsl:template name="hasSubpropEnum">
<xsl:param name="prop" select="."/>
<xsl:choose>
<xsl:when test="$prop/compound/subproperty/enumeration">true</xsl:when>
<xsl:when test="$prop/use-generic">
<!-- If no datatype child, then the prop must use the same datatype as
its template. -->
<xsl:call-template name="isEnum">
<xsl:call-template name="hasSubpropEnum">
<xsl:with-param name="prop"
select="key('genericref', $prop/use-generic)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$prop/compound/subproperty/use-generic">
<xsl:for-each select="$prop/compound/subproperty[use-generic]">
<xsl:call-template name="hasEnum">
<xsl:with-param name="prop"
select="key('genericref', use-generic)"/>
</xsl:call-template>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
</xsl:stylesheet>

Loading…
Annulla
Salva