Example usage for java.util StringTokenizer hasMoreElements

List of usage examples for java.util StringTokenizer hasMoreElements

Introduction

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

Prototype

public boolean hasMoreElements() 

Source Link

Document

Returns the same value as the hasMoreTokens method.

Usage

From source file:org.tinygroup.jspengine.compiler.TldLocationsCache.java

/**
 * Sets the list of JAR files that are known not to contain any TLDs.
 * //from w  w w.j a  va 2 s.co  m
 * Only shared JAR files (that is, those loaded by a delegation parent of
 * the webapp's classloader) will be checked against this list.
 * 
 * @param jarNames
 *            List of comma-separated names of JAR files that are known not
 *            to contain any TLDs
 */
public static void setNoTldJars(String jarNames) {
    if (jarNames != null) {
        if (noTldJars == null) {
            noTldJars = new HashSet<String>();
        } else {
            noTldJars.clear();
        }
        StringTokenizer tokenizer = new StringTokenizer(jarNames, ",");
        while (tokenizer.hasMoreElements()) {
            noTldJars.add(tokenizer.nextToken());
        }
    }
}

From source file:edu.lternet.pasta.common.EmlUtility.java

public static EmlPackageId emlPackageIdFromEML(File emlFile) throws Exception {
    EmlPackageId emlPackageId = null;//from  w  w w.ja v  a2s  .  c o  m

    if (emlFile != null) {
        String emlString = FileUtils.readFileToString(emlFile);
        try {
            DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document document = documentBuilder.parse(IOUtils.toInputStream(emlString));
            emlPackageId = getEmlPackageId(document);
        }
        /*
         * If a parsing exception is thrown, attempt to parse the packageId
         * using regular expressions. This could be fooled by comments text
         * in the EML document but is still better than nothing at all.
         */
        catch (SAXException e) {
            StringTokenizer stringTokenizer = new StringTokenizer(emlString, "\n");
            String DOUBLE_QUOTE_PATTERN = "packageId=\"([^\"]*)\"";
            String SINGLE_QUOTE_PATTERN = "packageId='([^']*)'";
            Pattern doubleQuotePattern = Pattern.compile(DOUBLE_QUOTE_PATTERN);
            Pattern singleQuotePattern = Pattern.compile(SINGLE_QUOTE_PATTERN);
            while (stringTokenizer.hasMoreElements()) {
                String token = stringTokenizer.nextToken();
                if (token.contains("packageId")) {

                    Matcher doubleQuoteMatcher = doubleQuotePattern.matcher(token);
                    if (doubleQuoteMatcher.find()) {
                        String packageId = doubleQuoteMatcher.group(1);
                        System.out.println(packageId);
                        EmlPackageIdFormat formatter = new EmlPackageIdFormat(Delimiter.DOT);
                        emlPackageId = formatter.parse(packageId);
                        break;
                    }

                    Matcher singleQuoteMatcher = singleQuotePattern.matcher(token);
                    if (singleQuoteMatcher.find()) {
                        String packageId = singleQuoteMatcher.group(1);
                        EmlPackageIdFormat formatter = new EmlPackageIdFormat(Delimiter.DOT);
                        emlPackageId = formatter.parse(packageId);
                        break;
                    }

                }
            }
        }
    }

    return emlPackageId;
}

From source file:org.wso2.carbon.apimgt.core.util.APIUtils.java

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "DM_CONVERT_CASE", justification = "Didn't need to do "
        + "as String already did internally")

/**/*  w ww .j  ava 2  s.c om*/
 * used to generate operationId according to the uri template and http verb
 */
public static String generateOperationIdFromPath(String path, String httpVerb) {
    //TODO need to write proper way of creating operationId
    StringTokenizer stringTokenizer = new StringTokenizer(path, "/");
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(httpVerb.toLowerCase());
    while (stringTokenizer.hasMoreElements()) {
        String part1 = stringTokenizer.nextToken();
        if (part1.contains("{")) {
            /*
                            stringBuilder.append("By" + pathParam);
            */
        } else if (part1.contains("*")) {
            stringBuilder.append(part1.replaceAll("\\*", "_star_"));
        } else {
            stringBuilder.append(part1);
        }
    }
    return stringBuilder.toString();
}

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  .  ja  v a2s . co 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:eionet.cr.web.util.JstlFunctions.java

/**
 *
 * @param stackTrace/*from w  w w  . j ava  2s  .c  om*/
 * @return
 */
public static String formatStackTrace(String stackTrace) {

    if (stackTrace == null || stackTrace.trim().length() == 0) {
        return stackTrace;
    }

    StringBuilder buf = new StringBuilder();
    StringTokenizer lines = new StringTokenizer(stackTrace, "\r\n");
    while (lines != null && lines.hasMoreElements()) {
        String line = lines.nextToken();
        line = StringUtils.replaceOnce(line, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
        buf.append(line).append("<br/>");
    }

    return buf.length() == 0 ? stackTrace : buf.toString();
}

From source file:org.web4thejob.studio.support.StudioUtil.java

public static String getQueryParam(String query, String param) {
    if (query == null)
        return null;
    notNull(param);// w ww .j a  va 2s  .co  m
    StringTokenizer tokenizer = new StringTokenizer(query, "&", false);
    while (tokenizer.hasMoreElements()) {
        String token = tokenizer.nextToken().trim();
        if (token.startsWith(param) && token.contains("=")) {
            return token.split("=")[1];
        }
    }
    return null;
}

From source file:org.yamj.core.tools.web.HTMLTools.java

/**
 * Example: src = "<a id="specialID"><br/> <img src="a.gif"/>my text</a> findStr = "specialID" result = "my text"
 *
 * @param src html text/*  www  .j a v  a2s . c  o m*/
 * @param findStr string to find in src
 * @param skip count of found texts to skip
 * @param fromIndex begin index in src
 * @return string from html text which is plain text without html tags
 */
public static String getTextAfterElem(String src, String findStr, int skip, int fromIndex) {
    int beginIndex = src.indexOf(findStr, fromIndex);
    if (beginIndex == -1) {
        return StringUtils.EMPTY;
    }
    StringTokenizer st = new StringTokenizer(src.substring(beginIndex + findStr.length()), "<");
    int i = 0;
    while (st.hasMoreElements()) {
        String elem = st.nextToken().replaceAll("&nbsp;|&#160;", "").trim();
        if (elem.length() != 0 && !elem.endsWith(">") && i++ >= skip) {
            String[] elems = elem.split(">");
            if (elems.length > 1) {
                return HTMLTools.decodeHtml(elems[1].trim());
            } else {
                return HTMLTools.decodeHtml(elems[0].trim());
            }
        }
    }
    return StringUtils.EMPTY;
}

From source file:com.liusoft.dlog4j.util.StringUtils.java

/**
 * // www . j a  v a  2 s .  c  om
 * @param tags
 * @return
 */
public static List stringToList(String tags) {
    if (tags == null)
        return null;
    ArrayList tagList = new ArrayList();
    StringTokenizer st = new StringTokenizer(tags);
    while (st.hasMoreElements()) {
        tagList.add(st.nextToken());
    }
    return tagList;
}

From source file:com.liusoft.dlog4j.util.StringUtils.java

/**
 * ch/*w  ww .  j av a 2 s . c o  m*/
 * @param tags
 * @param ch
 * @return
 */
public static List stringToList(String tags, String ch) {
    if (tags == null)
        return null;
    ArrayList tagList = new ArrayList();
    StringTokenizer st = new StringTokenizer(tags, ch);
    while (st.hasMoreElements()) {
        tagList.add(st.nextToken());
    }
    return tagList;
}

From source file:Utilities.java

/** Convert a space-separated list of Emacs-like key binding names to a list of Swing key strokes.
* @param s the string with keys//from   w  w  w .j ava 2  s . c  om
* @return array of key strokes, or <code>null</code> if the string description is not valid
* @see #stringToKey
*/
public static KeyStroke[] stringToKeys(String s) {
    StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), " "); // NOI18N
    ArrayList<KeyStroke> arr = new ArrayList<KeyStroke>();

    while (st.hasMoreElements()) {
        s = st.nextToken();

        KeyStroke k = stringToKey(s);

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

        arr.add(k);
    }

    return arr.toArray(new KeyStroke[arr.size()]);
}