Example usage for java.lang StringBuffer delete

List of usage examples for java.lang StringBuffer delete

Introduction

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

Prototype

@Override
public synchronized StringBuffer delete(int start, int end) 

Source Link

Usage

From source file:org.directwebremoting.drapgen.generate.gi.GiType.java

/**
 * @param directory Base directory in which to write the Java files
 * @throws java.io.IOException If writing fails
 *///from  w w  w.j a  va 2  s  . c  om
public void writeCode(String directory) throws IOException {
    String javaClassName = xmlClassName.replaceFirst("\\.xml$", ".java");
    File javaFile = new File(directory + javaClassName);
    File javaParentDir = javaFile.getParentFile();

    if (!javaParentDir.isDirectory()) {
        if (!javaParentDir.mkdirs()) {
            throw new IOException("Failed to create directory: " + javaParentDir.getName());
        }
    }

    FileWriter out = null;

    try {
        StringBuffer outerCode = output.getBuffer();
        if (outerCode.toString().trim().length() != 0) {
            int closeCurly = outerCode.lastIndexOf("}");
            if (closeCurly != -1) {
                outerCode.delete(closeCurly, outerCode.length() - 1);
            }

            out = new FileWriter(javaFile);
            out.append(outerCode);

            for (GiType innerSource : innerSources) {
                String innerCode = innerSource.output.toString();
                innerCode = innerCode.replaceAll("import .*;", "");
                innerCode = innerCode.replaceAll("package .*;", "");
                innerCode = innerCode.replaceAll(" " + getShortName() + "." + innerSource.getShortName(),
                        " " + innerSource.getShortName());

                out.append(innerCode);
            }

            if (closeCurly != -1) {
                out.append("}\n");
            }
        }
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:web.DirslidesController.java

public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {//from  www  .j  a  v a2  s . c om
        ModelAndView m = super.handleRequest(request, response);
    } catch (Exception e) {
        return handleError("error in handleRequest", e);
    }

    logger.info("came 1, DirslidesController");

    if (!GlobalConst.hddomain.contains(GlobalConst.PortalServer) && (!rbDirectoryExists.equals("1"))) {
        return handleError("Cannot manage directory feature in deluxe version.");
    }
    logger.info("came 2, DirslidesController");

    if (getDaoMapper() == null) {
        return handleError("DaoMapper is null in DirslidesController");
    }
    logger.info("came 3, DirslidesController");

    /** users should be allowed to view the directory blobs without the session **/
    String directoryid = request.getParameter(DbConstants.DIRECTORY_ID);
    if (RegexStrUtil.isNull(directoryid)) {
        return handleError("request, directory is null, for DirslidesController ");
    }
    logger.info("came 4, DirslidesController");
    if (directoryid.length() > GlobalConst.directoryidSize) {
        return handleError("directoryid.length() > WebConstants.directoryidSize, for DirslidesController ");
    }
    directoryid = RegexStrUtil.goodNameStr(directoryid);

    logger.info("came 5, DirslidesController");

    DirectoryDao directoryDao = (DirectoryDao) daoMapper.getDao(DbConstants.DIRECTORY);
    if (directoryDao == null) {
        return handleError("DirectoryDao is null in DirslidesController directory");
    }

    logger.info("came 6, DirslidesController");

    DirectoryStreamBlobDao dirBlobDao = (DirectoryStreamBlobDao) daoMapper.getDao(DbConstants.DIR_BLOB);
    if (dirBlobDao == null) {
        return handleError("dirBlobDao is null in DirslidesController directory");
    }

    logger.info("came 7, DirslidesController");
    List photos = null;
    List tagList = null;
    Directory dirBean = null;
    String dirName = null;
    logger.info("came 8, DirslidesController");
    try {
        photos = directoryDao.getBlobsByCategory(directoryid, DbConstants.PHOTO_CATEGORY,
                DbConstants.BLOB_READ_FROM_SLAVE);
        tagList = dirBlobDao.getAllTags(directoryid, DbConstants.BLOB_READ_FROM_SLAVE);
        dirBean = directoryDao.viewDirectory(directoryid);
        if (dirBean != null) {
            dirName = dirBean.getValue(DbConstants.DIRNAME);
        }
    } catch (BaseDaoException e) {
        return handleError("Exception occured in getStreamBlobs() DirslidesController, directory() ", e);
    }
    logger.info("came 9, DirslidesController");
    if (photos == null) {
        return handleError("photos null, DirslidesController, directoryid = " + directoryid);
    }

    /** 
     * check if this photo exists 
          */
    logger.info("came 10, DirslidesController");
    int photoNum = 0;
    int nextPhotoNum = 0;
    int prevPhotoNum = 0;

    String goPhoto = request.getParameter(DbConstants.GOTO_PHOTO);
    if (!RegexStrUtil.isNull(goPhoto)) {
        String showphoto = request.getParameter(DbConstants.SHOW_PHOTO);
        if (!RegexStrUtil.isNull(showphoto)) {
            photoNum = new Integer(showphoto).intValue();
        }
    } else {
        String photoNumStr = request.getParameter(DbConstants.PHOTO_NUM);
        if (!RegexStrUtil.isNull(photoNumStr)) {
            photoNum = new Integer(photoNumStr).intValue();
        }
    }

    logger.info("came 11, DirslidesController");

    String timerStr = request.getParameter(DbConstants.TIMER);
    if (RegexStrUtil.isNull(timerStr)) {
        timerStr = "0";
    }

    logger.info("came 12, DirslidesController");

    if (photos.size() == 1) {
        photoNum = nextPhotoNum = prevPhotoNum = 0;
    } else {
        if (photoNum >= photos.size()) {
            photoNum = 0;
            nextPhotoNum = photoNum + 1;
            prevPhotoNum = photos.size() - 1;
        } else {
            nextPhotoNum = photoNum + 1;
            if (photoNum != 0) {
                prevPhotoNum = photoNum - 1;
                ;
            } else {
                prevPhotoNum = photos.size() - 1;
            }
        }
    }
    logger.info("came 13, DirslidesController");

    Directory cobrand = null;
    CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND);
    if (cobrandDao == null) {
        return handleUserpageError("CobrandDao is null, DirslidesController ");
    }
    try {
        cobrand = cobrandDao.getDirCobrand(directoryid);
    } catch (Exception e) {
        return handleError("exception getDirCobrand(), DirslidesController ", e);
    }
    logger.info("came 14, DirslidesController");

    String url = "";
    String fn = request.getParameter(DbConstants.FNDOTX);
    Map myModel = new HashMap();
    if (!RegexStrUtil.isNull(fn)) {
        String beg = request.getParameter("count");
        if (beg != null) {
            int count = new Integer(beg).intValue();

            /*
            photos.size = 3;
            photonum = 0, count = 2;  
            photonum = 1, count = 1;  into play
            photonum = 2, count = 0;
            photonum = 3, count = -1;
            */

            if ((count > 0) && count <= photos.size()) {
                count--;
                String newBeg = "-1";
                if (count >= 0) {
                    newBeg = new Integer(count).toString();
                }

                logger.info("came 21 DirslidesController");

                StringBuffer myUrl = new StringBuffer("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"");
                myUrl.append(timerStr);
                myUrl.append("; URL=");
                myUrl.append("dirslides?directoryid=");
                myUrl.append(directoryid);
                myUrl.append("&dirname=");
                myUrl.append(dirName);
                myUrl.append("&photonum=");
                myUrl.append(nextPhotoNum);
                myUrl.append("&timer=");
                myUrl.append(timerStr);
                myUrl.append("&count=");
                myUrl.append(newBeg);
                myUrl.append("&fn.x=");
                myUrl.append(DbConstants.PLAY);
                myUrl.append("\">");
                url = myUrl.toString();
                logger.info("came 15, DirslidesController");
            } else {
                //lastone 
                myModel.put("count", null);
            }
        } // beg != null 
    } else {
        myModel.put("count", null);
    }
    logger.info("came 16, DirslidesController");

    StringBuffer usertags = new StringBuffer();
    if (tagList != null && tagList.size() > 0) {
        for (int i = 0; i < tagList.size(); i++) {
            if ((Photo) tagList.get(i) != null) {
                usertags.append(((Photo) tagList.get(i)).getValue(DbConstants.USER_TAGS));
            }
        }
    }
    logger.info("came 17, DirslidesController");

    /**
    * views resolved to the name of the jsp using ViewResolver
    */
    String viewName = DbConstants.DIR_SLIDES;
    myModel.put(viewName, photos);
    myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists);
    myModel.put(DbConstants.DIRNAME, dirName);
    myModel.put(DbConstants.DIRECTORY_ID, directoryid);
    myModel.put(DbConstants.USER_PAGE, userpage);
    myModel.put(DbConstants.VISITOR_PAGE, memberUserpage);
    myModel.put(DbConstants.LOGIN_INFO, loginInfo);
    myModel.put(DbConstants.SHARE_INFO, shareInfo);
    myModel.put(DbConstants.USER_TAGS, usertags.toString());
    logger.info("came 18, DirslidesController");

    StringBuffer sb = new StringBuffer();
    sb.append(photoNum);
    myModel.put(DbConstants.PHOTO_NUM, sb.toString());

    logger.info("came 20, DirslidesController");

    sb.delete(0, sb.length());
    sb.append(nextPhotoNum);
    myModel.put(DbConstants.NEXT_NUM, sb.toString());

    sb.delete(0, sb.length());
    sb.append(prevPhotoNum);
    myModel.put(DbConstants.PREV_NUM, sb.toString());

    myModel.put(DbConstants.COBRAND, cobrand);
    myModel.put(DbConstants.TIMER, timerStr);
    myModel.put(DbConstants.URL, url);
    myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login));
    logger.info("came 19, DirslidesController");
    return new ModelAndView(viewName, "model", myModel);

    //myModel.put(DbConstants.FN, fn);
}

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);
    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 {//from www . ja  v  a2s .  co  m
        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:org.nuxeo.typeDocPkg.ODTDoc.java

private Integer countNrOfPages(String fileName) throws IOException, JDOMException {
    try {/*  www  . j  a va 2  s .  co  m*/
        textBuffer = new StringBuffer();
        Integer numPage = 0;
        ZipFile zipFile = new ZipFile(fileName);

        Enumeration<?> entries = zipFile.entries();
        ZipEntry entry;

        while (entries.hasMoreElements()) {
            entry = (ZipEntry) entries.nextElement();

            if (entry.getName().equals("content.xml")) {

                textBuffer = new StringBuffer();
                StringBuffer out = new StringBuffer();

                InputStream inputStream = zipFile.getInputStream(entry);
                byte buf[] = new byte[1024];
                while (inputStream.read(buf) > 0) {
                    out.append(new String(buf, 0, 1024));
                    if (out.indexOf("soft-page-break") > 0) {
                        numPage++;
                    }
                    System.out.print(out);
                    out.delete(0, out.length());
                }
            }
        }
        return numPage;
    } catch (Exception e) {
        log.error("Error during the countNrOfPages method: ", e);
        return 1;
    }
}

From source file:com.sbcc.edu.jrollspellchecker.MainWindow.java

public void changedReplace(IndexedWord word) {
    int startIndex = word.getStartIndex();
    String tempWindowText = spellCheckText.getText();
    StringBuffer buf = new StringBuffer(spellCheckText.getText());
    buf.delete(word.getStartIndex(), word.getEndIndex());
    buf.insert(word.getStartIndex(), curWord.getText());
    System.out.println("Trying replace for " + word.data);
    spellCheckText.setText(buf.toString());
    this.mainIndexedWords = new ArrayList<IndexedWord>();
    indexTest(mainIndexedWords, startIndex);
    cycleNew(mainIndexedWords);/*from w ww . jav  a2s .co m*/
}

From source file:org.deegree.portal.standard.context.control.AbstractContextListener.java

/**
 * returns the name of the users start context. If the user does not own an individual start context the name of the
 * default start context for all users will be returned.
 * /*from  w w w.j a  va2s . co m*/
 * (copied and adapted from org.deegree.portal.standard.security.control.GetSessionIDListener)
 * 
 * @param userName
 * @return String
 * @throws IOException
 */
protected String getUsersStartContext(String userName) throws IOException {
    StringBuffer dir = new StringBuffer("users/");
    StringBuffer sb = new StringBuffer(300);
    sb.append(getHomePath()).append(userDir).append(userName);
    sb.append("/context.properties");

    File file = new File(sb.toString());
    if (!file.exists()) {
        sb.delete(0, sb.length());
        sb.append(getHomePath()).append(userDir).append("context.properties");
        file = new File(sb.toString());
    } else {
        dir.append(userName).append('/');
    }

    Properties prop = new Properties();
    InputStream is = file.toURL().openStream();
    prop.load(is);
    is.close();

    return dir.append(prop.getProperty("STARTCONTEXT")).toString();
}

From source file:com.abstratt.mdd.internal.frontend.textuml.TextUMLCompiler.java

/**
 * Given a position in a compilation unit, finds the contextual package name. 
 * // ww w .  jav a2 s.  c  o  m
 * @param toParse source of compilation unit
 * @param line line number, starting from 1
 * @param col column number, starting from 1
 * @return the name of the contextual package
 */
public String findPackageName(String toParse, final int line, final int col) {
    Token token = findTokenAt(toParse, line, col);
    if (token == null)
        return null;
    final Stack<String> segments = new Stack<String>();
    for (Node current = token; current != null; current = current.parent()) {
        current.apply(new AnalysisAdapter() {
            @Override
            public void caseAStart(AStart node) {
                segments.push(TextUMLCore.getSourceMiner().getQualifiedIdentifier(
                        ((APackageHeading) node.getPackageHeading()).getQualifiedIdentifier()));
            }

            public void caseASubNamespace(ASubNamespace node) {
                segments.push(TextUMLCore.getSourceMiner()
                        .getQualifiedIdentifier(((APackageHeading) node.getPackageHeading())));
            }
        });
    }
    if (segments.isEmpty())
        return null;
    StringBuffer result = new StringBuffer();
    while (!segments.isEmpty()) {
        result.append(segments.pop());
        result.append(NamedElement.SEPARATOR);
    }
    result.delete((result.length() - NamedElement.SEPARATOR.length()), result.length());
    return result.toString();
}

From source file:com.abstratt.mdd.internal.frontend.textuml.TextUMLCompiler.java

/**
 * Given a position in a compilation unit, finds the contextual namespace. 
 * //from  w ww  . j a v a2 s  .  co m
 * @param toParse source of compilation unit
 * @param line line number, starting from 1
 * @param col column number, starting from 1
 * @return the name of the contextual namespace
 */
public String findNamespace(String toParse, final int line, final int col) {
    Token token = findTokenAt(toParse, line, col, false, true);
    if (token == null)
        return null;
    final Stack<String> segments = new Stack<String>();
    for (Node current = token; current != null; current = current.parent()) {
        current.apply(new AnalysisAdapter() {
            @Override
            public void caseAStart(AStart node) {
                segments.push(TextUMLCore.getSourceMiner().getQualifiedIdentifier(
                        ((APackageHeading) node.getPackageHeading()).getQualifiedIdentifier()));
            }

            public void caseASubNamespace(ASubNamespace node) {
                segments.push(TextUMLCore.getSourceMiner()
                        .getQualifiedIdentifier(((APackageHeading) node.getPackageHeading())));
            }

            @Override
            public void caseAClassDef(AClassDef node) {
                segments.push(((AClassHeader) node.getClassHeader()).getIdentifier().getText());
            }

            @Override
            public void caseAStereotypeDef(AStereotypeDef node) {
                segments.push(((AStereotypeDefHeader) node.getStereotypeDefHeader()).getIdentifier().getText());
            }

            @Override
            public void caseAAssociationDef(AAssociationDef node) {
                final String associationName = ((AAssociationHeader) node.getAssociationHeader())
                        .getIdentifier().getText();
                if (associationName.length() > 0)
                    segments.push(associationName);
            }
        });
    }
    if (segments.isEmpty())
        return null;
    StringBuffer result = new StringBuffer();
    while (!segments.isEmpty()) {
        result.append(segments.pop());
        result.append(NamedElement.SEPARATOR);
    }
    result.delete((result.length() - NamedElement.SEPARATOR.length()), result.length());
    return result.toString();
}

From source file:com.jkoolcloud.tnt4j.streams.utils.Utils.java

/**
 * Clears string buffer content.// w ww.  j  av  a  2s.  c  o m
 *
 * @param sb
 *            string buffer to clear content
 * @return empty string buffer
 */
public static StringBuffer clear(StringBuffer sb) {
    return sb == null ? null : sb.delete(0, sb.length());
}

From source file:org.xwiki.rendering.internal.parser.reference.GenericLinkReferenceParser.java

/**
 * Find out the element located to the right of the passed separator.
 * //from  w w w .j  a v a 2s  .c om
 * @param content the string to parse. This parameter will be modified by the method to remove the parsed content.
 * @param separator the separator string to locate the element
 * @return the parsed element or null if the separator string wasn't found
 */
protected String parseElementAfterString(StringBuffer content, String separator) {
    String element = null;

    // Find the first non escaped separator (starting from the end of the content buffer).
    int index = content.lastIndexOf(separator);
    while (index != -1) {
        // Check if the element is found and it's not escaped.
        if (!shouldEscape(content, index)) {
            element = content.substring(index + separator.length()).trim();
            content.delete(index, content.length());
            break;
        }

        if (index > 0) {
            index = content.lastIndexOf(separator, index - 1);
        } else {
            break;
        }
    }

    return element;
}