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:hoot.services.controllers.osm.ElementResource.java
/** * <NAME>Element Service - Get Element By IDGet Element By Unique ID </NAME> * <DESCRIPTION>//from www. j a v a 2s. c o m * Convenience method which allows for retrieving a node, way, or relation by an OSM unique element ID. * Child element of ways and relations are not added to the output (use the "full" method for that functionality). The ID of * the map owning the element does not need to be specified in the query string because the information already exists in the * element ID. This method is not part of the OSM API * </DESCRIPTION> * <PARAMETERS> * <elementId> * long; OSM ID of the requested element * </elementId> * </PARAMETERS> * <OUTPUT> * XML representation of the requested element * </OUTPUT> * <EXAMPLE> * <URL>http://localhost:8080/hoot-services/osm/api/0.6/element/1_n_1</URL> * <REQUEST_TYPE>GET</REQUEST_TYPE> * <INPUT> * </INPUT> * <OUTPUT> * OSM XML * see https://insightcloud.digitalglobe.com/redmine/projects/hootenany/wiki/User_-_OsmElementService#Get-Element-By-Unique-ID * </OUTPUT> * </EXAMPLE> * * Returns a single element item's XML for a given map without its element children * * @param elementId a "hoot" formatted element id of the format: * <map id>_<first letter of the element type>_<element id>; valid element types include: node, * way, or relation * @return element XML document * @throws Exception * @see https://insightcloud.digitalglobe.com/redmine/projects/hootenany/wiki/User_-_OsmElementService#Get-Element-By-Unique-ID */ @GET @Path("/element/{elementId}") @Consumes({ MediaType.TEXT_PLAIN }) @Produces({ MediaType.TEXT_XML }) public Response getElementByUniqueId(@PathParam("elementId") final String elementId) throws Exception { Connection conn = DbUtils.createConnection(); Document elementDoc = null; try { log.debug("Initializing database connection..."); if (!UNIQUE_ELEMENT_ID_PATTERN.matcher(elementId).matches()) { ResourceErrorHandler.handleError("Invalid element ID: " + elementId, Status.BAD_REQUEST, log); } final String[] elementIdParts = elementId.split("_"); final ElementType elementTypeVal = Element.elementTypeFromString(elementIdParts[1]); if (elementTypeVal == null) { ResourceErrorHandler.handleError("Invalid element type: " + elementIdParts[1], Status.BAD_REQUEST, log); } elementDoc = getElementXml(elementIdParts[0], Long.parseLong(elementIdParts[2]), elementTypeVal, true, false, conn); } finally { DbUtils.closeConnection(conn); } log.debug("Returning response: " + StringUtils.abbreviate(XmlDocumentBuilder.toString(elementDoc), 100) + " ..."); return Response.ok(new DOMSource(elementDoc), MediaType.APPLICATION_XML) .header("Content-type", MediaType.APPLICATION_XML).build(); }
From source file:com.erudika.para.utils.Utils.java
/** * Abbreviates a string//from w ww.java 2 s . c om * @param str a string * @param max max length * @return a substring of that string */ public static String abbreviate(String str, int max) { return StringUtils.isBlank(str) ? "" : StringUtils.abbreviate(str, max); }
From source file:edu.kit.dama.ui.simon.panel.SimonMainPanel.java
/** * Build the overview tab including the list of all categories and der * overall status.// w w w . j ava 2s . c om * * @param pCategories A list of all categories. * * @return The tab component. */ private Component buildOverviewTab(String[] pCategories) { AbsoluteLayout abLay = new AbsoluteLayout(); UIUtils7.GridLayoutBuilder layoutBuilder = new UIUtils7.GridLayoutBuilder(4, pCategories.length + 1); updateButton = new Button("Update Status"); updateButton.addClickListener(this); Embedded logo = new Embedded(null, new ThemeResource("img/simon.png")); abLay.addComponent(logo, "top:30px;left:30px;"); Label simonSaysLabel = new Label("", ContentMode.HTML); simonSaysLabel.setHeight("150px"); setSimonSaysContent(simonSaysLabel, "Everything is fine."); abLay.addComponent(simonSaysLabel, "top:30px;left:250px;"); int row = 0; for (String category : pCategories) { HorizontalLayout rowLayout = new HorizontalLayout(); Label name = new Label(category); name.setWidth("200px"); name.setHeight("24px"); List<AbstractProbe> probes = probesByCategory.get(category); Collections.sort(probes, new Comparator<AbstractProbe>() { @Override public int compare(AbstractProbe o1, AbstractProbe o2) { return o1.getCurrentStatus().compareTo(o2.getCurrentStatus()); } }); int failed = 0; int unknown = 0; int unavailable = 0; int charactersPerProbe = 100; if (probes.size() > 0) { charactersPerProbe = (int) Math.rint((700.0 / probes.size()) / 8.0); } for (AbstractProbe probe : probes) { Label probeLabel = new Label(StringUtils.abbreviate(probe.getName(), charactersPerProbe)); probeLabel.setHeight("24px"); switch (probe.getCurrentStatus()) { case UNKNOWN: probeLabel.setDescription(probe.getName() + ": UNKNOWN"); probeLabel.addStyleName("probe-unknown"); unknown++; break; case UPDATING: probeLabel.setDescription(probe.getName() + ": UPDATING"); probeLabel.addStyleName("probe-updating"); break; case UNAVAILABLE: probeLabel.setDescription(probe.getName() + ": UNAVAILABLE"); probeLabel.addStyleName("probe-unavailable"); unavailable++; break; case FAILED: probeLabel.setDescription(probe.getName() + ": FAILED"); probeLabel.addStyleName("probe-failed"); failed++; break; default: probeLabel.setDescription(probe.getName() + ": SUCCESS"); probeLabel.addStyleName("probe-success"); } probeLabel.addStyleName("probe"); rowLayout.addComponent(probeLabel); } if (failed != 0) { setSimonSaysContent(simonSaysLabel, "There are errors!"); } else { if (unknown != 0) { setSimonSaysContent(simonSaysLabel, "There are unknown states. Please select 'Update Status'."); } else { if (unavailable != 0) { setSimonSaysContent(simonSaysLabel, "Some probes are unavailable. Please check their configuration."); } } } rowLayout.setWidth("700px"); layoutBuilder.addComponent(name, Alignment.TOP_LEFT, 0, row, 1, 1).addComponent(rowLayout, Alignment.TOP_LEFT, 1, row, 3, 1); row++; } layoutBuilder.addComponent(updateButton, Alignment.BOTTOM_RIGHT, 3, row, 1, 1); GridLayout tabLayout = layoutBuilder.getLayout(); tabLayout.setSpacing(true); tabLayout.setMargin(true); Panel p = new Panel(); p.setContent(tabLayout); p.setWidth("1024px"); p.setHeight("400px"); abLay.addComponent(p, "top:160px;left:30px;"); abLay.setSizeFull(); return abLay; }
From source file:com.github.cric.app.ui.SettingPanel.java
private void setMessage(String msg) { msgLabel.setText(StringUtils.abbreviate(msg, MAX_MSG_WIDTH)); }
From source file:hoot.services.controllers.osm.ElementResource.java
/** * <NAME>Element Service - Get Full Element By ID </NAME> * <DESCRIPTION>//from w w w. j a v a 2 s .co m * Convenience method which allows for retrieving a way or relation and all of its child elements * (way nodes or relation members) by numeric OSM element ID. The ID of the map owning the element * must be specified in the query string. * </DESCRIPTION> * <PARAMETERS> * <mapId> * string; ID or name of the map the requested element belongs to * </mapId> * <elementId> * long; OSM ID of the requested element * </elementId> * <elementType> * string; OSM type of the requested element; valid values are "node", "way", or "relation" * </elementType> * </PARAMETERS> * <OUTPUT> * XML representation of the requested element * </OUTPUT> * <EXAMPLE> * <URL>http://localhost:8080/hoot-services/osm/api/0.6/node/1/full?mapId=1</URL> * <REQUEST_TYPE>GET</REQUEST_TYPE> * <INPUT> * </INPUT> * <OUTPUT> * OSM XML * see https://insightcloud.digitalglobe.com/redmine/projects/hootenany/wiki/User_-_OsmElementService#Get-Full-Element-By-ID * </OUTPUT> * </EXAMPLE> * * Returns a single element item's XML for a given map with all of its element children * * @param mapId ID of the map the element belongs to * @param elementId OSM element ID of the element to retrieve * @param elementType OSM element type of the element to retrieve; valid values are: way * or relation * @return element XML document * @throws Exception * @see https://insightcloud.digitalglobe.com/redmine/projects/hootenany/wiki/User_-_OsmElementService#Get-Full-Element-By-ID */ @GET @Path("/{elementType: way|relation}/{elementId}/full") @Consumes({ MediaType.TEXT_PLAIN }) @Produces({ MediaType.TEXT_XML }) public Response getFullElement(@QueryParam("mapId") String mapId, @PathParam("elementId") final long elementId, @PathParam("elementType") final String elementType) throws Exception { final ElementType elementTypeVal = Element.elementTypeFromString(elementType); if (elementTypeVal == null) { ResourceErrorHandler.handleError("Invalid element type: " + elementType, Status.BAD_REQUEST, log); } Connection conn = DbUtils.createConnection(); Document elementDoc = null; try { log.debug("Initializing database connection..."); elementDoc = getElementXml(mapId, elementId, elementTypeVal, false, true, conn); } finally { DbUtils.closeConnection(conn); } log.debug("Returning response: " + StringUtils.abbreviate(XmlDocumentBuilder.toString(elementDoc), 100) + " ..."); return Response.ok(new DOMSource(elementDoc), MediaType.APPLICATION_XML) .header("Content-type", MediaType.APPLICATION_XML).build(); }
From source file:io.bitsquare.gui.components.paymentmethods.SepaForm.java
@Override protected void autoFillNameTextField() { if (useCustomAccountNameCheckBox != null && !useCustomAccountNameCheckBox.isSelected()) { String iban = ibanInputTextField.getText(); if (iban.length() > 9) iban = StringUtils.abbreviate(iban, 9); String method = BSResources.get(paymentAccount.getPaymentMethod().getId()); CountryBasedPaymentAccount countryBasedPaymentAccount = (CountryBasedPaymentAccount) this.paymentAccount; String country = countryBasedPaymentAccount.getCountry() != null ? countryBasedPaymentAccount.getCountry().code : "?"; String currency = this.paymentAccount.getSingleTradeCurrency() != null ? this.paymentAccount.getSingleTradeCurrency().getCode() : "?"; accountNameTextField.setText(//from ww w. j a v a 2s. co m method.concat(" (").concat(currency).concat("/").concat(country).concat("): ").concat(iban)); } }
From source file:hoot.services.controllers.osm.ChangesetResource.java
/** * Service method endpoint for uploading OSM changeset diff data * /*w w w. ja v a 2s . c o m*/ * @param changeset OSM changeset diff data * @param changesetId ID of the changeset being uploaded; changeset with the ID must already exist * @return response acknowledging the result of the update operation with updated entity ID * information * @throws Exception * @see http://wiki.openstreetmap.org/wiki/API_0.6 and * http://wiki.openstreetmap.org/wiki/OsmChange * @todo why can't I pass in changesetDiff as an XML doc instead of a string? */ @POST @Path("/{changesetId}/upload") @Consumes(MediaType.TEXT_XML) @Produces(MediaType.TEXT_XML) public Response upload(final String changeset, @PathParam("changesetId") final long changesetId, @QueryParam("mapId") final String mapId) throws Exception { Connection conn = DbUtils.createConnection(); Document changesetUploadResponse = null; try { log.debug("Intializing database connection..."); log.debug("Intializing changeset upload transaction..."); TransactionStatus transactionStatus = transactionManager .getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED)); conn.setAutoCommit(false); try { if (mapId == null) { throw new Exception("Invalid map id."); } long mapid = Long.parseLong(mapId); changesetUploadResponse = (new ChangesetDbWriter(conn)).write(mapid, changesetId, changeset); } catch (Exception e) { log.error("Rolling back transaction for changeset upload..."); transactionManager.rollback(transactionStatus); conn.rollback(); handleError(e, changesetId, StringUtils.abbreviate(changeset, 100)); } log.debug("Committing changeset upload transaction..."); transactionManager.commit(transactionStatus); conn.commit(); } finally { conn.setAutoCommit(true); DbUtils.closeConnection(conn); } log.debug("Returning changeset upload response: " + StringUtils.abbreviate(XmlDocumentBuilder.toString(changesetUploadResponse), 100) + " ..."); return Response.ok(new DOMSource(changesetUploadResponse), MediaType.TEXT_XML) .header("Content-type", MediaType.TEXT_XML).build(); }
From source file:com.francetelecom.clara.cloud.activation.plugin.cf.infrastructure.AbstractCfAdapterIT.java
/** * /*from w ww . j a v a2 s . c om*/ * @param virtualHost * @param testRequestPath * @param appNameToDumpDiagnosticLogs * the name of the app to display the logs of if the webgui is * unreacheable, or null to no display such logs. * @throws IOException */ protected void testRemoteAppWebGui(String virtualHost, String testRequestPath, String appNameToDumpDiagnosticLogs) throws IOException { HttpClientConfig defaultProxyConfig = getHttpProxyConfigToQueryWebGuiRoutes(); int retry = 0; int maxRetries = 10; String testResponse = null; StringBuffer testFailureDetails = new StringBuffer(); do { logger.info("Querying " + getWebGuiURL(virtualHost, testRequestPath) + " using proxyConfig=" + defaultProxyConfig + " ..."); try { testResponse = fetchRoutedContentAsString(getWebGuiURL(virtualHost, testRequestPath), defaultProxyConfig); break; } catch (HttpResponseException e) { String msg = "Querying " + getWebGuiURL(virtualHost, testRequestPath) + " ... done. Caught: " + e; logger.info(msg); testFailureDetails.append(msg); testFailureDetails.append("\n"); if (e.getStatusCode() == 404) { logger.info("Sleeping for 10s before next retry (" + retry + "/" + maxRetries + ")"); if (appNameToDumpDiagnosticLogs != null) { cfAdapter.logAppDiagnostics(appNameToDumpDiagnosticLogs, cfDefaultSpace); } try { Thread.sleep(10 * 1000); } catch (InterruptedException e1) { // Ignore } retry++; } else { break; // no retries for unexpected errors } } } while (retry < maxRetries); logger.info("Querying " + getWebGuiURL(virtualHost, testRequestPath) + " ... done. Returned: " + StringUtils.abbreviate(testResponse, 50)); assertThat(testResponse).as("webGui response").isNotNull().isNotEmpty(); assertThat(retry).overridingErrorMessage("Expecting zero retries on webGui polling, got " + retry + " retries. Details:" + testFailureDetails).isLessThanOrEqualTo(1); // Expect // the app to immediately return a valid response, retries are only here // to help diagnostics }
From source file:io.bitsquare.common.util.Utilities.java
public static String toTruncatedString(Object message, int maxLenght) { return StringUtils.abbreviate(message.toString(), maxLenght).replace("\n", ""); }
From source file:io.bitsquare.gui.main.funds.withdrawal.WithdrawalView.java
private void selectForWithdrawal(WithdrawalListItem item, boolean isSelected) { if (isSelected) selectedItems.add(item);//w w w .ja v a 2 s .co m else selectedItems.remove(item); fromAddresses = selectedItems.stream().map(WithdrawalListItem::getAddressString) .collect(Collectors.toSet()); if (!selectedItems.isEmpty()) { amountOfSelectedItems = Coin .valueOf(selectedItems.stream().mapToLong(e -> e.getBalance().getValue()).sum()); if (amountOfSelectedItems.isPositive()) { senderAmountAsCoinProperty.set(amountOfSelectedItems); amountTextField.setText(formatter.formatCoin(amountOfSelectedItems)); } else { senderAmountAsCoinProperty.set(Coin.ZERO); amountOfSelectedItems = Coin.ZERO; amountTextField.setText(""); withdrawFromTextField.setText(""); } if (selectedItems.size() == 1) { withdrawFromTextField .setText(selectedItems.stream().findAny().get().getAddressEntry().getAddressString()); withdrawFromTextField.setTooltip(null); } else { String tooltipText = "Withdraw from multiple addresses:\n" + selectedItems.stream() .map(WithdrawalListItem::getAddressString).collect(Collectors.joining(",\n")); int abbr = Math.max(10, 66 / selectedItems.size()); String text = "Withdraw from multiple addresses (" + selectedItems.stream().map(e -> StringUtils.abbreviate(e.getAddressString(), abbr)) .collect(Collectors.joining(", ")) + ")"; withdrawFromTextField.setText(text); withdrawFromTextField.setTooltip(new Tooltip(tooltipText)); } } else { reset(); } }