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.

propertyExpressions.html 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  5. <title>Property Expression Parsing</title>
  6. <link type="text/css" href="../../../page.css" rel="stylesheet">
  7. </head>
  8. <body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" text="#000000" bgcolor="#FFFFFF">
  9. <div class="content">
  10. <h1>Property Expression Parsing</h1>
  11. <p>
  12. <font size="-2">by&nbsp;Peter B. West</font>
  13. </p>
  14. <ul class="minitoc">
  15. <li>
  16. <a href="#N10014">Property expression parsing</a>
  17. <ul class="minitoc">
  18. <li>
  19. <a href="#N10044">Data types</a>
  20. </li>
  21. <li>
  22. <a href="#N10252">Tokenizer</a>
  23. </li>
  24. <li>
  25. <a href="#N1029C">Parser</a>
  26. </li>
  27. </ul>
  28. </li>
  29. </ul>
  30. <a name="N10014"></a>
  31. <h3>Property expression parsing</h3>
  32. <p>
  33. The parsing of property value expressions is handled by two
  34. closely related classes: <a href=
  35. "javascript:window.top.displayCode(
  36. 'PropertyTokenizer.html#PropertyTokenizerClass' )" ><span
  37. class= "codefrag" >org.apache.fop.fo.expr.PropertyTokenizer</span></a>
  38. and its subclass, <a href= "javascript:window.top.displayCode(
  39. 'PropertyParser.html#PropertyParserClass' )" ><span
  40. class= "codefrag" >org.apache.fop.fo.expr.PropertyParser</span></a>,
  41. and by <span class= "codefrag" >refineParsing(int, FONode,
  42. PropertyValue)</span> methods in the individual property
  43. classes. <span class= "codefrag" >PropertyTokenizer</span>, as
  44. the name suggests, handles the tokenizing of the expression,
  45. handing <a href= "javascript:window.top.displayCode(
  46. 'PropertyTokenizer.html#EOF' )" ><em>tokens</em></a> back to
  47. its subclass, <span
  48. class= "codefrag" >PropertyParser</span>. <span
  49. class= "codefrag" >PropertyParser</span>, in turn, returns a <a
  50. href= "javascript:window.top.displayCode(
  51. 'PropertyValueList.html#PropertyValueListClass' )" ><span
  52. class= "codefrag">PropertyValueList</span></a>, a list of <a
  53. href= "javascript:window.top.displayCode(
  54. 'PropertyValue.html#PropertyValueInterface' )" ><span class=
  55. "codefrag">PropertyValue</span></a>s.
  56. </p>
  57. <p>
  58. The tokenizer and parser rely in turn on the datatype
  59. definitions from the <span
  60. class= "codefrag" >org.apache.fop.datatypes</span> package,
  61. which include the <a href= "javascript:window.top.displayCode(
  62. 'PropertyValue.html#NO_TYPE' )" ><span class= "codefrag"
  63. >PropertyValue</span> datatype constant definitions</a>.
  64. </p>
  65. <a name="N10044"></a>
  66. <h4>Data types</h4>
  67. <p>
  68. The data types currently defined in
  69. <span class= "codefrag" >org.apache.fop.datatypes</span> include:
  70. </p>
  71. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  72. <tr>
  73. <th colspan="2" rowspan="1">Numbers and lengths</th>
  74. </tr>
  75. <tr>
  76. <th colspan="1" rowspan="1">Numeric</th>
  77. <td colspan="3" rowspan="1">
  78. The fundamental length data type. <em>Numerics</em> of
  79. various types are constructed by the classes listed
  80. below.
  81. </td>
  82. </tr>
  83. <tr>
  84. <td colspan="1" rowspan="1"></td>
  85. <th colspan="3"
  86. rowspan="1">Constructor classes for <em>Numeric</em></th>
  87. </tr>
  88. <tr>
  89. <td colspan="1" rowspan="1"></td>
  90. <td colspan="1" rowspan="1">Ems</td>
  91. <td colspan="2" rowspan="1">Relative length in <em>ems</em></td>
  92. </tr>
  93. <tr>
  94. <td colspan="1" rowspan="1"></td>
  95. <td colspan="1" rowspan="1">IntegerType</td>
  96. <td colspan="1" rowspan="1"></td>
  97. </tr>
  98. <tr>
  99. <td colspan="1" rowspan="1"></td>
  100. <td colspan="1" rowspan="1">Length</td>
  101. <td colspan="2" rowspan="1">In centimetres(cm), millimetres(mm),
  102. inches(in), points(pt), picas(pc) or pixels(px)</td>
  103. </tr>
  104. <tr>
  105. <td colspan="1" rowspan="1"></td>
  106. <td colspan="1" rowspan="1">Percentage</td>
  107. <td colspan="1" rowspan="1"></td>
  108. </tr>
  109. <tr>
  110. <th colspan="1" rowspan="1">Other Numeric</th>
  111. <td colspan="3" rowspan="1">
  112. Other numeric vaues which do not interact with the
  113. lengths represented by <em>Numeric</em> values.
  114. </td>
  115. </tr>
  116. <tr>
  117. <td colspan="1" rowspan="1"></td>
  118. <td colspan="1" rowspan="1">Angle</td>
  119. <td colspan="2" rowspan="1">In degrees(deg), gradients(grad) or
  120. radians(rad)</td>
  121. </tr>
  122. <tr>
  123. <td colspan="1" rowspan="1"></td>
  124. <td colspan="1" rowspan="1">Frequency</td>
  125. <td colspan="2" rowspan="1">In hertz(Hz) or kilohertz(kHz)</td>
  126. </tr>
  127. <tr>
  128. <td colspan="1" rowspan="1"></td>
  129. <td colspan="1" rowspan="1">Time</td>
  130. <td colspan="1" rowspan="1">In seconds(s) or milliseconds(ms)</td>
  131. </tr>
  132. <tr>
  133. <th colspan="2" rowspan="1">Strings</th>
  134. </tr>
  135. <tr>
  136. <th colspan="1" rowspan="1">StringType</th>
  137. <td colspan="3" rowspan="1">
  138. Base class for data types which result in a <em>String</em>.
  139. </td>
  140. </tr>
  141. <tr>
  142. <td colspan="1" rowspan="1"></td>
  143. <th colspan="1" rowspan="1">Literal</th>
  144. <td colspan="2" rowspan="1">
  145. A subclass of <em>StringType</em> for literals which
  146. exceed the constraints of an <em>NCName</em>.
  147. </td>
  148. </tr>
  149. <tr>
  150. <td colspan="1" rowspan="1"></td>
  151. <th colspan="1" rowspan="1">MimeType</th>
  152. <td colspan="2" rowspan="1">
  153. A subclass of <em>StringType</em> for literals which
  154. represent a mime type.
  155. </td>
  156. </tr>
  157. <tr>
  158. <td colspan="1" rowspan="1"></td>
  159. <th colspan="1" rowspan="1">UriType</th>
  160. <td colspan="2" rowspan="1">
  161. A subclass of <em>StringType</em> for literals which
  162. represent a URI, as specified by the argument to
  163. <em>url()</em>.
  164. </td>
  165. </tr>
  166. <tr>
  167. <td colspan="1" rowspan="1"></td>
  168. <th colspan="1" rowspan="1">NCName</th>
  169. <td colspan="2" rowspan="1">
  170. A subclass of <em>StringType</em> for literals which
  171. meet the constraints of an <em>NCName</em>.
  172. </td>
  173. </tr>
  174. <tr>
  175. <td colspan="1" rowspan="1"></td>
  176. <td colspan="1" rowspan="1"></td>
  177. <th colspan="1" rowspan="1">Country</th>
  178. <td colspan="1" rowspan="1">An RFC 3066/ISO 3166 country code.</td>
  179. </tr>
  180. <tr>
  181. <td colspan="1" rowspan="1"></td>
  182. <td colspan="1" rowspan="1"></td>
  183. <th colspan="1" rowspan="1">Language</th>
  184. <td colspan="1" rowspan="1">An RFC 3066/ISO 639 language code.</td>
  185. </tr>
  186. <tr>
  187. <td colspan="1" rowspan="1"></td>
  188. <td colspan="1" rowspan="1"></td>
  189. <th colspan="1" rowspan="1">Script</th>
  190. <td colspan="1" rowspan="1">An ISO 15924 script code.</td>
  191. </tr>
  192. <tr>
  193. <th colspan="2" rowspan="1">Enumerated types</th>
  194. </tr>
  195. <tr>
  196. <th colspan="1" rowspan="1">EnumType</th>
  197. <td colspan="3" rowspan="1">
  198. An integer representing one of the tokens in a set of
  199. enumeration values.
  200. </td>
  201. </tr>
  202. <tr>
  203. <td colspan="1" rowspan="1"></td>
  204. <th colspan="1" rowspan="1">MappedNumeric</th>
  205. <td colspan="2" rowspan="1">
  206. A subclass of <em>EnumType</em>. Maintains a
  207. <em>Numeric</em> with the value to which the associated
  208. "raw" enumeration token maps. E.g., the
  209. <em>font-size</em> enumeration value "medium" maps to
  210. the <em>Numeric</em> "12pt".
  211. </td>
  212. </tr>
  213. <tr>
  214. <th colspan="2" rowspan="1">Colors</th>
  215. </tr>
  216. <tr>
  217. <th colspan="1" rowspan="1">ColorType</th>
  218. <td colspan="3" rowspan="1">
  219. Maintains a four-element array of float, derived from
  220. the name of a standard colour, the name returned by a
  221. call to <em>system-color()</em>, or an RGB
  222. specification.
  223. </td>
  224. </tr>
  225. <tr>
  226. <th colspan="2" rowspan="1">Fonts</th>
  227. </tr>
  228. <tr>
  229. <th colspan="1" rowspan="1">FontFamilySet</th>
  230. <td colspan="3" rowspan="1">
  231. Maintains an array of <em>String</em>s containing a
  232. prioritized list of possibly generic font family names.
  233. </td>
  234. </tr>
  235. <tr>
  236. <th colspan="2" rowspan="1">Pseudo-types</th>
  237. </tr>
  238. <tr>
  239. <td colspan="4" rowspan="1">
  240. A variety of pseudo-types have been defined as
  241. convenience types for frequently appearing enumeration
  242. token values, or for other special purposes.
  243. </td>
  244. </tr>
  245. <tr>
  246. <th colspan="1" rowspan="1">Inherit</th>
  247. <td colspan="3" rowspan="1">
  248. For values of <em>inherit</em>.
  249. </td>
  250. </tr>
  251. <tr>
  252. <th colspan="1" rowspan="1">Auto</th>
  253. <td colspan="3" rowspan="1">
  254. For values of <em>auto</em>.
  255. </td>
  256. </tr>
  257. <tr>
  258. <th colspan="1" rowspan="1">None</th>
  259. <td colspan="3" rowspan="1">
  260. For values of <em>none</em>.
  261. </td>
  262. </tr>
  263. <tr>
  264. <th colspan="1" rowspan="1">Bool</th>
  265. <td colspan="3" rowspan="1">
  266. For values of <em>true/false</em>.
  267. </td>
  268. </tr>
  269. <tr>
  270. <th colspan="1" rowspan="1">FromNearestSpecified</th>
  271. <td colspan="3" rowspan="1">
  272. Created to ensure that, when associated with
  273. a shorthand, the <em>from-nearest-specified-value()</em>
  274. core function is the sole component of the expression.
  275. </td>
  276. </tr>
  277. <tr>
  278. <th colspan="1" rowspan="1">FromParent</th>
  279. <td colspan="3" rowspan="1">
  280. Created to ensure that, when associated with
  281. a shorthand, the <em>from-parent()</em>
  282. core function is the sole component of the expression.
  283. </td>
  284. </tr>
  285. </table>
  286. <a name="N10252"></a>
  287. <h4>Tokenizer</h4>
  288. <p>
  289. As mentioned above, the <span class= "codefrag"
  290. >PropertyTokenizer</span> hands <a href=
  291. "javascript:window.top.displayCode( 'PropertyTokenizer.html#EOF'
  292. )" ><em>tokens</em></a> back to its subclass, <span class=
  293. "codefrag" >PropertyParser</span>. Most of these tokens are
  294. self-explanatory, but a few need further comment.
  295. </p>
  296. <dl>
  297. <dt>AUTO</dt>
  298. <dd>
  299. Because of its frequency of occurrence, and the fact that it
  300. is always the <em>initial value</em> for any property which
  301. supports it, AUTO has been promoted into a pseudo-type with
  302. its on datatype class. Therefore, it is also reported as a
  303. token.
  304. </dd>
  305. <dt>NONE</dt>
  306. <dd>
  307. Similarly to AUTO, NONE has been promoted to a pseudo-type
  308. because of its frequency.
  309. </dd>
  310. <dt>BOOL</dt>
  311. <dd>
  312. There is a <em>de facto</em> boolean type buried in the
  313. enumeration types for many of the properties. It had been
  314. specified as a type in its own right in this code.
  315. </dd>
  316. <dt>MIMETYPE</dt>
  317. <dd>
  318. The property <span class= "codefrag" >content-type</span>
  319. introduces this complication. It can have two values of the
  320. form <strong>content-type:</strong><em>mime-type</em>
  321. (e.g. <span class= "codefrag"
  322. >content-type="content-type:xml/svg"</span>) or
  323. <strong>namespace-prefix:</strong><em>prefix</em>
  324. (e.g. <span class= "codefrag"
  325. >content-type="namespace-prefix:svg"</span>). The
  326. experimental code reduces these options to the payload in
  327. each case: an <span class= "codefrag" >NCName</span> in the
  328. case of a namespace prefix, and a MIMETYPE in the case of a
  329. content-type specification. <span class= "codefrag"
  330. >NCName</span>s cannot contain a "/".
  331. </dd>
  332. </dl>
  333. <a name="N1029C"></a>
  334. <h4>Parser</h4>
  335. <p>
  336. The parser returns a <a href= "javascript:window.top.displayCode(
  337. 'PropertyValueList.html#PropertyValueListClass' )" ><span
  338. class= "codefrag" >PropertyValueList</span ></a>, necessary
  339. because of the possibility that a list of <a href=
  340. "javascript:window.top.displayCode(
  341. 'PropertyValue.html#PropertyValueInterface' )" ><span class=
  342. "codefrag" >PropertyValue</span ></a> elements may be returned
  343. from the expressions of some properties.
  344. </p>
  345. <p>
  346. <span class= "codefrag" >PropertyValueList</span>s may contain
  347. <span class= "codefrag" >PropertyValue</span>s or other <span
  348. class= "codefrag" >PropertyValueList</span>s. This latter
  349. provision is necessitated by some of the more peculiar
  350. expression possibilities, <em>e.g.</em> <em>font</em> and
  351. <em>text-shadow</em>. <em>text-shadow</em> may contain whitespace
  352. separated sublists of either two or three elements, separated
  353. from one another by commas. To accommodate this peculiarity,
  354. comma separated elements are added to the top-level list,
  355. while whitespace separated values are always collected into
  356. sublists to be added to the top-level list.
  357. </p>
  358. <p>
  359. Other special cases include the processing of the core
  360. functions <span class= "codefrag" >from-parent()</span> and
  361. <span class= "codefrag" >from-nearest-specified-value()</span>
  362. when these function calls are assigned to a shorthand
  363. property, or used with a shorthand property name as an
  364. argument. In these cases, the function call must be the sole
  365. component of the expression. The pseudo-element classes <span
  366. class= "codefrag" >FromParent</span> and <span
  367. class= "codefrag" >FromNearestSpecified</span> are generated in
  368. these circumstances so that an exception will be thrown if
  369. they are involved in expression evaluation with other
  370. components. (See Rec. Section 5.10.4 Property Value
  371. Functions.)
  372. </p>
  373. <p>
  374. The experimental code is a simple extension of the existing
  375. parser code, which itself borrowed heavily from James
  376. Clark's XT processor.
  377. </p>
  378. </div>
  379. <table summary="footer" cellspacing="0" cellpadding="0" width="100%" height="20" border="0">
  380. <tr>
  381. <td colspan="2" height="1" bgcolor="#4C6C8F"><img height="1"
  382. width="1" alt="" src="../../../skin/images/spacer.gif"><a
  383. href="../../../skin/images/label.gif"></a><a
  384. href="../../../skin/images/page.gif"></a><a
  385. href="../../../skin/images/chapter.gif"></a><a
  386. href="../../../skin/images/chapter_open.gif"></a><a
  387. href="../../../skin/images/current.gif"></a><a
  388. href="../../..//favicon.ico"></a></td>
  389. </tr>
  390. <tr>
  391. <td colspan="2" bgcolor="#CFDCED" class="copyright"
  392. align="center"><font size="2" face="Arial, Helvetica,
  393. Sans-Serif">Copyright &copy; 1999-2002&nbsp;The Apache
  394. Software Foundation. All rights reserved.<script
  395. type="text/javascript" language="JavaScript"><!--
  396. document.write(" - "+"Last Published: " +
  397. document.lastModified); // --></script></font></td>
  398. </tr>
  399. <tr>
  400. <td align="left" bgcolor="#CFDCED" class="logos"></td><td
  401. align="right" bgcolor="#CFDCED" class="logos"></td>
  402. </tr>
  403. </table>
  404. </body>
  405. </html>