Example usage for java.lang StringBuffer length

List of usage examples for java.lang StringBuffer length

Introduction

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

Prototype

@Override
    public synchronized int length() 

Source Link

Usage

From source file:model.manager.AdministrationManager.java

/**
 * Method getClinicAccessString./* w w w .  j  a va2  s.c  o m*/
 * 
 * @param u
 *            User
 * @return String
 */
public static String getClinicAccessString(User u) {
    StringBuffer clinicList = new StringBuffer();
    for (Clinic s : u.getClinics()) {
        clinicList.append(s.getClinicName());
        clinicList.append(", ");
    }
    // remove last comma and spac
    if (clinicList.length() > 2) {
        clinicList = clinicList.delete(clinicList.length() - 2, clinicList.length());
    }
    return clinicList.toString();

}

From source file:com.duroty.controller.actions.GoogieSpellAction.java

protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActionMessages errors = new ActionMessages();

    PostMethod post = null;/*from  ww  w  . j a  va  2  s .c  o m*/

    try {
        Enumeration enumeration = request.getParameterNames();
        while (enumeration.hasMoreElements()) {
            String name = (String) enumeration.nextElement();
            String value = (String) request.getParameter(name);
            DLog.log(DLog.WARN, this.getClass(), name + " >> " + value);
        }

        String text = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><spellrequest textalreadyclipped=\"0\" ignoredups=\"0\" ignoredigits=\"1\" ignoreallcaps=\"1\"><text>"
                + request.getParameter("check") + "</text></spellrequest>";

        String lang = request.getParameter("lang");

        String id = request.getParameter("id");
        String cmd = request.getParameter("cmd");

        String url = "https://" + googleUrl + "/tbproxy/spell?lang=" + lang + "&hl=" + lang;

        post = new PostMethod(url);
        post.setRequestBody(text);
        post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");

        HttpClient client = new HttpClient();
        int result = client.executeMethod(post);

        // Display status code
        System.out.println("Response status code: " + result);

        // Display response
        System.out.println("Response body: ");

        String resp = post.getResponseBodyAsString();

        System.out.println(resp);

        String goodieSpell = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";

        Vector matches = getMatches(resp);

        if (matches.size() <= 0) {
            goodieSpell = goodieSpell + "<res id=\"" + id + "\" cmd=\"" + cmd + "\" />";
        } else {
            goodieSpell = goodieSpell + "<res id=\"" + id + "\" cmd=\"" + cmd + "\">";

            StringBuffer buffer = new StringBuffer();

            for (int i = 0; i < matches.size(); i++) {
                if (buffer.length() > 0) {
                    buffer.append("+");
                }

                String aux = (String) matches.get(i);
                aux = aux.substring(aux.indexOf(">") + 1, aux.length());
                aux = aux.substring(0, aux.indexOf("<"));
                aux = aux.trim().replaceAll("\\s+", "\\+");

                buffer.append(aux);
            }

            goodieSpell = goodieSpell + buffer.toString() + "</res>";

        }

        request.setAttribute("googieSpell", goodieSpell);
    } catch (Exception ex) {
        String errorMessage = ExceptionUtilities.parseMessage(ex);

        if (errorMessage == null) {
            errorMessage = "NullPointerException";
        }

        errors.add("general", new ActionMessage(ExceptionCode.ERROR_MESSAGES_PREFIX + "general", errorMessage));
        request.setAttribute("exception", errorMessage);
        doTrace(request, DLog.ERROR, getClass(), errorMessage);
    } finally {
        try {
            post.releaseConnection();
        } catch (Exception e) {
        }
    }

    if (errors.isEmpty()) {
        doTrace(request, DLog.INFO, getClass(), "OK");

        return mapping.findForward(Constants.ACTION_SUCCESS_FORWARD);
    } else {
        saveErrors(request, errors);

        return mapping.findForward(Constants.ACTION_FAIL_FORWARD);
    }
}

From source file:biomine.bmvis2.crawling.CrawlerFetch.java

public CrawlerFetch(Collection<String> queryNodes, boolean onlyNeighborHood, String database)
        throws IOException {

    URL queryUrl = null;/*from w  ww  .  ja  v  a  2 s  . c  o m*/

    queryUrl = new URL(WebConstants.DEFAULT_BASEURL + "/query.cgi");
    StringBuffer startNodesBuf = new StringBuffer();

    for (String nod : queryNodes)
        startNodesBuf.append(nod.replace(" ", "\\ ") + " ");

    if (queryNodes.isEmpty() == false)
        startNodesBuf.deleteCharAt(startNodesBuf.length() - 1);

    String key = onlyNeighborHood ? "end_nodes" : "start_nodes";

    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put(key, startNodesBuf.toString());
    if (database != null)
        parameters.put("database", database);
    String qc = URLUtils.getURLContents(queryUrl, parameters);

    queryId = qc.split("\"")[3];

    //      System.out.println("q = " + queryId);

    statusUrl = new URL(WebConstants.DEFAULT_BASEURL + "/status.cgi?query=" + queryId);
}

From source file:ca.uhn.hl7v2.model.primitive.tests.CommonIDTest.java

private String getString(int length, char c) {
    StringBuffer buf = new StringBuffer(length);

    for (int i = 0; i < length; i++) {
        buf.append(c);//from   w  w  w .j  av a  2 s .c o m
    }
    int l = buf.length();
    return buf.toString();
}

From source file:com.ugam.collage.plus.service.people_count.impl.TrackUpdatesServiceImpl.java

@Override
public List<TsCommentsVo> getReportingsTrackDetails(Integer yearId, Integer monthId) {

    List<TsCommentsVo> tsCommentsVoList = new ArrayList<TsCommentsVo>();
    List<TsComments> tsCommentsList = tsCommentsDao.findByYearIdMonthId(yearId, monthId);
    if (tsCommentsList.isEmpty()) {
        return null;
    }//from   w ww.  ja v a  2s  . com
    for (TsComments tsComments : tsCommentsList) {
        StringBuffer strBuffer = new StringBuffer();
        if (!tsComments.getReportAdditions().isEmpty()) {
            strBuffer.append(tsComments.getReportAdditions());
        }
        if (!tsComments.getReportAttrResign().isEmpty()) {
            if (strBuffer.length() > 0) {
                strBuffer.append(", ");
            }
            strBuffer.append(tsComments.getReportAttrResign());
        }
        if (!tsComments.getReportChanges().isEmpty()) {
            if (strBuffer.length() > 0) {
                strBuffer.append(", ");
            }
            strBuffer.append(tsComments.getReportChanges());
        }

        TsCommentsVo TsCommentsVo = new TsCommentsVo(tsComments.getId(),
                tsComments.getEmpFsAccess().getEmployeeId(), tsComments.getReportedOn().toString(),
                strBuffer.toString(), tsComments.getStatus(), tsComments.getComment());
        tsCommentsVoList.add(TsCommentsVo);
    }
    return tsCommentsVoList;
}

From source file:com.flexive.core.search.genericSQL.GenericSQLForeignTableSelector.java

/**
 * {@inheritDoc}/*w ww  .  j ava2 s .  c  om*/
 */
@Override
public void apply(Property prop, PropertyEntry entry, StringBuffer statement) throws FxSqlSearchException {
    if (hasTranslationTable && translatedColumn.equalsIgnoreCase(prop.getField())) {
        // select label from translation table
        statement.delete(0, statement.length());
        final long lang = FxContext.getUserTicket().getLanguage().getId();
        DBStorage storage = StorageManager.getStorageImpl();
        statement.append(("COALESCE(\n" + getLabelSelect() + "lang=" + lang + storage.getLimit(true, 1)
                + ") ,\n" + getLabelSelect() + "deflang=" + storage.getBooleanTrueExpression() + " "
                + storage.getLimit(true, 1) + ") \n" + ")"));
        entry.overrideDataType(FxDataType.String1024);
        return;
    }
    FxDataType type = columns.get(prop.getField().toUpperCase());
    if (type == null) {
        // This field does not exist
        throw new FxSqlSearchException(LOG, "ex.sqlSearch.query.undefinedField", prop.getField(),
                prop.getPropertyName(), getAllowedFields());
    } else {
        statement.insert(0, "(SELECT " + prop.getField() + " FROM " + tableName + " WHERE " + linksOn + "=")
                .append(")");
        entry.overrideDataType(type);
    }
}

From source file:com.newatlanta.appengine.vfs.provider.GaeFileNameParser.java

/**
 * Makes sure <code>filename</code> always specifies a path that is within a
 * sub-directory of the webapp root path.
 *//*from  ww  w  . j  a  v  a  2  s  .c om*/
public FileName parseUri(VfsComponentContext context, FileName baseName, String uri)
        throws FileSystemException {
    StringBuffer name = new StringBuffer();

    // Extract the scheme
    String scheme = UriParser.extractScheme(uri, name);
    if (scheme == null) { // this should never happen
        scheme = "gae";
    }

    // Remove encoding, and adjust the separators
    UriParser.canonicalizePath(name, 0, name.length(), this);
    UriParser.fixSeparators(name);

    // Normalise the path
    FileType fileType = UriParser.normalisePath(name);

    // all GAE files *must* be relative to the root file, which must be the
    // webapp root (though we have no way of enforcing this)
    String rootPath = "";
    if (baseName == null) { // this is the root object
        rootPath = name.toString();
        name.setLength(0);
    } else {
        rootPath = getRootPath(baseName);
        if (name.indexOf(rootPath) == 0) { // if ( name.startsWith( basePath ) )
            name.delete(0, rootPath.length());
        }
    }
    return new GaeFileName(scheme, rootPath, name.toString(), fileType);
}

From source file:com.qpark.eip.core.spring.security.EipRoleVoter.java

public String getRequiredRoles(final Collection<ConfigAttribute> attributes) {
    /* Handle logging of required roles. */
    TreeSet<String> ts = new TreeSet<String>();
    for (ConfigAttribute attribute : attributes) {
        if (this.supports(attribute)) {
            ts.add(attribute.toString());
        }/*from w  ww . j  av  a  2 s  . co m*/
    }
    StringBuffer sb = new StringBuffer(1024);
    for (String string : ts) {
        if (sb.length() > 0) {
            sb.append(", ");
        }
        sb.append(string);
    }
    return sb.toString();
}

From source file:com.callidusrobotics.swing.SwingConsole.java

@Override
public String getline(final int maxLen, final Color foreground, final Color background)
        throws ArrayIndexOutOfBoundsException {
    final StringBuffer stringBuffer = new StringBuffer(maxLen);

    boolean keepPolling = true;
    while (keepPolling) {
        if (stringBuffer.length() < maxLen) {
            showCursor();// w w  w .  ja v  a 2 s  .  com
        } else {
            hideCursor();
        }
        render();

        final char input = getKeyTyped();
        switch (input) {
        case KeyEvent.VK_ENTER:
            keepPolling = false;
            break;

        case KeyEvent.VK_BACK_SPACE:
            if (stringBuffer.length() > 0) {
                stringBuffer.deleteCharAt(stringBuffer.length() - 1);
                moveCursor(cursorRow, cursorCol - 1);
                print(cursorRow, cursorCol, ' ', background, background);
            }
            break;

        case KeyEvent.CHAR_UNDEFINED:
        case KeyEvent.VK_DELETE:
        case KeyEvent.VK_ESCAPE:
            // ignore these characters
            break;

        default:
            if (stringBuffer.length() < maxLen) {
                stringBuffer.append(input);
                print(cursorRow, cursorCol, input, foreground, background);
                moveCursor(cursorRow, cursorCol + 1);
            }
        }
    }

    hideCursor();
    render();

    return stringBuffer.toString();
}