From 039e254a64281529e722e07f80a356792eee1fd1 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Thu, 14 Feb 2002 09:35:13 +0000 Subject: [PATCH] Reimplement in a cleaner way later git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271319 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/taskdefs/AntStructure.java | 390 ------------------ .../tools/ant/taskdefs/AntStructure.java | 390 ------------------ 2 files changed, 780 deletions(-) delete mode 100644 proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/AntStructure.java delete mode 100644 proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/AntStructure.java diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/AntStructure.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/AntStructure.java deleted file mode 100644 index d15c8f0d5..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/AntStructure.java +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.util.Enumeration; -import java.util.Hashtable; -import org.apache.myrmidon.api.TaskException; -import org.apache.tools.ant.Task; - -/** - * Creates a partial DTD for Ant from the currently known tasks. - * - * @author Stefan Bodewig - * @version $Revision$ - */ - -public class AntStructure - extends Task -{ - private final String BOOLEAN = "%boolean;"; - private final String TASKS = "%tasks;"; - private final String TYPES = "%types;"; - - private Hashtable visited = new Hashtable(); - - private File output; - - /** - * The output file. - * - * @param output The new Output value - */ - public void setOutput( File output ) - { - this.output = output; - } - - public void execute() - throws TaskException - { - - if( output == null ) - { - throw new TaskException( "output attribute is required" ); - } - - 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/products/jdk/1.2/docs/guide/internat/encoding.doc.html - * - * fallback to platform specific anyway. - */ - out = new PrintWriter( new FileWriter( output ) ); - } - - printHead( out, getProject().getTaskDefinitions().keys(), - getProject().getDataTypeDefinitions().keys() ); - - printTargetDecl( out ); - - Enumeration dataTypes = getProject().getDataTypeDefinitions().keys(); - while( dataTypes.hasMoreElements() ) - { - String typeName = (String)dataTypes.nextElement(); - printElementDecl( out, typeName, - (Class)getProject().getDataTypeDefinitions().get( typeName ) ); - } - - Enumeration tasks = getProject().getTaskDefinitions().keys(); - while( tasks.hasMoreElements() ) - { - String taskName = (String)tasks.nextElement(); - printElementDecl( out, taskName, - (Class)getProject().getTaskDefinitions().get( taskName ) ); - } - - printTail( out ); - - } - catch( IOException ioe ) - { - throw new TaskException( "Error writing " + output.getAbsolutePath(), - ioe ); - } - finally - { - if( out != null ) - { - out.close(); - } - } - } - - /** - * Does this String match the XML-NMTOKEN production? - * - * @param s Description of Parameter - * @return The Nmtoken value - */ - protected boolean isNmtoken( String s ) - { - for( int i = 0; i < s.length(); i++ ) - { - char c = s.charAt( i ); - // XXX - we are ommitting CombiningChar and Extender here - if( !Character.isLetterOrDigit( c ) && - c != '.' && c != '-' && - c != '_' && c != ':' ) - { - return false; - } - } - return true; - } - - /** - * Do the Strings all match the XML-NMTOKEN production?

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

- * - * @param s Description of Parameter - * @return Description of the Returned Value - */ - protected boolean areNmtokens( String[] s ) - { - for( int i = 0; i < s.length; i++ ) - { - if( !isNmtoken( s[ i ] ) ) - { - return false; - } - } - return true; - } - - private void printElementDecl( PrintWriter out, String name, Class element ) - throws TaskException - { - - if( visited.containsKey( name ) ) - { - return; - } - visited.put( name, "" ); - - /* - IntrospectionHelper ih = null; - try - { - ih = IntrospectionHelper.getHelper( element ); - } - catch( Throwable t ) - { - // FIXME: failed to load the class properly. - // should we print a warning here? - return; - } - - StringBuffer sb = new StringBuffer( "" ).append( lSep ); - sb.append( "" ).append( lSep ); - out.println( sb ); - return; - } - - ArrayList v = new ArrayList(); - if( ih.supportsCharacters() ) - { - v.add( "#PCDATA" ); - } - - if( TaskContainer.class.isAssignableFrom( element ) ) - { - v.add( TASKS ); - } - - Iterator enum = ih.getNestedElements(); - while( enum.hasNext() ) - { - v.add( (String)enum.next() ); - } - - if( v.isEmpty() ) - { - sb.append( "EMPTY" ); - } - else - { - sb.append( "(" ); - for( int i = 0; i < v.size(); i++ ) - { - if( i != 0 ) - { - sb.append( " | " ); - } - sb.append( v.get( i ) ); - } - sb.append( ")" ); - if( v.size() > 1 || !v.get( 0 ).equals( "#PCDATA" ) ) - { - sb.append( "*" ); - } - } - sb.append( ">" ); - out.println( sb ); - - sb.setLength( 0 ); - sb.append( "" ).append( lSep ); - out.println( sb ); - - for( int i = 0; i < v.size(); i++ ) - { - String nestedName = (String)v.get( i ); - if( !"#PCDATA".equals( nestedName ) && - !TASKS.equals( nestedName ) && - !TYPES.equals( nestedName ) - ) - { - printElementDecl( out, nestedName, ih.getElementType( nestedName ) ); - } - } - */ - } - - private void printHead( PrintWriter out, Enumeration tasks, - Enumeration types ) - { - out.println( "" ); - out.println( "" ); - out.print( "" ); - out.print( "" ); - - out.println( "" ); - - out.print( "" ); - out.println( "" ); - out.println( "" ); - } - - private void printTail( PrintWriter out ) - { - } - - private void printTargetDecl( PrintWriter out ) - { - out.print( "" ); - out.println( "" ); - - out.println( "" ); - out.println( "" ); - } - -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/AntStructure.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/AntStructure.java deleted file mode 100644 index d15c8f0d5..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/AntStructure.java +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.util.Enumeration; -import java.util.Hashtable; -import org.apache.myrmidon.api.TaskException; -import org.apache.tools.ant.Task; - -/** - * Creates a partial DTD for Ant from the currently known tasks. - * - * @author Stefan Bodewig - * @version $Revision$ - */ - -public class AntStructure - extends Task -{ - private final String BOOLEAN = "%boolean;"; - private final String TASKS = "%tasks;"; - private final String TYPES = "%types;"; - - private Hashtable visited = new Hashtable(); - - private File output; - - /** - * The output file. - * - * @param output The new Output value - */ - public void setOutput( File output ) - { - this.output = output; - } - - public void execute() - throws TaskException - { - - if( output == null ) - { - throw new TaskException( "output attribute is required" ); - } - - 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/products/jdk/1.2/docs/guide/internat/encoding.doc.html - * - * fallback to platform specific anyway. - */ - out = new PrintWriter( new FileWriter( output ) ); - } - - printHead( out, getProject().getTaskDefinitions().keys(), - getProject().getDataTypeDefinitions().keys() ); - - printTargetDecl( out ); - - Enumeration dataTypes = getProject().getDataTypeDefinitions().keys(); - while( dataTypes.hasMoreElements() ) - { - String typeName = (String)dataTypes.nextElement(); - printElementDecl( out, typeName, - (Class)getProject().getDataTypeDefinitions().get( typeName ) ); - } - - Enumeration tasks = getProject().getTaskDefinitions().keys(); - while( tasks.hasMoreElements() ) - { - String taskName = (String)tasks.nextElement(); - printElementDecl( out, taskName, - (Class)getProject().getTaskDefinitions().get( taskName ) ); - } - - printTail( out ); - - } - catch( IOException ioe ) - { - throw new TaskException( "Error writing " + output.getAbsolutePath(), - ioe ); - } - finally - { - if( out != null ) - { - out.close(); - } - } - } - - /** - * Does this String match the XML-NMTOKEN production? - * - * @param s Description of Parameter - * @return The Nmtoken value - */ - protected boolean isNmtoken( String s ) - { - for( int i = 0; i < s.length(); i++ ) - { - char c = s.charAt( i ); - // XXX - we are ommitting CombiningChar and Extender here - if( !Character.isLetterOrDigit( c ) && - c != '.' && c != '-' && - c != '_' && c != ':' ) - { - return false; - } - } - return true; - } - - /** - * Do the Strings all match the XML-NMTOKEN production?

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

- * - * @param s Description of Parameter - * @return Description of the Returned Value - */ - protected boolean areNmtokens( String[] s ) - { - for( int i = 0; i < s.length; i++ ) - { - if( !isNmtoken( s[ i ] ) ) - { - return false; - } - } - return true; - } - - private void printElementDecl( PrintWriter out, String name, Class element ) - throws TaskException - { - - if( visited.containsKey( name ) ) - { - return; - } - visited.put( name, "" ); - - /* - IntrospectionHelper ih = null; - try - { - ih = IntrospectionHelper.getHelper( element ); - } - catch( Throwable t ) - { - // FIXME: failed to load the class properly. - // should we print a warning here? - return; - } - - StringBuffer sb = new StringBuffer( "" ).append( lSep ); - sb.append( "" ).append( lSep ); - out.println( sb ); - return; - } - - ArrayList v = new ArrayList(); - if( ih.supportsCharacters() ) - { - v.add( "#PCDATA" ); - } - - if( TaskContainer.class.isAssignableFrom( element ) ) - { - v.add( TASKS ); - } - - Iterator enum = ih.getNestedElements(); - while( enum.hasNext() ) - { - v.add( (String)enum.next() ); - } - - if( v.isEmpty() ) - { - sb.append( "EMPTY" ); - } - else - { - sb.append( "(" ); - for( int i = 0; i < v.size(); i++ ) - { - if( i != 0 ) - { - sb.append( " | " ); - } - sb.append( v.get( i ) ); - } - sb.append( ")" ); - if( v.size() > 1 || !v.get( 0 ).equals( "#PCDATA" ) ) - { - sb.append( "*" ); - } - } - sb.append( ">" ); - out.println( sb ); - - sb.setLength( 0 ); - sb.append( "" ).append( lSep ); - out.println( sb ); - - for( int i = 0; i < v.size(); i++ ) - { - String nestedName = (String)v.get( i ); - if( !"#PCDATA".equals( nestedName ) && - !TASKS.equals( nestedName ) && - !TYPES.equals( nestedName ) - ) - { - printElementDecl( out, nestedName, ih.getElementType( nestedName ) ); - } - } - */ - } - - private void printHead( PrintWriter out, Enumeration tasks, - Enumeration types ) - { - out.println( "" ); - out.println( "" ); - out.print( "" ); - out.print( "" ); - - out.println( "" ); - - out.print( "" ); - out.println( "" ); - out.println( "" ); - } - - private void printTail( PrintWriter out ) - { - } - - private void printTargetDecl( PrintWriter out ) - { - out.print( "" ); - out.println( "" ); - - out.println( "" ); - out.println( "" ); - } - -}