FileDocCategorySizeDatePackage
AntStructure.javaAPI DocApache Ant 1.7016759Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs

AntStructure

public class AntStructure extends org.apache.tools.ant.Task
Creates a partial DTD for Ant from the currently known tasks.
since
Ant 1.1
ant.task
category="xml"

Fields Summary
private static final String
LINE_SEP
private File
output
private StructurePrinter
printer
Constructors Summary
Methods Summary
public voidadd(org.apache.tools.ant.taskdefs.AntStructure$StructurePrinter p)
The StructurePrinter to use.

param
p the printer to use.
since
Ant 1.7

        printer = p;
    
protected booleanareNmtokens(java.lang.String[] s)
Do the Strings all match the XML-NMTOKEN production?

Otherwise they are not suitable as an enumerated attribute, for example.

param
s the array of string to test
return
true if all the strings in the array math XML-NMTOKEN

        return DTDPrinter.areNmtokens(s);
    
public voidexecute()
Build the antstructure DTD.

exception
BuildException if the DTD cannot be written.


        if (output == null) {
            throw new BuildException("output attribute is required", getLocation());
        }

        PrintWriter out = null;
        try {
            try {
                out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), "UTF8"));
            } catch (UnsupportedEncodingException ue) {
                /*
                 * Plain impossible with UTF8, see
                 * http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html
                 *
                 * fallback to platform specific anyway.
                 */
                out = new PrintWriter(new FileWriter(output));
            }

            printer.printHead(out, getProject(),
                              getProject().getTaskDefinitions(),
                              getProject().getDataTypeDefinitions());

            printer.printTargetDecl(out);

            Enumeration dataTypes = getProject().getDataTypeDefinitions().keys();
            while (dataTypes.hasMoreElements()) {
                String typeName = (String) dataTypes.nextElement();
                printer.printElementDecl(
                    out, getProject(), typeName,
                    (Class) getProject().getDataTypeDefinitions().get(typeName));
            }

            Enumeration tasks = getProject().getTaskDefinitions().keys();
            while (tasks.hasMoreElements()) {
                String tName = (String) tasks.nextElement();
                printer.printElementDecl(out, getProject(), tName,
                                         (Class) getProject().getTaskDefinitions().get(tName));
            }

            printer.printTail(out);

        } catch (IOException ioe) {
            throw new BuildException("Error writing "
                                     + output.getAbsolutePath(), ioe, getLocation());
        } finally {
            if (out != null) {
                out.close();
            }
        }
    
protected booleanisNmtoken(java.lang.String s)
Does this String match the XML-NMTOKEN production?

param
s the string to test
return
true if the string matches the XML-NMTOKEN

        return DTDPrinter.isNmtoken(s);
    
public voidsetOutput(java.io.File output)
The output file.

param
output the output file


                 
        
        this.output = output;