List of usage examples for java.lang StringBuffer lastIndexOf
@Override public int lastIndexOf(String str)
From source file:de.eod.jliki.users.jsfbeans.UserRegisterBean.java
/** * Adds a new user to the jLiki database.<br/> *//*from ww w .j a v a2 s. c om*/ 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:us.mn.state.health.lims.reports.action.implementation.ExportProjectByDate.java
protected void writeConsolidatedBaseToBuffer(ByteArrayOutputStream buffer, String[] splitBase) throws IOException, UnsupportedEncodingException { if (splitBase != null) { StringBuffer consolidatedLine = new StringBuffer(); for (String value : splitBase) { consolidatedLine.append(value); consolidatedLine.append(","); }/* www . ja v a2 s . com*/ consolidatedLine.deleteCharAt(consolidatedLine.lastIndexOf(",")); buffer.write(consolidatedLine.toString().getBytes("windows-1252")); } }
From source file:org.squale.squalix.tools.clearcase.task.ClearCaseTask.java
/** * Cette mthode modifie le paramtre <code>view_path</code> de la <code> * HashMap</code> des paramtres/* www . java2s .c o m*/ * temporaires de l'objet <code> * ProjectBO</code>. * * @throws Exception exception lors du traitement. */ private void modifyTempMap() throws Exception { /* * on rcupre le chemin du dossier dans lequel ont t mis les fichiers de la vue, et on met cette valeur dans * la hashmap de paramtres. */ StringBuffer buf = new StringBuffer(mConfiguration.getUmountViewCommand().trim()); int length = buf.length(); String viewPath = buf.substring(buf.lastIndexOf(ClearCaseConfiguration.SPACE) + 1, length); getData().putData(TaskData.VIEW_PATH, viewPath); }
From source file:com.asociate.dao.UsuarioDAO.java
/** * * @param amigos/*from ww w . java 2s . com*/ * @return */ public List<Usuario> getAmigosDeLista(List<Amistad> amigos) { List<Usuario> salida = new ArrayList(); Session sesion = HibernateUtil.getSessionFactory().openSession(); StringBuffer sb = new StringBuffer(); for (Amistad am : amigos) { sb.append(" "); sb.append(am.getIdAmigo()); sb.append(" ,"); } sb.delete(sb.lastIndexOf(",") - 1, sb.length()); try { Query qu = sesion.createQuery("Select U from Usuario U where U.persona.idPersona in(:list)"); qu.setParameter("list", sb.toString()); salida = qu.list(); } catch (RuntimeException e) { e.printStackTrace(); } finally { sesion.flush(); sesion.close(); } return salida; }
From source file:com.all.backend.web.controller.LoginServerController.java
@RequestMapping(method = POST, value = "/password") @ResponseBody//from w w w . j a v a2 s. c o m public String resetRequest(@RequestBody String mail, HttpServletRequest request) { log.info("\nACTION:ForgotPasswordRequest"); StringBuffer requestURL = request.getRequestURL(); String url = requestURL.substring(0, requestURL.lastIndexOf("/") + 1) + "reset/"; String forgotPasswordResult = userService.createPasswordResetRequest(mail, url); log.debug("forgotPasswordResult: " + forgotPasswordResult); String result = ""; String[] resultAsarray = forgotPasswordResult.split(";"); if (resultAsarray.length == 2) { result = resultAsarray[0]; url = resultAsarray[1]; PendingEmail pendingEmail = createPasswordPendingEmail(url, mail); BackendServiceHelper.queue(emailService, BackendConstants.SEND_RESET_PASSWORD_EMAIL_REQUEST_TYPE, pendingEmail); } else { result = forgotPasswordResult; } return result; }
From source file:org.etudes.component.app.melete.SpecialAccessDB.java
public void deleteSpecialAccess(List saList) throws Exception { Transaction tx = null;//from w w w . jav a 2 s . c o m SpecialAccess sa = null; String delAccessIds = null; StringBuffer allAccessIds = new StringBuffer("("); for (Iterator saIter = saList.iterator(); saIter.hasNext();) { Integer accessId = (Integer) saIter.next(); allAccessIds.append(accessId.toString() + ","); } if (allAccessIds.lastIndexOf(",") != -1) delAccessIds = allAccessIds.substring(0, allAccessIds.lastIndexOf(",")) + " )"; String delSpecialAccessStr = "delete SpecialAccess sa where sa.accessId in " + delAccessIds; try { Session session = getHibernateUtil().currentSession(); tx = session.beginTransaction(); int deletedEntities = session.createQuery(delSpecialAccessStr).executeUpdate(); tx.commit(); } catch (HibernateException he) { if (tx != null) tx.rollback(); logger.error(he.toString()); throw he; } catch (Exception e) { if (tx != null) tx.rollback(); logger.error(e.toString()); throw e; } finally { try { hibernateUtil.closeSession(); } catch (HibernateException he) { logger.error(he.toString()); throw he; } } }
From source file:org.wso2.carbon.appfactory.common.AppFactoryConfigurationBuilder.java
private String getKey(Stack<String> nameStack) { StringBuffer key = new StringBuffer(); for (int i = 0; i < nameStack.size(); i++) { String name = nameStack.elementAt(i); key.append(name).append("."); }/*from w ww . j a v a 2 s .c om*/ key.deleteCharAt(key.lastIndexOf(".")); return key.toString(); }
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 {//from w ww . j av a 2 s .c om fileContent.insert(fileContent.lastIndexOf("}"), method.METHOD_STRING); globalMethodList.add(method); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.bibsonomy.model.util.BibTexUtils.java
/** Adds the given field at the end of the given BibTeX entry by placing * it before the last brace. /*from ww w .j ava 2 s.co m*/ * * @param bibtex - the BibTeX entry * @param fieldName - the name of the field * @param fieldValue - the value of the field */ public static void addField(final StringBuffer bibtex, final String fieldName, final String fieldValue) { /* * ignore empty bibtex and empty field values */ if (bibtex == null || fieldValue == null || fieldValue.trim().equals("")) return; /* * remove last comma if there is one (before closing last curly bracket) */ final String bib = bibtex.toString().trim(); final Matcher m = LAST_COMMA_PATTERN.matcher(bib); if (m.matches()) { final int _lastIndex = bib.lastIndexOf(","); bibtex.replace(_lastIndex, _lastIndex + 1, ""); } final int lastIndexOf = bibtex.lastIndexOf("}"); if (lastIndexOf > 0) { bibtex.replace(lastIndexOf, bibtex.length(), "," + fieldName + " = {" + fieldValue + "}\n}"); } }
From source file:xyz.appint.union.utils.StringUtils.java
public static StringBuffer removeLastComma(StringBuffer sb) { StringBuffer stringBuf = new StringBuffer(); String s = new String(sb); if (sb.length() > 0) { int postion = sb.lastIndexOf(","); if (postion == sb.length() - 1) { s = s.substring(0, postion); }/*from ww w . j a va 2s . co m*/ } stringBuf.append(s); return stringBuf; }