bloritsch    01/10/25 10:49:04

  Modified:    bin/src  st.java
  Log:
  Optimize whitespace
  
  Revision  Changes    Path
  1.6       +126 -83   xml-cocoon2/bin/src/st.java
  
  Index: st.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/bin/src/st.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- st.java   2001/10/25 17:48:14     1.5
  +++ st.java   2001/10/25 17:49:03     1.6
  @@ -5,8 +5,9 @@
    * version 1.1, a copy of which has been included  with this distribution in *
    * the LICENSE file.                                                         *
    *****************************************************************************/
  -import java.io.FileInputStream;
  -import java.io.FileWriter;
  +
  +import java.io.FileInputStream;
  +import java.io.FileWriter;
   import java.io.IOException;
   
   /**
  @@ -33,53 +34,60 @@
    * Pretty printing
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.5 $ $Date: 2001/10/25 17:48:14 $
  + * @version CVS $Revision: 1.6 $ $Date: 2001/10/25 17:49:03 $
    */
   
  -public class st {
  +public class st
  +{
   
  -    public static String load(String filename)
  -    throws IOException {
  +    public static String load( String filename )
  +            throws IOException
  +    {
           FileInputStream fis;
   
  -        fis = new FileInputStream(filename);
  +        fis = new FileInputStream( filename );
           int available;
           byte[] data = null;
           byte[] tempData;
           byte[] copyData;
  -        do {
  +        do
  +        {
               available = 1024;
               tempData = new byte[available];
  -            available = fis.read(tempData, 0, available);
  -            if (available > 0) {
  -                copyData = new byte[(data == null ? 0 : data.length) + available];
  -                if (data != null) {
  -                    System.arraycopy(data, 0, copyData, 0, data.length);
  +            available = fis.read( tempData, 0, available );
  +            if ( available > 0 )
  +            {
  +                copyData = new byte[( data == null ? 0 : data.length ) + available];
  +                if ( data != null )
  +                {
  +                    System.arraycopy( data, 0, copyData, 0, data.length );
                   }
  -                System.arraycopy(tempData, 0, copyData, (data == null ? 0 : 
data.length), available);
  +                System.arraycopy( tempData, 0, copyData, ( data == null ? 0 : 
data.length ), available );
                   data = copyData;
               }
  -        } while (available > 0);
  +        } while ( available > 0 );
           fis.close();
   
  -        return (data != null ? new String(data) : "");
  +        return ( data != null ? new String( data ) : "" );
       }
   
  -    public static void save(String filename, String data)
  -    throws IOException {
  -        FileWriter fw = new FileWriter(filename);
  -        fw.write(data);
  +    public static void save( String filename, String data )
  +            throws IOException
  +    {
  +        FileWriter fw = new FileWriter( filename );
  +        fw.write( data );
           fw.close();
       }
   
  -    public static void main(String[] args) {
  +    public static void main( String[] args )
  +    {
           String inputName;
           String outputName;
           String arg;
           String label = null;
           String mimeType = null;
  -        int    mode = 0;
  -        String arg1=null, arg2=null, arg3=null, arg4=null;
  +        int mode = 0;
  +        String arg1 = null, arg2 = null, arg3 = null, arg4 = null;
   
           boolean clError = false;
   
  @@ -87,110 +95,145 @@
           outputName = null;
           int i;
           i = 0;
  -        while (i < args.length && clError == false) {
  +        while ( i < args.length && clError == false )
  +        {
               arg = args[i];
  -            if (arg.equals("-i") == true) {
  -                if (i + 1 < args.length)
  -                    inputName = args[i+1];
  +            if ( arg.equals( "-i" ) == true )
  +            {
  +                if ( i + 1 < args.length )
  +                    inputName = args[i + 1];
                   else
                       clError = true;
                   i += 2;
  -            } else if (arg.equals("-o") == true) {
  -                if (i + 1 < args.length)
  -                    outputName = args[i+1];
  +            }
  +            else if ( arg.equals( "-o" ) == true )
  +            {
  +                if ( i + 1 < args.length )
  +                    outputName = args[i + 1];
                   else
                       clError = true;
                   i += 2;
  -            } else if (arg.equals("-l") == true) {
  -                if (i + 1 < args.length)
  -                    label = args[i+1];
  +            }
  +            else if ( arg.equals( "-l" ) == true )
  +            {
  +                if ( i + 1 < args.length )
  +                    label = args[i + 1];
                   else
                       clError = true;
                   i += 2;
  -            } else if (arg.equals("-m") == true) {
  -                if (i + 1 < args.length)
  -                    mimeType = args[i+1];
  +            }
  +            else if ( arg.equals( "-m" ) == true )
  +            {
  +                if ( i + 1 < args.length )
  +                    mimeType = args[i + 1];
                   else
                       clError = true;
                   i += 2;
  -            } else if (arg.equals("-a") == true) {
  -                if (i + 3 < args.length && mode == 0) {
  +            }
  +            else if ( arg.equals( "-a" ) == true )
  +            {
  +                if ( i + 3 < args.length && mode == 0 )
  +                {
                       mode = 1; // add
  -                    arg1 = args[i+1];
  -                    arg2 = args[i+2];
  -                    arg3 = args[i+3];
  -                    if (i + 4 < args.length && !args[i+4].startsWith("-")) {
  -                        arg4 = args[i+4];
  +                    arg1 = args[i + 1];
  +                    arg2 = args[i + 2];
  +                    arg3 = args[i + 3];
  +                    if ( i + 4 < args.length && !args[i + 4].startsWith( "-" ) )
  +                    {
  +                        arg4 = args[i + 4];
                           i++;
  -                    } else {
  +                    }
  +                    else
  +                    {
                           arg4 = null;
                       }
                       i += 4;
  -                } else {
  +                }
  +                else
  +                {
                       clError = true;
                   }
  -            } else {
  +            }
  +            else
  +            {
                   clError = true;
               }
           }
  -        if (inputName == null || outputName == null) {
  +        if ( inputName == null || outputName == null )
  +        {
               clError = true;
           }
  -        if (mode == 0) {
  +        if ( mode == 0 )
  +        {
               clError = true;
           }
  -        if (clError == true) {
  -            System.out.println("Usage: st -i inputsitemap -o outputsitemap " +
  -                               "[-l label] [-m mimetype] -a componentcategory" +
  -                               " componentname class 
[optionalconfigurationstring]");
  -        } else {
  -            try {
  -                String data = load(inputName);
  +        if ( clError == true )
  +        {
  +            System.out.println( "Usage: st -i inputsitemap -o outputsitemap " +
  +                                "[-l label] [-m mimetype] -a componentcategory" +
  +                                " componentname class 
[optionalconfigurationstring]" );
  +        }
  +        else
  +        {
  +            try
  +            {
  +                String data = load( inputName );
   
  -                if (mode == 1) {
  +                if ( mode == 1 )
  +                {
                       // add a component
                       // arg1 : category
                       // arg2 : componentname
                       // arg3 : class
                       // arg4 : optional configuration
   
  -                    String searchString = new 
StringBuffer("</map:").append(arg1).append(">").toString();
  -                    int pos = data.indexOf(searchString);
  +                    String searchString = new StringBuffer( "</map:" ).append( arg1 
).append( ">" ).toString();
  +                    int pos = data.indexOf( searchString );
                       int categoryStartPos = data.indexOf(
  -                            new 
StringBuffer("</map:").append(arg1).append(">").toString());
  -                    if (categoryStartPos == -1) categoryStartPos = data.indexOf(
  -                            new StringBuffer("</map:").append(arg1).append(" 
").toString());
  -                    if (categoryStartPos != -1 && categoryStartPos < pos && pos != 
-1) {
  +                            new StringBuffer( "</map:" ).append( arg1 ).append( ">" 
).toString() );
  +                    if ( categoryStartPos == -1 )
  +                        categoryStartPos = data.indexOf(
  +                                new StringBuffer( "</map:" ).append( arg1 ).append( 
" " ).toString() );
  +                    if ( categoryStartPos != -1 && categoryStartPos < pos && pos != 
-1 )
  +                    {
                           // the category exists, now search if a component
                           // with the name already exists
  -                        int componentPos = data.substring(categoryStartPos, 
pos).indexOf(
  -                                new 
StringBuffer("name=\"").append(arg2).append("\"").toString());
  -                        if (componentPos == -1) {
  -                            StringBuffer buffer = new 
StringBuffer(data.substring(0, pos))
  -                             .append("<map:").append(arg1.substring(0, 
arg1.length()-1))
  -                             .append(" name=\"").append(arg2).append("\" 
src=\"").append(arg3).append("\"");
  -                            
  -                            if ( null == mimeType ) {
  -                                buffer.append(" 
mime-type=\"").append(mimeType).append("\"");
  +                        int componentPos = data.substring( categoryStartPos, pos 
).indexOf(
  +                                new StringBuffer( "name=\"" ).append( arg2 
).append( "\"" ).toString() );
  +                        if ( componentPos == -1 )
  +                        {
  +                            StringBuffer buffer = new StringBuffer( data.substring( 
0, pos ) )
  +                                    .append( "<map:" ).append( arg1.substring( 0, 
arg1.length() - 1 ) )
  +                                    .append( " name=\"" ).append( arg2 ).append( 
"\" src=\"" ).append( arg3 ).append( "\"" );
  +
  +                            if ( null == mimeType )
  +                            {
  +                                buffer.append( " mime-type=\"" ).append( mimeType 
).append( "\"" );
  +                            }
  +                            if ( null == label )
  +                            {
  +                                buffer.append( " label=\"" ).append( label 
).append( "\"" );
                               }
  -                            if (null == label) {
  -                                buffer.append(" 
label=\"").append(label).append("\"");
  +                            if ( null == arg4 )
  +                            {
  +                                buffer.append( ">\n" ).append( arg4 ).append( "\n" )
  +                                        .append( "</map:" ).append( arg1.substring( 
0, arg1.length() - 1 ) ).append( ">\n" );
                               }
  -                            if (null == arg4) {
  -                             buffer.append(">\n").append(arg4).append("\n")
  -                                   .append("</map:").append(arg1.substring(0, 
arg1.length()-1)).append(">\n");
  -                            } else {
  -                                buffer.append("/>\n");
  +                            else
  +                            {
  +                                buffer.append( "/>\n" );
                               }
  -                             buffer.append(data.substring(pos)).toString();
  -                             data = buffer.toString();
  +                            buffer.append( data.substring( pos ) ).toString();
  +                            data = buffer.toString();
                           }
                       }
                   }
   
  -                save(outputName, data);
  -            } catch (IOException ioe) {
  -                System.err.println("Exception: " + ioe);
  +                save( outputName, data );
  +            }
  +            catch ( IOException ioe )
  +            {
  +                System.err.println( "Exception: " + ioe );
                   ioe.printStackTrace();
               }
           }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to