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.activiti.engine.impl.persistence.entity.VariableInstanceEntityImpl.java
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("VariableInstanceEntity["); sb.append("id=").append(id); sb.append(", name=").append(name); sb.append(", type=").append(type != null ? type.getTypeName() : "null"); if (longValue != null) { sb.append(", longValue=").append(longValue); }//from ww w . j ava2 s . co m if (doubleValue != null) { sb.append(", doubleValue=").append(doubleValue); } if (textValue != null) { sb.append(", textValue=").append(StringUtils.abbreviate(textValue, 40)); } if (textValue2 != null) { sb.append(", textValue2=").append(StringUtils.abbreviate(textValue2, 40)); } if (byteArrayRef != null && byteArrayRef.getId() != null) { sb.append(", byteArrayValueId=").append(byteArrayRef.getId()); } sb.append("]"); return sb.toString(); }
From source file:org.apache.james.jmap.model.MessagePreviewGenerator.java
@VisibleForTesting
String abbreviate(String body) {
return StringUtils.abbreviate(body, MAX_PREVIEW_LENGTH);
}
From source file:org.apache.nifi.processors.standard.LogAttribute.java
protected String processFlowFile(final ComponentLog logger, final DebugLevels logLevel, final FlowFile flowFile, final ProcessSession session, final ProcessContext context) { final Set<String> attributeKeys = getAttributesToLog(flowFile.getAttributes().keySet(), context); final ComponentLog LOG = getLogger(); final String dashedLine; String logPrefix = context.getProperty(LOG_PREFIX).evaluateAttributeExpressions(flowFile).getValue(); if (StringUtil.isBlank(logPrefix)) { dashedLine = StringUtils.repeat('-', 50); } else {//from w w w .j ava2 s. c o m // abbreviate long lines logPrefix = StringUtils.abbreviate(logPrefix, 40); // center the logPrefix and pad with dashes logPrefix = StringUtils.center(logPrefix, 40, '-'); // five dashes on the left and right side, plus the dashed logPrefix dashedLine = StringUtils.repeat('-', 5) + logPrefix + StringUtils.repeat('-', 5); } // Pretty print metadata final StringBuilder message = new StringBuilder(); message.append("logging for flow file ").append(flowFile); message.append("\n"); message.append(dashedLine); message.append("\nStandard FlowFile Attributes"); message.append( String.format("\nKey: '%1$s'\n\tValue: '%2$s'", "entryDate", new Date(flowFile.getEntryDate()))); message.append(String.format("\nKey: '%1$s'\n\tValue: '%2$s'", "lineageStartDate", new Date(flowFile.getLineageStartDate()))); message.append(String.format("\nKey: '%1$s'\n\tValue: '%2$s'", "fileSize", flowFile.getSize())); message.append("\nFlowFile Attribute Map Content"); for (final String key : attributeKeys) { message.append(String.format("\nKey: '%1$s'\n\tValue: '%2$s'", key, flowFile.getAttribute(key))); } message.append("\n"); message.append(dashedLine); // The user can request to log the payload final boolean logPayload = context.getProperty(LOG_PAYLOAD).asBoolean(); if (logPayload) { message.append("\n"); if (flowFile.getSize() < ONE_MB) { final FlowFilePayloadCallback callback = new FlowFilePayloadCallback(); session.read(flowFile, callback); message.append(callback.getContents()); } else { message.append("\n Not including payload since it is larger than one mb."); } } final String outputMessage = message.toString().trim(); // Uses optional property to specify logging level switch (logLevel) { case info: LOG.info(outputMessage); break; case debug: LOG.debug(outputMessage); break; case warn: LOG.warn(outputMessage); break; case trace: LOG.trace(outputMessage); break; case error: LOG.error(outputMessage); break; default: LOG.debug(outputMessage); } return outputMessage; }
From source file:org.apache.nifi.toolkit.cli.impl.result.writer.DynamicTableWriter.java
@Override public void write(final Table table, final PrintStream output) { if (table == null) { throw new IllegalArgumentException("Table cannot be null"); }//www . j a v a 2 s .c o m if (output == null) { throw new IllegalArgumentException("Output cannot be null"); } if (table.getColumns().isEmpty()) { throw new IllegalArgumentException("Table has no columns to write"); } output.println(); final List<TableColumn> columns = table.getColumns(); final List<String[]> rows = table.getRows(); final int numColumns = columns.size(); final Integer[] columnLengths = determineColumnLengths(columns, rows); final List<String> columnNames = columns.stream().map(c -> c.getName()).collect(Collectors.toList()); final Object[] columnLengthsObj = Arrays.copyOf(columnLengths, numColumns, Object[].class); final Object[] columnNamesObj = columnNames.toArray(new Object[numColumns]); final String columnsPatternFormat = String.join("", Collections.nCopies(numColumns, "%%-%ds ")); final String columnsPattern = String.format(columnsPatternFormat, columnLengthsObj); // format the header line which will include the column names final String header = String.format(columnsPattern, columnNamesObj); output.println(header); // a little clunky way to dynamically create a nice header line, but at least no external dependency final Object[] headerLineValues = new Object[numColumns]; for (int i = 0; i < numColumns; i++) { int length = columnLengths[i]; headerLineValues[i] = String.join("", Collections.nCopies(length, "-")); } final String headerLine = String.format(columnsPattern, headerLineValues); output.println(headerLine); // format the rows and print them for (String[] row : rows) { // convert the row to an Object[] for the String.format and also abbreviate any values final Object[] rowValues = new Object[row.length]; for (int i = 0; i < row.length; i++) { final TableColumn column = columns.get(i); if (column.isAbbreviated()) { rowValues[i] = StringUtils.abbreviate(row[i], columnLengths[i]); } else { rowValues[i] = row[i]; } } final String rowString = String.format(columnsPattern, rowValues); output.println(rowString); } output.println(); output.flush(); }
From source file:org.apache.syncope.client.console.panels.SAML2IdPsDirectoryPanel.java
public SAML2IdPsDirectoryPanel(final String id, final PageReference pageRef) { super(id, new Builder<SAML2IdPTO, SAML2IdPTO, SAML2IdPsRestClient>(new SAML2IdPsRestClient(), pageRef) { private static final long serialVersionUID = 8517982765290075155L; @Override/* w ww . java2 s. c o m*/ protected WizardMgtPanel<SAML2IdPTO> newInstance(final String id, final boolean wizardInModal) { throw new UnsupportedOperationException(); } }.disableCheckBoxes()); this.addNewItemPanelBuilder(new SAML2IdPWizardBuilder(this, new SAML2IdPTO(), pageRef), false); modal.addSubmitButton(); modal.size(Modal.Size.Large); modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = 8804221891699487139L; @Override public void onClose(final AjaxRequestTarget target) { updateResultTable(target); modal.show(false); } }); // need to override to change the menu header actionTogglePanel = new ActionLinksTogglePanel<SAML2IdPTO>("outer", pageRef) { private static final long serialVersionUID = -7688359318035249200L; @Override public void toggleWithContent(final AjaxRequestTarget target, final ActionsPanel<SAML2IdPTO> actionsPanel, final SAML2IdPTO modelObject) { super.toggleWithContent(target, actionsPanel, modelObject); setHeader(target, StringUtils.abbreviate(modelObject.getName(), 25)); this.toggle(target, true); } }; addOuterObject(actionTogglePanel); addOuterObject(metadataModal); setWindowClosedReloadCallback(metadataModal); metadataModal.size(Modal.Size.Large); templateModal = new BaseModal<Serializable>("outer") { private static final long serialVersionUID = 5787433530654262016L; @Override protected void onConfigure() { super.onConfigure(); setFooterVisible(false); } }; templateModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = 8804221891699487139L; @Override public void onClose(final AjaxRequestTarget target) { templateModal.show(false); } }); templateModal.size(Modal.Size.Large); addOuterObject(templateModal); initResultTable(); final ImportMetadata importMetadata = new ImportMetadata("importMetadata", container, pageRef); addInnerObject(importMetadata); AjaxLink<Void> importMetadataLink = new AjaxLink<Void>("add") { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target) { importMetadata.toggle(target, true); } }; ((WebMarkupContainer) get("container:content")).addOrReplace(importMetadataLink); }
From source file:org.apache.syncope.client.console.topology.TopologyTogglePanel.java
@Override public void onEvent(final IEvent<?> event) { super.onEvent(event); if (event.getPayload() instanceof AjaxWizard.NewItemFinishEvent) { final AjaxWizard.NewItemFinishEvent item = AjaxWizard.NewItemFinishEvent.class.cast(event.getPayload()); final Serializable result = item.getResult(); final AjaxRequestTarget target = item.getTarget(); if (result != null && result instanceof ConnInstanceTO) { // update Toggle Panel header ConnInstanceTO conn = ConnInstanceTO.class.cast(result); setHeader(target, StringUtils.abbreviate(conn.getDisplayName(), HEADER_FIRST_ABBREVIATION)); }// www. j a va 2 s. c om } }
From source file:org.apache.syncope.client.console.wicket.ajax.markup.html.LabelInfo.java
public LabelInfo(final String id, final String title) { super(id, StringUtils.EMPTY); this.title = title == null ? StringUtils.EMPTY : StringUtils.abbreviate(title, 30); }
From source file:org.apache.syncope.client.console.wicket.ajax.markup.html.LabelInfo.java
public LabelInfo(final String id, final Collection<String> title) { super(id, StringUtils.EMPTY); if (CollectionUtils.isEmpty(title)) { this.title = StringUtils.EMPTY; } else {//w w w . j ava2 s. c om StringBuilder titleBuilder = new StringBuilder(); for (String el : title) { if (titleBuilder.length() > 0) { titleBuilder.append("; "); } if (StringUtils.isNoneEmpty(el)) { titleBuilder.append(el); } } this.title = StringUtils.abbreviate(titleBuilder.toString(), 50); } }
From source file:org.apache.syncope.client.console.wicket.markup.html.form.ActionLinksTogglePanel.java
public void updateHeader(final AjaxRequestTarget target, final Serializable modelObject) { final String header; if (modelObject == null) { header = new ResourceModel("actions", StringUtils.EMPTY).getObject(); } else if (modelObject instanceof UserTO) { header = ((UserTO) modelObject).getUsername(); } else if (modelObject instanceof UserWrapper) { header = ((UserWrapper) modelObject).getInnerObject().getUsername(); } else if (modelObject instanceof GroupTO) { header = ((GroupTO) modelObject).getName(); } else if (modelObject instanceof GroupWrapper) { header = ((GroupWrapper) modelObject).getInnerObject().getName(); } else if (modelObject instanceof AnyObjectTO) { header = ((AnyObjectTO) modelObject).getName(); } else if (modelObject instanceof AnyWrapper && AnyWrapper.class.cast(modelObject).getInnerObject() instanceof AnyObjectTO) { header = ((AnyObjectTO) ((AnyWrapper) modelObject).getInnerObject()).getName(); } else if (modelObject instanceof ReportTO) { header = ((ReportTO) modelObject).getName(); } else if (modelObject instanceof AttrTO) { header = ((AttrTO) modelObject).getSchema(); } else if (modelObject instanceof AbstractPolicyTO) { header = ((AbstractPolicyTO) modelObject).getDescription(); } else if (modelObject instanceof SecurityQuestionTO) { header = ((SecurityQuestionTO) modelObject).getContent(); } else if (modelObject instanceof AccessTokenTO) { header = ((AccessTokenTO) modelObject).getOwner(); } else if (modelObject instanceof ExecTO) { header = ((ExecTO) modelObject).getKey(); } else if (modelObject instanceof WorkflowDefinitionTO) { header = ((WorkflowDefinitionTO) modelObject).getName(); } else if (modelObject instanceof SchedTaskTO) { header = ((SchedTaskTO) modelObject).getName(); } else if (modelObject instanceof WorkflowFormTO) { header = ((WorkflowFormTO) modelObject).getKey(); } else if (modelObject instanceof EntityTO) { header = ((EntityTO) modelObject).getKey(); } else if (modelObject instanceof StatusBean) { header = ((StatusBean) modelObject).getResource(); } else if (modelObject instanceof PolicyRuleWrapper) { header = ((PolicyRuleWrapper) modelObject).getImplementationKey(); } else if (modelObject instanceof PolicyRuleWrapper) { header = ((PolicyRuleWrapper) modelObject).getImplementationKey(); } else if (modelObject instanceof ReportletWrapper) { header = ((ReportletWrapper) modelObject).getImplementationKey(); } else if (modelObject instanceof JobTO) { header = ((JobTO) modelObject).getRefKey() == null ? ((JobTO) modelObject).getRefDesc() : ((JobTO) modelObject).getRefKey(); } else if (modelObject instanceof ResourceProvision) { header = ((ResourceProvision) modelObject).getAnyType(); } else {/*from w ww. j a v a 2 s . c om*/ header = new ResourceModel("actions", StringUtils.EMPTY).getObject(); } setHeader(target, StringUtils.abbreviate(header, HEADER_FIRST_ABBREVIATION)); }
From source file:org.apache.sysml.api.mlcontext.MLContextUtil.java
/** * Obtain a display of script inputs./*w w w . jav a 2 s . c o m*/ * * @param name * the title to display for the inputs * @param map * the map of inputs * @param symbolTable the symbol table * @return the script inputs represented as a String */ public static String displayInputs(String name, Map<String, Object> map, LocalVariableMap symbolTable) { StringBuilder sb = new StringBuilder(); sb.append(name); sb.append(":\n"); Set<String> keys = map.keySet(); if (keys.isEmpty()) { sb.append("None\n"); } else { int count = 0; for (String key : keys) { Object object = map.get(key); @SuppressWarnings("rawtypes") Class clazz = object.getClass(); String type = clazz.getSimpleName(); if (object instanceof JavaRDD<?>) { type = "JavaRDD"; } else if (object instanceof RDD<?>) { type = "RDD"; } sb.append(" ["); sb.append(++count); sb.append("]"); sb.append(" ("); sb.append(type); if (doesSymbolTableContainMatrixObject(symbolTable, key)) { sb.append(" as Matrix"); } else if (doesSymbolTableContainFrameObject(symbolTable, key)) { sb.append(" as Frame"); } sb.append(") "); sb.append(key); sb.append(": "); String str = object.toString(); str = StringUtils.abbreviate(str, 100); sb.append(str); sb.append("\n"); } } return sb.toString(); }