List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:ch.cyberduck.core.threading.BackgroundException.java
/** * @return Detailed message from the underlying cause. *///from w w w . j ava 2 s . c om public String getDetailedCauseMessage() { final Throwable cause = this.getCause(); StringBuilder buffer = new StringBuilder(); if (null != cause) { if (StringUtils.isNotBlank(cause.getMessage())) { String m = StringUtils.chomp(cause.getMessage()); buffer.append(m); if (!m.endsWith(".")) { buffer.append("."); } } if (cause instanceof ServiceException) { final ServiceException s3 = (ServiceException) cause; if (StringUtils.isNotBlank(s3.getResponseStatus())) { // HTTP method status buffer.append(" ").append(s3.getResponseStatus()).append("."); } if (StringUtils.isNotBlank(s3.getErrorMessage())) { // S3 protocol message buffer.append(" ").append(s3.getErrorMessage()); } } else if (cause instanceof SardineException) { final SardineException http = (SardineException) cause; if (StringUtils.isNotBlank(http.getResponsePhrase())) { buffer.delete(0, buffer.length()); // HTTP method status buffer.append(http.getResponsePhrase()).append("."); } } else if (cause instanceof org.jets3t.service.impl.rest.HttpException) { final org.jets3t.service.impl.rest.HttpException http = (org.jets3t.service.impl.rest.HttpException) cause; buffer.append(" ").append(http.getResponseCode()); if (StringUtils.isNotBlank(http.getResponseMessage())) { buffer.append(" ").append(http.getResponseMessage()); } } else if (cause instanceof CloudFrontServiceException) { final CloudFrontServiceException cf = (CloudFrontServiceException) cause; if (StringUtils.isNotBlank(cf.getErrorMessage())) { buffer.append(" ").append(cf.getErrorMessage()); } if (StringUtils.isNotBlank(cf.getErrorDetail())) { buffer.append(" ").append(cf.getErrorDetail()); } } else if (cause instanceof FilesException) { final FilesException cf = (FilesException) cause; final StatusLine status = cf.getHttpStatusLine(); if (null != status) { if (StringUtils.isNotBlank(status.getReasonPhrase())) { buffer.append(" ").append(status.getReasonPhrase()); } } } else if (cause instanceof AmazonServiceException) { final AmazonServiceException a = (AmazonServiceException) cause; final String status = a.getErrorCode(); if (StringUtils.isNotBlank(status)) { buffer.append(" ").append(status); } } } String message = buffer.toString(); if (!StringUtils.isEmpty(message)) { if (Character.isLetter(message.charAt(message.length() - 1))) { message = message + "."; } } return Locale.localizedString(message, "Error"); }
From source file:org.apache.syncope.core.persistence.jpa.dao.AbstractAnyDAO.java
/** * Generate one where clause for each different attribute schema into the derived schema expression provided. * * @param expression derived schema expression * @param value derived attribute value//from w w w . j a v a 2 s .c o m * @param attrUtils USER / GROUP * @return where clauses to use to build the query */ private Set<String> getWhereClause(final String expression, final String value) { Parser parser = new Parser(new StringReader(expression)); // Schema names List<String> identifiers = new ArrayList<>(); // Literals List<String> literals = new ArrayList<>(); // Get schema names and literals for (Token token = parser.getNextToken(); token != null && StringUtils.isNotBlank(token.toString()); token = parser.getNextToken()) { if (token.kind == ParserConstants.STRING_LITERAL) { literals.add(token.toString().substring(1, token.toString().length() - 1)); } if (token.kind == ParserConstants.IDENTIFIER) { identifiers.add(token.toString()); } } // Sort literals in order to process later literals included into others Collections.sort(literals, (final String t, final String t1) -> { if (t == null && t1 == null) { return 0; } else if (t != null && t1 == null) { return -1; } else if (t == null && t1 != null) { return 1; } else if (t.length() == t1.length()) { return 0; } else if (t.length() > t1.length()) { return -1; } else { return 1; } }); // Split value on provided literals List<String> attrValues = split(value, literals); if (attrValues.size() != identifiers.size()) { LOG.error("Ambiguous JEXL expression resolution."); throw new IllegalArgumentException("literals and values have different size"); } // clauses to be used with INTERSECTed queries Set<String> clauses = new HashSet<>(); // builder to build the clauses StringBuilder bld = new StringBuilder(); // Contains used identifiers in order to avoid replications Set<String> used = new HashSet<>(); // Create several clauses: one for eanch identifiers for (int i = 0; i < identifiers.size(); i++) { if (!used.contains(identifiers.get(i))) { // verify schema existence and get schema type PlainSchema schema = plainSchemaDAO().find(identifiers.get(i)); if (schema == null) { LOG.error("Invalid schema id '{}'", identifiers.get(i)); throw new IllegalArgumentException("Invalid schema id " + identifiers.get(i)); } // clear builder bld.delete(0, bld.length()); bld.append("("); // set schema name bld.append("s.id = '").append(identifiers.get(i)).append("'"); bld.append(" AND "); bld.append("s.id = a.schema_id").append(" AND "); bld.append("a.id = v.attribute_id"); bld.append(" AND "); // use a value clause different for eanch different schema type switch (schema.getType()) { case Boolean: bld.append("v.booleanValue = '").append(attrValues.get(i)).append("'"); break; case Long: bld.append("v.longValue = ").append(attrValues.get(i)); break; case Double: bld.append("v.doubleValue = ").append(attrValues.get(i)); break; case Date: bld.append("v.dateValue = '").append(attrValues.get(i)).append("'"); break; default: bld.append("v.stringValue = '").append(attrValues.get(i)).append("'"); } bld.append(")"); used.add(identifiers.get(i)); clauses.add(bld.toString()); } } LOG.debug("Generated where clauses {}", clauses); return clauses; }
From source file:ch.elexis.data.Query.java
/** * Sortierung angeben. Dies muss als letzter Befehl nach einer Reihe von add() Sequenzen * erfolgen.//from w w w . ja v a 2 s.c o m * * @param reverse * true bei umgekehrter Sortierung * @param n1 * Beliebig viele Strings, die in absteigender Prioritt die Felder angeben, nach * denen sortiert werden soll. */ public void orderBy(final boolean reverse, final String... n1) { if (n1 != null && n1.length > 0) { StringBuilder sb = new StringBuilder(); sb.append(" ORDER BY "); for (String s : n1) { String mapped = template.map(s); if (mapped.matches("[A-Z]{2,}:.+")) { log.error("Ungltiges Feld " + s); return; } if (mapped.startsWith("S:D:") || mapped.startsWith("S:N:")) { mapped = mapped.substring(4); } sb.append(mapped); if (reverse == true) { sb.append(" DESC"); } sb.append(","); } sb.delete(sb.length() - 1, 10000); ordering = sb.toString(); } }
From source file:de.axelfaust.alfresco.nashorn.repo.loaders.AlfrescoClasspathURLStreamHandler.java
protected List<String> getOrCreatePrecedenceChain(final String script, final boolean allowExtension) { final Pair<String, Boolean> key = new Pair<String, Boolean>(script, Boolean.valueOf(allowExtension)); List<String> precendenceChain = this.precedenceChainByScript.get(key); if (precendenceChain == null) { precendenceChain = new ArrayList<String>(); this.precedenceChainByScript.put(key, precendenceChain); if (script.endsWith(".js") || script.endsWith(".nashornjs")) { precendenceChain.add(script); } else {// w w w . j a v a2s . co m final StringBuilder pathBuilder = new StringBuilder(script); final int basePathLength = this.basePath != null ? this.basePath.trim().length() : 0; final int extensionPathLength = allowExtension && this.extensionPath != null ? this.extensionPath.trim().length() : 0; for (final String suffix : SUFFIX_PRECEDENCE_LIST) { if (suffix != null) { pathBuilder.append(suffix); } if (extensionPathLength > 0) { if (basePathLength > 0) { pathBuilder.insert(basePathLength, '/'); pathBuilder.insert(basePathLength + 1, this.extensionPath); } else { pathBuilder.insert(0, this.extensionPath); pathBuilder.insert(extensionPathLength, '/'); } precendenceChain.add(pathBuilder.toString()); if (basePathLength > 0) { pathBuilder.delete(basePathLength, basePathLength + extensionPathLength + 1); } else { pathBuilder.delete(0, extensionPathLength + 1); } } precendenceChain.add(pathBuilder.toString()); if (suffix != null) { pathBuilder.delete(pathBuilder.length() - suffix.length(), pathBuilder.length()); } } } } return precendenceChain; }
From source file:org.apache.syncope.core.persistence.dao.impl.UserDAOImpl.java
/** * Generate one where clause for each different attribute schema into the derived schema expression provided. * * @param expression derived schema expression. * @param value derived attribute value. * @return where clauses to use to build the query. * @throws InvalidSearchConditionException in case of errors retrieving identifiers. *///from w w w. j a va 2s. c om private Set<String> getWhereClause(final String expression, final String value) throws InvalidSearchConditionException { final Parser parser = new Parser(new StringReader(expression)); // Schema names final List<String> identifiers = new ArrayList<String>(); // Literals final List<String> literals = new ArrayList<String>(); // Get schema names and literals Token token; while ((token = parser.getNextToken()) != null && StringUtils.hasText(token.toString())) { if (token.kind == ParserConstants.STRING_LITERAL) { literals.add(token.toString().substring(1, token.toString().length() - 1)); } if (token.kind == ParserConstants.IDENTIFIER) { identifiers.add(token.toString()); } } // Sort literals in order to process later literals included into others Collections.sort(literals, new Comparator<String>() { @Override public int compare(String t, String t1) { if (t == null && t1 == null) { return 0; } else if (t != null && t1 == null) { return -1; } else if (t == null && t1 != null) { return 1; } else if (t.length() == t1.length()) { return 0; } else if (t.length() > t1.length()) { return -1; } else { return 1; } } }); // Split value on provided literals final List<String> attrValues = split(value, literals); if (attrValues.size() != identifiers.size()) { LOG.error("Ambiguous jexl expression resolution."); throw new InvalidSearchConditionException("literals and values have different size"); } // clauses to be used with INTERSECTed queries final Set<String> clauses = new HashSet<String>(); // builder to build the clauses final StringBuilder bld = new StringBuilder(); // Contains used identifiers in order to avoid replications final Set<String> used = new HashSet<String>(); USchema schema; // Create several clauses: one for eanch identifiers for (int i = 0; i < identifiers.size(); i++) { if (!used.contains(identifiers.get(i))) { // verify schema existence and get schema type schema = schemaDAO.find(identifiers.get(i), USchema.class); if (schema == null) { LOG.error("Invalid schema name '{}'", identifiers.get(i)); throw new InvalidSearchConditionException("Invalid schema name " + identifiers.get(i)); } // clear builder bld.delete(0, bld.length()); bld.append("("); // set schema name bld.append("s.name = '").append(identifiers.get(i)).append("'"); bld.append(" AND "); bld.append("s.name = a.schema_name").append(" AND "); bld.append("a.id = v.attribute_id"); bld.append(" AND "); // use a value clause different for eanch different schema type switch (schema.getType()) { case Boolean: bld.append("v.booleanValue = '").append(attrValues.get(i)).append("'"); break; case Long: bld.append("v.longValue = ").append(attrValues.get(i)); break; case Double: bld.append("v.doubleValue = ").append(attrValues.get(i)); break; case Date: bld.append("v.dateValue = '").append(attrValues.get(i)).append("'"); break; default: bld.append("v.stringValue = '").append(attrValues.get(i)).append("'"); } bld.append(")"); used.add(identifiers.get(i)); clauses.add(bld.toString()); } } LOG.debug("Generated where clauses {}", clauses); return clauses; }
From source file:br.com.carlosrafaelgn.fplay.list.RadioStationList.java
private boolean parseIcecastColumn1(XmlPullParser parser, String[] fields, StringBuilder sb) throws Throwable { int ev = 0, pCount = 0; boolean hasFields = false, hasNextToken = false, parsingTags = false; String str;/*from w w w. j av a 2 s. c o m*/ while (hasNextToken || ((ev = parser.nextToken()) != XmlPullParser.END_DOCUMENT)) { hasNextToken = false; if (ev == XmlPullParser.END_TAG && parser.getName().equals("td")) break; if (ev == XmlPullParser.START_TAG && parser.getName().equals("p")) { pCount++; } else if (ev == XmlPullParser.START_TAG && parser.getName().equals("ul")) { parsingTags = true; sb.delete(0, sb.length()); } else if (parsingTags) { if (ev == XmlPullParser.START_TAG && parser.getName().equals("a")) { if (parser.nextToken() == XmlPullParser.TEXT) { if (sb.length() > 0) { sb.append(' '); } else { sb.append(tags); sb.append(": "); } sb.append(parser.getText()); } else { hasNextToken = true; ev = parser.getEventType(); } } else if (ev == XmlPullParser.END_TAG && parser.getName().equals("ul")) { hasFields = true; fields[6] = sb.toString().trim(); } } else { switch (pCount) { case 1: if (ev == XmlPullParser.START_TAG) { if (parser.getName().equals("a")) { for (int a = parser.getAttributeCount() - 1; a >= 0; a--) { if (parser.getAttributeName(a).equals("href")) { fields[1] = parser.getAttributeValue(a).trim(); //set hasFields to true, only if the title has been found! //hasFields = true; break; } } parser.nextToken(); if ((str = readStringIfPossible(parser, sb)) != null) { hasFields = true; fields[0] = str.trim(); } hasNextToken = true; ev = parser.getEventType(); } else if (fields[0].length() != 0 && parser.getName().equals("span")) { if (parser.nextToken() == XmlPullParser.TEXT) { fields[3] = parser.getText().trim(); if (fields[3].length() > 0) fields[3] = fields[3].substring(1).trim(); } else { hasNextToken = true; ev = parser.getEventType(); } } } break; case 2: if (fields[4].length() == 0 && (str = readStringIfPossible(parser, sb)) != null) { hasFields = true; fields[4] = str.trim(); hasNextToken = true; ev = parser.getEventType(); } else { hasNextToken = false; } break; case 3: if (ev == XmlPullParser.END_TAG && parser.getName().equals("strong")) { if (fields[5].length() == 0) { parser.nextToken(); if ((str = readStringIfPossible(parser, sb)) != null) { hasFields = true; fields[5] = str.trim(); } hasNextToken = true; ev = parser.getEventType(); } } break; } } } return hasFields; }
From source file:com.github.mavenplugins.doctest.ReportMojo.java
/** * Renders the request cell in the table */// w ww. j a va 2 s.com protected void renderRequestCell(Sink sink, RequestResultWrapper wrapper, AtomicInteger counter, String details) { StringBuilder builder = new StringBuilder(); String preview; int id = counter.incrementAndGet(); builder.append(wrapper.getRequestLine()); builder.append("<br/>"); builder.append("<a href=\"javascript:\" onclick=\"toggleVisibility('request-detail-"); builder.append(id); builder.append("');toggleVisibility('request-detail-"); builder.append(id); builder.append("-preview');\">"); builder.append(details); builder.append("</a><br/><div id=\"request-detail-"); builder.append(id); builder.append("-preview\" style=\"display: block;\">"); sink.rawText(builder.toString()); builder.delete(0, builder.length()); preview = wrapper.getEntity(); if (!StringUtils.isEmpty(wrapper.getEntity()) && wrapper.getEntity().length() <= maxPreview) { preview = wrapper.getEntity(); } else if (!StringUtils.isEmpty(wrapper.getEntity())) { preview = wrapper.getEntity().substring(0, maxPreview) + "…"; } if (!StringUtils.isEmpty(wrapper.getEntity())) { sink.verbatim(SinkEventAttributeSet.BOXED); sink.rawText(preview); sink.verbatim_(); } builder.append("</div>"); builder.append("<div id=\"request-detail-"); builder.append(id); builder.append("\" style=\"display: none;\">"); sink.rawText(builder.toString()); builder.delete(0, builder.length()); if (wrapper.getHeader() != null && wrapper.getHeader().length > 0) { sink.verbatim(SinkEventAttributeSet.BOXED); for (String header : wrapper.getHeader()) { sink.rawText(header); sink.rawText("<br/>"); } sink.verbatim_(); } if (wrapper.getParemeters() != null && wrapper.getParemeters().length > 0) { sink.verbatim(SinkEventAttributeSet.BOXED); for (String parameter : wrapper.getParemeters()) { sink.rawText(parameter); sink.rawText("<br/>"); } sink.verbatim_(); } if (!StringUtils.isEmpty(wrapper.getEntity())) { sink.verbatim(SinkEventAttributeSet.BOXED); sink.rawText(wrapper.getEntity()); sink.verbatim_(); } sink.rawText("</div>"); }
From source file:com.github.mavenplugins.doctest.ReportMojo.java
/** * Renders the response cell in the table. *///from w ww .j ava 2 s . c o m protected void renderResponseCell(Sink sink, ResponseResultWrapper wrapper, AtomicInteger counter, String details) { StringBuilder builder = new StringBuilder(); String preview; int id = counter.incrementAndGet(); builder.append(wrapper.getStatusLine()); builder.append("<br/>"); builder.append("<a href=\"javascript:\" onclick=\"toggleVisibility('response-detail-"); builder.append(id); builder.append("');toggleVisibility('response-detail-"); builder.append(id); builder.append("-preview');\">"); builder.append(details); builder.append("</a><br/><div id=\"response-detail-"); builder.append(id); builder.append("-preview\" style=\"display: block;\">"); sink.rawText(builder.toString()); builder.delete(0, builder.length()); preview = wrapper.getEntity(); if (!StringUtils.isEmpty(wrapper.getEntity()) && wrapper.getEntity().length() <= maxPreview) { preview = wrapper.getEntity(); } else if (!StringUtils.isEmpty(wrapper.getEntity())) { preview = wrapper.getEntity().substring(0, maxPreview) + "…"; } if (!StringUtils.isEmpty(wrapper.getEntity())) { sink.verbatim(SinkEventAttributeSet.BOXED); sink.rawText(preview); sink.verbatim_(); } builder.append("</div>"); builder.append("<div id=\"response-detail-"); builder.append(id); builder.append("\" style=\"display: none;\">"); sink.rawText(builder.toString()); builder.delete(0, builder.length()); if (wrapper.getHeader() != null && wrapper.getHeader().length > 0) { sink.verbatim(SinkEventAttributeSet.BOXED); for (String header : wrapper.getHeader()) { sink.rawText(header); sink.rawText("<br/>"); } sink.verbatim_(); } if (wrapper.getParemeters() != null && wrapper.getParemeters().length > 0) { sink.verbatim(SinkEventAttributeSet.BOXED); for (String parameter : wrapper.getParemeters()) { sink.rawText(parameter); sink.rawText("<br/>"); } sink.verbatim_(); } if (!StringUtils.isEmpty(wrapper.getEntity())) { sink.verbatim(SinkEventAttributeSet.BOXED); sink.rawText(wrapper.getEntity()); sink.verbatim_(); } sink.rawText("</div>"); }
From source file:org.syncope.core.persistence.dao.impl.UserDAOImpl.java
/** * Generate one where clause for each different attribute schema into the * derived schema expression provided./*from ww w .ja v a 2 s . com*/ * * @param expression derived schema expression. * @param value derived attribute value. * @return where clauses to use to build the query. * @throws InvalidSearchConditionException in case of errors retrieving * identifiers. */ private Set<String> getWhereClause(final String expression, final String value) throws InvalidSearchConditionException { final Parser parser = new Parser(new StringReader(expression)); // Schema names final List<String> identifiers = new ArrayList<String>(); // Literals final List<String> literals = new ArrayList<String>(); // Get schema names and literals Token token; while ((token = parser.getNextToken()) != null && StringUtils.hasText(token.toString())) { if (token.kind == ParserConstants.STRING_LITERAL) { literals.add(token.toString().substring(1, token.toString().length() - 1)); } if (token.kind == ParserConstants.IDENTIFIER) { identifiers.add(token.toString()); } } // Sort literals in order to process later literals included into others Collections.sort(literals, new Comparator<String>() { @Override public int compare(String t, String t1) { if (t == null && t1 == null) { return 0; } if (t != null && t1 == null) { return -1; } if (t == null && t1 != null) { return 1; } if (t.length() == t1.length()) { return 0; } if (t.length() > t1.length()) { return -1; } else { return 1; } } }); // Split value on provided literals final List<String> attrValues = split(value, literals); if (attrValues.size() != identifiers.size()) { LOG.error("Ambiguous jexl expression resolution."); throw new InvalidSearchConditionException("literals and values have different size"); } // clauses to be used with INTERSECTed queries final Set<String> clauses = new HashSet<String>(); // builder to build the clauses final StringBuilder bld = new StringBuilder(); // Contains used identifiers in order to avoid replications final Set<String> used = new HashSet<String>(); USchema schema; // Create several clauses: one for eanch identifiers for (int i = 0; i < identifiers.size(); i++) { if (!used.contains(identifiers.get(i))) { // verify schema existence and get schema type schema = schemaDAO.find(identifiers.get(i), USchema.class); if (schema == null) { LOG.error("Invalid schema name '{}'", identifiers.get(i)); throw new InvalidSearchConditionException("Invalid schema name " + identifiers.get(i)); } // clear builder bld.delete(0, bld.length()); bld.append("("); // set schema name bld.append("s.name = '").append(identifiers.get(i)).append("'"); bld.append(" AND "); bld.append("s.name = a.schema_name").append(" AND "); bld.append("a.id = v.attribute_id"); bld.append(" AND "); // use a value clause different for eanch different schema type switch (schema.getType()) { case Boolean: bld.append("v.booleanValue = '").append(attrValues.get(i)).append("'"); break; case Long: bld.append("v.longValue = ").append(attrValues.get(i)); break; case Double: bld.append("v.doubleValue = ").append(attrValues.get(i)); break; case Date: bld.append("v.dateValue = '").append(attrValues.get(i)).append("'"); break; default: bld.append("v.stringValue = '").append(attrValues.get(i)).append("'"); } bld.append(")"); used.add(identifiers.get(i)); clauses.add(bld.toString()); } } LOG.debug("Generated where clauses {}", clauses); return clauses; }