FileDocCategorySizeDatePackage
Tokens.javaAPI DocApache Ant 1.704354Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.types.resources

Tokens

public class Tokens extends BaseResourceCollectionWrapper
ResourceCollection consisting of StringResources gathered from tokenizing another ResourceCollection with a Tokenizer implementation.
since
Ant 1.7

Fields Summary
private org.apache.tools.ant.util.Tokenizer
tokenizer
private String
encoding
Constructors Summary
Methods Summary
public synchronized voidadd(org.apache.tools.ant.util.Tokenizer tokenizer)
Add the nested Tokenizer to this Tokens ResourceCollection. A LineTokenizer will be used by default.

param
tokenizer the tokenizer to add.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        if (this.tokenizer != null) {
            throw new BuildException("Only one nested tokenizer allowed.");
        }
        this.tokenizer = tokenizer;
    
protected synchronized voiddieOnCircularReference(java.util.Stack stk, org.apache.tools.ant.Project p)
Overrides the BaseResourceCollectionContainer version to check the nested Tokenizer.

param
stk the stack of data types to use (recursively).
param
p the project to use to dereference the references.
throws
BuildException on error.

        if (isChecked()) {
            return;
        }
        if (isReference()) {
            super.dieOnCircularReference(stk, p);
        } else {
            if (tokenizer instanceof DataType) {
                stk.push(tokenizer);
                invokeCircularReferenceCheck((DataType) tokenizer, stk, p);
            }
            setChecked(true);
        }
    
protected synchronized java.util.CollectiongetCollection()
Sort the contained elements.

return
a Collection of Resources.

        ResourceCollection rc = getResourceCollection();
        if (rc.size() == 0) {
            return Collections.EMPTY_SET;
        }
        if (tokenizer == null) {
            tokenizer = new LineTokenizer();
        }
        ConcatResourceInputStream cat = new ConcatResourceInputStream(rc);
        cat.setManagingComponent(this);

        InputStreamReader rdr = null;
        if (encoding == null) {
            rdr = new InputStreamReader(cat);
        } else {
            try {
                rdr = new InputStreamReader(cat, encoding);
            } catch (UnsupportedEncodingException e) {
                throw new BuildException(e);
            }
        }
        ArrayList result = new ArrayList();
        try {
            for (String s = tokenizer.getToken(rdr); s != null; s = tokenizer.getToken(rdr)) {
                result.add(new StringResource(s));
            }
        } catch (IOException e) {
            throw new BuildException("Error reading tokens", e);
        }
        return result;
    
public synchronized voidsetEncoding(java.lang.String encoding)
Set the encoding used to create the tokens.

param
encoding the encoding to use.

        this.encoding = encoding;