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) 

Source Link

Document

Constructs a string tokenizer for the specified string.

Usage

From source file:at.tuwien.minimee.util.PslistWinParser.java

private void parseLine(String line) throws IOException {

    StringTokenizer tokenizer = new StringTokenizer(line, " ");

    if (!tokenizer.hasMoreTokens()) {
        return;//  www  . ja  v  a 2 s.  co  m
    }

    String start = tokenizer.nextToken();

    if (start.compareTo("Name") == 0) {
        this.dataLine = true;
        return;
    } else if (!dataLine)
        return;

    // only if dataline is true can read the informations
    WinProcessExecutionFootprint pfp = parseProcessLine(tokenizer);
    line = input.readLine();
    line = input.readLine();
    tokenizer = new StringTokenizer(line, " ");

    if (line != null && line != "")
        parseProcessTimeLine(tokenizer, pfp);

    list.add(pfp);

    dataLine = false;
    // }

}

From source file:Main.java

protected static List<String> splitTrimmed(String text, String separator) {
    List<String> parts = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(text, separator);
    while (st.hasMoreTokens()) {
        String token = st.nextToken().trim();
        if (token.length() > 0) {
            parts.add(token);/*w ww.j  a  v a2 s . c  om*/
        }
    }
    return parts;
}

From source file:com.nanyou.framework.jdbc.sql.dynamic.DynamicSql.java

private void findChildren(DynamicParent parent, String sql) {
    try {/*from w ww  . ja v a2s.  co m*/
        sql = StringUtils.remove(sql, ";");

        BufferedReader in = new BufferedReader(new StringReader(sql));
        while (true) {
            String line = in.readLine();
            if (line == null) {
                break;
            }
            if (StringUtils.trim(line).startsWith("--<")) {
                line = StringUtils.trim(line);
                line = new String(line.substring(3, line.lastIndexOf('>')));
                StringTokenizer st = new StringTokenizer(line, "= \t");
                String tagName = st.nextToken();
                SqlTag child = new SqlTag();
                child.setName(tagName);
                child.setHandler(SqlTagHandlerFactory.getSqlTagHandler(tagName));
                while (st.hasMoreTokens()) {
                    String key = st.nextToken();
                    String value = StringUtils.remove(st.nextToken(), "\"");
                    if ("prepend".equalsIgnoreCase(key)) {
                        child.setPrependAttr(value);
                    } else if ("property".equalsIgnoreCase(key)) {
                        child.setPropertyAttr(value);
                    } else if ("open".equalsIgnoreCase(key)) {
                        child.setOpenAttr(value);
                    } else if ("close".equalsIgnoreCase(key)) {
                        child.setCloseAttr(value);
                    } else if ("conjunction".equalsIgnoreCase(key)) {
                        child.setConjunctionAttr(value);
                    } else if ("compareProperty".equalsIgnoreCase(key)) {
                        child.setComparePropertyAttr(value);
                    } else if ("compareValue".equalsIgnoreCase(key)) {
                        child.setCompareValueAttr(value);
                    }
                }
                String endTagName = "</" + tagName + ">";
                StringBuffer sb = new StringBuffer();
                while (true) {
                    line = in.readLine();
                    if (line == null) {
                        break;
                    }
                    if (line.indexOf(endTagName) > 0) {
                        break;
                    }
                    sb.append(line).append("\n");
                }
                findChildren(child, sb.toString());
                parent.addChild(child);
            } else {
                SqlText child = new SqlText();
                ((SqlText) child).setText(line);
                parent.addChild(child);
            }
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.web4thejob.sandbox.web.panel.DefaultHelpPanel.java

@Override
public void processMessage(Message message) {
    if (message.getId() == MessageEnum.ACTIVATED
            && message.getArg(MessageArgEnum.ARG_ITEM, Object.class) instanceof Panel
            && message.getArg(MessageArgEnum.ARG_ITEM, Panel.class).isPersisted()) {

        Panel panel = message.getArg(MessageArgEnum.ARG_ITEM, Panel.class);

        Query query = ContextUtil.getEntityFactory().buildQuery(Document.class);
        Criterion criterion = query.addCriterion(new Path(Document.FLD_CODE), Condition.EQ,
                panel.getBeanName());/*  w  w  w  .ja  v  a 2 s . c o  m*/
        Document doc = ContextUtil.getDRS().findUniqueByQuery(query);
        if (doc != null) {
            bind(doc);
        } else {
            PanelDefinition panelDefinition = ORMUtil.getPanelDefinition(panel.getBeanName());
            if (panelDefinition != null) {
                StringTokenizer tokenizer = new StringTokenizer(panelDefinition.getType(), ", ");
                while (tokenizer.hasMoreTokens()) {
                    criterion.setValue(tokenizer.nextToken());
                    doc = ContextUtil.getDRS().findUniqueByQuery(query);
                    if (doc != null) {
                        bind(doc);
                        break;
                    }
                }
            }

            if (doc == null && activeQuery != null) {
                doc = ContextUtil.getDRS().findUniqueByQuery(activeQuery);
                if (doc != null) {
                    bind(doc);
                }
            }
        }

    }

    super.processMessage(message);
}

From source file:heanetmedia.models.MediaList.java

/**
* Setting the Media list by making a request to media with the proper id, splitting results and adding them to the list as Media objects 
*//*  w w  w .ja v  a2 s . c  om*/
public boolean setMediaList() {
    //Set url(s) with md5 encoded id
    String guid = hashUserId();
    String response = curl(MediaList.listUrl + "UserGUID=" + guid);

    //Splitting response
    StringTokenizer st = new StringTokenizer(response, "[]");

    //Check login then adds data to the list if successful
    if (st.hasMoreTokens() && checkLogin(st.nextToken())) {
        StringTokenizer data = new StringTokenizer(st.nextToken(), "{}");
        String s = null;

        while (data.hasMoreTokens()) {
            s = data.nextToken();

            if (!s.equals(",")) {
                add(new Media(new JSONObject("{" + s + "}")));
            }
        }
    } else {
        return false;
    }

    return true;
}

From source file:Main.java

public void paint(Graphics g) {
    m_fm = g.getFontMetrics();//from   w  w  w .ja v a2  s  .c o m

    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

    g.setColor(getForeground());
    g.setFont(getFont());
    Insets insets = getInsets();
    int x = insets.left;
    int y = insets.top + m_fm.getAscent();

    StringTokenizer st = new StringTokenizer(getText(), "\t");
    while (st.hasMoreTokens()) {
        String str = st.nextToken();
        g.drawString(str, x, y);
        //insert distance for each tab
        x += m_fm.stringWidth(str) + 50;

        if (!st.hasMoreTokens())
            break;
    }
}

From source file:com.xruby.debug.DebugCommandLineOptions.java

public List<URL> getClassPathList() {
    StringTokenizer st = new StringTokenizer(classPath, ";");
    List<URL> list = new ArrayList<URL>();

    while (st.hasMoreTokens()) {
        File file = new File(st.nextToken());
        if (file.exists()) {
            try {
                list.add(file.toURI().toURL());
            } catch (MalformedURLException e) {
                // TODO: Handle this exception
            }/*ww  w  . jav  a 2 s . co  m*/
        }
    }

    return list;
}

From source file:JavaUtils.java

/**
 * Utility to initialise the values of the JRE major/minor version.
 * Assumes the "java.version" string is in the form "XX.YY.ZZ".
 * Works for SUN JRE's./* ww  w  .  ja va  2  s . co m*/
 */
private static void initialiseJREVersion() {
    String version = System.getProperty("java.version");

    // Assume that the version string is of the form XX.YY.ZZ (works for SUN JREs)
    StringTokenizer tokeniser = new StringTokenizer(version, ".");
    String token = tokeniser.nextToken();
    try {
        Integer ver = new Integer(token);
        majorVersion = ver.intValue();

        token = tokeniser.nextToken();
        ver = new Integer(token);
        minorVersion = ver.intValue();
    } catch (Exception e) {
        // Do nothing
    }
    versionInitialised = true;
}

From source file:net.sourceforge.dvb.projectx.xinput.ftp.FtpVO.java

public void fromString(String string) {
    // Don't use String.split(), because it is not available on jdk 1.2
    StringTokenizer st = new StringTokenizer(string, "|");
    String[] tokens = new String[6];

    for (int i = 0; st.hasMoreTokens() && i < 6; i++)
        tokens[i] = st.nextElement().toString();

    server = tokens[1];//from ww w  . ja  v a2  s  .  c om
    directory = tokens[3];
    user = tokens[4];
    password = tokens[5];

    try {
        Integer.parseInt(tokens[2]);
        port = tokens[2];
    } catch (Exception e) {
        port = null;
    }
}