123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <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('./{$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>
|