You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

XSLTProcess.java 48 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant.taskdefs;
  19. import java.io.File;
  20. import java.util.Enumeration;
  21. import java.util.Iterator;
  22. import java.util.Vector;
  23. import org.apache.tools.ant.AntClassLoader;
  24. import org.apache.tools.ant.BuildException;
  25. import org.apache.tools.ant.DirectoryScanner;
  26. import org.apache.tools.ant.DynamicConfigurator;
  27. import org.apache.tools.ant.Project;
  28. import org.apache.tools.ant.PropertyHelper;
  29. import org.apache.tools.ant.types.CommandlineJava;
  30. import org.apache.tools.ant.types.Environment;
  31. import org.apache.tools.ant.types.Mapper;
  32. import org.apache.tools.ant.types.Path;
  33. import org.apache.tools.ant.types.PropertySet;
  34. import org.apache.tools.ant.types.Reference;
  35. import org.apache.tools.ant.types.Resource;
  36. import org.apache.tools.ant.types.ResourceCollection;
  37. import org.apache.tools.ant.types.XMLCatalog;
  38. import org.apache.tools.ant.types.resources.FileResource;
  39. import org.apache.tools.ant.types.resources.Resources;
  40. import org.apache.tools.ant.types.resources.Union;
  41. import org.apache.tools.ant.types.resources.FileProvider;
  42. import org.apache.tools.ant.util.FileNameMapper;
  43. import org.apache.tools.ant.util.FileUtils;
  44. import org.apache.tools.ant.util.ResourceUtils;
  45. /**
  46. * Processes a set of XML documents via XSLT. This is
  47. * useful for building views of XML based documentation.
  48. *
  49. *
  50. * @since Ant 1.1
  51. *
  52. * @ant.task name="xslt" category="xml"
  53. */
  54. public class XSLTProcess extends MatchingTask implements XSLTLogger {
  55. /** destination directory */
  56. private File destDir = null;
  57. /** where to find the source XML file, default is the project's basedir */
  58. private File baseDir = null;
  59. /** XSL stylesheet as a filename */
  60. private String xslFile = null;
  61. /** XSL stylesheet as a {@link org.apache.tools.ant.types.Resource} */
  62. private Resource xslResource = null;
  63. /** extension of the files produced by XSL processing */
  64. private String targetExtension = ".html";
  65. /** name for XSL parameter containing the filename */
  66. private String fileNameParameter = null;
  67. /** name for XSL parameter containing the file directory */
  68. private String fileDirParameter = null;
  69. /** additional parameters to be passed to the stylesheets */
  70. private Vector params = new Vector();
  71. /** Input XML document to be used */
  72. private File inFile = null;
  73. /** Output file */
  74. private File outFile = null;
  75. /** The name of the XSL processor to use */
  76. private String processor;
  77. /** Classpath to use when trying to load the XSL processor */
  78. private Path classpath = null;
  79. /** The Liason implementation to use to communicate with the XSL
  80. * processor */
  81. private XSLTLiaison liaison;
  82. /** Flag which indicates if the stylesheet has been loaded into
  83. * the processor */
  84. private boolean stylesheetLoaded = false;
  85. /** force output of target files even if they already exist */
  86. private boolean force = false;
  87. /** XSL output properties to be used */
  88. private Vector outputProperties = new Vector();
  89. /** for resolving entities such as dtds */
  90. private XMLCatalog xmlCatalog = new XMLCatalog();
  91. /** Utilities used for file operations */
  92. private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
  93. /**
  94. * Whether to style all files in the included directories as well.
  95. *
  96. * @since Ant 1.5
  97. */
  98. private boolean performDirectoryScan = true;
  99. /**
  100. * factory element for TraX processors only
  101. * @since Ant 1.6
  102. */
  103. private Factory factory = null;
  104. /**
  105. * whether to reuse Transformer if transforming multiple files.
  106. * @since 1.5.2
  107. */
  108. private boolean reuseLoadedStylesheet = true;
  109. /**
  110. * AntClassLoader for the nested <classpath> - if set.
  111. *
  112. * <p>We keep this here in order to reset the context classloader
  113. * in execute. We can't use liaison.getClass().getClassLoader()
  114. * since the actual liaison class may have been loaded by a loader
  115. * higher up (system classloader, for example).</p>
  116. *
  117. * @since Ant 1.6.2
  118. */
  119. private AntClassLoader loader = null;
  120. /**
  121. * Mapper to use when a set of files gets processed.
  122. *
  123. * @since Ant 1.6.2
  124. */
  125. private Mapper mapperElement = null;
  126. /**
  127. * Additional resource collections to process.
  128. *
  129. * @since Ant 1.7
  130. */
  131. private Union resources = new Union();
  132. /**
  133. * Whether to use the implicit fileset.
  134. *
  135. * @since Ant 1.7
  136. */
  137. private boolean useImplicitFileset = true;
  138. /**
  139. * The default processor is trax
  140. * @since Ant 1.7
  141. */
  142. public static final String PROCESSOR_TRAX = "trax";
  143. /**
  144. * whether to suppress warnings.
  145. *
  146. * @since Ant 1.8.0
  147. */
  148. private boolean suppressWarnings = false;
  149. /**
  150. * whether to fail the build if an error occurs during transformation.
  151. *
  152. * @since Ant 1.8.0
  153. */
  154. private boolean failOnTransformationError = true;
  155. /**
  156. * whether to fail the build if an error occurs.
  157. *
  158. * @since Ant 1.8.0
  159. */
  160. private boolean failOnError = true;
  161. /**
  162. * Whether the build should fail if the nested resource collection
  163. * is empty.
  164. *
  165. * @since Ant 1.8.0
  166. */
  167. private boolean failOnNoResources = true;
  168. /**
  169. * System properties to set during transformation.
  170. *
  171. * @since Ant 1.8.0
  172. */
  173. private CommandlineJava.SysProperties sysProperties =
  174. new CommandlineJava.SysProperties();
  175. /**
  176. * Trace configuration for Xalan2.
  177. *
  178. * @since Ant 1.8.0
  179. */
  180. private TraceConfiguration traceConfiguration;
  181. /**
  182. * Creates a new XSLTProcess Task.
  183. */
  184. public XSLTProcess() {
  185. } //-- XSLTProcess
  186. /**
  187. * Whether to style all files in the included directories as well;
  188. * optional, default is true.
  189. *
  190. * @param b true if files in included directories are processed.
  191. * @since Ant 1.5
  192. */
  193. public void setScanIncludedDirectories(boolean b) {
  194. performDirectoryScan = b;
  195. }
  196. /**
  197. * Controls whether the stylesheet is reloaded for every transform.
  198. *
  199. * <p>Setting this to true may get around a bug in certain
  200. * Xalan-J versions, default is false.</p>
  201. * @param b a <code>boolean</code> value
  202. * @since Ant 1.5.2
  203. */
  204. public void setReloadStylesheet(boolean b) {
  205. reuseLoadedStylesheet = !b;
  206. }
  207. /**
  208. * Defines the mapper to map source to destination files.
  209. * @param mapper the mapper to use
  210. * @exception BuildException if more than one mapper is defined
  211. * @since Ant 1.6.2
  212. */
  213. public void addMapper(Mapper mapper) {
  214. if (mapperElement != null) {
  215. handleError("Cannot define more than one mapper");
  216. } else {
  217. mapperElement = mapper;
  218. }
  219. }
  220. /**
  221. * Adds a collection of resources to style in addition to the
  222. * given file or the implicit fileset.
  223. *
  224. * @param rc the collection of resources to style
  225. * @since Ant 1.7
  226. */
  227. public void add(ResourceCollection rc) {
  228. resources.add(rc);
  229. }
  230. /**
  231. * Add a nested &lt;style&gt; element.
  232. * @param rc the configured Resources object represented as &lt;style&gt;.
  233. * @since Ant 1.7
  234. */
  235. public void addConfiguredStyle(Resources rc) {
  236. if (rc.size() != 1) {
  237. handleError("The style element must be specified with exactly one"
  238. + " nested resource.");
  239. } else {
  240. setXslResource((Resource) rc.iterator().next());
  241. }
  242. }
  243. /**
  244. * API method to set the XSL Resource.
  245. * @param xslResource Resource to set as the stylesheet.
  246. * @since Ant 1.7
  247. */
  248. public void setXslResource(Resource xslResource) {
  249. this.xslResource = xslResource;
  250. }
  251. /**
  252. * Adds a nested filenamemapper.
  253. * @param fileNameMapper the mapper to add
  254. * @exception BuildException if more than one mapper is defined
  255. * @since Ant 1.7.0
  256. */
  257. public void add(FileNameMapper fileNameMapper) throws BuildException {
  258. Mapper mapper = new Mapper(getProject());
  259. mapper.add(fileNameMapper);
  260. addMapper(mapper);
  261. }
  262. /**
  263. * Executes the task.
  264. *
  265. * @exception BuildException if there is an execution problem.
  266. * @todo validate that if either in or our is defined, then both are
  267. */
  268. public void execute() throws BuildException {
  269. if ("style".equals(getTaskType())) {
  270. log("Warning: the task name <style> is deprecated. Use <xslt> instead.",
  271. Project.MSG_WARN);
  272. }
  273. File savedBaseDir = baseDir;
  274. DirectoryScanner scanner;
  275. String[] list;
  276. String[] dirs;
  277. String baseMessage =
  278. "specify the stylesheet either as a filename in style attribute "
  279. + "or as a nested resource";
  280. if (xslResource == null && xslFile == null) {
  281. handleError(baseMessage);
  282. return;
  283. }
  284. if (xslResource != null && xslFile != null) {
  285. handleError(baseMessage + " but not as both");
  286. return;
  287. }
  288. if (inFile != null && !inFile.exists()) {
  289. handleError("input file " + inFile + " does not exist");
  290. return;
  291. }
  292. try {
  293. if (sysProperties.size() > 0) {
  294. sysProperties.setSystem();
  295. }
  296. Resource styleResource;
  297. if (baseDir == null) {
  298. baseDir = getProject().getBaseDir();
  299. }
  300. liaison = getLiaison();
  301. // check if liaison wants to log errors using us as logger
  302. if (liaison instanceof XSLTLoggerAware) {
  303. ((XSLTLoggerAware) liaison).setLogger(this);
  304. }
  305. log("Using " + liaison.getClass().toString(), Project.MSG_VERBOSE);
  306. if (xslFile != null) {
  307. // If we enter here, it means that the stylesheet is supplied
  308. // via style attribute
  309. File stylesheet = getProject().resolveFile(xslFile);
  310. if (!stylesheet.exists()) {
  311. stylesheet = FILE_UTILS.resolveFile(baseDir, xslFile);
  312. /*
  313. * shouldn't throw out deprecation warnings before we know,
  314. * the wrong version has been used.
  315. */
  316. if (stylesheet.exists()) {
  317. log("DEPRECATED - the 'style' attribute should be "
  318. + "relative to the project's");
  319. log(" basedir, not the tasks's basedir.");
  320. }
  321. }
  322. FileResource fr = new FileResource();
  323. fr.setProject(getProject());
  324. fr.setFile(stylesheet);
  325. styleResource = fr;
  326. } else {
  327. styleResource = xslResource;
  328. }
  329. if (!styleResource.isExists()) {
  330. handleError("stylesheet " + styleResource + " doesn't exist.");
  331. return;
  332. }
  333. // if we have an in file and out then process them
  334. if (inFile != null && outFile != null) {
  335. process(inFile, outFile, styleResource);
  336. return;
  337. }
  338. /*
  339. * if we get here, in and out have not been specified, we are
  340. * in batch processing mode.
  341. */
  342. //-- make sure destination directory exists...
  343. checkDest();
  344. if (useImplicitFileset) {
  345. scanner = getDirectoryScanner(baseDir);
  346. log("Transforming into " + destDir, Project.MSG_INFO);
  347. // Process all the files marked for styling
  348. list = scanner.getIncludedFiles();
  349. for (int i = 0; i < list.length; ++i) {
  350. process(baseDir, list[i], destDir, styleResource);
  351. }
  352. if (performDirectoryScan) {
  353. // Process all the directories marked for styling
  354. dirs = scanner.getIncludedDirectories();
  355. for (int j = 0; j < dirs.length; ++j) {
  356. list = new File(baseDir, dirs[j]).list();
  357. for (int i = 0; i < list.length; ++i) {
  358. process(baseDir, dirs[j] + File.separator + list[i], destDir,
  359. styleResource);
  360. }
  361. }
  362. }
  363. } else { // only resource collections, there better be some
  364. if (resources.size() == 0) {
  365. if (failOnNoResources) {
  366. handleError("no resources specified");
  367. }
  368. return;
  369. }
  370. }
  371. processResources(styleResource);
  372. } finally {
  373. if (loader != null) {
  374. loader.resetThreadContextLoader();
  375. loader.cleanup();
  376. loader = null;
  377. }
  378. if (sysProperties.size() > 0) {
  379. sysProperties.restoreSystem();
  380. }
  381. liaison = null;
  382. stylesheetLoaded = false;
  383. baseDir = savedBaseDir;
  384. }
  385. }
  386. /**
  387. * Set whether to check dependencies, or always generate;
  388. * optional, default is false.
  389. *
  390. * @param force true if always generate.
  391. */
  392. public void setForce(boolean force) {
  393. this.force = force;
  394. }
  395. /**
  396. * Set the base directory;
  397. * optional, default is the project's basedir.
  398. *
  399. * @param dir the base directory
  400. **/
  401. public void setBasedir(File dir) {
  402. baseDir = dir;
  403. }
  404. /**
  405. * Set the destination directory into which the XSL result
  406. * files should be copied to;
  407. * required, unless <tt>in</tt> and <tt>out</tt> are
  408. * specified.
  409. * @param dir the name of the destination directory
  410. **/
  411. public void setDestdir(File dir) {
  412. destDir = dir;
  413. }
  414. /**
  415. * Set the desired file extension to be used for the target;
  416. * optional, default is html.
  417. * @param name the extension to use
  418. **/
  419. public void setExtension(String name) {
  420. targetExtension = name;
  421. }
  422. /**
  423. * Name of the stylesheet to use - given either relative
  424. * to the project's basedir or as an absolute path; required.
  425. *
  426. * @param xslFile the stylesheet to use
  427. */
  428. public void setStyle(String xslFile) {
  429. this.xslFile = xslFile;
  430. }
  431. /**
  432. * Set the optional classpath to the XSL processor
  433. *
  434. * @param classpath the classpath to use when loading the XSL processor
  435. */
  436. public void setClasspath(Path classpath) {
  437. createClasspath().append(classpath);
  438. }
  439. /**
  440. * Set the optional classpath to the XSL processor
  441. *
  442. * @return a path instance to be configured by the Ant core.
  443. */
  444. public Path createClasspath() {
  445. if (classpath == null) {
  446. classpath = new Path(getProject());
  447. }
  448. return classpath.createPath();
  449. }
  450. /**
  451. * Set the reference to an optional classpath to the XSL processor
  452. *
  453. * @param r the id of the Ant path instance to act as the classpath
  454. * for loading the XSL processor
  455. */
  456. public void setClasspathRef(Reference r) {
  457. createClasspath().setRefid(r);
  458. }
  459. /**
  460. * Set the name of the XSL processor to use; optional, default trax.
  461. *
  462. * @param processor the name of the XSL processor
  463. */
  464. public void setProcessor(String processor) {
  465. this.processor = processor;
  466. }
  467. /**
  468. * Whether to use the implicit fileset.
  469. *
  470. * <p>Set this to false if you want explicit control with nested
  471. * resource collections.</p>
  472. * @param useimplicitfileset set to true if you want to use implicit fileset
  473. * @since Ant 1.7
  474. */
  475. public void setUseImplicitFileset(boolean useimplicitfileset) {
  476. useImplicitFileset = useimplicitfileset;
  477. }
  478. /**
  479. * Add the catalog to our internal catalog
  480. *
  481. * @param xmlCatalog the XMLCatalog instance to use to look up DTDs
  482. */
  483. public void addConfiguredXMLCatalog(XMLCatalog xmlCatalog) {
  484. this.xmlCatalog.addConfiguredXMLCatalog(xmlCatalog);
  485. }
  486. /**
  487. * Pass the filename of the current processed file as a xsl parameter
  488. * to the transformation. This value sets the name of that xsl parameter.
  489. *
  490. * @param fileNameParameter name of the xsl parameter retrieving the
  491. * current file name
  492. */
  493. public void setFileNameParameter(String fileNameParameter) {
  494. this.fileNameParameter = fileNameParameter;
  495. }
  496. /**
  497. * Pass the directory name of the current processed file as a xsl parameter
  498. * to the transformation. This value sets the name of that xsl parameter.
  499. *
  500. * @param fileDirParameter name of the xsl parameter retrieving the
  501. * current file directory
  502. */
  503. public void setFileDirParameter(String fileDirParameter) {
  504. this.fileDirParameter = fileDirParameter;
  505. }
  506. /**
  507. * Whether to suppress warning messages of the processor.
  508. *
  509. * @since Ant 1.8.0
  510. */
  511. public void setSuppressWarnings(boolean b) {
  512. suppressWarnings = b;
  513. }
  514. /**
  515. * Whether to suppress warning messages of the processor.
  516. *
  517. * @since Ant 1.8.0
  518. */
  519. public boolean getSuppressWarnings() {
  520. return suppressWarnings;
  521. }
  522. /**
  523. * Whether transformation errors should make the build fail.
  524. *
  525. * @since Ant 1.8.0
  526. */
  527. public void setFailOnTransformationError(boolean b) {
  528. failOnTransformationError = b;
  529. }
  530. /**
  531. * Whether any errors should make the build fail.
  532. *
  533. * @since Ant 1.8.0
  534. */
  535. public void setFailOnError(boolean b) {
  536. failOnError = b;
  537. }
  538. /**
  539. * Whether the build should fail if the nested resource collection is empty.
  540. *
  541. * @since Ant 1.8.0
  542. */
  543. public void setFailOnNoResources(boolean b) {
  544. failOnNoResources = b;
  545. }
  546. /**
  547. * A system property to set during transformation.
  548. *
  549. * @since Ant 1.8.0
  550. */
  551. public void addSysproperty(Environment.Variable sysp) {
  552. sysProperties.addVariable(sysp);
  553. }
  554. /**
  555. * A set of system properties to set during transformation.
  556. *
  557. * @since Ant 1.8.0
  558. */
  559. public void addSyspropertyset(PropertySet sysp) {
  560. sysProperties.addSyspropertyset(sysp);
  561. }
  562. /**
  563. * Enables Xalan2 traces and uses the given configuration.
  564. *
  565. * <p>Note that this element doesn't have any effect with a
  566. * processor other than trax or if the Transformer is not Xalan2's
  567. * transformer implementation.</p>
  568. *
  569. * @since Ant 1.8.0
  570. */
  571. public TraceConfiguration createTrace() {
  572. if (traceConfiguration != null) {
  573. throw new BuildException("can't have more than one trace"
  574. + " configuration");
  575. }
  576. traceConfiguration = new TraceConfiguration();
  577. return traceConfiguration;
  578. }
  579. /**
  580. * Configuration for Xalan2 traces.
  581. *
  582. * @since Ant 1.8.0
  583. */
  584. public TraceConfiguration getTraceConfiguration() {
  585. return traceConfiguration;
  586. }
  587. /**
  588. * Load processor here instead of in setProcessor - this will be
  589. * called from within execute, so we have access to the latest
  590. * classpath.
  591. *
  592. * @param proc the name of the processor to load.
  593. * @exception Exception if the processor cannot be loaded.
  594. */
  595. private void resolveProcessor(String proc) throws Exception {
  596. if (proc.equals(PROCESSOR_TRAX)) {
  597. liaison = new org.apache.tools.ant.taskdefs.optional.TraXLiaison();
  598. } else {
  599. //anything else is a classname
  600. Class clazz = loadClass(proc);
  601. liaison = (XSLTLiaison) clazz.newInstance();
  602. }
  603. }
  604. /**
  605. * Load named class either via the system classloader or a given
  606. * custom classloader.
  607. *
  608. * As a side effect, the loader is set as the thread context classloader
  609. * @param classname the name of the class to load.
  610. * @return the requested class.
  611. * @exception Exception if the class could not be loaded.
  612. */
  613. private Class loadClass(String classname) throws Exception {
  614. if (classpath == null) {
  615. return Class.forName(classname);
  616. }
  617. loader = getProject().createClassLoader(classpath);
  618. loader.setThreadContextLoader();
  619. return Class.forName(classname, true, loader);
  620. }
  621. /**
  622. * Specifies the output name for the styled result from the
  623. * <tt>in</tt> attribute; required if <tt>in</tt> is set
  624. *
  625. * @param outFile the output File instance.
  626. */
  627. public void setOut(File outFile) {
  628. this.outFile = outFile;
  629. }
  630. /**
  631. * specifies a single XML document to be styled. Should be used
  632. * with the <tt>out</tt> attribute; ; required if <tt>out</tt> is set
  633. *
  634. * @param inFile the input file
  635. */
  636. public void setIn(File inFile) {
  637. this.inFile = inFile;
  638. }
  639. /**
  640. * Throws a BuildException if the destination directory hasn't
  641. * been specified.
  642. * @since Ant 1.7
  643. */
  644. private void checkDest() {
  645. if (destDir == null) {
  646. handleError("destdir attributes must be set!");
  647. }
  648. }
  649. /**
  650. * Styles all existing resources.
  651. *
  652. * @param stylesheet style sheet to use
  653. * @since Ant 1.7
  654. */
  655. private void processResources(Resource stylesheet) {
  656. Iterator iter = resources.iterator();
  657. while (iter.hasNext()) {
  658. Resource r = (Resource) iter.next();
  659. if (!r.isExists()) {
  660. continue;
  661. }
  662. File base = baseDir;
  663. String name = r.getName();
  664. FileProvider fp = (FileProvider) r.as(FileProvider.class);
  665. if (fp != null) {
  666. FileResource f = ResourceUtils.asFileResource(fp);
  667. base = f.getBaseDir();
  668. if (base == null) {
  669. name = f.getFile().getAbsolutePath();
  670. }
  671. }
  672. process(base, name, destDir, stylesheet);
  673. }
  674. }
  675. /**
  676. * Processes the given input XML file and stores the result
  677. * in the given resultFile.
  678. *
  679. * @param baseDir the base directory for resolving files.
  680. * @param xmlFile the input file
  681. * @param destDir the destination directory
  682. * @param stylesheet the stylesheet to use.
  683. * @exception BuildException if the processing fails.
  684. */
  685. private void process(File baseDir, String xmlFile, File destDir, Resource stylesheet)
  686. throws BuildException {
  687. File outF = null;
  688. File inF = null;
  689. try {
  690. long styleSheetLastModified = stylesheet.getLastModified();
  691. inF = new File(baseDir, xmlFile);
  692. if (inF.isDirectory()) {
  693. log("Skipping " + inF + " it is a directory.", Project.MSG_VERBOSE);
  694. return;
  695. }
  696. FileNameMapper mapper = null;
  697. if (mapperElement != null) {
  698. mapper = mapperElement.getImplementation();
  699. } else {
  700. mapper = new StyleMapper();
  701. }
  702. String[] outFileName = mapper.mapFileName(xmlFile);
  703. if (outFileName == null || outFileName.length == 0) {
  704. log("Skipping " + inFile + " it cannot get mapped to output.", Project.MSG_VERBOSE);
  705. return;
  706. } else if (outFileName == null || outFileName.length > 1) {
  707. log("Skipping " + inFile + " its mapping is ambiguos.", Project.MSG_VERBOSE);
  708. return;
  709. }
  710. outF = new File(destDir, outFileName[0]);
  711. if (force || inF.lastModified() > outF.lastModified()
  712. || styleSheetLastModified > outF.lastModified()) {
  713. ensureDirectoryFor(outF);
  714. log("Processing " + inF + " to " + outF);
  715. configureLiaison(stylesheet);
  716. setLiaisonDynamicFileParameters(liaison, inF);
  717. liaison.transform(inF, outF);
  718. }
  719. } catch (Exception ex) {
  720. // If failed to process document, must delete target document,
  721. // or it will not attempt to process it the second time
  722. log("Failed to process " + inFile, Project.MSG_INFO);
  723. if (outF != null) {
  724. outF.delete();
  725. }
  726. handleTransformationError(ex);
  727. }
  728. } //-- processXML
  729. /**
  730. * Process the input file to the output file with the given stylesheet.
  731. *
  732. * @param inFile the input file to process.
  733. * @param outFile the destination file.
  734. * @param stylesheet the stylesheet to use.
  735. * @exception BuildException if the processing fails.
  736. */
  737. private void process(File inFile, File outFile, Resource stylesheet) throws BuildException {
  738. try {
  739. long styleSheetLastModified = stylesheet.getLastModified();
  740. log("In file " + inFile + " time: " + inFile.lastModified(), Project.MSG_DEBUG);
  741. log("Out file " + outFile + " time: " + outFile.lastModified(), Project.MSG_DEBUG);
  742. log("Style file " + xslFile + " time: " + styleSheetLastModified, Project.MSG_DEBUG);
  743. if (force || inFile.lastModified() >= outFile.lastModified()
  744. || styleSheetLastModified >= outFile.lastModified()) {
  745. ensureDirectoryFor(outFile);
  746. log("Processing " + inFile + " to " + outFile, Project.MSG_INFO);
  747. configureLiaison(stylesheet);
  748. setLiaisonDynamicFileParameters(liaison, inFile);
  749. liaison.transform(inFile, outFile);
  750. } else {
  751. log("Skipping input file " + inFile + " because it is older than output file "
  752. + outFile + " and so is the stylesheet " + stylesheet, Project.MSG_DEBUG);
  753. }
  754. } catch (Exception ex) {
  755. log("Failed to process " + inFile, Project.MSG_INFO);
  756. if (outFile != null) {
  757. outFile.delete();
  758. }
  759. handleTransformationError(ex);
  760. }
  761. }
  762. /**
  763. * Ensure the directory exists for a given file
  764. *
  765. * @param targetFile the file for which the directories are required.
  766. * @exception BuildException if the directories cannot be created.
  767. */
  768. private void ensureDirectoryFor(File targetFile) throws BuildException {
  769. File directory = targetFile.getParentFile();
  770. if (!directory.exists()) {
  771. if (!directory.mkdirs()) {
  772. handleError("Unable to create directory: "
  773. + directory.getAbsolutePath());
  774. }
  775. }
  776. }
  777. /**
  778. * Get the factory instance configured for this processor
  779. *
  780. * @return the factory instance in use
  781. */
  782. public Factory getFactory() {
  783. return factory;
  784. }
  785. /**
  786. * Get the XML catalog containing entity definitions
  787. *
  788. * @return the XML catalog for the task.
  789. */
  790. public XMLCatalog getXMLCatalog() {
  791. xmlCatalog.setProject(getProject());
  792. return xmlCatalog;
  793. }
  794. /**
  795. * Get an enumeration on the outputproperties.
  796. * @return the outputproperties
  797. */
  798. public Enumeration getOutputProperties() {
  799. return outputProperties.elements();
  800. }
  801. /**
  802. * Get the Liason implementation to use in processing.
  803. *
  804. * @return an instance of the XSLTLiason interface.
  805. */
  806. protected XSLTLiaison getLiaison() {
  807. // if processor wasn't specified, use TraX.
  808. if (liaison == null) {
  809. if (processor != null) {
  810. try {
  811. resolveProcessor(processor);
  812. } catch (Exception e) {
  813. handleError(e);
  814. }
  815. } else {
  816. try {
  817. resolveProcessor(PROCESSOR_TRAX);
  818. } catch (Exception e1) { // should not happen
  819. handleError(e1);
  820. }
  821. }
  822. }
  823. return liaison;
  824. }
  825. /**
  826. * Create an instance of an XSL parameter for configuration by Ant.
  827. *
  828. * @return an instance of the Param class to be configured.
  829. */
  830. public Param createParam() {
  831. Param p = new Param();
  832. params.addElement(p);
  833. return p;
  834. }
  835. /**
  836. * The Param inner class used to store XSL parameters
  837. */
  838. public static class Param {
  839. /** The parameter name */
  840. private String name = null;
  841. /** The parameter's value */
  842. private String expression = null;
  843. private Object ifCond;
  844. private Object unlessCond;
  845. private Project project;
  846. /**
  847. * Set the current project
  848. *
  849. * @param project the current project
  850. */
  851. public void setProject(Project project) {
  852. this.project = project;
  853. }
  854. /**
  855. * Set the parameter name.
  856. *
  857. * @param name the name of the parameter.
  858. */
  859. public void setName(String name) {
  860. this.name = name;
  861. }
  862. /**
  863. * The parameter value
  864. * NOTE : was intended to be an XSL expression.
  865. * @param expression the parameter's value.
  866. */
  867. public void setExpression(String expression) {
  868. this.expression = expression;
  869. }
  870. /**
  871. * Get the parameter name
  872. *
  873. * @return the parameter name
  874. * @exception BuildException if the name is not set.
  875. */
  876. public String getName() throws BuildException {
  877. if (name == null) {
  878. throw new BuildException("Name attribute is missing.");
  879. }
  880. return name;
  881. }
  882. /**
  883. * Get the parameter's value
  884. *
  885. * @return the parameter value
  886. * @exception BuildException if the value is not set.
  887. */
  888. public String getExpression() throws BuildException {
  889. if (expression == null) {
  890. throw new BuildException("Expression attribute is missing.");
  891. }
  892. return expression;
  893. }
  894. /**
  895. * Set whether this param should be used. It will be used if
  896. * the expression evalutes to true or the name of a property
  897. * which has been set, otherwise it won't.
  898. * @param ifCond evaluated expression
  899. * @since Ant 1.8.0
  900. */
  901. public void setIf(Object ifCond) {
  902. this.ifCond = ifCond;
  903. }
  904. /**
  905. * Set whether this param should be used. It will be used if
  906. * the expression evalutes to true or the name of a property
  907. * which has been set, otherwise it won't.
  908. * @param ifProperty evaluated expression
  909. */
  910. public void setIf(String ifProperty) {
  911. setIf((Object) ifProperty);
  912. }
  913. /**
  914. * Set whether this param should NOT be used. It will not be
  915. * used if the expression evaluates to true or the name of a
  916. * property which has been set, otherwise it will be used.
  917. * @param unlessCond evaluated expression
  918. * @since Ant 1.8.0
  919. */
  920. public void setUnless(Object unlessCond) {
  921. this.unlessCond = unlessCond;
  922. }
  923. /**
  924. * Set whether this param should NOT be used. It will not be
  925. * used if the expression evaluates to true or the name of a
  926. * property which has been set, otherwise it will be used.
  927. * @param unlessProperty evaluated expression
  928. */
  929. public void setUnless(String unlessProperty) {
  930. setUnless((Object) unlessProperty);
  931. }
  932. /**
  933. * Ensures that the param passes the conditions placed
  934. * on it with <code>if</code> and <code>unless</code> properties.
  935. * @return true if the task passes the "if" and "unless" parameters
  936. */
  937. public boolean shouldUse() {
  938. PropertyHelper ph = PropertyHelper.getPropertyHelper(project);
  939. return ph.testIfCondition(ifCond)
  940. && ph.testUnlessCondition(unlessCond);
  941. }
  942. } // Param
  943. /**
  944. * Create an instance of an output property to be configured.
  945. * @return the newly created output property.
  946. * @since Ant 1.5
  947. */
  948. public OutputProperty createOutputProperty() {
  949. OutputProperty p = new OutputProperty();
  950. outputProperties.addElement(p);
  951. return p;
  952. }
  953. /**
  954. * Specify how the result tree should be output as specified
  955. * in the <a href="http://www.w3.org/TR/xslt#output">
  956. * specification</a>.
  957. * @since Ant 1.5
  958. */
  959. public static class OutputProperty {
  960. /** output property name */
  961. private String name;
  962. /** output property value */
  963. private String value;
  964. /**
  965. * @return the output property name.
  966. */
  967. public String getName() {
  968. return name;
  969. }
  970. /**
  971. * set the name for this property
  972. * @param name A non-null String that specifies an
  973. * output property name, which may be namespace qualified.
  974. */
  975. public void setName(String name) {
  976. this.name = name;
  977. }
  978. /**
  979. * @return the output property value.
  980. */
  981. public String getValue() {
  982. return value;
  983. }
  984. /**
  985. * set the value for this property
  986. * @param value The non-null string value of the output property.
  987. */
  988. public void setValue(String value) {
  989. this.value = value;
  990. }
  991. }
  992. /**
  993. * Initialize internal instance of XMLCatalog
  994. * @throws BuildException on error
  995. */
  996. public void init() throws BuildException {
  997. super.init();
  998. xmlCatalog.setProject(getProject());
  999. }
  1000. /**
  1001. * Loads the stylesheet and set xsl:param parameters.
  1002. *
  1003. * @param stylesheet the file from which to load the stylesheet.
  1004. * @exception BuildException if the stylesheet cannot be loaded.
  1005. * @deprecated since Ant 1.7
  1006. */
  1007. protected void configureLiaison(File stylesheet) throws BuildException {
  1008. FileResource fr = new FileResource();
  1009. fr.setProject(getProject());
  1010. fr.setFile(stylesheet);
  1011. configureLiaison(fr);
  1012. }
  1013. /**
  1014. * Loads the stylesheet and set xsl:param parameters.
  1015. *
  1016. * @param stylesheet the resource from which to load the stylesheet.
  1017. * @exception BuildException if the stylesheet cannot be loaded.
  1018. * @since Ant 1.7
  1019. */
  1020. protected void configureLiaison(Resource stylesheet) throws BuildException {
  1021. if (stylesheetLoaded && reuseLoadedStylesheet) {
  1022. return;
  1023. }
  1024. stylesheetLoaded = true;
  1025. try {
  1026. log("Loading stylesheet " + stylesheet, Project.MSG_INFO);
  1027. // We call liason.configure() and then liaison.setStylesheet()
  1028. // so that the internal variables of liaison can be set up
  1029. if (liaison instanceof XSLTLiaison2) {
  1030. ((XSLTLiaison2) liaison).configure(this);
  1031. }
  1032. if (liaison instanceof XSLTLiaison3) {
  1033. // If we are here we can set the stylesheet as a
  1034. // resource
  1035. ((XSLTLiaison3) liaison).setStylesheet(stylesheet);
  1036. } else {
  1037. // If we are here we cannot set the stylesheet as
  1038. // a resource, but we can set it as a file. So,
  1039. // we make an attempt to get it as a file
  1040. FileProvider fp =
  1041. (FileProvider) stylesheet.as(FileProvider.class);
  1042. if (fp != null) {
  1043. liaison.setStylesheet(fp.getFile());
  1044. } else {
  1045. handleError(liaison.getClass().toString()
  1046. + " accepts the stylesheet only as a file");
  1047. return;
  1048. }
  1049. }
  1050. for (Enumeration e = params.elements(); e.hasMoreElements();) {
  1051. Param p = (Param) e.nextElement();
  1052. if (p.shouldUse()) {
  1053. liaison.addParam(p.getName(), p.getExpression());
  1054. }
  1055. }
  1056. } catch (Exception ex) {
  1057. log("Failed to transform using stylesheet " + stylesheet, Project.MSG_INFO);
  1058. handleTransformationError(ex);
  1059. }
  1060. }
  1061. /**
  1062. * Sets file parameter(s) for directory and filename if the attribute
  1063. * 'filenameparameter' or 'filedirparameter' are set in the task.
  1064. *
  1065. * @param liaison to change parameters for
  1066. * @param inFile to get the additional file information from
  1067. * @throws Exception if an exception occurs on filename lookup
  1068. *
  1069. * @since Ant 1.7
  1070. */
  1071. private void setLiaisonDynamicFileParameters(
  1072. XSLTLiaison liaison, File inFile) throws Exception {
  1073. if (fileNameParameter != null) {
  1074. liaison.addParam(fileNameParameter, inFile.getName());
  1075. }
  1076. if (fileDirParameter != null) {
  1077. String fileName = FileUtils.getRelativePath(baseDir, inFile);
  1078. File file = new File(fileName);
  1079. // Give always a slash as file separator, so the stylesheet could be sure about that
  1080. // Use '.' so a dir+"/"+name would not result in an absolute path
  1081. liaison.addParam(fileDirParameter, file.getParent() != null ? file.getParent().replace(
  1082. '\\', '/') : ".");
  1083. }
  1084. }
  1085. /**
  1086. * Create the factory element to configure a trax liaison.
  1087. * @return the newly created factory element.
  1088. * @throws BuildException if the element is created more than one time.
  1089. */
  1090. public Factory createFactory() throws BuildException {
  1091. if (factory != null) {
  1092. handleError("'factory' element must be unique");
  1093. } else {
  1094. factory = new Factory();
  1095. }
  1096. return factory;
  1097. }
  1098. /**
  1099. * Throws an exception with the given message if failOnError is
  1100. * true, otherwise logs the message using the WARN level.
  1101. *
  1102. * @since Ant 1.8.0
  1103. */
  1104. protected void handleError(String msg) {
  1105. if (failOnError) {
  1106. throw new BuildException(msg, getLocation());
  1107. }
  1108. log(msg, Project.MSG_WARN);
  1109. }
  1110. /**
  1111. * Throws an exception with the given nested exception if
  1112. * failOnError is true, otherwise logs the message using the WARN
  1113. * level.
  1114. *
  1115. * @since Ant 1.8.0
  1116. */
  1117. protected void handleError(Throwable ex) {
  1118. if (failOnError) {
  1119. throw new BuildException(ex);
  1120. } else {
  1121. log("Caught an exception: " + ex, Project.MSG_WARN);
  1122. }
  1123. }
  1124. /**
  1125. * Throws an exception with the given nested exception if
  1126. * failOnError and failOnTransformationError are true, otherwise
  1127. * logs the message using the WARN level.
  1128. *
  1129. * @since Ant 1.8.0
  1130. */
  1131. protected void handleTransformationError(Exception ex) {
  1132. if (failOnError && failOnTransformationError) {
  1133. throw new BuildException(ex);
  1134. } else {
  1135. log("Caught an error during transformation: " + ex,
  1136. Project.MSG_WARN);
  1137. }
  1138. }
  1139. /**
  1140. * The factory element to configure a transformer factory
  1141. * @since Ant 1.6
  1142. */
  1143. public static class Factory {
  1144. /** the factory class name to use for TraXLiaison */
  1145. private String name;
  1146. /**
  1147. * the list of factory attributes to use for TraXLiaison
  1148. */
  1149. private Vector attributes = new Vector();
  1150. /**
  1151. * @return the name of the factory.
  1152. */
  1153. public String getName() {
  1154. return name;
  1155. }
  1156. /**
  1157. * Set the name of the factory
  1158. * @param name the name of the factory.
  1159. */
  1160. public void setName(String name) {
  1161. this.name = name;
  1162. }
  1163. /**
  1164. * Create an instance of a factory attribute.
  1165. * @param attr the newly created factory attribute
  1166. */
  1167. public void addAttribute(Attribute attr) {
  1168. attributes.addElement(attr);
  1169. }
  1170. /**
  1171. * return the attribute elements.
  1172. * @return the enumeration of attributes
  1173. */
  1174. public Enumeration getAttributes() {
  1175. return attributes.elements();
  1176. }
  1177. /**
  1178. * A JAXP factory attribute. This is mostly processor specific, for
  1179. * example for Xalan 2.3+, the following attributes could be set:
  1180. * <ul>
  1181. * <li>http://xml.apache.org/xalan/features/optimize (true|false) </li>
  1182. * <li>http://xml.apache.org/xalan/features/incremental (true|false) </li>
  1183. * </ul>
  1184. */
  1185. public static class Attribute implements DynamicConfigurator {
  1186. /** attribute name, mostly processor specific */
  1187. private String name;
  1188. /** attribute value, often a boolean string */
  1189. private Object value;
  1190. /**
  1191. * @return the attribute name.
  1192. */
  1193. public String getName() {
  1194. return name;
  1195. }
  1196. /**
  1197. * @return the output property value.
  1198. */
  1199. public Object getValue() {
  1200. return value;
  1201. }
  1202. /**
  1203. * Not used.
  1204. * @param name not used
  1205. * @return null
  1206. * @throws BuildException never
  1207. */
  1208. public Object createDynamicElement(String name) throws BuildException {
  1209. return null;
  1210. }
  1211. /**
  1212. * Set an attribute.
  1213. * Only "name" and "value" are supported as names.
  1214. * @param name the name of the attribute
  1215. * @param value the value of the attribute
  1216. * @throws BuildException on error
  1217. */
  1218. public void setDynamicAttribute(String name, String value) throws BuildException {
  1219. // only 'name' and 'value' exist.
  1220. if ("name".equalsIgnoreCase(name)) {
  1221. this.name = value;
  1222. } else if ("value".equalsIgnoreCase(name)) {
  1223. // a value must be of a given type
  1224. // say boolean|integer|string that are mostly used.
  1225. if ("true".equalsIgnoreCase(value)) {
  1226. this.value = Boolean.TRUE;
  1227. } else if ("false".equalsIgnoreCase(value)) {
  1228. this.value = Boolean.FALSE;
  1229. } else {
  1230. try {
  1231. this.value = new Integer(value);
  1232. } catch (NumberFormatException e) {
  1233. this.value = value;
  1234. }
  1235. }
  1236. } else {
  1237. throw new BuildException("Unsupported attribute: " + name);
  1238. }
  1239. }
  1240. } // -- class Attribute
  1241. } // -- class Factory
  1242. /**
  1243. * Mapper implementation of the "traditional" way &lt;xslt&gt;
  1244. * mapped filenames.
  1245. *
  1246. * <p>If the file has an extension, chop it off. Append whatever
  1247. * the user has specified as extension or ".html".</p>
  1248. *
  1249. * @since Ant 1.6.2
  1250. */
  1251. private class StyleMapper implements FileNameMapper {
  1252. public void setFrom(String from) {
  1253. }
  1254. public void setTo(String to) {
  1255. }
  1256. public String[] mapFileName(String xmlFile) {
  1257. int dotPos = xmlFile.lastIndexOf('.');
  1258. if (dotPos > 0) {
  1259. xmlFile = xmlFile.substring(0, dotPos);
  1260. }
  1261. return new String[] {xmlFile + targetExtension};
  1262. }
  1263. }
  1264. /**
  1265. * Configuration for Xalan2 traces.
  1266. *
  1267. * @since Ant 1.8.0
  1268. */
  1269. public final class TraceConfiguration {
  1270. private boolean elements, extension, generation, selection, templates;
  1271. /**
  1272. * Set to true if the listener is to print events that occur
  1273. * as each node is 'executed' in the stylesheet.
  1274. */
  1275. public void setElements(boolean b) {
  1276. elements = b;
  1277. }
  1278. /**
  1279. * True if the listener is to print events that occur as each
  1280. * node is 'executed' in the stylesheet.
  1281. */
  1282. public boolean getElements() {
  1283. return elements;
  1284. }
  1285. /**
  1286. * Set to true if the listener is to print information after
  1287. * each extension event.
  1288. */
  1289. public void setExtension(boolean b) {
  1290. extension = b;
  1291. }
  1292. /**
  1293. * True if the listener is to print information after each
  1294. * extension event.
  1295. */
  1296. public boolean getExtension() {
  1297. return extension;
  1298. }
  1299. /**
  1300. * Set to true if the listener is to print information after
  1301. * each result-tree generation event.
  1302. */
  1303. public void setGeneration(boolean b) {
  1304. generation = b;
  1305. }
  1306. /**
  1307. * True if the listener is to print information after each
  1308. * result-tree generation event.
  1309. */
  1310. public boolean getGeneration() {
  1311. return generation;
  1312. }
  1313. /**
  1314. * Set to true if the listener is to print information after
  1315. * each selection event.
  1316. */
  1317. public void setSelection(boolean b) {
  1318. selection = b;
  1319. }
  1320. /**
  1321. * True if the listener is to print information after each
  1322. * selection event.
  1323. */
  1324. public boolean getSelection() {
  1325. return selection;
  1326. }
  1327. /**
  1328. * Set to true if the listener is to print an event whenever a
  1329. * template is invoked.
  1330. */
  1331. public void setTemplates(boolean b) {
  1332. templates = b;
  1333. }
  1334. /**
  1335. * True if the listener is to print an event whenever a
  1336. * template is invoked.
  1337. */
  1338. public boolean getTemplates() {
  1339. return templates;
  1340. }
  1341. /**
  1342. * The stream to write traces to.
  1343. */
  1344. public java.io.OutputStream getOutputStream() {
  1345. return new LogOutputStream(XSLTProcess.this);
  1346. }
  1347. }
  1348. }