List of usage examples for org.apache.commons.lang StringUtils abbreviate
public static String abbreviate(String str, int maxWidth)
Abbreviates a String using ellipses.
From source file:org.jumpmind.vaadin.ui.sqlexplorer.QueryPanel.java
protected boolean execute(final boolean runAsScript, String sqlText, final int tabPosition, final boolean forceNewTab) { boolean scheduled = false; if (runnersInProgress == null) { runnersInProgress = new HashSet<SqlRunner>(); }//from www . ja v a2s . c o m if (sqlText == null) { if (!runAsScript) { sqlText = selectSqlToRun(); } else { sqlText = sqlArea.getValue(); } sqlText = sqlText != null ? sqlText.trim() : null; } if (StringUtils.isNotBlank(sqlText)) { final HorizontalLayout executingLayout = new HorizontalLayout(); executingLayout.setMargin(true); executingLayout.setSizeFull(); final Label label = new Label("Executing:\n\n" + StringUtils.abbreviate(sqlText, 250), ContentMode.PREFORMATTED); label.setEnabled(false); executingLayout.addComponent(label); executingLayout.setComponentAlignment(label, Alignment.TOP_LEFT); final String sql = sqlText; final Tab executingTab; if (!forceNewTab && generalResultsTab != null) { replaceGeneralResultsWith(executingLayout, FontAwesome.SPINNER); executingTab = null; } else { executingTab = resultsTabs.addTab(executingLayout, StringUtils.abbreviate(sql, 20), FontAwesome.SPINNER, tabPosition); } if (executingTab != null) { executingTab.setClosable(true); resultsTabs.setSelectedTab(executingTab); } final SqlRunner runner = new SqlRunner(sql, runAsScript, user, db, settingsProvider.get(), this, generalResultsTab != null); runnersInProgress.add(runner); runner.setConnection(connection); runner.setListener(new SqlRunner.ISqlRunnerListener() { private static final long serialVersionUID = 1L; @Override public void writeSql(String sql) { QueryPanel.this.appendSql(sql); } @Override public void reExecute(String sql) { QueryPanel.this.reExecute(sql); } public void finished(final FontAwesome icon, final List<Component> results, final long executionTimeInMs, final boolean transactionStarted, final boolean transactionEnded) { VaadinSession.getCurrent().access(new Runnable() { @Override public void run() { try { if (transactionEnded) { transactionEnded(); } else if (transactionStarted) { rollbackButtonValue = true; commitButtonValue = true; setButtonsEnabled(); sqlArea.setStyleName("transaction-in-progress"); connection = runner.getConnection(); } addToSqlHistory(StringUtils.abbreviate(sql, 1024 * 8), runner.getStartTime(), executionTimeInMs, user); for (Component resultComponent : results) { resultComponent.setSizeFull(); if (forceNewTab || generalResultsTab == null || results.size() > 1) { if (resultComponent instanceof TabularResultLayout) { resultComponent = ((TabularResultLayout) resultComponent) .refreshWithoutSaveButton(); } addResultsTab(resultComponent, StringUtils.abbreviate(sql, 20), icon, tabPosition); } else { replaceGeneralResultsWith(resultComponent, icon); resultsTabs.setSelectedTab(generalResultsTab.getComponent()); } String statusVal; if (canceled) { statusVal = "Sql canceled after " + executionTimeInMs + " ms for " + db.getName() + ". Finished at " + SimpleDateFormat.getTimeInstance().format(new Date()); } else { statusVal = "Sql executed in " + executionTimeInMs + " ms for " + db.getName() + ". Finished at " + SimpleDateFormat.getTimeInstance().format(new Date()); } status.setValue(statusVal); resultStatuses.put(resultComponent, statusVal); canceled = false; } } finally { setButtonsEnabled(); if (executingTab != null) { resultsTabs.removeTab(executingTab); } else if (results.size() > 1) { resetGeneralResultsTab(); } runnersInProgress.remove(runner); runner.setListener(null); } } }); } }); final Button cancel = new Button("Cancel"); cancel.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { log.info("Canceling sql: " + sql); label.setValue("Canceling" + label.getValue().substring(9)); executingLayout.removeComponent(cancel); canceled = true; new Thread(new Runnable() { @Override public void run() { runner.cancel(); } }).start(); } }); executingLayout.addComponent(cancel); scheduled = true; runner.start(); } setButtonsEnabled(); return scheduled; }
From source file:org.jumpmind.vaadin.ui.sqlexplorer.TabularResultLayout.java
private void createMenuBar() { HorizontalLayout resultBar = new HorizontalLayout(); resultBar.setWidth(100, Unit.PERCENTAGE); resultBar.setMargin(new MarginInfo(false, true, false, true)); HorizontalLayout leftBar = new HorizontalLayout(); leftBar.setSpacing(true);//from w ww . ja v a 2 s . co m resultLabel = new Label("", ContentMode.HTML); leftBar.addComponent(resultLabel); final Label sqlLabel = new Label("", ContentMode.TEXT); sqlLabel.setWidth(800, Unit.PIXELS); leftBar.addComponent(sqlLabel); resultBar.addComponent(leftBar); resultBar.setComponentAlignment(leftBar, Alignment.MIDDLE_LEFT); resultBar.setExpandRatio(leftBar, 1); MenuBar rightBar = new MenuBar(); rightBar.addStyleName(ValoTheme.MENUBAR_BORDERLESS); rightBar.addStyleName(ValoTheme.MENUBAR_SMALL); MenuBar.MenuItem refreshButton = rightBar.addItem("", new Command() { private static final long serialVersionUID = 1L; @Override public void menuSelected(MenuBar.MenuItem selectedItem) { listener.reExecute(sql); } }); refreshButton.setIcon(FontAwesome.REFRESH); MenuBar.MenuItem exportButton = rightBar.addItem("", new Command() { private static final long serialVersionUID = 1L; @Override public void menuSelected(MenuBar.MenuItem selectedItem) { new ExportDialog(grid, db.getName(), sql).show(); } }); exportButton.setIcon(FontAwesome.UPLOAD); if (isInQueryGeneralResults) { MenuBar.MenuItem keepResultsButton = rightBar.addItem("", new Command() { private static final long serialVersionUID = 1L; @Override public void menuSelected(com.vaadin.ui.MenuBar.MenuItem selectedItem) { queryPanel.addResultsTab(refreshWithoutSaveButton(), StringUtils.abbreviate(sql, 20), queryPanel.getGeneralResultsTab().getIcon()); queryPanel.resetGeneralResultsTab(); } }); keepResultsButton.setIcon(FontAwesome.CLONE); keepResultsButton.setDescription("Save these results to a new tab"); } if (showSql) { sqlLabel.setValue(StringUtils.abbreviate(sql, 200)); } resultBar.addComponent(rightBar); resultBar.setComponentAlignment(rightBar, Alignment.MIDDLE_RIGHT); this.addComponent(resultBar, 0); }
From source file:org.kontalk.client.KonMessageListener.java
private void processChatMessage(Message m) { LOGGER.info("got message: " + StringUtils.abbreviate(m.toXML().toString(), 300)); // note: thread and subject are null if message comes from the Kontalk // Android client String threadID = m.getThread() != null ? m.getThread() : ""; // TODO a message can contain all sorts of extensions, we should loop // over all of them // timestamp/*from w ww .j a v a 2 s .com*/ // delayed deliver extension is the first the be processed // because it's used also in delivery receipts // first: new XEP-0203 specification PacketExtension delay = m.getExtension(DelayInformation.ELEMENT, DelayInformation.NAMESPACE); // fallback: obsolete XEP-0091 specification if (delay == null) { delay = m.getExtension("x", "jabber:x:delay"); } Optional<Date> serverDate = Optional.empty(); if (delay != null && delay instanceof DelayInformation) { Date date = ((DelayInformation) delay).getStamp(); if (date.after(new Date())) LOGGER.warning("delay time is in future: " + date); serverDate = Optional.of(date); } // process possible chat state notification (XEP-0085) PacketExtension chatstate = m.getExtension(ChatStateExtension.NAMESPACE); if (chatstate != null) { LOGGER.info("got chatstate: " + chatstate.getElementName()); mControl.processChatState(m.getFrom(), threadID, serverDate, chatstate.getElementName()); if (!chatstate.getElementName().equals(ChatState.active.name())) // we assume there is no other content return; } // check for delivery receipt (XEP-0184) DeliveryReceipt receipt = DeliveryReceipt.from(m); if (receipt != null) { // HOORAY! our message was received String receiptID = receipt.getId(); if (receiptID == null || receiptID.isEmpty()) { LOGGER.warning("message has invalid receipt ID: " + receiptID); } else { mControl.setMessageStatus(receiptID, Status.RECEIVED); } // we ignore anything else that might be in this message return; } // must be an incoming message // get content/text from body and/or encryption/url extension MessageContent content = parseMessageContent(m); // make sure not to save a message without content if (content.isEmpty()) { LOGGER.warning("can't find any content in message"); return; } String xmppID = m.getPacketID() != null ? m.getPacketID() : ""; if (xmppID.isEmpty()) { LOGGER.warning("message does not have a XMPP ID"); } // add message boolean success = mControl.newInMessage(m.getFrom(), xmppID, threadID, serverDate, content); // on success, send a 'received' for a request (XEP-0184) DeliveryReceiptRequest request = DeliveryReceiptRequest.from(m); if (request != null && success && !xmppID.isEmpty()) { Message received = new Message(m.getFrom(), Message.Type.chat); received.addExtension(new DeliveryReceipt(xmppID)); mClient.sendPacket(received); } }
From source file:org.kontalk.client.PublicKeyListener.java
@Override public void processPacket(Stanza packet) { LOGGER.info("got public key: " + StringUtils.abbreviate(packet.toXML().toString(), 300)); PublicKeyPublish publicKeyPacket = (PublicKeyPublish) packet; if (publicKeyPacket.getType() == IQ.Type.set) { LOGGER.warning("ignoring public key packet with type 'set'"); return;//from w ww.ja va 2 s.c o m } if (publicKeyPacket.getType() == IQ.Type.result) { byte[] keyData = publicKeyPacket.getPublicKey(); if (keyData == null) { LOGGER.warning("got public key packet without public key"); return; } mControl.setPGPKey(publicKeyPacket.getFrom(), keyData); } }
From source file:org.kontalk.view.Utils.java
static String shortenUserName(String jid, int maxLength) { String local = XmppStringUtils.parseLocalpart(jid); local = StringUtils.abbreviate(local, maxLength); String domain = XmppStringUtils.parseDomain(jid); return XmppStringUtils.completeJidFrom(local, domain); }
From source file:org.kontalk.view.Utils.java
static String shortenJID(String jid, int maxLength) { if (jid.length() > maxLength) { String local = XmppStringUtils.parseLocalpart(jid); local = StringUtils.abbreviate(local, (int) (maxLength * 0.4)); String domain = XmppStringUtils.parseDomain(jid); domain = StringUtils.abbreviate(domain, (int) (maxLength * 0.6)); jid = XmppStringUtils.completeJidFrom(local, domain); }//w w w .jav a 2 s . c o m return jid; }
From source file:org.kuali.kfs.fp.document.JournalVoucherDocumentTest.java
private JournalVoucherDocument buildDocument() throws Exception { // put accounting lines into document parameter for later JournalVoucherDocument document = (JournalVoucherDocument) getDocumentParameterFixture(); StackTraceElement[] trace = Thread.currentThread().getStackTrace(); document.getDocumentHeader()//from w w w . j av a2 s.c o m .setDocumentDescription(StringUtils.abbreviate("Unit Test doc for " + trace[3].getMethodName(), SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength( document.getDocumentHeader().getClass(), "documentDescription"))); document.getDocumentHeader() .setExplanation(StringUtils.abbreviate( "Unit test created document for " + trace[3].getClassName() + "." + trace[3].getMethodName(), SpringContext.getBean(DataDictionaryService.class) .getAttributeMaxLength(document.getDocumentHeader().getClass(), "explanation"))); // set accountinglines to document for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) { sourceFixture.addAsVoucherSourceTo(document); } document.setBalanceTypeCode(KFSConstants.BALANCE_TYPE_ACTUAL); return document; }
From source file:org.kuali.kfs.module.tem.document.TravelAuthorizationDocument.java
/** * Customization for accounting lines associated with travel advances * @param postable the general ledger pending entry source which is the source of the customized explicit entry * @param explicitEntry the explicit entry to customize *//*w w w . j a v a 2s . com*/ protected void customizeAdvanceExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) { final String paymentDocumentType = StringUtils.isBlank(getTravelAdvancePaymentDocumentType()) ? TemConstants.TravelDocTypes.TRAVEL_AUTHORIZATION_CHECK_ACH_DOCUMENT : getTravelAdvancePaymentDocumentType(); explicitEntry.setFinancialDocumentTypeCode(paymentDocumentType); final String description = MessageFormat.format( getConfigurationService().getPropertyValueAsString( TemKeyConstants.TA_MESSAGE_ADVANCE_ACCOUNTING_LINES_GLPE_DESCRIPTION), getDataDictionaryService().getDocumentTypeNameByClass(getClass()), getDocumentNumber()); final int maxLength = getDataDictionaryService().getAttributeMaxLength(GeneralLedgerPendingEntry.class, KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC); explicitEntry.setTransactionLedgerEntryDescription(StringUtils.abbreviate(description, maxLength)); explicitEntry.setOrganizationDocumentNumber(getTravelDocumentIdentifier()); }
From source file:org.kuali.kpme.pm.position.web.PositionMaintainableServiceImpl.java
private Note createNote(String noteText, String noteTarget, String principalId) { Note note = new Note(); note.setRemoteObjectIdentifier(noteTarget); note.setNoteText(StringUtils.abbreviate(noteText, 800)); note.setAuthorUniversalIdentifier(principalId); note.setNotePostedTimestampToCurrent(); return note;//from w ww . j a va 2 s . c om }
From source file:org.kuali.ole.fp.document.JournalVoucherDocumentTest.java
private JournalVoucherDocument buildDocument() throws Exception { // put accounting lines into document parameter for later JournalVoucherDocument document = (JournalVoucherDocument) getDocumentParameterFixture(); StackTraceElement[] trace = Thread.currentThread().getStackTrace(); document.getDocumentHeader()//from ww w .jav a 2 s . co m .setDocumentDescription(StringUtils.abbreviate("Unit Test doc for " + trace[3].getMethodName(), SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength( document.getDocumentHeader().getClass(), "documentDescription"))); document.getDocumentHeader() .setExplanation(StringUtils.abbreviate( "Unit test created document for " + trace[3].getClassName() + "." + trace[3].getMethodName(), SpringContext.getBean(DataDictionaryService.class) .getAttributeMaxLength(document.getDocumentHeader().getClass(), "explanation"))); // set accountinglines to document for (AccountingLineFixture sourceFixture : getSourceAccountingLineParametersFromFixtures()) { sourceFixture.addAsVoucherSourceTo(document); } document.setBalanceTypeCode(OLEConstants.BALANCE_TYPE_ACTUAL); return document; }