diff options
author | Karen Lease <klease@apache.org> | 2000-11-10 21:51:24 +0000 |
---|---|---|
committer | Karen Lease <klease@apache.org> | 2000-11-10 21:51:24 +0000 |
commit | a02dba544228b829f47bc21b759738859a1b1532 (patch) | |
tree | d5360a1dbaeeb6520f36a66696b58a42168b363f /src | |
parent | e9dfb3e4f65e8aa8a4afd292d0c71ef637bdf946 (diff) | |
download | xmlgraphics-fop-a02dba544228b829f47bc21b759738859a1b1532.tar.gz xmlgraphics-fop-a02dba544228b829f47bc21b759738859a1b1532.zip |
New property-related XSL files
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193762 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/codegen/enumgen.xsl | 45 | ||||
-rw-r--r-- | src/codegen/propinc.xsl | 79 | ||||
-rw-r--r-- | src/codegen/propmap.xsl | 114 |
3 files changed, 238 insertions, 0 deletions
diff --git a/src/codegen/enumgen.xsl b/src/codegen/enumgen.xsl new file mode 100644 index 000000000..5b1cb9a64 --- /dev/null +++ b/src/codegen/enumgen.xsl @@ -0,0 +1,45 @@ +<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:include href="./propinc.xsl"/> + +<xsl:output method="text" /> + +<xsl:template match="property[not(@type='generic')]"> + <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> + <xsl:variable name="bEnum"> + <xsl:call-template name="isEnum"/> + </xsl:variable> + <xsl:if test="$bEnum='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"> + 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> + } +</redirect:write> + </xsl:if> +</xsl:template> + + +</xsl:stylesheet> diff --git a/src/codegen/propinc.xsl b/src/codegen/propinc.xsl new file mode 100644 index 000000000..e25755aa6 --- /dev/null +++ b/src/codegen/propinc.xsl @@ -0,0 +1,79 @@ +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > + +<xsl:key name="genericref" match="property[@type='generic']" use="class-name"/> + +<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="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> + +<!-- The name of the subclass of Property to be created --> +<xsl:template name="propclass"> + <xsl:param name="prop" select="."/> + <xsl:choose> + <xsl:when test="$prop/datatype"> + <xsl:value-of select="$prop/datatype"/><xsl:text>Property</xsl:text> + </xsl:when> + <xsl:when test="$prop/use-generic[@ispropclass='true']"> + <xsl:value-of select="$prop/use-generic"/> + </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="propclass"> + <xsl:with-param name="prop" + select="key('genericref', $prop/use-generic)"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <!-- ERROR --> + <xsl:message terminate="yes"> + No datatype found for property: <xsl:value-of select="$prop/name"/> + </xsl:message> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<!-- return a boolean value --> +<xsl:template name="isEnum"> + <xsl:param name="prop" select="."/> + <xsl:choose> + <xsl:when test="$prop/datatype"> + <xsl:value-of select="boolean($prop/datatype='Enum')"/> + </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:with-param name="prop" + select="key('genericref', $prop/use-generic)"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise>false</xsl:otherwise> + </xsl:choose> +</xsl:template> + +</xsl:stylesheet>
\ No newline at end of file diff --git a/src/codegen/propmap.xsl b/src/codegen/propmap.xsl new file mode 100644 index 000000000..bd832a9d1 --- /dev/null +++ b/src/codegen/propmap.xsl @@ -0,0 +1,114 @@ +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:lxslt="http://xml.apache.org/xslt"> + +<xsl:include href="propinc.xsl"/> + +<xsl:output method="text" /> + + +<xsl:template name="genmaker"> + <xsl:param name="prop" select="."/> + <xsl:param name="htname"/> + + <xsl:variable name="makerclass"> + <xsl:choose> + <xsl:when test="$prop/use-generic and count($prop/*)=2"> + <xsl:value-of select="$prop/use-generic"/> + </xsl:when> + <xsl:when test="$prop/class-name"> + <xsl:value-of select="$prop/class-name"/><xsl:text>Maker</xsl:text> + </xsl:when> + <xsl:otherwise> <!-- make from name --> + <xsl:call-template name="makeClassName"> + <xsl:with-param name="propstr" select="$prop/name"/> + </xsl:call-template><xsl:text>Maker</xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> +<xsl:text> </xsl:text><xsl:value-of select="$htname"/>.put("<xsl:value-of select="$prop/name"/>", <xsl:value-of select="$makerclass"/>.maker("<xsl:value-of select="$prop/name"/>")); +</xsl:template> + + +<xsl:template match="text()"/> + +<xsl:template match="property-list"> +package org.apache.fop.fo.properties; + +import java.util.Hashtable; +import java.util.Enumeration; +import org.apache.fop.svg.*; + +public class <xsl:value-of select="@family"/>PropertyMapping { + + private static Hashtable s_htGeneric = new Hashtable(200); + private static Hashtable s_htElementLists = new Hashtable(10); + <xsl:for-each select="element-property-list"> + private static Hashtable s_ht<xsl:value-of select="localname[1]"/>;</xsl:for-each> + + <xsl:apply-templates/> + + public static Hashtable getGenericMappings() { + return s_htGeneric; + } + + public static Enumeration getElementMappings() { + return s_htElementLists.keys(); + } + + public static Hashtable getElementMapping(String elemName) { + return (Hashtable)s_htElementLists.get(elemName); + } +} +</xsl:template> + +<xsl:template match="generic-property-list"> + static { + // Generate the generic mapping +<xsl:apply-templates> + <xsl:with-param name="htname" select='"s_htGeneric"'/> + </xsl:apply-templates> + } +</xsl:template> + +<xsl:template match="element-property-list"> + <xsl:variable name="ename" select="localname[1]"/> + static { + s_ht<xsl:value-of select="$ename"/> = new Hashtable(); + <xsl:for-each select="localname"> + s_htElementLists.put("<xsl:value-of select='.'/>", s_ht<xsl:value-of select='$ename'/>); + </xsl:for-each> + +<xsl:apply-templates> + <xsl:with-param name='htname'>s_ht<xsl:value-of select="$ename"/></xsl:with-param> + </xsl:apply-templates> + } +</xsl:template> + +<xsl:template match="property"> + <xsl:param name="htname"/> + <xsl:variable name="refname" select="name"/> + <xsl:choose> + <xsl:when test="@type='ref'"> + <xsl:call-template name="genmaker"> + <xsl:with-param name="htname" select="$htname"/> + <xsl:with-param name="prop" + select='document(concat(@family, "properties.xml"))//property[name=$refname]'/> + </xsl:call-template> + </xsl:when> + <xsl:when test="not(@type)"> + <xsl:call-template name="genmaker"> + <xsl:with-param name="htname" select="$htname"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise/> + </xsl:choose> +</xsl:template> + +<xsl:template match="property[@type='generic']"> + /* PROPCLASS = <xsl:call-template name="propclass"/> */ +</xsl:template> + +</xsl:stylesheet> + + |