List of usage examples for org.apache.commons.lang3 StringUtils abbreviate
public static String abbreviate(final String str, final int maxWidth)
Abbreviates a String using ellipses.
From source file:org.languagetool.server.LanguageToolHttpHandler.java
private void logError(String remoteAddress, Exception e, int errorCode, HttpExchange httpExchange, Map<String, String> params, boolean textLoggingAllowed, boolean logStacktrace, long runtimeMillis) { String message = "An error has occurred: '" + e.getMessage() + "', sending HTTP code " + errorCode + ". "; message += "Access from " + remoteAddress + ", "; message += "HTTP user agent: " + getHttpUserAgent(httpExchange) + ", "; message += "User agent param: " + params.get("useragent") + ", "; if (params.get("v") != null) { message += "v: " + params.get("v") + ", "; }//w w w.j a va 2 s . co m message += "Referrer: " + getHttpReferrer(httpExchange) + ", "; message += "language: " + params.get("language") + ", "; message += "h: " + reqCounter.getHandleCount() + ", "; message += "r: " + reqCounter.getRequestCount() + ", "; if (params.get("username") != null) { message += "user: " + params.get("username") + ", "; } if (params.get("apiKey") != null) { message += "apiKey: " + params.get("apiKey") + ", "; } message += "time: " + runtimeMillis + ", "; String text = params.get("text"); if (text != null) { message += "text length: " + text.length() + ", "; } message += "m: " + ServerTools.getMode(params) + ", "; if (params.containsKey("instanceId")) { message += "iID: " + params.get("instanceId") + ", "; } if (logStacktrace) { message += "Stacktrace follows:"; message += ExceptionUtils.getStackTrace(e); print(message, System.err); } else { message += "(no stacktrace logged)"; print(message, System.err); } if (!(e instanceof TextTooLongException || e instanceof TooManyRequestsException || ExceptionUtils.getRootCause(e) instanceof ErrorRateTooHighException || e.getCause() instanceof TimeoutException)) { if (config.isVerbose() && text != null && textLoggingAllowed) { print("Exception was caused by this text (" + text.length() + " chars, showing up to 500):\n" + StringUtils.abbreviate(text, 500), System.err); logToDatabase(params, message + StringUtils.abbreviate(text, 500)); } else { logToDatabase(params, message); } } }
From source file:org.lockss.config.BaseConfigFile.java
protected void filterConfig(Configuration config) throws IOException { if (keyPred != null) { List<String> delKeys = null; for (String key : config.keySet()) { if (!keyPred.evaluate(key)) { String msg = "Illegal config key: " + key + " = " + StringUtils.abbreviate(config.get(key), 50) + " in " + m_fileUrl; if (keyPred.failOnIllegalKey()) { log.error(msg);/*from w w w .j a va 2s . com*/ throw new IOException(msg); } else { log.warning(msg); if (delKeys == null) { delKeys = new ArrayList<String>(); } delKeys.add(key); } } } if (delKeys != null) { for (String key : delKeys) { config.remove(key); } } } }
From source file:org.lockss.config.ConfigManager.java
private void logConfig(Configuration config, Configuration oldConfig, Configuration.Differences diffs) { int maxLogValLen = config.getInt(PARAM_MAX_LOG_VAL_LEN, DEFAULT_MAX_LOG_VAL_LEN); Set<String> diffSet = diffs.getDifferenceSet(); SortedSet<String> keys = new TreeSet<String>(diffSet); int elided = 0; int numDiffs = keys.size(); // keys includes param name prefixes that aren't actual params, so // numDiffs is inflated by several. for (String key : keys) { if (numDiffs <= 40 || log.isDebug3() || shouldParamBeLogged(key)) { if (config.containsKey(key)) { String val = config.get(key); log.debug(" " + key + " = " + StringUtils.abbreviate(val, maxLogValLen)); } else if (oldConfig.containsKey(key)) { log.debug(" " + key + " (removed)"); }//ww w . j a v a 2 s. c o m } else { elided++; } } if (elided > 0) log.debug(elided + " keys elided"); log.debug("New TdbAus: " + diffs.getTdbAuDifferenceCount()); if (log.isDebug3()) { log.debug3("TdbDiffs: " + diffs.getTdbDifferences()); } if (log.isDebug2()) { Tdb tdb = config.getTdb(); if (tdb != null) { log.debug2(StringPool.AU_CONFIG_PROPS.toStats()); Histogram hist1 = new Histogram(15); Histogram hist2 = new Histogram(15); Histogram hist3 = new Histogram(15); for (TdbAu.Id id : tdb.getAllTdbAuIds()) { TdbAu tau = id.getTdbAu(); hist1.addDataPoint(tau.getParams().size()); hist2.addDataPoint(tau.getAttrs().size()); hist3.addDataPoint(tau.getProperties().size()); } logHist("Tdb Params", hist1); logHist("Tdb Attrs", hist2); logHist("Tdb Props", hist3); } } }
From source file:org.lockss.devtools.plugindef.EditableDefinablePlugin.java
public void setPluginNotes(String notes) { if (notes != null) { logger.info("Setting the plugin notes to: " + (logger.isDebug() ? notes : StringUtils.abbreviate(notes, 50))); } else {// www . j a v a 2 s . c o m logger.warning("Setting plugin notes to null"); } definitionMap.putString(DefinablePlugin.KEY_PLUGIN_NOTES, notes); }
From source file:org.lockss.devtools.plugindef.EditableDefinablePlugin.java
public String getPluginNotes() { String ret = super.getPluginNotes(); if (ret != null) { logger.info("The plugin notes are: " + (logger.isDebug() ? ret : StringUtils.abbreviate(ret, 50))); } else {/*from w w w .j av a 2 s .c om*/ logger.info("The plugin notes are null"); } return ret; }
From source file:org.lockss.devtools.plugindef.EDPInspectorTableModel.java
static boolean handleDynamicallyLoadedComponentException(Component parentComponent, DynamicallyLoadedComponentException dlce) { Throwable cause = dlce.getCause(); if (cause != null) { String errorMessage;//from w w w . j a va 2 s . c o m if (cause instanceof ClassCastException) { errorMessage = "The class you have specified does not seem to be of the right type."; } else if (cause instanceof ClassNotFoundException) { errorMessage = "The class you have specified does not seem to be loadable under the current class path."; } else if (cause instanceof InstantiationException) { errorMessage = "The class you have specified seems to have caused an instantiation error."; } else if (cause instanceof IllegalAccessException) { errorMessage = "The class you have specified does not seem to have a public constructor."; } else { throw dlce; // rethrow } String[] messages = new String[] { errorMessage, "The internal error was of type " + cause.getClass().getName() + " with the following message:", " ", "\"" + StringUtils.abbreviate(dlce.getMessage(), 80) + "\"", " ", "Do you want to commit this value to the plugin anyway?", }; int sel = JOptionPane.showConfirmDialog(parentComponent, messages, "Dynamically Loaded Component Exception", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); return sel == JOptionPane.YES_OPTION; } else { throw dlce; // rethrow } }
From source file:org.lol.reddit.views.PostListingHeader.java
public PostListingHeader(final Context context, final String titleText, final String subtitleText) { super(context); final float dpScale = context.getResources().getDisplayMetrics().density; setOrientation(LinearLayout.VERTICAL); final int sidesPadding = (int) (15.0f * dpScale); final int topPadding = (int) (10.0f * dpScale); setPadding(sidesPadding, topPadding, sidesPadding, topPadding); final Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Light.ttf"); final TextView title = new TextView(context); title.setText(StringUtils.abbreviate(titleText, 33)); title.setTextSize(22.0f);/*from w w w . j a va2s .c om*/ title.setTypeface(tf); title.setTextColor(Color.WHITE); addView(title); final TextView subtitle = new TextView(context); subtitle.setTextSize(14.0f); subtitle.setText(StringUtils.abbreviate(subtitleText, 50)); subtitle.setTextColor(Color.rgb(200, 200, 200)); addView(subtitle); setBackgroundColor(Color.rgb(50, 50, 50)); // TODO theme color }
From source file:org.metaservice.core.maven.MavenIndexCrawler.java
public void searchGroupedAndDump(Indexer nexusIndexer, String descr, Query q, Grouping g) throws IOException { System.out.println("Searching for " + descr); GroupedSearchResponse response = nexusIndexer.searchGrouped(new GroupedSearchRequest(q, g, centralContext)); for (Map.Entry<String, ArtifactInfoGroup> entry : response.getResults().entrySet()) { ArtifactInfo ai = entry.getValue().getArtifactInfos().iterator().next(); System.out.println("* Plugin " + ai.artifactId); System.out.println(" Latest version: " + ai.version); System.out.println(StringUtils.isBlank(ai.description) ? "No description in plugin's POM." : StringUtils.abbreviate(ai.description, 60)); System.out.println();//from ww w . ja v a 2 s . co m } System.out.println("------"); System.out.println("Total record hits: " + response.getTotalHitsCount()); System.out.println(); }
From source file:org.onexus.collection.store.sql.adapters.StringAdapter.java
@Override public void append(StringBuilder container, Object object) throws Exception { String value = (String) object; if (value.length() > 128) { value = StringUtils.abbreviate(value, 128); log.info("Value '" + object + "' abbreviated."); }/*from w w w. j a v a 2 s . c o m*/ container.append(sqlUtils.quoteString(value)); }
From source file:org.onexus.ui.workspace.internal.wizards.data.CreateCollectionWizard.java
@Override public void onFinish() { super.onFinish(); // Create collection Collection collection = newCollection(); // Collect fields from other collections in the same folder Map<String, Field> otherFields = collectFields(); List<Field> fields = new ArrayList<Field>(); for (String header : headers) { String shortName, title;//from w w w . j a va2s.c om if (otherFields.containsKey(header)) { Field field = otherFields.get(header); shortName = field.getLabel(); title = field.getTitle(); } else { String lower = StringUtils.lowerCase(header); shortName = StringUtils.abbreviate(lower, 20); title = StringUtils.capitalize(lower); } Field field = new Field(header, shortName, title, deduceClass(sampleData.get(header))); if (header.toLowerCase().contains("pvalue") || header.toLowerCase().contains("qvalue")) { field.setProperties(Arrays.asList(new Property[] { new Property("BROWSER_DECORATOR", "PVALUE2") })); } if (primaryKeys.contains(header)) { field.setPrimaryKey(Boolean.TRUE); } fields.add(field); } collection.setFields(fields); // Deduce links from other collections in the same folder Map<String, Link> otherLinks = collectLinks(); List<Link> links = new ArrayList<Link>(); List<Collection> allProjectCollections = new ArrayList<Collection>(); addAllCollections(allProjectCollections, resourceManager.getProject(sourceURI.getProjectUrl()).getORI()); for (String header : headers) { if (otherLinks.containsKey(header)) { Link otherLink = otherLinks.get(header); Link link = new Link(); link.setCollection(otherLink.getCollection()); link.getFields().add(otherLink.getFields().get(0)); links.add(link); } else { for (Collection col : allProjectCollections) { Field field = col.getField(header); if (field != null && (header.toLowerCase().endsWith("id") || header.toLowerCase().endsWith("key"))) { // Only link to collections without any link if (col.getLinks() == null || col.getLinks().isEmpty()) { Link link = new Link(); link.setCollection(new ORI((String) null, col.getORI().getPath())); link.getFields().add(header); links.add(link); } } } } } collection.setLinks(links); Loader loader = new Loader(); loader.setPlugin("tsv-loader"); List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("data", sourceURI.getPath())); if (nullEmpty > nullDash && nullEmpty > nullString && nullEmpty > nullNA) { parameters.add(new Parameter("NULL_VALUE", "")); } if (nullString > nullDash && nullString > nullEmpty && nullString > nullNA) { parameters.add(new Parameter("NULL_VALUE", "NULL")); } if (nullNA > nullDash && nullNA > nullString && nullNA > nullEmpty) { parameters.add(new Parameter("NULL_VALUE", "NA")); } loader.setParameters(parameters); collection.setLoader(loader); resourceManager.save(collection); PageParameters params = new PageParameters().add(ResourcesPage.PARAMETER_RESOURCE, collection.getORI()); setResponsePage(ResourcesPage.class, params); }