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.

constants.xsl 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <!-- $Id$ -->
  16. <xsl:stylesheet version="1.0"
  17. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  18. <xsl:include href="./propinc.xsl"/>
  19. <xsl:output method="text" />
  20. <xsl:template match="allprops">
  21. <xsl:variable name="constlist">
  22. <xsl:for-each select="document(propfile)//generic-property-list
  23. //enumeration/value">
  24. <xsl:sort select="@const"/>
  25. <xsl:value-of select="@const"/>:</xsl:for-each>
  26. </xsl:variable>
  27. <xsl:variable name="propertylist">
  28. <xsl:for-each select="document(propfile)//generic-property-list//
  29. property[not(@type = 'generic')]">
  30. <xsl:sort select="name"/>
  31. <xsl:text>PR_</xsl:text>
  32. <xsl:call-template name="makeEnumConstant">
  33. <xsl:with-param name="propstr" select="name" />
  34. </xsl:call-template>
  35. <xsl:text>:</xsl:text>
  36. </xsl:for-each>
  37. </xsl:variable>
  38. <xsl:variable name="compoundpropertylist">
  39. <xsl:for-each select="document(propfile)//generic-property-list//
  40. property/compound/subproperty">
  41. <xsl:sort select="name"/>
  42. <xsl:text>CP_</xsl:text>
  43. <xsl:call-template name="makeEnumConstant">
  44. <xsl:with-param name="propstr" select="name" />
  45. </xsl:call-template>
  46. <xsl:text>:</xsl:text>
  47. </xsl:for-each>
  48. </xsl:variable>
  49. <xsl:variable name="elementlist">
  50. <xsl:for-each select="document(elementfile)//element">
  51. <xsl:sort select="name"/>
  52. <xsl:text>FO_</xsl:text>
  53. <xsl:call-template name="makeEnumConstant">
  54. <xsl:with-param name="propstr" select="name" />
  55. </xsl:call-template>
  56. <xsl:text>:</xsl:text>
  57. </xsl:for-each>
  58. </xsl:variable>
  59. <xsl:text>
  60. package org.apache.fop.fo;
  61. public interface Constants {</xsl:text>
  62. // element constants
  63. <xsl:call-template name="sortconsts">
  64. <xsl:with-param name="consts" select="$elementlist"/>
  65. <xsl:with-param name="counter" select="'ELEMENT'"/>
  66. </xsl:call-template>
  67. // Masks
  68. int COMPOUND_SHIFT = 9;
  69. int PROPERTY_MASK = (1 &lt;&lt; COMPOUND_SHIFT)-1;
  70. int COMPOUND_MASK = ~PROPERTY_MASK;
  71. int COMPOUND_COUNT = 11;
  72. // property constants
  73. <xsl:call-template name="sortconsts">
  74. <xsl:with-param name="consts" select="$propertylist"/>
  75. <xsl:with-param name="counter" select="'PROPERTY'"/>
  76. </xsl:call-template>
  77. // compound property constants
  78. <xsl:call-template name="sortconsts">
  79. <xsl:with-param name="consts" select="$compoundpropertylist"/>
  80. <xsl:with-param name="suffix" select="' &lt;&lt; COMPOUND_SHIFT'"/>
  81. </xsl:call-template>
  82. // Enumeration constants
  83. <xsl:call-template name="sortconsts">
  84. <xsl:with-param name="consts" select="$constlist"/>
  85. </xsl:call-template>
  86. // Enumeration Interfaces
  87. public interface GenericBooleanInterface {
  88. int TRUE = Constants.TRUE;
  89. int FALSE = Constants.FALSE;
  90. }
  91. public interface GenericBorderStyleInterface {
  92. int NONE = Constants.NONE;
  93. int HIDDEN = Constants.HIDDEN;
  94. int DOTTED = Constants.DOTTED;
  95. int DASHED = Constants.DASHED;
  96. int SOLID = Constants.SOLID;
  97. int DOUBLE = Constants.DOUBLE;
  98. int GROOVE = Constants.GROOVE;
  99. int RIDGE = Constants.RIDGE;
  100. int INSET = Constants.INSET;
  101. int OUTSET = Constants.OUTSET;
  102. }
  103. public interface GenericBreakInterface {
  104. int AUTO = Constants.AUTO;
  105. int COLUMN = Constants.COLUMN;
  106. int PAGE = Constants.PAGE;
  107. int EVEN_PAGE = Constants.EVEN_PAGE;
  108. int ODD_PAGE = Constants.ODD_PAGE;
  109. }
  110. public interface GenericCondBorderWidthInterface {
  111. public interface Conditionality {
  112. int DISCARD = Constants.DISCARD;
  113. int RETAIN = Constants.RETAIN;
  114. }
  115. }
  116. public interface GenericCondPaddingInterface {
  117. public interface Conditionality {
  118. int DISCARD = Constants.DISCARD;
  119. int RETAIN = Constants.RETAIN;
  120. }
  121. }
  122. public interface GenericKeepInterface {
  123. public interface WithinPage {
  124. int AUTO = Constants.AUTO;
  125. int ALWAYS = Constants.ALWAYS;
  126. }
  127. public interface WithinLine {
  128. int AUTO = Constants.AUTO;
  129. int ALWAYS = Constants.ALWAYS;
  130. }
  131. public interface WithinColumn {
  132. int AUTO = Constants.AUTO;
  133. int ALWAYS = Constants.ALWAYS;
  134. }
  135. }
  136. public interface GenericSpaceInterface {
  137. public interface Precedence {
  138. int FORCE = Constants.FORCE;
  139. }
  140. public interface Conditionality {
  141. int DISCARD = Constants.DISCARD;
  142. int RETAIN = Constants.RETAIN;
  143. }
  144. }
  145. <xsl:apply-templates select = "document(propfile)//property[not(@type='generic')]">
  146. <xsl:sort select="name"/>
  147. </xsl:apply-templates>
  148. <xsl:text>
  149. }
  150. </xsl:text>
  151. </xsl:template>
  152. <xsl:template match="property">
  153. <xsl:variable name="classname">
  154. <xsl:choose>
  155. <xsl:when test="class-name">
  156. <xsl:value-of select="class-name"/>
  157. </xsl:when>
  158. <xsl:otherwise>
  159. <xsl:call-template name="makeClassName">
  160. <xsl:with-param name="propstr" select="name"/>
  161. </xsl:call-template>
  162. </xsl:otherwise>
  163. </xsl:choose>
  164. </xsl:variable>
  165. <xsl:variable name="bEnum">
  166. <xsl:call-template name="hasEnum"/>
  167. </xsl:variable>
  168. <xsl:variable name="bSubpropEnum">
  169. <xsl:call-template name="hasSubpropEnum"/>
  170. </xsl:variable>
  171. <xsl:if test="$bEnum='true' or contains($bSubpropEnum, 'true')">
  172. <!--redirect:write select="concat($classname, '.java')"-->
  173. <!-- Handle enumeration values -->
  174. <xsl:text>
  175. public interface </xsl:text>
  176. <xsl:value-of select="$classname"/>
  177. <xsl:if test="use-generic">
  178. <xsl:text> extends </xsl:text>
  179. <xsl:value-of select="use-generic"/>
  180. <xsl:text>Interface</xsl:text>
  181. </xsl:if>
  182. <xsl:text> {</xsl:text>
  183. <xsl:for-each select="enumeration/value">
  184. <xsl:text>
  185. int </xsl:text>
  186. <xsl:value-of select="@const"/>
  187. <xsl:text> = Constants.</xsl:text>
  188. <xsl:value-of select="@const"/>
  189. <xsl:text>;</xsl:text>
  190. </xsl:for-each>
  191. <xsl:text> }
  192. </xsl:text>
  193. </xsl:if>
  194. </xsl:template>
  195. <xsl:template name="sortconsts">
  196. <xsl:param name="consts"/>
  197. <xsl:param name="prevconst"/>
  198. <xsl:param name="num" select="1"/>
  199. <xsl:param name="suffix" select="''"/>
  200. <xsl:param name="counter" select="''"/>
  201. <xsl:variable name="cval" select="substring-before($consts,':')"/>
  202. <xsl:choose>
  203. <xsl:when test="$consts = ''">
  204. <xsl:if test="$counter != ''">
  205. <xsl:text>
  206. int </xsl:text>
  207. <xsl:value-of select="$counter"/>_COUNT = <xsl:value-of select="$num - 1"/>;
  208. </xsl:if>
  209. </xsl:when>
  210. <xsl:when test="$cval = $prevconst">
  211. <xsl:call-template name="sortconsts">
  212. <xsl:with-param name="consts" select="substring-after($consts,concat($cval, ':'))"/>
  213. <xsl:with-param name="num" select="$num"/>
  214. <xsl:with-param name="prevconst" select="$cval"/>
  215. <xsl:with-param name="counter" select="$counter"/>
  216. <xsl:with-param name="suffix" select="$suffix"/>
  217. </xsl:call-template>
  218. </xsl:when>
  219. <xsl:otherwise>
  220. <xsl:text>
  221. int </xsl:text>
  222. <xsl:value-of select="$cval"/>
  223. <xsl:text> = </xsl:text>
  224. <xsl:value-of select="$num"/>
  225. <xsl:value-of select="$suffix"/>
  226. <xsl:text>;</xsl:text>
  227. <xsl:call-template name="sortconsts">
  228. <xsl:with-param name="consts" select="substring-after($consts,concat($cval, ':'))"/>
  229. <xsl:with-param name="num" select="$num + 1"/>
  230. <xsl:with-param name="prevconst" select="$cval"/>
  231. <xsl:with-param name="counter" select="$counter"/>
  232. <xsl:with-param name="suffix" select="$suffix"/>
  233. </xsl:call-template>
  234. </xsl:otherwise>
  235. </xsl:choose>
  236. </xsl:template>
  237. </xsl:stylesheet>