List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:DataAn.reportManager.service.impl.ReportServiceImpl.java
@Override public String getParentFSCatalog(long dirId) { List<ReportFileSystem> list = new ArrayList<ReportFileSystem>(); ReportFileSystem fs = fileDao.get(dirId); list.add(fs);/* www . j a va 2 s. c o m*/ Long parentId = fs.getParentId(); while (parentId != null) { ReportFileSystem parentFs = fileDao.get(parentId); list.add(parentFs); parentId = parentFs.getParentId(); } Collections.reverse(list); StringBuilder sb = new StringBuilder(); sb.append("{"); for (ReportFileSystem f : list) { sb.append("\"" + f.getId().toString() + "\"" + ":" + "\"" + f.getFileName() + "\"" + ","); } if (sb.lastIndexOf(",") != -1) { sb.deleteCharAt(sb.lastIndexOf(",")); } sb.append("}"); return sb.toString(); }
From source file:net.sf.jabref.importer.fileformat.BibtexParser.java
/** * Tries to restore the key// ww w.j a v a 2s . c om * * @return rest of key on success, otherwise empty string * @throws IOException on Reader-Error */ private String fixKey() throws IOException { StringBuilder key = new StringBuilder(); int lookaheadUsed = 0; char currentChar; // Find a char which ends key (','&&'\n') or entryfield ('='): do { currentChar = (char) read(); key.append(currentChar); lookaheadUsed++; } while ((currentChar != ',') && (currentChar != '\n') && (currentChar != '=') && (lookaheadUsed < BibtexParser.LOOKAHEAD)); // Consumed a char too much, back into reader and remove from key: unread(currentChar); key.deleteCharAt(key.length() - 1); // Restore if possible: switch (currentChar) { case '=': // Get entryfieldname, push it back and take rest as key key = key.reverse(); boolean matchedAlpha = false; for (int i = 0; i < key.length(); i++) { currentChar = key.charAt(i); /// Skip spaces: if (!matchedAlpha && (currentChar == ' ')) { continue; } matchedAlpha = true; // Begin of entryfieldname (e.g. author) -> push back: unread(currentChar); if ((currentChar == ' ') || (currentChar == '\n')) { /* * found whitespaces, entryfieldname completed -> key in * keybuffer, skip whitespaces */ StringBuilder newKey = new StringBuilder(); for (int j = i; j < key.length(); j++) { currentChar = key.charAt(j); if (!Character.isWhitespace(currentChar)) { newKey.append(currentChar); } } // Finished, now reverse newKey and remove whitespaces: parserResult.addWarning( Localization.lang("Line %0: Found corrupted BibTeX key.", String.valueOf(line))); key = newKey.reverse(); } } break; case ',': parserResult.addWarning(Localization.lang("Line %0: Found corrupted BibTeX key (contains whitespaces).", String.valueOf(line))); break; case '\n': parserResult.addWarning(Localization.lang("Line %0: Found corrupted BibTeX key (comma missing).", String.valueOf(line))); break; default: // No more lookahead, give up: unreadBuffer(key); return ""; } return removeWhitespaces(key).toString(); }
From source file:com.janrain.backplane2.server.Backplane2Controller.java
private String checkScope(String scope, String authenticatedBusOwner) throws BackplaneServerException { StringBuilder result = new StringBuilder(); List<BusConfig2> ownedBuses = daoFactory.getBusDao().retrieveByOwner(authenticatedBusOwner); if (StringUtils.isEmpty(scope)) { // request scope empty, ask/offer permission to all owned buses for (BusConfig2 bus : ownedBuses) { result.append("bus:").append(bus.get(BusConfig2.Field.BUS_NAME)).append(" "); }/* w w w . j a va2 s . com*/ if (result.length() > 0) { result.deleteCharAt(result.length() - 1); } } else { List<String> ownedBusNames = new ArrayList<String>(); for (BusConfig2 bus : ownedBuses) { ownedBusNames.add(bus.get(BusConfig2.Field.BUS_NAME)); } for (String scopeToken : scope.split(" ")) { if (scopeToken.startsWith("bus:")) { String bus = scopeToken.substring(4); if (!ownedBusNames.contains(bus)) continue; } result.append(scopeToken).append(" "); } if (result.length() > 0) { result.deleteCharAt(result.length() - 1); } } String resultString = result.toString(); if (!resultString.equals(scope)) { logger.info("Authenticated bus owner " + authenticatedBusOwner + " is authoritative for requested scope: " + resultString); } return resultString; }
From source file:co.runrightfast.core.security.auth.x500.DistinguishedName.java
/** * * @return String DN in RFC 2253 format/*w ww.java 2 s .c om*/ */ @Override public String toString() { final StringBuilder sb = new StringBuilder(128); if (StringUtils.isNotBlank(userid)) { sb.append("UID=").append(userid).append(','); } if (StringUtils.isNotBlank(commonName)) { sb.append("CN=").append(commonName).append(','); } if (StringUtils.isNotBlank(organizationalUnitName)) { sb.append("OU=").append(organizationalUnitName).append(','); } if (StringUtils.isNotBlank(organizationName)) { sb.append("O=").append(organizationName).append(','); } if (StringUtils.isNotBlank(country)) { sb.append("C=").append(country).append(','); } if (StringUtils.isNotBlank(stateOrProvinceName)) { sb.append("ST=").append(stateOrProvinceName).append(','); } if (StringUtils.isNotBlank(streetAddress)) { sb.append("STREET=").append(streetAddress).append(','); } if (StringUtils.isNotBlank(country)) { sb.append("C=").append(country).append(','); } if (StringUtils.isNotBlank(domain)) { Arrays.stream(StringUtils.split(domain, '.')) .forEach(domainComponent -> sb.append("DC=").append(domainComponent).append(',')); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:org.dasein.cloud.cloudstack.CSMethod.java
public String buildUrl(String command, Param... params) throws CloudException, InternalException { ProviderContext ctx = provider.getContext(); String apiShared = ""; String apiSecret = ""; try {//from w w w . ja v a 2 s .c om List<ContextRequirements.Field> fields = provider.getContextRequirements().getConfigurableValues(); for (ContextRequirements.Field f : fields) { if (f.type.equals(ContextRequirements.FieldType.KEYPAIR)) { byte[][] keyPair = (byte[][]) ctx.getConfigurationValue(f); apiShared = new String(keyPair[0], "utf-8"); apiSecret = new String(keyPair[1], "utf-8"); } } } catch (UnsupportedEncodingException ignore) { } if (ctx == null) { throw new CloudException("No context was set for this request"); } try { StringBuilder str = new StringBuilder(); String apiKey = apiShared; String accessKey = apiSecret; StringBuilder newKey = new StringBuilder(); for (int i = 0; i < apiKey.length(); i++) { char c = apiKey.charAt(i); if (c != '\r') { newKey.append(c); } } apiKey = newKey.toString(); newKey = new StringBuilder(); for (int i = 0; i < accessKey.length(); i++) { char c = accessKey.charAt(i); if (c != '\r') { newKey.append(c); } } accessKey = newKey.toString(); str.append(ctx.getCloud().getEndpoint()); // Make sure the url ends up exactly as http://x.x.x.x:y/client/api?command= // otherwise the server may choke like we've found it does for uploadSslCert command. while (str.lastIndexOf("/") == str.length() - 1) { str.deleteCharAt(str.length() - 1); } if (!str.toString().endsWith("/api")) { str.append("/api"); } str.append("?command="); str.append(command); for (Param param : params) { str.append("&"); str.append(param.getKey()); if (param.getValue() != null) { str.append("="); str.append(URLEncoder.encode(param.getValue(), "UTF-8").replaceAll("\\+", "%20")); } } str.append("&apiKey="); str.append(URLEncoder.encode(apiKey, "UTF-8").replaceAll("\\+", "%20")); str.append("&signature="); try { str.append(URLEncoder.encode(getSignature(command, apiKey, accessKey, params), "UTF-8") .replaceAll("\\+", "%20")); } catch (SignatureException e) { throw new InternalException(e); } return str.toString(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new RuntimeException("This cannot happen: " + e.getMessage()); } }
From source file:tr.edu.gsu.nerwip.retrieval.reader.wikipedia.WikipediaReader.java
/** * Retrieve the text located in /*from w w w . ja v a 2s .c o m*/ * a quote (BLOCKQUOTE) HTML element. * * @param element * Element to be processed. * @param rawStr * Current raw text string. * @param linkedStr * Current text with hyperlinks. * @return * {@code true} iff the element was processed. */ private boolean processQuoteElement(Element element, StringBuilder rawStr, StringBuilder linkedStr) { boolean result = true; // possibly modify the previous characters if (rawStr.length() > 0 && rawStr.charAt(rawStr.length() - 1) == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // insert quotes rawStr.append(" \""); linkedStr.append(" \""); // recursive processing int rawIdx = rawStr.length(); int linkedIdx = linkedStr.length(); processTextElement(element, rawStr, linkedStr); // possibly remove characters added after quote marks while (rawStr.length() > rawIdx && (rawStr.charAt(rawIdx) == '\n' || rawStr.charAt(rawIdx) == ' ')) { rawStr.deleteCharAt(rawIdx); linkedStr.deleteCharAt(linkedIdx); } // possibly modify the ending characters if (rawStr.length() > 0 && rawStr.charAt(rawStr.length() - 1) == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // insert quotes rawStr.append("\""); linkedStr.append("\""); return result; }
From source file:tr.edu.gsu.nerwip.retrieval.reader.wikipedia.WikipediaReader.java
/** * Retrieve the text located in /*w ww . j a v a 2s . c o m*/ * a list (UL or OL) HTML element. * * @param element * Element to be processed. * @param rawStr * Current raw text string. * @param linkedStr * Current text with hyperlinks. * @param ordered * Whether the list is numbered or not. */ private void processListElement(Element element, StringBuilder rawStr, StringBuilder linkedStr, boolean ordered) { // possibly remove the last new line character char c = rawStr.charAt(rawStr.length() - 1); if (c == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly remove preceeding space c = rawStr.charAt(rawStr.length() - 1); if (c == ' ') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly add a column c = rawStr.charAt(rawStr.length() - 1); if (c != '.' && c != ':' && c != ';') { rawStr.append(":"); linkedStr.append(":"); } // process each list element int count = 1; for (Element listElt : element.getElementsByTag(XmlNames.ELT_LI)) { // add leading space rawStr.append(" "); linkedStr.append(" "); // possibly add number if (ordered) { rawStr.append(count + ") "); linkedStr.append(count + ") "); } count++; // get text and links processTextElement(listElt, rawStr, linkedStr); // possibly remove the last new line character c = rawStr.charAt(rawStr.length() - 1); if (c == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // add final separator rawStr.append(";"); linkedStr.append(";"); } // possibly remove last separator c = rawStr.charAt(rawStr.length() - 1); if (c == ';') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); c = rawStr.charAt(rawStr.length() - 1); if (c != '.') { rawStr.append("."); linkedStr.append("."); } rawStr.append("\n"); linkedStr.append("\n"); } }
From source file:net.firejack.platform.generate.tools.Render.java
/** * @param method/* ww w. j a va 2 s. c om*/ * @return */ public String renderMethod(Method method) { StringBuilder builder = new StringBuilder(); MethodType type = method.getType(); StringBuilder searchableFields = new StringBuilder(); if (method.getReturnType() != null) { Model model = (Model) method.getReturnType().getDomain(); List<Field> fields = new ArrayList<Field>(); searchFields(model, fields); if (type == MethodType.search || type == MethodType.searchCount || type == MethodType.searchWithFilter || type == MethodType.searchCountWithFilter) { for (Field field : fields) if (field.isSearchable()) searchableFields.append("\"").append(field.getName()).append("\","); if (searchableFields.length() != 0) searchableFields.deleteCharAt(searchableFields.length() - 1); } builder.append("return "); } if (type == MethodType.create) { builder.append("super.saveOrUpdate(").append(method.getParams().first().getName()).append(")"); } else if (type == MethodType.update) { builder.append("super.saveOrUpdate(").append(method.getParams().first().getName()).append(")"); } else if (type == MethodType.delete) { builder.append("super.deleteById(").append(method.getParams().first().getName()).append(")"); } else if (type == MethodType.read) { builder.append("super.findById(").append(method.getParams().first().getName()).append(")"); } else if (type == MethodType.readAll) { builder.append("super.search(null, paging)"); } else if (type == MethodType.readAllWithFilter) { builder.append("super.findWithFilter(null, null, idsFilter, paging)"); } else if (type == MethodType.search) { builder.append("super.simpleSearch(term, Arrays.<String>asList(").append(searchableFields) .append("), paging, null)"); } else if (type == MethodType.searchCount) { builder.append("super.simpleSearchCount(term, Arrays.<String>asList(").append(searchableFields) .append("), null)"); } else if (type == MethodType.searchWithFilter) { builder.append("super.simpleSearch(term, Arrays.<String>asList(").append(searchableFields) .append("), paging, idsFilter)"); } else if (type == MethodType.searchCountWithFilter) { builder.append("super.simpleSearchCount(term, Arrays.<String>asList(").append(searchableFields) .append("), idsFilter)"); } else if (type == MethodType.advancedSearch) { builder.append("super.advancedSearch(queryParameters, paging)"); } else if (type == MethodType.advancedSearchCount) { builder.append("super.advancedSearchCount(queryParameters)"); } else if (type == MethodType.advancedSearchWithIdsFilter) { builder.append("super.advancedSearchWithIdsFilter(queryParameters, paging, idsFilter)"); } else if (type == MethodType.advancedSearchCountWithIdsFilter) { builder.append("super.advancedSearchCountWithIdsFilter(queryParameters, idsFilter)"); } return builder.toString().trim(); }
From source file:com.aquatest.dbinterface.tools.DatabaseUpdater.java
/** * Generates a SQL query to UPDATE existing data in the database. * /*w ww . j a v a 2 s . co m*/ * @param table * database table to build the SQL query on * @param fieldNames * names of the columns needed in this query * @return prepared sql statement for the fields in the table * @throws JSONException * if fieldNames contains an object that is not a String */ private SQLiteStatement generateUpdateQueryString(String table, JSONArray fieldNames) throws JSONException { StringBuilder sql = new StringBuilder(); // initialise the query with the table // TODO escape the table name sql.append("UPDATE ").append(table).append(" SET"); // do this to optimise the Android code int fieldCount = fieldNames.length(); // add items to sql by iterating over the array for (int i = 0; i < fieldCount; i++) { String fieldName = fieldNames.getString(i); // exclude some columns from the update if (includeFieldInUpdates(fieldName)) { // add the field name to sql sql.append(" "); // id field must be renamed _id if ("id".equals(fieldName)) { sql.append("_"); } sql.append(fieldName).append(" = ?,"); } } // remove trailing comma sql.deleteCharAt(sql.length() - 1); // close off the query sql.append(" WHERE (_id = ?)"); // Log.v("SQL", "prepared sql statement: [" + sql.toString() + "]"); // return the prepared query return dA.database.compileStatement(sql.toString()); }
From source file:tr.edu.gsu.nerwip.retrieval.reader.wikipedia.WikipediaReader.java
/** * Retrieve the text located in /*from www.j a va 2s . c om*/ * a description list (DL) HTML element. * * @param element * Element to be processed. * @param rawStr * Current raw text string. * @param linkedStr * Current text with hyperlinks. */ private void processDescriptionListElement(Element element, StringBuilder rawStr, StringBuilder linkedStr) { // possibly remove the last new line character char c = rawStr.charAt(rawStr.length() - 1); if (c == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly remove preceeding space c = rawStr.charAt(rawStr.length() - 1); if (c == ' ') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly add a column c = rawStr.charAt(rawStr.length() - 1); if (c != '.' && c != ':' && c != ';') { rawStr.append(":"); linkedStr.append(":"); } // process each list element Elements elements = element.children(); Iterator<Element> it = elements.iterator(); Element tempElt = null; if (it.hasNext()) tempElt = it.next(); while (tempElt != null) { // add leading space rawStr.append(" "); linkedStr.append(" "); // get term String tempName = tempElt.tagName(); if (tempName.equals(XmlNames.ELT_DT)) { // process term processTextElement(tempElt, rawStr, linkedStr); // possibly remove the last new line character c = rawStr.charAt(rawStr.length() - 1); if (c == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly remove preceeding space c = rawStr.charAt(rawStr.length() - 1); if (c == ' ') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly add a column and space c = rawStr.charAt(rawStr.length() - 1); if (c != '.' && c != ':' && c != ';') { rawStr.append(": "); linkedStr.append(": "); } // go to next element if (it.hasNext()) tempElt = it.next(); else tempElt = null; } // get definition // if(tempName.equals(XmlNames.ELT_DD)) if (tempElt != null) { // process term processTextElement(tempElt, rawStr, linkedStr); // possibly remove the last new line character c = rawStr.charAt(rawStr.length() - 1); if (c == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly remove preceeding space c = rawStr.charAt(rawStr.length() - 1); if (c == ' ') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly add a semi-column c = rawStr.charAt(rawStr.length() - 1); if (c != '.' && c != ':' && c != ';') { rawStr.append(";"); linkedStr.append(";"); } // go to next element if (it.hasNext()) tempElt = it.next(); else tempElt = null; } } // possibly remove last separator c = rawStr.charAt(rawStr.length() - 1); if (c == ';') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); c = rawStr.charAt(rawStr.length() - 1); if (c != '.') { rawStr.append("."); linkedStr.append("."); } rawStr.append("\n"); linkedStr.append("\n"); } }