List of usage examples for java.lang StringBuilder indexOf
@Override public int indexOf(String str)
From source file:org.wso2.carbon.dataservices.sql.driver.TDriver.java
private void addProperty(Properties props, StringBuilder token) throws SQLException { String propName = token.substring(0, token.indexOf(Constants.EQUAL)); if (!TDriverUtil.getAvailableDriverProperties().contains(propName)) { throw new SQLException("Invalid driver property '" + propName + "' specified"); }//from w w w. ja va 2 s . c om String propValue = token.substring(token.indexOf(Constants.EQUAL) + 1, token.length()); props.setProperty(propName, propValue); }
From source file:org.geomajas.layer.common.proxy.LayerHttpServiceImpl.java
public String addCredentialsToUrl(final String url, final LayerAuthentication authentication) { if (null != authentication && LayerAuthenticationMethod.URL.equals(authentication.getAuthenticationMethod())) { StringBuilder res = new StringBuilder(url); if (res.indexOf(URL_PARAM_START) >= 0) { res.append(URL_PARAM_SEPARATOR); } else {/* ww w.j a va 2 s . c o m*/ res.append(URL_PARAM_START); } res.append(authentication.getUserKey()); res.append(URL_PARAM_IS); res.append(authentication.getUser()); res.append(URL_PARAM_SEPARATOR); res.append(authentication.getPasswordKey()); res.append(URL_PARAM_IS); res.append(authentication.getPassword()); return res.toString(); } return url; }
From source file:gov.nih.nci.cabig.caaers.domain.AdverseEventCtcTerm.java
@Override @Transient// w w w .j av a 2s .co m public String getUniversalTerm() { if (getTerm() == null) { return null; } else if (getAdverseEvent() != null && (getAdverseEvent().getDetailsForOther() != null || getAdverseEvent().getLowLevelTerm() != null)) { StringBuilder sb = new StringBuilder(getTerm().getFullName()); // strip everything after "Other", if it is in the name int otherAt = sb.indexOf("Other"); if (otherAt >= 0) { sb.delete(otherAt + 5, sb.length()); } if (getAdverseEvent().getDetailsForOther() != null) sb.append(": ").append(getAdverseEvent().getDetailsForOther()); if (getAdverseEvent().getLowLevelTerm() != null && getAdverseEvent().getLowLevelTerm().getMeddraTerm() != null) { sb.append(": ").append(getAdverseEvent().getLowLevelTerm().getMeddraTerm()); } return sb.toString(); } else { return getTerm().getFullName(); } }
From source file:ca.uhn.fhir.rest.method.HttpDeleteClientInvocation.java
@Override public HttpRequestBase asHttpRequest(String theUrlBase, Map<String, List<String>> theExtraParams, EncodingEnum theEncoding, Boolean thePrettyPrint) { StringBuilder b = new StringBuilder(); b.append(theUrlBase);/*from w w w.jav a 2 s. c om*/ if (!theUrlBase.endsWith("/")) { b.append('/'); } b.append(myUrlPath); appendExtraParamsWithQuestionMark(myParams, b, b.indexOf("?") == -1); appendExtraParamsWithQuestionMark(theExtraParams, b, b.indexOf("?") == -1); HttpDelete retVal = new HttpDelete(b.toString()); super.addHeadersToRequest(retVal, theEncoding); return retVal; }
From source file:com.md87.charliebravo.commands.IssueCommand.java
protected void executeOldIssue(InputHandler handler, Response response, String line) throws Exception { final List<String> result = Downloader.getPage("http://bugs.dmdirc.com/view.php?id=" + line); final StringBuilder builder = new StringBuilder(); for (String resline : result) { builder.append(resline);// w ww .ja v a 2 s.c om } if (builder.indexOf("APPLICATION ERROR #1100") > -1) { response.sendMessage("That issue was not found", true); } else if (builder.indexOf("<p>Access Denied.</p>") > -1) { response.sendMessage("that issue is private. Please see " + "http://bugs.dmdirc.com/view/" + line); } else { final Map<String, String> data = new HashMap<String, String>(); final Pattern pattern = Pattern.compile( "<td class=\"category\".*?>\\s*(.*?)\\s*" + "</td>\\s*(?:<!--.*?-->\\s*)?<td.*?>\\s*(.*?)\\s*</td>", Pattern.CASE_INSENSITIVE + Pattern.DOTALL); final Matcher matcher = pattern.matcher(builder); while (matcher.find()) { data.put(matcher.group(1).toLowerCase(), matcher.group(2)); } response.sendMessage("issue " + data.get("id") + " is \"" + data.get("summary").substring(9) + "\". Current " + "status is " + data.get("status") + " (" + data.get("resolution") + "). See http://bugs.dmdirc.com/view/" + data.get("id")); response.addFollowup(new IssueFollowup(data)); } }
From source file:org.sonatype.nexus.plugins.rrb.MavenRepositoryReader.java
private String extracktKey(StringBuilder indata) { String key = ""; int start = indata.indexOf("<Key>"); int end = indata.indexOf("</Key>"); if (start > 0 && end > start) { key = indata.substring(start + 5, end); }/*from w w w .j a va2 s. com*/ return key; }
From source file:com.l2jfree.status.StatusThread.java
protected final String readLine() throws IOException { String line = _in.readLine(); if (line == null) return null; StringBuilder sb = new StringBuilder(line); for (int index; (index = sb.indexOf("\b")) != -1;) sb.replace(index, index + 1, ""); return sb.toString(); }
From source file:hydrograph.engine.core.xmlparser.parametersubstitution.ParameterSubstitutor.java
private void substituteMutable(StringBuilder mutable, Stack<String> unresolvedParameters) { int startIndex = mutable.indexOf(VARIABLE_PREFIX); int endIndex = mutable.indexOf(VARIABLE_SUFFIX, startIndex); // return if nothing to substitute if (startIndex == -1 || endIndex == -1) { return;// w w w . j a v a 2 s . c o m } // get parameter name String parameterName = mutable.substring(startIndex + VARIABLE_PREFIX.length(), endIndex); // raise exception if parameter name is blank if (parameterName == null || parameterName.trim().length() == 0) { throw new ParameterSubstitutorException("Parameter name can not be blank. Please correct."); } parameterName = parameterName.trim(); String parameterValue = null; if (resolvedParameterCache.containsKey(parameterName)) { // obtain value from cache if already present parameterValue = resolvedParameterCache.get(parameterName); LOG.info("cache used for " + parameterName); } else { // check if the parameter is already on the stack then raise // exception // that it is circular substitution if (unresolvedParameters.search(parameterName) != -1) { throw new ParameterSubstitutorException("Found a circular depencency between parameter " + parameterName + " and " + unresolvedParameters.peek() + ". Both are referencing each other and cannot be resolved. Please correct."); } // get parameter value parameterValue = parameterBank.getParameter(parameterName); // if value is null then raise exception if (parameterValue == null) { throw new ParameterSubstitutorException( "No value is found for the parameter " + parameterName + " to substitute"); } // if parameter key to be substituted is in quotes("") then escape // special characters from its value if (isParameterPresentInQuotes(mutable, startIndex, endIndex)) { parameterValue = StringEscapeUtils.escapeXml(parameterValue); } // add current parameter to stack to check for circular loop later unresolvedParameters.push(parameterName); // check of substitution if there is a parameter reference in // parameter // value(internal substitution) parameterValue = substitute(parameterValue, unresolvedParameters); // remove parameter from stack as soon as it is resolved unresolvedParameters.pop(); // add resolved value to cache resolvedParameterCache.put(parameterName, parameterValue); } // delete parameter syntax mutable.delete(startIndex, endIndex + VARIABLE_SUFFIX.length()); // insert parameter value mutable.insert(startIndex, parameterValue); // check for next substitution and do it if available substituteMutable(mutable, unresolvedParameters); }
From source file:nl.b3p.kaartenbalie.service.requesthandler.GetFeatureInfoRequestHandler.java
/** * Processes the parameters and creates the specified urls from the given parameters. * Each url will be used to recieve the data from the ServiceProvider this url is refering to. * * @param dw DataWrapper which contains all information that has to be sent to the client * @param user User the user which invoked the request * * @return byte[]/*w w w.j a va2s. c om*/ * * @throws Exception * @throws IOException */ public void getRequest(DataWrapper dw, User user) throws IOException, Exception { //Waarom de Content-Disposition header setten? Je weet niet of het .xml is. //dw.setHeader("Content-Disposition", "inline; filename=\"GetFeatureInfo.xml\";"); OGCRequest ogcrequest = dw.getOgcrequest(); String value = ""; if (ogcrequest.containsParameter(OGCConstants.WMS_PARAM_INFO_FORMAT)) { String fileName = null; value = ogcrequest.getParameter(OGCConstants.FEATURE_INFO_FORMAT); if (value != null && value.length() > 0) { dw.setContentType(value); if (value.equalsIgnoreCase(OGCConstants.WMS_PARAM_WMS_HTML)) { fileName = "GetFeature.htm"; } else if (value.equalsIgnoreCase(OGCConstants.WMS_PARAM_WMS_GML) || value.equalsIgnoreCase(OGCConstants.WMS_PARAM_GML)) { fileName = "GetFeature.gml"; } else if (value.equalsIgnoreCase(OGCConstants.WMS_PARAM_WMS_XML) || value.equalsIgnoreCase(OGCConstants.WMS_PARAM_XML)) { fileName = "GetFeature.xml"; } } else { dw.setContentType(OGCConstants.WMS_PARAM_WMS_XML); fileName = "GetFeature.xml"; } if (fileName != null) { dw.setHeader("Content-Disposition", "inline; filename=\"" + fileName + "\";"); } } Long timeFromStart = new Long(dw.getRequestReporting().getMSSinceStart()); this.user = user; this.url = user.getPersonalURL(dw.getRequest(), dw.getOgcrequest().getServiceProviderName()); Integer[] orgIds = this.user.getOrganizationIds(); OGCRequest ogc = dw.getOgcrequest(); String spInUrl = ogc.getServiceProviderName(); String[] la = ogc.getParameter(OGCConstants.WMS_PARAM_QUERY_LAYERS).split(","); List<LayerSummary> lsl = LayerSummary.createLayerSummaryList(Arrays.asList(la), spInUrl, (spInUrl == null)); List spUrls = getServiceProviderURLS(lsl, orgIds, true, dw, false); if (spUrls == null || spUrls.isEmpty()) { log.error("No urls qualify for request."); throw new Exception(KBConfiguration.FEATUREINFO_QUERYABLE_EXCEPTION); } ArrayList urlWrapper = new ArrayList(); Iterator it = spUrls.iterator(); while (it.hasNext()) { SpLayerSummary spInfo = (SpLayerSummary) it.next(); ServiceProviderRequest firWrapper = new ServiceProviderRequest(); firWrapper.setMsSinceRequestStart(timeFromStart); Integer serviceProviderId = spInfo.getServiceproviderId(); if (serviceProviderId != null && serviceProviderId.intValue() == -1) { //Say hello to B3P Layering!! } else { firWrapper.setServiceProviderId(serviceProviderId); String abbr = spInfo.getSpAbbr(); firWrapper.setServiceProviderAbbreviation(abbr); B3PCredentials credentials = new B3PCredentials(); credentials.setUserName(spInfo.getUsername()); credentials.setPassword(spInfo.getPassword()); firWrapper.setCredentials(credentials); String layersList = spInfo.getLayersAsString(); StringBuilder url = new StringBuilder(); url.append(spInfo.getSpUrl()); if (url.indexOf("?") != url.length() - 1 && url.indexOf("&") != url.length() - 1) { if (url.indexOf("?") >= 0) { url.append("&"); } else { url.append("?"); } } String[] params = dw.getOgcrequest().getParametersArray(); for (int i = 0; i < params.length; i++) { String[] keyValuePair = params[i].split("="); if (keyValuePair[0].equalsIgnoreCase(OGCConstants.WMS_PARAM_LAYERS)) { url.append(OGCConstants.WMS_PARAM_LAYERS); url.append("="); url.append(layersList); url.append("&"); } else if (keyValuePair[0].equalsIgnoreCase(OGCConstants.WMS_PARAM_QUERY_LAYERS)) { url.append(OGCConstants.WMS_PARAM_QUERY_LAYERS); url.append("="); url.append(layersList); url.append("&"); } else { url.append(params[i]); url.append("&"); } } firWrapper.setProviderRequestURI(url.toString()); urlWrapper.add(firWrapper); } } getOnlineData(dw, urlWrapper, false, OGCConstants.WMS_REQUEST_GetFeatureInfo); }
From source file:fr.landel.utils.commons.StringUtils.java
/** * Injects all arguments in the specified char sequence. The arguments are * injected by replacement of the braces. If no index is specified between * braces, an internal index is created and the index is automatically * incremented. The index starts from 0. To exclude braces, just double them * (like {{0}} will return {0}). If number greater than arguments number are * specified, they are ignored.//www .j a va2s . c om * * <p> * precondition: {@code charSequence} cannot be {@code null} * </p> * * <pre> * StringUtils.inject("", "test"); // => "" * * StringUtils.inject("I'll go to the {} this {}", "beach", "afternoon"); * // => "I'll go to the beach this afternoon" * * StringUtils.inject("I'll go to the {1} this {0}", "afternoon", "beach"); * // => "I'll go to the beach this afternoon" * * StringUtils.inject("I'll go to the {1} this {}", "afternoon", "beach"); * // => "I'll go to the beach this afternoon" * * StringUtils.inject("I'll go to {} {3} {} {2}", "the", "this", "afternoon", "beach"); * // => "I'll go to the beach this afternoon" * * StringUtils.inject("I'll go to {{}}{3} {} {2}{{0}} {4} {text}", "the", "this", "afternoon", "beach"); * // => "I'll go to {}beach the afternoon{0} {4} {text}" * </pre> * * @param charSequence * the input char sequence * @param arguments * the arguments to inject * @param <T> * the arguments type * @return the result with replacements */ @SafeVarargs public static <T> String inject(final CharSequence charSequence, final T... arguments) { if (charSequence == null) { throw new IllegalArgumentException("The input char sequence cannot be null"); } else if (isEmpty(charSequence) || arguments == null || arguments.length == 0) { return charSequence.toString(); } final StringBuilder output = new StringBuilder(charSequence); // if no brace, just returns the string if (output.indexOf(BRACE_OPEN) < 0) { return output.toString(); } // replace the excluded braces by a temporary string replaceBrace(output, BRACE_OPEN_EXCLUDE, BRACE_OPEN_TMP); replaceBrace(output, BRACE_CLOSE_EXCLUDE, BRACE_CLOSE_TMP); // replace the braces without index by the arguments int i = 0; int index = 0; while ((index = output.indexOf(BRACES, index)) > -1 && i < arguments.length) { output.replace(index, index + BRACES.length(), String.valueOf(arguments[i++])); index += BRACES.length(); } // replace braces with index by the arguments int len; String param; for (i = 0; i < arguments.length; ++i) { index = 0; param = new StringBuilder(BRACE_OPEN).append(i).append(BRACE_CLOSE).toString(); len = param.length(); while ((index = output.indexOf(param, index)) > -1) { output.replace(index, index + len, String.valueOf(arguments[i])); index += len; } } // replace the temporary brace by the simple brace replaceBrace(output, BRACE_OPEN_TMP, BRACE_OPEN); replaceBrace(output, BRACE_CLOSE_TMP, BRACE_CLOSE); return output.toString(); }