Browse Source

Actually enable namespace support in ProjectHelper2

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273819 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
21660b7678
2 changed files with 50 additions and 8 deletions
  1. +1
    -1
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  2. +49
    -7
      src/main/org/apache/tools/ant/util/JAXPUtils.java

+ 1
- 1
src/main/org/apache/tools/ant/helper/ProjectHelper2.java View File

@@ -161,7 +161,7 @@ public class ProjectHelper2 extends ProjectHelper {
/**
* SAX 2 style parser used to parse the given file.
*/
context.parser =JAXPUtils.getXMLReader();
context.parser =JAXPUtils.getNamespaceXMLReader();

String uri = fu.toURI(context.buildFile.getAbsolutePath());



+ 49
- 7
src/main/org/apache/tools/ant/util/JAXPUtils.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -90,6 +90,14 @@ public class JAXPUtils {
*/
private static SAXParserFactory parserFactory = null;

/**
* Parser Factory to create Namespace aware parsers.
*
* @since Ant 1.6
*/
private static SAXParserFactory nsParserFactory = null;


/**
* Returns the parser factory to use. Only one parser factory is
* ever created by this method and is then cached for future use.
@@ -98,7 +106,7 @@ public class JAXPUtils {
*
* @since Ant 1.5
*/
public synchronized static SAXParserFactory getParserFactory()
public synchronized static SAXParserFactory getParserFactory()
throws BuildException {

if (parserFactory == null) {
@@ -107,6 +115,24 @@ public class JAXPUtils {
return parserFactory;
}

/**
* Returns the parser factory to use to create namespace aware parsers.
*
* @return a SAXParserFactory to use which supports manufacture of
* namespace aware parsers
*
* @since Ant 1.6
*/
public synchronized static SAXParserFactory getNSParserFactory()
throws BuildException {

if (nsParserFactory == null) {
nsParserFactory = newParserFactory();
nsParserFactory.setNamespaceAware(true);
}
return nsParserFactory;
}

/**
* Returns a new parser factory instance.
*
@@ -118,7 +144,7 @@ public class JAXPUtils {
return SAXParserFactory.newInstance();
} catch (FactoryConfigurationError e) {
throw new BuildException("XML parser factory has not been "
+ "configured correctly: "
+ "configured correctly: "
+ e.getMessage(), e);
}
}
@@ -133,7 +159,7 @@ public class JAXPUtils {
*/
public static Parser getParser() throws BuildException {
try {
return newSAXParser().getParser();
return newSAXParser(getParserFactory()).getParser();
} catch (SAXException e) {
throw convertToBuildException(e);
}
@@ -149,7 +175,22 @@ public class JAXPUtils {
*/
public static XMLReader getXMLReader() throws BuildException {
try {
return newSAXParser().getXMLReader();
return newSAXParser(getParserFactory()).getXMLReader();
} catch (SAXException e) {
throw convertToBuildException(e);
}
}

/**
* Returns a newly created SAX 2 XMLReader, which is namespace aware
*
* @return a SAX 2 XMLReader.
* @see #getParserFactory
* @since Ant 1.6
*/
public static XMLReader getNamespaceXMLReader() throws BuildException {
try {
return newSAXParser(getNSParserFactory()).getXMLReader();
} catch (SAXException e) {
throw convertToBuildException(e);
}
@@ -174,9 +215,10 @@ public class JAXPUtils {
*
* @since Ant 1.5
*/
private static SAXParser newSAXParser() throws BuildException {
private static SAXParser newSAXParser(SAXParserFactory factory)
throws BuildException {
try {
return getParserFactory().newSAXParser();
return factory.newSAXParser();
} catch (ParserConfigurationException e) {
throw new BuildException("Cannot create parser for the given "
+ "configuration: " + e.getMessage(), e);


Loading…
Cancel
Save