Java Code Examples for org.apache.commons.lang.StringUtils.abbreviate()

The following are Jave code examples for showing how to use abbreviate() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: kaltura-ce-sakai-extension   File: MediaService.java   Source Code and License Vote up 6 votes
/**
 * Add a new collection to the location (site) indicated
 * 
 * @param title the title for this collection
 * @param locationId the unique id of the location to place this collection in
 * @return the newly created media collection
 * @throws IllegalArgumentException  if the params are invalid
 * @throws SecurityException if the user does not have permissions
 */
public MediaCollection addCollection(String title, String locationId) {
    if (locationId == null) {
        locationId = external.getCurrentLocationId();
    }
    if (StringUtils.isBlank(locationId)) {
        throw new IllegalArgumentException("location must be set");
    }
    String ownerId = checkPermOrException(ExternalLogic.PERM_ADMIN, locationId);
    if (StringUtils.isBlank(ownerId)) {
        throw new IllegalArgumentException("ownerId must be set");
    }
    if (StringUtils.isBlank(title)) {
        throw new IllegalArgumentException("title must be set");
    }
    if (log.isDebugEnabled()) log.debug("addCollection(title=" + title + ", locationId=" + locationId + ")");
    title = StringUtils.abbreviate(title, 250); // max length 255
    MediaCollection mc = new MediaCollection(title, null, "1", null);
    Map<String, String> metadata = mc.extractMetadataMap();
    KalturaCategory siteCat = kalturaAPIService.getSiteCategory(locationId);
    KalturaPlaylist kp = kalturaAPIService.getOrAddKalturaPlaylist(siteCat.id, title, metadata);
    mc = new MediaCollection(kp, locationId, metadata);
    mc.setItems( new ArrayList<MediaItem>(0) );
    log.info("User ("+external.getCurrentUserId()+") added collection ("+mc.getId()+", "+mc.getTitle()+") to location ("+mc.getLocationId()+"): " + mc);
    return mc;
}
 
Example 2
Project: kaltura-ce-sakai-extension   File: KalturaAPIService.java   Source Code and License Vote up 6 votes
/**
 * creates a playlist name that is <= 150 characters and is unique
 * 
 * @param playlistName the name of the playlist
 * @return the safe playlist name
 * @throws IllegalArgumentException if playlist name is invalid
 */
@NoProfile
protected String makeSafePlaylistName(String playlistName) {
    playlistName = StringUtils.trimToNull(playlistName);
    if (playlistName == null) {
        throw new IllegalArgumentException("playlistName cannot be null");
    }
    if (playlistName.length() > PLAYLIST_MAX_LENGTH) {
        playlistName = StringUtils.abbreviate(playlistName, CATEGORY_MAX_LENGTH);
        playlistName = playlistName.substring(0, CATEGORY_MAX_LENGTH-3) + RandomStringUtils.randomAlphanumeric(3);
    }
    return playlistName;
}
 
Example 3
Project: athena   File: NetSnmpDeviceDescriptor.java   Source Code and License Vote up 6 votes
private DeviceDescription populateDescription(ISnmpSession session, Device device) {
    NetworkDevice networkDevice = new NetworkDevice(CLASS_REGISTRY,
                                                    session.getAddress().getHostAddress());
    try {
        session.walkDevice(networkDevice, Collections.singletonList(CLASS_REGISTRY.getClassToOidMap().get(
                System.class)));

        com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System systemTree =
                (com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System)
                        networkDevice.getRootObject().getEntity(CLASS_REGISTRY.getClassToOidMap().get(
                                com.btisystems.mibbler.mibs.netsnmp.netsnmp.mib_2.System.class));
        if (systemTree != null) {
            // TODO SNMP sys-contacts may be verbose; ONOS-GUI doesn't abbreviate fields neatly;
            // so cut it here until supported in prop displayer
            String manufacturer = StringUtils.abbreviate(systemTree.getSysContact(), 20);
            return new DefaultDeviceDescription(device.id().uri(), device.type(),
                                                manufacturer, UNKNOWN, UNKNOWN, UNKNOWN,
                                                device.chassisId(), (SparseAnnotations) device.annotations());
        }
    } catch (IOException ex) {
        throw new IllegalArgumentException("Error reading details for device." + session.getAddress(), ex);
    }
    return null;
}
 
Example 4
Project: convertigo-engine   File: GetStoreContent.java   Source Code and License Vote up 5 votes
private Element createProjectElement(Document document, MobileApplication mobileApplication, String projectName) {
	Element projectElement = document.createElement("project");
	
	Element eProjectName = document.createElement("name");
	eProjectName.setTextContent(projectName);
	projectElement.appendChild(eProjectName);
	
	Element eApp = document.createElement("application");
	
	Element eAppName = document.createElement("name");
	String appName = mobileApplication.getApplicationName();
	if (appName.equals("")) {
		appName = projectName;
	}
	eAppName.setTextContent(appName);
	eApp.appendChild(eAppName);
	
	Element eAppDescr = document.createElement("descr");
	String descr = StringUtils.abbreviate(mobileApplication.getApplicationDescription(), 100);
	eAppDescr.setTextContent(descr);
	eApp.appendChild(eAppDescr);
	eApp.appendChild(document.createElement("platforms"));
	
	projectElement.appendChild(eApp);
	
	return projectElement;
}
 
Example 5
Project: kaltura-ce-sakai-extension   File: KalturaAPIService.java   Source Code and License Vote up 5 votes
/**
 * creates a category name that is <= 50 characters and is unique
 * 
 * @param categoryName the name of the category
 * @return the safe category name
 * @throws IllegalArgumentException if playlist name is invalid
 */
@NoProfile
protected String makeSafeCategoryName(String categoryName) {
    categoryName = StringUtils.trimToNull(categoryName);
    if (categoryName == null) {
        throw new IllegalArgumentException("categoryName cannot be null");
    }
    if (categoryName.length() > CATEGORY_MAX_LENGTH) {
        categoryName = StringUtils.abbreviate(categoryName, CATEGORY_MAX_LENGTH);
        categoryName = categoryName.substring(0, CATEGORY_MAX_LENGTH-3) + RandomStringUtils.randomAlphanumeric(3);
    }
    return categoryName;
}
 
Example 6
Project: Hydrograph   File: GraphPropertiesHandler.java   Source Code and License Vote up 5 votes
private  String getCurrentGraphName()
{
	String graphName= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput().getName();
	graphName = StringUtils.remove(graphName, Constants.JOB_EXTENSION);
	graphName = StringUtils.abbreviate(graphName, 20);
	return graphName;
}