List of usage examples for java.lang StringBuffer indexOf
@Override public int indexOf(String str)
From source file:grails.plugin.springsecurity.web.filter.DebugFilter.java
protected void log(boolean dumpStack, String message, Object... args) { StringBuilder output = new StringBuilder(256); output.append("\n\n************************************************************\n\n"); output.append(message).append("\n"); if (dumpStack) { StringWriter os = new StringWriter(); GrailsUtil.deepSanitize(new Exception()).printStackTrace(new PrintWriter(os)); StringBuffer buffer = os.getBuffer(); // Remove the exception in case it scares people. int start = buffer.indexOf("java.lang.Exception"); buffer.replace(start, start + 19, ""); output.append("\nCall stack: \n").append(os); }/*from w ww . jav a 2s .c om*/ output.append("\n\n************************************************************\n\n"); log.info(output.toString(), args); }
From source file:com.telefonica.euro_iaas.sdc.puppetwrapper.services.impl.CatalogManagerMongoImpl.java
public String generateSiteStr() { List<Node> nodeList = mongoTemplate.findAll(Node.class); StringBuffer sb = new StringBuffer(); for (Node node : nodeList) { if (node.isManifestGenerated() && sb.indexOf("import '" + node.getGroupName() + "/*.pp'") == -1) { sb.append("import '" + node.getGroupName() + "/*.pp'"); sb.append(eol);//from w ww . j a v a 2s.co m } } return sb.toString(); }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.ExecuteServiceHandler.java
/** * This method creates a MediaType based on the mimetype that was provided * /* ww w . java2s . com*/ * @param mimeType * @return MediaType */ private MediaType createMediaType(String mimeType) { MediaType mediaType; String type, subtype; StringBuffer sb = new StringBuffer(mimeType); int index = sb.indexOf("/"); // If a slash was found then there is a type and subtype if (index != -1) { type = sb.substring(0, index); subtype = sb.substring(index + 1, mimeType.length()); mediaType = new MediaType(type, subtype); } else { // Assume there is just a type for the mime, no subtype mediaType = new MediaType(mimeType); } return mediaType; }
From source file:org.springframework.security.config.annotation.web.builders.DebugFilter.java
void log(String message, boolean dumpStack) { StringBuilder output = new StringBuilder(256); output.append("\n\n************************************************************\n\n"); output.append(message).append("\n"); if (dumpStack) { StringWriter os = new StringWriter(); new Exception().printStackTrace(new PrintWriter(os)); StringBuffer buffer = os.getBuffer(); // Remove the exception in case it scares people. int start = buffer.indexOf("java.lang.Exception"); buffer.replace(start, start + 19, ""); output.append("\nCall stack: \n").append(os.toString()); }//from www. j a v a 2 s. co m output.append("\n\n************************************************************\n\n"); logger.info(output.toString()); }
From source file:com.example.android.AudioArchive.model.RemoteJSONSource.java
private MediaMetadataCompat buildFromRSS(RSSItem rssItem, String genre) { String title = rssItem.getTitle(); String album = rssItem.categories.get(0).toString(); String artist = ""; if (rssItem.getDescription().contains("by")) { StringBuffer stringBuffer = new StringBuffer(rssItem.getDescription()); artist = stringBuffer.substring(stringBuffer.indexOf("by")); } else {//from ww w.j ava 2 s . c o m artist = "Unknown"; } String source = rssItem.getEnclosures().get(0).getLink(); String iconUrl = "https://archive.org/services/get-item-image.php?identifier=afewmoreverses_1606_librivox&mediatype=audio&collection=librivoxaudio"; String html = rssItem.getDescription(); String imgRegex = "<[iI][mM][gG][^>]+[sS][rR][cC]\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>"; Pattern p = Pattern.compile(imgRegex); Matcher m = p.matcher(html); if (m.find()) { iconUrl = m.group(1); } // Since we don't have a unique ID in the server, we fake one using the hashcode of // the music source. In a real world app, this could come from the server. String id = String.valueOf(source.hashCode()); // Adding the music source to the MediaMetadata (and consequently using it in the // mediaSession.setMetadata) is not a good idea for a real world music app, because // the session metadata can be accessed by notification listeners. This is done in this // sample for convenience only. //noinspection ResourceType return new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id) .putString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE, source) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album) .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) // .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, title) .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION, title) // .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .build(); }
From source file:nl.b3p.kaartenbalie.service.requesthandler.DescribeLayerRequestHandler.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. * /* www .j av a 2s . c o m*/ * @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[] * * @throws Exception * @throws IOException */ public void getRequest(DataWrapper dw, User user) throws IOException, Exception { dw.setHeader("Content-Disposition", "inline; filename=\"DescribeLayer.xml\";"); this.user = user; this.url = user.getPersonalURL(dw.getRequest(), dw.getOgcrequest().getServiceProviderName()); Integer[] orgIds = user.getOrganizationIds(); //for authorization OGCRequest ogcRequest = dw.getOgcrequest(); //should DescribeLayer do anything with format param? at present it doesn't dw.setContentType(OGCConstants.WMS_PARAM_WMS_XML); Long timeFromStart = new Long(dw.getRequestReporting().getMSSinceStart()); String requestParam = ogcRequest.getParameter(OGCConstants.REQUEST); // -- // -- check if there are service provider urls to collect data from // -- getSeviceProviderURLS returns list with SpLayerSummary objects // -- String spInUrl = ogcRequest.getServiceProviderName(); String[] la = ogcRequest.getParameter(OGCConstants.WMS_PARAM_LAYERS).split(","); List<LayerSummary> lsl = LayerSummary.createLayerSummaryList(Arrays.asList(la), spInUrl, (spInUrl == null)); List spInfo = getServiceProviderURLS(lsl, orgIds, false, dw, false); if (spInfo == null || spInfo.isEmpty()) { //Error message from KBConfiguration in b3p-commons-gis? log.error(requestParam + ": no urls qualify for request."); throw new Exception("No Serviceprovider available! User might not have rights to any Serviceprovider!"); } // -- // -- prepare to collect data // -- ArrayList urlWrapper = new ArrayList(); Iterator it = spInfo.iterator(); while (it.hasNext()) { SpLayerSummary spLayerSummary = (SpLayerSummary) it.next(); ServiceProviderRequest dlrWrapper = new ServiceProviderRequest(); dlrWrapper.setMsSinceRequestStart(timeFromStart); dlrWrapper.setWmsVersion(ogcRequest.getParameter(OGCConstants.WMS_VERSION)); Integer serviceProviderId = spLayerSummary.getServiceproviderId(); if (serviceProviderId != null && serviceProviderId.intValue() == -1) { //B3P layering necessary for DescribeLayer? // when is Id < -1 ? } else { B3PCredentials credentials = new B3PCredentials(); credentials.setUserName(spLayerSummary.getUsername()); credentials.setPassword(spLayerSummary.getPassword()); dlrWrapper.setServiceProviderId(serviceProviderId); dlrWrapper.setServiceProviderAbbreviation(spLayerSummary.getSpAbbr()); dlrWrapper.setCredentials(credentials); String layersList = spLayerSummary.getLayersAsString(); // StringBuffer url = new StringBuffer(); url.append(spLayerSummary.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 { url.append(params[i]); url.append("&"); } } dlrWrapper.setProviderRequestURI(url.toString()); urlWrapper.add(dlrWrapper); } } getOnlineData(dw, urlWrapper, false, OGCConstants.WMS_REQUEST_DescribeLayer); }
From source file:net.alchemiestick.katana.winehqappdb.WineSearch.java
@Override protected void onPostExecute(StringBuffer res) { String str = "Processing responce! (" + Long.valueOf(res.length()).toString() + " bytes)"; tvlist.clear();/* w ww . j a va2s.c om*/ // tvlist.add(str); int istart = res.indexOf("<table"); int iend = res.indexOf("</table>", istart); String tab; try { tab = res.substring(istart, iend); } catch (StringIndexOutOfBoundsException e) { tvlist.add(new str_link("No Match Found", "")); return; } iend = 0; String link; for (int i = 1; iend < tab.lastIndexOf("</td>"); i++) { istart = tab.indexOf("<tr class=\"color" + Long.valueOf(i % 2).toString() + "\">", iend); istart = tab.indexOf("<td>", istart) + 6; istart = tab.indexOf("href=", istart) + 6; iend = tab.indexOf("\"", istart); link = tab.substring(istart, iend); istart = tab.indexOf(">", istart) + 1; iend = tab.indexOf("</a>", istart); str = tab.substring(istart, iend); iend = tab.indexOf("</tr>", istart); tvlist.add(new str_link(str, link)); } }
From source file:org.dknight.app.UnmanagedAMLauncher.java
/** *//*from ww w . ja v a 2 s. c o m*/ public UnmanagedAMLauncher(Configuration conf) throws Exception { // Set up RPC this.conf = conf; String classUrl = this.getClass().getResource("/").getPath(); StringBuffer confStrBuilder = new StringBuffer(classUrl); int targetnIdx = confStrBuilder.indexOf("classes"); confStrBuilder = confStrBuilder.replace(targetnIdx, confStrBuilder.length(), "test-classes/yarn-conf.xml"); this.conf.addResource(new Path(confStrBuilder.toString())); }
From source file:org.openmrs.module.idcards.web.servlet.PrintEmptyIdcardsServlet.java
/** * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) *//*from w w w .j ava 2 s .co m*/ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Integer mrnCount = ServletRequestUtils.getRequiredIntParameter(request, "mrn_count"); Integer templateId = ServletRequestUtils.getIntParameter(request, "templateId", 1); String generatedMRNs = ServletRequestUtils.getStringParameter(request, "generated_mrns", "none"); String password = ServletRequestUtils.getStringParameter(request, "pdf_password"); if (!StringUtils.hasLength(password)) throw new ServletException("A non-empty password is required."); IdcardsTemplate card = getIdcardsService().getIdcardsTemplate(templateId); StringBuffer requestURL = request.getRequestURL(); String baseURL = requestURL.substring(0, requestURL.indexOf("/moduleServlet")); List<Integer> identifiers = null; if ("none".equals(generatedMRNs)) { identifiers = Collections.nCopies(mrnCount, 0); } else if ("pregenerated".equals(generatedMRNs)) { identifiers = getIdcardsService().printGeneratedIdentifiers(mrnCount, card); } else if ("generateNew".equals(generatedMRNs)) { Integer min = Integer .valueOf(Context.getAdministrationService().getGlobalProperty("idcards.generateMin")); Integer max = Integer .valueOf(Context.getAdministrationService().getGlobalProperty("idcards.generateMax")); identifiers = getIdcardsService().generateAndPrintIdentifiers(mrnCount, min, max, card); } else throw new ServletException("Invalid choice for 'generatedMRNs' parameter"); generateOutput(card, baseURL, response, identifiers, password); }
From source file:org.apache.cocoon.HtmlUnitTestCase.java
/** * Copy file from webapp source to deployment area filtering content * to replace parameter by value./*from w w w.j av a2 s . c o m*/ * The source and deployment directories are defined by the properties * htmlunit.test.source-dir and htmlunit.test.deploy-dir. * * This method is most useful for testing the automatic reloading of * changed files. */ protected void copyWebappFile(String filename, String param, String value) throws Exception { String srcdir = System.getProperty("htmlunit.test.source-dir"); String dstdir = System.getProperty("htmlunit.test.deploy-dir"); File srcfile = new File(srcdir + "/" + filename); File dstfile = new File(dstdir + "/" + filename); final String encoding = "ISO-8859-1"; StringBuffer content = new StringBuffer(FileUtils.readFileToString(srcfile, encoding)); int index = content.indexOf(param); while (index != -1) { content.replace(index, index + param.length(), value); index = content.indexOf(param, index + 1); } FileUtils.writeStringToFile(dstfile, content.toString(), encoding); // Leave server some time to realize that file has changed. Thread.sleep(1000); }