directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r475809 - in /directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/ld...
Date Thu, 16 Nov 2006 16:46:38 GMT
Author: pamarcelot
Date: Thu Nov 16 08:46:37 2006
New Revision: 475809

URL: http://svn.apache.org/viewvc?view=rev&rev=475809
Log:
Importing project ldapstudio-dsml-command

Added:
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/.classpath
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/.project
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/META-INF/
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/META-INF/MANIFEST.MF
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/build.xml
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/ivy.xml
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/log4j.conf
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/java/
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/java/org/
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/java/org/apache/
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/java/org/apache/directory/
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/java/org/apache/directory/ldapstudio/
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/java/org/apache/directory/ldapstudio/dsmlCommand/
    directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/java/org/apache/directory/ldapstudio/dsmlCommand/DsmlCommand.java

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/.classpath
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/.classpath?view=auto&rev=475809
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/.classpath (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/.classpath Thu Nov 16
08:46:37 2006
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="lib" path="lib/commons-cli-1.0.jar"/>
+	<classpathentry kind="lib" path="lib/commons-lang-2.1.jar"/>
+	<classpathentry kind="lib" path="lib/commons-logging-1.1.jar"/>
+	<classpathentry kind="lib" path="lib/commons-collections-3.1.jar"/>
+	<classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
+	<classpathentry kind="lib" path="lib/nlog4j-1.2.25.jar"/>
+	<classpathentry kind="lib" path="lib/xpp3-1.1.3_8.jar"/>
+	<classpathentry kind="lib" path="lib/ldapstudio-dsml-parser-0.1.jar"/>
+	<classpathentry kind="lib" path="lib/shared-asn1-0.9.6-SNAPSHOT.jar"/>
+	<classpathentry kind="lib" path="lib/shared-ldap-0.9.6-SNAPSHOT.jar"/>
+	<classpathentry kind="lib" path="lib/antlr-2.7.6.jar"/>
+	<classpathentry kind="output" path="target"/>
+</classpath>

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/.project
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/.project?view=auto&rev=475809
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/.project (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/.project Thu Nov 16 08:46:37
2006
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>ldapstudio-dsml-command</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/META-INF/MANIFEST.MF?view=auto&rev=475809
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/META-INF/MANIFEST.MF (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/META-INF/MANIFEST.MF Thu
Nov 16 08:46:37 2006
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Main-Class: org.apache.directory.ldapstudio.dsmlCommand.DsmlCommand
+Class-Path: lib/commons-collections-3.1.jar 
+ lib/commons-cli-1.0.jar 
+ lib/commons-lang-2.1.jar 
+ lib/commons-logging-1.1.jar 
+ lib/dom4j-1.6.1.jar 
+ lib/nlog4j-1.2.25.jar 
+ lib/shared-asn1-0.9.6-SNAPSHOT.jar 
+ lib/shared-ldap-0.9.6-SNAPSHOT.jar 
+ lib/xpp3-1.1.3_8.jar 
+ lib/ldapstudio-dsml-parser-0.1.jar 
+ 
\ No newline at end of file

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/build.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/build.xml?view=auto&rev=475809
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/build.xml (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/build.xml Thu Nov 16 08:46:37
2006
@@ -0,0 +1,149 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project name="ldapstudio-dsml-command" default="bundle" xmlns:ivy="antlib:fr.jayasoft.ivy.ant">
+	<property name="project.name" value="ldapstudio-dsml-command" />
+	<property name="project.version" value="0.1" />
+
+	<property name="project.output" value="${basedir}/target" />
+	<property name="project.build" value="${project.output}/build" />
+	<property name="project.src" value="${basedir}/src/main/java" />
+
+	<property name="lib.dir" value="lib" />
+
+	<property name="repository.dir" location="../dependencies/externals/"/>
+
+	<!-- Configuring Ivy (Needs to be AFTER the $repository.dir declaration) -->
+	<ivy:configure file="../tools/ivyconf.xml"/>
+
+	<!-- ================================== -->
+	<!--               RESOLVE              -->
+	<!-- ================================== -->
+	<target name="resolve" description="--> retreive dependencies with ivy">
+		<ivy:retrieve/>
+	</target>
+
+	<!-- ================================== -->
+	<!--             CLASSPATH              -->
+	<!-- ================================== -->
+	<target name="build-classpath" description="Computes a classpath according to current
OS" >
+		<path id="classpath">
+			<fileset dir="${lib.dir}" />
+		</path>
+	</target>
+
+	<!-- ================================== -->
+	<!--             COMPILE                -->
+	<!-- ================================== -->
+	<target name="compile" depends="resolve,checkclasses,build-classpath" unless="classes-up2date"
description="Compiles the plugin">
+		<mkdir dir="${project.build}" />
+		<copy todir="${project.build}">
+			<fileset dir="${basedir}">
+				<include name="log4j.conf" />
+			</fileset>
+		</copy>
+		<mkdir dir="${project.build}/META-INF" />
+		<copy todir="${project.build}/META-INF">
+			<fileset dir="${basedir}/META-INF">
+				<include name="**" />
+			</fileset>
+		</copy>
+		<!--<copy todir="${project.build}">
+			<fileset dir="${basedir}/src/main/resources">
+				<include name="**" />
+			</fileset>
+		</copy>-->
+		<javac
+			source="1.5"
+			debug="yes"
+			srcdir="${project.src}"
+			excludes=""
+			destdir="${project.build}"
+			classpathref="classpath"
+			listfiles="yes" />
+
+		<tstamp>
+			<format pattern="yyyy-MMM-dd, HH:mm 'GMT'Z" property="timestamp" locale="en" />
+		</tstamp>
+		<echo message="${project.name}-${project.version} compiled ${timestamp} by ${user.name}"
file="${project.build}/compile.timestamp" />
+	</target>
+
+	<target name="checkclasses">
+		<uptodate property="classes-up2date" targetfile="${project.build}/compile.timestamp">
+			<srcfiles dir="${project.src}" />
+		</uptodate>
+	</target>
+
+	<!-- ================================== -->
+	<!--              JAR                   -->
+	<!-- ================================== -->
+	<target name="jar" description="Creates jar file" depends="compile">
+		<jar destfile="${project.output}/${project.name}_${project.version}.jar" manifest="${project.build}/META-INF/MANIFEST.MF">
+			<fileset dir="${project.build}" excludes="compile.timestamp" />
+		</jar>
+	</target>
+	
+	<!-- ================================== -->
+	<!--              JAVADOC               -->
+	<!-- ================================== -->
+	<target name="javadoc" description="Generate Javadoc files">
+		<mkdir dir="${basedir}/doc" />
+		<javadoc destdir="${basedir}/doc">
+			<fileset dir="src/main/java" defaultexcludes="yes">
+				<include name="org/apache/directory/ldapstudio/**"/>
+			</fileset>
+		</javadoc>
+	</target>
+	
+	<!-- ================================== -->
+	<!--              BUNDLE                -->
+	<!-- ================================== -->
+	<property name="project.bundle" value="${project.output}/ldapstudio-dsml-command" />
+	
+	<target name="bundle" description="Bundles the command" depends="jar">
+		<mkdir dir="${project.bundle}" />
+		<mkdir dir="${project.bundle}/lib" />
+		<copy todir="${project.bundle}/lib">
+			<fileset dir="${basedir}/${lib.dir}">
+				<include name="*.jar" />
+			</fileset>
+		</copy>
+		<copy todir="${project.bundle}">
+			<fileset dir="${project.output}">
+				<include name="*${project.name}_${project.version}.jar" />
+			</fileset>
+		</copy>
+	</target>
+
+	<!-- ================================== -->
+	<!--               CLEAN                -->
+	<!-- ================================== -->
+	<target name="clean" description="Deletes any generated file (javadoc, classes, jars,
distribution)">
+		<delete includeemptydirs="true">
+			<fileset dir="${basedir}">
+				<exclude name=".project" />
+				<exclude name=".classpath" />
+				<exclude name="build.xml" />
+				<exclude name="ivy.xml" />
+				<exclude name="log4j.conf" />
+				<exclude name="META-INF/**" />
+				<exclude name="src/**" />
+			</fileset>
+		</delete>
+	</target>
+</project>

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/ivy.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/ivy.xml?view=auto&rev=475809
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/ivy.xml (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/ivy.xml Thu Nov 16 08:46:37
2006
@@ -0,0 +1,25 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<ivy-module version="1.0">
+	<info organisation="org.apache.directory.ldapstudio" module="ldapdstudio-command"/>
+	<dependencies>
+		<dependency org="commons-cli" name="commons-cli" rev="1.0"/>
+		<dependency org="org.apache.directory.ldapstudio" name="ldapstudio-dsml-parser" rev="0.1"/>
+    </dependencies>
+</ivy-module>
\ No newline at end of file

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/log4j.conf
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/log4j.conf?view=auto&rev=475809
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/log4j.conf (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/log4j.conf Thu Nov 16
08:46:37 2006
@@ -0,0 +1,9 @@
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=FATAL, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/java/org/apache/directory/ldapstudio/dsmlCommand/DsmlCommand.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/java/org/apache/directory/ldapstudio/dsmlCommand/DsmlCommand.java?view=auto&rev=475809
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/java/org/apache/directory/ldapstudio/dsmlCommand/DsmlCommand.java
(added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-command/src/main/java/org/apache/directory/ldapstudio/dsmlCommand/DsmlCommand.java
Thu Nov 16 08:46:37 2006
@@ -0,0 +1,333 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.dsmlCommand;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.commons.cli.AlreadySelectedException;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.MissingArgumentException;
+import org.apache.commons.cli.MissingOptionException;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.apache.commons.cli.UnrecognizedOptionException;
+import org.apache.log4j.PropertyConfigurator;
+import org.apache.directory.ldapstudio.dsmlv2.engine.Dsmlv2Engine;
+import org.xmlpull.v1.XmlPullParserException;
+
+/**
+ * This class implements the DSMLv2 Command Line.
+ */
+public class DsmlCommand
+{
+    /** The options of the command */
+    private static Options options = new Options();
+    
+    // Default values
+    private final static String DEFAULT_HOST = "localhost";
+    private final static int DEFAULT_PORT = 10389;
+    private final static String DEFAULT_USER = "uid=admin, ou=system";
+    private final static String DEFAULT_PASSWORD = "secret";
+    
+    // Options fields
+    private boolean debug = false;
+    private String host;
+    private int port;
+    private String user;
+    private String password;
+    private String input;
+    private String output;
+    
+    
+    public static void main( String[] args )
+    {
+        // Configuring log4j
+        PropertyConfigurator.configure( DsmlCommand.class.getClassLoader().getResource( "log4j.conf"
) ); //$NON-NLS-1$
+        
+        if ( args.length == 0 )
+        {
+            System.err.println( "Type help for usage." );
+            System.exit( 1 );
+        }
+        
+        init();
+        
+        if ( "help".equals( args[0] ) )
+        {
+            printHelp();
+            System.exit( 0 );
+        }
+        
+        DsmlCommand dsmlCommand = new DsmlCommand();
+        
+        CommandLine cmd = dsmlCommand.getCommandLine( args );
+        
+        dsmlCommand.processOptions( cmd );
+        
+        dsmlCommand.processCommand( cmd );
+        
+        System.exit( 0 );
+    }
+
+
+    /**
+     * Processes the given Command Line
+     * @param cmd a Command Line
+     */
+    private void processCommand( CommandLine cmd )
+    {
+        if ( debug ) 
+        {
+            System.out.println( "host: " + host );
+            System.out.println( "port: " + port );
+            System.out.println( "user: " + user );
+            System.out.println( "password: " + password );
+            System.out.println( "input: " + input );
+            if ( output != null )
+            {
+                System.out.println( "output: " + output );
+            }
+            else
+            {
+                System.out.println( "output: console");
+            }
+            System.out.println( "----------" );
+        }
+        
+        Dsmlv2Engine engine = new Dsmlv2Engine( host, port, user, password);
+        
+        
+        // Processing DSMLv2 input file on the server 
+        String response = null;
+        try
+        {
+            response = engine.processDSMLFile( input );
+        }
+        catch ( FileNotFoundException e )
+        {
+            System.err.println( "The input file could not been found.");
+            System.exit( 1 );
+        }
+        catch ( XmlPullParserException e )
+        {
+            System.err.println( "An error ocurred when parsing the input file.");
+            System.err.println( "Error: " + e.getMessage() );
+            System.exit( 1 );
+        }
+        
+        if ( output == null )
+        {
+            // If output hasn't be defined, the standard
+            System.out.println( response );
+        }
+        else
+        {
+            // If an output file has been defined, we write in it 
+            File outputFile = new File( output );
+            
+            FileWriter fw = null;
+            try
+            {
+                fw = new FileWriter( outputFile );
+
+                fw.write( response );
+                
+                fw.close();
+            }
+            catch ( IOException e )
+            {
+                System.err.println( "An error ocurred while writing file to disk." );
+                System.err.println( "Error: " + e.getMessage() );
+                System.exit( 1 );
+            }
+            
+            System.out.println( "Done" );
+        }
+    }
+
+
+    /**
+     * Inits the command options.
+     */
+    private static void init()
+    {
+        Option op = new Option( "d", "debug", false, "toggle debug mode" );
+        op.setRequired( false );
+        options.addOption( op );
+        op = new Option( "h", "host", true, "the server host: defaults to localhost" );
+        op.setRequired( false );
+        options.addOption( op );
+        op = new Option( "p", "port", true, "the server port: defaults to 10389" );
+        op.setRequired( false );
+        options.addOption( op );
+        op = new Option( "u", "user", true, "the user dn: default to uid=admin, ou=system"
);
+        op.setRequired( false );
+        options.addOption( op );
+        op = new Option( "w", "password", true, "the user's password: defaults to secret"
);
+        op.setRequired( false );
+        options.addOption( op );
+        op = new Option( "i", "input", true, "the input DSMLv2 file" );
+        op.setRequired( true );
+        options.addOption( op );
+        op = new Option( "o", "output", true, "the output DSMLv2 file: if this option is
ommited, the response will be printed out." );
+        op.setRequired( false );
+        options.addOption( op );
+    }
+    
+    
+    /**
+     * Converts received args[] into a Command Line
+     * @param args an arguments array
+     * @return the corresponding Command Line
+     */
+    private CommandLine getCommandLine( String[] args )
+    {
+        CommandLineParser parser = new PosixParser();
+        CommandLine cmdline = null;
+        try
+        {
+            cmdline = parser.parse( options, args );
+        }
+        catch ( AlreadySelectedException ase )
+        {
+            System.err.println( "Command line parsing failed.  Reason: already selected "
+                + ase.getMessage() );
+            System.exit( 1 );
+        }
+        catch ( MissingArgumentException mae )
+        {
+            System.err.println( "Command line parsing failed.  Reason: missing argument "
+                + mae.getMessage() );
+            System.exit( 1 );
+        }
+        catch ( MissingOptionException moe )
+        {
+            System.err.println( "Command line parsing failed.  Reason: missing option "
+                + moe.getMessage() );
+            System.exit( 1 );
+        }
+        catch ( UnrecognizedOptionException uoe )
+        {
+            System.err.println( "Command line parsing failed.  Reason: unrecognized option"
+                + uoe.getMessage() );
+            System.exit( 1 );
+        }
+        catch ( ParseException pe )
+        {
+            System.err.println( "Command line parsing failed.  Reason: " + pe.getClass()
);
+            System.exit( 1 );
+        }
+
+        return cmdline;
+    }
+
+    /**
+     * Prints Help on the console
+     */
+    private static void printHelp()
+    {
+        HelpFormatter formatter = new HelpFormatter();
+        formatter.printHelp( "<command> [options]", "\nOptions:", options, "" );
+
+    }
+    
+    
+    /**
+     * Processes the Options of a given Command Line
+     * @param cmd the Command Line
+     * @throws NumberFormatException when the port value couldn't be parsed correctly
+     */
+    private void processOptions(CommandLine cmd) throws NumberFormatException
+    {
+        // DEBUG
+        if ( cmd.hasOption( "d" ) )
+        {
+            debug = true;
+        }
+        
+        // HOST
+        if ( cmd.hasOption( "h" ) )
+        {
+            host = cmd.getOptionValue( "h" );
+        }
+        else
+        {
+            host = DEFAULT_HOST;
+        }
+        
+        // PORT
+        if ( cmd.hasOption( "p" ) )
+        {
+            try
+            {
+                port = Integer.parseInt( cmd.getOptionValue( "p" ) );
+            }
+            catch (NumberFormatException e) {
+                System.err.println("port must be an integer.");
+                System.exit( 1 );
+            }
+            // TODO add a verification to check if port is between XXX and XXX.
+        }
+        else
+        {
+            port = DEFAULT_PORT;
+        }
+        
+        // USER
+        if ( cmd.hasOption( "u" ) )
+        {
+            user = cmd.getOptionValue( "u" );
+        }
+        else
+        {
+            user = DEFAULT_USER;
+        }
+        
+        // PASSWORD
+        if ( cmd.hasOption( "w" ) )
+        {
+            password = cmd.getOptionValue( "w" );
+        }
+        else
+        {
+            password = DEFAULT_PASSWORD;
+        }
+        
+        // INPUT
+        if ( cmd.hasOption( "i" ) )
+        {
+            input = cmd.getOptionValue( "i" );
+        }
+        
+        // OUTPUT
+        if ( cmd.hasOption( "o" ) )
+        {
+            output = cmd.getOptionValue( "o" );
+        }
+    }
+}



Mime
View raw message