List of usage examples for java.lang StringBuffer delete
@Override public synchronized StringBuffer delete(int start, int end)
From source file:playground.andreas.bln.ana.events2counts.PtCountCountComparisonKMLWriter.java
private ScreenOverlayType createBiasErrorGraphAlight(String kmlFilename) { int index = kmlFilename.lastIndexOf(System.getProperty("file.separator")); if (index == -1) { index = kmlFilename.lastIndexOf('/'); }/*from ww w . j a va 2 s . c o m*/ String outdir; if (index == -1) { outdir = ""; } else { outdir = kmlFilename.substring(0, index) + System.getProperty("file.separator"); } // ------------------------------------------------------------------------------ PtBiasErrorGraph epAlight = new PtBiasErrorGraph(this.alightCountComparisonFilter.getCountsForHour(null), this.iter, null, "error graph - Alighting"); epAlight.createChart(0); double[] meanErrorAlight = epAlight.getMeanRelError(); double[] meanBiasAlight = epAlight.getMeanAbsBias(); String fileAlight = outdir + "biasErrorGraphDataAlight.txt"; log.info("writing chart data to " + new File(fileAlight).getAbsolutePath()); try { BufferedWriter bwriter = IOUtils.getBufferedWriter(fileAlight); StringBuffer buffer = new StringBuffer(200); buffer.append("hour \t mean relative error \t mean absolute bias"); bwriter.write(buffer.toString()); bwriter.newLine(); for (int i = 0; i < meanErrorAlight.length; i++) { buffer.delete(0, buffer.length()); buffer.append(i + 1); buffer.append('\t'); buffer.append(meanErrorAlight[i]); buffer.append('\t'); buffer.append(meanBiasAlight[i]); bwriter.write(buffer.toString()); bwriter.newLine(); } bwriter.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String chartAlight = "errorGraphErrorBiasAlight.png"; try { writeChartToKmz(chartAlight, epAlight.getChart()); return createOverlayBottomRight(chartAlight, "Error Graph [Error/Bias]"); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:dao.CobrandDaoDb.java
/** * deleteUserCobrand method - deletes the cobranding information for user * @param loginId - the login id/* ww w. ja v a2 s .co m*/ * @param login - the login * @throws BaseDaoException - when error occurs */ public void deleteUserCobrand(String loginId, String login) throws BaseDaoException { if (RegexStrUtil.isNull(loginId)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource for user cobrand partitioned on user */ String sourceName = scalabilityManager.getWriteScalability(loginId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, deleteUserCobrand() " + sourceName + " loginId = " + loginId); } Connection conn = null; try { conn = ds.getConnection(); deleteUserQuery.run(conn, loginId); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception while deleting user cobrand file ", e2); } throw new BaseDaoException("error occured while deleting user cobrand file", e); } try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception while deleting user cobrand file ", e2); } /** * delete user cobrand from cache */ Fqn fqn = cacheUtil.fqn(DbConstants.USER_COBRAND); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, login)) { treeCache.remove(fqn, login); } fqn = cacheUtil.fqn(DbConstants.USER_BLOB_COBRAND); StringBuffer sb = new StringBuffer(loginId); sb.append("-"); sb.append("0"); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } sb.delete(0, sb.length()); sb.append(loginId); sb.append("-"); sb.append("1"); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } }
From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.Cas2Authenticator.java
protected String getAppURL(HttpServletRequest httpRequest) { log.debug("getAppURL"); if (isValidStartupPage(httpRequest)) { StringBuffer sb = new StringBuffer(VirtualHostHelper.getServerURL(httpRequest)); if (VirtualHostHelper.getServerURL(httpRequest).endsWith("/")) { sb.deleteCharAt(sb.length() - 1); }/* w ww.ja v a 2 s. com*/ sb.append(httpRequest.getRequestURI()); if (httpRequest.getQueryString() != null) { sb.append("?"); sb.append(httpRequest.getQueryString()); // remove ticket parameter from URL to correctly validate the // service int indexTicketKey = sb.lastIndexOf(ticketKey + "="); if (indexTicketKey != -1) { sb.delete(indexTicketKey - 1, sb.length()); } } log.debug(sb.toString()); return sb.toString(); } if (appURL == null || appURL.equals("")) { log.debug("null app url"); appURL = NUXEO_SERVER_PATTERN_KEY; } if (appURL.contains(NUXEO_SERVER_PATTERN_KEY)) { String nxurl = BaseURL.getBaseURL(httpRequest); log.debug(String.format("nxurl app url : %s", appURL.replace(NUXEO_SERVER_PATTERN_KEY, nxurl))); return appURL.replace(NUXEO_SERVER_PATTERN_KEY, nxurl); } else { log.debug(String.format("appurl: %s", appURL)); return appURL; } }
From source file:dao.CobrandDaoDb.java
/** * deleteDirCobrand method - deletes the cobranding information for directory * @param directoryId - the directory id * @throws BaseDaoException - when error occurs *//*from ww w .java2s. com*/ public void deleteDirCobrand(String directoryId) throws BaseDaoException { if (RegexStrUtil.isNull(directoryId)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource for directoryId cobrand partitioned on directoryId */ String sourceName = scalabilityManager.getWriteScalability(directoryId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException( "ds null, deleteDirCobrand() " + sourceName + " directoryId = " + directoryId); } Connection conn = null; try { conn = ds.getConnection(); deleteDirectoryQuery.run(conn, directoryId); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception while deleting directory cobrand file ", e2); } throw new BaseDaoException("error occured while deleting directory cobrand file", e); } try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception while deleting directory cobrand file ", e2); } /** * delete directory cobrand from cache */ Fqn fqn = cacheUtil.fqn(DbConstants.DIR_COBRAND); if (treeCache.exists(fqn, directoryId)) { treeCache.remove(fqn, directoryId); } fqn = cacheUtil.fqn(DbConstants.DIRECTORY); if (treeCache.exists(fqn, directoryId)) { treeCache.remove(fqn, directoryId); } fqn = cacheUtil.fqn(DbConstants.DIR_BLOB_COBRAND); StringBuffer sb = new StringBuffer(directoryId); sb.append("-"); sb.append("0"); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } sb.delete(0, sb.length()); sb.append(directoryId); sb.append("-"); sb.append("1"); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } }
From source file:dao.CobrandDaoDb.java
/** * deleteCollCobrand method - deletes the cobranding information for collabrum * @param collabrumId - the collabrum id * @throws BaseDaoException - when error occurs */// www. ja va 2s. co m public void deleteCollCobrand(String collabrumId) throws BaseDaoException { if (RegexStrUtil.isNull(collabrumId)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource for collabrumId cobrand partitioned on collabrumId */ String sourceName = scalabilityManager.getWriteScalability(collabrumId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException( "ds null, deleteCollCobrand() " + sourceName + " collabrumId = " + collabrumId); } Connection conn = null; try { conn = ds.getConnection(); deleteCollQuery.run(conn, collabrumId); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception while deleting collabrum cobrand file ", e2); } throw new BaseDaoException("error occured while deleting collabrum cobrand file", e); } try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception while deleting collabrum cobrand file ", e2); } /** * delete collabrum cobrand from cache */ Fqn fqn = cacheUtil.fqn(DbConstants.COLL_COBRAND); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLLABRUM); if (treeCache.exists(fqn, collabrumId)) { treeCache.remove(fqn, collabrumId); } fqn = cacheUtil.fqn(DbConstants.COLL_BLOB_COBRAND); StringBuffer sb = new StringBuffer(collabrumId); sb.append("-"); sb.append("0"); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } sb.delete(0, sb.length()); sb.append(collabrumId); sb.append("-"); sb.append("1"); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } }
From source file:com.leosys.core.telnet.Telent.java
public void readUntil(String str) { char last = str.charAt(str.length() - 1); String[] ss;//from w w w . j ava 2s. c o m try { StringBuffer sb = new StringBuffer(); char c; int code = -1; boolean ansiControl = false; boolean start = true; while ((code = (in.read())) != -1) { c = (char) code; if (c == '\033') {//vt100?\033 ansiControl = true; int code2 = in.read(); char cc = (char) code2; if (cc == '[' || cc == '(') { } } if (!ansiControl) { if (c == '\r') { String olds = new String(sb.toString().getBytes(ORIG_CODEC), TRANSLATE_CODEC); System.out.println(olds); if (sb.lastIndexOf(str) != -1) { break; } sb.delete(0, sb.length()); } else if (c == '\n') ; else sb.append(c); if (sb.lastIndexOf(str) != -1) { break; } } if (ansiControl) { if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '"') { ansiControl = false; } } } System.out.println(new String(sb.toString().getBytes(ORIG_CODEC), TRANSLATE_CODEC)); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.eclipse.skalli.gerrit.client.internal.GerritClientImpl.java
/** * Utility method for checking accounts. * * This indirection was introduced to allow splitting the call if the parameter list is huge. * Depending on the database this could easily fail. Hence split it into separate SQL queries * and merge the results.//from w ww.ja v a 2s. c o m * * @throws ConnectionException in case of connection / communication problems * @throws CommandException in case of unsuccessful commands */ private Collection<String> queryKnownAccounts(Collection<String> variousAccounts) throws ConnectionException, CommandException { final List<String> result = new ArrayList<String>(); final StringBuffer sb = new StringBuffer(); sb.append("SELECT external_id FROM ").append(GSQL.Tables.ACCOUNT_EXTERNAL_IDS) .append(" WHERE external_id IN ("); boolean noRealParameters = true; for (String variousAccount : variousAccounts) { if (!StringUtils.isBlank(variousAccount)) { sb.append("'").append(ACCOUNTS_PREFIX).append(variousAccount).append("', "); noRealParameters = false; } } sb.delete(sb.length() - 2, sb.length()); sb.append(");"); if (noRealParameters) { return result; } final List<String> gsqlResult = gsql(sb.toString(), ResultFormat.JSON); for (final String entry : gsqlResult) { if (isRow(entry)) { result.add( StringUtils.removeStart(JSONUtil.getString(entry, "columns.external_id"), ACCOUNTS_PREFIX)); } } return result; }
From source file:com.glaf.chart.web.springmvc.ChartController.java
@RequestMapping("/edit") public ModelAndView edit(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); LoginContext loginContext = RequestUtils.getLoginContext(request); DatabaseQuery query = new DatabaseQuery(); query.active("1"); List<Database> activeDatabases = new ArrayList<Database>(); List<Database> databases = null; if (loginContext.isSystemAdministrator()) { databases = databaseService.list(query); } else {//w ww . j a v a 2 s . c o m databases = databaseService.getDatabases(loginContext.getActorId()); } if (databases != null && !databases.isEmpty()) { for (Database database : databases) { if ("1".equals(database.getActive())) { DatabaseConnectionConfig config = new DatabaseConnectionConfig(); if (config.checkConfig(database)) { activeDatabases.add(database); logger.debug(database.getName() + " check connection ok."); } } } } if (!activeDatabases.isEmpty()) { request.setAttribute("databases", activeDatabases); } Map<String, Object> params = RequestUtils.getParameterMap(request); String chartId = ParamUtils.getString(params, "chartId"); Chart chart = null; if (StringUtils.isNotEmpty(chartId)) { chart = chartService.getChart(chartId); request.setAttribute("chart", chart); if (StringUtils.isNotEmpty(chart.getQueryIds())) { List<String> queryIds = StringTools.split(chart.getQueryIds()); StringBuffer sb01 = new StringBuffer(); StringBuffer sb02 = new StringBuffer(); for (String queryId : queryIds) { QueryDefinition queryDefinition = queryDefinitionService.getQueryDefinition(queryId); if (queryDefinition != null) { sb01.append(queryDefinition.getId()).append(","); sb02.append(queryDefinition.getTitle()).append("[").append(queryDefinition.getId()) .append("],"); } } if (sb01.toString().endsWith(",")) { sb01.delete(sb01.length() - 1, sb01.length()); } if (sb02.toString().endsWith(",")) { sb02.delete(sb02.length() - 1, sb02.length()); } request.setAttribute("queryIds", sb01.toString()); request.setAttribute("queryNames", sb02.toString()); } } String x_view = ViewProperties.getString("chart.edit"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/bi/chart/edit", modelMap); }
From source file:com.glaf.activiti.web.rest.ActivitiProcessResource.java
@GET @Path("view/{processInstanceId}") @Produces({ MediaType.TEXT_HTML }) @ResponseBody// www .ja va 2 s.c o m @Transactional(readOnly = true) public byte[] view(@Context HttpServletRequest request, @PathParam("processInstanceId") String processInstanceId) { String contextPath = request.getContextPath(); StringBuffer buffer = new StringBuffer(); if (StringUtils.isNotEmpty(processInstanceId)) { ProcessInstanceInfo processInstanceInfo = activitiProcessQueryService .getProcessInstanceInfo(processInstanceId); if (processInstanceInfo != null) { StringBuffer positionBuffer = new StringBuffer(); StringBuffer position = new StringBuffer(); StringBuffer text = new StringBuffer(); int id = 0; List<ActivityInfo> processedActivityInfos = processInstanceInfo.getProcessedActivityInfos(); List<ActivityInfo> activeActivityInfos = processInstanceInfo.getActiveActivityInfos(); ActivityCoordinates coordinates = null; HistoricActivityInstance activityInstance = null; if (processedActivityInfos != null && !processedActivityInfos.isEmpty()) { for (ActivityInfo info : processedActivityInfos) { coordinates = info.getCoordinates(); activityInstance = info.getActivityInstance(); if (activityInstance == null) { continue; } position.delete(0, position.length()); text.delete(0, text.length()); String elId = "_pai_" + (++id); String title = activityInstance.getActivityName(); position.append("left:").append(coordinates.getX() - 2).append("px;"); position.append("top:").append(coordinates.getY() - 2).append("px;"); position.append("height:").append(coordinates.getHeight() - 2).append("px;"); position.append("width:").append(coordinates.getWidth() - 2).append("px;"); buffer.append("\n <div class=\"tip processed\" id=\"").append(elId) .append("\" style=\"").append(position).append("\"></div>"); Date startDate = activityInstance.getStartTime(); Date endDate = activityInstance.getEndTime(); buffer.append("\n <script>$('").append(elId).append("').store('tip:title', '") .append(title).append('\'').append(").store('tip:text', '") .append("<br/><b>:</b> ").append(DateUtils.getDateTime(startDate)) .append("<br/><b>?:</b> ").append(DateUtils.getDateTime(endDate)); if (activityInstance.getAssignee() != null) { buffer.append("<br/><b>:</b> ").append(activityInstance.getAssignee()); } buffer.append("');</script>"); } } if (activeActivityInfos != null && !activeActivityInfos.isEmpty()) { id = 0; for (ActivityInfo activityInfo : activeActivityInfos) { coordinates = activityInfo.getCoordinates(); String elId = "_aai_" + (++id); positionBuffer.delete(0, positionBuffer.length()); positionBuffer.append("left:").append(coordinates.getX() - 2).append("px;"); positionBuffer.append("top:").append(coordinates.getY() - 2).append("px;"); positionBuffer.append("height:").append(coordinates.getHeight() - 2).append("px;"); positionBuffer.append("width:").append(coordinates.getWidth() - 2).append("px;"); buffer.append("\n <div class=\"tip active\" id=\"").append(elId) .append("\" style=\"").append(positionBuffer.toString()).append("\"></div>"); activityInstance = activityInfo.getActivityInstance(); if (activityInstance != null) { String title = activityInstance.getActivityName(); Date startDate = activityInstance.getStartTime(); buffer.append("\n <script>$('").append(elId).append("').store('tip:title', '") .append(title).append('\'').append(").store('tip:text', '") .append("<br/><b>:</b> ").append(DateUtils.getDateTime(startDate)); if (activityInstance.getAssignee() != null) { buffer.append("<br/><b>:</b> ").append(activityInstance.getAssignee()); } buffer.append("');</script>"); } } } } } String view = CustomProperties.getString("activiti.rs.view"); if (StringUtils.isEmpty(view)) { view = "com/glaf/activiti/web/rest/view.ftl"; } String content = null; if (cache.get(view) != null) { content = (String) cache.get(view); } else { try { Resource resouce = new ClassPathResource(view); content = FileUtils.readFile(resouce.getInputStream()); cache.put(view, content); } catch (IOException e) { e.printStackTrace(); } } Map<String, Object> context = new java.util.HashMap<String, Object>(); context.put("contextPath", contextPath); context.put("x_script", buffer.toString()); context.put("processInstanceId", processInstanceId); content = QueryUtils.replaceTextParas(content, context); try { return content.getBytes("UTF-8"); } catch (IOException e) { return content.getBytes(); } }
From source file:com.glaf.report.web.springmvc.MxReportController.java
@RequestMapping("/chooseChart") public ModelAndView chooseChart(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); request.removeAttribute("canSubmit"); Map<String, Object> params = RequestUtils.getParameterMap(request); String rowId = ParamUtils.getString(params, "reportId"); ChartQuery query = new ChartQuery(); List<Chart> list = chartService.list(query); request.setAttribute("unselecteds", list); Report report = null;/*ww w . j a v a 2s . co m*/ if (StringUtils.isNotEmpty(rowId)) { report = reportService.getReport(rowId); request.setAttribute("report", report); if (StringUtils.isNotEmpty(report.getChartIds())) { StringBuffer sb01 = new StringBuffer(); StringBuffer sb02 = new StringBuffer(); List<String> selecteds = new java.util.ArrayList<String>(); List<String> chartIds = StringTools.split(report.getChartIds()); for (Chart c : list) { if (chartIds.contains(c.getId())) { selecteds.add(c.getId()); sb01.append(c.getId()).append(","); sb02.append(c.getSubject()).append(","); } } if (sb01.toString().endsWith(",")) { sb01.delete(sb01.length() - 1, sb01.length()); } if (sb02.toString().endsWith(",")) { sb02.delete(sb02.length() - 1, sb02.length()); } request.setAttribute("selecteds", selecteds); request.setAttribute("chartIds", sb01.toString()); request.setAttribute("chartNames", sb02.toString()); } if (StringUtils.isNotEmpty(report.getQueryIds())) { List<String> queryIds = StringTools.split(report.getQueryIds()); StringBuffer sb01 = new StringBuffer(); StringBuffer sb02 = new StringBuffer(); for (String queryId : queryIds) { QueryDefinition queryDefinition = queryDefinitionService.getQueryDefinition(queryId); if (queryDefinition != null) { sb01.append(queryDefinition.getId()).append(","); sb02.append(queryDefinition.getTitle()).append("[").append(queryDefinition.getId()) .append("],"); } } if (sb01.toString().endsWith(",")) { sb01.delete(sb01.length() - 1, sb01.length()); } if (sb02.toString().endsWith(",")) { sb02.delete(sb02.length() - 1, sb02.length()); } request.setAttribute("queryIds", sb01.toString()); request.setAttribute("queryNames", sb02.toString()); } } String x_view = ViewProperties.getString("report.chooseChart"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/bi/report/chooseChart", modelMap); }