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.

fo-property-mapping.xsl 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. xmlns:lxslt="http://xml.apache.org/xslt">
  19. <xsl:include href="propinc.xsl"/>
  20. <xsl:output method="text" />
  21. <xsl:template name="genmaker">
  22. <xsl:param name="prop" select="."/>
  23. <xsl:param name="htname"/>
  24. <xsl:variable name="makerclass">
  25. <xsl:choose>
  26. <xsl:when test="$prop/use-generic and count($prop/*)=2">
  27. <xsl:value-of select="$prop/use-generic"/>
  28. </xsl:when>
  29. <xsl:when test="$prop/class-name">
  30. <xsl:value-of select="$prop/class-name"/><xsl:text>Maker</xsl:text>
  31. </xsl:when>
  32. <xsl:otherwise> <!-- make from name -->
  33. <xsl:call-template name="makeClassName">
  34. <xsl:with-param name="propstr" select="$prop/name"/>
  35. </xsl:call-template><xsl:text>Maker</xsl:text>
  36. </xsl:otherwise>
  37. </xsl:choose>
  38. </xsl:variable>
  39. <xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz-:'" />
  40. <xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ__'" />
  41. <xsl:variable name="enum" select="translate($prop/name, $lcletters, $ucletters)"/>
  42. <xsl:text> addPropertyName("</xsl:text><xsl:value-of select="$prop/name"/>", PR_<xsl:value-of select="$enum"/>);
  43. <xsl:text> </xsl:text><xsl:value-of select="$htname"/>[PR_<xsl:value-of select="$enum"/>] =<xsl:value-of select="$makerclass"/>.maker(PR_<xsl:value-of select="$enum"/>);
  44. </xsl:template>
  45. <xsl:template name="genenum">
  46. <xsl:param name="prop" select="."/>
  47. <xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz-:'" />
  48. <xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ__'" />
  49. <xsl:variable name="num" select="count(preceding-sibling::property)"/>
  50. <xsl:variable name="enum" select="translate($prop/name, $lcletters, $ucletters)"/>
  51. <!--
  52. <xsl:text> public final static short </xsl:text><xsl:value-of select="$enum"/> = <xsl:value-of select="$num"/>;
  53. -->
  54. </xsl:template>
  55. <xsl:template match="text()"/>
  56. <xsl:template match="text()" mode="enums"/>
  57. <xsl:template match="property-list">
  58. package org.apache.fop.fo.properties;
  59. import java.util.HashMap;
  60. import java.util.Set;
  61. import org.apache.fop.fo.Constants;
  62. import org.apache.fop.fo.Property;
  63. //import org.apache.fop.svg.*;
  64. public class <xsl:value-of select="@family"/>PropertyMapping implements Constants {
  65. private static Property.Maker[] s_htGeneric = new Property.Maker[PROPERTY_COUNT+1];
  66. /* s_htElementLists not currently used; apparently for specifying element-specific
  67. * property makers (instead of the default maker for a particular property); see
  68. * former org.apache.fop.fo.PropertyListBuilder
  69. */
  70. private static HashMap s_htElementLists = new HashMap();
  71. private static HashMap s_htSubPropNames = new HashMap();
  72. private static HashMap s_htPropNames = new HashMap();
  73. private static HashMap s_htPropIds = new HashMap();
  74. <xsl:for-each select="element-property-list">
  75. private static HashMap s_ht<xsl:value-of select="localname[1]"/>;</xsl:for-each>
  76. <xsl:apply-templates/>
  77. public static Property.Maker[] getGenericMappings() {
  78. return s_htGeneric;
  79. }
  80. public static Set getElementMappings() {
  81. return s_htElementLists.keySet();
  82. }
  83. public static Property.Maker[] getElementMapping(int elemName) {
  84. return (Property.Maker[])s_htElementLists.get(new Integer(elemName));
  85. }
  86. public static int getPropertyId(String name) {
  87. // check to see if base.compound or just base property
  88. int sepchar = name.indexOf('.');
  89. if (sepchar > -1) {
  90. Integer baseId = (Integer) s_htPropNames.get(name.substring(0, sepchar));
  91. if (baseId == null) {
  92. return -1;
  93. } else {
  94. int cmpdId = getSubPropertyId(name.substring(sepchar + 1));
  95. if (cmpdId == -1) {
  96. return -1;
  97. } else {
  98. return baseId.intValue() + cmpdId;
  99. }
  100. }
  101. } else {
  102. Integer baseId = (Integer) s_htPropNames.get(name);
  103. if (baseId == null)
  104. return -1;
  105. return baseId.intValue();
  106. }
  107. }
  108. public static int getSubPropertyId(String name) {
  109. Integer i = (Integer) s_htSubPropNames.get(name);
  110. if (i == null)
  111. return -1;
  112. return i.intValue();
  113. }
  114. // returns a property, compound, or property.compound name
  115. public static String getPropertyName(int id) {
  116. if (((id &amp; Constants.COMPOUND_MASK) == 0)
  117. || ((id &amp; Constants.PROPERTY_MASK) == 0)) {
  118. return (String) s_htPropIds.get(new Integer(id));
  119. } else {
  120. return (String) s_htPropIds.get(new Integer(
  121. id &amp; Constants.PROPERTY_MASK)) + "." + s_htPropIds.get(
  122. new Integer(id &amp; Constants.COMPOUND_MASK));
  123. }
  124. }
  125. static {
  126. addSubPropertyName("length", CP_LENGTH);
  127. addSubPropertyName("conditionality", CP_CONDITIONALITY);
  128. addSubPropertyName("block-progression-direction", CP_BLOCK_PROGRESSION_DIRECTION);
  129. addSubPropertyName("inline-progression-direction", CP_INLINE_PROGRESSION_DIRECTION);
  130. addSubPropertyName("within-line", CP_WITHIN_LINE);
  131. addSubPropertyName("within-column", CP_WITHIN_COLUMN);
  132. addSubPropertyName("within-page", CP_WITHIN_PAGE);
  133. addSubPropertyName("minimum", CP_MINIMUM);
  134. addSubPropertyName("maximum", CP_MAXIMUM);
  135. addSubPropertyName("optimum", CP_OPTIMUM);
  136. addSubPropertyName("precedence", CP_PRECEDENCE);
  137. }
  138. public static void addPropertyName(String name, int id) {
  139. s_htPropNames.put(name, new Integer(id));
  140. s_htPropIds.put(new Integer(id), name);
  141. }
  142. public static void addSubPropertyName(String name, int id) {
  143. s_htSubPropNames.put(name, new Integer(id));
  144. s_htPropIds.put(new Integer(id), name);
  145. }
  146. }
  147. </xsl:template>
  148. <xsl:template match="generic-property-list">
  149. <xsl:apply-templates mode="enums"/>
  150. static {
  151. // Generate the generic mapping
  152. <xsl:apply-templates>
  153. <xsl:with-param name="htname" select='"s_htGeneric"'/>
  154. </xsl:apply-templates>
  155. }
  156. </xsl:template>
  157. <xsl:template match="element-property-list">
  158. <xsl:variable name="ename" select="localname[1]"/>
  159. static {
  160. s_ht<xsl:value-of select="$ename"/> = new HashMap();
  161. <xsl:for-each select="localname">
  162. s_htElementLists.put("<xsl:value-of select='.'/>", s_ht<xsl:value-of select='$ename'/>);
  163. </xsl:for-each>
  164. <xsl:apply-templates>
  165. <xsl:with-param name='htname'>s_ht<xsl:value-of select="$ename"/></xsl:with-param>
  166. </xsl:apply-templates>
  167. }
  168. </xsl:template>
  169. <xsl:template match="property[@type='generic']" mode="enums">
  170. /* PROPCLASS = <xsl:call-template name="propclass"/> */
  171. </xsl:template>
  172. <xsl:template match="property" mode="enums">
  173. <xsl:param name="htname"/>
  174. <xsl:variable name="refname" select="name"/>
  175. <xsl:choose>
  176. <xsl:when test="@type='ref'">
  177. <xsl:call-template name="genenum">
  178. <xsl:with-param name="htname" select="$htname"/>
  179. <xsl:with-param name="prop"
  180. select='document(concat(@family, "properties.xml"))//property[name=$refname]'/>
  181. </xsl:call-template>
  182. </xsl:when>
  183. <xsl:when test="not(@type)">
  184. <xsl:call-template name="genenum">
  185. <xsl:with-param name="htname" select="$htname"/>
  186. </xsl:call-template>
  187. </xsl:when>
  188. <xsl:otherwise/>
  189. </xsl:choose>
  190. </xsl:template>
  191. <xsl:template match="subproperty" mode="enums">
  192. <xsl:call-template name="genenum"/>
  193. </xsl:template>
  194. <xsl:template match="property">
  195. <xsl:param name="htname"/>
  196. <xsl:variable name="refname" select="name"/>
  197. <xsl:choose>
  198. <xsl:when test="@type='ref'">
  199. <xsl:call-template name="genmaker">
  200. <xsl:with-param name="htname" select="$htname"/>
  201. <xsl:with-param name="prop"
  202. select='document(concat(@family, "properties.xml"))//property[name=$refname]'/>
  203. </xsl:call-template>
  204. </xsl:when>
  205. <xsl:when test="not(@type)">
  206. <xsl:call-template name="genmaker">
  207. <xsl:with-param name="htname" select="$htname"/>
  208. </xsl:call-template>
  209. </xsl:when>
  210. <xsl:otherwise/>
  211. </xsl:choose>
  212. </xsl:template>
  213. <xsl:template match="property[@type='generic']">
  214. /* PROPCLASS = <xsl:call-template name="propclass"/> */
  215. </xsl:template>
  216. </xsl:stylesheet>