Example usage for java.lang StringBuffer insert

List of usage examples for java.lang StringBuffer insert

Introduction

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

Prototype

@Override
public StringBuffer insert(int offset, double d) 

Source Link

Usage

From source file:com.sfs.whichdoctor.dao.SavedSearchDAOImpl.java

/**
 * Used to get a Collection of SearchBean details for a
 * specified search filter./*from w  w  w .  java2  s.  c  o  m*/
 *
 * @param filter the filter
 * @param username or public saved searches
 * @param favourite load favourites or load everything
 * @return the collection
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<SearchBean> load(final String filter, final String username, final boolean favourite)
        throws WhichDoctorDaoException {

    dataLogger.info("Searches for: " + username + " requested");

    Collection<SearchBean> savedsearches = new ArrayList<SearchBean>();

    ArrayList<Object> parameters = new ArrayList<Object>();
    parameters.add(username);

    StringBuffer loadSearch = new StringBuffer();
    loadSearch.insert(0, this.getSQL().getValue("search/loadUser"));

    if (favourite) {
        loadSearch.append(" AND favourite = true");
    }
    if (StringUtils.isNotBlank(filter)) {
        loadSearch.append(" AND (Name LIKE ? OR Description LIKE ?)");
        parameters.add("%" + filter + "%");
        parameters.add("%" + filter + "%");
    }
    loadSearch.append(" ORDER BY savedsearch.Name");

    try {
        savedsearches = this.getJdbcTemplateReader().query(loadSearch.toString(), parameters.toArray(),
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadSearch(rs);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for search: " + ie.getMessage());
    }
    return savedsearches;
}

From source file:org.millr.slick.utils.TrimString.java

public TrimString(String input, int length, boolean soft) {

    LOGGER.info(">>>> Trimming String");

    // Replace basic HTML. Will break if HTML is malformed.
    String contentString = input.replaceAll("<[^>]*>", "");

    if (contentString == null || contentString.trim().isEmpty()) {
        LOGGER.info("String is empty");
        trimmedString = contentString;//from   www. ja v  a  2 s  .  c o m
    }

    try {
        StringBuffer sb = new StringBuffer(contentString);

        int desiredLength = length;
        int endIndex = sb.indexOf(" ", desiredLength);

        //If soft, remove three characters to make room for elipsis.
        if (soft) {
            desiredLength = length - 3;
            endIndex = sb.indexOf(" ", desiredLength);
            contentString = escapeHtml(sb.insert(endIndex, "...").substring(0, endIndex + 3));
        } else {
            contentString = escapeHtml(sb.substring(0, endIndex));
        }
    } catch (Exception e) {
        LOGGER.error("Exception: " + e.getMessage(), e);
    }
    trimmedString = contentString;
}

From source file:org.apache.james.protocols.smtp.core.fastfail.DNSRBLHandler.java

/**
 *
 * This checks DNSRBL whitelists and blacklists.  If the remote IP is whitelisted
 * it will be permitted to send e-mail, otherwise if the remote IP is blacklisted,
 * the sender will only be permitted to send e-mail to postmaster (RFC 2821) or
 * abuse (RFC 2142), unless authenticated.
 *///from  www  .j  a  va 2  s  .  c o m
public void checkDNSRBL(SMTPSession session, String ipAddress) {

    /*
     * don't check against rbllists if the client is allowed to relay..
     * This whould make no sense.
     */
    if (session.isRelayingAllowed()) {
        session.getLogger().info("Ipaddress " + session.getRemoteAddress().getAddress()
                + " is allowed to relay. Don't check it");
        return;
    }

    if (whitelist != null || blacklist != null) {
        StringBuffer sb = new StringBuffer();
        StringTokenizer st = new StringTokenizer(ipAddress, " .", false);
        while (st.hasMoreTokens()) {
            sb.insert(0, st.nextToken() + ".");
        }
        String reversedOctets = sb.toString();

        if (whitelist != null) {
            String[] rblList = whitelist;
            for (String rbl : rblList) {
                if (resolve(reversedOctets + rbl)) {
                    if (session.getLogger().isInfoEnabled()) {
                        session.getLogger().info("Connection from " + ipAddress + " whitelisted by " + rbl);
                    }

                    return;
                } else {
                    if (session.getLogger().isDebugEnabled()) {
                        session.getLogger().debug("IpAddress " + session.getRemoteAddress().getAddress()
                                + " not listed on " + rbl);
                    }
                }
            }
        }

        if (blacklist != null) {
            String[] rblList = blacklist;
            for (String rbl : rblList) {
                if (resolve(reversedOctets + rbl)) {
                    if (session.getLogger().isInfoEnabled()) {
                        session.getLogger().info("Connection from " + ipAddress + " restricted by " + rbl
                                + " to SMTP AUTH/postmaster/abuse.");
                    }

                    // we should try to retrieve details
                    if (getDetail) {
                        Collection<String> txt = resolveTXTRecords(reversedOctets + rbl);

                        // Check if we found a txt record
                        if (!txt.isEmpty()) {
                            // Set the detail
                            String blocklistedDetail = txt.iterator().next().toString();

                            session.setAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, blocklistedDetail,
                                    State.Connection);
                        }
                    }

                    session.setAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, "true", State.Connection);
                    return;
                } else {
                    // if it is unknown, it isn't blocked
                    if (session.getLogger().isDebugEnabled()) {
                        session.getLogger().debug("unknown host exception thrown:" + rbl);
                    }
                }

            }
        }
    }
}

From source file:ISO8601DateTimeFormat.java

/**
 * Write an integer value with leading zeros.
 * @param buf The buffer to append the string.
 * @param value The value to write.//ww  w. j  a  va  2s  .  co m
 * @param length The length of the string to write.
 */
protected final void appendInt(StringBuffer buf, int value, int length) {
    int len1 = buf.length();
    buf.append(value);
    int len2 = buf.length();
    for (int i = len2; i < len1 + length; ++i) {
        buf.insert(len1, '0');
    }
}

From source file:com.sap.research.connectivity.gw.parsers.JavaSourceFileEditor.java

private void insertMethod(JavaSourceMethod method, StringBuffer fileContent) {
    //We insert just before the end of the class
    try {/*  w w w.java2s .c  o  m*/
        fileContent.insert(fileContent.lastIndexOf("}"), method.METHOD_STRING);
        globalMethodList.add(method);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:javax.faces.component.UIComponentBase.java

private static void getPathToComponent(UIComponent component, StringBuffer buf) {
    if (component == null)
        return;/*from w  w w  .ja  v a 2s .  c  o  m*/

    StringBuffer intBuf = new StringBuffer();

    intBuf.append("[Class: ");
    intBuf.append(component.getClass().getName());
    if (component instanceof UIViewRoot) {
        intBuf.append(",ViewId: ");
        intBuf.append(((UIViewRoot) component).getViewId());
    } else {
        intBuf.append(",Id: ");
        intBuf.append(component.getId());
    }
    intBuf.append("]");

    buf.insert(0, intBuf.toString());

    getPathToComponent(component.getParent(), buf);
}

From source file:xbird.util.jdbc.impl.DerbyAccessor.java

public String escapeString(String inputString) {
    int start = inputString.indexOf(CHAR_DELIMITER);
    StringBuffer result;
    //if delimeter is not found inside the string nothing to do
    if (start != -1) {
        result = new StringBuffer(inputString);
        int current;
        int delLength = CHAR_DELIMITER.length();
        while (start != -1) {
            //insert delimter character
            result = result.insert(start, CHAR_DELIMITER);
            current = start + delLength + 1;
            start = result.toString().indexOf(CHAR_DELIMITER, current);
        }//from w ww  . ja v a  2  s .co m
        return result.toString();
    }
    return inputString;
}

From source file:it.unibas.spicybenchmark.operators.generators.GenerateTupleNodeBenchmark.java

private void generateGlobalId(INode node, TupleNodeBenchmark tupleNodeBenchmark) {
    StringBuffer globalId = new StringBuffer();
    INode fatherNode = node.getFather();
    while (fatherNode != null) {
        if (fatherNode instanceof TupleNode && !fatherNode.isVirtual()) {
            TupleNodeBenchmark fatherNodeInCache = cache.get(fatherNode);
            globalId.insert(0, SEPARATOR).insert(0, fatherNodeInCache.getLocalId());//.insert(0, fatherNode.getLabel());
        } else {/*from ww  w . j a  v a 2 s  .  c  o  m*/
            globalId.insert(0, SEPARATOR).insert(0, fatherNode.getLabel());
        }
        fatherNode = fatherNode.getFather();
    }
    String localId = tupleNodeBenchmark.getLocalId();
    globalId.append(localId);
    tupleNodeBenchmark.setGlobalId(globalId.toString());
}

From source file:org.osaf.cosmo.server.ServiceLocator.java

private String resolveUrl(String path, String servicePrefix, boolean absolute, boolean withTicket) {
    StringBuffer buf = new StringBuffer();

    if (absolute)
        buf.insert(0, appMountUrl).append(servicePrefix).append("/");

    buf.append(path);//from  w  w w  .  jav  a2  s  .com

    if (withTicket && ticketKey != null)
        buf.append("?").append(PARAM_TICKET).append("=").append(ticketKey);

    return buf.toString();
}

From source file:org.alfresco.util.schemacomp.DbProperty.java

/**
 * Work backwards from this DbProperty's DbObject to the root object to create a path in the
 * following format:/*from   w  w w .ja v a2  s.  c  o m*/
 * <p>
 * root.child.grandchild[...].property
 * <p>
 * e.g. myschema.person.age.nullable
 * <p>
 * This isn't exactly the same as a FQ database object name, for example the property name could be indexed:
 * <p>
 * e.g. myschema.person.pk_person.columnNames[2]
 * <p>
 * to reflect the third column name in the primary key named "pk_person" on the person table.
 * 
 * @return String path
 */
public String getPath() {
    StringBuffer sb = new StringBuffer();

    if (getPropertyName() != null) {
        sb.append(".");
        sb.append(getPropertyName());
    }

    for (DbObject pathElement = dbObject; pathElement != null; pathElement = pathElement.getParent()) {
        sb.insert(0, pathElement.getName());
        if (pathElement.getParent() != null) {
            sb.insert(0, ".");
        }
    }

    return sb.toString();
}