Index: Property.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
retrieving revision 1.48
diff -c -r1.48 Property.java
*** Property.java	15 Apr 2002 13:36:17 -0000	1.48
--- Property.java	6 May 2002 19:19:07 -0000
***************
*** 68,73 ****
--- 68,75 ----
  import java.util.Properties;
  import java.util.Vector;
  import java.util.Enumeration;
+ import org.xml.sax.*;
+ import org.xml.sax.helpers.*;
  
  /**
   * Will set a Project property. Used to be a hack in ProjectHelper
***************
*** 83,88 ****
--- 85,91 ----
      protected String name;
      protected String value;
      protected File file;
+     protected File xmlFile;
      protected String resource;
      protected Path classpath;
      protected String env;
***************
*** 129,135 ****
      public File getFile() {
          return file;
      }
!     
      public void setPrefix(String prefix) {
          this.prefix = prefix;
          if (!prefix.endsWith(".")) {
--- 132,146 ----
      public File getFile() {
          return file;
      }
! 
!     public void setXmlFile(File xmlFile) {
!         this.xmlFile=xmlFile;
!     }
! 
!     public File getXmlFile() {
!         return xmlFile;
!     }
! 
      public void setPrefix(String prefix) {
          this.prefix = prefix;
          if (!prefix.endsWith(".")) {
***************
*** 201,214 ****
                                           location);
              }
          } else {
!             if (file == null && resource == null && env == null) {
!                 throw new BuildException("You must specify file, resource or "
                                           + "environment when not using the "
                                           + "name attribute", location);
              }
          }
!         
!         if (file == null && resource == null && prefix != null) {
              throw new BuildException("Prefix is only valid when loading from "
                                       + "a file or resource", location);
          }
--- 212,225 ----
                                           location);
              }
          } else {
!             if (file == null && xmlFile == null && resource == null && env == null) {
!                 throw new BuildException("You must specify file, xml file, resource or "
                                           + "environment when not using the "
                                           + "name attribute", location);
              }
          }
! 
!         if (file == null && xmlFile == null && resource == null && prefix != null) {
              throw new BuildException("Prefix is only valid when loading from "
                                       + "a file or resource", location);
          }
***************
*** 221,226 ****
--- 232,241 ----
              loadFile(file);
          }
  
+         if (xmlFile != null) {
+             loadXmlFile(xmlFile);
+         }
+ 
          if (resource != null) {
              loadResource(resource);
          }
***************
*** 260,265 ****
--- 275,333 ----
          }
      }
  
+     protected void loadXmlFile(File file) throws BuildException {
+         final Properties props = new Properties();
+         log("Loading " + file.getAbsolutePath(), Project.MSG_VERBOSE);
+         try {
+             if (file.exists()) {
+                 XMLReader parser = XMLReaderFactory.createXMLReader();
+                 parser.setContentHandler(
+                     new DefaultHandler() {
+                         private String currPath = "";
+                         private boolean hadText = false;
+                         public void startElement (String uri, String localName, String qName, Attributes attributes) {
+                             if (currPath.length()>0) currPath=currPath+"/";
+                             currPath=currPath+localName;
+                             for (int i=0, l=attributes.getLength(); i<l; i++) {
+                                 String propName = currPath + '.' + attributes.getLocalName(i);
+                                 if (!props.containsKey(propName)) {
+                                     props.setProperty(propName, attributes.getValue(i));
+                                 }
+                             }
+                             hadText = false;
+                         }
+                         public void characters (char ch[], int start, int length) {
+                           String propName = currPath + "#TEXT";
+                           String value = new String(ch, start, length);
+                           if (hadText) props.setProperty(propName, props.getProperty(propName) + value);
+                           else if (!props.containsKey(propName)) {
+                               props.setProperty(propName, value);
+                               hadText = true;
+                           }
+                         }
+                         public void endElement (String uri, String localName, String qName) {
+                             int currLength = currPath.length();
+                             int nameLength = localName.length();
+                             currPath = currPath.substring(0, currLength - nameLength - (currLength > nameLength ? 1 : 0));
+                             hadText = false;
+                         }
+                     }
+                 );
+                 FileInputStream fis = new FileInputStream(file);
+                 parser.parse(new InputSource(fis));
+                 fis.close();
+                 addProperties(props);
+             } else {
+                 log("Unable to find xml file: " + file.getAbsolutePath(),
+                     Project.MSG_VERBOSE);
+             }
+         } catch (SAXException ex) {
+             throw new BuildException(ex, location);
+         } catch (IOException ex) {
+             throw new BuildException(ex, location);
+         }
+     }
+ 
      protected void loadResource(String name) {
          Properties props = new Properties();
          log("Resource Loading " + name, Project.MSG_VERBOSE);
***************
*** 294,300 ****
                  } catch (IOException e) {}
              }
          }
!         
      }
  
      protected void loadEnvironment(String prefix) {
--- 362,368 ----
                  } catch (IOException e) {}
              }
          }
! 
      }
  
      protected void loadEnvironment(String prefix) {
***************
*** 355,361 ****
              while (!resolved) {
                  Vector fragments = new Vector();
                  Vector propertyRefs = new Vector();
!                 ProjectHelper.parsePropertyString(value, fragments, 
                                                    propertyRefs);
  
                  resolved = true;
--- 423,429 ----
              while (!resolved) {
                  Vector fragments = new Vector();
                  Vector propertyRefs = new Vector();
!                 ProjectHelper.parsePropertyString(value, fragments,
                                                    propertyRefs);
  
                  resolved = true;
***************
*** 368,374 ****
                          if (fragment == null) {
                              String propertyName = (String) j.nextElement();
                              if (propertyName.equals(name)) {
!                                 throw new BuildException("Property " + name 
                                                           + " was circularly "
                                                           + "defined.");
                              }
--- 436,442 ----
                          if (fragment == null) {
                              String propertyName = (String) j.nextElement();
                              if (propertyName.equals(name)) {
!                                 throw new BuildException("Property " + name
                                                           + " was circularly "
                                                           + "defined.");
                              }

