Example usage for org.apache.commons.lang StringUtils abbreviate

List of usage examples for org.apache.commons.lang StringUtils abbreviate

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils abbreviate.

Prototype

public static String abbreviate(String str, int maxWidth) 

Source Link

Document

Abbreviates a String using ellipses.

Usage

From source file:org.madsonic.ajax.NowPlayingService.java

private List<NowPlayingInfo> convert(List<TransferStatus> statuses) throws Exception {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    String url = request.getRequestURL().toString();
    List<NowPlayingInfo> result = new ArrayList<NowPlayingInfo>();
    for (TransferStatus status : statuses) {

        Player player = status.getPlayer();
        File file = status.getFile();

        if (player != null && player.getUsername() != null && file != null) {

            String username = player.getUsername();
            UserSettings userSettings = settingsService.getUserSettings(username);
            if (!userSettings.isNowPlayingAllowed()) {
                continue;
            }//from   w  ww . jav a2s  . c om

            MediaFile mediaFile = mediaFileService.getMediaFile(file);
            File coverArt = mediaFileService.getCoverArt(mediaFile);

            String artist = mediaFile.getArtist();
            String title = mediaFile.getTitle();

            String streamUrl = url.replaceFirst("/dwr/.*",
                    "/stream?player=" + player.getId() + "&id=" + mediaFile.getId());
            String albumUrl = url.replaceFirst("/dwr/.*", "/main.view?id=" + mediaFile.getId());

            MetaDataParser parser = metaDataParserFactory.getParser(mediaFile.getFile());
            MetaData metaData = parser.getMetaData(mediaFile.getFile());

            String lyricsUrl;
            if (metaData.hasLyrics()) {
                lyricsUrl = "lyrics.view?id=" + mediaFile.getId();
            } else {
                lyricsUrl = url.replaceFirst("/dwr/.*", "/lyrics.view?artistUtf8Hex="
                        + StringUtil.utf8HexEncode(artist) + "&songUtf8Hex=" + StringUtil.utf8HexEncode(title));
            }

            //              String coverArtUrl = coverArt == null ? null : url.replaceFirst("/dwr/.*", "/coverArt.view?size=48&id=" + mediaFile.getId());
            //              String coverArtZoomUrl = coverArt == null ? null : url.replaceFirst("/dwr/.*", "/coverArt.view?id=" + mediaFile.getId());

            String coverArtUrl = url.replaceFirst("/dwr/.*", "/coverArt.view?size=48&id=" + mediaFile.getId());
            String coverArtZoomUrl = url.replaceFirst("/dwr/.*", "/coverArt.view?id=" + mediaFile.getId());

            String avatarUrl = null;
            if (userSettings.getAvatarScheme() == AvatarScheme.SYSTEM) {
                avatarUrl = url.replaceFirst("/dwr/.*", "/avatar.view?id=" + userSettings.getSystemAvatarId());
            } else if (userSettings.getAvatarScheme() == AvatarScheme.CUSTOM
                    && settingsService.getCustomAvatar(username) != null) {
                avatarUrl = url.replaceFirst("/dwr/.*", "/avatar.view?username=" + username);
            }

            // Rewrite URLs in case we're behind a proxy.
            if (settingsService.isRewriteUrlEnabled()) {
                String referer = request.getHeader("referer");
                streamUrl = StringUtil.rewriteUrl(streamUrl, referer);
                albumUrl = StringUtil.rewriteUrl(albumUrl, referer);
                lyricsUrl = StringUtil.rewriteUrl(lyricsUrl, referer);
                coverArtUrl = StringUtil.rewriteUrl(coverArtUrl, referer);
                coverArtZoomUrl = StringUtil.rewriteUrl(coverArtZoomUrl, referer);
                avatarUrl = StringUtil.rewriteUrl(avatarUrl, referer);
            }

            String tooltip = StringUtil.toHtml(artist) + " &ndash; " + StringUtil.toHtml(title);

            if (StringUtils.isNotBlank(player.getName())) {
                username += "@" + player.getName();
            }
            artist = StringUtil.toHtml(StringUtils.abbreviate(artist, 25));
            title = StringUtil.toHtml(StringUtils.abbreviate(title, 25));
            username = StringUtil.toHtml(StringUtils.abbreviate(username, 25));

            long minutesAgo = status.getMillisSinceLastUpdate() / 1000L / 60L;
            if (minutesAgo < 60) {
                result.add(new NowPlayingInfo(username, artist, title, tooltip, streamUrl, albumUrl, lyricsUrl,
                        coverArtUrl, coverArtZoomUrl, avatarUrl, (int) minutesAgo));
            }
        }
    }

    return result;

}

From source file:org.ngrinder.model.PerfTest.java

public String getDescription() {
    return StringUtils.abbreviate(description, MAX_LONG_STRING_SIZE - MARGIN_FOR_ABBREVIATION);
}

From source file:org.nuclos.client.wizard.NuclosEntityWizardStaticModel.java

public String getTableOrViewName() {
    final boolean virtual = !StringUtils.isBlank(virtualentity);
    if (strTableName != null) {
        if (!virtual && strTableName.startsWith("V_")) {
            strTableName = "T_" + strTableName.substring(2);
        } else if (virtual && strTableName.startsWith("T_")) {
            strTableName = "V_" + strTableName.substring(2);
        }//from   w w w .  ja v  a2  s . c  om
        if (strTableName.length() > 30) {
            return StringUtils.abbreviate(StringUtils.deleteWhitespace(strTableName).toUpperCase(), 30);
        } else if (strTableName.length() < 1) {
            final String sTable = (virtual ? "V_EO" : "T_EO_")
                    + StringUtils.deleteWhitespace(entityName).toUpperCase();
            return sTable;
        } else {
            return strTableName;
        }
    } else {
        final String sTable = StringUtils.abbreviate(
                (virtual ? "V_EO" : "T_EO_") + StringUtils.deleteWhitespace(entityName).toUpperCase(), 30);
        return sTable;
    }
}

From source file:org.ojbc.bundles.connectors.OJBWebApplicationConnectorIntTest.java

@Test
public void testCriminalHistoryQuery() throws Exception {

    //create and populate a criminal history POJO
    DetailsRequest chr = new DetailsRequest();

    chr.setIdentificationID("12345");
    chr.setIdentificationSourceText(/*from w w w .j a  va2s . c  o  m*/
            "{http://ojbc.org/Services/WSDL/Person_Query_Service-Criminal_History/1.0}Person-Query-Service---Criminal-History");

    //Add SAML token to request call
    Element samlToken = SAMLTokenUtils.createStaticAssertionAsElement(
            "http://ojbc.org/ADS/AssertionDelegationService",
            SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS, SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1,
            true, true, null);

    String federatedQueryID = returnFederatedQueryGUID();

    //Invoke the service
    String response = detailQueryDispatcher.invokeRequest(chr, federatedQueryID, samlToken);

    log.info("Body recieved by Service (truncated): " + StringUtils.abbreviate(response, 503));

    Assert.assertNotNull(response);
}

From source file:org.ojbc.bundles.connectors.OJBWebApplicationConnectorIntTest.java

@Test
public void testWarrantsQuery() throws Exception {

    //create and populate a warrants POJO
    DetailsRequest warrantsRequest = new DetailsRequest();

    warrantsRequest.setIdentificationID("12345");
    warrantsRequest.setIdentificationSourceText(
            "{http://ojbc.org/Services/WSDL/Person_Query_Service-Warrants/1.0}Person-Query-Service---Warrants");

    //Add SAML token to request call
    Element samlToken = SAMLTokenUtils.createStaticAssertionAsElement(
            "http://ojbc.org/ADS/AssertionDelegationService",
            SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS, SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1,
            true, true, null);// w  w w .  j av a 2  s. c o m

    String federatedQueryID = returnFederatedQueryGUID();

    String response = detailQueryDispatcher.invokeRequest(warrantsRequest, federatedQueryID, samlToken);

    log.info("Body recieved by Service (truncated): " + StringUtils.abbreviate(response, 503));

    Assert.assertNotNull(response);

}

From source file:org.ojbc.bundles.connectors.OJBWebApplicationConnectorIntTest.java

@Test
@Ignore/*from   ww  w . j  a  v  a2s .  c  om*/
public void testPersonSearchRequest() throws Exception {

    //create and populate a person search request POJO
    PersonSearchRequest personSearchRequest = PersonSearchRequestTestUtils.createPersonSearchRequestModel();

    //Add SAML token to request call
    Element samlToken = SAMLTokenUtils.createStaticAssertionAsElement(
            "http://ojbc.org/ADS/AssertionDelegationService",
            SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS, SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1,
            true, true, null);

    String federatedQueryID = returnFederatedQueryGUID();

    //Invoke the service
    String response = personSearchRequestProcessor.invokePersonSearchRequest(personSearchRequest,
            federatedQueryID, samlToken);

    log.info("Body recieved by Service (truncated): " + StringUtils.abbreviate(response, 503));

    Assert.assertNotNull(response);

}

From source file:org.ojbc.bundles.connectors.OJBWebApplicationConnectorIntTest.java

@Test
public void testIncidentReportRequest() throws Exception {

    //create and populate a person search request POJO
    DetailsRequest incidentReportRequest = new DetailsRequest();

    incidentReportRequest.setIdentificationID("{Citation}");
    incidentReportRequest.setIdentificationSourceText(
            "{http://ojbc.org/Services/WSDL/IncidentReportRequestService/1.0}SubmitIncidentIdentiferIncidentReportRequest-DPS");

    String federatedQueryID = returnFederatedQueryGUID();

    //Invoke the service
    String response = detailQueryDispatcher.invokeRequest(incidentReportRequest, federatedQueryID, null);

    log.info("Body recieved by Service (truncated): " + StringUtils.abbreviate(response, 503));

    Assert.assertNotNull(response);/*from w w  w .  j a  va 2 s  .c om*/

}

From source file:org.ojbc.bundles.connectors.OJBWebApplicationConnectorIntTest.java

@Test
public void testIncidentSearchRequest() throws Exception {

    //create and populate a person search request POJO
    DetailsRequest incidentReportRequest = new DetailsRequest();

    incidentReportRequest.setIdentificationID("12345");
    incidentReportRequest.setIdentificationSourceText(
            "{http://ojbc.org/Services/WSDL/IncidentSearchRequestService/1.0}SubmitIncidentPersonSearchRequest-DPS");

    String federatedQueryID = returnFederatedQueryGUID();

    //Invoke the service
    String response = detailQueryDispatcher.invokeRequest(incidentReportRequest, federatedQueryID, null);

    log.info("Body recieved by Service (truncated): " + StringUtils.abbreviate(response, 503));

    Assert.assertNotNull(response);//w  ww  .j a  va  2 s.co  m

}

From source file:org.ojbc.bundles.connectors.OJBWebApplicationConnectorIntTest.java

@Test
public void testSubscriptionSearchRequest() throws Exception {

    //Add SAML token to request call
    Element samlToken = SAMLTokenUtils.createStaticAssertionAsElement(
            "http://ojbc.org/ADS/AssertionDelegationService",
            SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS, SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1,
            true, true, null);/*from   ww w .j ava2s  . c  o m*/

    String federatedQueryID = returnFederatedQueryGUID();

    //Invoke the service
    String response = subscriptionSearchRequestProcessor.invokeSubscriptionSearchRequest(federatedQueryID,
            samlToken);

    log.info("Body recieved by Service (truncated): " + StringUtils.abbreviate(response, 503));

    Assert.assertNotNull(response);

}

From source file:org.ojbc.bundles.connectors.OJBWebApplicationConnectorIntTest.java

@Test
public void testSubscriptionQueryRequest() throws Exception {

    //Add SAML token to request call
    Element samlToken = SAMLTokenUtils.createStaticAssertionAsElement(
            "http://ojbc.org/ADS/AssertionDelegationService",
            SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS, SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1,
            true, true, null);//from   w  ww  .j  a va  2s .  com

    String federatedQueryID = returnFederatedQueryGUID();

    //create and populate a person search request POJO
    DetailsRequest subscriptionQueryRequest = new DetailsRequest();

    subscriptionQueryRequest.setIdentificationID("62720");
    subscriptionQueryRequest.setIdentificationSourceText("subscriptions");

    //Invoke the service
    String response = subscriptionQueryRequestProcessor.invokeRequest(subscriptionQueryRequest,
            federatedQueryID, samlToken);

    log.info("Body recieved by Service (truncated): " + StringUtils.abbreviate(response, 503));

    Assert.assertNotNull(response);

}