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.

ProjectHelper.java 27 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Ant", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. */
  54. package org.apache.tools.ant;
  55. import java.io.*;
  56. import java.util.*;
  57. import org.xml.sax.*;
  58. import org.w3c.dom.*;
  59. import org.apache.tools.ant.taskdefs.*;
  60. import javax.xml.parsers.*;
  61. /**
  62. * Configures a Project (complete with Targets and Tasks) based on
  63. * a XML build file.
  64. *
  65. * @author duncan@x180.com
  66. */
  67. public class ProjectHelper {
  68. private static SAXParserFactory parserFactory = null;
  69. private org.xml.sax.Parser parser;
  70. private Project project;
  71. private File buildFile;
  72. private File buildFileParent;
  73. private Locator locator;
  74. /**
  75. * Configures the Project with the contents of the specified XML file.
  76. */
  77. public static void configureProject(Project project, File buildFile) throws BuildException {
  78. new ProjectHelper(project, buildFile).parse();
  79. }
  80. /**
  81. * Constructs a new Ant parser for the specified XML file.
  82. */
  83. private ProjectHelper(Project project, File buildFile) {
  84. this.project = project;
  85. this.buildFile = new File(buildFile.getAbsolutePath());
  86. buildFileParent = new File(this.buildFile.getParent());
  87. }
  88. /**
  89. * Parses the project file.
  90. */
  91. private void parse() throws BuildException {
  92. FileInputStream inputStream = null;
  93. InputSource inputSource = null;
  94. try {
  95. SAXParser saxParser = getParserFactory().newSAXParser();
  96. parser = saxParser.getParser();
  97. String uri = "file:" + buildFile.getAbsolutePath().replace('\\', '/');
  98. for (int index = uri.indexOf('#'); index != -1; index = uri.indexOf('#')) {
  99. uri = uri.substring(0, index) + "%23" + uri.substring(index+1);
  100. }
  101. inputStream = new FileInputStream(buildFile);
  102. inputSource = new InputSource(inputStream);
  103. inputSource.setSystemId(uri);
  104. project.log("parsing buildfile " + buildFile + " with URI = " + uri, Project.MSG_VERBOSE);
  105. saxParser.parse(inputSource, new RootHandler());
  106. }
  107. catch(ParserConfigurationException exc) {
  108. throw new BuildException("Parser has not been configured correctly", exc);
  109. }
  110. catch(SAXParseException exc) {
  111. Location location =
  112. new Location(buildFile.toString(), exc.getLineNumber(), exc.getColumnNumber());
  113. Throwable t = exc.getException();
  114. if (t instanceof BuildException) {
  115. BuildException be = (BuildException) t;
  116. if (be.getLocation() == Location.UNKNOWN_LOCATION) {
  117. be.setLocation(location);
  118. }
  119. throw be;
  120. }
  121. throw new BuildException(exc.getMessage(), t, location);
  122. }
  123. catch(SAXException exc) {
  124. Throwable t = exc.getException();
  125. if (t instanceof BuildException) {
  126. throw (BuildException) t;
  127. }
  128. throw new BuildException(exc.getMessage(), t);
  129. }
  130. catch(FileNotFoundException exc) {
  131. throw new BuildException(exc);
  132. }
  133. catch(IOException exc) {
  134. throw new BuildException("Error reading project file", exc);
  135. }
  136. finally {
  137. if (inputStream != null) {
  138. try {
  139. inputStream.close();
  140. }
  141. catch (IOException ioe) {
  142. // ignore this
  143. }
  144. }
  145. }
  146. }
  147. /**
  148. * The common superclass for all sax event handlers in Ant. Basically
  149. * throws an exception in each method, so subclasses should override
  150. * what they can handle.
  151. *
  152. * Each type of xml element (task, target, etc) in ant will
  153. * have its own subclass of AbstractHandler.
  154. *
  155. * In the constructor, this class takes over the handling of sax
  156. * events from the parent handler, and returns
  157. * control back to the parent in the endElement method.
  158. */
  159. private class AbstractHandler extends HandlerBase {
  160. protected DocumentHandler parentHandler;
  161. public AbstractHandler(DocumentHandler parentHandler) {
  162. this.parentHandler = parentHandler;
  163. // Start handling SAX events
  164. parser.setDocumentHandler(this);
  165. }
  166. public void startElement(String tag, AttributeList attrs) throws SAXParseException {
  167. throw new SAXParseException("Unexpected element \"" + tag + "\"", locator);
  168. }
  169. public void characters(char[] buf, int start, int end) throws SAXParseException {
  170. String s = new String(buf, start, end).trim();
  171. if (s.length() > 0) {
  172. throw new SAXParseException("Unexpected text \"" + s + "\"", locator);
  173. }
  174. }
  175. /**
  176. * Called when this element and all elements nested into it have been
  177. * handled.
  178. */
  179. protected void finished() {}
  180. public void endElement(String name) throws SAXException {
  181. finished();
  182. // Let parent resume handling SAX events
  183. parser.setDocumentHandler(parentHandler);
  184. }
  185. }
  186. /**
  187. * Handler for the root element. It's only child must be the "project" element.
  188. */
  189. private class RootHandler extends HandlerBase {
  190. /**
  191. * resolve file: URIs as relative to the build file.
  192. */
  193. public InputSource resolveEntity(String publicId,
  194. String systemId) {
  195. project.log("resolving systemId: " + systemId, Project.MSG_VERBOSE);
  196. if (systemId.startsWith("file:")) {
  197. String path = systemId.substring(5);
  198. int index = path.indexOf("file:");
  199. // we only have to handle these for backward compatibility
  200. // since they are in the FAQ.
  201. while (index != -1) {
  202. path = path.substring(0, index) + path.substring(index + 5);
  203. index = path.indexOf("file:");
  204. }
  205. String entitySystemId = path;
  206. index = path.indexOf("%23");
  207. // convert these to #
  208. while (index != -1) {
  209. path = path.substring(0, index) + "#" + path.substring(index + 3);
  210. index = path.indexOf("%23");
  211. }
  212. File file = new File(path);
  213. if (!file.isAbsolute()) {
  214. file = new File(buildFileParent, path);
  215. }
  216. try {
  217. InputSource inputSource = new InputSource(new FileInputStream(file));
  218. inputSource.setSystemId("file:" + entitySystemId);
  219. return inputSource;
  220. } catch (FileNotFoundException fne) {
  221. project.log(file.getAbsolutePath()+" could not be found",
  222. Project.MSG_WARN);
  223. }
  224. }
  225. // use default if not file or file not found
  226. return null;
  227. }
  228. public void startElement(String tag, AttributeList attrs) throws SAXParseException {
  229. if (tag.equals("project")) {
  230. new ProjectHandler(this).init(tag, attrs);
  231. } else {
  232. throw new SAXParseException("Config file is not of expected XML type", locator);
  233. }
  234. }
  235. public void setDocumentLocator(Locator locator) {
  236. ProjectHelper.this.locator = locator;
  237. }
  238. }
  239. /**
  240. * Handler for the top level "project" element.
  241. */
  242. private class ProjectHandler extends AbstractHandler {
  243. public ProjectHandler(DocumentHandler parentHandler) {
  244. super(parentHandler);
  245. }
  246. public void init(String tag, AttributeList attrs) throws SAXParseException {
  247. String def = null;
  248. String name = null;
  249. String id = null;
  250. String baseDir = null;
  251. for (int i = 0; i < attrs.getLength(); i++) {
  252. String key = attrs.getName(i);
  253. String value = attrs.getValue(i);
  254. if (key.equals("default")) {
  255. def = value;
  256. } else if (key.equals("name")) {
  257. name = value;
  258. } else if (key.equals("id")) {
  259. id = value;
  260. } else if (key.equals("basedir")) {
  261. baseDir = value;
  262. } else {
  263. throw new SAXParseException("Unexpected attribute \"" + attrs.getName(i) + "\"", locator);
  264. }
  265. }
  266. if (def == null) {
  267. throw new SAXParseException("The default attribute of project is required",
  268. locator);
  269. }
  270. project.setDefaultTarget(def);
  271. if (name != null) {
  272. project.setName(name);
  273. project.addReference(name, project);
  274. }
  275. if (id != null) project.addReference(id, project);
  276. if (project.getProperty("basedir") != null) {
  277. project.setBasedir(project.getProperty("basedir"));
  278. } else {
  279. if (baseDir == null) {
  280. project.setBasedir(buildFileParent.getAbsolutePath());
  281. } else {
  282. // check whether the user has specified an absolute path
  283. if ((new File(baseDir)).isAbsolute()) {
  284. project.setBasedir(baseDir);
  285. } else {
  286. project.setBaseDir(project.resolveFile(baseDir, buildFileParent));
  287. }
  288. }
  289. }
  290. }
  291. public void startElement(String name, AttributeList attrs) throws SAXParseException {
  292. if (name.equals("taskdef")) {
  293. handleTaskdef(name, attrs);
  294. } else if (name.equals("property")) {
  295. handleProperty(name, attrs);
  296. } else if (name.equals("target")) {
  297. handleTarget(name, attrs);
  298. } else if (project.getDataTypeDefinitions().get(name) != null) {
  299. handleDataType(name, attrs);
  300. } else {
  301. throw new SAXParseException("Unexpected element \"" + name + "\"", locator);
  302. }
  303. }
  304. private void handleTaskdef(String name, AttributeList attrs) throws SAXParseException {
  305. (new TaskHandler(this, null)).init(name, attrs);
  306. }
  307. private void handleProperty(String name, AttributeList attrs) throws SAXParseException {
  308. (new TaskHandler(this, null)).init(name, attrs);
  309. }
  310. private void handleTarget(String tag, AttributeList attrs) throws SAXParseException {
  311. new TargetHandler(this).init(tag, attrs);
  312. }
  313. private void handleDataType(String name, AttributeList attrs) throws SAXParseException {
  314. new DataTypeHandler(this).init(name, attrs);
  315. }
  316. }
  317. /**
  318. * Handler for "target" elements.
  319. */
  320. private class TargetHandler extends AbstractHandler {
  321. private Target target;
  322. public TargetHandler(DocumentHandler parentHandler) {
  323. super(parentHandler);
  324. }
  325. public void init(String tag, AttributeList attrs) throws SAXParseException {
  326. String name = null;
  327. String depends = "";
  328. String ifCond = null;
  329. String unlessCond = null;
  330. String id = null;
  331. String description = null;
  332. for (int i = 0; i < attrs.getLength(); i++) {
  333. String key = attrs.getName(i);
  334. String value = attrs.getValue(i);
  335. if (key.equals("name")) {
  336. name = value;
  337. } else if (key.equals("depends")) {
  338. depends = value;
  339. } else if (key.equals("if")) {
  340. ifCond = value;
  341. } else if (key.equals("unless")) {
  342. unlessCond = value;
  343. } else if (key.equals("id")) {
  344. id = value;
  345. } else if (key.equals("description")) {
  346. description = value;
  347. } else {
  348. throw new SAXParseException("Unexpected attribute \"" + key + "\"", locator);
  349. }
  350. }
  351. if (name == null) {
  352. throw new SAXParseException("target element appears without a name attribute", locator);
  353. }
  354. target = new Target();
  355. target.setName(name);
  356. target.setIf(ifCond);
  357. target.setUnless(unlessCond);
  358. target.setDescription(description);
  359. project.addTarget(name, target);
  360. if (id != null && !id.equals(""))
  361. project.addReference(id, target);
  362. // take care of dependencies
  363. if (depends.length() > 0) {
  364. StringTokenizer tok =
  365. new StringTokenizer(depends, ",", false);
  366. while (tok.hasMoreTokens()) {
  367. target.addDependency(tok.nextToken().trim());
  368. }
  369. }
  370. }
  371. public void startElement(String name, AttributeList attrs) throws SAXParseException {
  372. if (project.getDataTypeDefinitions().get(name) != null) {
  373. new DataTypeHandler(this, target).init(name, attrs);
  374. } else {
  375. new TaskHandler(this, target).init(name, attrs);
  376. }
  377. }
  378. }
  379. /**
  380. * Handler for all task elements.
  381. */
  382. private class TaskHandler extends AbstractHandler {
  383. private Target target;
  384. private Task task;
  385. private RuntimeConfigurable wrapper = null;
  386. public TaskHandler(DocumentHandler parentHandler, Target target) {
  387. super(parentHandler);
  388. this.target = target;
  389. }
  390. public void init(String tag, AttributeList attrs) throws SAXParseException {
  391. try {
  392. task = project.createTask(tag);
  393. } catch (BuildException e) {
  394. // swallow here, will be thrown again in
  395. // UnknownElement.maybeConfigure if the problem persists.
  396. }
  397. if (task == null) {
  398. task = new UnknownElement(tag);
  399. task.setProject(project);
  400. }
  401. task.setLocation(new Location(buildFile.toString(), locator.getLineNumber(), locator.getColumnNumber()));
  402. configureId(task, attrs);
  403. // Top level tasks don't have associated targets
  404. if (target != null) {
  405. task.setOwningTarget(target);
  406. target.addTask(task);
  407. task.init();
  408. wrapper = task.getRuntimeConfigurableWrapper();
  409. wrapper.setAttributes(attrs);
  410. } else {
  411. task.init();
  412. configure(task, attrs, project);
  413. }
  414. }
  415. protected void finished() {
  416. if (task != null && target == null) {
  417. task.execute();
  418. }
  419. }
  420. public void characters(char[] buf, int start, int end) throws SAXParseException {
  421. if (wrapper == null) {
  422. try {
  423. addText(project, task, buf, start, end);
  424. } catch (BuildException exc) {
  425. throw new SAXParseException(exc.getMessage(), locator, exc);
  426. }
  427. } else {
  428. wrapper.addText(buf, start, end);
  429. }
  430. }
  431. public void startElement(String name, AttributeList attrs) throws SAXParseException {
  432. new NestedElementHandler(this, task, wrapper).init(name, attrs);
  433. }
  434. }
  435. /**
  436. * Handler for all nested properties.
  437. */
  438. private class NestedElementHandler extends AbstractHandler {
  439. private Object target;
  440. private Object child;
  441. private RuntimeConfigurable parentWrapper;
  442. private RuntimeConfigurable childWrapper = null;
  443. public NestedElementHandler(DocumentHandler parentHandler,
  444. Object target,
  445. RuntimeConfigurable parentWrapper) {
  446. super(parentHandler);
  447. if (target instanceof TaskAdapter) {
  448. this.target = ((TaskAdapter) target).getProxy();
  449. } else {
  450. this.target = target;
  451. }
  452. this.parentWrapper = parentWrapper;
  453. }
  454. public void init(String propType, AttributeList attrs) throws SAXParseException {
  455. Class targetClass = target.getClass();
  456. IntrospectionHelper ih =
  457. IntrospectionHelper.getHelper(targetClass);
  458. try {
  459. if (target instanceof UnknownElement) {
  460. child = new UnknownElement(propType.toLowerCase());
  461. ((UnknownElement) target).addChild((UnknownElement) child);
  462. } else {
  463. child = ih.createElement(project, target, propType.toLowerCase());
  464. }
  465. configureId(child, attrs);
  466. if (parentWrapper != null) {
  467. childWrapper = new RuntimeConfigurable(child);
  468. childWrapper.setAttributes(attrs);
  469. parentWrapper.addChild(childWrapper);
  470. } else {
  471. configure(child, attrs, project);
  472. }
  473. } catch (BuildException exc) {
  474. throw new SAXParseException(exc.getMessage(), locator, exc);
  475. }
  476. }
  477. public void characters(char[] buf, int start, int end) throws SAXParseException {
  478. if (parentWrapper == null) {
  479. try {
  480. addText(project, child, buf, start, end);
  481. } catch (BuildException exc) {
  482. throw new SAXParseException(exc.getMessage(), locator, exc);
  483. }
  484. } else {
  485. childWrapper.addText(buf, start, end);
  486. }
  487. }
  488. public void startElement(String name, AttributeList attrs) throws SAXParseException {
  489. new NestedElementHandler(this, child, childWrapper).init(name, attrs);
  490. }
  491. }
  492. /**
  493. * Handler for all data types at global level.
  494. */
  495. private class DataTypeHandler extends AbstractHandler {
  496. private Target target;
  497. private Object element;
  498. private RuntimeConfigurable wrapper = null;
  499. public DataTypeHandler(DocumentHandler parentHandler) {
  500. this(parentHandler, null);
  501. }
  502. public DataTypeHandler(DocumentHandler parentHandler, Target target) {
  503. super(parentHandler);
  504. this.target = target;
  505. }
  506. public void init(String propType, AttributeList attrs) throws SAXParseException {
  507. try {
  508. element = project.createDataType(propType);
  509. if (element == null) {
  510. throw new BuildException("Unknown data type "+propType);
  511. }
  512. configureId(element, attrs);
  513. if (target != null) {
  514. wrapper = new RuntimeConfigurable(element);
  515. wrapper.setAttributes(attrs);
  516. target.addDataType(wrapper);
  517. } else {
  518. configure(element, attrs, project);
  519. }
  520. } catch (BuildException exc) {
  521. throw new SAXParseException(exc.getMessage(), locator, exc);
  522. }
  523. }
  524. public void characters(char[] buf, int start, int end) throws SAXParseException {
  525. try {
  526. addText(project, element, buf, start, end);
  527. } catch (BuildException exc) {
  528. throw new SAXParseException(exc.getMessage(), locator, exc);
  529. }
  530. }
  531. public void startElement(String name, AttributeList attrs) throws SAXParseException {
  532. new NestedElementHandler(this, element, wrapper).init(name, attrs);
  533. }
  534. }
  535. public static void configure(Object target, AttributeList attrs,
  536. Project project) throws BuildException {
  537. if( target instanceof TaskAdapter )
  538. target=((TaskAdapter)target).getProxy();
  539. IntrospectionHelper ih =
  540. IntrospectionHelper.getHelper(target.getClass());
  541. project.addBuildListener(ih);
  542. for (int i = 0; i < attrs.getLength(); i++) {
  543. // reflect these into the target
  544. String value=replaceProperties(project, attrs.getValue(i),
  545. project.getProperties() );
  546. try {
  547. ih.setAttribute(project, target,
  548. attrs.getName(i).toLowerCase(), value);
  549. } catch (BuildException be) {
  550. // id attribute must be set externally
  551. if (!attrs.getName(i).equals("id")) {
  552. throw be;
  553. }
  554. }
  555. }
  556. }
  557. /**
  558. * Adds the content of #PCDATA sections to an element.
  559. */
  560. public static void addText(Project project, Object target, char[] buf, int start, int end)
  561. throws BuildException {
  562. addText(project, target, new String(buf, start, end));
  563. }
  564. /**
  565. * Adds the content of #PCDATA sections to an element.
  566. */
  567. public static void addText(Project project, Object target, String text)
  568. throws BuildException {
  569. if (text == null || text.trim().length() == 0) {
  570. return;
  571. }
  572. if(target instanceof TaskAdapter)
  573. target = ((TaskAdapter) target).getProxy();
  574. IntrospectionHelper.getHelper(target.getClass()).addText(project, target, text);
  575. }
  576. /** Replace ${NAME} with the property value
  577. */
  578. public static String replaceProperties(Project project, String value, Hashtable keys )
  579. throws BuildException
  580. {
  581. // XXX use Map instead of proj, it's too heavy
  582. // XXX need to replace this code with something better.
  583. StringBuffer sb=new StringBuffer();
  584. int i=0;
  585. int prev=0;
  586. // assert value!=nil
  587. int pos;
  588. while( (pos=value.indexOf( "$", prev )) >= 0 ) {
  589. if(pos>0) {
  590. sb.append( value.substring( prev, pos ) );
  591. }
  592. if( pos == (value.length() - 1)) {
  593. sb.append('$');
  594. prev = pos + 1;
  595. }
  596. else if (value.charAt( pos + 1 ) != '{' ) {
  597. sb.append( value.charAt( pos + 1 ) );
  598. prev=pos+2; // XXX
  599. } else {
  600. int endName=value.indexOf( '}', pos );
  601. if( endName < 0 ) {
  602. throw new BuildException("Syntax error in prop: " +
  603. value );
  604. }
  605. String n=value.substring( pos+2, endName );
  606. if (!keys.containsKey(n)) {
  607. project.log("Property ${" + n + "} has not been set", Project.MSG_VERBOSE);
  608. }
  609. String v = (keys.containsKey(n)) ? (String) keys.get(n) : "${"+n+"}";
  610. //System.out.println("N: " + n + " " + " V:" + v);
  611. sb.append( v );
  612. prev=endName+1;
  613. }
  614. }
  615. if( prev < value.length() ) sb.append( value.substring( prev ) );
  616. // System.out.println("After replace: " + sb.toString());
  617. // System.out.println("Before replace: " + value);
  618. return sb.toString();
  619. }
  620. private static SAXParserFactory getParserFactory() {
  621. if (parserFactory == null) {
  622. parserFactory = SAXParserFactory.newInstance();
  623. }
  624. return parserFactory;
  625. }
  626. /**
  627. * Scan AttributeList for the id attribute and maybe add a
  628. * reference to project.
  629. *
  630. * <p>Moved out of {@link #configure configure} to make it happen
  631. * at parser time.</p>
  632. */
  633. private void configureId(Object target, AttributeList attr) {
  634. String id = attr.getValue("id");
  635. if (id != null) {
  636. project.addReference(id, target);
  637. }
  638. }
  639. }