Example usage for java.lang StringBuffer indexOf

List of usage examples for java.lang StringBuffer indexOf

Introduction

In this page you can find the example usage for java.lang StringBuffer indexOf.

Prototype

@Override
public int indexOf(String str) 

Source Link

Usage

From source file:de.hero.vertretungsplan.HtmlWork.java

public void extractTable(StringBuffer strHtml) throws IOException {
    SharedPreferences.Editor editor = mySharedPreferences.edit();

    ArrayList<HashMap<String, String>> lstEintraege = new ArrayList<HashMap<String, String>>();

    HashMap<String, String> hmEintrag = new HashMap<String, String>();

    int intIndex = strHtml.indexOf("<table");
    strHtml.delete(0, intIndex - 1);//from   w  ww  .  j  ava 2  s.  c  om
    intIndex = strHtml.indexOf("</table");
    strHtml.delete(intIndex, strHtml.length() - 1);
    DateFormat dfm = new SimpleDateFormat("dd.MM.yyyy");
    DateFormat dfm2 = new SimpleDateFormat("dd.MM.yy");
    Date dat = new Date();
    try {
        dat = dfm.parse(strHtml.substring(strHtml.indexOf(":") + 2));
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //      int date = dat.getDate();
    //      int month = dat.getMonth() + 1;

    //String strAktualisierungsText =  ((date < 10) ? "0" + date : date)  + "." + ((month < 10) ? "0" + month : month) + "." + (dat.getYear() + 1900) + " - " + strHtml.substring(strHtml.indexOf("<td>") + 4,strHtml.indexOf("</td"));
    String datumVertretungsplan = dfm2.format(dat);
    String aOderBWoche = strHtml.substring(strHtml.indexOf("<td>") + 4, strHtml.indexOf("</td"));
    Log.d("HtmlWork", "strAktualisierungsText " + datumVertretungsplan);
    editor.putString(context.getString(R.string.datumVertretungsplan), datumVertretungsplan);
    editor.putString("aOderBWoche", aOderBWoche);
    editor.commit();

    intIndex = strHtml.indexOf("<tr>");
    int intIndex2 = strHtml.indexOf("</tr>");
    strHtml.delete(0, intIndex2 + 4);
    intIndex = strHtml.indexOf("<tr>");
    intIndex2 = strHtml.indexOf("</tr>");

    strHtml.delete(0, intIndex2 + 4);
    intIndex2 = strHtml.indexOf("</tr>");
    strHtml.delete(0, intIndex2 + 4);
    intIndex = strHtml.indexOf("<tr>");
    intIndex2 = strHtml.indexOf("</tr>");
    while (intIndex != -1) {
        StringBuffer strZeile = new StringBuffer(strHtml.substring(intIndex + 4, intIndex2));
        int intIndex4 = strZeile.indexOf("</t");
        strZeile.delete(0, intIndex4 + 5);
        int intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");

        String stunde = strZeile.substring(intIndex3 + 4, intIndex4);
        hmEintrag.put("stunde", stunde + ((stunde.endsWith(".")) ? " Stunde" : ". Stunde"));

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");
        hmEintrag.put("fach1", strZeile.substring(intIndex3 + 4, intIndex4));

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");
        hmEintrag.put("vertreter", strZeile.substring(intIndex3 + 4, intIndex4));

        /*strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");
        hmEintrag.put("fach2", strZeile.substring(intIndex3 + 4, intIndex4));*/

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");
        hmEintrag.put("klassen", strZeile.substring(intIndex3 + 4, intIndex4));

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");
        hmEintrag.put("raum", strZeile.substring(intIndex3 + 4, intIndex4));

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");

        String strTemp = strZeile.substring(intIndex3 + 4, intIndex4);

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");

        hmEintrag.put("text", strTemp + " " + strZeile.substring(intIndex3 + 4, intIndex4));

        lstEintraege.add(hmEintrag);

        hmEintrag = new HashMap<String, String>();

        strHtml.delete(0, intIndex2 + 2);
        intIndex = strHtml.indexOf("<tr>");
        intIndex2 = strHtml.indexOf("</tr>");
    }
    FileOutputStream fos = context.openFileOutput(context.getString(R.string.filename), Context.MODE_PRIVATE);
    ObjectOutputStream oos = new ObjectOutputStream(fos);

    int oldHash = mySharedPreferences.getInt(context.getString(R.string.v_plan_hash_value), 0);

    oos.writeObject(lstEintraege);
    oos.close();
    fos.close();
    int newHash = lstEintraege.hashCode();
    editor.putInt(context.getString(R.string.v_plan_hash_value), newHash);
    editor.commit();

    Log.d("HtmlWork", "oldHash: " + oldHash + "; newHash: " + newHash);
    if (oldHash != newHash) {
        onDataChange();
    }
}

From source file:dk.defxws.fgssolrremote.OperationsImpl.java

private void indexDoc(String pid, String repositoryName, String indexName, InputStream foxmlStream,
        StringBuffer resultXml, String indexDocXslt) throws java.rmi.RemoteException {
    String xsltName = indexDocXslt;
    String[] params = new String[12];
    int beginParams = indexDocXslt.indexOf("(");
    if (beginParams > -1) {
        xsltName = indexDocXslt.substring(0, beginParams).trim();
        int endParams = indexDocXslt.indexOf(")");
        if (endParams < beginParams)
            throw new GenericSearchException(
                    "Format error (no ending ')') in indexDocXslt=" + indexDocXslt + ": ");
        StringTokenizer st = new StringTokenizer(indexDocXslt.substring(beginParams + 1, endParams), ",");
        params = new String[12 + 2 * st.countTokens()];
        int i = 1;
        while (st.hasMoreTokens()) {
            String param = st.nextToken().trim();
            if (param == null || param.length() < 1)
                throw new GenericSearchException("Format error (empty param) in indexDocXslt=" + indexDocXslt
                        + " params[" + i + "]=" + param);
            int eq = param.indexOf("=");
            if (eq < 0)
                throw new GenericSearchException("Format error (no '=') in indexDocXslt=" + indexDocXslt
                        + " params[" + i + "]=" + param);
            String pname = param.substring(0, eq).trim();
            String pvalue = param.substring(eq + 1).trim();
            if (pname == null || pname.length() < 1)
                throw new GenericSearchException("Format error (no param name) in indexDocXslt=" + indexDocXslt
                        + " params[" + i + "]=" + param);
            if (pvalue == null || pvalue.length() < 1)
                throw new GenericSearchException("Format error (no param value) in indexDocXslt=" + indexDocXslt
                        + " params[" + i + "]=" + param);
            params[10 + 2 * i] = pname;//  w w  w  . j av a 2 s  . co m
            params[11 + 2 * i++] = pvalue;
        }
    }
    params[0] = "REPOSITORYNAME";
    params[1] = repositoryName;
    params[2] = "FEDORASOAP";
    params[3] = config.getFedoraSoap(repositoryName);
    params[4] = "FEDORAUSER";
    params[5] = config.getFedoraUser(repositoryName);
    params[6] = "FEDORAPASS";
    params[7] = config.getFedoraPass(repositoryName);
    params[8] = "TRUSTSTOREPATH";
    params[9] = config.getTrustStorePath(repositoryName);
    params[10] = "TRUSTSTOREPASS";
    params[11] = config.getTrustStorePass(repositoryName);
    String xsltPath = config.getConfigName() + "/index/" + indexName + "/"
            + config.getUpdateIndexDocXslt(indexName, xsltName);
    StringBuffer sb = (new GTransformer()).transform(xsltPath, new StreamSource(foxmlStream),
            config.getURIResolver(indexName), params);
    if (logger.isDebugEnabled())
        logger.debug("indexDoc=\n" + sb.toString());
    if (sb.indexOf("</field>") > 0) { // skip if no fields
        try {
            sendToSolr("/update", sb.toString());
        } catch (Exception e) {
            throw new GenericSearchException("updateIndex sendToSolr:\n" + e, e);
        }
        if (indexDocExists(pid)) {
            updateTotal++;
            resultXml.append("<updated>" + pid + "</updated>\n");
        } else {
            insertTotal++;
            docCount++;
            resultXml.append("<inserted>" + pid + "</inserted>\n");
        }
        logger.info("IndexDocument=" + pid + " insertTotal=" + insertTotal + " updateTotal=" + updateTotal
                + " deleteTotal=" + deleteTotal + " emptyTotal=" + emptyTotal + " warnCount=" + warnCount
                + " docCount=" + docCount);
    } else {
        deletePid(pid, indexName, resultXml);
        logger.warn("IndexDocument " + pid + " does not contain any IndexFields!!! RepositoryName="
                + repositoryName + " IndexName=" + indexName);
        emptyTotal++;
    }
}

From source file:org.osaf.cosmo.atom.generator.BaseItemFeedGenerator.java

protected void addPathInfo(StringBuffer iri, String pathInfo) {
    // if there's a query string, insert the projection just
    // before it//from   w  ww  .j a  v a 2 s.  co m
    int qm = iri.indexOf("?");
    if (qm > 0)
        iri.insert(qm, '/').insert(qm + 1, pathInfo);
    else
        iri.append('/').append(pathInfo);
}

From source file:dk.defxws.fgssolrremote.OperationsImpl.java

public String updateIndex(String action, String value, String repositoryName, String indexName,
        String indexDocXslt, String resultPageXslt) throws java.rmi.RemoteException {
    insertTotal = 0;/*w w w.  ja va  2s.c  o m*/
    updateTotal = 0;
    deleteTotal = 0;
    emptyTotal = 0;
    StringBuffer resultXml = new StringBuffer();
    try {
        resultXml = sendToSolr("/select?q=*%3A*&rows=0");
    } catch (Exception e) {
        throw new GenericSearchException("updateIndex sendToSolr:\n" + e, e);
    }
    int i = resultXml.indexOf("numFound=");
    int j = resultXml.indexOf("\"", i + 10);
    String numFound = resultXml.substring(i + 10, j);
    try {
        docCount = Integer.parseInt(numFound);
    } catch (NumberFormatException e) {
        throw new GenericSearchException(
                "updateIndex NumberFormatException numFound=" + numFound + "\n" + resultXml, e);
    }
    int initDocCount = 0;
    resultXml = new StringBuffer();
    resultXml.append("<solrUpdateIndex");
    resultXml.append(" indexName=\"" + indexName + "\"");
    resultXml.append(">\n");
    try {
        initDocCount = docCount;
        if ("createEmpty".equals(action)) {
            createEmpty(indexName, resultXml);
            initDocCount = 0;
        } else {
            if ("deletePid".equals(action))
                deletePid(value, indexName, resultXml);
            else {
                if ("fromPid".equals(action))
                    fromPid(value, repositoryName, indexName, resultXml, indexDocXslt);
                else {
                    if ("fromFoxmlFiles".equals(action))
                        fromFoxmlFiles(value, repositoryName, indexName, resultXml, indexDocXslt);
                    else if ("optimize".equals(action))
                        optimize(indexName, resultXml);
                }
            }
        }
    } finally {
        docCount = initDocCount + insertTotal - deleteTotal;
    }
    logger.info("updateIndex " + action + " indexName=" + indexName + " docCount=" + docCount);
    resultXml.append("<counts");
    resultXml.append(" insertTotal=\"" + insertTotal + "\"");
    resultXml.append(" updateTotal=\"" + updateTotal + "\"");
    resultXml.append(" deleteTotal=\"" + deleteTotal + "\"");
    resultXml.append(" emptyTotal=\"" + emptyTotal + "\"");
    resultXml.append(" docCount=\"" + docCount + "\"");
    resultXml.append(" warnCount=\"" + warnCount + "\"");
    resultXml.append("/>\n");
    resultXml.append("</solrUpdateIndex>\n");
    if (logger.isDebugEnabled())
        logger.debug("resultXml =\n" + resultXml.toString());
    params = new String[12];
    params[0] = "OPERATION";
    params[1] = "updateIndex";
    params[2] = "ACTION";
    params[3] = action;
    params[4] = "VALUE";
    params[5] = value;
    params[6] = "REPOSITORYNAME";
    params[7] = repositoryName;
    params[8] = "INDEXNAME";
    params[9] = indexName;
    params[10] = "RESULTPAGEXSLT";
    params[11] = resultPageXslt;
    String xsltPath = config.getConfigName() + "/index/" + config.getIndexName(indexName) + "/"
            + config.getUpdateIndexResultXslt(indexName, resultPageXslt);
    StringBuffer sb = (new GTransformer()).transform(xsltPath, resultXml, params);
    return sb.toString();
}

From source file:com.navjagpal.fileshare.WebServer.java

private void handleLoginRequest(DefaultHttpServerConnection serverConnection, HttpRequest request,
        RequestLine requestLine) throws HttpException, IOException {

    BasicHttpEntityEnclosingRequest enclosingRequest = new BasicHttpEntityEnclosingRequest(
            request.getRequestLine());//  ww w.ja v  a  2  s  .  c  o  m
    serverConnection.receiveRequestEntity(enclosingRequest);

    InputStream input = enclosingRequest.getEntity().getContent();
    InputStreamReader reader = new InputStreamReader(input);

    StringBuffer form = new StringBuffer();
    while (reader.ready()) {
        form.append((char) reader.read());
    }
    String password = form.substring(form.indexOf("=") + 1);
    if (password.equals(mSharedPreferences.getString(FileSharingService.PREFS_PASSWORD, ""))) {
        HttpResponse response = new BasicHttpResponse(new HttpVersion(1, 1), 302, "Found");
        response.addHeader("Location", "/");
        response.addHeader("Set-Cookie", "id=" + createCookie());
        response.setEntity(new StringEntity(getHTMLHeader() + "Success!" + getHTMLFooter()));
        serverConnection.sendResponseHeader(response);
        serverConnection.sendResponseEntity(response);
    } else {
        HttpResponse response = new BasicHttpResponse(new HttpVersion(1, 1), 401, "Unauthorized");
        response.setEntity(
                new StringEntity(getHTMLHeader() + "<p>Login failed.</p>" + getLoginForm() + getHTMLFooter()));
        serverConnection.sendResponseHeader(response);
        serverConnection.sendResponseEntity(response);
    }
}

From source file:com.hyron.poscafe.service.action.LogInOutAction.java

@Override
public boolean parseParams(List<VirtualKey> params) {
    boolean ret = false;
    StringBuffer tmpBuf = new StringBuffer();
    for (VirtualKey vk : params) {
        tmpBuf.append(vk.getValue().isEmpty() ? vk.getKeyType().getType() : vk.getValue());
    }/*from  w w  w.ja va  2 s.c  o m*/
    int i = 0;
    for (i = 0; i < regexp.length; i++) {
        Pattern pattern = Pattern.compile(regexp[i]);
        Matcher matcher = pattern.matcher(tmpBuf);
        if (matcher.matches()) {
            ret = true;
            break;
        }
    }

    if (i == 0) {
        int pos = tmpBuf.indexOf("ENTER");
        cashierID = tmpBuf.substring(0, pos);
        int pos2 = tmpBuf.indexOf("ENTERLOGIN_OUT", pos + "ENTER".length());
        password = tmpBuf.substring(pos + "ENTER".length(), pos2);
        logout = false;
        ret = true;
        log.debug("Parse params success.");
    } else if (i == 1) {
        int pos = tmpBuf.indexOf("ENTER");
        cashierID = tmpBuf.substring(0, pos);
        int pos2 = tmpBuf.indexOf("LOGIN_OUT", pos + "ENTER".length());
        password = tmpBuf.substring(pos + "ENTER".length(), pos2);
        logout = false;
        ret = true;
        log.debug("Parse params success.");
    } else if (i == 2) {
        cashierID = "";
        password = "";
        logout = true;
        ret = true;
        log.debug("Parse params success.");
    } else {
        log.debug("Parse params failed.");
    }
    return ret;
}

From source file:net.sf.jabref.logic.groups.KeywordGroup.java

/**
 * Removes matches of searchString in the entry's field. This is only
 * possible if the search expression is not a regExp.
 *//*from  w  w  w  .  j a  v  a 2 s .c o m*/
private void removeMatches(BibEntry entry) {
    if (!entry.hasField(searchField)) {
        return; // nothing to modify
    }
    String content = entry.getField(searchField);
    StringBuffer sbOrig = new StringBuffer(content);
    StringBuffer sbLower = new StringBuffer(content.toLowerCase());
    StringBuffer haystack = caseSensitive ? sbOrig : sbLower;
    String needle = caseSensitive ? searchExpression : searchExpression.toLowerCase();
    int i;
    int j;
    int k;
    final String separator = jabRefPreferences.get(JabRefPreferences.KEYWORD_SEPARATOR);
    while ((i = haystack.indexOf(needle)) >= 0) {
        sbOrig.replace(i, i + needle.length(), "");
        sbLower.replace(i, i + needle.length(), "");
        // reduce spaces at i to 1
        j = i;
        k = i;
        while (((j - 1) >= 0) && (separator.indexOf(haystack.charAt(j - 1)) >= 0)) {
            --j;
        }
        while ((k < haystack.length()) && (separator.indexOf(haystack.charAt(k)) >= 0)) {
            ++k;
        }
        sbOrig.replace(j, k, (j >= 0) && (k < sbOrig.length()) ? separator : "");
        sbLower.replace(j, k, (j >= 0) && (k < sbOrig.length()) ? separator : "");
    }

    String result = sbOrig.toString().trim();
    if (result.isEmpty()) {
        entry.clearField(searchField);
    } else {
        entry.setField(searchField, result);
    }
}

From source file:com.digitalpebble.storm.crawler.protocol.http.HttpResponse.java

private void parseHeaders(PushbackInputStream in, StringBuffer line) throws IOException, HttpException {

    while (readLine(in, line, true) != 0) {

        // handle HTTP responses with missing blank line after headers
        int pos;//www  .  j  a v a2 s . c o m
        if (((pos = line.indexOf("<!DOCTYPE")) != -1) || ((pos = line.indexOf("<HTML")) != -1)
                || ((pos = line.indexOf("<html")) != -1)) {

            in.unread(line.substring(pos).getBytes(StandardCharsets.UTF_8));
            line.setLength(pos);

            try {
                // TODO: (CM) We don't know the header names here
                // since we're just handling them generically. It would
                // be nice to provide some sort of mapping function here
                // for the returned header names to the standard metadata
                // names in the ParseData class
                processHeaderLine(line);
            } catch (Exception e) {
                // fixme:
                HttpProtocol.LOGGER.warn("Error: ", e);
            }
            return;
        }

        processHeaderLine(line);
    }
}

From source file:net.sf.jabref.groups.structure.KeywordGroup.java

/**
 * Removes matches of searchString in the entry's field. This is only
 * possible if the search expression is not a regExp.
 *///from w w w  .  j ava 2s . c  o m
private void removeMatches(BibEntry entry) {
    if (!entry.hasField(searchField)) {
        return; // nothing to modify
    }
    String content = entry.getField(searchField);
    StringBuffer sbOrig = new StringBuffer(content);
    StringBuffer sbLower = new StringBuffer(content.toLowerCase());
    StringBuffer haystack = caseSensitive ? sbOrig : sbLower;
    String needle = caseSensitive ? searchExpression : searchExpression.toLowerCase();
    int i;
    int j;
    int k;
    final String separator = Globals.prefs.get(JabRefPreferences.GROUP_KEYWORD_SEPARATOR);
    while ((i = haystack.indexOf(needle)) >= 0) {
        sbOrig.replace(i, i + needle.length(), "");
        sbLower.replace(i, i + needle.length(), "");
        // reduce spaces at i to 1
        j = i;
        k = i;
        while (((j - 1) >= 0) && (separator.indexOf(haystack.charAt(j - 1)) >= 0)) {
            --j;
        }
        while ((k < haystack.length()) && (separator.indexOf(haystack.charAt(k)) >= 0)) {
            ++k;
        }
        sbOrig.replace(j, k, (j >= 0) && (k < sbOrig.length()) ? separator : "");
        sbLower.replace(j, k, (j >= 0) && (k < sbOrig.length()) ? separator : "");
    }

    String result = sbOrig.toString().trim();
    if (result.isEmpty()) {
        entry.clearField(searchField);
    } else {
        entry.setField(searchField, result);
    }
}

From source file:nz.co.fortytwo.freeboard.server.util.CreateCamelDiagramTest.java

private void addNodeAndLink(StringBuffer buffer, ProcessorDefinition<?> p, String id, String lastNode,
        String label) {//from  w ww.java2 s .  c  o  m
    // add unique definition
    String shape = "shape=invhouse, ";
    String fill = "style=filled, fillcolor=khaki, ";
    if (p instanceof ToDefinition) {
        shape = "shape=invhouse, ";
        fill = "style=filled, fillcolor=darkkhaki, ";
    }

    buffer.append(id + " [" + shape + fill + " label = \"" + label + "\"];\n");
    String link = lastNode + " -> " + id + ";\n";
    if (buffer.indexOf(link) < 0) {
        buffer.append(link);
    }
}