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:JavaUtils.java

/**
 * Check if the current version is equals than the argument version.
 * @param version the version/*from   ww w  . j  av a2s .c om*/
 * @return true if the runtime version is equals than the argument
 */
public static boolean isEqualsThan(String version) {
    boolean equals = false;
    StringTokenizer tokeniser = new StringTokenizer(version, ".");
    String token = tokeniser.nextToken();
    try {
        Integer ver = new Integer(token);
        int majorVersion = ver.intValue();

        token = tokeniser.nextToken();
        ver = new Integer(token);
        int minorVersion = ver.intValue();
        if (getJREMajorVersion() == majorVersion && getJREMinorVersion() == minorVersion) {
            equals = true;
        }
    } catch (Exception e) {
        // Do nothing
    }

    return equals;
}

From source file:fr.openwide.talendalfresco.alfresco.util.ContentDataUtil.java

/**
 * [talendalfresco] In comparison to ContentData.createContentProperty(),
 * if there is no mimetype it guesses it using the mimetypeService, therefore
 * not exploding if no mimetype.//  w ww.  j av a2  s  .c o m
 * 
 * Construct a content property from a string
 * 
 * @param contentPropertyStr the string representing the content details
 * @return Returns a bean version of the string
 */
public static ContentData createContentPropertyWithGuessedMimetype(String contentPropertyStr,
        MimetypeService mimetypeService) {
    String contentUrl = null;
    String mimetype = null;
    long size = 0L;
    String encoding = null;
    Locale locale = null;
    // now parse the string
    StringTokenizer tokenizer = new StringTokenizer(contentPropertyStr, "|");
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        if (token.startsWith("contentUrl=")) {
            contentUrl = token.substring(11);
            if (contentUrl.length() == 0) {
                contentUrl = null;
            }
        } else if (token.startsWith("mimetype=")) {
            mimetype = token.substring(9);
            if (mimetype.length() == 0) {
                mimetype = null;
            }
        } else if (token.startsWith("size=")) {
            String sizeStr = token.substring(5);
            if (sizeStr.length() > 0) {
                size = Long.parseLong(sizeStr);
            }
        } else if (token.startsWith("encoding=")) {
            encoding = token.substring(9);
            if (encoding.length() == 0) {
                encoding = null;
            }
        } else if (token.startsWith("locale=")) {
            String localeStr = token.substring(7);
            if (localeStr.length() > 0) {
                locale = I18NUtil.parseLocale(localeStr);
            }
        }
    }

    // [talendalfresco] if no mimetype, let's guess it
    if (mimetype == null) {
        mimetype = mimetypeService.guessMimetype(contentUrl);
    }

    ContentData property = new ContentData(contentUrl, mimetype, size, encoding, locale);
    // done
    return property;
}

From source file:Main.java

/**
 * Replaces all contiguous sequences of #x9 (tab), #xA (line feed) and #xD
 * (carriage return) with a single #x20 (space) character, and removes any
 * leading and trailing whitespace characters, as specified for whiteSpace
 * facet <tt>collapse</tt>.//from  ww  w. java 2 s  .c  o m
 */
public static String collapseWhiteSpace(String s) {
    StringBuilder sb = new StringBuilder(s.length());

    StringTokenizer st = new StringTokenizer(s, "\t\r\n ");

    if (st.hasMoreTokens()) {
        sb.append(st.nextToken());
    }

    while (st.hasMoreTokens()) {
        sb.append(' ').append(st.nextToken());
    }

    return sb.toString();
}

From source file:Main.java

/**
 * Returns a reference to a file with the specified name that is located
 * somewhere on the classpath. The code for this method is an adaptation of
 * code supplied by Dave Postill./*from   w  w  w. j a va2  s .c om*/
 * 
 * @param name
 *          the filename.
 * 
 * @return a reference to a file or <code>null if no file could be
 *         found.
 */
public static File findFileOnClassPath(final String name) {

    final String classpath = System.getProperty("java.class.path");
    final String pathSeparator = System.getProperty("path.separator");

    final StringTokenizer tokenizer = new StringTokenizer(classpath, pathSeparator);

    while (tokenizer.hasMoreTokens()) {
        final String pathElement = tokenizer.nextToken();

        final File directoryOrJar = new File(pathElement);
        final File absoluteDirectoryOrJar = directoryOrJar.getAbsoluteFile();

        if (absoluteDirectoryOrJar.isFile()) {
            final File target = new File(absoluteDirectoryOrJar.getParent(), name);
            if (target.exists()) {
                return target;
            }
        } else {
            final File target = new File(directoryOrJar, name);
            if (target.exists()) {
                return target;
            }
        }

    }
    return null;

}

From source file:com.edmunds.etm.runtime.api.ApplicationVersion.java

private static Integer getNextIntegerToken(StringTokenizer tok) {
    String s = tok.nextToken();
    if ((s.length() > 1) && s.startsWith("0")) {
        throw new NumberFormatException("Number part has a leading 0: '" + s + "'");
    }//from  www  .  j a v  a 2s.co  m
    return Integer.valueOf(s);
}

From source file:com.opensymphony.xwork2.config.ConfigurationUtil.java

/**
 * Splits the string into a list using a comma as the token separator.
 * @param parent The comma separated string.
 * @return A list of tokens from the specified string.
 *//*from   w ww.j a  v  a  2  s.co m*/
public static List<String> buildParentListFromString(String parent) {
    if (StringUtils.isEmpty(parent)) {
        return Collections.emptyList();
    }

    StringTokenizer tokenizer = new StringTokenizer(parent, ",");
    List<String> parents = new ArrayList<>();

    while (tokenizer.hasMoreTokens()) {
        String parentName = tokenizer.nextToken().trim();

        if (StringUtils.isNotEmpty(parentName)) {
            parents.add(parentName);
        }
    }

    return parents;
}

From source file:edu.cmu.cs.lti.ark.fn.data.prep.ParsePreparation.java

/**
 * Converts a POS tagged file into conll format
 * @param posFile/*from   ww w . j  av a2s.c o m*/
 * @param conllInputFile
 */
public static void printCoNLLTypeInput(String posFile, String conllInputFile) throws IOException {
    List<String> posSentences = readLines(posFile);
    BufferedWriter bWriter = new BufferedWriter(new FileWriter(conllInputFile));
    try {
        for (String posSentence : posSentences) {
            posSentence = replaceSentenceWithPTBWords(posSentence);
            ArrayList<String> words = new ArrayList<String>();
            ArrayList<String> pos = new ArrayList<String>();
            ArrayList<String> parents = new ArrayList<String>();
            ArrayList<String> labels = new ArrayList<String>();
            StringTokenizer st = new StringTokenizer(posSentence.trim());
            while (st.hasMoreTokens()) {
                String token = st.nextToken();
                int lastIndex = token.lastIndexOf('_');
                String word = token.substring(0, lastIndex);
                String POS = token.substring(lastIndex + 1);
                words.add(word);
                pos.add(POS);
                parents.add("0");
                labels.add("SUB");
            }
            writeStuff(bWriter, words, pos, parents, labels);
        }
    } finally {
        IOUtils.closeQuietly(bWriter);
    }
}

From source file:Main.java

/**
 * Parses a string into a locale. The string is expected to be of the same
 * format of the string obtained by calling Locale.toString().
 * //  w  w  w .j  a  va2  s  .  co  m
 * @param localeString
 *            string representation of a locale
 * @return a locale or <code>null</code> if string is empty or null
 */
public static Locale parseLocale(String localeString) {
    if (localeString == null || localeString.trim().length() == 0) {
        return null;
    }
    StringTokenizer tokens = new StringTokenizer(localeString, "_"); //$NON-NLS-1$
    List<String> localeSections = new ArrayList<String>();
    while (tokens.hasMoreTokens()) {
        localeSections.add(tokens.nextToken());
    }
    Locale locale = null;
    switch (localeSections.size()) {
    case 1:
        locale = new Locale(localeSections.get(0));
        break;
    case 2:
        locale = new Locale(localeSections.get(0), localeSections.get(1));
        break;
    case 3:
        locale = new Locale(localeSections.get(0), localeSections.get(1), localeSections.get(2));
        break;
    default:
        break;
    }
    return locale;
}

From source file:com.evolveum.liferay.usercreatehook.ws.WSConfig.java

public static List<String> getAllwaysPermittedEmailDomains() {
    List<String> result = new ArrayList<String>();
    String value = PropsUtil.get(PROPERTY_EMAIL_DOMAINS_ALLWAYS_PERMITTED);
    if (!StringUtils.isBlank(value)) {
        StringTokenizer st = new StringTokenizer(value, ",");
        while (st.hasMoreTokens()) {
            String domain = st.nextToken().trim().toLowerCase();
            result.add(domain);//from w ww.ja va  2 s .c  o m
        }
    }
    LOG.debug("Property '" + PROPERTY_EMAIL_DOMAINS_ALLWAYS_PERMITTED + "'  value: '" + value
            + "'. Used domains from list: '" + result + "'");
    return result;
}

From source file:com.silverpeas.components.model.AbstractSpringJndiDaoTest.java

/**
 * Workaround to be able to use Sun's JNDI file system provider on Unix
 *
 * @param ic : the JNDI initial context/*from  w  w w  .j a  v a  2  s.c o  m*/
 * @param jndiName : the binding name
 * @param ref : the reference to be bound
 * @throws NamingException
 */
protected static void rebind(InitialContext ic, String jndiName, Object ref) throws NamingException {
    Context currentContext = ic;
    StringTokenizer tokenizer = new StringTokenizer(jndiName, "/", false);
    while (tokenizer.hasMoreTokens()) {
        String name = tokenizer.nextToken();
        if (tokenizer.hasMoreTokens()) {
            try {
                currentContext = (Context) currentContext.lookup(name);
            } catch (javax.naming.NameNotFoundException nnfex) {
                currentContext = currentContext.createSubcontext(name);
            }
        } else {
            currentContext.rebind(name, ref);
        }
    }
}