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

/**
 * 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>/*w w  w  .jav  a2  s.  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:com.jims.oauth2.common.utils.OAuthUtils.java

public static boolean hasContentType(String requestContentType, String requiredContentType) {
    if (OAuthUtils.isEmpty(requiredContentType) || OAuthUtils.isEmpty(requestContentType)) {
        return false;
    }//  w ww .ja v a 2s  .  com
    StringTokenizer tokenizer = new StringTokenizer(requestContentType, ";");
    while (tokenizer.hasMoreTokens()) {
        if (requiredContentType.equals(tokenizer.nextToken())) {
            return true;
        }
    }

    return false;
}

From source file:com.icesoft.faces.component.ext.taglib.Util.java

/**
 * Gets the comma separated list of enabling user roles from the given
 * component and checks if current user is in one of these roles.
 *
 * @param component a user role aware component
 * @return true if no user roles are defined for this component or user is
 *         in one of these roles, false otherwise
 *//*from  w  w w .j  av  a2s. c  o  m*/
public static boolean isEnabledOnUserRole(UIComponent component) {
    if (ignoreUserRoleAttributes()) {
        return true;
    }
    String userRole;
    if (component instanceof IceExtended) {
        userRole = ((IceExtended) component).getEnabledOnUserRole();
    } else {
        userRole = (String) component.getAttributes().get(IceExtended.ENABLED_ON_USER_ROLE_ATTR);
    }

    // there is no restriction
    if (userRole == null) {
        return true;
    }

    FacesContext facesContext = FacesContext.getCurrentInstance();
    StringTokenizer st = new StringTokenizer(userRole, ",");
    while (st.hasMoreTokens()) {
        if (facesContext.getExternalContext().isUserInRole(st.nextToken().trim())) {
            return true;
        }
    }
    return false;
}

From source file:com.izforge.izpack.util.IoHelper.java

/**
 * Extracts a long value from a string in a special manner. The string will be broken into
 * tokens with a standard StringTokenizer. Around the assumed place (with the given half range)
 * the tokens are scanned reverse for a token which represents a long. if useNotIdentifier is not
 * null, tokens which are contains this string will be ignored. The first founded long returns.
 *
 * @param in               the string which should be parsed
 * @param assumedPlace     token number which should contain the value
 * @return founded long/* w  w w. ja v a  2 s  . com*/
 */
private static long extractLong(String in, int assumedPlace) {
    long ret = -1;
    StringTokenizer st = new StringTokenizer(in);
    int length = st.countTokens();
    int i;
    int currentRange = 0;
    String[] interestedEntries = new String[3 + 3];
    for (i = 0; i < length - 3 + assumedPlace; ++i) {
        st.nextToken(); // Forget this entries.
    }

    for (i = 0; i < 3 + 3; ++i) { // Put the interesting Strings into an intermediate array.
        if (st.hasMoreTokens()) {
            interestedEntries[i] = st.nextToken();
            currentRange++;
        }
    }

    for (i = currentRange - 1; i >= 0; --i) {
        if (interestedEntries[i].contains("%")) {
            continue;
        }
        try {
            ret = Long.parseLong(interestedEntries[i]);
        } catch (NumberFormatException nfe) {
            continue;
        }
        break;
    }
    return ret;
}

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 w  ww. ja  v  a  2 s. co 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.icesoft.jasper.compiler.TldLocationsCache.java

/**
 * Sets the list of JARs that are known not to contain any TLDs.
 *
 * @param jarNames List of comma-separated names of JAR files that are known
 *                 not to contain any TLDs
 *///from w  w w.  j  a v  a 2  s. c  o m
public static void setNoTldJars(String jarNames) {
    if (jarNames != null) {
        noTldJars.clear();
        StringTokenizer tokenizer = new StringTokenizer(jarNames, ",");
        while (tokenizer.hasMoreElements()) {
            noTldJars.add(tokenizer.nextToken());
        }
    }
}

From source file:bboss.org.apache.velocity.util.StringUtils.java

/**
 * Create a string array from a string separated by delim
 *
 * @param line the line to split/*from   w  w  w  .ja va2s.c o m*/
 * @param delim the delimter to split by
 * @return a string array of the split fields
 */
public static String[] split(String line, String delim) {
    List list = new ArrayList();
    StringTokenizer t = new StringTokenizer(line, delim);
    while (t.hasMoreTokens()) {
        list.add(t.nextToken());
    }
    return (String[]) list.toArray(new String[list.size()]);
}

From source file:com.icesoft.faces.component.ext.taglib.Util.java

/**
 * Gets the comma separated list of visibility user roles from the given
 * component and checks if current user is in one of these roles.
 *
 * @param component a user role aware component
 * @return true if no user roles are defined for this component or user is
 *         in one of these roles, false otherwise
 *///ww w  . j a  v a2  s.c  o m
public static boolean isRenderedOnUserRole(UIComponent component) {
    if (ignoreUserRoleAttributes()) {
        return true;
    }
    String userRole;
    if (component instanceof IceExtended) {
        userRole = ((IceExtended) component).getRenderedOnUserRole();
    } else {
        userRole = (String) component.getAttributes().get(IceExtended.RENDERED_ON_USER_ROLE_ATTR);
    }

    if (log.isTraceEnabled()) {
        log.trace("userRole in " + getRoot(component) + " is " + userRole);

    }

    //there is no restriction
    if (userRole == null) {
        return true;
    }

    FacesContext facesContext = FacesContext.getCurrentInstance();
    StringTokenizer st = new StringTokenizer(userRole, ",");
    while (st.hasMoreTokens()) {
        if (facesContext.getExternalContext().isUserInRole(st.nextToken().trim())) {
            return true;
        }
    }
    return false;
}

From source file:com.topsem.common.net.IPSeeker.java

/**
 * ip??/*from w  w w.  j a  v a  2  s .c o  m*/
 * @param ip ?ip
 * @return ?ip
 */
private static byte[] getIpByteArrayFromString(String ip) throws Exception {
    byte[] ret = new byte[4];
    java.util.StringTokenizer st = new java.util.StringTokenizer(ip, ".");
    try {
        ret[0] = (byte) (Integer.parseInt(st.nextToken()) & 0xFF);
        ret[1] = (byte) (Integer.parseInt(st.nextToken()) & 0xFF);
        ret[2] = (byte) (Integer.parseInt(st.nextToken()) & 0xFF);
        ret[3] = (byte) (Integer.parseInt(st.nextToken()) & 0xFF);
    } catch (Exception e) {
        throw e;
    }
    return ret;
}

From source file:NimbleTree.java

/**
 * A static constructor (is this the right term?) where a lisp-style s-expression
 * is passed in as a string. This can't be a true constructor because the result
 * is a tree over String, not a generic tree.
 *//*w ww.j  a v  a  2  s  .c o m*/
public static NimbleTree<String> makeTreeOverStringFromSExpression(String input) {
    NimbleTree<String> tree = new NimbleTree<String>();
    Stack<TreeNode<String>> previousParents = new Stack<TreeNode<String>>();

    // Make sure the string is tokenizable
    // FIXME allow [] and maybe other delimiters?
    input = input.replace("(", " ( ");
    input = input.replace(")", " ) ");

    StringTokenizer st = new StringTokenizer(input);

    boolean firstTimeThrough = true;
    while (st.hasMoreTokens()) {
        String currTok = st.nextToken().trim();

        if (currTok.equals("")) {
            // Tokenizer gave us an empty token, do nothing.

        } else if (currTok.equals("(")) {
            // Get the *next* token and make a new subtree on it.
            currTok = st.nextToken().trim();

            if (firstTimeThrough == true) {
                // The tree is of the form "(x)"
                // This is the root node: just set its data
                firstTimeThrough = false;
                tree.getRoot().setData(currTok);

            } else {
                // This is the root of a new subtree. Save parent,
                // then set this node to be the new parent.
                tree.addChild(currTok);
                tree.getCurrentNode().getEnd().setID(tree.getNodeCount());
                previousParents.push(tree.getCurrentNode());
                tree.setCurrentNode(tree.getCurrentNode().getEnd());
            }

        } else if (currTok.equals(")")) {
            // Finished adding children to current parent. Go back
            // to previous parent (if there was none, it's because
            // current parent is root, so we're finished anyway).
            if (!previousParents.empty()) {
                tree.setCurrentNode(previousParents.pop());
            }

        } else {
            if (firstTimeThrough == true) {
                // The tree is of the form "x".
                // This is to be the root node: just set its data. 
                firstTimeThrough = false;
                tree.getRoot().setData(currTok);
            } else {
                // Add a child node to current parent.
                tree.addChild(currTok);
                tree.getCurrentNode().getEnd().setID(tree.getNodeCount());
            }
        }
    }

    return tree;
}