Example usage for java.util StringTokenizer nextToken

List of usage examples for java.util StringTokenizer nextToken

Introduction

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

Prototype

public String nextToken() 

Source Link

Document

Returns the next token from this string tokenizer.

Usage

From source file:hudson.model.Items.java

/**
 * Does the opposite of {@link #toNameList(Collection)}.
 *///from   w w w  . j av  a  2s  . c  om
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.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  ww  .  j  av a2s . 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: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   w  w w. j  a  va 2  s.c  o  m*/
            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:com.jaspersoft.jasperserver.rest.RESTUtils.java

public static List<String> stringToList(String roles, String delimiter) {
    List<String> lst = new LinkedList<String>();
    StringTokenizer sTok = new StringTokenizer(roles, delimiter);

    while (sTok.hasMoreTokens()) {
        lst.add(sTok.nextToken().trim());
    }/*w w w.jav  a  2 s  . c  om*/

    return lst;
}

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();
            }//w  w w .j  a v a  2s  .c  o  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:org.paxml.tag.AbstractTag.java

/**
 * Break an object into string values./*  w  w w  .  j a va  2  s.  c om*/
 * 
 * @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   w ww  .  jav  a 2  s  . co 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);
    }
}

From source file:com.github.dozermapper.core.util.ReflectionUtils.java

/**
 * Find a method with concrete string representation of it's parameters
 *
 * @param clazz         clazz to search//from  w w w .j  ava2  s. c o m
 * @param methodName    name of method with representation of it's parameters
 * @param beanContainer beanContainer instance
 * @return found method
 * @throws NoSuchMethodException if no method found
 */
public static Method findAMethod(Class<?> clazz, String methodName, BeanContainer beanContainer)
        throws NoSuchMethodException {
    StringTokenizer tokenizer = new StringTokenizer(methodName, "(");
    String m = tokenizer.nextToken();
    Method result;
    // If tokenizer has more elements, it mean that parameters may have been specified
    if (tokenizer.hasMoreElements()) {
        StringTokenizer tokens = new StringTokenizer(tokenizer.nextToken(), ")");
        String params = tokens.hasMoreTokens() ? tokens.nextToken() : null;
        result = findMethodWithParam(clazz, m, params, beanContainer);
    } else {
        result = findMethod(clazz, methodName);
    }
    if (result == null) {
        throw new NoSuchMethodException(clazz.getName() + "." + methodName);
    }
    return result;
}

From source file:org.bedework.notifier.web.MethodBase.java

/** Return a path, broken into its elements, after "." and ".." are removed.
 * If the parameter path attempts to go above the root we return null.
 *
 * Other than the backslash thing why not use URI?
 *
 * @param path      String path to be fixed
 * @return String[]   fixed path broken into elements
 * @throws NoteException on error//from  ww w  .j av  a 2 s.  c  o  m
 */
public static List<String> fixPath(final String path) throws NoteException {
    if (path == null) {
        return null;
    }

    String decoded;
    try {
        decoded = URLDecoder.decode(path, "UTF8");
    } catch (Throwable t) {
        throw new NoteException("bad path: " + path);
    }

    if (decoded == null) {
        return (null);
    }

    /** Make any backslashes into forward slashes.
     */
    if (decoded.indexOf('\\') >= 0) {
        decoded = decoded.replace('\\', '/');
    }

    /** Ensure a leading '/'
     */
    if (!decoded.startsWith("/")) {
        decoded = "/" + decoded;
    }

    /** Remove all instances of '//'.
     */
    while (decoded.indexOf("//") >= 0) {
        decoded = decoded.replaceAll("//", "/");
    }

    /** Somewhere we may have /./ or /../
     */

    StringTokenizer st = new StringTokenizer(decoded, "/");

    ArrayList<String> al = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String s = st.nextToken();

        if (s.equals(".")) {
            // ignore
        } else if (s.equals("..")) {
            // Back up 1
            if (al.size() == 0) {
                // back too far
                return null;
            }

            al.remove(al.size() - 1);
        } else {
            al.add(s);
        }
    }

    return al;
}

From source file:jenkins.plugins.testopia.TestopiaBuilder.java

/**
 * Maybe adds a system property if it is in format <key>=<value>.
 * /*from  w ww  .  ja va2s.com*/
 * @param systemProperty System property entry in format <key>=<value>.
 * @param listener Jenkins Build listener
 */
public static void maybeAddSystemProperty(String systemProperty, BuildListener listener) {
    final StringTokenizer tokenizer = new StringTokenizer(systemProperty, "=:");
    if (tokenizer.countTokens() == 2) {
        final String key = tokenizer.nextToken();
        final String value = tokenizer.nextToken();

        if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(value)) {
            if (key.contains(BASIC_HTTP_PASSWORD)) {
                listener.getLogger().println(Messages.Testopia_Builder_Password(key));
            } else {
                listener.getLogger().println(Messages.Testopia_Builder_Setting(key, value));
            }
            try {
                System.setProperty(key, value);
            } catch (SecurityException se) {
                se.printStackTrace(listener.getLogger());
            }

        }
    }
}