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

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