You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

elements.xsl 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <xsl:stylesheet version="1.0"
  2. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:lxslt="http://xml.apache.org/xslt"
  4. xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
  5. extension-element-prefixes="redirect">
  6. <xsl:output method="text" />
  7. <xsl:variable name="prefixVal">
  8. <xsl:value-of select="//elements/@prefix"/>
  9. </xsl:variable>
  10. <xsl:template name="capfirst">
  11. <xsl:param name="str"/>
  12. <xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz'" />
  13. <xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
  14. <xsl:value-of select="concat(translate(substring($str, 1, 1),
  15. $lcletters, $ucletters), substring($str, 2))"/>
  16. </xsl:template>
  17. <xsl:template name="capall">
  18. <xsl:param name="str"/>
  19. <xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz'" />
  20. <xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
  21. <xsl:value-of select="translate($str,
  22. $lcletters, $ucletters)"/>
  23. </xsl:template>
  24. <xsl:template name="makeClassName">
  25. <xsl:param name="propstr"/>
  26. <xsl:choose>
  27. <xsl:when test="contains($propstr, '-')">
  28. <xsl:call-template name="capfirst">
  29. <xsl:with-param name="str" select="substring-before($propstr, '-')"/>
  30. </xsl:call-template>
  31. <xsl:call-template name="makeClassName">
  32. <xsl:with-param name="propstr" select="substring-after($propstr, '-')"/>
  33. </xsl:call-template>
  34. </xsl:when>
  35. <xsl:otherwise>
  36. <xsl:call-template name="capfirst">
  37. <xsl:with-param name="str" select="$propstr"/>
  38. </xsl:call-template>
  39. </xsl:otherwise>
  40. </xsl:choose>
  41. </xsl:template>
  42. <xsl:template match="attributes"><xsl:apply-templates/></xsl:template>
  43. <xsl:template match="includeAttributes">
  44. <xsl:variable name="attr-ref">
  45. <xsl:value-of select="@ref"/>
  46. </xsl:variable>
  47. <xsl:for-each select="/elements/commonAttributes">
  48. <xsl:choose>
  49. <xsl:when test="@ref = $attr-ref">
  50. <xsl:apply-templates/>
  51. </xsl:when>
  52. </xsl:choose>
  53. </xsl:for-each>
  54. </xsl:template>
  55. <xsl:template match="attribute">"<xsl:apply-templates/>"<xsl:if test="not(position()=last())">, </xsl:if></xsl:template>
  56. <xsl:template match="elements">
  57. <xsl:apply-templates select="element"/>
  58. </xsl:template>
  59. <xsl:template match="tagname">
  60. <xsl:apply-templates/>
  61. </xsl:template>
  62. <xsl:template match="element">
  63. <xsl:variable name="name">
  64. <xsl:apply-templates select="tagname"/>
  65. </xsl:variable>
  66. <xsl:variable name="classname">
  67. <xsl:choose>
  68. <xsl:when test="class-name">
  69. <xsl:value-of select="class-name"/>
  70. </xsl:when>
  71. <xsl:otherwise>
  72. <xsl:call-template name="makeClassName">
  73. <xsl:with-param name="propstr" select="$name"/>
  74. </xsl:call-template>
  75. </xsl:otherwise>
  76. </xsl:choose>
  77. </xsl:variable>
  78. <redirect:write select="concat('./{$prefixVal}/', $classname, '.java')">
  79. package org.apache.fop.<xsl:value-of select="$prefixVal"/>;
  80. import org.apache.fop.fo.*;
  81. import org.apache.fop.layout.Area;
  82. import org.apache.fop.layout.FontState;
  83. import org.apache.fop.apps.FOPException;
  84. import org.w3c.dom.Element;
  85. public class <xsl:value-of select="$classname"/> extends <xsl:call-template name="capall"><xsl:with-param name="str" select="$prefixVal"/></xsl:call-template>Obj {
  86. /**
  87. * inner class for making <xsl:apply-templates select="tagname"/> objects.
  88. */
  89. public static class Maker extends FObj.Maker {
  90. /**
  91. * make a <xsl:apply-templates select="tagname"/> object.
  92. *
  93. * @param parent the parent formatting object
  94. * @param propertyList the explicit properties of this object
  95. *
  96. * @return the <xsl:apply-templates select="tagname"/> object
  97. */
  98. public FObj make(FObj parent,
  99. PropertyList propertyList) throws FOPException {
  100. return new <xsl:value-of select="$classname"/>(parent, propertyList);
  101. }
  102. }
  103. /**
  104. * returns the maker for this object.
  105. *
  106. * @return the maker for <xsl:apply-templates select="tagname"/> objects
  107. */
  108. public static FObj.Maker maker() {
  109. return new <xsl:value-of select="$classname"/>.Maker();
  110. }
  111. /**
  112. * constructs a <xsl:apply-templates select="tagname"/> object (called by Maker).
  113. *
  114. * @param parent the parent formatting object
  115. * @param propertyList the explicit properties of this object
  116. */
  117. protected <xsl:value-of select="$classname"/>(FObj parent, PropertyList propertyList) {
  118. super(parent, propertyList);
  119. this.name = "<xsl:value-of select="//@prefix"/>:<xsl:value-of select="$name"/>";
  120. tagName = "<xsl:value-of select="$name"/>";
  121. props = new String[] {<xsl:apply-templates select="attributes"/>};
  122. }
  123. <xsl:if test="@addText">
  124. protected void addCharacters(char data[], int start, int length) {
  125. this.children.addElement(new String(data, start, length - start));
  126. }
  127. </xsl:if>
  128. }
  129. </redirect:write>
  130. </xsl:template>
  131. </xsl:stylesheet>