List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:module.regulation.dispatch.presentationTier.RegulationDispatchAction.java
private String serializeAjaxFilterResponse(String sEcho, Integer iTotalRecords, Integer iTotalDisplayRecords, java.util.List<RegulationDispatchWorkflowMetaProcess> limitedEntries, HttpServletRequest request) { StringBuilder stringBuilder = new StringBuilder("{"); stringBuilder.append("\"sEcho\": ").append(sEcho).append(", \n"); stringBuilder.append("\"iTotalRecords\": ").append(iTotalRecords).append(", \n"); stringBuilder.append("\"iTotalDisplayRecords\": ").append(iTotalDisplayRecords).append(", \n"); stringBuilder.append("\"aaData\": ").append("[ \n"); for (RegulationDispatchWorkflowMetaProcess entry : limitedEntries) { RegulationDispatchWorkflowMetaProcess meta = ((RegulationDispatchWorkflowMetaProcess) entry); boolean ableToAccessQueue = RegulationDispatchSystem .isRegulationDispatchManager(Authenticate.getUser()); String reference = entry.getReference(); LocalDate emissionDate = entry.getEmissionDate(); String dispatchDescription = entry.getInstanceDescription(); Person emissor = entry.getRequestorUser().getPerson(); String regulationReference = entry.getRegulationReference() != null ? entry.getRegulationReference() : ""; Boolean hasMainDocument = entry.getMainDocument() != null; stringBuilder.append("[ \"").append(reference).append("\", "); stringBuilder.append("\"").append(escapeQuotes(emissionDate.toString("dd/MM/yyyy"))).append("\", "); stringBuilder.append("\"").append(escapeQuotes(dispatchDescription)).append("\", "); stringBuilder.append("\"").append(escapeQuotes(emissor.getName())).append("\", "); stringBuilder.append("\"").append(escapeQuotes(regulationReference)).append("\", "); stringBuilder.append("\"") .append(ableToAccessQueue ? generateLinkForView(request, entry) : "permission_not_granted") .append(","); stringBuilder/*from w w w .j a v a 2 s .c o m*/ .append(ableToAccessQueue ? generateLinkForEdition(request, entry) : "permission_not_granted") .append(","); stringBuilder.append(ableToAccessQueue && entry.isActive() ? generateLinkForRemoval(request, entry) : "permission_not_granted").append(","); stringBuilder.append(ableToAccessQueue && hasMainDocument ? generateLinkForMainDocument(request, entry) : "permission_not_granted").append("\","); stringBuilder.append("\"").append(entry.isActive()).append("\" ], "); } stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length()); stringBuilder.append(" ]\n }"); return stringBuilder.toString(); }
From source file:org.sakaiproject.reports.logic.impl.ReportsManagerImpl.java
public StringBuilder replaceForMultiSet(StringBuilder inQuery, List reportParams) { if (reportParams == null) { return inQuery; }/*from w ww . j a va 2s .c om*/ Iterator iter = reportParams.iterator(); // loop through all the parameters and find in query for replacement while (iter.hasNext()) { // get the paremeter and associated parameter definition ReportParam rp = (ReportParam) iter.next(); ReportDefinitionParam rdp = rp.getReportDefinitionParam(); if (ReportDefinitionParam.VALUE_TYPE_MULTI_OF_SET.equals(rdp.getValueType()) || ReportDefinitionParam.VALUE_TYPE_MULTI_OF_QUERY.equals(rdp.getValueType())) { if (rp.getListValue().size() > 1) { int index = inQuery.indexOf("(?)"); inQuery.delete(index, index + 3); StringBuilder tempString = new StringBuilder("("); for (int i = 0; i < rp.getListValue().size(); i++) { tempString.append("?,"); } tempString.delete(tempString.length() - 1, tempString.length()); tempString.append(") "); inQuery.insert(index, tempString); } } } return inQuery; }
From source file:com.gst.infrastructure.dataqueries.service.ReadWriteNonCoreDataServiceImpl.java
@Transactional @Override/*from ww w . j a va2 s . c om*/ public CommandProcessingResult createDatatable(final JsonCommand command) { String datatableName = null; try { this.context.authenticatedUser(); this.fromApiJsonDeserializer.validateForCreate(command.json()); final JsonElement element = this.fromJsonHelper.parse(command.json()); final JsonArray columns = this.fromJsonHelper.extractJsonArrayNamed("columns", element); datatableName = this.fromJsonHelper.extractStringNamed("datatableName", element); final String apptableName = this.fromJsonHelper.extractStringNamed("apptableName", element); Boolean multiRow = this.fromJsonHelper.extractBooleanNamed("multiRow", element); /*** * In cases of tables storing hierarchical entities (like m_group), * different entities would end up being stored in the same table. * * Ex: Centers are a specific type of group, add abstractions for * the same ***/ final String actualAppTableName = mapToActualAppTable(apptableName); if (multiRow == null) { multiRow = false; } validateDatatableName(datatableName); validateAppTable(apptableName); final boolean isConstraintApproach = this.configurationDomainService .isConstraintApproachEnabledForDatatables(); final String fkColumnName = apptableName.substring(2) + "_id"; final String dataTableNameAlias = datatableName.toLowerCase().replaceAll("\\s", "_"); final String fkName = dataTableNameAlias + "_" + fkColumnName; StringBuilder sqlBuilder = new StringBuilder(); final StringBuilder constrainBuilder = new StringBuilder(); final Map<String, Long> codeMappings = new HashMap<>(); sqlBuilder = sqlBuilder.append("CREATE TABLE `" + datatableName + "` ("); if (multiRow) { sqlBuilder = sqlBuilder.append("`id` BIGINT(20) NOT NULL AUTO_INCREMENT, ") .append("`" + fkColumnName + "` BIGINT(20) NOT NULL, "); } else { sqlBuilder = sqlBuilder.append("`" + fkColumnName + "` BIGINT(20) NOT NULL, "); } for (final JsonElement column : columns) { parseDatatableColumnObjectForCreate(column.getAsJsonObject(), sqlBuilder, constrainBuilder, dataTableNameAlias, codeMappings, isConstraintApproach); } // Remove trailing comma and space sqlBuilder = sqlBuilder.delete(sqlBuilder.length() - 2, sqlBuilder.length()); if (multiRow) { sqlBuilder = sqlBuilder.append(", PRIMARY KEY (`id`)") .append(", KEY `fk_" + apptableName.substring(2) + "_id` (`" + fkColumnName + "`)") .append(", CONSTRAINT `fk_" + fkName + "` ").append("FOREIGN KEY (`" + fkColumnName + "`) ") .append("REFERENCES `" + actualAppTableName + "` (`id`)"); } else { sqlBuilder = sqlBuilder.append(", PRIMARY KEY (`" + fkColumnName + "`)") .append(", CONSTRAINT `fk_" + fkName + "` ").append("FOREIGN KEY (`" + fkColumnName + "`) ") .append("REFERENCES `" + actualAppTableName + "` (`id`)"); } sqlBuilder.append(constrainBuilder); sqlBuilder = sqlBuilder.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;"); this.jdbcTemplate.execute(sqlBuilder.toString()); registerDatatable(datatableName, apptableName); registerColumnCodeMapping(codeMappings); } catch (final DataIntegrityViolationException e) { final Throwable realCause = e.getCause(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("datatable"); if (realCause.getMessage().toLowerCase().contains("duplicate column name")) { baseDataValidator.reset().parameter("name").failWithCode("duplicate.column.name"); } else if (realCause.getMessage().contains("Table") && realCause.getMessage().contains("already exists")) { baseDataValidator.reset().parameter("datatableName").value(datatableName) .failWithCode("datatable.already.exists"); } else if (realCause.getMessage().contains("Column") && realCause.getMessage().contains("big")) { baseDataValidator.reset().parameter("column").failWithCode("length.too.big"); } else if (realCause.getMessage().contains("Row") && realCause.getMessage().contains("large")) { baseDataValidator.reset().parameter("row").failWithCode("size.too.large"); } throwExceptionIfValidationWarningsExist(dataValidationErrors); } catch (final PersistenceException | BadSqlGrammarException ee) { Throwable realCause = ExceptionUtils.getRootCause(ee.getCause()); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("datatable"); if (realCause.getMessage().toLowerCase().contains("duplicate column name")) { baseDataValidator.reset().parameter("name").failWithCode("duplicate.column.name"); } else if (realCause.getMessage().contains("Table") && realCause.getMessage().contains("already exists")) { baseDataValidator.reset().parameter("datatableName").value(datatableName) .failWithCode("datatable.already.exists"); } else if (realCause.getMessage().contains("Column") && realCause.getMessage().contains("big")) { baseDataValidator.reset().parameter("column").failWithCode("length.too.big"); } else if (realCause.getMessage().contains("Row") && realCause.getMessage().contains("large")) { baseDataValidator.reset().parameter("row").failWithCode("size.too.large"); } throwExceptionIfValidationWarningsExist(dataValidationErrors); } return new CommandProcessingResultBuilder().withCommandId(command.commandId()) .withResourceIdAsString(datatableName).build(); }
From source file:com.cloud.network.NetworkModelImpl.java
@Override public void canProviderSupportServices(Map<Provider, Set<Service>> providersMap) { for (Provider provider : providersMap.keySet()) { // check if services can be turned off NetworkElement element = getElementImplementingProvider(provider.getName()); if (element == null) { throw new InvalidParameterValueException( "Unable to find the Network Element implementing the Service Provider '" + provider.getName() + "'"); }/*w w w .j a v a 2 s . c o m*/ Set<Service> enabledServices = new HashSet<Service>(); enabledServices.addAll(providersMap.get(provider)); if (enabledServices != null && !enabledServices.isEmpty()) { if (!element.canEnableIndividualServices()) { Set<Service> requiredServices = new HashSet<Service>(); requiredServices.addAll(element.getCapabilities().keySet()); if (requiredServices.contains(Network.Service.Gateway)) { requiredServices.remove(Network.Service.Gateway); } if (requiredServices.contains(Network.Service.Firewall)) { requiredServices.remove(Network.Service.Firewall); } if (enabledServices.contains(Network.Service.Firewall)) { enabledServices.remove(Network.Service.Firewall); } // exclude gateway service if (enabledServices.size() != requiredServices.size()) { StringBuilder servicesSet = new StringBuilder(); for (Service requiredService : requiredServices) { // skip gateway service as we don't allow setting it via API if (requiredService == Service.Gateway) { continue; } servicesSet.append(requiredService.getName() + ", "); } servicesSet.delete(servicesSet.toString().length() - 2, servicesSet.toString().length()); throw new InvalidParameterValueException( "Cannot enable subset of Services, Please specify the complete list of Services: " + servicesSet.toString() + " for Service Provider " + provider.getName()); } } List<String> serviceList = new ArrayList<String>(); for (Service service : enabledServices) { // check if the service is provided by this Provider if (!element.getCapabilities().containsKey(service)) { throw new UnsupportedServiceException( provider.getName() + " Provider cannot provide service " + service.getName()); } serviceList.add(service.getName()); } if (!element.verifyServicesCombination(enabledServices)) { throw new UnsupportedServiceException("Provider " + provider.getName() + " doesn't support services combination: " + serviceList); } } } }
From source file:com.filemanager.free.activities.MainActivity.java
@Override public void onConnected(Bundle bundle) { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient); Person.Image personImage; Person.Cover.CoverPhoto personCover; try {//from w ww. ja va2 s.c o m personImage = currentPerson.getImage(); personCover = currentPerson.getCover().getCoverPhoto(); } catch (Exception e) { personCover = null; personImage = null; } if (personCover != null && personImage != null) { String imgUrl = personImage.getUrl(); // getting full size image StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(imgUrl); stringBuilder.delete(imgUrl.length() - 6, imgUrl.length()); Log.d("G+", stringBuilder.toString()); mGoogleName.setText(currentPerson.getDisplayName()); mGoogleId.setText(accountName); // setting cover pic ImageLoader.getInstance().loadImage(personCover.getUrl(), displayImageOptions, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); drawerHeaderParent.setBackgroundColor(Color.parseColor("#ffffff")); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { drawerHeaderView .setBackground(new BitmapDrawable(con.getResources(), loadedImage)); } else { drawerHeaderView.setBackgroundDrawable( new BitmapDrawable(con.getResources(), loadedImage)); } } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { super.onLoadingFailed(imageUri, view, failReason); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor(skin)); } @Override public void onLoadingStarted(String imageUri, View view) { super.onLoadingStarted(imageUri, view); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor(skin)); } }); // setting profile pic ImageLoader.getInstance().loadImage(stringBuilder.toString(), displayImageOptions, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); drawerProfilePic.setImageBitmap(loadedImage); drawerProfilePic.setVisibility(View.VISIBLE); } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { super.onLoadingFailed(imageUri, view, failReason); } }); } else { Toast.makeText(this, getResources().getText(R.string.no_cover_photo), Toast.LENGTH_SHORT).show(); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor(skin)); } } }
From source file:com.tesora.dve.db.Emitter.java
public void emitExpressionSet(SchemaContext sc, ConnectionValues cv, ExpressionSet set, StringBuilder buf, int prefix) { buf.append("("); for (final ExpressionNode value : set.getSubExpressions()) { emitExpression(sc, cv, value, buf, prefix); buf.append(", "); }// w w w . ja va2 s. c o m buf.delete(buf.length() - 2, buf.length() - 1).append(")"); }
From source file:com.igniva.filemanager.activities.MainActivity.java
@Override public void onConnected(Bundle bundle) { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient); Person.Image personImage; Person.Cover.CoverPhoto personCover; try {/*from www. ja v a 2s .co m*/ personImage = currentPerson.getImage(); personCover = currentPerson.getCover().getCoverPhoto(); } catch (Exception e) { personCover = null; personImage = null; } if (personCover != null && personImage != null) { String imgUrl = personImage.getUrl(); // getting full size image StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(imgUrl); stringBuilder.delete(imgUrl.length() - 6, imgUrl.length()); Log.d("G+", stringBuilder.toString()); mGoogleName.setText(currentPerson.getDisplayName()); mGoogleId.setText(accountName); // setting cover pic ImageLoader.getInstance().loadImage(personCover.getUrl(), displayImageOptions, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); drawerHeaderParent.setBackgroundColor(Color.parseColor("#ffffff")); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { drawerHeaderView.setBackground(new BitmapDrawable(loadedImage)); } else drawerHeaderView.setBackgroundDrawable(new BitmapDrawable(loadedImage)); } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { super.onLoadingFailed(imageUri, view, failReason); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent .setBackgroundColor(Color.parseColor((currentTab == 1 ? skinTwo : skin))); } @Override public void onLoadingStarted(String imageUri, View view) { super.onLoadingStarted(imageUri, view); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent .setBackgroundColor(Color.parseColor((currentTab == 1 ? skinTwo : skin))); } }); // setting profile pic ImageLoader.getInstance().loadImage(stringBuilder.toString(), displayImageOptions, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); drawerProfilePic.setImageBitmap(loadedImage); drawerProfilePic.setVisibility(View.VISIBLE); } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { super.onLoadingFailed(imageUri, view, failReason); } }); } else { Toast.makeText(this, getResources().getText(R.string.no_cover_photo), Toast.LENGTH_SHORT).show(); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab == 1 ? skinTwo : skin))); } } }
From source file:com.amaze.filemanager.activities.MainActivity.java
@Override public void onConnected(Bundle bundle) { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient); Person.Image personImage; Person.Cover.CoverPhoto personCover; try {/*w w w .ja va 2s . c o m*/ personImage = currentPerson.getImage(); personCover = currentPerson.getCover().getCoverPhoto(); } catch (Exception e) { personCover = null; personImage = null; } if (personCover != null && personImage != null) { String imgUrl = personImage.getUrl(); // getting full size image StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(imgUrl); stringBuilder.delete(imgUrl.length() - 6, imgUrl.length()); Log.d("G+", stringBuilder.toString()); mGoogleName.setText(currentPerson.getDisplayName()); mGoogleId.setText(accountName); // setting cover pic ImageLoader.getInstance().loadImage(personCover.getUrl(), displayImageOptions, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); drawerHeaderParent.setBackgroundColor(Color.parseColor("#ffffff")); drawerHeaderView.setBackground(new BitmapDrawable(loadedImage)); } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { super.onLoadingFailed(imageUri, view, failReason); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor(skin)); } @Override public void onLoadingStarted(String imageUri, View view) { super.onLoadingStarted(imageUri, view); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor(skin)); } }); // setting profile pic ImageLoader.getInstance().loadImage(stringBuilder.toString(), displayImageOptions, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); drawerProfilePic.setImageBitmap(loadedImage); drawerProfilePic.setVisibility(View.VISIBLE); } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { super.onLoadingFailed(imageUri, view, failReason); } }); } else { Toast.makeText(this, getResources().getText(R.string.no_cover_photo), Toast.LENGTH_SHORT).show(); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor(skin)); } } }
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 av a 2 s .co 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:com.impetus.client.cassandra.CassandraClientBase.java
/** * On relation columns.//from ww w . j a v a 2 s. c o m * * @param columnNames * the column names * @param columnValues * the column values * @param columnNameBuilder * the column name builder * @param columnValueBuilder * the column value builder * @param rl * the rl * @return To remove redundant columns in insert query */ private StringBuilder onRelationColumns(String columnNames, String columnValues, StringBuilder columnNameBuilder, StringBuilder columnValueBuilder, RelationHolder rl) { int relnameIndx = columnNameBuilder.indexOf("\"" + rl.getRelationName() + "\""); if (relnameIndx != -1 && rl.getRelationValue() != null) { List<String> cNameArray = Arrays.asList(columnNames.split(",")); List<String> cValueArray = new ArrayList<String>(Arrays.asList(columnValues.split(","))); int cValueIndex = cNameArray.indexOf("\"" + rl.getRelationName() + "\""); if (cValueArray.get(cValueIndex).equals("null")) { columnNameBuilder.delete(relnameIndx - 1, relnameIndx + rl.getRelationName().length() + 2); cValueArray.remove(cValueIndex); columnValueBuilder = new StringBuilder( cValueArray.toString().substring(1, cValueArray.toString().length() - 1)); } } return columnValueBuilder; }