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:com.sonyericsson.hudson.plugins.gerrit.trigger.dependency.DependencyQueueTaskDispatcher.java

/**
 * Return a list of Abstract Projects from their string names.
 * @param projects The string containing the projects, comma-separated.
 * @param context The context in which to read the string
 * @return the list of projects// w  w  w. j a  v  a  2 s .c  om
 */
public static List<Job> getProjectsFromString(String projects, Item context) {
    List<Job> dependencyJobs = new ArrayList<Job>();
    if (StringUtils.isEmpty(projects)) {
        return null;
    } else {
        Jenkins jenkins = Jenkins.getInstance();
        assert jenkins != null;
        StringTokenizer tokens = new StringTokenizer(projects, ",");
        while (tokens.hasMoreTokens()) {
            String projectName = tokens.nextToken().trim();
            if (!projectName.isEmpty()) {
                Item item = jenkins.getItem(projectName, context, Item.class);
                if ((item != null) && (item instanceof Job)) {
                    dependencyJobs.add((Job) item);
                    logger.debug("project dependency job added : {}", item);
                }
            }
        }
    }
    return dependencyJobs;
}

From source file:FTPApp.java

public static int getFileSize(FtpClient client, String fileName) throws IOException {
    TelnetInputStream lst = client.list();
    String str = "";
    fileName = fileName.toLowerCase();//from  w  w w . j av  a2 s  .  c om
    while (true) {
        int c = lst.read();
        char ch = (char) c;
        if (c < 0 || ch == '\n') {
            str = str.toLowerCase();
            if (str.indexOf(fileName) >= 0) {
                StringTokenizer tk = new StringTokenizer(str);
                int index = 0;
                while (tk.hasMoreTokens()) {
                    String token = tk.nextToken();
                    if (index == 4)
                        try {
                            return Integer.parseInt(token);
                        } catch (NumberFormatException ex) {
                            return -1;
                        }
                    index++;
                }
            }
            str = "";
        }
        if (c <= 0)
            break;
        str += ch;
    }
    return -1;
}

From source file:com.trackplus.ddl.DataWriter.java

private static void insertBlobData(Connection con, String line) throws DDLException {
    String sql = "INSERT INTO TBLOB(OBJECTID, BLOBVALUE, TPUUID) VALUES(?,?,?)";
    StringTokenizer st = new StringTokenizer(line, ",");
    Integer objectID = Integer.valueOf(st.nextToken());
    String base64Str = st.nextToken();
    byte[] bytes = Base64.decodeBase64(base64Str);
    String tpuid = null;//from   w  w  w .j a va 2s. co m
    if (st.hasMoreTokens()) {
        tpuid = st.nextToken();
    }

    try {
        PreparedStatement preparedStatement = con.prepareStatement(sql);
        preparedStatement.setInt(1, objectID);
        preparedStatement.setBinaryStream(2, new ByteArrayInputStream(bytes), bytes.length);
        preparedStatement.setString(3, tpuid);
        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        throw new DDLException(e.getMessage(), e);
    }
}

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.  ja va  2  s  . 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:com.openkm.dao.ConfigDAO.java

/**
 * Find by pk with a default value//from www .  j a  v a 2s.  co  m
 */
public static List<String> getList(String key, String defaultValue) throws DatabaseException {
    List<String> list = new ArrayList<String>();
    String dbValue = getProperty(key, defaultValue, Config.LIST);
    StringTokenizer st = new StringTokenizer(dbValue, "\t\n\r\f");

    while (st.hasMoreTokens()) {
        String tk = st.nextToken().trim();

        if (tk != null && !tk.equals("")) {
            list.add(tk);
        }
    }

    return list;
}

From source file:de.vanita5.twittnuker.util.net.ssl.AbstractCheckSignatureVerifier.java

public static String[] getCNs(final X509Certificate cert) {
    final LinkedList<String> cnList = new LinkedList<String>();
    /*//from w w w .ja  va2  s.  c o m
     * Sebastian Hauer's original StrictSSLProtocolSocketFactory used
     * getName() and had the following comment:
     *
     * Parses a X.500 distinguished name for the value of the "Common Name"
     * field. This is done a bit sloppy right now and should probably be
     * done a bit more according to <code>RFC 2253</code>.
     *
     * I've noticed that toString() seems to do a better job than getName()
     * on these X500Principal objects, so I'm hoping that addresses
     * Sebastian's concern.
     *
     * For example, getName() gives me this:
     * 1.2.840.113549.1.9.1=#16166a756c6975736461766965734063756362632e636f6d
     *
     * whereas toString() gives me this: EMAILADDRESS=juliusdavies@cucbc.com
     *
     * Looks like toString() even works with non-ascii domain names! I
     * tested it with "&#x82b1;&#x5b50;.co.jp" and it worked fine.
     */

    final String subjectPrincipal = cert.getSubjectX500Principal().toString();
    final StringTokenizer st = new StringTokenizer(subjectPrincipal, ",+");
    while (st.hasMoreTokens()) {
        final String tok = st.nextToken().trim();
        if (tok.length() > 3) {
            if (tok.substring(0, 3).equalsIgnoreCase("CN=")) {
                cnList.add(tok.substring(3));
            }
        }
    }
    if (!cnList.isEmpty()) {
        final String[] cns = new String[cnList.size()];
        cnList.toArray(cns);
        return cns;
    } else
        return null;
}

From source file:net.sf.webphotos.util.Util.java

/**
 * Ajusta a largura das colunas do modelo.
 *
 * @param tabela Tabela que deseja ajustar as colunas.
 * @param parametros Tamanhos das colunas separadas por vrgula.
 *///  w  ww  . j a  v  a2s. c  om
public static void ajustaLargura(JTable tabela, String parametros) {
    int temR = -1;
    TableColumnModel modeloColunas = tabela.getColumnModel();
    if (parametros == null) {
        return;
    }
    if (parametros.length() > 0) {
        StringTokenizer tok = new StringTokenizer(parametros, ",");
        int ct = 0;
        String l;
        while (tok.hasMoreTokens()) {
            l = tok.nextToken();
            try {
                modeloColunas.getColumn(ct).setPreferredWidth(Integer.parseInt(l));
            } catch (NumberFormatException nE) {
                switch (l) {
                case "*":
                    log.info("Packing column " + ct);
                    packColumn(tabela, ct, 1);
                    break;
                case "R":
                    temR = ct;
                    break;
                }
            } catch (Exception e) {
            }
            ct++;
        }

        if (temR > 0) {
            modeloColunas.getColumn(temR).setPreferredWidth(modeloColunas.getColumn(temR).getPreferredWidth()
                    + tabela.getWidth() - modeloColunas.getTotalColumnWidth());
            log.debug("Tamanho da tabela: " + (modeloColunas.getColumn(temR).getPreferredWidth()
                    + tabela.getWidth() - modeloColunas.getTotalColumnWidth()));
        }

        //Testes
        log.debug("Tamanho Total: " + modeloColunas.getTotalColumnWidth());
        log.debug("Tamanho da tabela: " + tabela.getWidth());
    }
}

From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferable.java

public static void pasteString(String s, SpreadSheet spreadsheet, int row0, int col0) {
    StringTokenizer st = new StringTokenizer(s, "\n");
    int row = row0;//,maxRow=spreadsheet.getRowCount()-1;
    while (st.hasMoreTokens()/*&&row<=maxRow*/) //maxRow useless, maxRow increased automatically 
        pasteStringLine(st.nextToken(), spreadsheet, row++, col0);
}

From source file:edu.stanford.muse.util.SloppyDates.java

private static Triple<Integer, Integer, Integer> parseDate(String s) {
    // separate into month and date
    // "jan10", "10jan", "jan 10" "10 jan" should all work
    s = s.toLowerCase();//from ww w.j  a va 2s.  com
    s = s.trim();
    StringBuilder sb = new StringBuilder();
    // detect when string changes from alpha to num or vice versa and ensure a whitespace there
    boolean prevCharDigit = false, prevCharLetter = false;
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (Character.isWhitespace(c)) {
            sb.append(c);
            prevCharDigit = prevCharLetter = false;
            continue;
        }
        // treat apostrophe like a space
        if (c == '\'') {
            sb.append(' ');
            prevCharDigit = prevCharLetter = false;
            continue;
        }

        if (Character.isLetter(c)) {
            if (prevCharDigit)
                sb.append(' ');
            sb.append(c);
            prevCharLetter = true;
            prevCharDigit = false;
        } else if (Character.isDigit(c)) {
            if (prevCharLetter)
                sb.append(' ');
            sb.append(c);
            prevCharDigit = true;
            prevCharLetter = false;
        } else
            throw new RuntimeException();
    }

    String newS = sb.toString();
    log.info("string " + s + " parsed to " + newS);
    StringTokenizer st = new StringTokenizer(newS);

    int nTokens = st.countTokens();
    if (nTokens == 0 || nTokens > 3)
        return new Triple<Integer, Integer, Integer>(-1, -1, -1);

    int mm = -1, dd = -1, yy = -1;
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        boolean isNumber = true;
        int num = -1;
        try {
            num = Integer.parseInt(token);
        } catch (NumberFormatException nfe) {
            isNumber = false;
        }
        if (isNumber && num < 0)
            return new Triple<Integer, Integer, Integer>(-1, -1, -1);
        if (isNumber) {
            if (dd == -1 && num > 0 && num <= 31)
                dd = num;
            else if (yy == -1) {
                yy = num;
                if (yy < 100) {
                    yy = (yy > 12) ? (1900 + yy) : (2000 + yy);
                }
                if (yy < 1900 || yy > 2015)
                    return new Triple<Integer, Integer, Integer>(-1, -1, -1);
            } else
                return new Triple<Integer, Integer, Integer>(-1, -1, -1);
        } else {
            int x = SloppyDates.uniquePrefixIdx(token, monthNames);
            if (x >= 0 && mm == -1)
                mm = x;
            else
                return new Triple<Integer, Integer, Integer>(-1, -1, -1);
        }
    }
    return new Triple<Integer, Integer, Integer>(dd, mm, yy);
}

From source file:de.instantouch.model.io.SnakeJSONWriter.java

public static String beautify(String jsonString, boolean appendNewline) {

    String beautyString = appendNewline ? newliner(jsonString) : jsonString;

    String delim = String.valueOf("\r\n");
    StringTokenizer tokenizer = new StringTokenizer(beautyString, delim);

    StringWriter beautyWriter = new StringWriter();
    PrintWriter beautyPrinter = new PrintWriter(beautyWriter);

    int tabs = 0;
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        if (token.contains("}") || token.contains("]")) {
            tabs--;//w  ww  .j  a  va  2s  .  c om
        }

        beautyPrinter.println(printtabs(beautyPrinter, tabs) + token);
        if (token.contains("{") || token.contains("[")) {
            tabs++;
        }
    }

    return beautyWriter.toString();
}