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:com.kcs.core.utilities.Utility.java

public static String[] split(String value, String delim) {
    if (value == null) {
        return new String[0];
    }/*from www  .jav a  2 s.c  o  m*/
    if (value.trim().equals("")) {
        return new String[0];
    }
    String[] ret = null;
    if (value.indexOf(delim) == -1) {
        ret = new String[1];
        ret[0] = value;
    } else {
        StringTokenizer stoken = new StringTokenizer(value, delim);
        ret = new String[stoken.countTokens()];
        int i = 0;
        while (stoken.hasMoreTokens()) {
            ret[i] = stoken.nextToken();
            i++;
        }
    }
    return ret;
}

From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferable.java

public static void pasteStringLine(String s, SpreadSheet spreadsheet, int row0, int col0) {
    String valueS;//w  w  w  .  j a v a2 s .  com
    CommonSpreadSheetModel model = (CommonSpreadSheetModel) spreadsheet.getModel();
    String delim = "\t";
    StringTokenizer st = new StringTokenizer(s, delim, true);
    int col = col0, maxCol = spreadsheet.getColumnCount() - 1;
    FieldContext fieldContext = model.getFieldContext();
    boolean round = fieldContext.isRound();
    fieldContext.setRound(true);
    while (st.hasMoreTokens() && col <= maxCol) {
        valueS = st.nextToken();
        if (delim.equals(valueS))
            valueS = "";
        else if (st.hasMoreTokens())
            st.nextToken();
        try {
            model.setValueAt(valueS, row0, ++col);
        } catch (Exception e) {
        }
    }
    fieldContext.setRound(round);
}

From source file:com.openkm.dao.ConfigDAO.java

/**
 * Find by pk with a default value/*w w  w  . j ava  2  s .  co m*/
 */
public static String getSelectedOption(String key, String value) throws DatabaseException {
    StringTokenizer st = new StringTokenizer(value, "|");
    ConfigStoredSelect stSelect = new ConfigStoredSelect();
    boolean selected = false;

    while (st.hasMoreTokens()) {
        String tk = st.nextToken().trim();
        ConfigStoredOption stOption = new ConfigStoredOption();

        if (tk.startsWith(ConfigStoredOption.SELECTED)) {
            stOption.setName(tk.substring(1));
            stOption.setValue(tk.substring(1));
            stOption.setSelected(true);
            selected = true;
        } else {
            stOption.setName(tk);
            stOption.setValue(tk);
            stOption.setSelected(false);
        }

        stSelect.getOptions().add(stOption);
    }

    // Set first option as default
    if (!selected && stSelect.getOptions().size() > 0) {
        stSelect.getOptions().get(0).setSelected(true);
    }

    String dbValue = getProperty(key, new Gson().toJson(stSelect), Config.SELECT);
    ConfigStoredSelect dbSelect = new Gson().fromJson(dbValue, ConfigStoredSelect.class);

    for (ConfigStoredOption option : dbSelect.getOptions()) {
        if (option.isSelected()) {
            return option.getValue();
        }
    }

    return "";
}

From source file:hudson.model.Items.java

/**
 * Computes the relative name of list of items after a rename or move occurred.
 * Used to manage job references as names in plugins to support {@link hudson.model.listeners.ItemListener#onLocationChanged}.
 * <p>//from   www  . ja  v a  2s.  c o m
 * In a hierarchical context, when a plugin has a reference to a job as <code>../foo/bar</code> this method will
 * handle the relative path as "foo" is renamed to "zot" to compute <code>../zot/bar</code>
 *
 * @param oldFullName the old full name of the item
 * @param newFullName the new full name of the item
 * @param relativeNames coma separated list of Item relative names
 * @param context the {link ItemGroup} relative names refer to
 * @return relative name for the renamed item, based on the same ItemGroup context
 */
public static String computeRelativeNamesAfterRenaming(String oldFullName, String newFullName,
        String relativeNames, ItemGroup context) {

    StringTokenizer tokens = new StringTokenizer(relativeNames, ",");
    List<String> newValue = new ArrayList<String>();
    while (tokens.hasMoreTokens()) {
        String relativeName = tokens.nextToken().trim();
        String canonicalName = getCanonicalName(context, relativeName);
        if (canonicalName.equals(oldFullName) || canonicalName.startsWith(oldFullName + '/')) {
            String newCanonicalName = newFullName + canonicalName.substring(oldFullName.length());
            if (relativeName.startsWith("/")) {
                newValue.add("/" + newCanonicalName);
            } else {
                newValue.add(getRelativeNameFrom(newCanonicalName, context.getFullName()));
            }
        } else {
            newValue.add(relativeName);
        }
    }
    return StringUtils.join(newValue, ",");
}

From source file:hudson.plugins.testlink.util.TestLinkHelper.java

/**
 * <p>Formats a custom field into an environment variable. It appends 
 * TESTLINK_TESTCASE in front of the environment variable name.</p>
 * /*from   ww w.  ja va  2  s  .  c  o  m*/
 * <p>So, for example, the custom field which name is Sample  Custom Field and 
 * value is <b>Sample Value</b>, will be added into the environment variables 
 * as TESTLINK_TESTCASE_SAMPLE__CUSTOM_FIELD="Sample Value" (note for the double spaces).</p>
 * 
 * <p>If the custom's value contains commas (,), then this method splits the 
 * value and, for each token found, it creates a new environment variable 
 * appending a numeric index after its name</p>
 * 
 * <p>So, for example, the custom field which name is Sample Custom Field and 
 * value is <b>Sample Value 1, Sample Value 2</b>, will generate three 
 * environment variables: TESTLINK_TESTCASE_SAMPLE_CUSTOM_FIELD="Sample Value 1, Sample Value 2", 
 * TESTLINK_TESTCASE_SAMPLE_CUSTOM_FIELD_0="Sample Value 1" and 
 * TESTLINK_TESTCASE_SAMPLE_CUSTOM_FIELD_1="Sample Value 2".</p> 
 * 
 * @param customField The custom field
 * @param testLinkEnvVar TestLink envVars
 */
public static void addCustomFieldEnvironmentVariableName(CustomField customField,
        Map<String, String> testLinkEnvVar) {
    String customFieldName = customField.getName();
    String customFieldValue = customField.getValue();

    customFieldName = customFieldName.toUpperCase(); // uppercase
    customFieldName = customFieldName.trim(); // trim
    customFieldName = TESTLINK_TESTCASE_PREFIX + customFieldName; // add prefix
    customFieldName = customFieldName.replaceAll("\\s+", "_"); // replace white spaces

    testLinkEnvVar.put(customFieldName, customFieldValue);

    if (StringUtils.isNotBlank(customFieldValue)) {
        StringTokenizer tokenizer = new StringTokenizer(customFieldValue, ",");
        if (tokenizer.countTokens() > 1) {
            int index = 0;
            while (tokenizer.hasMoreTokens()) {
                String token = tokenizer.nextToken();
                token = token.trim();

                customFieldName = customField.getName();
                customFieldName = customFieldName.toUpperCase(); // uppercase
                customFieldName = customFieldName.trim(); // trim

                String tokenName = TESTLINK_TESTCASE_PREFIX + customFieldName + "_" + index; // add prefix
                tokenName = tokenName.replaceAll("\\s+", "_"); // replace white spaces

                testLinkEnvVar.put(tokenName, token);
                ++index;
            }
        }
    }
}

From source file:com.floreantpos.config.TerminalConfig.java

public static Locale getDefaultLocale() {
    String defaultLocaleString = config.getString(DEFAULT_LOCALE, null);
    if (StringUtils.isEmpty(defaultLocaleString)) {
        return null;
    }/*  w w w.  j ava 2  s.c o m*/
    String language = "";
    String country = "";
    String variant = "";
    StringTokenizer st = new StringTokenizer(defaultLocaleString, "_");
    if (st.hasMoreTokens())
        language = st.nextToken();
    if (st.hasMoreTokens())
        country = st.nextToken();
    if (st.hasMoreTokens())
        variant = st.nextToken();
    Locale disName = new Locale(language, country, variant);

    return disName;
}

From source file:com.bigdata.dastor.utils.FBUtilities.java

public static String[] strip(String string, String token) {
    StringTokenizer st = new StringTokenizer(string, token);
    List<String> result = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        result.add((String) st.nextElement());
    }/* ww w .  j  a va 2s.  co  m*/
    return result.toArray(new String[0]);
}

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// w  w w.j  av a  2  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:com.glaf.core.util.FtpUtils.java

private static void changeToDirectory(String remoteFile) {
    if (!remoteFile.startsWith("/")) {
        throw new RuntimeException(" path must start with '/'");
    }//from  ww w  .j av  a  2  s . c om
    if (remoteFile.startsWith("/") && remoteFile.indexOf("/") > 0) {
        try {
            getFtpClient().changeWorkingDirectory("/");
            String tmp = "";
            remoteFile = remoteFile.substring(0, remoteFile.lastIndexOf("/"));
            StringTokenizer token = new StringTokenizer(remoteFile, "/");
            while (token.hasMoreTokens()) {
                String str = token.nextToken();
                tmp = tmp + "/" + str;
                getFtpClient().changeWorkingDirectory(tmp);
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:com.adito.agent.client.ProxyUtil.java

/**
 * Attempt to proxy settings from Internet Explorer.
 * /*w w w .j  a  va  2  s  .com*/
 * @return internet explorer proxy settings
 * @throws IOException if IE settings could not be obtained for some reason
 */
public static BrowserProxySettings lookupIEProxySettings() throws IOException {

    try {
        Vector addresses = new Vector();
        Vector proxies = new Vector();
        String proxyServerValue = null;
        String proxyOveride = null;

        /* Only use jRegistry if on Windows, running 1.3 or up Java
         * and NOT Windows Vista with JDK6.0 (because of jvm crash)
         */

        if (Utils.isSupportedJRE("+1.3") && Utils.isSupportedPlatform(
                "Windows") /*&&
                           !(Utils.isSupportedOSVersion("+6.0") && Utils.isSupportedJRE("+1.6"))*/) {

            /*
             * We can use jRegistryKey API to lookup IE settings in the
             * registry
             */
            //                RegistryKey key = new RegistryKey(RootKey.HKEY_CURRENT_USER,
            //                                "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); //$NON-NLS-1$

            String proxyEnable = WinRegistry.getRegistryValue("user",
                    "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyEnable", "0");
            if (proxyEnable != null) { //$NON-NLS-1$
                /*
                 * We have ProxyEnable so check to see if we are using a
                 * proxy
                 */
                if (proxyEnable.equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$

                    proxyServerValue = WinRegistry.getRegistryValue("user",
                            "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyServer",
                            null);
                    if (proxyServerValue != null) { //$NON-NLS-1$
                        /**
                         * We have some proxy settings. The values will be
                         * in the format "server.proxy.net:8888" or
                         */

                        proxyOveride = WinRegistry.getRegistryValue("user",
                                "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
                                "ProxyOverride", null);
                    }
                } else {

                }
            }
        } else {
            if (System.getProperty("java.vendor").startsWith("Microsoft")) { //$NON-NLS-1$ //$NON-NLS-2$
                try {
                    Class clazz = Class.forName("com.ms.lang.RegKey"); //$NON-NLS-1$
                    int userRoot = clazz.getField("USER_ROOT").getInt(null); //$NON-NLS-1$
                    int keyOpenAll = clazz.getField("KEYOPEN_ALL").getInt(null); //$NON-NLS-1$
                    // #ifdef DEBUG
                    log.info(Messages.getString("ProxyUtil.lookingForRoot")); //$NON-NLS-1$
                    // #endif
                    Object rootKey = clazz.getMethod("getRootKey", new Class[] { int.class }).invoke(null, //$NON-NLS-1$
                            new Object[] { new Integer(userRoot) });
                    // #ifdef DEBUG
                    log.info(Messages.getString("ProxyUtil.getIERegistryKey")); //$NON-NLS-1$
                    // #endif
                    Object key = clazz.getConstructor(new Class[] { clazz, String.class, int.class })
                            .newInstance(new Object[] { rootKey,
                                    "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", //$NON-NLS-1$
                                    new Integer(keyOpenAll) });
                    // #ifdef DEBUG
                    log.info(Messages.getString("ProxyUtil.checkingIfProxyEnabled")); //$NON-NLS-1$
                    // #endif
                    if (((Integer) (clazz.getMethod("getIntValue", new Class[] { String.class }).invoke(key, //$NON-NLS-1$
                            new Object[] { "ProxyEnable" }))).intValue() == 1) { //$NON-NLS-1$
                        // #ifdef DEBUG
                        log.info(Messages.getString("ProxyUtil.gettingProxyServerList")); //$NON-NLS-1$
                        // #endif
                        proxyServerValue = (String) (clazz.getMethod("getStringValue", //$NON-NLS-1$
                                new Class[] { String.class, String.class })
                                .invoke(key, new Object[] { "ProxyServer", "" })); //$NON-NLS-1$ //$NON-NLS-2$
                        // #ifdef DEBUG
                        log.info(Messages.getString("ProxyUtil.gettingProxyOverides")); //$NON-NLS-1$
                        // #endif
                        proxyOveride = (String) (clazz
                                .getMethod("getStringValue", new Class[] { String.class, String.class }) //$NON-NLS-1$
                                .invoke(key, new Object[] { "ProxyOverride", "" })); //$NON-NLS-1$ //$NON-NLS-2$
                    }
                } catch (Throwable t) {
                    t.printStackTrace();
                }

            } else {
                // #ifdef DEBUG
                log.info(MessageFormat.format(Messages.getString("ProxyUtil.unsupportedJavaRuntime"), //$NON-NLS-1$
                        new Object[] { System.getProperty("java.version"), //$NON-NLS-1$
                                System.getProperty("java.vendor") })); //$NON-NLS-1$
                // #endif
            }

        }

        ProxyInfo p;

        if (proxyServerValue != null && proxyServerValue.indexOf(';') > -1) {
            /**
             * Format is multiple
             * "ftp=ftp.com:4444;gopher=gopher.com:3333;http=198.162.1.119:8888;https=https.com:2222;socks=socks.com:1111"
             */
            StringTokenizer tokens = new StringTokenizer(proxyServerValue, ";"); //$NON-NLS-1$

            while (tokens.hasMoreTokens()) {
                p = createProxyInfo(tokens.nextToken(), "IE Proxy Settings"); //$NON-NLS-1$
                proxies.addElement(p);
            }

        } else if (proxyServerValue != null) {
            /**
             * Format is single "http=server.proxy.net:8888" or
             * "server.proxy.net:8888"
             */
            p = createProxyInfo(proxyServerValue, "IE Proxy Settings"); //$NON-NLS-1$
            proxies.addElement(p);
        }

        BrowserProxySettings bps = new BrowserProxySettings();
        bps.setBrowser("Internet Explorer"); //$NON-NLS-1$
        bps.setProxies(new ProxyInfo[proxies.size()]);
        proxies.copyInto(bps.getProxies());
        if (proxyOveride != null) {

            StringTokenizer tokens = new StringTokenizer(proxyOveride, ";"); //$NON-NLS-1$

            while (tokens.hasMoreTokens()) {
                addresses.addElement(tokens.nextToken());
            }
        }

        bps.setBypassAddr(new String[addresses.size()]);
        addresses.copyInto(bps.getBypassAddr());
        return bps;

    } catch (Throwable t) {
        t.printStackTrace();
        throw new IOException(MessageFormat.format(Messages.getString("ProxyUtil.failedToLookupIEProxies"), //$NON-NLS-1$
                new Object[] { t.getMessage() }));
    }
}