List of usage examples for java.lang StringBuffer indexOf
@Override public int indexOf(String str)
From source file:org.wso2.carbon.governance.sramp.SRAMPServlet.java
private String getServletURL(HttpServletRequest req) { try {// ww w . j a va2s . co m StringBuffer requestURL = req.getRequestURL(); return requestURL.substring(0, requestURL.indexOf(S_RAMP_SERVLET_CONTEXT) + S_RAMP_SERVLET_CONTEXT.length()); } catch (Exception ignore) { // if there are any issues in obtaining the servlet URL, simply return the default HTTPS // URL. return servletURL; } }
From source file:com.bluexml.xforms.actions.AbstractWorkflowAction.java
/** * Appends parameters that may be useful to the given target URL. * /*ww w . ja va2 s . co m*/ * @param targetUrl * @return */ protected String addRedirectionParameters(String targetUrl, boolean autoAdvance, boolean addParams, Map<String, String> initParams, String suffix) { if (addParams == false) { return targetUrl; } boolean first = true; StringBuffer outParamsStr = new StringBuffer(suffix); for (String param : initParams.keySet()) { if (isParameterToSkip(param)) { break; } first = addParam(outParamsStr, first, param, initParams.get(param)); } if (autoAdvance) { first = addParam(outParamsStr, first, MsgId.PARAM_AUTO_ADVANCE.getText(), "true"); } // redirect to specified URL String infixe = (outParamsStr.indexOf("?") == -1) ? "?" : "&"; String location = targetUrl + infixe + outParamsStr; return location; }
From source file:com.betfair.testing.utils.cougar.helpers.CougarHelpers.java
private String cleanCommandLineArgs(String vmName) { vmName = vmName.replaceAll("\"", ""); // Strip any quotes from the name (needed for running on Jenkins server) StringBuffer buff = new StringBuffer(vmName); int argIndex = -1; while ((argIndex = buff.indexOf("-D")) != -1) { // While there's a command line argument in the string int argEnd = -1; if ((argEnd = buff.indexOf(" ", argIndex)) == -1) { // If this argument is at the end of the display name then clean to the end rather than to next white space argEnd = buff.length();//ww w . ja v a2 s. c o m } buff.replace(argIndex - 1, argEnd, ""); // remove contents of buffer between space before arg starts and the next white space/end of buffer } return buff.toString(); }
From source file:org.mitre.dsmiley.httpproxy.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 . java 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:org.codehaus.tycho.eclipsepackaging.ProductExportMojo.java
private void copyExecutable(TargetEnvironment environment, File target) throws MojoExecutionException, MojoFailureException { getLog().debug("Creating launcher"); FeatureDescription feature;//from ww w .j a v a 2 s. co m // eclipse 3.2 if (isEclipse32Platform()) { feature = featureResolutionState.getFeature("org.eclipse.platform.launchers", null); } else { feature = featureResolutionState.getFeature("org.eclipse.equinox.executable", null); } if (feature == null) { throw new MojoExecutionException("RPC delta feature not found!"); } File location = feature.getLocation(); String os = environment.getOs(); String ws = environment.getWs(); String arch = environment.getArch(); File osLauncher = new File(location, "bin/" + ws + "/" + os + "/" + arch); try { // Don't copy eclipsec file IOFileFilter eclipsecFilter = FileFilterUtils .notFileFilter(FileFilterUtils.prefixFileFilter("eclipsec")); FileUtils.copyDirectory(osLauncher, target, eclipsecFilter); } catch (IOException e) { throw new MojoExecutionException("Unable to copy launcher executable", e); } File launcher = getLauncher(environment, target); // make launcher executable try { getLog().debug("running chmod"); ArchiveEntryUtils.chmod(launcher, 0755, null); } catch (ArchiverException e) { throw new MojoExecutionException("Unable to make launcher being executable", e); } File osxEclipseApp = null; // Rename launcher if (productConfiguration.getLauncher() != null && productConfiguration.getLauncher().getName() != null) { String launcherName = productConfiguration.getLauncher().getName(); String newName = launcherName; // win32 has extensions if (PlatformPropertiesUtils.OS_WIN32.equals(os)) { String extension = FilenameUtils.getExtension(launcher.getAbsolutePath()); newName = launcherName + "." + extension; } else if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) { // the launcher is renamed to "eclipse", because // this is the value of the CFBundleExecutable // property within the Info.plist file. // see http://jira.codehaus.org/browse/MNGECLIPSE-1087 newName = "eclipse"; } getLog().debug("Renaming launcher to " + newName); File newLauncher = new File(launcher.getParentFile(), newName); if (!launcher.renameTo(newLauncher)) { throw new MojoExecutionException("Could not rename native launcher to " + newName); } launcher = newLauncher; // macosx: the *.app directory is renamed to the // product configuration launcher name // see http://jira.codehaus.org/browse/MNGECLIPSE-1087 if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) { newName = launcherName + ".app"; getLog().debug("Renaming Eclipse.app to " + newName); File eclipseApp = new File(target, "Eclipse.app"); osxEclipseApp = new File(eclipseApp.getParentFile(), newName); eclipseApp.renameTo(osxEclipseApp); // ToDo: the "Info.plist" file must be patched, so that the // property "CFBundleName" has the value of the // launcherName variable } } // icons if (productConfiguration.getLauncher() != null) { if (PlatformPropertiesUtils.OS_WIN32.equals(os)) { getLog().debug("win32 icons"); List<String> icons = productConfiguration.getW32Icons(); if (icons != null) { getLog().debug(icons.toString()); try { String[] args = new String[icons.size() + 1]; args[0] = launcher.getAbsolutePath(); int pos = 1; for (String string : icons) { args[pos] = string; pos++; } IconExe.main(args); } catch (Exception e) { throw new MojoExecutionException("Unable to replace icons", e); } } else { getLog().debug("icons is null"); } } else if (PlatformPropertiesUtils.OS_LINUX.equals(os)) { String icon = productConfiguration.getLinuxIcon(); if (icon != null) { try { File sourceXPM = new File(project.getBasedir(), removeFirstSegment(icon)); File targetXPM = new File(launcher.getParentFile(), "icon.xpm"); FileUtils.copyFile(sourceXPM, targetXPM); } catch (IOException e) { throw new MojoExecutionException("Unable to create ico.xpm", e); } } } else if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) { String icon = productConfiguration.getMacIcon(); if (icon != null) { try { if (osxEclipseApp == null) { osxEclipseApp = new File(target, "Eclipse.app"); } File source = new File(project.getBasedir(), removeFirstSegment(icon)); File targetFolder = new File(osxEclipseApp, "/Resources/" + source.getName()); FileUtils.copyFile(source, targetFolder); // Modify eclipse.ini File iniFile = new File(osxEclipseApp + "/Contents/MacOS/eclipse.ini"); if (iniFile.exists() && iniFile.canWrite()) { StringBuffer buf = new StringBuffer(FileUtils.readFileToString(iniFile)); int pos = buf.indexOf("Eclipse.icns"); buf.replace(pos, pos + 12, source.getName()); FileUtils.writeStringToFile(iniFile, buf.toString()); } } catch (Exception e) { throw new MojoExecutionException("Unable to create macosx icon", e); } } } } // eclipse 3.2 if (isEclipse32Platform()) { File startUpJar = new File(location, "bin/startup.jar"); try { FileUtils.copyFileToDirectory(startUpJar, target); } catch (IOException e) { throw new MojoExecutionException("Unable to copy startup.jar executable", e); } } }
From source file:de.innovationgate.wgpublisher.url.DefaultURLBuilder.java
private String innerBuildLogoutURL(WGDatabase db, HttpServletRequest request, String redirectURL) throws WGException { StringBuffer url = new StringBuffer(); url.append(WGPDispatcher.getPublisherURL(request)).append("/"); url.append(db.getDbReference()).append("/"); url.append("logout"); String parameterIntroducor = "?"; if (url.indexOf("?") != -1) { parameterIntroducor = "&"; }/*from www.jav a 2 s . c om*/ try { url.append(parameterIntroducor).append("&redirect=") .append(_core.getURLEncoder().encodeQueryPart(redirectURL)); } catch (Exception e) { throw new RuntimeException(e); } return url.toString(); }
From source file:org.ala.spatial.util.AnalysisJobMaxent.java
public void readReplaceBetween(String fname, String startOldText, String endOldText, String replText) { String line;//w w w . ja v a2 s. co m StringBuffer sb = new StringBuffer(); try { FileInputStream fis = new FileInputStream(fname); BufferedReader reader = new BufferedReader(new InputStreamReader(fis)); while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } int start, end; start = sb.indexOf(startOldText); if (start >= 0) { end = sb.indexOf(endOldText, start + 1); sb.replace(start, end + endOldText.length(), replText); } reader.close(); BufferedWriter out = new BufferedWriter(new FileWriter(fname)); out.write(sb.toString()); out.close(); } catch (Throwable e) { System.err.println("*** exception ***"); e.printStackTrace(System.out); } }
From source file:org.kepler.util.DelimitedReader.java
private String readOneRowDataString() { // Vector oneRowDataVector = new Vector(); StringBuffer rowData = new StringBuffer(); String rowDataString = null;//from ww w . j ava 2s . c o m int singleCharactor = -2; if (dataReader != null) { // log.debug("in dataReader is not null"); try { while (singleCharactor != -1) { // log.debug("in singleCharactor is not null"); singleCharactor = dataReader.read(); char charactor = (char) singleCharactor; rowData.append(charactor); // find string - line ending in the row data boolean foundLineEnding = (rowData.indexOf(lineEnding) != -1); // if we are being lenient, try some other line endings for // parsing the data if (!foundLineEnding && this.isLenient()) { // have we discovered the ending already in this data? if (this.discoveredLineEnding != null) { foundLineEnding = (rowData.indexOf(this.discoveredLineEnding) != -1); } // otherwise we need to try a few of them out else { for (int i = 0; i < possibleLineEndings.size(); i++) { String possibleLineEnding = (String) possibleLineEndings.get(i); foundLineEnding = (rowData.indexOf(possibleLineEnding) != -1); if (foundLineEnding) { this.discoveredLineEnding = possibleLineEnding; break; } } } } // finally see if we found the end of the line if (foundLineEnding) { log.debug("found line ending"); // strip the header lines if (stripHeader && numHeaderLines > 0 && headLineNumberCount < numHeaderLines) { // reset string buffer(descard the header line) rowData = null; rowData = new StringBuffer(); } else { rowDataString = rowData.toString(); log.debug("The row data is " + rowDataString); break; } headLineNumberCount++; } } } catch (Exception e) { log.debug("Couldn't read data from input stream"); } } // System.out.println("the row data before reutrn is "+rowDataString); return rowDataString; }
From source file:uk.ac.cam.ucs.webauth.RavenFilter.java
@Override public void doFilter(ServletRequest servletReq, ServletResponse servletResp, FilterChain chain) throws IOException, ServletException { // Only process http requests. if ((servletReq instanceof HttpServletRequest) == false) { String msg = "Configuration Error. RavenFilter can only handle Http requests. The rest of the filter chain will NOT be processed."; log.error(msg);/* ww w. j av a 2 s . com*/ return; } if (testingMode) { servletReq.setAttribute(ATTR_REMOTE_USER, "test"); ((HttpServletRequest) servletReq).getSession().setAttribute(ATTR_REMOTE_USER, "test"); chain.doFilter(servletReq, servletResp); return; } HttpServletRequest request = (HttpServletRequest) servletReq; HttpServletResponse response = (HttpServletResponse) servletResp; HttpSession session = request.getSession(); log.debug("RavenFilter running for: " + request.getServletPath()); // Check for an authentication reply in the request // If its a POST request then we cannot read parameters because this // trashes the inputstream which we want to pass to the servlet. So, if // its a post request then assume that there is no WLS-RESPONSE in the // request. This is reasonable because WLS-Response is sent from the // raven server and it won't do that with a POST request. String wlsResponse = null; if (!"POST".equals(request.getMethod())) { wlsResponse = request.getParameter(WLS_RESPONSE_PARAM); log.debug("WLS-Response is " + wlsResponse); } else { log.debug("Not checking WLS-Response because we have a POST request"); } // WebauthResponse storedResponse = (WebauthResponse) // session.getAttribute(WLS_RESPONSE_PARAM); WebauthRequest storedRavenReq = (WebauthRequest) session.getAttribute(SESS_RAVEN_REQ_KEY); log.debug("Stored raven request is " + storedRavenReq); RavenState storedState = (RavenState) session.getAttribute(SESS_STORED_STATE_KEY); log.debug("Stored state is " + storedState); /* * Check the stored state if we have it */ if (storedState != null) { if (storedState.status != 200) { session.setAttribute(SESS_STORED_STATE_KEY, null); response.sendError(storedState.status); return; } /* * We do not check for expiry of the state because in this * implementation we simply use the session expiry the web admin has * configured in Tomcat (since the Raven authentication is only used * to set up the session, it makes sense to use the session's expiry * rather than Raven's). */ /* * We do not check for state.last or state.issue being in the * future. State.issue is already checked in the WebauthValidator * when the state is initially created. State.last is set by * System.currentTimeMillis at state creation time and therefore * cannot be in the future. */ if (wlsResponse == null || wlsResponse.length() == 0) { log.debug("Accepting stored session"); if (allowedPrincipals == null || allowedPrincipals.contains(storedState.principal.getName())) { chain.doFilter(request, response); return; } else { response.sendError(403, "You are not authorized to view this page."); return; } } } // end if (storedState != null) /* * Check the received response if we have it. * * Note - if we have both a stored state and a WLS-Response, we let the * WLS-Response override the stored state (this is no worse than if the * same request arrived a few minutes later when the first session would * have expired, thus removing the stored state) */ if (wlsResponse != null && wlsResponse.length() > 0) { WebauthResponse webauthResponse = new WebauthResponse(wlsResponse); session.setAttribute(WLS_RESPONSE_PARAM, webauthResponse); try { log.debug("Validating received response with stored request"); if (storedRavenReq == null) { response.sendError(500, "Failed to find a stored Raven request in the user's session."); return; } this.getWebauthValidator().validate(storedRavenReq, webauthResponse); RavenPrincipal principal = new RavenPrincipal(webauthResponse.get("principal")); RavenState state = new RavenState(200, webauthResponse.get("issue"), webauthResponse.get("life"), webauthResponse.get("id"), principal, webauthResponse.get("auth"), webauthResponse.get("sso"), webauthResponse.get("params")); log.debug("Storing new state " + state.toString()); session.setAttribute(SESS_STORED_STATE_KEY, state); session.setAttribute(ATTR_REMOTE_USER, state.principal.getName()); request.setAttribute(ATTR_REMOTE_USER, state.principal.getName()); /* * We do a redirect here so the user doesn't see the * WLS-Response in his browser location */ response.sendRedirect(webauthResponse.get("url")); return; } catch (WebauthException e) { log.debug("Response validation failed - " + e.getMessage()); try { int status = webauthResponse.getInt("status"); if (status > 0) response.sendError(status, e.getMessage()); else response.sendError(500, "Response validation failed - " + e.getMessage()); } catch (Exception e2) { response.sendError(500, "Response validation failed - " + e.getMessage()); } return; } } else { /* * No WLS-Response, no stored state. Redirect the user to Raven to * log in */ WebauthRequest webauthReq = new WebauthRequest(); StringBuffer url = request.getRequestURL(); if (serverURLPrefix != null) { // strip off everything up to and including the servlet path and // replace with the prefix String contextPath = request.getContextPath(); log.debug("Context path is: " + contextPath); log.debug("Request url is: " + request.getRequestURL()); int index = url.indexOf(contextPath); if (index == -1) { log.error("Failed to find context path (" + contextPath + ") in request url " + url); } else { url = new StringBuffer(serverURLPrefix + url.substring(index + contextPath.length())); } } if (request.getQueryString() != null && request.getQueryString().length() > 0) { url.append('?'); url.append(request.getQueryString()); } log.debug("Redirecting with url " + url.toString()); webauthReq.set("url", url.toString()); session.setAttribute(SESS_RAVEN_REQ_KEY, webauthReq); response.sendRedirect(sRavenAuthenticatePage + "?" + webauthReq.toQString()); return; } }