Example usage for java.util StringTokenizer StringTokenizer

List of usage examples for java.util StringTokenizer StringTokenizer

Introduction

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

Prototype

public StringTokenizer(String str, String delim, boolean returnDelims) 

Source Link

Document

Constructs a string tokenizer for the specified string.

Usage

From source file:com.joliciel.talismane.utils.DaoUtils.java

public static List<String> getSelectArray(String selectString, String alias) {
    List<String> selectArray = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(selectString, ",", false);
    boolean haveAlias = alias != null && alias.length() > 0;
    while (st.hasMoreTokens()) {
        String column = st.nextToken().trim();
        if (haveAlias)
            selectArray.add(alias + "." + column + " as " + alias + "_" + column);
        else//from  ww w  .  ja  va2  s  .  c o m
            selectArray.add(column);

    }
    return selectArray;
}

From source file:elaborate.util.StringUtil.java

@SuppressWarnings("boxing")
public static String replace(String originalTerm, String replacementTerm, String body,
        List<Integer> occurrencesToReplace, boolean preserveCase) {
    StringTokenizer tokenizer = new StringTokenizer(body, DELIM, true);

    // Log.info("body:[{}]", body);
    StringBuilder replaced = new StringBuilder(body.length());
    int occurrence = 1;
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        DelimiterDetector delimiterDetector = new DelimiterDetector(token);
        String strippedToken = delimiterDetector.getStripped();
        if (strippedToken.equalsIgnoreCase(originalTerm)) {
            String replacement = preserveCase ? TextCase.detectCase(strippedToken).applyTo(replacementTerm)
                    : replacementTerm;//from ww w. j a v  a2s. co  m
            replaced.append(occurrencesToReplace.contains(occurrence)
                    ? delimiterDetector.getPreDelimiters() + replacement + delimiterDetector.getPostDelimiters()
                    : token);
            occurrence++;
        } else {
            replaced.append(token);
        }
    }
    // Log.info("replaced:[{}]", replaced);
    return replaced.toString();
}

From source file:info.magnolia.templating.jsp.taglib.ConvertNewLineTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *//*  w w  w  .ja  va2 s  . co  m*/
@Override
public int doEndTag() throws JspException {
    String bodyText = bodyContent.getString();

    if (StringUtils.isNotEmpty(bodyText)) {
        StringTokenizer bodyTk = new StringTokenizer(bodyText, "\n", false);
        JspWriter out = pageContext.getOut();

        try {
            if (this.para) {
                // wrap text in p
                while (bodyTk.hasMoreTokens()) {
                    out.write("<p>");
                    out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\''));
                    out.write("</p>");
                }
            } else {
                // add newlines
                while (bodyTk.hasMoreTokens()) {
                    out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\''));
                    if (bodyTk.hasMoreTokens()) {
                        out.write("<br/>");
                    }
                }
            }
        } catch (IOException e) {
            throw new JspTagException(e.getMessage());
        }
    }
    return EVAL_PAGE;
}

From source file:com.orientechnologies.orient.jdbc.H2.java

public static Collection<String> translate(String sql) throws SQLException {
    List<String> sections = new ArrayList<String>();
    if (StringUtils.isNotEmpty(sql)) {
        boolean quoted = false;
        int bracesOpen = 0;
        boolean create = false;
        boolean type = false;
        boolean typeLen = false;
        boolean not = false;
        int max = 0;
        String lastWord = null;// w w w  . ja  v  a  2  s .c o m
        String className = null;
        String fieldName = null;
        boolean classNameAppended = false;
        StringBuffer section = new StringBuffer();

        for (final StringTokenizer splitter = new StringTokenizer(sql, " ();,'`\r\n\t", true); splitter
                .hasMoreTokens();) {
            String w = splitter.nextToken();
            if (w.length() == 0)
                continue;

            if (!quoted) {
                w = w.toUpperCase();
                if (stripWords.contains(w) || (SPACE.equals(w)))
                    section.append(SPACE_CHAR);
                else if (QUOTE.equals(w) || QUOTE_ALT.equals(w)) {
                    section.append(w);
                    if (QUOTE_ALT.equals(w) && !quoted)
                        w = QUOTE;
                    if (QUOTE.equals(w) && !QUOTE.equals(lastWord))
                        quoted = !quoted;
                } else if (BRACE_OPEN.equals(w)) {
                    bracesOpen++;
                    if (create) {
                        trim(section);
                        if (!type) {
                            sections.add(section.toString());
                            section = new StringBuffer("CREATE PROPERTY ");
                            section.append(className).append('.');
                        } else {
                            sections.add(section.toString());
                            section = new StringBuffer("ALTER PROPERTY ");
                            section.append(className).append('.');
                            section.append(fieldName).append(" MAX ");
                            typeLen = true;
                        }
                    } else
                        section.append(w);

                } else if (BRACE_CLOSED.equals(w)) {
                    bracesOpen--;
                    if (create) {
                        if (typeLen) {
                            trim(section);
                            section.append(SPACE_CHAR).append(max);
                            typeLen = false;
                            max = 0;
                            section.append(SPACE_CHAR);
                            continue;
                        } else if (type) {
                            type = false;
                            classNameAppended = false;
                        } else
                            create = false;
                    }
                    section.append(w);
                } else if (COMMA.equals(w)) {
                    if (create) {
                        if (type) {
                            if (!typeLen) {
                                trim(section);
                                sections.add(section.toString());
                                section = new StringBuffer("CREATE PROPERTY ");
                                section.append(className).append('.');
                                type = false;
                                classNameAppended = true;
                                fieldName = null;
                            } else
                                max++;
                        } else
                            section.append(w);
                    }
                } else if (create) {
                    if (type) {
                        boolean suppw = supportedWords.contains(w);
                        if (typeLen || suppw) {
                            if (suppw) {
                                if (NOT.equals(w)) {
                                    not = true;
                                    continue;
                                } else {
                                    trim(section);
                                    sections.add(section.toString());
                                    section = new StringBuffer("ALTER PROPERTY ");
                                    section.append(className).append('.');
                                    section.append(fieldName);
                                    if (not) {
                                        section.append(" NOT");
                                        not = false;
                                    }
                                    if (NULL.equals(w)) {
                                        if (section.lastIndexOf(NOT) == section.length() - 3)
                                            section.append(w).append("=TRUE");
                                        else
                                            section.append(SPACE_CHAR).append(NOT).append(w).append("=FALSE");
                                    } else
                                        section.append(w);
                                }
                            } else
                                max += Integer.parseInt(w);
                        } else {
                            final String mtype = typeMap.get(w);
                            if (StringUtils.isEmpty(mtype))
                                throw new SQLException(String
                                        .format("Sorry, type %s is not supported by Orient at the moment.", w));
                            section.append(mtype);
                        }

                    } else if (!classNameAppended) {
                        className = w;
                        section.append(className);
                        classNameAppended = true;
                    } else {
                        if (section.charAt(section.length() - 1) == SPACE_CHAR)
                            section.deleteCharAt(section.length() - 1);
                        section.append(w);
                        fieldName = w;
                        type = true;
                    }
                } else if (supportedWords.contains(w))
                    section.append(w);
                else if (SEMICOLON.equals(w)) {
                    trim(section);
                    sections.add(section.toString());
                    section = new StringBuffer();
                } else if (TABLE.equals(w)) {
                    section.append(CLASS);
                    create = true;
                } else
                    section.append(w);
            } else
                section.append(w);
        }
    }
    return sections;
}