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.qiongsong.ficus.dal.internal.DDLFormatterImpl.java

private String formatCommentOn(String sql) {
    final StringBuilder result = new StringBuilder(60).append("\n    ");
    final StringTokenizer tokens = new StringTokenizer(sql, " '[]\"", true);

    boolean quoted = false;
    while (tokens.hasMoreTokens()) {
        final String token = tokens.nextToken();
        result.append(token);/*  www.j  a  va  2  s.  co  m*/
        if (isQuote(token)) {
            quoted = !quoted;
        } else if (!quoted) {
            if ("is".equals(token)) {
                result.append("\n       ");
            }
        }
    }

    return result.toString();
}

From source file:ca.uhn.fhir.rest.method.QualifiedParamList.java

public static QualifiedParamList splitQueryStringByCommasIgnoreEscape(String theQualifier, String theParams) {
    QualifiedParamList retVal = new QualifiedParamList();
    retVal.setQualifier(theQualifier);//w w  w  .j a v  a2 s . c o m

    StringTokenizer tok = new StringTokenizer(theParams, ",", true);
    String prev = null;
    while (tok.hasMoreElements()) {
        String str = tok.nextToken();
        if (isBlank(str)) {
            prev = null;
            continue;
        }

        if (str.equals(",")) {
            if (countTrailingSlashes(prev) % 2 == 1) {
                int idx = retVal.size() - 1;
                String existing = retVal.get(idx);
                prev = existing.substring(0, existing.length() - 1) + ',';
                retVal.set(idx, prev);
            } else {
                prev = null;
            }
            continue;
        }

        if (prev != null && prev.length() > 0 && prev.charAt(prev.length() - 1) == ',') {
            int idx = retVal.size() - 1;
            String existing = retVal.get(idx);
            prev = existing + str;
            retVal.set(idx, prev);
        } else {
            retVal.add(str);
            prev = str;
        }

    }

    return retVal;
}

From source file:sample.service.ProductService.java

public List<Product> searchProductList(String keywords) {
    List<String> keywordList = new ArrayList<String>();
    for (StringTokenizer tokenizer = new StringTokenizer(keywords.toLowerCase(), " ", false); tokenizer
            .hasMoreTokens();) {//from  ww  w  . j av  a2  s. c o m
        keywordList.add(tokenizer.nextToken());
    }
    return productDao.selectProductList(keywordList, SelectOptions.get());
}

From source file:Main.java

public static Pattern compilePattern(String key, boolean ignoreCase) {
    StringTokenizer stk = new StringTokenizer(key, "*?", true);
    StringBuilder regex = new StringBuilder();
    while (stk.hasMoreTokens()) {
        String tk = stk.nextToken();
        char ch1 = tk.charAt(0);
        if (ch1 == '*') {
            regex.append(".*");
        } else if (ch1 == '?') {
            regex.append(".");
        } else {//from   ww w .  java  2  s .  c om
            regex.append("\\Q").append(tk).append("\\E");
        }
    }
    return Pattern.compile(regex.toString(), ignoreCase ? Pattern.CASE_INSENSITIVE : 0);
}

From source file:de.elbe5.base.util.StringUtil.java

public static String toHtmlText(String src) {
    if (src == null) {
        return "";
    }//w w w.  jav  a  2s.com
    if (src.indexOf('\n') == -1)
        return StringEscapeUtils.escapeHtml4(src);

    StringTokenizer stk = new StringTokenizer(src, "\n", true);
    if (stk.countTokens() == 0)
        return "";
    StringBuilder sb = new StringBuilder();
    String token;
    while (stk.hasMoreTokens()) {
        token = stk.nextToken();
        if (token.equals("\n"))
            sb.append("\n<br/>\n");
        else
            sb.append(StringEscapeUtils.escapeHtml4(token));
    }
    return sb.toString();
}

From source file:it.eng.spagobi.commons.utilities.PortletUtilities.java

/**
 * Starting from the original URL and the request, creates a string representing the
 * Portlet URL./*from  w  w  w  .j  a v a  2s.  co  m*/
 * 
 * @param aHttpServletRequest The request object at input
 * @param originalURL The starting original URL
 * 
 * @return A String representing the Portlet URL
 */
public static String createPortletURL(HttpServletRequest aHttpServletRequest, String originalURL) {

    RenderResponse renderResponse = (RenderResponse) aHttpServletRequest.getAttribute("javax.portlet.response");

    PortletURL aPortletURL = renderResponse.createActionURL();

    logger.debug("Original URL.... " + originalURL + "indexOf ? is " + originalURL.indexOf("?"));

    String parameters = originalURL.substring(originalURL.indexOf("?") + 1);

    StringTokenizer st = new StringTokenizer(parameters, "&", false);

    String parameterToken = null;
    String parameterName = null;
    String parameterValue = null;
    while (st.hasMoreTokens()) {
        parameterToken = st.nextToken();
        logger.debug("Parameter Token [" + parameterToken + "]");

        parameterName = parameterToken.substring(0, parameterToken.indexOf("="));
        parameterValue = parameterToken.substring(parameterToken.indexOf("=") + 1);

        logger.debug("Parameter Name [" + parameterName + "]");
        logger.debug("Parameter Value [" + parameterValue + "]");

        aPortletURL.setParameter(parameterName, parameterValue);
    }

    return aPortletURL.toString();
}

From source file:de.tudarmstadt.ukp.csniper.webapp.search.tgrep.PennTreeUtils.java

public static PennTreeNode parsePennTree(String aTree) {
    StringTokenizer st = new StringTokenizer(aTree, "() ", true);

    PennTreeNode root = null;//  w w w . ja  va  2 s. c  o  m
    Stack<PennTreeNode> stack = new Stack<PennTreeNode>();
    boolean seenLabel = false;
    int i = 0;
    while (st.hasMoreTokens()) {
        String t = st.nextToken().trim();
        if (t.length() == 0) {
            // Skip
        } else if ("(".equals(t)) {
            PennTreeNode n = new PennTreeNode();
            stack.push(n);
            if (root == null) {
                root = n;
            }
            seenLabel = false;
        } else if (")".equals(t)) {
            PennTreeNode n = stack.pop();
            if (!stack.isEmpty()) {
                PennTreeNode p = stack.peek();
                p.addChild(n);
            }
        } else if (seenLabel) {
            // If the node has two labels, its a leaf, add a new terminal node then.
            PennTreeNode p = stack.peek();
            PennTreeNode n = new PennTreeNode();
            n.setTokenIndex(i);
            i++;
            n.setLabel(t);
            p.addChild(n);
        } else {
            PennTreeNode n = stack.peek();
            n.setLabel(t);
            seenLabel = true;
        }
    }

    return root;
}

From source file:net.lightbody.bmp.proxy.jetty.http.InclusiveByteRange.java

/** 
 * @param headers Enumeration of Range header fields.
 * @param size Size of the resource./* ww w  .  j a va 2s. c o  m*/
 * @return LazyList of satisfiable ranges
 */
public static List satisfiableRanges(Enumeration headers, long size) {
    Object satRanges = null;

    // walk through all Range headers
    headers: while (headers.hasMoreElements()) {
        String header = (String) headers.nextElement();
        StringTokenizer tok = new StringTokenizer(header, "=,", false);
        String t = null;
        try {
            // read all byte ranges for this header 
            while (tok.hasMoreTokens()) {
                t = tok.nextToken().trim();

                long first = -1;
                long last = -1;
                int d = t.indexOf('-');
                if (d < 0 || t.indexOf("-", d + 1) >= 0) {
                    if ("bytes".equals(t))
                        continue;
                    log.warn("Bad range format: " + t);
                    continue headers;
                } else if (d == 0) {
                    if (d + 1 < t.length())
                        last = Long.parseLong(t.substring(d + 1).trim());
                    else {
                        log.warn("Bad range format: " + t);
                        continue headers;
                    }
                } else if (d + 1 < t.length()) {
                    first = Long.parseLong(t.substring(0, d).trim());
                    last = Long.parseLong(t.substring(d + 1).trim());
                } else
                    first = Long.parseLong(t.substring(0, d).trim());

                if (first == -1 && last == -1)
                    continue headers;

                if (first != -1 && last != -1 && (first > last))
                    continue headers;

                if (first < size) {
                    InclusiveByteRange range = new InclusiveByteRange(first, last);
                    satRanges = LazyList.add(satRanges, range);
                }
            }
        } catch (Exception e) {
            log.warn("Bad range format: " + t);
            LogSupport.ignore(log, e);
        }
    }
    return LazyList.getList(satRanges, true);
}

From source file:info.magnolia.cms.taglibs.util.ConvertNewLineTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *///  w  ww . jav  a2s.  c o  m
public int doEndTag() throws JspException {
    String bodyText = bodyContent.getString();

    if (StringUtils.isNotEmpty(bodyText)) {
        StringTokenizer bodyTk = new StringTokenizer(bodyText, "\n", false); //$NON-NLS-1$
        JspWriter out = pageContext.getOut();

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

From source file:com.agimatec.validation.jsr303.NestedMetaProperty.java

void parse() {
    try {//ww  w . j a v  a2 s  . co m
        StringTokenizer tokens = new StringTokenizer(propertyPath, ".[]", true);
        while (tokens.hasMoreTokens()) {
            String token = tokens.nextToken();
            if ("[".equals(token)) {
                String sindex = tokens.nextToken();
                int idx = Integer.parseInt(sindex);
                token = tokens.nextToken();
                if (!"]".equals(token)) {
                    throw new ValidationException("']' missing, invalid property format: " + propertyPath);
                }
                useIndexedValue(idx);
                resolveMetaBean();
            } else if (!".".equals(token)) { // it is a property name
                MetaProperty mp = getMetaBean().getProperty(token);
                if (mp == null) {
                    throw new ValidationException(
                            "unknown property '" + token + "' in " + getMetaBean().getId());
                }
                if (getValue() != null) {
                    setValue(PropertyAccess.getProperty(getValue(), token));
                }
                setMetaProperty(mp);
                resolveMetaBean();
            }
        }
    } catch (ValidationException ex) {
        throw ex; // route exception
    } catch (Exception ex) { // wrap exception
        throw new ValidationException("invalid property format: " + propertyPath, ex);

    }
}