List of usage examples for java.lang StringBuffer indexOf
@Override public int indexOf(String str)
From source file:org.nuxeo.ecm.webengine.model.impl.AbstractWebContext.java
@Override public String getBaseURL() { StringBuffer sb = request.getRequestURL(); int p = sb.indexOf(getBasePath()); if (p > -1) { return sb.substring(0, p); }//from ww w. j a va 2 s . c o m return sb.toString(); }
From source file:org.ormma.controller.OrmmaAssetController.java
/** * Write an input stream to a file wrapping it with ormma stuff * /* www. jav a2 s.com*/ * @param in * the input stream * @param file * the file to store it in * @param storeInHashedDirectory * use a hashed directory name * @return the path where it was stored * @throws IllegalStateException * the illegal state exception * @throws IOException * Signals that an I/O exception has occurred. */ public String writeToDiskWrap(InputStream in, String file, boolean storeInHashedDirectory, String injection, String bridgePath, String ormmaPath) throws IllegalStateException, IOException /** * writes a HTTP entity to the specified filename and location on disk */ { byte buff[] = new byte[1024]; MessageDigest digest = null; if (storeInHashedDirectory) { try { digest = java.security.MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } // check for html tag in the input ByteArrayOutputStream fromFile = new ByteArrayOutputStream(); FileOutputStream out = null; try { do { int numread = in.read(buff); if (numread <= 0) { break; } if (storeInHashedDirectory && digest != null) { digest.update(buff); } fromFile.write(buff, 0, numread); } while (true); String wholeHTML = fromFile.toString(); Log.d("html", wholeHTML); boolean hasHTMLWrap = wholeHTML.indexOf("</html>") >= 0; // TODO cannot have injection when full html StringBuffer wholeHTMLBuffer = null; if (hasHTMLWrap) { wholeHTMLBuffer = new StringBuffer(wholeHTML); int start = wholeHTMLBuffer.indexOf("/ormma_bridge.js"); if (start <= 0) { // TODO error } wholeHTMLBuffer.replace(start, start + "/ormma_bridge.js".length(), "file:/" + bridgePath); start = wholeHTMLBuffer.indexOf("/ormma.js"); if (start <= 0) { // TODO error } wholeHTMLBuffer.replace(start, start + "/ormma.js".length(), "file:/" + ormmaPath); } out = getAssetOutputString(file); if (!hasHTMLWrap) { out.write("<html>".getBytes()); out.write("<head>".getBytes()); out.write("<meta name='viewport' content='user-scalable=no initial-scale=1.0' />".getBytes()); out.write("<title>Advertisement</title> ".getBytes()); out.write( ("<script src=\"file:/" + bridgePath + "\" type=\"text/javascript\"></script>").getBytes()); out.write( ("<script src=\"file:/" + ormmaPath + "\" type=\"text/javascript\"></script>").getBytes()); if (injection != null) { out.write("<script type=\"text/javascript\">".getBytes()); out.write(injection.getBytes()); out.write("</script>".getBytes()); } out.write("</head>".getBytes()); out.write("<body style=\"margin:0; padding:0; overflow:hidden; background-color:transparent;\">" .getBytes()); out.write("<div align=\"center\"> ".getBytes()); } if (!hasHTMLWrap) { out.write(fromFile.toByteArray()); } else { out.write(wholeHTMLBuffer.toString().getBytes()); } if (!hasHTMLWrap) { out.write("</div> ".getBytes()); out.write("</body> ".getBytes()); out.write("</html> ".getBytes()); } out.flush(); // out.close(); // in.close(); } finally { if (fromFile != null) { try { fromFile.close(); } catch (Exception e) { // TODO: handle exception } fromFile = null; } if (out != null) { try { out.close(); } catch (Exception e) { // TODO: handle exception } out = null; } } String filesDir = getFilesDir(); if (storeInHashedDirectory && digest != null) { filesDir = moveToAdDirectory(file, filesDir, asHex(digest)); } return filesDir; }
From source file:org.kuali.kra.protocol.protocol.funding.ProtocolFundingSourceServiceImplBase.java
@Override public String updateLookupParameter(String parameter, String boClassName, String fieldConversions) { StringBuffer fullParameterBuffer = new StringBuffer(parameter); int start = fullParameterBuffer.indexOf(KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL) + KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL.length(); int end = fullParameterBuffer.indexOf(KRADConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL); fullParameterBuffer.replace(start, end, boClassName); start = fullParameterBuffer.indexOf(KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL) + KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL.length(); end = fullParameterBuffer.indexOf(KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL); fullParameterBuffer.replace(start, end, fieldConversions); return fullParameterBuffer.toString(); }
From source file:org.kuali.kra.irb.protocol.funding.ProtocolFundingSourceServiceImpl.java
/** * {@inheritDoc}/*w ww . j a v a 2 s . c om*/ * @see org.kuali.kra.irb.protocol.funding.ProtocolFundingSourceService#updateLookupParameter(java.lang.String, java.lang.String, java.lang.String) */ public String updateLookupParameter(String parameter, String boClassName, String fieldConversions) { StringBuffer fullParameterBuffer = new StringBuffer(parameter); int start = fullParameterBuffer.indexOf(KNSConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL) + KNSConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL.length(); int end = fullParameterBuffer.indexOf(KNSConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL); fullParameterBuffer.replace(start, end, boClassName); start = fullParameterBuffer.indexOf(KNSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL) + KNSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL.length(); end = fullParameterBuffer.indexOf(KNSConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL); fullParameterBuffer.replace(start, end, fieldConversions); return fullParameterBuffer.toString(); }
From source file:org.apache.nutch.protocol.s2jh.HttpResponse.java
private void parseHeaders(PushbackInputStream in, StringBuffer line) throws IOException, HttpException { while (readLine(in, line, true) != 0) { // handle HTTP responses with missing blank line after headers int pos;/*from ww w.ja va2 s.c om*/ if (((pos = line.indexOf("<!DOCTYPE")) != -1) || ((pos = line.indexOf("<HTML")) != -1) || ((pos = line.indexOf("<html")) != -1)) { in.unread(line.substring(pos).getBytes("UTF-8")); line.setLength(pos); try { // TODO: (CM) We don't know the header names here // since we're just handling them generically. It would // be nice to provide some sort of mapping function here // for the returned header names to the standard metadata // names in the ParseData class processHeaderLine(line); } catch (Exception e) { // fixme: Http.LOG.error("Failed with the following exception: ", e); } return; } processHeaderLine(line); } }
From source file:com.fuseim.webapp.ProxyServlet.java
/** * For a redirect response from the target server, this translates {@code theUrl} to redirect to * and translates it to one the original client can use. */// ww w . ja va 2 s . c o m protected String rewriteUrlFromResponse(HttpServletRequest servletRequest, String theUrl) { //TODO document example paths final String targetUri = getTargetUri(servletRequest); if (theUrl.startsWith(targetUri)) { /*- * The URL points back to the back-end server. * Instead of returning it verbatim we replace the target path with our * source path in a way that should instruct the original client to * request the URL pointed through this Proxy. * We do this by taking the current request and rewriting the path part * using this servlet's absolute path and the path from the returned URL * after the base target URL. */ StringBuffer curUrl = servletRequest.getRequestURL(); //no query int pos; // Skip the protocol part if ((pos = curUrl.indexOf("://")) >= 0) { // Skip the authority part // + 3 to skip the separator between protocol and authority if ((pos = curUrl.indexOf("/", pos + 3)) >= 0) { // Trim everything after the authority part. curUrl.setLength(pos); } } // Context path starts with a / if it is not blank curUrl.append(servletRequest.getContextPath()); // Servlet path starts with a / if it is not blank curUrl.append(servletRequest.getServletPath()); curUrl.append(theUrl, targetUri.length(), theUrl.length()); theUrl = curUrl.toString(); } return theUrl; }
From source file:com.google.dart.tools.ui.text.dart.CompletionProposalLabelProvider.java
/** * Returns the display string for a Dart type signature. * /* w w w.j a v a 2s . co m*/ * @param typeSignature the type signature to create a display name for * @return the display name for <code>typeSignature</code> * @throws IllegalArgumentException if <code>typeSignature</code> is not a valid signature * @see Signature#toCharArray(char[]) * @see Signature#getSimpleName(char[]) */ private char[] createTypeDisplayName(char[] typeSignature) throws IllegalArgumentException { char[] displayName = Signature.getSimpleName(Signature.toCharArray(typeSignature)); // XXX see https://bugs.eclipse.org/bugs/show_bug.cgi?id=84675 boolean useShortGenerics = false; if (useShortGenerics) { StringBuffer buf = new StringBuffer(); buf.append(displayName); int pos; do { pos = buf.indexOf("? extends "); //$NON-NLS-1$ if (pos >= 0) { buf.replace(pos, pos + 10, "+"); //$NON-NLS-1$ } else { pos = buf.indexOf("? super "); //$NON-NLS-1$ if (pos >= 0) { buf.replace(pos, pos + 8, "-"); //$NON-NLS-1$ } } } while (pos >= 0); return buf.toString().toCharArray(); } return displayName; }
From source file:org.apache.nutch.protocol.http.HttpResponse.java
private void parseHeaders(PushbackInputStream in, StringBuffer line, StringBuffer httpHeaders) throws IOException, HttpException { while (readLine(in, line, true) != 0) { if (httpHeaders != null) httpHeaders.append(line).append("\n"); // handle HTTP responses with missing blank line after headers int pos;//from w w w .jav a 2 s . c o m if (((pos = line.indexOf("<!DOCTYPE")) != -1) || ((pos = line.indexOf("<HTML")) != -1) || ((pos = line.indexOf("<html")) != -1)) { in.unread(line.substring(pos).getBytes("UTF-8")); line.setLength(pos); try { // TODO: (CM) We don't know the header names here // since we're just handling them generically. It would // be nice to provide some sort of mapping function here // for the returned header names to the standard metadata // names in the ParseData class processHeaderLine(line); } catch (Exception e) { // fixme: Http.LOG.warn("Error: ", e); } return; } processHeaderLine(line); } }
From source file:com.newatlanta.appengine.vfs.provider.GaeFileNameParser.java
/** * Makes sure <code>filename</code> always specifies a path that is within a * sub-directory of the webapp root path. *//*from w ww .j a va2 s . c o m*/ public FileName parseUri(VfsComponentContext context, FileName baseName, String uri) throws FileSystemException { StringBuffer name = new StringBuffer(); // Extract the scheme String scheme = UriParser.extractScheme(uri, name); if (scheme == null) { // this should never happen scheme = "gae"; } // Remove encoding, and adjust the separators UriParser.canonicalizePath(name, 0, name.length(), this); UriParser.fixSeparators(name); // Normalise the path FileType fileType = UriParser.normalisePath(name); // all GAE files *must* be relative to the root file, which must be the // webapp root (though we have no way of enforcing this) String rootPath = ""; if (baseName == null) { // this is the root object rootPath = name.toString(); name.setLength(0); } else { rootPath = getRootPath(baseName); if (name.indexOf(rootPath) == 0) { // if ( name.startsWith( basePath ) ) name.delete(0, rootPath.length()); } } return new GaeFileName(scheme, rootPath, name.toString(), fileType); }
From source file:com.isecpartners.gizmo.HttpRequest.java
private void readerToStringBuffer(DataInputStream buffered, StringBuffer contents) { try {//from www . j a v a2 s . c o m byte ch_n = buffered.readByte(); while (ch_n != -1) { contents.append((char) ch_n); if ((contents.indexOf("\r\n\r\n") != -1) || (buffered.available() == 0)) { break; } ch_n = buffered.readByte(); } } catch (Exception ex) { System.out.println(ex); } }