List of usage examples for java.lang StringBuffer lastIndexOf
@Override public int lastIndexOf(String str)
From source file:org.etudes.component.app.melete.SectionDB.java
public void deleteResources(Session session, List<String> delResources, boolean removeResourceFlag) { StringBuffer delResourceIds = new StringBuffer("("); // delete melete resource for (String delRes : delResources) { if (delRes == null) continue; delResourceIds.append("'" + delRes + "',"); if (removeResourceFlag == true) { try { meleteCHService.removeResource(delRes); } catch (Exception e) { logger.warn("unable to delete resource.its still asociated with section." + delRes); }//from w ww. j a v a2 s.c o m } } if (delResourceIds.lastIndexOf(",") != -1) delResourceIds = new StringBuffer(delResourceIds.substring(0, delResourceIds.lastIndexOf(",")) + " )"); String delMeleteResourceStr = "delete MeleteResource mr where mr.resourceId in " + delResourceIds; int deletedEntities = session.createQuery(delMeleteResourceStr).executeUpdate(); }
From source file:net.sourceforge.myvd.inserts.jdbc.JdbcInsert.java
private void createSELECT(ArrayList<Attribute> attributes, StringBuffer buf) { Iterator<Attribute> it = attributes.iterator(); boolean foundRDN = false; boolean foundAttrib = false; if (attributes.size() == 0) { buf.append(" * "); return;/*from w w w . ja va 2s . c om*/ } while (it.hasNext()) { foundAttrib = false; String attrib = it.next().getAttribute().getName(); if (attrib.equalsIgnoreCase(this.rdn)) { foundRDN = true; } if (attrib.equalsIgnoreCase("*")) { buf.append("* "); } else { String ldap2dbVal = ldap2db.get(attrib.toLowerCase()); if (ldap2dbVal != null) { buf.append(ldap2dbVal).append(' '); foundAttrib = true; } else { continue; } } if ((it.hasNext() || !foundRDN) && foundAttrib) { buf.append(','); } } if (!foundRDN) { buf.append(this.ldap2db.get(this.rdn.toLowerCase())).append(" ,"); } if (!foundAttrib) { buf.setLength(buf.lastIndexOf(",") - 1); } if (buf.charAt(buf.length() - 1) == ',') { buf.setLength(buf.length() - 1); } }
From source file:org.kuali.ole.module.purap.document.web.struts.PurchaseOrderAction.java
/** * Forwards to the RetransmitForward.jsp page so that we could open 2 windows for retransmit, * one is to display the PO tabbed page and the other one display the pdf document. * * @param mapping/*w w w .ja v a2s .c o m*/ * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward printingRetransmitPo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String basePath = getApplicationBaseUrl(); String docId = ((PurchaseOrderForm) form).getPurchaseOrderDocument().getDocumentNumber(); String methodToCallPrintRetransmitPurchaseOrderPDF = "printingRetransmitPoOnly"; String methodToCallDocHandler = "docHandler"; String printPOPDFUrl = getUrlForPrintPO(basePath, docId, methodToCallPrintRetransmitPurchaseOrderPDF); String displayPOTabbedPageUrl = getUrlForPrintPO(basePath, docId, methodToCallDocHandler); KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form; PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase.getDocument(); StringBuffer itemIndexesBuffer = createSelectedItemIndexes(po.getItems()); if (itemIndexesBuffer.length() > 0) { itemIndexesBuffer.deleteCharAt(itemIndexesBuffer.lastIndexOf(",")); request.setAttribute("selectedItemIndexes", itemIndexesBuffer.toString()); } request.setAttribute("printPOPDFUrl", printPOPDFUrl); request.setAttribute("displayPOTabbedPageUrl", displayPOTabbedPageUrl); request.setAttribute("docId", docId); String label = SpringContext.getBean(DataDictionaryService.class) .getDocumentLabelByTypeName(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER); request.setAttribute("purchaseOrderLabel", label); return mapping.findForward("retransmitPurchaseOrderPDF"); }
From source file:org.kuali.kfs.module.purap.document.web.struts.PurchaseOrderAction.java
/** * Forwards to the RetransmitForward.jsp page so that we could open 2 windows for retransmit, one is to display the PO tabbed * page and the other one display the pdf document. * * @param mapping//from www . j a v a 2s . c om * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward printingRetransmitPo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String basePath = getApplicationBaseUrl(); String docId = ((PurchaseOrderForm) form).getPurchaseOrderDocument().getDocumentNumber(); String methodToCallPrintRetransmitPurchaseOrderPDF = "printingRetransmitPoOnly"; String methodToCallDocHandler = "docHandler"; String printPOPDFUrl = getUrlForPrintPO(basePath, docId, methodToCallPrintRetransmitPurchaseOrderPDF); String displayPOTabbedPageUrl = getUrlForPrintPO(basePath, docId, methodToCallDocHandler); KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form; PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase.getDocument(); StringBuffer itemIndexesBuffer = createSelectedItemIndexes(po.getItems()); if (itemIndexesBuffer.length() > 0) { itemIndexesBuffer.deleteCharAt(itemIndexesBuffer.lastIndexOf(",")); request.setAttribute("selectedItemIndexes", itemIndexesBuffer.toString()); } if (itemIndexesBuffer.length() == 0) { GlobalVariables.getMessageMap().putError(PurapConstants.PO_RETRANSMIT_SELECT_TAB_ERRORS, PurapKeyConstants.ERROR_PURCHASE_ORDER_RETRANSMIT_SELECT); return returnToPreviousPage(mapping, kualiDocumentFormBase); } request.setAttribute("printPOPDFUrl", printPOPDFUrl); request.setAttribute("displayPOTabbedPageUrl", displayPOTabbedPageUrl); request.setAttribute("docId", docId); String label = SpringContext.getBean(DataDictionaryService.class) .getDocumentLabelByTypeName(KFSConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER); request.setAttribute("purchaseOrderLabel", label); return mapping.findForward("retransmitPurchaseOrderPDF"); }
From source file:com.openerp.orm.ORM.java
/** * Creates the statement./* ww w .j a v a 2s .c o m*/ * * @param moduleDBHelper * the module db helper * @return the sQL statement */ public SQLStatement createStatement(BaseDBHelper moduleDBHelper) { this.tableName = modelToTable(moduleDBHelper.getModelName()); this.fields = moduleDBHelper.getColumns(); SQLStatement statement = new SQLStatement(); StringBuffer create = new StringBuffer(); create.append("CREATE TABLE IF NOT EXISTS "); create.append(this.tableName); create.append(" ("); for (Fields field : this.fields) { Object type = field.getType(); if (field.getType() instanceof Many2Many) { handleMany2ManyCol(moduleDBHelper, field); continue; } if (field.getType() instanceof Many2One) { if (((Many2One) field.getType()).isM2OObject()) { BaseDBHelper m2oDb = ((Many2One) field.getType()).getM2OObject(); createMany2OneTable(m2oDb); } type = Types.integer(); } try { create.append(field.getName()); create.append(" "); create.append(type.toString()); create.append(", "); } catch (Exception e) { } } create.deleteCharAt(create.lastIndexOf(",")); create.append(")"); this.statements.put("create", create.toString()); statement.setTable_name(this.tableName); statement.setType("create"); statement.setStatement(create.toString()); return statement; }
From source file:org.gbif.portal.service.log.TripletQueryLoggingInterceptor.java
/** * Creates a brief message from the criteria * @param messagePreamble/*w ww.j a va 2 s.co m*/ * @param criteria * @return */ protected void createMessagePreamble(StringBuffer messagePreamble, List<PropertyStoreTripletDTO> criteria) { Map<String, Set<String>> subjects = new HashMap<String, Set<String>>(); for (PropertyStoreTripletDTO dto : criteria) { String subject = dto.getSubject(); String loggableSubject = getServiceKeyToBriefLoggableName().get(subject); // only log the ones we care about - e.g. ones we can make sense of if (loggableSubject != null) { String value = null; // some of them are null due to "coordinates areNot null" for example if (dto.getObject() != null) { value = dto.getObject().toString(); } // map the object to what it really is - e.g. ID -> loggable string if (serviceObjectToLoggableStringMappers.containsKey(subject)) { LoggableFromPredicateAndObject converter = serviceObjectToLoggableStringMappers.get(subject); value = converter.getLoggable(dto.getPredicate(), dto.getObject()); if (value == null) { if (logger.isDebugEnabled()) { logger.debug("Unable to get a loggable for key[" + dto.getObject() + "] using [" + converter.getClass().getSimpleName() + "] - ignoring from message"); } } } if (value != null) { if (subjects.containsKey(loggableSubject)) { subjects.get(loggableSubject).add(value); } else { Set<String> values = new HashSet<String>(); values.add(value); subjects.put(loggableSubject, values); } } } } for (String subject : subjects.keySet()) { messagePreamble.append(subject + "["); for (String value : subjects.get(subject)) { messagePreamble.append(value + ","); } messagePreamble.delete(messagePreamble.lastIndexOf(","), messagePreamble.lastIndexOf(",") + 1); messagePreamble.append("] "); } }
From source file:weka.gui.explorer.ClassifierPanelRemoteLauncher.java
/** * Purge the supplied tasks from the server * //from w ww .j ava2 s .co m * @param taskIDs a list of task IDs of tasks to purge */ protected void purgeTasksFromServer(List<String> taskIDs) { InputStream is = null; PostMethod post = null; StringBuffer tasks = new StringBuffer(); for (String id : taskIDs) { tasks.append(id + ","); } String taskList = tasks.substring(0, tasks.lastIndexOf(",")); try { String service = PurgeTaskServlet.CONTEXT_PATH + "/?name=" + taskList + "&client=Y"; post = new PostMethod(constructURL(service)); post.setDoAuthentication(true); post.addRequestHeader(new Header("Content-Type", "text/plain")); // Get HTTP client HttpClient client = WekaServer.ConnectionManager.getSingleton().createHttpClient(); WekaServer.ConnectionManager.addCredentials(client, m_username, m_password); int result = client.executeMethod(post); if (result == 401) { logMessage("Unable to purge tasks from server - authentication " + "required"); } else { is = post.getResponseBodyAsStream(); ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(is)); Object response = ois.readObject(); if (response.toString().startsWith(WekaServlet.RESPONSE_ERROR)) { logMessage("Server returned an error: " + "while trying to purge completed tasks: '" + taskList + "'. (" + response.toString() + ")." + " Check logs on server."); } } } catch (Exception ex) { logMessage( "An error occurred while trying to purge completed tasks from " + "server: " + ex.getMessage()); ex.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (Exception e) { } } if (post != null) { // Release current connection to the connection pool post.releaseConnection(); } } }
From source file:org.apache.geode.internal.cache.wan.WANTestBase.java
public static void createLocator(int dsId, int port, Set<String> localLocatorsList, Set<String> remoteLocatorsList) { WANTestBase test = new WANTestBase(); Properties props = test.getDistributedSystemProperties(); props.setProperty(MCAST_PORT, "0"); props.setProperty(DISTRIBUTED_SYSTEM_ID, "" + dsId); StringBuffer localLocatorBuffer = new StringBuffer(localLocatorsList.toString()); localLocatorBuffer.deleteCharAt(0);//from ww w . j av a2 s .c o m localLocatorBuffer.deleteCharAt(localLocatorBuffer.lastIndexOf("]")); String localLocator = localLocatorBuffer.toString(); localLocator = localLocator.replace(" ", ""); props.setProperty(LOCATORS, localLocator); props.setProperty(START_LOCATOR, "localhost[" + port + "],server=true,peer=true,hostname-for-clients=localhost"); StringBuffer remoteLocatorBuffer = new StringBuffer(remoteLocatorsList.toString()); remoteLocatorBuffer.deleteCharAt(0); remoteLocatorBuffer.deleteCharAt(remoteLocatorBuffer.lastIndexOf("]")); String remoteLocator = remoteLocatorBuffer.toString(); remoteLocator = remoteLocator.replace(" ", ""); props.setProperty(REMOTE_LOCATORS, remoteLocator); test.getSystem(props); }
From source file:org.egov.works.web.actions.reports.WorksGISReportAction.java
public String search() { List<Object[]> findAll = null; locationList = new ArrayList<GeoLocation>(); GeoLatLong latlong = new GeoLatLong(); Map<String, Object> markerdata = null; final String query = generateQuery(); try {/* www . ja v a 2 s .c om*/ LOGGER.info("HQl query=" + query.toString()); findAll = persistenceService.findAllBy(query.toString()); LOGGER.info("HQl query RESULT " + findAll.size()); Long estId, projcodeId, contractPeriod; BigDecimal estLat, estLon; String estNumber, estWorkName, wpno, tenderDocReleasedDt, typeOfWork, subTypeOfWork, workOrderDate, contractorName, workCommencedDt; Money workValue; Double ovrheads; // Start format and push the data GeoLocation geoLocation = null; for (final Object[] columnOutput : findAll) { // Reset the values estId = projcodeId = contractPeriod = null; estLat = estLon = null; estNumber = estWorkName = wpno = tenderDocReleasedDt = typeOfWork = subTypeOfWork = workOrderDate = contractorName = workCommencedDt = null; workValue = null; ovrheads = null; // Set the values estId = (Long) columnOutput[0]; estLat = (BigDecimal) columnOutput[1]; estLon = (BigDecimal) columnOutput[2]; estNumber = (String) columnOutput[3]; estWorkName = (String) columnOutput[4]; workValue = (Money) columnOutput[5]; ovrheads = (Double) columnOutput[6]; wpno = (String) columnOutput[7]; tenderDocReleasedDt = (String) columnOutput[8]; typeOfWork = (String) columnOutput[9]; subTypeOfWork = (String) columnOutput[10]; projcodeId = (Long) columnOutput[11]; geoLocation = new GeoLocation(); if (null != estLat && null != estLon) { latlong = new GeoLatLong(); latlong.setLatitude(estLat); latlong.setLongitude(estLat); } geoLocation.setGeoLatLong(latlong); // **geoLocation.setUseNiceInfoWindow(true); geoLocation.setUrlRedirect( "../estimate/abstractEstimate!edit.action?id=" + estId + "&sourcepage=search~" + estNumber); String max50CharName = ""; if (null != estWorkName && estWorkName.length() >= 50) max50CharName = estWorkName.substring(0, 50) + "..."; else max50CharName = estWorkName; geoLocation.setInfo2("Work Name=" + max50CharName); if (workValue != null || ovrheads != null) { BigDecimal amt = workValue != null ? new BigDecimal(workValue.getValue()) : BigDecimal.ZERO; amt = amt.add(ovrheads != null ? new BigDecimal(ovrheads) : BigDecimal.ZERO); geoLocation.setInfo3("Estimate Value(Rs)=" + NumberUtil.formatNumber(amt, NumberUtil.NumberFormatStyle.CRORES)); } else geoLocation.setInfo3("Estimate Value(Rs)=0.00"); if (wpno != null) geoLocation.setInfo4("Works Package Number=" + wpno); markerdata = new HashMap<String, Object>(); if (typeOfWork != null) { geoLocation.appendToInfo5("Type of Work=" + typeOfWork); if (typeOfWork.equalsIgnoreCase(WorksConstants.TYPE_OF_WORK_BRIDGES)) markerdata.put("icon", GeoLocationConstants.MARKEROPTION_ICON_PURPLE); else if (typeOfWork.equalsIgnoreCase(WorksConstants.TYPE_OF_WORK_BUILDINGS)) markerdata.put("icon", GeoLocationConstants.MARKEROPTION_ICON_YELLOW); else if (typeOfWork.equalsIgnoreCase(WorksConstants.TYPE_OF_WORK_ELECTRICAL)) markerdata.put("icon", GeoLocationConstants.MARKEROPTION_ICON_GREEN); else if (typeOfWork.equalsIgnoreCase(WorksConstants.TYPE_OF_WORK_ROADS)) markerdata.put("icon", GeoLocationConstants.MARKEROPTION_ICON_ORANGE); else if (typeOfWork.equalsIgnoreCase(WorksConstants.TYPE_OF_WORK_STORMWATER_DRAIN)) markerdata.put("icon", GeoLocationConstants.MARKEROPTION_ICON_BLUE); } if (subTypeOfWork != null) geoLocation.appendToInfo5("Subtype of Work=" + subTypeOfWork); if (tenderDocReleasedDt != null) geoLocation.appendToInfo5("Tender Document Released Date=" + tenderDocReleasedDt); final String tenderAmount = getTenderAmount(estId); if (StringUtils.isNotBlank(tenderAmount)) geoLocation.appendToInfo5("Tender Finalized Value(Rs)=" + tenderAmount); if (contractorId != null && contractorId != -1) { workOrderDate = (String) columnOutput[12]; if (columnOutput[13] != null) contractPeriod = Long.parseLong(columnOutput[13].toString()); contractorName = (String) columnOutput[14]; workCommencedDt = (String) columnOutput[15]; if (workOrderDate != null) geoLocation.appendToInfo5("Work Order Date=" + workOrderDate); if (workCommencedDt != null) geoLocation.appendToInfo5("Work Commenced Date=" + workCommencedDt); if (contractPeriod != null) geoLocation.appendToInfo5("Contract Period In Days=" + contractPeriod); if (workCommencedDt != null && contractPeriod != null) { final Date woDate = new Date(workCommencedDt); final Calendar cal = Calendar.getInstance(); cal.setTime(woDate); cal.add(Calendar.DATE, new Long(contractPeriod).intValue()); geoLocation.appendToInfo5("Expected Date Of Completion =" + sdf.format(cal.getTime())); } if (projcodeId != null) { final String paymentAmt = getPaymentAmount(projcodeId); if (paymentAmt != null) geoLocation.appendToInfo5("Payment Released(Rs)=" + paymentAmt); } if (contractorName != null) geoLocation.appendToInfo5("Contractor Name=" + contractorName); } else { final List<WorkOrder> woList = persistenceService.findAllBy( " select woe.workOrder from WorkOrderEstimate woe where woe.estimate.id=? and upper(woe.workOrder.egwStatus.code) not in ('" + WorksConstants.NEW + "','" + WorksConstants.CANCELLED_STATUS + "') ", estId); if (woList != null && woList.size() > 0) { final StringBuffer workOrderDatesBuf = new StringBuffer(""); final StringBuffer workCommencedDateBuf = new StringBuffer(""); final StringBuffer contractorNameBuf = new StringBuffer(""); final StringBuffer workExpectedCompletionDateBuf = new StringBuffer(""); final StringBuffer workOrderContractPeriodBuf = new StringBuffer(""); for (final WorkOrder wo : woList) { Long workOrderContractPeriod = null; workOrderDatesBuf.append(sdf.format(wo.getWorkOrderDate()) + ","); contractorNameBuf.append(wo.getContractor().getName() + ","); if (wo.getContractPeriod() != null) { workOrderContractPeriod = Long.valueOf(wo.getContractPeriod()); workOrderContractPeriodBuf.append(wo.getContractPeriod() + ","); } else workOrderContractPeriodBuf.append("NA,"); boolean workCommencedPresent = false; boolean workExpectedCompletedPresent = false; for (final OfflineStatus ss : wo.getOfflineStatuses()) if (ss.getEgwStatus().getCode() .equalsIgnoreCase(WorksConstants.WO_STATUS_WOCOMMENCED)) { workCommencedDateBuf.append(sdf.format(ss.getStatusDate()) + ","); workCommencedPresent = true; if (workOrderContractPeriod != null) { final Calendar cal = Calendar.getInstance(); cal.setTime(wo.getWorkOrderDate()); cal.add(Calendar.DATE, workOrderContractPeriod.intValue()); workExpectedCompletionDateBuf.append(sdf.format(cal.getTime()) + ","); workExpectedCompletedPresent = true; } } if (!workCommencedPresent) workCommencedDateBuf.append("NA,"); if (!workExpectedCompletedPresent) workExpectedCompletionDateBuf.append("NA,"); } geoLocation.appendToInfo5("Work Order Date=" + workOrderDatesBuf.deleteCharAt(workOrderDatesBuf.lastIndexOf(",")).toString()); if (StringUtils.isNotBlank(workCommencedDateBuf.toString())) geoLocation.appendToInfo5("Work Commenced Date=" + workCommencedDateBuf .deleteCharAt(workCommencedDateBuf.lastIndexOf(",")).toString()); if (StringUtils.isNotBlank(workOrderContractPeriodBuf.toString())) geoLocation.appendToInfo5("Contract Period In Days=" + workOrderContractPeriodBuf .deleteCharAt(workOrderContractPeriodBuf.lastIndexOf(",")).toString()); if (StringUtils.isNotBlank(workExpectedCompletionDateBuf.toString())) geoLocation.appendToInfo5("Expected Date Of Completion=" + workExpectedCompletionDateBuf .deleteCharAt(workExpectedCompletionDateBuf.lastIndexOf(",")).toString()); if (projcodeId != null) { final String paymentAmt = getPaymentAmount(projcodeId); if (paymentAmt != null) geoLocation.appendToInfo5("Payment Released(Rs)=" + paymentAmt); } geoLocation.appendToInfo5("Contractor Name=" + contractorNameBuf.deleteCharAt(contractorNameBuf.lastIndexOf(",")).toString()); } } geoLocation.setMarkerOptionData(markerdata); locationList.add(geoLocation); } ServletActionContext.getRequest().setAttribute("kmlfilename", "coczone"); ServletActionContext.getRequest().setAttribute(GeoLocationConstants.GEOLOCATIONLIST_ATTRIBUTE, locationList); resultStatus = AFTER_SEARCH; if (locationList != null && locationList.size() >= 1) return GMAP; } catch (final Exception e) { LOGGER.error(e, e); } return GMAP; }