Example:
<root-tag myattr="true">
<inner-tag someattr="val">Text</inner-tag>
<a2><a3><a4>false</a4></a3></a2>
<x>x1</x>
<x>x2</x>
</root-tag>
this generates the following properties:
root-tag(myattr)=true root-tag.inner-tag=Text root-tag.inner-tag(someattr)=val root-tag.a2.a3.a4=false root-tag.x=x1,x2
The collapseAttributes property of this task can be set to true (the default is false) which will instead result in the following properties (note the difference in names of properties corresponding to XML attributes):
root-tag.myattr=true root-tag.inner-tag=Text root-tag.inner-tag.someattr=val root-tag.a2.a3.a4=false root-tag.x=x1,x2
Optionally, to more closely mirror the abilities of the Property task, a selected set of attributes can be treated specially. To enable this behavior, the "semanticAttributes" property of this task must be set to true (it defaults to false). If this attribute is specified, the following attributes take on special meaning (setting this to true implicitly sets collapseAttributes to true as well):
For example, with keepRoot = false, the following properties file:
<root-tag>
<build>
<build folder="build">
<classes id="build.classes" location="${build.folder}/classes"/>
<reference refid="build.classes"/>
</build>
<compile>
<classpath pathid="compile.classpath">
<pathelement location="${build.classes}"/>
</classpath>
</compile>
<run-time>
<jars>*.jar</jars>
<classpath pathid="run-time.classpath">
<path refid="compile.classpath"/>
<pathelement path="${run-time.jars}"/>
</classpath>
</run-time>
</root-tag>
is equivalent to the following entries in a build file:
<property name="build" location="build"/>
<property name="build.classes" location="${build.location}/classes"/>
<property name="build.reference" refid="build.classes"/>
<property name="run-time.jars" value="*.jar/>
<classpath id="compile.classpath">
<pathelement location="${build.classes}"/>
</classpath>
<classpath id="run-time.classpath">
<path refid="compile.classpath"/>
<pathelement path="${run-time.jars}"/>
</classpath>
This task requires the following attributes:
This task supports the following attributes:
| Modifier and Type | Field and Description |
|---|---|
| private Map | |
| private static final String[] | |
| private boolean | |
| private String | |
| private static final FileUtils | |
| private static final String | |
| private boolean | |
| private boolean | |
| private static final String | |
| private static final String | |
| private static final String | |
| private String | |
| private static final String | |
| private File | |
| private boolean | |
| private Resource | |
| private boolean | |
| private static final String | |
| private XMLCatalog |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addConfigured(ResourceCollection
the resource to pack as a single element Resource collection. a)Set the source resource. |
| public void | addConfiguredXMLCatalog(XMLCatalog
the XMLCatalog to use catalog)add an XMLCatalog as a nested element; optional. |
| private void | addNodeRecursively(Node node, String prefix, Object container)
Iterate through all nodes in the tree. |
| pack-priv void | |
| private void | addProperty(String name, String value, String id)
Actually add the given property/value to the project after writing a log message. |
| public void | |
| private String | |
| private String | |
| protected boolean | |
| public String | |
| protected EntityResolver | |
| protected File | |
| protected boolean | |
| protected boolean | |
| protected boolean | |
| protected String | |
| protected Resource | |
| protected File | |
| protected boolean | |
| protected boolean | |
| public void | |
| private static boolean | isSemanticAttribute(String attributeName)
Return whether the provided attribute name is recognized or not. |
| public Object | Returns: the Object created by this node. Generally, this is either a String if this node resulted in setting an attribute, or a Path.the XML Node to parse node, String A string to prepend to any properties that get
added by this node. prefix, Object Optionally, an object that a parent node
generated that this node might belong to. For example, this
node could be within a node that generated a Path. container)Process the given node, adding any required attributes from this child node alone -- but not processing any children. |
| private File | resolveFile(String fileName)
Let project resolve the file - or do it ourselves if rootDirectory has been set. |
| public void | setCollapseAttributes(boolean
if true treat attributes as nested elements collapseAttributes)flag to treat attributes as nested elements; optional, default false |
| public void | |
| public void | |
| public void | setIncludeSemanticAttribute(boolean
if true include the semantic attribute
name. includeSemanticAttribute)Include the semantic attribute name as part of the property name. |
| public void | setKeeproot(boolean
if true (default), include the xml root tag keepRoot)flag to include the xml root tag as a first value in the property name; optional, default is true |
| public void | |
| public void | setRootDirectory(File
the directory. rootDirectory)The directory to use for resolving file references. |
| public void | setSemanticAttributes(boolean
if true enable the special handling. semanticAttributes)Attribute to enable special handling of attributes - see ant manual. |
| public void | |
| public void | setValidate(boolean
if true validate the XML file, default false validate)flag to validate the XML file; optional, default false |
| protected boolean | Returns: true for this task.Whether this task can deal with non-file resources. |
| addedAttributes | back to summary |
|---|---|
| private Map<String, String> addedAttributes | |
| ATTRIBUTES | back to summary |
|---|---|
| private static final String[] ATTRIBUTES | |
| collapseAttributes | back to summary |
|---|---|
| private boolean collapseAttributes | |
| delimiter | back to summary |
|---|---|
| private String delimiter | |
| FILE_UTILS | back to summary |
|---|---|
| private static final FileUtils FILE_UTILS | |
| ID | back to summary |
|---|---|
| private static final String ID | |
| includeSemanticAttribute | back to summary |
|---|---|
| private boolean includeSemanticAttribute | |
| keepRoot | back to summary |
|---|---|
| private boolean keepRoot | |
| LOCATION | back to summary |
|---|---|
| private static final String LOCATION | |
| PATH | back to summary |
|---|---|
| private static final String PATH | |
| PATHID | back to summary |
|---|---|
| private static final String PATHID | |
| prefix | back to summary |
|---|---|
| private String prefix | |
| REF_ID | back to summary |
|---|---|
| private static final String REF_ID | |
| rootDirectory | back to summary |
|---|---|
| private File rootDirectory | |
| semanticAttributes | back to summary |
|---|---|
| private boolean semanticAttributes | |
| src | back to summary |
|---|---|
| private Resource src | |
| validate | back to summary |
|---|---|
| private boolean validate | |
| VALUE | back to summary |
|---|---|
| private static final String VALUE | |
| xmlCatalog | back to summary |
|---|---|
| private XMLCatalog xmlCatalog | |
| XmlProperty | back to summary |
|---|---|
| public XmlProperty() | |
| addConfigured | back to summary |
|---|---|
| public void addConfigured(ResourceCollection a) Set the source resource.
| |
| addConfiguredXMLCatalog | back to summary |
|---|---|
| public void addConfiguredXMLCatalog(XMLCatalog catalog) add an XMLCatalog as a nested element; optional.
| |
| addNodeRecursively | back to summary |
|---|---|
| private void addNodeRecursively(Node node, String prefix, Object container) Iterate through all nodes in the tree. | |
| addNodeRecursively | back to summary |
|---|---|
| pack-priv void addNodeRecursively(Node node, String prefix) | |
| addProperty | back to summary |
|---|---|
| private void addProperty(String name, String value, String id) Actually add the given property/value to the project after writing a log message. | |
| execute | back to summary |
|---|---|
| public void execute() throws BuildException Overrides org. Run the task.
| |
| getAttributeName | back to summary |
|---|---|
| private String getAttributeName(Node attributeNode) Return a reasonable attribute name for the given node. If we are using semantic attributes or collapsing attributes, the returned name is ".nodename". Otherwise, we return "(nodename)". This is long-standing (and default) <xmlproperty> behavior. | |
| getAttributeValue | back to summary |
|---|---|
| private String getAttributeValue(Node attributeNode) Return the value for the given attribute. If we are not using semantic attributes, its just the literal string value of the attribute. If we are using semantic attributes, then first dependent properties are resolved (i.e., ${foo} is resolved based on the foo property value), and then an appropriate data type is used. In particular, location-based properties are resolved to absolute file names. Also for refid values, look up the referenced object from the project. | |
| getCollapseAttributes | back to summary |
|---|---|
protected boolean getCollapseAttributes()
| |
| getDelimiter | back to summary |
|---|---|
| public String getDelimiter() Get the current delimiter.
| |
| getEntityResolver | back to summary |
|---|---|
protected EntityResolver getEntityResolver()
| |
| getFile | back to summary |
|---|---|
protected File getFile()
| |
| getIncludeSemanticAttribute | back to summary |
|---|---|
protected boolean getIncludeSemanticAttribute()
| |
| getIncludeSementicAttribute | back to summary |
|---|---|
| protected boolean getIncludeSementicAttribute()
Deprecated
| |
| getKeeproot | back to summary |
|---|---|
protected boolean getKeeproot()
| |
| getPrefix | back to summary |
|---|---|
protected String getPrefix()
| |
| getResource | back to summary |
|---|---|
protected Resource getResource()
| |
| getRootDirectory | back to summary |
|---|---|
protected File getRootDirectory()
| |
| getSemanticAttributes | back to summary |
|---|---|
protected boolean getSemanticAttributes()
| |
| getValidate | back to summary |
|---|---|
protected boolean getValidate()
| |
| init | back to summary |
|---|---|
| public void init() Overrides org. Initializes the task.
| |
| isSemanticAttribute | back to summary |
|---|---|
| private static boolean isSemanticAttribute(String attributeName) Return whether the provided attribute name is recognized or not. | |
| processNode | back to summary |
|---|---|
| public Object processNode(Node node, String prefix, Object container) Process the given node, adding any required attributes from this child node alone -- but not processing any children.
| |
| resolveFile | back to summary |
|---|---|
| private File resolveFile(String fileName) Let project resolve the file - or do it ourselves if rootDirectory has been set. | |
| setCollapseAttributes | back to summary |
|---|---|
| public void setCollapseAttributes(boolean collapseAttributes) flag to treat attributes as nested elements; optional, default false
| |
| setDelimiter | back to summary |
|---|---|
| public void setDelimiter(String delimiter) Sets a new delimiter.
| |
| setFile | back to summary |
|---|---|
| public void setFile(File src) The XML file to parse; required.
| |
| setIncludeSemanticAttribute | back to summary |
|---|---|
| public void setIncludeSemanticAttribute(boolean includeSemanticAttribute) Include the semantic attribute name as part of the property name. Ignored if semanticAttributes is not set to true.
| |
| setKeeproot | back to summary |
|---|---|
| public void setKeeproot(boolean keepRoot) flag to include the xml root tag as a first value in the property name; optional, default is true
| |
| setPrefix | back to summary |
|---|---|
| public void setPrefix(String prefix) the prefix to prepend to each property
| |
| setRootDirectory | back to summary |
|---|---|
| public void setRootDirectory(File rootDirectory) The directory to use for resolving file references. Ignored if semanticAttributes is not set to true.
| |
| setSemanticAttributes | back to summary |
|---|---|
| public void setSemanticAttributes(boolean semanticAttributes) Attribute to enable special handling of attributes - see ant manual.
| |
| setSrcResource | back to summary |
|---|---|
| public void setSrcResource(Resource src) The resource to pack; required.
| |
| setValidate | back to summary |
|---|---|
| public void setValidate(boolean validate) flag to validate the XML file; optional, default false
| |
| supportsNonFileResources | back to summary |
|---|---|
| protected boolean supportsNonFileResources() Whether this task can deal with non-file resources. This implementation returns true only if this task is <xmlproperty>. Any subclass of this class that also wants to support non-file resources needs to override this method. We need to do so for backwards compatibility reasons since we can't expect subclasses to support resources.
| |