FileDocCategorySizeDatePackage
ParserSupports.javaAPI DocApache Ant 1.704801Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs.condition

ParserSupports

public class ParserSupports extends org.apache.tools.ant.ProjectComponent implements Condition
Test for the XML parser supporting a particular feature
since
Ant 1.7

Fields Summary
private String
feature
private String
property
private String
value
public static final String
ERROR_BOTH_ATTRIBUTES
error - combined attributes not allowed
public static final String
FEATURE
feature
public static final String
PROPERTY
property
public static final String
NOT_RECOGNIZED
error - not recognized
public static final String
NOT_SUPPORTED
error - not supported
public static final String
ERROR_NO_ATTRIBUTES
error - missing attribute
public static final String
ERROR_NO_VALUE
error - no value
Constructors Summary
Methods Summary
public booleaneval()
{@inheritDoc}.

        if (feature != null && property != null) {
            throw new BuildException(ERROR_BOTH_ATTRIBUTES);
        }
        if (feature == null && property == null) {
            throw new BuildException(ERROR_NO_ATTRIBUTES);
        }
        //pick a value that is good for everything
        if (feature != null) {
            return evalFeature();
        }
        if (value == null) {
            throw new BuildException(ERROR_NO_VALUE);
        }
        return evalProperty();
    
public booleanevalFeature()
Set a feature

return
true if the feature could be set

        XMLReader reader = getReader();
        if (value == null) {
            value = "true";
        }
        boolean v = Project.toBoolean(value);
        try {
            reader.setFeature(feature, v);
        } catch (SAXNotRecognizedException e) {
            log(FEATURE + NOT_RECOGNIZED + feature, Project.MSG_VERBOSE);
            return false;
        } catch (SAXNotSupportedException e) {
            log(FEATURE + NOT_SUPPORTED + feature, Project.MSG_VERBOSE);
            return false;
        }
        return true;
    
public booleanevalProperty()
Set a property

return
true if the feature could be set

        XMLReader reader = getReader();
        try {
            reader.setProperty(property, value);
        } catch (SAXNotRecognizedException e) {
            log(PROPERTY + NOT_RECOGNIZED + property, Project.MSG_VERBOSE);
            return false;
        } catch (SAXNotSupportedException e) {
            log(PROPERTY + NOT_SUPPORTED + property, Project.MSG_VERBOSE);
            return false;
        }
        return true;
    
private org.xml.sax.XMLReadergetReader()
Get our reader

return
a reader

        JAXPUtils.getParser();
        return JAXPUtils.getXMLReader();
    
public voidsetFeature(java.lang.String feature)
Feature to probe for.

param
feature the feature to probe for.


                    
        
        this.feature = feature;
    
public voidsetProperty(java.lang.String property)
Property to probe for

param
property the property to probe for.

        this.property = property;
    
public voidsetValue(java.lang.String value)
Optional value to set. Converted to a boolean value when setting a property

param
value the value to set.

        this.value = value;