PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/external/apache-xml/src/main/java/org/apache/xalan/templates/ElemSort.java

https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk
Java | 349 lines | 89 code | 25 blank | 235 comment | 11 complexity | ad2aa978211a5b35a0589e3ce5cd0355 MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /*
  19. * $Id: ElemSort.java 468643 2006-10-28 06:56:03Z minchau $
  20. */
  21. package org.apache.xalan.templates;
  22. import org.apache.xalan.res.XSLTErrorResources;
  23. import org.apache.xpath.XPath;
  24. import org.w3c.dom.DOMException;
  25. import org.w3c.dom.Node;
  26. /**
  27. * Implement xsl:sort.
  28. * <pre>
  29. * <!ELEMENT xsl:sort EMPTY>
  30. * <!ATTLIST xsl:sort
  31. * select %expr; "."
  32. * lang %avt; #IMPLIED
  33. * data-type %avt; "text"
  34. * order %avt; "ascending"
  35. * case-order %avt; #IMPLIED
  36. * >
  37. * <!-- xsl:sort cannot occur after any other elements or
  38. * any non-whitespace character -->
  39. * </pre>
  40. * @see <a href="http://www.w3.org/TR/xslt#sorting">sorting in XSLT Specification</a>
  41. * @xsl.usage advanced
  42. */
  43. public class ElemSort extends ElemTemplateElement
  44. {
  45. static final long serialVersionUID = -4991510257335851938L;
  46. /**
  47. * xsl:sort has a select attribute whose value is an expression.
  48. * @serial
  49. */
  50. private XPath m_selectExpression = null;
  51. /**
  52. * Set the "select" attribute.
  53. * xsl:sort has a select attribute whose value is an expression.
  54. * For each node to be processed, the expression is evaluated
  55. * with that node as the current node and with the complete
  56. * list of nodes being processed in unsorted order as the current
  57. * node list. The resulting object is converted to a string as if
  58. * by a call to the string function; this string is used as the
  59. * sort key for that node. The default value of the select attribute
  60. * is ., which will cause the string-value of the current node to
  61. * be used as the sort key.
  62. *
  63. * @param v Value to set for the "select" attribute
  64. */
  65. public void setSelect(XPath v)
  66. {
  67. if (v.getPatternString().indexOf("{") < 0)
  68. m_selectExpression = v;
  69. else
  70. error(XSLTErrorResources.ER_NO_CURLYBRACE, null);
  71. }
  72. /**
  73. * Get the "select" attribute.
  74. * xsl:sort has a select attribute whose value is an expression.
  75. * For each node to be processed, the expression is evaluated
  76. * with that node as the current node and with the complete
  77. * list of nodes being processed in unsorted order as the current
  78. * node list. The resulting object is converted to a string as if
  79. * by a call to the string function; this string is used as the
  80. * sort key for that node. The default value of the select attribute
  81. * is ., which will cause the string-value of the current node to
  82. * be used as the sort key.
  83. *
  84. * @return The value of the "select" attribute
  85. */
  86. public XPath getSelect()
  87. {
  88. return m_selectExpression;
  89. }
  90. /**
  91. * lang specifies the language of the sort keys.
  92. * @serial
  93. */
  94. private AVT m_lang_avt = null;
  95. /**
  96. * Set the "lang" attribute.
  97. * lang specifies the language of the sort keys; it has the same
  98. * range of values as xml:lang [XML]; if no lang value is
  99. * specified, the language should be determined from the system environment.
  100. *
  101. * @param v The value to set for the "lang" attribute
  102. */
  103. public void setLang(AVT v)
  104. {
  105. m_lang_avt = v;
  106. }
  107. /**
  108. * Get the "lang" attribute.
  109. * lang specifies the language of the sort keys; it has the same
  110. * range of values as xml:lang [XML]; if no lang value is
  111. * specified, the language should be determined from the system environment.
  112. *
  113. * @return The value of the "lang" attribute
  114. */
  115. public AVT getLang()
  116. {
  117. return m_lang_avt;
  118. }
  119. /**
  120. * data-type specifies the data type of the
  121. * strings to be sorted.
  122. * @serial
  123. */
  124. private AVT m_dataType_avt = null;
  125. /**
  126. * Set the "data-type" attribute.
  127. * <code>data-type</code> specifies the data type of the
  128. * strings; the following values are allowed:
  129. * <ul>
  130. * <li>
  131. * <code>text</code> specifies that the sort keys should be
  132. * sorted lexicographically in the culturally correct manner for the
  133. * language specified by <code>lang</code>.
  134. * </li>
  135. * <li>
  136. * <code>number</code> specifies that the sort keys should be
  137. * converted to numbers and then sorted according to the numeric value;
  138. * the sort key is converted to a number as if by a call to the
  139. * <b><a href="http://www.w3.org/TR/xpath#function-number">number</a></b> function; the <code>lang</code>
  140. * attribute is ignored.
  141. * </li>
  142. * <li>
  143. * A <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> with a prefix
  144. * is expanded into an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> as described
  145. * in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>; the expanded-name identifies the data-type;
  146. * the behavior in this case is not specified by this document.
  147. * </li>
  148. * </ul>
  149. * <p>The default value is <code>text</code>.</p>
  150. * <blockquote>
  151. * <b>NOTE: </b>The XSL Working Group plans that future versions of XSLT will
  152. * leverage XML Schemas to define further values for this
  153. * attribute.</blockquote>
  154. *
  155. * @param v Value to set for the "data-type" attribute
  156. */
  157. public void setDataType(AVT v)
  158. {
  159. m_dataType_avt = v;
  160. }
  161. /**
  162. * Get the "data-type" attribute.
  163. * <code>data-type</code> specifies the data type of the
  164. * strings; the following values are allowed:
  165. * <ul>
  166. * <li>
  167. * <code>text</code> specifies that the sort keys should be
  168. * sorted lexicographically in the culturally correct manner for the
  169. * language specified by <code>lang</code>.
  170. * </li>
  171. * <li>
  172. * <code>number</code> specifies that the sort keys should be
  173. * converted to numbers and then sorted according to the numeric value;
  174. * the sort key is converted to a number as if by a call to the
  175. * <b><a href="http://www.w3.org/TR/xpath#function-number">number</a></b> function; the <code>lang</code>
  176. * attribute is ignored.
  177. * </li>
  178. * <li>
  179. * A <a href="http://www.w3.org/TR/REC-xml-names#NT-QName">QName</a> with a prefix
  180. * is expanded into an <a href="http://www.w3.org/TR/xpath#dt-expanded-name">expanded-name</a> as described
  181. * in <a href="#qname">[<b>2.4 Qualified Names</b>]</a>; the expanded-name identifies the data-type;
  182. * the behavior in this case is not specified by this document.
  183. * </li>
  184. * </ul>
  185. * <p>The default value is <code>text</code>.</p>
  186. * <blockquote>
  187. * <b>NOTE: </b>The XSL Working Group plans that future versions of XSLT will
  188. * leverage XML Schemas to define further values for this
  189. * attribute.</blockquote>
  190. *
  191. * @return The value of the "data-type" attribute
  192. */
  193. public AVT getDataType()
  194. {
  195. return m_dataType_avt;
  196. }
  197. /**
  198. * order specifies whether the strings should be sorted in ascending
  199. * or descending order.
  200. * @serial
  201. */
  202. private AVT m_order_avt = null;
  203. /**
  204. * Set the "order" attribute.
  205. * order specifies whether the strings should be sorted in ascending
  206. * or descending order; ascending specifies ascending order; descending
  207. * specifies descending order; the default is ascending.
  208. *
  209. * @param v The value to set for the "order" attribute
  210. */
  211. public void setOrder(AVT v)
  212. {
  213. m_order_avt = v;
  214. }
  215. /**
  216. * Get the "order" attribute.
  217. * order specifies whether the strings should be sorted in ascending
  218. * or descending order; ascending specifies ascending order; descending
  219. * specifies descending order; the default is ascending.
  220. *
  221. * @return The value of the "order" attribute
  222. */
  223. public AVT getOrder()
  224. {
  225. return m_order_avt;
  226. }
  227. /**
  228. * case-order has the value upper-first or lower-first.
  229. * The default value is language dependent.
  230. * @serial
  231. */
  232. private AVT m_caseorder_avt = null;
  233. /**
  234. * Set the "case-order" attribute.
  235. * case-order has the value upper-first or lower-first; this applies
  236. * when data-type="text", and specifies that upper-case letters should
  237. * sort before lower-case letters or vice-versa respectively.
  238. * For example, if lang="en", then A a B b are sorted with
  239. * case-order="upper-first" and a A b B are sorted with case-order="lower-first".
  240. * The default value is language dependent.
  241. *
  242. * @param v The value to set for the "case-order" attribute
  243. *
  244. * @serial
  245. */
  246. public void setCaseOrder(AVT v)
  247. {
  248. m_caseorder_avt = v;
  249. }
  250. /**
  251. * Get the "case-order" attribute.
  252. * case-order has the value upper-first or lower-first; this applies
  253. * when data-type="text", and specifies that upper-case letters should
  254. * sort before lower-case letters or vice-versa respectively.
  255. * For example, if lang="en", then A a B b are sorted with
  256. * case-order="upper-first" and a A b B are sorted with case-order="lower-first".
  257. * The default value is language dependent.
  258. *
  259. * @return The value of the "case-order" attribute
  260. */
  261. public AVT getCaseOrder()
  262. {
  263. return m_caseorder_avt;
  264. }
  265. /**
  266. * Get an int constant identifying the type of element.
  267. * @see org.apache.xalan.templates.Constants
  268. *
  269. * @return The token ID of the element
  270. */
  271. public int getXSLToken()
  272. {
  273. return Constants.ELEMNAME_SORT;
  274. }
  275. /**
  276. * Return the node name.
  277. *
  278. * @return The element's name
  279. */
  280. public String getNodeName()
  281. {
  282. return Constants.ELEMNAME_SORT_STRING;
  283. }
  284. /**
  285. * Add a child to the child list.
  286. *
  287. * @param newChild Child to add to the child list
  288. *
  289. * @return Child just added to the child list
  290. *
  291. * @throws DOMException
  292. */
  293. public Node appendChild(Node newChild) throws DOMException
  294. {
  295. error(XSLTErrorResources.ER_CANNOT_ADD,
  296. new Object[]{ newChild.getNodeName(),
  297. this.getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
  298. //" to " + this.m_elemName);
  299. return null;
  300. }
  301. /**
  302. * This function is called after everything else has been
  303. * recomposed, and allows the template to set remaining
  304. * values that may be based on some other property that
  305. * depends on recomposition.
  306. */
  307. public void compose(StylesheetRoot sroot)
  308. throws javax.xml.transform.TransformerException
  309. {
  310. super.compose(sroot);
  311. StylesheetRoot.ComposeState cstate = sroot.getComposeState();
  312. java.util.Vector vnames = cstate.getVariableNames();
  313. if(null != m_caseorder_avt)
  314. m_caseorder_avt.fixupVariables(vnames, cstate.getGlobalsSize());
  315. if(null != m_dataType_avt)
  316. m_dataType_avt.fixupVariables(vnames, cstate.getGlobalsSize());
  317. if(null != m_lang_avt)
  318. m_lang_avt.fixupVariables(vnames, cstate.getGlobalsSize());
  319. if(null != m_order_avt)
  320. m_order_avt.fixupVariables(vnames, cstate.getGlobalsSize());
  321. if(null != m_selectExpression)
  322. m_selectExpression.fixupVariables(vnames, cstate.getGlobalsSize());
  323. }
  324. }