List of usage examples for java.lang StringBuffer lastIndexOf
@Override public int lastIndexOf(String str)
From source file:hydrograph.ui.graph.command.ComponentPasteCommand.java
private String getPrefix(Object node) { String currentName = ((Component) node).getComponentLabel().getLabelContents(); String prefix = currentName;//from w ww .j a va2 s . c o m StringBuffer buffer = new StringBuffer(currentName); try { if (buffer.lastIndexOf(UNDERSCORE) != -1 && (buffer.lastIndexOf(UNDERSCORE) != buffer.length())) { String substring = StringUtils .trim(buffer.substring(buffer.lastIndexOf(UNDERSCORE) + 1, buffer.length())); if (StringUtils.isNumeric(substring)) { prefix = buffer.substring(0, buffer.lastIndexOf(UNDERSCORE)); } } } catch (Exception exception) { LOGGER.warn("Cannot process component name for detecting prefix : ", exception.getMessage()); } return prefix; }
From source file:net.wasdev.gameon.auth.github.GitHubCallback.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //ok, we have our code.. so the user has agreed to our app being authed. String code = request.getParameter("code"); String state = (String) request.getSession().getAttribute("github"); //now we need to invoke the access_token endpoint to swap the code for a token. StringBuffer callbackURL = request.getRequestURL(); int index = callbackURL.lastIndexOf("/"); callbackURL.replace(index, callbackURL.length(), "").append("/GitHubCallback"); HttpRequestFactory requestFactory;// w ww . j a v a 2 s .c o m try { //we'll ignore the ssl cert of the github server for now.. //eventually we may add this to the player truststore.. requestFactory = new NetHttpTransport.Builder().doNotValidateCertificate().build() .createRequestFactory(); //prepare the request.. GenericUrl url = new GenericUrl("https://github.com/login/oauth/access_token"); //set the client id & secret from the injected environment. url.put("client_id", key); url.put("client_secret", secret); //add the code we just got given.. url.put("code", code); url.put("redirect_uri", callbackURL); url.put("state", state); //now place the request to github.. HttpRequest infoRequest = requestFactory.buildGetRequest(url); HttpResponse r = infoRequest.execute(); String resp = "failed."; if (r.isSuccessStatusCode()) { //response comes back as query param encoded data.. we'll grab the token from that... resp = r.parseAsString(); //http client way to parse query params.. List<NameValuePair> params = URLEncodedUtils.parse(resp, Charset.forName("UTF-8")); String token = null; for (NameValuePair param : params) { if ("access_token".equals(param.getName())) { token = param.getValue(); } } if (token != null) { //great, we have a token, now we can use that to request the user profile.. GenericUrl query = new GenericUrl("https://api.github.com/user"); query.put("access_token", token); HttpRequest userRequest = requestFactory.buildGetRequest(query); HttpResponse u = userRequest.execute(); if (u.isSuccessStatusCode()) { //user profile comes back as json.. resp = u.parseAsString(); System.out.println(resp); //use om to parse the json, so we can grab the id & name from it. ObjectMapper om = new ObjectMapper(); JsonNode jn = om.readValue(resp, JsonNode.class); Map<String, String> claims = new HashMap<String, String>(); claims.put("valid", "true"); //github id is a number, but we'll read it as text incase it changes in future.. claims.put("id", "github:" + jn.get("id").asText()); claims.put("name", jn.get("login").textValue()); String jwt = createJwt(claims); //log for now, we'll clean this up once it's all working =) System.out.println("New User Authed: " + claims.get("id") + " jwt " + jwt); response.sendRedirect(callbackSuccess + "/" + jwt); } else { System.out.println(u.getStatusCode()); response.sendRedirect("http://game-on.org/#/game"); } } else { System.out.println("did not find token in github response " + resp); response.sendRedirect("http://game-on.org/#/game"); } } else { response.sendRedirect("http://game-on.org/#/game"); } } catch (GeneralSecurityException e) { throw new ServletException(e); } }
From source file:org.medici.bia.controller.search.SimpleSearchController.java
/** * This controller act as a dispatcher for result view. * //from w ww . j a va2 s .co m * @param command * @param result * @return */ @RequestMapping(method = { RequestMethod.POST }) public ModelAndView processSubmit(@ModelAttribute("command") SimpleSearchCommand command, BindingResult result) { Map<String, Object> model = new HashMap<String, Object>(0); try { command.setText(URIUtil.decode(command.getText(), "UTF-8")); } catch (URIException e) { } if (StringUtils.countMatches(command.getText(), "\"") % 2 != 0) { StringBuffer tempString = new StringBuffer(command.getText()); tempString.setCharAt(tempString.lastIndexOf("\""), ' '); command.setText(tempString.toString()); } model.put("yourSearch", command.getText()); // RR: we consider single quote equivalent to double quotes model.put("textSearch", command.getText().replace("'", "%22").replace("\"", "%22")); // This number is used to generate an unique id for new search UUID uuid = UUID.randomUUID(); command.setSearchUUID(uuid.toString()); model.put("searchUUID", uuid.toString()); // Add outputFields; List<String> outputFields = getOutputFields(command.getSimpleSearchPerimeter()); model.put("outputFields", outputFields); return new ModelAndView("search/SimpleSearchResult", model); }
From source file:ar.com.zauber.commons.social.openid.security.OpenIDAuthenticationProcessingFilter.java
/** * @see AbstractAuthenticationProcessingFilter * #attemptAuthentication(HttpServletRequest, HttpServletResponse) *//*from www .ja v a 2 s . co m*/ @Override public final Authentication attemptAuthentication(final HttpServletRequest request, final HttpServletResponse response) throws AuthenticationException, IOException, ServletException { OpenIdUser user = null; try { user = relyingParty.discover(request); if (user == null) { if (RelyingParty.isAuthResponse(request)) { // authentication timeout return null; } else { // set error msg if the openid_identifier is not resolved. if (request.getParameter(relyingParty.getIdentifierParameter()) != null) { request.setAttribute(OpenIdServletFilter.ERROR_MSG_ATTR, "as"); } // error response.sendRedirect(errorUrl); return null; } } if (user.isAuthenticated()) { // user already authenticated return this.getAuthenticationManager() .authenticate(new OpenIDAuthenticationToken(new OpenIDIdentity(user.getIdentity()))); } if (user.isAssociated() && RelyingParty.isAuthResponse(request)) { // verify authentication if (relyingParty.verifyAuth(user, request, response)) { // authenticated return this.getAuthenticationManager() .authenticate(new OpenIDAuthenticationToken(new OpenIDIdentity(user.getIdentity()))); } else { // failed verification throw new BadCredentialsException("open id authentication failed"); } } // associate and authenticate user StringBuffer url = request.getRequestURL(); String trustRoot = url.substring(0, url.indexOf("/", 9)); String realm = url.substring(0, url.lastIndexOf("/")); String returnTo = url.toString(); if (relyingParty.associateAndAuthenticate(user, request, response, trustRoot, realm, returnTo)) { // successful association return null; } } catch (Exception e) { throw new AuthenticationServiceException( "Exception while authenticating with openID: " + e.getMessage(), e); } return null; }
From source file:hydrograph.ui.expression.editor.util.ExpressionEditorUtil.java
/** * Returns package name from formatted text. * //from ww w . j a v a 2s . c o m * @param formattedPackageName * Format should be : package-name.* - jarname * @return * package-name */ public String getPackageNameFromFormattedText(String formattedPackageName) { StringBuffer buffer = new StringBuffer(); try { buffer.append(formattedPackageName); buffer.delete(buffer.lastIndexOf(Constants.ASTERISK), formattedPackageName.length() - 1); buffer.delete(buffer.lastIndexOf(Constants.DOT), buffer.length()); return buffer.toString(); } catch (Exception exception) { LOGGER.warn("Invalid format of package name", exception); } return Constants.EMPTY_STRING; }
From source file:com.all.backend.web.controller.PasswordResetServerController.java
@RequestMapping("/reset/{key}") public String showResetPasswordView(@PathVariable String key, Model model, HttpServletRequest request) { log.info("\nACTION:PasswordReset"); User user = registrationService.getUserForPasswordResetRequest(key); if (user != null) { StringBuffer requestURL = request.getRequestURL(); String url = requestURL.substring(0, requestURL.lastIndexOf("/") + 1); log.debug("url: " + url); model.addAttribute("submitUrl", url); model.addAttribute("userFullName", user.getFullName()); model.addAttribute("key", key); return "resetPassword.jsp"; }/* w w w.j av a 2 s . co m*/ return "expiredPassword.jsp"; }
From source file:de.tudarmstadt.ukp.dkpro.wsd.io.reader.AidaReader.java
private void addAnnotations(JCas jCas, StringBuffer documentText, String namedEntity, String aidaResult) { int offset = documentText.lastIndexOf(namedEntity); int length = namedEntity.length(); if (offset == -1) { offset = documentText.lastIndexOf(namedEntity.replaceAll("'", " '")); length += StringUtils.countMatches(namedEntity, "'"); }/* w w w .ja va2 s . com*/ // add WSDItem WSDItem wsdItem = getWsdItem(jCas, offset, length, namedEntity); // Get sense tags FSArray senseArray = new FSArray(jCas, 1); Sense sense = new Sense(jCas); sense.setId(StringEscapeUtils.unescapeJava(aidaResult)); sense.setConfidence(1.0); sense.addToIndexes(); senseArray.set(0, sense); WSDResult wsdResult = new WSDResult(jCas); wsdResult.setWsdItem(wsdItem); wsdResult.setSenses(senseArray); wsdResult.setSenseInventory(senseInventory); wsdResult.setDisambiguationMethod(DISAMBIGUATION_METHOD_NAME); wsdResult.addToIndexes(); }
From source file:org.medici.bia.controller.search.ExpandResultsSimpleSearchController.java
/** * This controller act as a dispatcher for result view. * // w ww.j a va 2 s. co m * @param command * @param result * @return */ @RequestMapping(method = { RequestMethod.GET }) public ModelAndView processSubmit(@ModelAttribute("command") ExpandResultsSimpleSearchCommand command, BindingResult result) { Map<String, Object> model = new HashMap<String, Object>(0); try { command.setsSearch(URIUtil.decode(command.getsSearch(), "UTF-8")); } catch (URIException e) { } if (StringUtils.countMatches(command.getsSearch(), "\"") % 2 != 0) { StringBuffer tempString = new StringBuffer(command.getsSearch()); tempString.setCharAt(tempString.lastIndexOf("\""), ' '); command.setsSearch(tempString.toString()); } //This code is for highlight the correct words StringBuffer yourSearch = new StringBuffer(); if (command.getsSearch().contains("\"")) { StringTokenizer stringTokenizer = new StringTokenizer(command.getsSearch().replace('"', ' '), " "); while (stringTokenizer.hasMoreTokens()) { String currentToken = stringTokenizer.nextToken(); if (currentToken.length() > 0 && currentToken != "") { if (yourSearch.toString().length() > 0) yourSearch.append(" " + currentToken); else yourSearch.append(currentToken); } } } else { yourSearch.append(command.getsSearch()); } model.put("yourSearch", yourSearch.toString()); if (command.getsSearch().contains("\"")) { command.setsSearch(command.getsSearch().replace("\"", "\\\"")); } // This number is used to generate an unique id for new search UUID uuid = UUID.randomUUID(); command.setSearchUUID(uuid.toString()); model.put("searchUUID", uuid.toString()); // Add outputFields; List<String> outputFields = getOutputFields(command.getSimpleSearchPerimeter()); model.put("outputFields", outputFields); return new ModelAndView("search/ExpandSimpleSearchResult", model); }
From source file:org.wso2.carbon.identity.application.common.config.IdentityApplicationConfig.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 ww w. j a va2s .c om key.deleteCharAt(key.lastIndexOf(".")); return key.toString(); }
From source file:com.dyuproject.demos.openidservlet.HomeServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getSession().getAttribute(WebConstants.SessionConstants.RC_USER) != null) { response.sendRedirect("/login/logged.html"); return;/* w w w. j a v a2 s. c om*/ } String loginWith = request.getParameter("loginWith"); if (loginWith != null) { // If the ui supplies a LoginWithGoogle or LoginWithYahoo // link/button, // this will speed up the openid process by skipping discovery. // The override is done by adding the OpenIdUser to the request // attribute. if (loginWith.equals("google")) { OpenIdUser user = OpenIdUser.populate("https://www.google.com/accounts/o8/id", YadisDiscovery.IDENTIFIER_SELECT, "https://www.google.com/accounts/o8/ud"); request.setAttribute(OpenIdUser.ATTR_NAME, user); } else if (loginWith.equals("yahoo")) { OpenIdUser user = OpenIdUser.populate("http://https://me.yahoo.com/user", YadisDiscovery.IDENTIFIER_SELECT, "https://open.login.yahooapis.com/openid/op/auth"); request.setAttribute(OpenIdUser.ATTR_NAME, user); } } String errorMsg = OpenIdServletFilter.DEFAULT_ERROR_MSG; try { OpenIdUser user = _relyingParty.discover(request); if (user == null) { if (RelyingParty.isAuthResponse(request)) { // authentication timeout response.sendRedirect(request.getRequestURI()); } else { // set error msg if the openid_identifier is not resolved. if (request.getParameter(_relyingParty.getIdentifierParameter()) != null) { request.setAttribute(OpenIdServletFilter.ERROR_MSG_ATTR, errorMsg); } // new user request.getRequestDispatcher("/login/login.jsp").forward(request, response); } return; } if (user.isAuthenticated()) { // user already authenticated request.getRequestDispatcher("/preAuth").forward(request, response); return; } if (user.isAssociated() && RelyingParty.isAuthResponse(request)) { // verify authentication if (_relyingParty.verifyAuth(user, request, response)) { // authenticated // redirect to home to remove the query params instead of // doing: // request.getRequestDispatcher("/home.jsp").forward(request, // response); response.sendRedirect(request.getContextPath() + "/home/"); } else { // failed verification request.getRequestDispatcher("/login/login.jsp").forward(request, response); } return; } // associate and authenticate user StringBuffer url = request.getRequestURL(); String trustRoot = url.substring(0, url.indexOf("/", 9)); String realm = url.substring(0, url.lastIndexOf("/")); String returnTo = url.toString(); if (_relyingParty.associateAndAuthenticate(user, request, response, trustRoot, realm, returnTo)) { // successful association return; } } catch (UnknownHostException uhe) { System.err.println("not found"); errorMsg = OpenIdServletFilter.ID_NOT_FOUND_MSG; } catch (FileNotFoundException fnfe) { System.err.println("could not be resolved"); errorMsg = OpenIdServletFilter.DEFAULT_ERROR_MSG; } catch (Exception e) { errorMsg = OpenIdServletFilter.DEFAULT_ERROR_MSG; } request.setAttribute(OpenIdServletFilter.ERROR_MSG_ATTR, errorMsg); request.getRequestDispatcher("/login/login.jsp").forward(request, response); }