Example usage for java.util StringTokenizer hasMoreTokens

List of usage examples for java.util StringTokenizer hasMoreTokens

Introduction

In this page you can find the example usage for java.util StringTokenizer hasMoreTokens.

Prototype

public boolean hasMoreTokens() 

Source Link

Document

Tests if there are more tokens available from this tokenizer's string.

Usage

From source file:org.zkoss.spring.security.SecurityUtil.java

private static List<Permission> parsePermissions(String permissionsString) {
    final Set<Permission> permissions = new HashSet<Permission>();
    final StringTokenizer tokenizer;
    tokenizer = new StringTokenizer(permissionsString, ",", false);

    while (tokenizer.hasMoreTokens()) {
        String permission = tokenizer.nextToken();
        try {/*from   w w  w.  j av  a 2 s  .  c o m*/
            permissions.add(permissionFactory.buildFromMask(Integer.valueOf(permission)));
        } catch (NumberFormatException nfe) {
            // Not an integer mask. Try using a name
            permissions.add(permissionFactory.buildFromName(permission));
        }
    }
    return new ArrayList<Permission>(permissions);
}

From source file:de.kapsi.net.daap.DaapUtil.java

/**
 * Splits a meta String ("foo,bar,alice,bob") and stores the data
 * in an ArrayList//w  w w.  ja  v  a 2 s . c om
 * 
 * @param meta a meta String
 * @return the splitten meta String as ArrayList
 */
public static final ArrayList parseMeta(String meta) {
    StringTokenizer tok = new StringTokenizer(meta, ",");
    ArrayList list = new ArrayList(tok.countTokens());
    boolean flag = false;

    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();

        // Must be te fist! See DAAP documentation 
        // for more info!
        if (!flag && token.equals("dmap.itemkind")) {
            list.add(0, token);
            flag = true;
        } else {
            list.add(token);
        }
    }
    return list;
}

From source file:hudson.model.Items.java

/**
 * Does the opposite of {@link #toNameList(Collection)}.
 *//*ww  w  .  ja  va 2s .com*/
public static <T extends Item> List<T> fromNameList(ItemGroup context, @Nonnull String list,
        @Nonnull Class<T> type) {
    Jenkins hudson = Jenkins.getInstance();

    List<T> r = new ArrayList<T>();
    StringTokenizer tokens = new StringTokenizer(list, ",");
    while (tokens.hasMoreTokens()) {
        String fullName = tokens.nextToken().trim();
        T item = hudson.getItem(fullName, context, type);
        if (item != null)
            r.add(item);
    }
    return r;
}

From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java

private static void setSeriesColors(Object renderer, final String seriesColors) {
    if (seriesColors != null) {
        StringTokenizer st = new StringTokenizer(seriesColors, ",");

        int i = 0;
        while (st.hasMoreTokens()) {
            String colorName = st.nextToken().trim();
            Color color = null;//from  www  .  jav  a2s  .  com
            try {
                color = Colour.getColor(colorName);
            } catch (XPathException e) {
            }

            if (color != null) {
                if (renderer instanceof SpiderWebPlot) {
                    ((SpiderWebPlot) renderer).setSeriesPaint(i, color);
                } else {
                    ((CategoryItemRenderer) renderer).setSeriesPaint(i, color);
                }
            } else {
                logger.warn("Invalid colour name or hex value specified for SeriesColors: " + colorName
                        + ", default colour will be used instead.");
            }

            i++;
        }
    }
}

From source file:de.bayern.gdi.utils.StringUtils.java

/**
 * Split a command line.// w  w  w. j  a v  a2s. co  m
 * @param toProcess the command line to process.
 * @return the command line broken into strings.
 * An empty or null toProcess parameter results in a zero sized array.
 * @throws IllegalArgumentException Thrown if quotes are unbalanced.
 */
public static String[] splitCommandLine(String toProcess) throws IllegalArgumentException {

    if (toProcess == null || toProcess.length() == 0) {
        //no command? no string
        return new String[0];
    }
    // parse with a simple finite state machine

    State state = State.NORMAL;
    StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
    ArrayList<String> result = new ArrayList<String>();
    StringBuilder current = new StringBuilder();
    boolean lastTokenHasBeenQuoted = false;

    while (tok.hasMoreTokens()) {
        String nextTok = tok.nextToken();
        switch (state) {
        case IN_QUOTE:
            if ("\'".equals(nextTok)) {
                lastTokenHasBeenQuoted = true;
                state = State.NORMAL;
            } else {
                current.append(nextTok);
            }
            break;
        case IN_DOUBLE_QUOTE:
            if ("\"".equals(nextTok)) {
                lastTokenHasBeenQuoted = true;
                state = State.NORMAL;
            } else {
                current.append(nextTok);
            }
            break;
        default:
            if ("\'".equals(nextTok)) {
                state = State.IN_QUOTE;
            } else if ("\"".equals(nextTok)) {
                state = State.IN_DOUBLE_QUOTE;
            } else if (" ".equals(nextTok)) {
                if (lastTokenHasBeenQuoted || current.length() != 0) {
                    result.add(current.toString());
                    current.setLength(0);
                }
            } else {
                current.append(nextTok);
            }
            lastTokenHasBeenQuoted = false;
            break;
        }
    }
    if (lastTokenHasBeenQuoted || current.length() != 0) {
        result.add(current.toString());
    }
    if (state == State.IN_QUOTE || state == State.IN_DOUBLE_QUOTE) {
        throw new IllegalArgumentException("unbalanced quotes in " + toProcess);
    }
    return result.toArray(new String[result.size()]);
}

From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java

private static void setSectionColors(JFreeChart chart, Configuration config) {
    String sectionColors = config.getSectionColors();
    String sectionColorsDelimiter = config.getSectionColorsDelimiter();

    if (sectionColors != null) {
        PiePlot plot = ((PiePlot) chart.getPlot());

        StringTokenizer st = new StringTokenizer(sectionColors, sectionColorsDelimiter);

        while (st.hasMoreTokens()) {
            String sectionName = st.nextToken().trim();
            String colorName = "";

            if (st.hasMoreTokens()) {
                colorName = st.nextToken().trim();
            }/*from   w ww .j  a v  a  2  s  . co m*/

            Color color = null;

            try {
                color = Colour.getColor(colorName);
            } catch (XPathException e) {
            }

            if (color != null) {
                plot.setSectionPaint(sectionName, color);
            } else {
                logger.warn("Invalid colour name or hex value specified for SectionColors: " + colorName
                        + ", default colour will be used instead. Section Name: " + sectionName);
            }
        }
    }
}

From source file:mitm.common.tools.SendMail.java

private static Address[] getRecipients(String recipients) throws AddressException {
    if (StringUtils.isBlank(recipients)) {
        return null;
    }//from   w w  w  . j  a v a2s. co m

    List<Address> addresses = new LinkedList<Address>();

    StringTokenizer tokenizer = new StringTokenizer(recipients, ",");

    while (tokenizer.hasMoreTokens()) {
        String recipient = tokenizer.nextToken();

        addresses.add(new InternetAddress(recipient));
    }

    return (Address[]) addresses.toArray(new Address[0]);
}

From source file:org.apache.axis2.transport.http.impl.httpclient4.HTTPProxyConfigurator.java

/**
 * Check if the specified host is in the list of non proxy hosts.
 *
 * @param host//ww  w. ja va  2 s .com
 *            host name
 * @param nonProxyHosts
 *            string containing the list of non proxy hosts
 * @return true/false
 */
public static boolean isHostInNonProxyList(String host, String nonProxyHosts) {
    if ((nonProxyHosts == null) || (host == null)) {
        return false;
    }

    /*
     * The http.nonProxyHosts system property is a list enclosed in double
     * quotes with items separated by a vertical bar.
     */
    StringTokenizer tokenizer = new StringTokenizer(nonProxyHosts, "|\"");

    while (tokenizer.hasMoreTokens()) {
        String pattern = tokenizer.nextToken();
        if (match(pattern, host, false)) {
            return true;
        }
    }
    return false;
}

From source file:org.paxml.tag.AbstractTag.java

/**
 * Break an object into string values.//from   w w  w.j  a  v a  2s .  com
 * 
 * @param obj
 *            the object which can be either a list, if given null, empty
 *            set will return.
 * @param delimiters
 *            the delimiters used to create StringTokenizer if the given
 *            object is a not a List, if given null, this delimiter set will
 *            be used: ", \r\n\t\f"
 * @return a ordered set of trimmed strings which contains no null nor blank
 *         string, never returns null List.
 */
public static Set<String> parseDelimitedString(Object obj, String delimiters) {
    Set<String> set = new LinkedHashSet<String>(0);
    if (obj instanceof List) {
        for (Object item : (List) obj) {
            if (item != null) {
                String str = item.toString().trim();
                if (str.length() > 0) {
                    set.add(str);
                }
            }
        }
    } else if (obj != null) {
        if (delimiters == null) {
            delimiters = ", \r\n\t\f";
        }
        StringTokenizer st = new StringTokenizer(obj.toString(), delimiters);
        while (st.hasMoreTokens()) {
            String part = st.nextToken().trim();
            if (part.length() > 0) {
                set.add(part);
            }
        }
    }
    return set;
}

From source file:services.ConfigurationService.java

public static List<String> listPuppetFiles(final Integer type)
        throws PuppetConfigurationException, GoogleComputeEngineException {
    String serverName = googleComputeService.getClusterPublicAddress();
    List<String> files = new ArrayList<String>();
    try {//from   ww w  .  ja va2s  . c  o m
        if (serverName == null || serverName.isEmpty()) {
            return files;
        }
        StringBuilder destinationPath = new StringBuilder();
        SSHClient client = new SSHClient(serverName, 22);
        switch (type) {
        case PuppetConfiguration.PUPPET_MANIFEST:
            destinationPath.append(PuppetConfiguration.getPuppetManifestsDirectory());
            break;
        case PuppetConfiguration.PUPPET_FILE:
            destinationPath.append(PuppetConfiguration.getPuppetFilesDirectory());
            break;
        default:
            throw new PuppetConfigurationException("incorrect puppet file type");
        }
        try {
            client.connect(CLUSTER_USER);
            if (client.sendCommand("ls", destinationPath.toString()) > 0) {
                throw new GoogleComputeEngineException(
                        "cannot list the files for directory: " + destinationPath.toString());
            }
            StringTokenizer st = new StringTokenizer(client.getStringOutput());
            while (st.hasMoreTokens()) {
                files.add(st.nextToken());
            }
            return files;
        } catch (SSHException e) {
            throw new GoogleComputeEngineException(e);
        } finally {
            client.disconnect();
        }
    } catch (IOException e) {
        throw new GoogleComputeEngineException(e);
    }
}