Browse Source

add xmlcatalog nested element to the xmlproperty task

PR: 27053
Obtained from: David Crossley and Dave Brondsema


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276840 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 20 years ago
parent
commit
1ddab2c141
8 changed files with 99 additions and 5 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +2
    -0
      WHATSNEW
  3. +6
    -1
      docs/manual/CoreTasks/xmlproperty.html
  4. +3
    -0
      src/etc/testcases/taskdefs/skinconfig.dtd
  5. +10
    -0
      src/etc/testcases/taskdefs/xmlproperty.xml
  6. +6
    -0
      src/etc/testcases/taskdefs/xmlproperty_needscat.xml
  7. +66
    -4
      src/main/org/apache/tools/ant/taskdefs/XmlProperty.java
  8. +5
    -0
      src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java

+ 1
- 0
CONTRIBUTORS View File

@@ -39,6 +39,7 @@ Danno Ferrin
Davanum Srinivas
Dave Brondsema
David A. Herman
David Crossley
David Kavanagh
David Maclean
David Rees


+ 2
- 0
WHATSNEW View File

@@ -69,6 +69,8 @@ Other changes:
* Allow file attribute of <move> to rename a directory.
Bugzilla Report 22863.

* Add xmlcatalog nested element to XmlProperty. Bugzilla report 27053.

Fixed bugs:
-----------



+ 6
- 1
docs/manual/CoreTasks/xmlproperty.html View File

@@ -131,6 +131,11 @@ is roughly equivalent to the following fragments in a build.xml file:
</tr>
</table>

<h3><a name="nested">Nested Elements</a></h3>
<h4>xmlcatalog</h4>
<p>The <a href="../CoreTypes/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a>
element is used to perform entity resolution.</p>

<a name="examples">
<h3>Examples</h3>
</a>
@@ -257,4 +262,4 @@ is equivalent to the following entries in a build file:
Reserved.</p>

</body>
</html>
</html>

+ 3
- 0
src/etc/testcases/taskdefs/skinconfig.dtd View File

@@ -0,0 +1,3 @@
<!ELEMENT skinconfig (foo, bar?)>
<!ELEMENT foo (#PCDATA)>
<!ELEMENT bar (#PCDATA)>

+ 10
- 0
src/etc/testcases/taskdefs/xmlproperty.xml View File

@@ -7,4 +7,14 @@
<target name="testdtd">
<xmlproperty file="xmlproperty_withdtd.xml"/>
</target>

<target name="testneedscat">
<xmlproperty file="xmlproperty_needscat.xml">
<xmlcatalog>
<dtd publicId="-//FOO//DTD Skin Configuration V0.1//EN"
location="skinconfig.dtd"/>
</xmlcatalog>
</xmlproperty>
</target>

</project>

+ 6
- 0
src/etc/testcases/taskdefs/xmlproperty_needscat.xml View File

@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<!DOCTYPE skinconfig PUBLIC "-//FOO//DTD Skin Configuration V0.1//EN" "http://example-no-dtd.com/dtd/skinconfig.dtd">
<skinconfig>
<foo>true</foo>
<bar>false</bar>
</skinconfig>

+ 66
- 4
src/main/org/apache/tools/ant/taskdefs/XmlProperty.java View File

@@ -21,10 +21,12 @@ import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.XMLCatalog;
import org.apache.tools.ant.util.FileUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -32,6 +34,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.EntityResolver;

/**
* Loads property values from a valid XML file, generating the
@@ -178,6 +181,7 @@ public class XmlProperty extends org.apache.tools.ant.Task {
private File rootDirectory = null;
private FileUtils fileUtils = FileUtils.newFileUtils();
private Hashtable addedAttributes = new Hashtable();
private XMLCatalog xmlCatalog = new XMLCatalog();

private static final String ID = "id";
private static final String REF_ID = "refid";
@@ -202,6 +206,15 @@ public class XmlProperty extends org.apache.tools.ant.Task {

public void init() {
super.init();
xmlCatalog.setProject(getProject());
}


/**
* @return the xmlCatalog as the entityresolver.
*/
protected EntityResolver getEntityResolver() {
return xmlCatalog;
}

/**
@@ -226,7 +239,9 @@ public class XmlProperty extends org.apache.tools.ant.Task {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(validate);
factory.setNamespaceAware(false);
Document document = factory.newDocumentBuilder().parse(src);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(getEntityResolver());
Document document = builder.parse(src);
Element topElement = document.getDocumentElement();

// Keep a hashtable of attributes added by this task.
@@ -571,48 +586,95 @@ public class XmlProperty extends org.apache.tools.ant.Task {
this.collapseAttributes = collapseAttributes;
}

public void setSemanticAttributes (boolean semanticAttributes) {
/**
* Attribute to enable special handling of attributes - see ant manual.
* @param semanticAttributes if true enable the special handling.
*/
public void setSemanticAttributes(boolean semanticAttributes) {
this.semanticAttributes = semanticAttributes;
}

public void setRootDirectory (File rootDirectory) {
/**
* The directory to use for resolving file references.
* Ignored if semanticAttributes is not set to true.
* @param rootDirectory the directory.
*/
public void setRootDirectory(File rootDirectory) {
this.rootDirectory = rootDirectory;
}

public void setIncludeSemanticAttribute (boolean includeSemanticAttribute) {
/**
* Include the semantic attribute name as part of the property name.
* Ignored if semanticAttributes is not set to true.
* @param includeSemanticAttribute if true include the sematic attribute
* name.
*/
public void setIncludeSemanticAttribute(boolean includeSemanticAttribute) {
this.includeSemanticAttribute = includeSemanticAttribute;
}

/**
* add an XMLCatalog as a nested element; optional.
* @param catalog the XMLCatalog to use
*/
public void addConfiguredXMLCatalog(XMLCatalog catalog) {
xmlCatalog.addConfiguredXMLCatalog(catalog);
}

/* Expose members for extensibility */

/**
* @return the file attribute.
*/
protected File getFile () {
return this.src;
}

/**
* @return the prefix attribute.
*/
protected String getPrefix () {
return this.prefix;
}

/**
* @return the keeproot attribute.
*/
protected boolean getKeeproot () {
return this.keepRoot;
}

/**
* @return the validate attribute.
*/
protected boolean getValidate () {
return this.validate;
}

/**
* @return the collapse attributes attribute.
*/
protected boolean getCollapseAttributes () {
return this.collapseAttributes;
}

/**
* @return the semantic attributes attribute.
*/
protected boolean getSemanticAttributes () {
return this.semanticAttributes;
}

/**
* @return the root directory attribute.
*/
protected File getRootDirectory () {
return this.rootDirectory;
}

/**
* @return the include semantic attribute.
*/
protected boolean getIncludeSementicAttribute () {
return this.includeSemanticAttribute;
}


+ 5
- 0
src/testcases/org/apache/tools/ant/taskdefs/XmlPropertyTest.java View File

@@ -104,6 +104,11 @@ public class XmlPropertyTest extends BuildFileTest {
doTest("testSemanticInclude", false, false, true, false, true);
}

public void testNeedsCatalog() {
executeTarget("testneedscat");
assertEquals("true", getProject().getProperty("skinconfig.foo"));
}

/**
* Actually run a test, finding all input files (and corresponding
* goldfile)


Loading…
Cancel
Save