List of usage examples for java.lang StringBuffer substring
@Override public synchronized String substring(int start, int end)
From source file:ar.com.zauber.commons.social.openid.security.OpenIDAuthenticationProcessingFilter.java
/** * @see AbstractAuthenticationProcessingFilter * #attemptAuthentication(HttpServletRequest, HttpServletResponse) *//* www . ja v a 2s . 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:de.bermuda.arquillian.example.ContentTypeProxyTest.java
@Test public void checkURLTest() { String localPath = "/foo/bar"; PostMethod postMethod = postRequest("TestContent", localPath); StringBuffer body = getHTTPBody(postMethod); Assert.assertTrue("HTTP Body is empty", body.length() > 0); String returnedPath = body.substring(body.indexOf("<path>") + 6, body.indexOf("</path>")); Assert.assertEquals("Path was not correctly mirrored", localPath, returnedPath); }
From source file:de.bermuda.arquillian.example.ContentTypeProxyTest.java
@Test public void checkBodyTest() { String content = "TestContent"; PostMethod postMethod = postRequest(content); StringBuffer body = getHTTPBody(postMethod); Assert.assertTrue("HTTP Body is empty", body.length() > 0); String returnedContent = body.substring(body.indexOf("<content>") + 9, body.indexOf("</content>")); Assert.assertEquals("Body was not copied", content, returnedContent); }
From source file:gate.util.TestFiles.java
/** * Helper method to extract an empty element from a string * containing XML/*from ww w. j a v a 2 s. c om*/ */ String getEmptyElement(String xml, String elementName) { // find the index of "<elementName"; find the next ">" int start = xml.indexOf("<" + elementName); int end = xml.indexOf(">", start); // get the range between the two indices StringBuffer xmlBuf = new StringBuffer(xml); String substr = xmlBuf.substring(start, end + 1); if (DEBUG) { Out.prln("start=" + start + "; end=" + end + "; substr=" + substr); } return substr; }
From source file:com.yolodata.tbana.hadoop.mapred.util.CSVReader.java
protected void foundDelimiter(StringBuffer sb, List<Text> values, boolean takeDelimiterOut) throws UnsupportedEncodingException { Text text = new Text(); String val = (takeDelimiterOut) ? sb.substring(0, sb.length() - separator.length()) : sb.toString(); val = StringUtils.strip(val, "\n"); val = StringUtils.strip(val, delimiter); text.set(val); values.add(text);/* w w w . ja v a 2 s . c o m*/ sb.setLength(0); }
From source file:org.qedeq.base.utility.StringUtility.java
/** * Search for first line followed by whitespace and delete this string within the whole * text./*from ww w .j a v a 2 s.c om*/ * <p> * For example the following text *<pre> * Do you know the muffin man, * The muffin man, the muffin man, * Do you know the muffin man, * Who lives on Drury Lane? *</pre> * will be converted into: *<pre> *Do you know the muffin man, *The muffin man, the muffin man, *Do you know the muffin man, *Who lives on Drury Lane? *</pre> * * @param buffer Work on this text. */ public static void deleteLineLeadingWhitespace(final StringBuffer buffer) { int current = 0; int lastLf = -1; // detect position of last line feed before content starts (lastLf) while (current < buffer.length()) { if (!Character.isWhitespace(buffer.charAt(current))) { break; } if ('\n' == buffer.charAt(current)) { lastLf = current; } current++; } // string from last whitespace line feed until first non whitespace final String empty = buffer.substring(lastLf + 1, current); // delete this string out of the text if (empty.length() > 0) { // System.out.println(string2Hex(empty)); buffer.delete(lastLf + 1, current); // delete first occurence replace(buffer, "\n" + empty, "\n"); // delete same whitespace on all following lines } }
From source file:com.clican.pluto.cms.dao.hibernate.BaseDao.java
protected String getInString(IPojo[] array) { StringBuffer str = new StringBuffer(); str.append("("); for (IPojo pojo : array) { str.append(pojo.getId());//from ww w . ja v a2 s .c om str.append(","); } return str.substring(0, str.length() - 1) + ")"; }
From source file:eionet.transfer.controller.FileOpsController.java
/** * AJAX Upload file for transfer./* w ww .j a v a 2 s.co m*/ */ @RequestMapping(value = "/fileupload", method = RequestMethod.POST, params = "ajaxupload=1") public void importFileWithAJAX(@RequestParam("file") MultipartFile myFile, @RequestParam("fileTTL") int fileTTL, HttpServletRequest request, HttpServletResponse response) throws IOException { if (myFile == null || myFile.getOriginalFilename() == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Select a file to upload"); return; } if (fileTTL > 90) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid expiration date"); return; } String uuidName = storeFile(myFile, fileTTL); response.setContentType("text/xml"); PrintWriter printer = response.getWriter(); StringBuffer requestUrl = request.getRequestURL(); String url = requestUrl.substring(0, requestUrl.length() - "/fileupload".length()); printer.println("<?xml version='1.0'?>"); printer.println("<package>"); printer.println("<downloadLink>" + url + "/download/" + uuidName + "</downloadLink>"); printer.println("<deleteLink>" + url + "/delete/" + uuidName + "</deleteLink>"); printer.println("</package>"); printer.flush(); response.flushBuffer(); }
From source file:com.clican.pluto.cms.dao.hibernate.BaseDao.java
protected String getInString(Collection<? extends IPojo> collection) { StringBuffer str = new StringBuffer(); str.append("("); for (IPojo pojo : collection) { str.append(pojo.getId());/* w w w .j a v a 2 s. c o m*/ str.append(","); } return str.substring(0, str.length() - 1) + ")"; }
From source file:com.huguesjohnson.retroleague.rss.RssParserHandler.java
@Override public void endElement(String uri, String localName, String qName) throws SAXException { super.endElement(uri, localName, qName); try {/*from ww w . java2s. co m*/ String tagName = localName; if ((tagName == null) || (tagName.length() < 1)) { tagName = qName; } if (inItemBlock) { if (tagName.equalsIgnoreCase(TAG_ITEM)) { if (this.currentEntry.getPostedDate().compareTo(this.minimumDate) > 0) { this.entryList.add(this.currentEntry); } this.currentEntry = null; readThis = false; inItemBlock = false; } else if (tagName.equalsIgnoreCase(TAG_TITLE)) { //check if this is the rss channel title or the item title if (this.currentEntry != null) { String title = this.characters.toString(); if (this.source == Sources.Facebook) { title = StringEscapeUtils.unescapeHtml4(title); } this.currentEntry.setTitle(title); } readThis = false; } else if (tagName.equalsIgnoreCase(TAG_DESCRIPTION)) { //check if this is the rss channel description or the item description if (this.currentEntry != null) { //TODO - hack to ensure content is html, maybe look for a less hacky solution StringBuffer content = new StringBuffer(this.characters.toString()); if ((!content.substring(0, 1).equals("<")) || (!content.substring(0, 4).equals("<"))) { content.insert(0, "<p>"); content.append("</p>"); } this.currentEntry.setContent(content.toString()); } readThis = false; } else if (tagName.equalsIgnoreCase(TAG_PUBDATE)) { String sDate = this.characters.toString(); this.currentEntry.setPostedDate(this.dateParser.parseDate(sDate)); readThis = false; } else if (tagName.equalsIgnoreCase(TAG_LINK)) { //check if this is the rss channel link or the item link if (this.currentEntry != null) { this.currentEntry.setUrl(this.characters.toString()); } readThis = false; } } else { if (tagName.equalsIgnoreCase(TAG_TITLE)) { //don't care about the rss channel title readThis = false; } } } catch (Exception x) { Log.e(TAG, "endElement", x); } }