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 36KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. <!--
  2. Copyright 1999-2004 The Apache Software Foundation
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. -->
  13. <!-- $Id$ -->
  14. <xsl:stylesheet version="1.0"
  15. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  16. xmlns:lxslt="http://xml.apache.org/xslt"
  17. xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
  18. extension-element-prefixes="redirect">
  19. <xsl:include href="./propinc.xsl"/>
  20. <xsl:output method="text" />
  21. <xsl:template match="extfile">
  22. <!--<xsl:message>Do <xsl:value-of select="@href"/></xsl:message>-->
  23. <xsl:apply-templates select="document(@href)/*"/>
  24. </xsl:template>
  25. <!-- Content of element is code to calculate the base length -->
  26. <xsl:template match="percent-ok">
  27. <xsl:text>
  28. /** Return object used to calculate base Length
  29. * for percent specifications.
  30. */
  31. public PercentBase getPercentBase(final FObj fo, final PropertyList propertyList) {</xsl:text>
  32. <xsl:choose>
  33. <xsl:when test="@base">
  34. <xsl:text>
  35. return new LengthBase(fo, propertyList, LengthBase.</xsl:text>
  36. <xsl:value-of select="@base"/><xsl:text>);
  37. </xsl:text>
  38. </xsl:when>
  39. <xsl:otherwise>
  40. <!-- I have no idea what's happening here. Is this supposed to be
  41. an anonymous class returning the actual base length?
  42. -->
  43. <xsl:text>
  44. return new LengthBase(fo, propertyList, LengthBase.CUSTOM_BASE) {
  45. public int getBaseLength() {
  46. return (</xsl:text>
  47. <xsl:value-of select="."/>
  48. <xsl:text>);
  49. }
  50. });</xsl:text>
  51. </xsl:otherwise>
  52. </xsl:choose>
  53. <xsl:text>
  54. }</xsl:text>
  55. </xsl:template>
  56. <!-- Look for "auto" length keyword -->
  57. <xsl:template match="auto-ok">
  58. <xsl:text>
  59. protected boolean isAutoLengthAllowed() {
  60. return true;
  61. }</xsl:text>
  62. </xsl:template>
  63. <xsl:template match="enumeration">
  64. <xsl:text>
  65. public Property checkEnumValues(String value) {</xsl:text>
  66. <xsl:for-each select="value">
  67. <xsl:call-template name="enumvals">
  68. <xsl:with-param name="specvals" select="concat(.,' ')"/>
  69. </xsl:call-template>
  70. </xsl:for-each>
  71. <xsl:text>
  72. return super.checkEnumValues(value);
  73. }</xsl:text>
  74. </xsl:template>
  75. <!-- Look for keyword equivalents. Value is the new expression -->
  76. <xsl:template match="keyword-equiv[1]">
  77. <xsl:text>
  78. // Initialize hashtable of keywords
  79. static HashMap s_htKeywords;
  80. static {
  81. s_htKeywords = new HashMap(</xsl:text>
  82. <xsl:value-of select="count(../keyword-equiv)"/>
  83. <xsl:text>);</xsl:text>
  84. <xsl:for-each select="../keyword-equiv">
  85. <xsl:text>
  86. s_htKeywords.put("</xsl:text>
  87. <xsl:value-of select="@match"/>
  88. <xsl:text>", "</xsl:text>
  89. <xsl:value-of select="."/>
  90. <xsl:text>");</xsl:text>
  91. </xsl:for-each>
  92. <xsl:text>
  93. }
  94. protected String checkValueKeywords(String keyword) {
  95. String value = (String)s_htKeywords.get(keyword);
  96. if (value == null) {
  97. return super.checkValueKeywords(keyword);
  98. }
  99. else return value;
  100. }</xsl:text>
  101. </xsl:template>
  102. <xsl:template match="keyword-equiv[position()>1]"/>
  103. <!-- Generate code to convert from other datatypes to property datatype -->
  104. <xsl:template match='datatype-conversion[1]'>
  105. <xsl:variable name="propclass">
  106. <xsl:choose>
  107. <xsl:when test="../compound">
  108. <xsl:call-template name="propclass">
  109. <xsl:with-param name="prop"
  110. select="../compound/subproperty[@set-by-shorthand]"/>
  111. </xsl:call-template>
  112. </xsl:when><xsl:otherwise>
  113. <xsl:call-template name="propclass">
  114. <xsl:with-param name="prop" select=".."/>
  115. </xsl:call-template>
  116. </xsl:otherwise>
  117. </xsl:choose>
  118. </xsl:variable>
  119. <xsl:text>
  120. // See if other value types are acceptable
  121. protected Property convertPropertyDatatype(
  122. Property p, PropertyList propertyList, FObj fo) {</xsl:text>
  123. <xsl:for-each select="../datatype-conversion">
  124. <xsl:variable name="dtc">
  125. <xsl:choose>
  126. <xsl:when test="@vartype">
  127. <xsl:value-of select="@vartype"/>
  128. </xsl:when><xsl:otherwise>
  129. <xsl:value-of select="@from-type"/>
  130. </xsl:otherwise>
  131. </xsl:choose>
  132. </xsl:variable>
  133. <xsl:text>
  134. </xsl:text>
  135. <xsl:value-of select="$dtc"/>
  136. <xsl:text> </xsl:text>
  137. <xsl:value-of select="@varname"/>
  138. <xsl:text> = p.get</xsl:text>
  139. <xsl:value-of select="@from-type"/>
  140. <xsl:text>();
  141. if (</xsl:text>
  142. <xsl:value-of select="@varname"/>
  143. <xsl:text> != null) {
  144. return new </xsl:text>
  145. <xsl:value-of select="$propclass"/><xsl:text>(
  146. </xsl:text>
  147. <xsl:value-of select='normalize-space(.)'/><xsl:text>);
  148. }</xsl:text>
  149. </xsl:for-each>
  150. <xsl:text>
  151. return super.convertPropertyDatatype(p, propertyList, fo);
  152. }</xsl:text>
  153. </xsl:template>
  154. <xsl:template match="datatype-conversion[position()>1]"/>
  155. <!-- generate getDefaultForXXX for property components -->
  156. <xsl:template match="default[@subproperty]" priority="2">
  157. <xsl:variable name="spname">
  158. <xsl:call-template name="makeClassName">
  159. <xsl:with-param name="propstr" select="@subproperty"/>
  160. </xsl:call-template>
  161. </xsl:variable>
  162. <xsl:text>
  163. protected String getDefaultFor</xsl:text>
  164. <xsl:value-of select='$spname'/>
  165. <xsl:text>() {
  166. return "</xsl:text>
  167. <xsl:value-of select='.'/>
  168. <xsl:text>";
  169. }</xsl:text>
  170. </xsl:template>
  171. <!-- generate default "make" method for non-compound properties -->
  172. <xsl:template match="default[not(../compound)]" priority="1">
  173. <xsl:if test='not(@contextdep = "true")'>
  174. <xsl:text>
  175. private Property m_defaultProp=null;</xsl:text>
  176. </xsl:if>
  177. <xsl:text>
  178. public Property make(PropertyList propertyList) throws FOPException {</xsl:text>
  179. <xsl:choose>
  180. <xsl:when test='@contextdep="true"'>
  181. <xsl:text>
  182. return make(propertyList, "</xsl:text>
  183. <xsl:value-of select='.'/>
  184. <xsl:text>", propertyList.getParentFObj());</xsl:text>
  185. </xsl:when>
  186. <xsl:otherwise>
  187. <xsl:text>
  188. if (m_defaultProp == null) {
  189. m_defaultProp=make(propertyList, "</xsl:text>
  190. <xsl:value-of select='.'/>
  191. <xsl:text>", propertyList.getParentFObj());
  192. }
  193. return m_defaultProp;</xsl:text>
  194. </xsl:otherwise>
  195. </xsl:choose>
  196. <xsl:text>
  197. }</xsl:text>
  198. </xsl:template>
  199. <xsl:template match="text()"/>
  200. <!-- Ignore properties which reference others. Only for mapping! -->
  201. <xsl:template match="property[@type='ref']"/>
  202. <!-- Only if more explicit rules not matched (ref) -->
  203. <xsl:template match="property">
  204. <!-- Only create a specific class for those properties not based on
  205. template (generic) property definitions or which extends a
  206. generic definition.
  207. -->
  208. <xsl:if test='not(use-generic) or count(*)>2'>
  209. <xsl:variable name="eclassname">
  210. <xsl:choose>
  211. <xsl:when test="class-name">
  212. <xsl:value-of select="class-name"/>
  213. </xsl:when>
  214. <xsl:otherwise>
  215. <xsl:call-template name="makeClassName">
  216. <xsl:with-param name="propstr" select="name"/>
  217. </xsl:call-template>
  218. </xsl:otherwise>
  219. </xsl:choose>
  220. </xsl:variable>
  221. <xsl:variable name="classname">
  222. <xsl:value-of select="$eclassname"/>
  223. <xsl:if test="not(@type='generic')">
  224. <xsl:text>Maker</xsl:text>
  225. </xsl:if>
  226. </xsl:variable>
  227. <!-- The class of the Property object to be created -->
  228. <xsl:variable name="propclass">
  229. <xsl:call-template name="propclass"/>
  230. </xsl:variable>
  231. <!-- The superclass for this PropertyMaker -->
  232. <xsl:variable name="superclass">
  233. <xsl:choose>
  234. <xsl:when test="use-generic[@ispropclass='true']">
  235. <xsl:value-of select="use-generic"/><xsl:text>.Maker</xsl:text>
  236. </xsl:when>
  237. <xsl:when test="use-generic">
  238. <xsl:value-of select="use-generic"/>
  239. </xsl:when>
  240. <xsl:otherwise>
  241. <xsl:value-of select="datatype"/><xsl:text>Property.Maker</xsl:text>
  242. </xsl:otherwise>
  243. </xsl:choose>
  244. </xsl:variable>
  245. <!-- Is this property an Enum or derived from a generic Enum -->
  246. <xsl:variable name="enumconst">
  247. <xsl:if test="enumeration/value and not(@type='generic')">
  248. <xsl:text> implements Constants</xsl:text></xsl:if>
  249. </xsl:variable>
  250. <redirect:write select="concat($classname, '.java')">
  251. <xsl:text>package org.apache.fop.fo.properties;
  252. </xsl:text>
  253. <xsl:if test=".//keyword-equiv or ./name[.='generic-color']">
  254. <xsl:text>
  255. import java.util.HashMap;</xsl:text>
  256. </xsl:if>
  257. <xsl:if test=
  258. "((./datatype and
  259. (not (./datatype[.='String' or .='Enum' or .='List'
  260. or .='Length' or .='Character' or .='Number'])
  261. or (./datatype[.='Length'] and ./percent-ok)
  262. ) )
  263. or .//datatype-conversion)
  264. and ./name[. !='generic-color']">
  265. <xsl:text>
  266. import org.apache.fop.datatypes.*;</xsl:text>
  267. </xsl:if>
  268. <xsl:text>
  269. import org.apache.fop.fo.*;</xsl:text>
  270. <xsl:if test="not(
  271. (./datatype and ./datatype[. ='List'])
  272. or ./class-name[.='GenericCondPadding']
  273. or ./name[.='generic-boolean'
  274. or .='generic-color'])">
  275. <xsl:text>
  276. import org.apache.fop.apps.FOPException;</xsl:text>
  277. </xsl:if>
  278. <xsl:if test=".//enumeration and @type='generic'">
  279. <xsl:text>
  280. import org.apache.fop.fo.Constants;</xsl:text>
  281. </xsl:if>
  282. <xsl:text>
  283. public class </xsl:text>
  284. <xsl:value-of select="$classname"/>
  285. <xsl:text> extends </xsl:text>
  286. <xsl:value-of select="$superclass"/><xsl:value-of select="$enumconst"/>
  287. <xsl:text> {</xsl:text>
  288. <!-- If has enumerated values and is a generic class, create a nested
  289. interface defining the enumeration constants -->
  290. <xsl:if test=".//enumeration and @type='generic'">
  291. <xsl:text>
  292. public interface Enums {</xsl:text>
  293. <xsl:for-each select="enumeration/value">
  294. <xsl:text>
  295. int </xsl:text>
  296. <xsl:value-of select="@const"/>
  297. <xsl:text> = Constants.</xsl:text>
  298. <xsl:value-of select="@const"/>
  299. <xsl:text>;</xsl:text>
  300. </xsl:for-each>
  301. <xsl:for-each select="compound/subproperty[enumeration]">
  302. <xsl:variable name="spname">
  303. <xsl:call-template name="makeClassName">
  304. <xsl:with-param name="propstr" select="name"/>
  305. </xsl:call-template>
  306. </xsl:variable>
  307. <xsl:text>
  308. public interface </xsl:text>
  309. <xsl:value-of select="$spname"/>
  310. <xsl:text> {</xsl:text>
  311. <xsl:for-each select="enumeration/value">
  312. <xsl:text>
  313. int </xsl:text>
  314. <xsl:value-of select="@const"/>
  315. <xsl:text> = Constants.</xsl:text>
  316. <xsl:value-of select="@const"/>
  317. <xsl:text>;</xsl:text>
  318. </xsl:for-each>
  319. <xsl:text>
  320. }</xsl:text>
  321. </xsl:for-each>
  322. <xsl:text>
  323. }</xsl:text>
  324. </xsl:if>
  325. <!-- Handle enumeration values -->
  326. <xsl:for-each select="enumeration/value">
  327. <xsl:text>
  328. protected final static EnumProperty s_prop</xsl:text>
  329. <xsl:value-of select="@const"/>
  330. <xsl:text> = new EnumProperty(</xsl:text>
  331. <xsl:if test="../../@type='generic'">
  332. <xsl:text>Enums.</xsl:text>
  333. </xsl:if>
  334. <xsl:value-of select="@const"/>
  335. <xsl:text>);</xsl:text>
  336. </xsl:for-each>
  337. <!-- Look for compound properties -->
  338. <xsl:if test="compound">
  339. <xsl:variable name="enumclass">
  340. <xsl:choose>
  341. <xsl:when test="@type='generic'">
  342. <xsl:text>Enums</xsl:text>
  343. </xsl:when>
  344. <xsl:otherwise>
  345. <xsl:value-of select="$eclassname"/>
  346. </xsl:otherwise>
  347. </xsl:choose>
  348. </xsl:variable>
  349. <xsl:for-each select="compound/subproperty">
  350. <xsl:variable name="spname">
  351. <xsl:call-template name="makeClassName">
  352. <xsl:with-param name="propstr" select="name"/>
  353. </xsl:call-template>
  354. </xsl:variable>
  355. <xsl:variable name="sp_superclass">
  356. <xsl:choose>
  357. <xsl:when test="use-generic">
  358. <xsl:value-of select="use-generic"/>
  359. </xsl:when>
  360. <xsl:otherwise>
  361. <xsl:value-of select="datatype"/>
  362. <xsl:text>Property.Maker</xsl:text>
  363. </xsl:otherwise>
  364. </xsl:choose>
  365. </xsl:variable>
  366. <xsl:choose>
  367. <xsl:when test='*[local-name(.)!="name" and local-name(.)!="datatype" and local-name(.)!="use-generic" and local-name(.)!="default"]'>
  368. <xsl:text>
  369. static private class SP_</xsl:text>
  370. <xsl:value-of select="$spname"/>
  371. <xsl:text>Maker extends </xsl:text>
  372. <xsl:value-of select="$sp_superclass"/>
  373. <xsl:if test="enumeration">
  374. <xsl:text> implements </xsl:text>
  375. <xsl:value-of select="$enumclass"/>
  376. <xsl:text>.</xsl:text>
  377. <xsl:value-of select="$spname"/>
  378. </xsl:if>
  379. <xsl:text> {
  380. SP_</xsl:text>
  381. <xsl:value-of select="$spname"/>
  382. <xsl:text>Maker(int sPropName) {
  383. super(sPropName);
  384. }</xsl:text>
  385. <xsl:for-each select="enumeration/value">
  386. <xsl:text>
  387. protected final static EnumProperty s_prop</xsl:text>
  388. <xsl:value-of select="@const"/>
  389. <xsl:text> = new EnumProperty(</xsl:text>
  390. <xsl:value-of select="@const"/>
  391. <xsl:text>);</xsl:text>
  392. </xsl:for-each>
  393. <xsl:apply-templates
  394. select="percent-ok|auto-ok|keyword-equiv|
  395. datatype-conversion|enumeration"/>
  396. <xsl:text>
  397. }
  398. final private static Property.Maker s_</xsl:text>
  399. <xsl:value-of select="$spname"/>
  400. <xsl:text>Maker =
  401. new SP_</xsl:text><xsl:value-of select="$spname"/>
  402. <xsl:text>Maker(</xsl:text>
  403. <xsl:if test="not(../../@type = 'generic')">
  404. <xsl:text>Constants.PR_</xsl:text>
  405. <xsl:call-template name="makeEnumConstant">
  406. <xsl:with-param name="propstr" select="../../name"/>
  407. </xsl:call-template>
  408. <xsl:text> | </xsl:text>
  409. </xsl:if>
  410. <xsl:text>Constants.CP_</xsl:text>
  411. <xsl:call-template name="makeEnumConstant">
  412. <xsl:with-param name="propstr" select="name"/>
  413. </xsl:call-template>
  414. <xsl:text>);</xsl:text>
  415. </xsl:when>
  416. <xsl:otherwise>
  417. <xsl:text>
  418. final private static Property.Maker s_</xsl:text>
  419. <xsl:value-of select="$spname"/>
  420. <xsl:text>Maker =
  421. new </xsl:text><xsl:value-of select="$sp_superclass"/>
  422. <xsl:text>(</xsl:text>
  423. <xsl:if test="not(../../@type = 'generic')">
  424. <xsl:text>Constants.PR_</xsl:text>
  425. <xsl:call-template name="makeEnumConstant">
  426. <xsl:with-param name="propstr" select="../../name"/>
  427. </xsl:call-template>
  428. <xsl:text> | </xsl:text>
  429. </xsl:if>
  430. <xsl:text>Constants.CP_</xsl:text>
  431. <xsl:call-template name="makeEnumConstant">
  432. <xsl:with-param name="propstr" select="name"/>
  433. </xsl:call-template>
  434. <xsl:text>);</xsl:text>
  435. </xsl:otherwise>
  436. </xsl:choose>
  437. </xsl:for-each>
  438. </xsl:if>
  439. <xsl:text>
  440. static public Property.Maker maker(int propertyId) {
  441. return new </xsl:text>
  442. <xsl:value-of select="$classname"/>
  443. <xsl:text>(propertyId);
  444. }
  445. protected </xsl:text>
  446. <xsl:value-of select="$classname"/>
  447. <xsl:text>(int propId) {
  448. super(propId);</xsl:text>
  449. <xsl:if test="compound">
  450. <xsl:text>
  451. m_shorthandMaker= getSubpropMaker(Constants.CP_</xsl:text>
  452. <xsl:call-template name="makeEnumConstant">
  453. <xsl:with-param name="propstr" select=
  454. 'compound/subproperty[@set-by-shorthand="true"]/name'/>
  455. </xsl:call-template>
  456. <xsl:text>);</xsl:text>
  457. </xsl:if>
  458. <xsl:text>
  459. }
  460. </xsl:text>
  461. <xsl:if test="compound">
  462. <xsl:text>
  463. Property.Maker m_shorthandMaker;
  464. public Property checkEnumValues(String value) {
  465. return m_shorthandMaker.checkEnumValues(value);
  466. }
  467. protected boolean isCompoundMaker() {
  468. return true;
  469. }
  470. protected Property.Maker getSubpropMaker(int subpropId) {</xsl:text>
  471. <xsl:for-each select="compound/subproperty">
  472. <xsl:variable name="spname">
  473. <xsl:call-template name="makeClassName">
  474. <xsl:with-param name="propstr" select="name"/>
  475. </xsl:call-template>
  476. </xsl:variable>
  477. <xsl:text>
  478. if (subpropId == Constants.CP_</xsl:text>
  479. <xsl:call-template name="makeEnumConstant">
  480. <xsl:with-param name="propstr" select="name"/>
  481. </xsl:call-template>
  482. <xsl:text>)
  483. return s_</xsl:text>
  484. <xsl:value-of select="$spname"/>
  485. <xsl:text>Maker;</xsl:text>
  486. </xsl:for-each>
  487. <xsl:text>
  488. return super.getSubpropMaker(subpropId);
  489. }
  490. protected Property setSubprop(Property baseProp, int subpropId,
  491. Property subProp) {
  492. </xsl:text>
  493. <xsl:value-of select="datatype"/>
  494. <xsl:text> val = baseProp.get</xsl:text>
  495. <xsl:value-of select="datatype"/>
  496. <xsl:text>();
  497. // Do some type checking???
  498. // Check if one of our subproperties???
  499. val.setComponent(subpropId, subProp, false);
  500. return baseProp;
  501. }
  502. public Property getSubpropValue(Property baseProp, int subpropId) {
  503. </xsl:text>
  504. <xsl:value-of select="datatype"/>
  505. <xsl:text> val = baseProp.get</xsl:text>
  506. <xsl:value-of select="datatype"/>
  507. <xsl:text>();
  508. return val.getComponent(subpropId);
  509. }
  510. </xsl:text>
  511. <xsl:choose>
  512. <!-- some subproperty default is context dependent;
  513. don't cache default! -->
  514. <xsl:when test='.//default[@contextdep="true"]'>
  515. <xsl:text>
  516. public Property make(PropertyList propertyList) throws FOPException {
  517. return makeCompound(propertyList, propertyList.getParentFObj());
  518. }</xsl:text>
  519. </xsl:when>
  520. <xsl:otherwise>
  521. <xsl:text>
  522. private Property m_defaultProp=null;
  523. public Property make(PropertyList propertyList) throws FOPException {
  524. if (m_defaultProp == null) {
  525. m_defaultProp=makeCompound(
  526. propertyList, propertyList.getParentFObj());
  527. }
  528. return m_defaultProp;
  529. }</xsl:text>
  530. </xsl:otherwise>
  531. </xsl:choose>
  532. <xsl:text>
  533. protected Property makeCompound(PropertyList pList, FObj fo) throws FOPException {</xsl:text>
  534. <xsl:value-of select="datatype"/>
  535. <xsl:text> p = new </xsl:text>
  536. <xsl:value-of select="datatype"/>
  537. <xsl:text>();
  538. Property subProp;</xsl:text>
  539. <xsl:for-each select="compound/subproperty/name">
  540. <xsl:variable name="spname">
  541. <xsl:call-template name="makeClassName">
  542. <xsl:with-param name="propstr" select="."/>
  543. </xsl:call-template>
  544. </xsl:variable>
  545. <xsl:text>
  546. // set default for subprop </xsl:text>
  547. <xsl:value-of select="."/>
  548. <xsl:text>
  549. subProp = getSubpropMaker(Constants.CP_</xsl:text>
  550. <xsl:call-template name="makeEnumConstant">
  551. <xsl:with-param name="propstr" select="."/>
  552. </xsl:call-template>
  553. <xsl:text>).make(pList, getDefaultFor</xsl:text>
  554. <xsl:value-of select='$spname'/>
  555. <xsl:text>(), fo);
  556. p.setComponent(Constants.CP_</xsl:text>
  557. <xsl:call-template name="makeEnumConstant">
  558. <xsl:with-param name="propstr" select="."/>
  559. </xsl:call-template>
  560. <xsl:text>, subProp, true);</xsl:text>
  561. </xsl:for-each>
  562. <xsl:text>
  563. return new </xsl:text>
  564. <xsl:value-of select="$propclass"/>
  565. <xsl:text>(p);
  566. }
  567. </xsl:text>
  568. <!-- generate a "getDefaultForXXX" for each subproperty XXX -->
  569. <xsl:for-each select="compound/subproperty">
  570. <xsl:variable name="spname">
  571. <xsl:call-template name="makeClassName">
  572. <xsl:with-param name="propstr" select="name"/>
  573. </xsl:call-template>
  574. </xsl:variable>
  575. <xsl:text>
  576. protected String getDefaultFor</xsl:text>
  577. <xsl:value-of select='$spname'/>
  578. <xsl:text>() {</xsl:text>
  579. <xsl:choose>
  580. <xsl:when test="default">
  581. <xsl:text>
  582. return "</xsl:text>
  583. <xsl:value-of select='default'/>
  584. <xsl:text>";</xsl:text>
  585. </xsl:when>
  586. <xsl:when test=
  587. "use-generic and key('genericref', use-generic)/default">
  588. <xsl:text>
  589. return "</xsl:text>
  590. <xsl:value-of select='key(&apos;genericref&apos;,
  591. use-generic)/default'/>
  592. <xsl:text>";</xsl:text>
  593. </xsl:when>
  594. <xsl:otherwise>
  595. <xsl:text>
  596. return "";</xsl:text>
  597. </xsl:otherwise>
  598. </xsl:choose>
  599. <xsl:text>
  600. }</xsl:text>
  601. </xsl:for-each>
  602. <xsl:text>
  603. /** Set the appropriate components when the "base" property is set. */
  604. public Property convertProperty(Property p, PropertyList pList,FObj fo)
  605. throws FOPException {
  606. if (p instanceof </xsl:text>
  607. <xsl:value-of select="$propclass"/>
  608. <xsl:text>) return p;
  609. if (! (p instanceof EnumProperty)) {
  610. // delegate to the subprop maker to do conversions
  611. p = m_shorthandMaker.convertProperty(p,pList,fo);
  612. }
  613. if (p != null) {
  614. Property prop = makeCompound(pList, fo);
  615. </xsl:text>
  616. <xsl:value-of select="datatype"/>
  617. <xsl:text> pval = prop.get</xsl:text>
  618. <xsl:value-of select="datatype"/>
  619. <xsl:text>();</xsl:text>
  620. <xsl:for-each select="compound/subproperty[@set-by-shorthand='true']">
  621. <xsl:text>
  622. pval.setComponent(Constants.CP_</xsl:text>
  623. <xsl:call-template name="makeEnumConstant">
  624. <xsl:with-param name="propstr" select="name"/>
  625. </xsl:call-template>
  626. <xsl:text>, p, false);</xsl:text>
  627. </xsl:for-each>
  628. <xsl:text>
  629. return prop;
  630. }
  631. else return null;</xsl:text>
  632. <!--
  633. else {
  634. // throw some kind of exception!
  635. throw new FOPException("Can't convert value to <xsl:value-of select='$spdt'/> type");
  636. }
  637. -->
  638. <xsl:text>
  639. }
  640. </xsl:text>
  641. </xsl:if> <!-- property/compound -->
  642. <xsl:if test="inherited">
  643. <xsl:text>
  644. public boolean isInherited() {
  645. return </xsl:text>
  646. <xsl:value-of select="inherited"/>
  647. <xsl:text>;
  648. }
  649. </xsl:text>
  650. </xsl:if>
  651. <!-- the default implementation returns false -->
  652. <xsl:if test='inherited/@type="specified"'>
  653. <xsl:text>
  654. public boolean inheritsSpecified() {
  655. return true;
  656. }
  657. </xsl:text>
  658. </xsl:if>
  659. <!-- Currently only works for Enum values -->
  660. <xsl:if test="derive">
  661. <xsl:text>
  662. public Property compute(PropertyList propertyList) {
  663. Property computedProperty = null;
  664. Property correspondingProperty = propertyList.get(Constants.PR_</xsl:text>
  665. <xsl:call-template name="makeEnumConstant">
  666. <xsl:with-param name="propstr" select="derive/@from"/>
  667. </xsl:call-template>
  668. <xsl:text>);
  669. if (correspondingProperty != null) {
  670. int correspondingValue = correspondingProperty.getEnum();</xsl:text>
  671. <xsl:for-each select="derive/if">
  672. <xsl:text>
  673. if (correspondingValue == Constants.</xsl:text>
  674. <xsl:value-of select="@match"/>
  675. <xsl:text>)
  676. computedProperty = new EnumProperty(</xsl:text>
  677. <xsl:value-of select="."/>
  678. <xsl:text>);
  679. else</xsl:text>
  680. </xsl:for-each>
  681. <xsl:text>
  682. ;
  683. }
  684. return computedProperty;
  685. }
  686. </xsl:text>
  687. </xsl:if>
  688. <!-- If any corresponding element at property or subproperty levels -->
  689. <xsl:if test=".//corresponding">
  690. <xsl:if test=".//corresponding/@use-if-specified='true'">
  691. <xsl:text>
  692. public boolean isCorrespondingForced(PropertyList propertyList) {
  693. FObj parentFO = propertyList.getParentFObj();</xsl:text>
  694. <xsl:for-each select=".//corresponding/propval">
  695. <xsl:text>
  696. if (propertyList.getExplicit(</xsl:text>
  697. <xsl:apply-templates select="."/>
  698. <xsl:text>) != null)
  699. return true;</xsl:text>
  700. </xsl:for-each>
  701. <xsl:text>
  702. return false;
  703. }
  704. </xsl:text>
  705. </xsl:if>
  706. <xsl:text>
  707. public Property compute(PropertyList propertyList) throws FOPException {
  708. FObj parentFO = propertyList.getParentFObj();
  709. Property p=null;</xsl:text>
  710. <xsl:choose>
  711. <xsl:when test="corresponding/propexpr">
  712. <xsl:text>
  713. // Make sure the property is set before calculating it!
  714. if (propertyList.getExplicitOrShorthand(</xsl:text>
  715. <xsl:apply-templates select="corresponding/propval"/>
  716. <xsl:text>) == null)
  717. return p;
  718. StringBuffer sbExpr=new StringBuffer();
  719. sbExpr.setLength(0);</xsl:text>
  720. <xsl:apply-templates select="corresponding/propexpr"/>
  721. <xsl:text>
  722. p = make(propertyList, sbExpr.toString(), propertyList.getParentFObj());</xsl:text>
  723. </xsl:when>
  724. <xsl:otherwise>
  725. <xsl:text>
  726. p= propertyList.getExplicitOrShorthand(</xsl:text>
  727. <xsl:apply-templates select="corresponding/propval"/>
  728. <xsl:text>);</xsl:text>
  729. </xsl:otherwise>
  730. </xsl:choose>
  731. <xsl:text>
  732. if (p != null) {
  733. p = convertProperty(p, propertyList, parentFO );
  734. }</xsl:text>
  735. <xsl:if test="compound">
  736. <xsl:text>
  737. else p = makeCompound(propertyList, parentFO);
  738. Property subprop;</xsl:text>
  739. <xsl:for-each select="compound/subproperty/corresponding">
  740. <xsl:choose>
  741. <xsl:when test="propexpr">
  742. <xsl:apply-templates select="propexpr"/>
  743. <xsl:text>
  744. subprop = getSubpropMaker("</xsl:text>
  745. <xsl:value-of select='../name'/>
  746. <xsl:text>").
  747. make(propertyList, sbExpr.toString(), parentFO);</xsl:text>
  748. </xsl:when>
  749. <xsl:otherwise>
  750. <xsl:text>
  751. subprop = propertyList.getExplicitOrShorthand(</xsl:text>
  752. <xsl:apply-templates select="propval"/>
  753. <xsl:text>);</xsl:text>
  754. </xsl:otherwise>
  755. </xsl:choose>
  756. <xsl:text>
  757. if (subprop != null) {
  758. setSubprop(p, Constants.CP_</xsl:text>
  759. <xsl:call-template name="makeEnumConstant">
  760. <xsl:with-param name="propstr" select="../name"/>
  761. </xsl:call-template>
  762. <xsl:text>, subprop);
  763. }</xsl:text>
  764. </xsl:for-each>
  765. </xsl:if>
  766. <xsl:text>
  767. return p;
  768. }
  769. </xsl:text>
  770. </xsl:if>
  771. <!-- If can be specified by any shorthand property -->
  772. <xsl:if test="shorthand">
  773. <xsl:text>
  774. public Property getShorthand(PropertyList propertyList) {
  775. Property p = null;
  776. ListProperty listprop;</xsl:text>
  777. <xsl:for-each select="shorthand">
  778. <xsl:variable name="shprop" select="."/>
  779. <xsl:text>
  780. if (p == null) {
  781. listprop =
  782. (ListProperty)propertyList.getExplicit(Constants.PR_</xsl:text>
  783. <xsl:call-template name="makeEnumConstant">
  784. <xsl:with-param name="propstr" select="$shprop"/>
  785. </xsl:call-template>
  786. <xsl:text>);
  787. if (listprop != null) {
  788. // Get a parser for the shorthand to set the individual properties
  789. ShorthandParser shparser =
  790. new </xsl:text>
  791. <xsl:value-of select="key('shorthandref', $shprop)/datatype-parser"/>
  792. <xsl:text>(listprop);
  793. p = shparser.getValueForProperty(
  794. getPropId(), this, propertyList);
  795. }
  796. }</xsl:text>
  797. </xsl:for-each>
  798. <xsl:text>
  799. return p;
  800. }
  801. </xsl:text>
  802. </xsl:if>
  803. <xsl:apply-templates select=
  804. "percent-ok|auto-ok|default|keyword-equiv|datatype-conversion|
  805. enumeration|extfile"/>
  806. <xsl:text>
  807. }
  808. </xsl:text>
  809. </redirect:write>
  810. </xsl:if> <!-- need to create a class -->
  811. </xsl:template>
  812. <xsl:template match="corresponding/propexpr/propval">
  813. <xsl:text>
  814. sbExpr.append("_fop-property-value(");</xsl:text> <!-- Note: interpreted by property parser -->
  815. <xsl:apply-templates/>
  816. <xsl:text>
  817. sbExpr.append(")");</xsl:text>
  818. </xsl:template>
  819. <xsl:template match="propval">
  820. <xsl:choose>
  821. <xsl:when test="wmabs2rel[@dir='LEFT']">
  822. <xsl:call-template name="makeMap">
  823. <xsl:with-param name="lrtb" select='"START"'/>
  824. <xsl:with-param name="rltb" select='"END"'/>
  825. <xsl:with-param name="tbrl" select='"AFTER"'/>
  826. </xsl:call-template>
  827. </xsl:when>
  828. <xsl:when test="wmabs2rel[@dir='RIGHT']">
  829. <xsl:call-template name="makeMap">
  830. <xsl:with-param name="lrtb" select='"END"'/>
  831. <xsl:with-param name="rltb" select='"START"'/>
  832. <xsl:with-param name="tbrl" select='"BEFORE"'/>
  833. </xsl:call-template>
  834. </xsl:when>
  835. <xsl:when test="wmabs2rel[@dir='TOP']">
  836. <xsl:call-template name="makeMap">
  837. <xsl:with-param name="lrtb" select='"BEFORE"'/>
  838. <xsl:with-param name="rltb" select='"BEFORE"'/>
  839. <xsl:with-param name="tbrl" select='"START"'/>
  840. </xsl:call-template>
  841. </xsl:when>
  842. <xsl:when test="wmabs2rel[@dir='BOTTOM']">
  843. <xsl:call-template name="makeMap">
  844. <xsl:with-param name="lrtb" select='"AFTER"'/>
  845. <xsl:with-param name="rltb" select='"AFTER"'/>
  846. <xsl:with-param name="tbrl" select='"END"'/>
  847. </xsl:call-template>
  848. </xsl:when>
  849. <xsl:when test="wmrel2abs[@dir='START']">
  850. <xsl:call-template name="makeMap">
  851. <xsl:with-param name="lrtb" select='"LEFT"'/>
  852. <xsl:with-param name="rltb" select='"RIGHT"'/>
  853. <xsl:with-param name="tbrl" select='"TOP"'/>
  854. </xsl:call-template>
  855. </xsl:when>
  856. <xsl:when test="wmrel2abs[@dir='END']">
  857. <xsl:call-template name="makeMap">
  858. <xsl:with-param name="lrtb" select='"RIGHT"'/>
  859. <xsl:with-param name="rltb" select='"LEFT"'/>
  860. <xsl:with-param name="tbrl" select='"BOTTOM"'/>
  861. </xsl:call-template>
  862. </xsl:when>
  863. <xsl:when test="wmrel2abs[@dir='BEFORE'] or parwmrel2abs[@dir='BEFORE']">
  864. <xsl:call-template name="makeMap">
  865. <xsl:with-param name="lrtb" select='"TOP"'/>
  866. <xsl:with-param name="rltb" select='"TOP"'/>
  867. <xsl:with-param name="tbrl" select='"RIGHT"'/>
  868. </xsl:call-template>
  869. </xsl:when>
  870. <xsl:when test="wmrel2abs[@dir='AFTER'] or parwmrel2abs[@dir='AFTER']">
  871. <xsl:call-template name="makeMap">
  872. <xsl:with-param name="lrtb" select='"BOTTOM"'/>
  873. <xsl:with-param name="rltb" select='"BOTTOM"'/>
  874. <xsl:with-param name="tbrl" select='"LEFT"'/>
  875. </xsl:call-template>
  876. </xsl:when>
  877. <xsl:when test="wmrel2abs[@dir='BLOCKPROGDIM']">
  878. <xsl:call-template name="makeMap">
  879. <xsl:with-param name="lrtb" select='"HEIGHT"'/>
  880. <xsl:with-param name="rltb" select='"HEIGHT"'/>
  881. <xsl:with-param name="tbrl" select='"WIDTH"'/>
  882. </xsl:call-template>
  883. </xsl:when>
  884. <xsl:when test="wmrel2abs[@dir='INLINEPROGDIM']">
  885. <xsl:call-template name="makeMap">
  886. <xsl:with-param name="lrtb" select='"WIDTH"'/>
  887. <xsl:with-param name="rltb" select='"WIDTH"'/>
  888. <xsl:with-param name="tbrl" select='"HEIGHT"'/>
  889. </xsl:call-template>
  890. </xsl:when>
  891. <xsl:otherwise>UNKNOWN <xsl:value-of select="."/></xsl:otherwise>
  892. </xsl:choose>
  893. </xsl:template>
  894. <xsl:template match="corresponding//text()">
  895. <xsl:variable name="tval" select='normalize-space(.)'/>
  896. <xsl:if test="$tval != ''">
  897. <xsl:text>
  898. sbExpr.append("</xsl:text>
  899. <xsl:value-of select='$tval'/>
  900. <xsl:text>");</xsl:text>
  901. </xsl:if>
  902. </xsl:template>
  903. <xsl:template name="makeMap">
  904. <xsl:param name="lrtb"/>
  905. <xsl:param name="rltb"/>
  906. <xsl:param name="tbrl"/>
  907. <xsl:choose>
  908. <xsl:when test="parwmrel2abs">
  909. <xsl:text>parentFO.propertyList</xsl:text>
  910. </xsl:when>
  911. <xsl:otherwise>
  912. <xsl:text>propertyList</xsl:text>
  913. </xsl:otherwise>
  914. </xsl:choose>
  915. <xsl:text>.wmMap(Constants.PR_</xsl:text>
  916. <xsl:apply-templates mode="x">
  917. <xsl:with-param name="dir" select='$lrtb'/>
  918. </xsl:apply-templates>
  919. <xsl:text>, Constants.PR_</xsl:text>
  920. <xsl:apply-templates mode="x">
  921. <xsl:with-param name="dir" select='$rltb'/>
  922. </xsl:apply-templates>
  923. <xsl:text>, Constants.PR_</xsl:text>
  924. <xsl:apply-templates mode="x">
  925. <xsl:with-param name="dir" select='$tbrl'/>
  926. </xsl:apply-templates>
  927. <xsl:text>)</xsl:text>
  928. </xsl:template>
  929. <xsl:template match="corresponding//text()" mode="x">
  930. <xsl:variable name="tval" select='normalize-space(.)'/>
  931. <xsl:if test="$tval != ''">
  932. <xsl:call-template name="makeEnumConstant">
  933. <xsl:with-param name="propstr" select="$tval"/>
  934. </xsl:call-template>
  935. </xsl:if>
  936. </xsl:template>
  937. <xsl:template match="propval/wmrel2abs">
  938. <xsl:text>
  939. sbExpr.append(propertyList.wmRelToAbs(PropertyList.</xsl:text>
  940. <xsl:value-of select="@dir"/>
  941. <xsl:text>));</xsl:text>
  942. </xsl:template>
  943. <xsl:template match="propval/parwmrel2abs">
  944. <xsl:text>
  945. sbExpr.append(parentFO.propertyList.wmRelToAbs(PropertyList.</xsl:text>
  946. <xsl:value-of select="@dir"/>
  947. <xsl:text>));</xsl:text>
  948. </xsl:template>
  949. <xsl:template match="propval/wmabs2rel">
  950. <xsl:text>
  951. sbExpr.append(propertyList.wmAbsToRel(PropertyList.</xsl:text>
  952. <xsl:value-of select="@dir"/>
  953. <xsl:text>));</xsl:text>
  954. </xsl:template>
  955. <xsl:template match="propval/wmrel2abs" mode="x">
  956. <xsl:param name="dir"/>
  957. <xsl:value-of select="$dir"/>
  958. </xsl:template>
  959. <xsl:template match="propval/parwmrel2abs" mode="x">
  960. <xsl:param name="dir"/>
  961. <xsl:value-of select="$dir"/>
  962. </xsl:template>
  963. <xsl:template match="propval/wmabs2rel" mode="x">
  964. <xsl:param name="dir"/>
  965. <xsl:value-of select="$dir"/>
  966. </xsl:template>
  967. <!-- avoid unwanted output to placeholder file -->
  968. <xsl:template match="localname"/>
  969. <!-- Check that each member of the nodeset dtlist has the same value.
  970. Print a message if any member of dtlist is different
  971. from the first member. Return the first member.
  972. -->
  973. <xsl:template name="check-subprop-datatype">
  974. <xsl:param name="dtlist"/>
  975. <xsl:variable name="dt">
  976. <xsl:value-of select='$dtlist[1]'/>
  977. </xsl:variable>
  978. <xsl:for-each select="$dtlist">
  979. <xsl:if test=". != $dt">
  980. <xsl:message>
  981. <xsl:text>Conflict between subproperty datatypes: </xsl:text>
  982. <xsl:value-of select='.'/> != <xsl:value-of select='$dt'/>
  983. </xsl:message>
  984. </xsl:if>
  985. </xsl:for-each>
  986. <xsl:value-of select='$dt'/>
  987. </xsl:template>
  988. <!-- If the value of an enumeration constant contains two or more words,
  989. separated by a blank, map all of these words to the same constant.
  990. -->
  991. <xsl:template name="enumvals">
  992. <xsl:param name="specvals"/>
  993. <xsl:if test='string-length($specvals)>0'>
  994. <xsl:variable name="oneval" select="substring-before($specvals, ' ')"/>
  995. <xsl:text>
  996. if (value.equals("</xsl:text>
  997. <xsl:value-of select="$oneval"/>
  998. <xsl:text>")) {
  999. return s_prop</xsl:text>
  1000. <xsl:value-of select="@const"/>
  1001. <xsl:text>;
  1002. }</xsl:text>
  1003. <xsl:call-template name="enumvals">
  1004. <xsl:with-param name="specvals" select="substring-after($specvals, ' ')"/>
  1005. </xsl:call-template>
  1006. </xsl:if>
  1007. </xsl:template>
  1008. </xsl:stylesheet>