Java XML Parse String parseArgs(String[] args)

Here you can find the source of parseArgs(String[] args)

Description

Parses the command line arguments.

License

Apache License

Parameter

Parameter Description
args the arguments to be parsed.

Return

a string with the values of the arguments.

Declaration

public static String[] parseArgs(String[] args) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*from  w w w  .  j a  va2 s. c  o m*/
     * Parses the command line arguments.
     * 
     * @param args the arguments to be parsed.
     * @return a string with the values of the arguments.
     */
    public static String[] parseArgs(String[] args) {
        List<String> col = new ArrayList<String>();
        for (String arg : args) {
            String narg = arg.trim();
            if (narg.contains("=")) {
                for (String n : narg.split("=")) {
                    col.add(n);
                }
            } else
                col.add(arg.trim());
        }
        boolean sproject = false;
        boolean sfile = false;
        boolean sproperties = false;
        boolean srepr = false;
        String project = "";
        String file = "";
        String properties = "";
        String repr = "";
        for (String c : col) {
            if (c.startsWith("-project")) {
                sproject = true;
                sfile = false;
                sproperties = false;
                srepr = false;
            } else if (c.startsWith("-file")) {
                sproject = false;
                sfile = true;
                sproperties = false;
                srepr = false;
            } else if (c.startsWith("-properties")) {
                sproject = false;
                sfile = false;
                sproperties = true;
                srepr = false;
            } else if (c.startsWith("-repr")) {
                sproject = false;
                sfile = false;
                sproperties = false;
                srepr = true;
            } else {
                if (sproject)
                    project += c + " ";
                else if (sfile)
                    file += c + " ";
                else if (sproperties)
                    properties += c + " ";
                else if (srepr)
                    repr += c + " ";
            }
        }
        return new String[] { project.trim(), file.trim(), properties.trim(), repr.trim().toUpperCase() };
    }
}

Related

  1. parse(String xml)
  2. parseAccessNumber(String line)
  3. parseAddressLines(String[] addressLines)
  4. parseArg(String arg)
  5. parseArgs(String text)
  6. parseArgs(String[] args)
  7. parseArgsString(String args)
  8. parseArgsToVmArgs(String[] args, String prefixOfVmArgs)
  9. parseArguments(final String command)