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.

properties.xsl 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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:template match="property" priority="-1">
  8. <xsl:variable name="classname" select="class-name"/>
  9. <redirect:write select="concat('@org/apache/fop@/fo/properties/', $classname, '.java')">
  10. package org.apache.fop.fo.properties;
  11. import org.apache.fop.datatypes.*;
  12. import org.apache.fop.fo.*;
  13. import org.apache.fop.apps.FOPException;
  14. public class <xsl:value-of select="class-name"/> extends Property {
  15. public static class Maker extends Property.Maker {
  16. public boolean isInherited() { return <xsl:value-of select="inherited"/>; }
  17. public Property make(PropertyList propertyList, String value) throws FOPException {
  18. <xsl:choose>
  19. <xsl:when test="make">
  20. <xsl:variable name="datatype" select="datatype"/>
  21. <xsl:value-of select="$datatype"/> v;
  22. <xsl:if test="make/to-double">
  23. double d = toDouble(value);
  24. </xsl:if>
  25. <xsl:for-each select="make/if">
  26. if (value.equals("<xsl:value-of select="@match"/>")) {
  27. v = new <xsl:value-of select="$datatype"/>(<xsl:value-of select="."/>);
  28. }
  29. </xsl:for-each>
  30. <xsl:for-each select="make/else-if-number">
  31. else if (!Double.isNaN(d)) {
  32. v = new <xsl:value-of select="$datatype"/>( <xsl:value-of select="."/>);
  33. }
  34. </xsl:for-each>
  35. else {
  36. v = new <xsl:value-of select="datatype"/>(<xsl:value-of select="make/else"/>);
  37. }
  38. return new <xsl:value-of select="class-name"/>(propertyList, v);
  39. </xsl:when>
  40. <xsl:otherwise>
  41. return new <xsl:value-of select="class-name"/>(propertyList, new <xsl:value-of select="datatype"/>(value));
  42. </xsl:otherwise>
  43. </xsl:choose>
  44. }
  45. public Property make(PropertyList propertyList) throws FOPException {
  46. return make(propertyList, "<xsl:value-of select="default"/>");
  47. }
  48. }
  49. public static Property.Maker maker() {
  50. return new <xsl:value-of select="class-name"/>.Maker();
  51. }
  52. private <xsl:value-of select="datatype"/> value;
  53. public <xsl:value-of select="class-name"/>(PropertyList propertyList, <xsl:value-of select="datatype"/> explicitValue) {
  54. this.propertyList = propertyList;
  55. this.value = explicitValue;
  56. }
  57. public <xsl:value-of select="datatype"/> get<xsl:value-of select="datatype"/>() {
  58. return this.value;
  59. }
  60. }
  61. </redirect:write>
  62. </xsl:template>
  63. <xsl:template match="property[datatype/enumeration]">
  64. <xsl:variable name="classname" select="class-name"/>
  65. <redirect:write select="concat('@org/apache/fop@/fo/properties/', $classname, '.java')">
  66. package org.apache.fop.fo.properties;
  67. import org.apache.fop.datatypes.*;
  68. import org.apache.fop.fo.*;
  69. import org.apache.fop.apps.FOPException;
  70. public class <xsl:value-of select="class-name"/> extends Property {
  71. <xsl:for-each select="datatype/enumeration/value">
  72. public final static int <xsl:value-of select="@const"/> = <xsl:number/>;</xsl:for-each>
  73. public static class Maker extends Property.Maker {
  74. public boolean isInherited() { return <xsl:value-of select="inherited"/>; }
  75. public Property make(PropertyList propertyList, String value) throws FOPException {
  76. int v;
  77. <xsl:for-each select="datatype/enumeration/value">
  78. if (value.equals("<xsl:value-of select="."/>")) { v = <xsl:value-of select="@const"/>; }
  79. else</xsl:for-each>
  80. {
  81. System.err.println("WARNING: Unknown value for <xsl:value-of select="name"/>: " + value);
  82. return make(propertyList, "<xsl:value-of select="default"/>");
  83. }
  84. return new <xsl:value-of select="class-name"/>(propertyList, v);
  85. }
  86. public Property make(PropertyList propertyList) throws FOPException {
  87. return make(propertyList, "<xsl:value-of select="default"/>");
  88. }
  89. <xsl:if test="derive">
  90. public Property compute(PropertyList propertyList) {
  91. Property computedProperty = null;
  92. Property correspondingProperty = propertyList.get("<xsl:value-of select="derive/@from"/>");
  93. if (correspondingProperty != null) {
  94. int correspondingValue = correspondingProperty.getEnum();
  95. <xsl:for-each select="derive/if">
  96. if (correspondingValue == <xsl:value-of select="@match"/>)
  97. computedProperty = new <xsl:value-of select="$classname"/>(propertyList, <xsl:value-of select="."/>);
  98. else</xsl:for-each>
  99. ;
  100. }
  101. return computedProperty;
  102. }
  103. </xsl:if>
  104. }
  105. public static Property.Maker maker() {
  106. return new <xsl:value-of select="class-name"/>.Maker();
  107. }
  108. private int value;
  109. public <xsl:value-of select="class-name"/>(PropertyList propertyList, int explicitValue) {
  110. this.propertyList = propertyList;
  111. this.value = explicitValue;
  112. }
  113. public int getEnum() {
  114. return this.value;
  115. }
  116. }
  117. </redirect:write>
  118. </xsl:template>
  119. </xsl:stylesheet>