Example usage for java.lang StringBuffer substring

List of usage examples for java.lang StringBuffer substring

Introduction

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

Prototype

@Override
public synchronized String substring(int start, int end) 

Source Link

Usage

From source file:com.hbc.api.gateway.alizhifu.util.AlipayCallBackValidator.java

public boolean signValidate(HttpServletRequest request) throws UnsupportedEncodingException {
    Map<String, String> parmmap = this.getParameterMap(request);
    Map<String, String> filterMap = this.parmFilter(parmmap);
    String cleanLink = this.createLinkString(filterMap);

    String alisign = request.getParameter("sign");
    String signType = request.getParameter("sign_type");
    if (StringUtils.isBlank(alisign) || StringUtils.isBlank(signType)) {
        return Boolean.FALSE;
    }//from w w  w. j av  a2 s  .  c o m

    if (signType.equalsIgnoreCase(SIGN_TYPE_OF_MD5)) {
        return AliPayMD5.verify(cleanLink, alisign, alipayConfig.securityCode, SIGN_ENCODING);
    } else if (signType.equalsIgnoreCase(SIGN_TYPE_OF_RSA)) {
        StringBuffer spayurl = new StringBuffer();
        for (String keystr : filterMap.keySet()) {
            spayurl = spayurl.append(keystr + "=" + URLDecoder.decode(filterMap.get(keystr), "UTF-8") + "&");
        }
        String dspayurl = spayurl.substring(0, spayurl.length() - 1);
        //mysign = RSA.sign(dspayurl, alipayConfig.privateKey, "UTF-8");
    }
    return Boolean.FALSE;
}

From source file:org.apache.lucene.analysis.de.GermanStemmer.java

/**
  * Does some optimizations on the term. This optimisations are contextual.
  *///w w  w . ja va 2 s  .  c om
 private void optimize(StringBuffer buffer) {
     // Additional step for female plurals of professions and inhabitants.
     if (buffer.length() > 5 && buffer.substring(buffer.length() - 5, buffer.length()).equals("erin*")) {
         buffer.deleteCharAt(buffer.length() - 1);
         strip(buffer);
     }
     // Additional step for irregular plural nouns like "Matrizen -> Matrix".
     if (buffer.charAt(buffer.length() - 1) == ('z')) {
         buffer.setCharAt(buffer.length() - 1, 'x');
     }
 }

From source file:org.apache.lucene.analysis.de.GermanStemmer.java

/**
  * Removes a particle denotion ("ge") from a term.
  *///from  w  w  w  . j a v  a2  s . co m
 private void removeParticleDenotion(StringBuffer buffer) {
     if (buffer.length() > 4) {
         for (int c = 0; c < buffer.length() - 3; c++) {
             if (buffer.substring(c, c + 4).equals("gege")) {
                 buffer.delete(c, c + 2);
                 return;
             }
         }
     }
 }

From source file:de.eod.jliki.users.jsfbeans.UserRegisterBean.java

/**
 * Adds a new user to the jLiki database.<br/>
 *///from  ww w  .j a  va2s  . c o  m
public final void addNewUser() {
    final User newUser = new User(this.username, this.password, this.email, this.firstname, this.lastname);
    final String userHash = UserDBHelper.addUserToDB(newUser);

    if (userHash == null) {
        Messages.addFacesMessage(null, FacesMessage.SEVERITY_ERROR, "message.user.register.failed",
                this.username);
        return;
    }

    UserRegisterBean.LOGGER.debug("Adding user: " + newUser.toString());

    final FacesContext fc = FacesContext.getCurrentInstance();
    final HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
    final ResourceBundle mails = ResourceBundle.getBundle("de.eod.jliki.EMailMessages",
            fc.getViewRoot().getLocale());
    final String activateEMailTemplate = mails.getString("user.registration.email");
    final StringBuffer url = request.getRequestURL();
    final String serverUrl = url.substring(0, url.lastIndexOf("/"));

    UserRegisterBean.LOGGER.debug("Generated key for user: \"" + userHash + "\"");

    final String emsLink = serverUrl + "/activate.xhtml?user=" + newUser.getName() + "&key=" + userHash;
    final String emsLikiName = ConfigManager.getInstance().getConfig().getPageConfig().getPageName();
    final String emsEMailText = MessageFormat.format(activateEMailTemplate, emsLikiName, this.firstname,
            this.lastname, this.username, emsLink);

    final String emsHost = ConfigManager.getInstance().getConfig().getEmailConfig().getHostname();
    final int emsPort = ConfigManager.getInstance().getConfig().getEmailConfig().getPort();
    final String emsUser = ConfigManager.getInstance().getConfig().getEmailConfig().getUsername();
    final String emsPass = ConfigManager.getInstance().getConfig().getEmailConfig().getPassword();
    final boolean emsTSL = ConfigManager.getInstance().getConfig().getEmailConfig().isUseTLS();
    final String emsSender = ConfigManager.getInstance().getConfig().getEmailConfig().getSenderAddress();

    final Email activateEmail = new SimpleEmail();
    activateEmail.setHostName(emsHost);
    activateEmail.setSmtpPort(emsPort);
    activateEmail.setAuthentication(emsUser, emsPass);
    activateEmail.setTLS(emsTSL);
    try {
        activateEmail.setFrom(emsSender);
        activateEmail.setSubject("Activate jLiki Account");
        activateEmail.setMsg(emsEMailText);
        activateEmail.addTo(this.email);
        activateEmail.send();
    } catch (final EmailException e) {
        UserRegisterBean.LOGGER.error("Sending activation eMail failed!", e);
        return;
    }

    this.username = "";
    this.password = "";
    this.confirm = "";
    this.email = "";
    this.firstname = "";
    this.lastname = "";
    this.captcha = "";
    this.termsOfUse = false;
    this.success = true;

    Messages.addFacesMessage(null, FacesMessage.SEVERITY_INFO, "message.user.registered", this.username);
}

From source file:org.venice.piazza.servicecontroller.messaging.handlers.ExecuteServiceHandler.java

/**
 * This method creates a MediaType based on the mimetype that was provided
 * // w  ww. j av a2s  .co  m
 * @param mimeType
 * @return MediaType
 */
private MediaType createMediaType(String mimeType) {
    MediaType mediaType;
    String type, subtype;
    StringBuffer sb = new StringBuffer(mimeType);
    int index = sb.indexOf("/");
    // If a slash was found then there is a type and subtype
    if (index != -1) {
        type = sb.substring(0, index);

        subtype = sb.substring(index + 1, mimeType.length());
        mediaType = new MediaType(type, subtype);
    } else {
        // Assume there is just a type for the mime, no subtype
        mediaType = new MediaType(mimeType);
    }

    return mediaType;
}

From source file:org.qedeq.base.utility.StringUtility.java

/**
 * Get a byte array of a hex string representation.
 *
 * @param   hex     Hex string representation of data.
 * @return  Data array./*ww w .  j  av  a2s. c  o  m*/
 * @throws  IllegalArgumentException Padding wrong or illegal hexadecimal character.
 */
public static byte[] hex2byte(final String hex) {

    StringBuffer buffer = new StringBuffer(hex.length());
    char c;
    for (int i = 0; i < hex.length(); i++) {
        c = hex.charAt(i);
        if (!Character.isWhitespace(c)) {
            if (!Character.isLetterOrDigit(c)) {
                throw new IllegalArgumentException("Illegal hex char");
            }
            buffer.append(c);
        }
    }
    if (buffer.length() % 2 != 0) {
        throw new IllegalArgumentException("Bad padding");
    }
    byte[] result = new byte[buffer.length() / 2];
    for (int i = 0; i < buffer.length() / 2; i++) {
        try {
            result[i] = (byte) Integer.parseInt(buffer.substring(2 * i, 2 * i + 2), 16);
        } catch (Exception e) {
            throw new IllegalArgumentException("Illegal hex char");
        }
    }
    return result;
}

From source file:com.shenit.commons.utils.HttpUtils.java

/**
 * ??//from  w  w w. j a  va 2s .  c om
 * 
 * @param uri
 * @param req
 * @return
 */
public static String toUrl(String uri, HttpServletRequest req) {
    StringBuffer buffer = req.getRequestURL();
    boolean isSsl = buffer.indexOf(URL_SSL_PREFIX) > -1;
    String base = buffer.substring(0, buffer.indexOf(SLASH, URL_SSL_PREFIX.length() - (isSsl ? 0 : 1)));
    return StringUtils.isEmpty(uri) ? base : base + uri;
}

From source file:org.ppwcode.vernacular.l10n_III.I18nExceptionHelpers.java

/**
 * Helper method for processTemplate to scan the full pattern, once the beginning of a pattern was found.
 *///  w w w  .j a  v a  2  s  .c  o  m
private static String processTemplatePattern(Object context, Locale locale, List<Object> objects,
        CharacterIterator iterator) throws I18nException {
    // previous token was "{", scan up to balanced "}"
    // scan full pattern now
    StringBuffer patternAcc = new StringBuffer(128);
    char token = ' '; // initialise with dummy value
    int balance = 1;
    while ((balance > 0) && (token != CharacterIterator.DONE)) {
        token = iterator.next();
        patternAcc.append(token);
        if (token == '{') {
            balance++;
        } else if (token == '}') {
            balance--;
        }
    }
    // done or bad template ?!?
    if (token == CharacterIterator.DONE) {
        throw new I18nTemplateException("Bad template pattern", patternAcc.toString());
    }
    // remove last "}"
    patternAcc.setLength(patternAcc.length() - 1);
    // prepare pattern, treat the "," for formatting parts
    int comma = patternAcc.indexOf(",");
    String pattern = null;
    String patternPostfix = "";
    if (comma == -1) {
        pattern = patternAcc.toString();
    } else if (comma == 0) {
        throw new I18nTemplateException("Bad template pattern", patternAcc.toString());
    } else {
        pattern = patternAcc.substring(0, comma);
        patternPostfix = patternAcc.substring(comma, patternAcc.length());
    }
    // process pattern
    String processedPattern = processPattern(pattern, context, locale, objects);
    return processedPattern + patternPostfix;
}

From source file:org.kuali.ole.web.LicenseRestServlet.java

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    PrintWriter out = resp.getWriter();
    resp.setContentType("text/xml;charset=UTF-8");
    String result = "";
    Licenses licenses = null;/* w w  w. ja va 2  s.co  m*/
    try {
        ArrayList<File> files = extractBagFilesFromRequest(req, resp);
        for (File file : files) {
            if (file.getName().equalsIgnoreCase("licenses.xml")) {
                String licensesXml = FileUtils.readFileToString(file);
                licenses = (Licenses) Licenses.deserialize(licensesXml);
                for (License license : licenses.getLicenses()) {
                    if (!license.getFormat().equals("onixpl")) {
                        LicenseAttachment licenseAttachment = (LicenseAttachment) license;
                        licenseAttachment.setFilePath(file.getParent());
                    }
                }
            }
        }
        ds.createLicenses(licenses);
        compressUtils.deleteFiles(files);
        File extractFile = new File(extractFilePath);
        extractFile.delete();
    } catch (Exception e) {
        LOG.error("EXception : ", e);
    }
    StringBuffer ids = new StringBuffer();
    for (License license : licenses.getLicenses()) {
        ids.append(license.getId());
        ids.append("/");
    }

    out.write(responseUrl + ids.substring(0, (ids.length() - 1)));
}

From source file:gov.nih.nci.cabig.report2caaers.exchange.EDIMessagePreProcessor.java

public void process(Exchange exchange) throws Exception {
    // just get the body as a string
    String body = exchange.getIn().getBody(String.class);
    log.info("inside EDIMessagePreProcessor...");

    // replace @@ characters with comma
    String replacedDoubleAt = body.replace("@@", ",");

    // replace ## characters with semicolon
    String replacedDoubleHash = replacedDoubleAt.replace("##", ";");

    StringBuffer mIdB = new StringBuffer();
    for (String path : msgComboIdPaths) {
        String value = XPathBuilder.xpath(path).evaluate(exchange, String.class);
        if (StringUtils.isNotBlank(value)) {
            mIdB.append(value).append("::");
        }//from  ww w  . jav  a  2 s.  c om
    }
    String msgComboId = mIdB.substring(0, mIdB.length() - 2); //remove the last '::' char

    // set the properties in the exchange
    Map<String, Object> properties = exchange.getProperties();
    properties.put(MSG_COMBO_ID, msgComboId);

    String msgNumb = XPathBuilder.xpath("//messagenumb/text()").evaluate(exchange, String.class);
    String msgDt = XPathBuilder.xpath("//messagedate/text()").evaluate(exchange, String.class);
    String msgSndrId = XPathBuilder.xpath("//messagesenderidentifier/text()").evaluate(exchange, String.class);
    String msgRcvrId = XPathBuilder.xpath("//messagereceiveridentifier/text()").evaluate(exchange,
            String.class);

    properties.put(MSG_NUMB, msgNumb);
    properties.put(MSG_DT, msgDt);
    properties.put(MSG_SNDR_ID, msgSndrId);
    properties.put(MSG_RCVR_ID, msgRcvrId);
    properties.put(CAAERS_WS_USERNAME, caaersWSUser);
    properties.put(CAAERS_WS_PASSWORD, caaersWSPassword);

    Date now = new Date();

    properties.put(MSG_ID, UUID.randomUUID().toString());
    properties.put(TODAY_DT, msgDF.format(now));
    properties.put(ORIGINAL_MSG, replacedDoubleHash);

    exchange.getOut().setBody(replacedDoubleHash);
}