List of usage examples for java.lang StringBuffer substring
@Override public synchronized String substring(int start, int end)
From source file:org.ambraproject.service.feed.FeedServiceImpl.java
/** * Queries for a list of articles from solr using the parameters set in searchParams * * @param searchParameters//from w ww .j a v a 2 s . co m * @return solr search result that contains list of articles */ @Override public Document getArticles(final FeedSearchParameters searchParameters) { Map<String, String> params = new HashMap<String, String>(); // result format params.put("wt", "xml"); // what I want returned, the fields needed for rss feed params.put("fl", "id,title_display,publication_date,author_without_collab_display,author_collab_only_display," + "author_display,volume,issue,article_type,subject_hierarchy,abstract_primary_display,copyright"); // filters String fq = "doc_type:full " + "AND !article_type_facet:\"Issue Image\" " + "AND cross_published_journal_key:" + searchParameters.getJournal(); String[] categories = searchParameters.getCategories(); if (categories != null && categories.length > 0) { StringBuffer sb = new StringBuffer(); for (String category : categories) { sb.append("\"").append(category).append("\" AND "); } params.put("q", "subject_level_1:(" + sb.substring(0, sb.length() - 5) + ")"); } if (searchParameters.getAuthor() != null) { fq = fq + " AND author:\"" + searchParameters.getAuthor() + "\""; } String startDate = "*"; String endDate = "*"; boolean addDateRange = false; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); if (searchParameters.getSDate() != null) { startDate = sdf.format(searchParameters.getSDate().getTime()); startDate = startDate + "T00:00:00Z"; addDateRange = true; } if (searchParameters.getEDate() != null) { endDate = sdf.format(searchParameters.getEDate().getTime()); endDate = endDate + "T00:00:00Z"; addDateRange = true; } if (addDateRange == true) { fq = fq + " AND publication_date:[" + startDate + " TO " + endDate + "]"; } params.put("fq", fq); // number of results params.put("rows", Integer.toString(searchParameters.getMaxResults())); // sort the result if (searchParameters.isMostViewed()) { // Sorts RSS Feed for the most viewed articles linked from the most viewed tab. String mostViewedKey = "ambra.virtualJournals." + journalService.getCurrentJournalName() + ".mostViewedArticles"; Integer days = configuration.getInt(mostViewedKey + ".timeFrame"); String sortField = (days != null) ? solrFieldConverter.getViewCountingFieldName(days) : solrFieldConverter.getAllTimeViewsField(); params.put("sort", sortField + " desc"); } else { params.put("sort", "publication_date desc"); } Document result = null; try { result = solrHttpService.makeSolrRequest(params); } catch (SolrException e) { e.printStackTrace(); } return result; }
From source file:org.talend.designer.runprocess.bigdata.BigDataJavaProcessor.java
@Override public List<String> extractArgumentSegments() { List<String> list = new ArrayList<String>(); list.add(ProcessorConstants.CMD_KEY_WORD_LIBJAR); StringBuffer libJars = new StringBuffer(); Set<String> libNames = JavaProcessorUtilities.extractLibNamesOnlyForMapperAndReducer(process); if (libNames != null && libNames.size() > 0) { Iterator<String> itLibNames = libNames.iterator(); while (itLibNames.hasNext()) { libJars.append(getLibFolderInWorkingDir() + itLibNames.next()).append(','); }//from w ww.j a v a 2 s.c o m } list.add(libJars.substring(0, libJars.length() - 1)); return list; }
From source file:com.hyron.poscafe.service.action.LogInOutAction.java
@Override public boolean parseParams(List<VirtualKey> params) { boolean ret = false; StringBuffer tmpBuf = new StringBuffer(); for (VirtualKey vk : params) { tmpBuf.append(vk.getValue().isEmpty() ? vk.getKeyType().getType() : vk.getValue()); }//ww w . jav a2 s . c o m int i = 0; for (i = 0; i < regexp.length; i++) { Pattern pattern = Pattern.compile(regexp[i]); Matcher matcher = pattern.matcher(tmpBuf); if (matcher.matches()) { ret = true; break; } } if (i == 0) { int pos = tmpBuf.indexOf("ENTER"); cashierID = tmpBuf.substring(0, pos); int pos2 = tmpBuf.indexOf("ENTERLOGIN_OUT", pos + "ENTER".length()); password = tmpBuf.substring(pos + "ENTER".length(), pos2); logout = false; ret = true; log.debug("Parse params success."); } else if (i == 1) { int pos = tmpBuf.indexOf("ENTER"); cashierID = tmpBuf.substring(0, pos); int pos2 = tmpBuf.indexOf("LOGIN_OUT", pos + "ENTER".length()); password = tmpBuf.substring(pos + "ENTER".length(), pos2); logout = false; ret = true; log.debug("Parse params success."); } else if (i == 2) { cashierID = ""; password = ""; logout = true; ret = true; log.debug("Parse params success."); } else { log.debug("Parse params failed."); } return ret; }
From source file:dk.defxws.fgssolrremote.OperationsImpl.java
protected boolean indexDocExists(String pid) throws GenericSearchException { boolean indexDocExists = true; StringBuffer resultXml = new StringBuffer(); try {/*from w w w .ja v a 2 s .co m*/ resultXml = sendToSolr("/select?q=PID%3A%22" + pid + "%22&rows=0"); } catch (Exception e) { throw new GenericSearchException("updateIndex sendToSolr:\n" + e, e); } int i = resultXml.indexOf("numFound="); int j = resultXml.indexOf("\"", i + 10); String numFound = resultXml.substring(i + 10, j); if (numFound.equals("0")) indexDocExists = false; if (logger.isDebugEnabled()) logger.debug("indexDocExists pid=" + pid + " indexDocExists=" + indexDocExists); return indexDocExists; }
From source file:org.openmrs.module.FacesRegister.web.controller.Faces361BRegisterManageController.java
private String dateFormat(String s) { /*/*from w w w .j a v a 2 s. c o m*/ * this method formats the date string * it takes input in the format of dd/mm/yyyy and returns yyyy-mm-dd * This is done so that we can ensure correct sql date format */ String temp = ""; StringBuffer st = new StringBuffer(s); for (int i = st.length() - 1; i >= 0; i--) { if (st.charAt(i) == '/') st.replace(i, i + 1, "-"); //replace the slash "/" with the dash "-" } temp = st.substring(6, 10) + "-" + st.substring(3, 5) + "-" + st.substring(0, 2); // format date (yyyy-mm-dd) return temp; }
From source file:com.esri.geoevent.datastore.GeoEventDataStoreProxy.java
private Response execute(CloseableHttpClient http, ServerInfo serverInfo, HttpRequestBase request, MessageContext context) throws IOException { ensureCertsAreLoaded(context);//w w w . j av a2 s . c om CloseableHttpResponse response = http.execute(request, serverInfo.httpContext); if (response == null) { return Response.status(Response.Status.BAD_GATEWAY).build(); } Header[] responseHeaders = response.getAllHeaders(); ResponseBuilder builder = Response.status(response.getStatusLine().getStatusCode()); for (Header header : responseHeaders) { builder.header(header.getName(), header.getValue()); } String strReply = new String(EntityUtils.toByteArray(response.getEntity())); HttpServletRequest servletRequest = context.getHttpServletRequest(); StringBuffer entireRequestUrl = servletRequest.getRequestURL(); builder.entity(strReply.replaceAll(serverInfo.url.toExternalForm(), entireRequestUrl.substring(0, entireRequestUrl.indexOf(servletRequest.getPathInfo())) + "/" + serverInfo.name + "/")); return builder.build(); }
From source file:com.qihang.winter.poi.excel.export.base.ExportBase.java
/** * ?cell,??/*from w w w . j a v a 2 s. c o m*/ * * @param entity * @param obj * @return * @throws Exception */ public Object getCellValue(com.qihang.winter.poi.excel.entity.params.ExcelExportEntity entity, Object obj) throws Exception { Object value; if (obj instanceof Map) { value = ((Map<?, ?>) obj).get(entity.getKey()); } else { value = entity.getMethods() != null ? getFieldBySomeMethod(entity.getMethods(), obj) : entity.getMethod().invoke(obj, new Object[] {}); } if (StringUtils.isNotEmpty(entity.getFormat())) { value = formatValue(value, entity); } if (entity.getReplace() != null && entity.getReplace().length > 0) { value = replaceValue(entity.getReplace(), String.valueOf(value)); } if (needHanlderList != null && needHanlderList.contains(entity.getName())) { value = dataHanlder.exportHandler(obj, entity.getName(), value); } if (StringUtils.isNotEmpty(entity.getDicCode())) { if (StringUtil.isNotEmpty(value)) { CommonService commonService = (CommonService) ApplicationContextUtil.getContext() .getBean("commonService"); String[] typeCodeArray = value.toString().split(","); StringBuffer sb = new StringBuffer(); for (String typeCode : typeCodeArray) { sb.append("'" + typeCode + "',"); } List<TSType> tsTypeList = commonService .findByQueryString("from TSType where TSTypegroup.typegroupcode='" + entity.getDicCode() + "' and typecode in (" + sb.substring(0, sb.length() - 1) + ")"); StringBuffer valueSb = new StringBuffer(); for (TSType tsType : tsTypeList) { valueSb.append(tsType.getTypename() + ","); } if (valueSb.length() > 0) { value = valueSb.substring(0, valueSb.length() - 1); } } else { value = ""; } } if (StringUtils.isNotEmpty(entity.getSuffix()) && value != null) { value = value + entity.getSuffix(); } return value == null ? "" : value.toString(); }
From source file:library.memorymonitor.ProcfsBasedProcessTree.java
/** * Returns a string printing PIDs of process present in the * ProcfsBasedProcessTree. Output format : [pid pid ..] */// www. j a va2s . co m public String toString() { StringBuffer pTree = new StringBuffer("[ "); for (String p : processTree.keySet()) { pTree.append(p); pTree.append(" "); } return pTree.substring(0, pTree.length()) + "]"; }
From source file:net.mlw.vlh.adapter.hibernate3.util.StatementBuilder.java
/** * Usage of filters: {key} -> :keyName add to query's parameter map keyValue * [key] -> keyValue/*from w w w.j a v a2 s . c om*/ * * @param hql * @param whereClause * @return Query for ordinary list * @throws HibernateException * @throws ParseException */ public Query generate(Session session, StringBuffer hql, Map whereClause, boolean isRemoveEmptyStrings) throws HibernateException, ParseException { if (whereClause == null) { whereClause = Collections.EMPTY_MAP; } Map arguments = new HashMap(); // Include or exclude the filters. for (int i = 0, end = 0, start; ((start = hql.toString().indexOf("/~", end)) >= 0); i++) { end = hql.toString().indexOf("~/", start); String key = hql.substring(start + 2, hql.indexOf(":", start)); Object value = whereClause.get(key); if (isValuePopulated(value, isRemoveEmptyStrings)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("The filter key=[" + key + "] with the value=[" + value + "] is accepted by the hql preprocesor"); } hql.replace(start, end + 2, hql.substring(hql.indexOf(":", start) + 1, end)); } else { if (LOGGER.isInfoEnabled()) { LOGGER.info("The filter key=[" + key + "] is removed from the query by the hql preprocesor."); } hql.replace(start, end + 2, ""); } end -= start; } // Replace any [key] with the value in the whereClause Map. for (int i = 0, end = 0, start; ((start = hql.toString().indexOf('[', end)) >= 0); i++) { end = hql.toString().indexOf(']', start); String key = hql.substring(start + 1, end); Object value = whereClause.get(key); hql.replace(start, end + 1, (value == null) ? "" : value.toString()); end -= (key.length() + 2); } // Replace any "{key}" with the value in the whereClause Map, // then placing the value in the partameters list. for (int i = 0, end = 0, start; ((start = hql.toString().indexOf('{', end)) >= 0); i++) { end = hql.toString().indexOf('}', start); String key = hql.substring(start + 1, end); Object value = whereClause.get(key); if (value == null) { throw new NullPointerException("Property '" + key + "' was not provided."); } arguments.put(key, value); hql.replace(start, end + 1, ":" + key); end -= (key.length() + 2); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("The final query is " + hql); } Query query = session.createQuery(hql.toString()); // Now set all the patameters on the statement. if (setters == null) { for (Iterator keys = arguments.keySet().iterator(); keys.hasNext();) { String key = (String) keys.next(); Object value = arguments.get(key); if (value instanceof List) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Setting a paremeterList to the query."); } query.setParameterList(key, ((List) value).toArray()); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "Using the default setter for key=[" + key + "] with the value=[" + value + "]"); } getDefaultSetter().set(query, key, value); } } } else { for (Iterator keys = arguments.keySet().iterator(); keys.hasNext();) { String key = (String) keys.next(); Object value = arguments.get(key); getSetter(key).set(query, key, value); } } return query; }
From source file:eu.europa.esig.dss.DSSUtils.java
/** * This method replaces in a string one pattern by another one without using regexp. * * @param string/*from w ww.j av a 2 s. co m*/ * @param oldPattern * @param newPattern * @return */ public static StringBuffer replaceStrStr(final StringBuffer string, final String oldPattern, final String newPattern) { if ((string == null) || (oldPattern == null) || oldPattern.equals("") || (newPattern == null)) { return string; } final StringBuffer replaced = new StringBuffer(); int startIdx = 0; int idxOld; while ((idxOld = string.indexOf(oldPattern, startIdx)) >= 0) { replaced.append(string.substring(startIdx, idxOld)); replaced.append(newPattern); startIdx = idxOld + oldPattern.length(); } replaced.append(string.substring(startIdx)); return replaced; }