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.

enumgen.xsl 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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:include href="./propinc.xsl"/>
  7. <xsl:output method="text" />
  8. <!-- zap text content -->
  9. <xsl:template match="text()"/>
  10. <xsl:template match="property[not(@type='generic')]">
  11. <xsl:variable name="classname">
  12. <xsl:choose>
  13. <xsl:when test="class-name">
  14. <xsl:value-of select="class-name"/>
  15. </xsl:when>
  16. <xsl:otherwise>
  17. <xsl:call-template name="makeClassName">
  18. <xsl:with-param name="propstr" select="name"/>
  19. </xsl:call-template>
  20. </xsl:otherwise>
  21. </xsl:choose>
  22. </xsl:variable>
  23. <xsl:variable name="bEnum">
  24. <xsl:call-template name="hasEnum"/>
  25. </xsl:variable>
  26. <xsl:variable name="bSubpropEnum">
  27. <xsl:call-template name="hasSubpropEnum"/>
  28. </xsl:variable>
  29. <xsl:if test="$bEnum='true' or contains($bSubpropEnum, 'true')">
  30. <redirect:write select="concat('./', $classname, '.java')">
  31. package org.apache.fop.fo.properties;
  32. <!-- Handle enumeration values -->
  33. public interface <xsl:value-of select="$classname"/>
  34. <xsl:if test="use-generic and $bEnum='true'">
  35. extends <xsl:value-of select="use-generic"/>.Enums
  36. </xsl:if>{
  37. <xsl:for-each select="enumeration/value">
  38. public final static int <xsl:value-of select="@const"/> = Constants.<xsl:value-of select="@const"/>;
  39. </xsl:for-each>
  40. <xsl:if test="contains($bSubpropEnum, 'true')">
  41. <xsl:call-template name="genSubpropEnum"/>
  42. </xsl:if>
  43. }
  44. </redirect:write>
  45. </xsl:if>
  46. </xsl:template>
  47. <xsl:template name="genSubpropEnum">
  48. <xsl:param name="prop" select="."/>
  49. <xsl:choose>
  50. <xsl:when test="$prop/compound/subproperty/enumeration">
  51. <xsl:for-each select="compound/subproperty[enumeration]">
  52. public interface <xsl:value-of select="name"/> {
  53. <xsl:for-each select="enumeration/value">
  54. public final static int <xsl:value-of select="@const"/> = Constants.<xsl:value-of select="@const"/>;
  55. </xsl:for-each>
  56. }
  57. </xsl:for-each>
  58. </xsl:when>
  59. <xsl:when test="$prop/use-generic">
  60. <xsl:call-template name="inhspenums">
  61. <xsl:with-param name="prop" select="key('genericref', $prop/use-generic)"/>
  62. </xsl:call-template>
  63. </xsl:when>
  64. <xsl:when test="$prop/compound/subproperty/use-generic">
  65. <!-- generate "interface <subprop> extends <gensubprop>.Enums" -->
  66. <xsl:for-each select="$prop/compound/subproperty[use-generic]">
  67. <xsl:variable name="bSpEnum">
  68. <xsl:call-template name="hasEnum">
  69. <xsl:with-param name="prop"
  70. select="key('genericref', use-generic)"/>
  71. </xsl:call-template>
  72. </xsl:variable>
  73. <xsl:if test="$bSpEnum='true'">
  74. public interface <xsl:value-of select="name"/> extends <xsl:value-of select="use-generic"/>.Enums { }
  75. </xsl:if>
  76. </xsl:for-each>
  77. </xsl:when>
  78. <xsl:otherwise>false</xsl:otherwise>
  79. </xsl:choose>
  80. </xsl:template>
  81. <xsl:template name="inhspenums">
  82. <xsl:param name="prop"/>
  83. <xsl:variable name="generic_name">
  84. <xsl:choose>
  85. <xsl:when test="$prop/class-name">
  86. <xsl:value-of select="$prop/class-name"/>
  87. </xsl:when>
  88. <xsl:otherwise>
  89. <xsl:call-template name="makeClassName">
  90. <xsl:with-param name="propstr" select="$prop/name"/>
  91. </xsl:call-template>
  92. </xsl:otherwise>
  93. </xsl:choose>
  94. </xsl:variable>
  95. <!-- generate "interface <subprop> extends <genprop>.<subprop>" -->
  96. <xsl:for-each select="$prop/compound/subproperty[enumeration]">
  97. <xsl:variable name="spname">
  98. <xsl:call-template name="makeClassName">
  99. <xsl:with-param name="propstr" select="name"/>
  100. </xsl:call-template>
  101. </xsl:variable>
  102. public interface <xsl:value-of select="$spname"/> extends <xsl:value-of select="$generic_name"/>.Enums.<xsl:value-of select="$spname"/> {
  103. }
  104. </xsl:for-each>
  105. <xsl:if test="$prop/use-generic">
  106. <xsl:call-template name="inhspenums">
  107. <xsl:with-param name="prop" select="key('genericref', $prop/use-generic)"/>
  108. </xsl:call-template>
  109. </xsl:if>
  110. </xsl:template>
  111. </xsl:stylesheet>