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

The following are Jave code examples for showing how to use startsWith() 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.
+ Save this method
Example 1
Project: kaltura-ce-sakai-extension   File: SakaiExternalLogicImpl.java   View Source Code Vote up 7 votes
public void currentAllowAdminAccess() {
    if (securityAdvisorTL.get() == null) {
        // only set the advisor if there is not already one
        SecurityAdvisor securityAdvisor = new SecurityAdvisor() {
            public SecurityAdvice isAllowed(String userId, String function, String reference) {
                if (StringUtils.startsWith(function, KALTURA_PREFIX)) {
                    return SecurityAdvice.ALLOWED;
                }
                return SecurityAdvice.PASS;
            }
        };
        securityAdvisorTL.set(securityAdvisor);
    }
    securityService.pushAdvisor( securityAdvisorTL.get() );
    if (StringUtils.isBlank(getCurrentUserId())) {
        // force a current user to the admin if there is not one right now
        String adminUserRef = developerHelperService.getUserRefFromUserId(getAdminUserId());
        developerHelperService.setCurrentUser(adminUserRef);
    }
}
 
Example 2
Project: Hydrograph   File: IntegerOrParameterValidationRule.java   View Source Code Vote up 7 votes
@Override
public boolean validate(Object object, String propertyName,Map<String,List<FixedWidthGridRow>> inputSchemaMap,
		boolean isJobImported){
	String value = (String) object;
	if(StringUtils.isNotBlank(value)){
		Matcher matcher=Pattern.compile("[\\d]*").matcher(value);
		if((matcher.matches())|| 
			((StringUtils.startsWith(value, "@{") && StringUtils.endsWith(value, "}")) &&
					!StringUtils.contains(value, "@{}"))){
			return true;
		}
		errorMessage = propertyName + " is mandatory";
	}
	errorMessage = propertyName + " is not integer value or valid parameter";
	return false;
}
 
Example 3
Project: mxisd   File: RestBackendConfig.java   View Source Code Vote up 6 votes
private String buildEndpointUrl(String endpoint) {
    if (StringUtils.startsWith(endpoint, "/")) {
        if (StringUtils.isBlank(getHost())) {
            throw new ConfigurationException("rest.host");
        }

        try {
            new URL(getHost());
        } catch (MalformedURLException e) {
            throw new ConfigurationException("rest.host", e.getMessage());
        }

        return getHost() + endpoint;
    } else {
        return endpoint;
    }
}
 
Example 4
Project: Hydrograph   File: PreStartActivity.java   View Source Code Vote up 6 votes
private void restartHydrograph() {
	logger.info("Starting New Hydrograph");
	String path = Platform.getInstallLocation().getURL().getPath();
	if ((StringUtils.isNotBlank(path)) && (StringUtils.startsWith(path, "/")) && (OSValidator.isWindows())) {
		path = StringUtils.substring(path, 1);
	}
	String command = path + HYDROGRAPH_EXE;
	Runtime runtime = Runtime.getRuntime();
	try {
		if (OSValidator.isWindows()) {
			String[] commandArray = { "cmd.exe", "/c", command };
			runtime.exec(commandArray);
		}
	} catch (IOException ioException) {
		logger.error("Exception occurred while starting hydrograph" + ioException);
	}
	System.exit(0);
}
 
Example 5
Project: Hydrograph   File: DataViewerUtility.java   View Source Code Vote up 6 votes
public void closeDataViewerWindows(Job job) {
	if(job==null){
		return;
	}
	
	List<DebugDataViewer> dataViewerList = new ArrayList<>(); 
	dataViewerList.addAll(JobManager.INSTANCE.getDataViewerMap().values());
			
	Iterator<DebugDataViewer> iterator = dataViewerList.iterator();
	while(iterator.hasNext()){
		
		DebugDataViewer daDebugDataViewer = (DebugDataViewer) iterator.next();
		String windowName=(String) daDebugDataViewer.getDataViewerWindowTitle();
		if(StringUtils.startsWith(windowName, job.getConsoleName().replace(".", "_"))){
			daDebugDataViewer.close();	
			JobManager.INSTANCE.getDataViewerMap().remove(windowName);
			iterator.remove();
		}
		
	}
}
 
Example 6
Project: mxisd   File: GenericTemplateNotificationGenerator.java   View Source Code Vote up 5 votes
private String getTemplateContent(String location) {
    try {
        InputStream is = StringUtils.startsWith(location, "classpath:") ?
                app.getResource(location).getInputStream() : new FileInputStream(location);
        return IOUtils.toString(is, StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new InternalServerError("Unable to read template content at " + location + ": " + e.getMessage());
    }
}
 
Example 7
Project: mxisd   File: GenericTemplateConfig.java   View Source Code Vote up 5 votes
protected static String getName(String path) {
    if (StringUtils.startsWith(path, classpathPrefix)) {
        return "Built-in (" + path.substring(classpathPrefix.length()) + ")";
    }

    return path;
}
 
Example 8
Project: ymate-payment-v2   File: WxPayAccountMeta.java   View Source Code Vote up 5 votes
public void setSandboxPrefix(String sandboxPrefix) {
    sandboxPrefix = StringUtils.defaultIfBlank(sandboxPrefix, "sandboxnew");
    if (StringUtils.startsWith(sandboxPrefix, "/")) {
        sandboxPrefix = StringUtils.substringAfter(sandboxPrefix, "/");
    }
    if (!StringUtils.endsWith(this.sandboxPrefix, "/")) {
        sandboxPrefix = sandboxPrefix + "/";
    }
    this.sandboxPrefix = sandboxPrefix;
}
 
Example 9
Project: Hydrograph   File: FTPProtocolSelectionValidator.java   View Source Code Vote up 5 votes
private boolean validatePort(String text, String propertyName){
	if(StringUtils.isNotBlank(text)){
		Matcher matcher=Pattern.compile("[\\d]*").matcher(text);
		if((matcher.matches())|| 
			((StringUtils.startsWith(text, "@{") && StringUtils.endsWith(text, "}")) &&
					!StringUtils.contains(text, "@{}"))){
			return true;
		}
		errorMessage = propertyName + " is mandatory";
	}
	errorMessage = propertyName + " is not integer value or valid parameter";
	return false;
}
 
Example 10
Project: Hydrograph   File: BuildExpressionEditorDataSturcture.java   View Source Code Vote up 5 votes
@SuppressWarnings("restriction")
public PackageFragmentRoot getSrcPackageFragment(IJavaProject iJavaProject) throws JavaModelException {
	for(IPackageFragmentRoot iPackageFragmentRoot:iJavaProject.getAllPackageFragmentRoots()){
		if(iPackageFragmentRoot instanceof PackageFragmentRoot && iPackageFragmentRoot.getKind()==iPackageFragmentRoot.K_SOURCE){
			if(StringUtils.startsWith(iPackageFragmentRoot.toString(),hydrograph.ui.common.util.Constants.ProjectSupport_SRC)){
				return (PackageFragmentRoot) iPackageFragmentRoot;
			}
		}
	}
	return null;
}
 
Example 11
Project: Hydrograph   File: FunctionsComposite.java   View Source Code Vote up 5 votes
private void performSelectionActivity(List methodsList){
	if (methodsList.getItemCount() != 0
			&& !StringUtils.startsWith(methodsList.getItem(0),Messages.CANNOT_SEARCH_INPUT_STRING)) {
		MethodDetails methodDetails = (MethodDetails) methodsList.getData(String.valueOf(methodsList
				.getSelectionIndex()));
		if (methodDetails != null && StringUtils.isNotBlank(methodDetails.getJavaDoc())) {
			descriptionStyledText.setText(methodDetails.getJavaDoc());
		} else {
			descriptionStyledText.setText(Messages.JAVA_DOC_NOT_AVAILABLE);
		}
	}else{
		
	}
		
}
 
Example 12
Project: Hydrograph   File: ExpressionEditorStyledText.java   View Source Code Vote up 5 votes
@Override
public void insert(String string) {
	if (!StringUtils.startsWith(StringUtils.trim(string),Messages.CANNOT_SEARCH_INPUT_STRING)) {
		super.insert(string);
		this.setFocus();
		this.setSelection(this.getText().length() + 100);
	}
}
 
Example 13
Project: Hydrograph   File: ApplicationWorkbenchWindowAdvisor.java   View Source Code Vote up 5 votes
private static String getInstallationConfigPath()  {
	String path = Platform.getInstallLocation().getURL().getPath();
	if(StringUtils.isNotBlank(path) && StringUtils.startsWith(path, "/") && OSValidator.isWindows()){
		path = StringUtils.substring(path, 1);
	}
	
	return path + "config/service/config" ;
}
 
Example 14
Project: athena   File: DefaultGangliaMetricsReporter.java   View Source Code Vote up 5 votes
/**
 * Looks up whether the metric name contains the given prefix keywords.
 * Note that the keywords are separated with comma as delimiter
 *
 * @param full the original metric name that to be compared with
 * @param prefixes the prefix keywords that are matched against with the metric name
 * @return boolean value that denotes whether the metric name starts with the given prefix
 */
protected boolean containsName(String full, String prefixes) {
    String[] prefixArray = StringUtils.split(prefixes, ",");
    for (String prefix : prefixArray) {
        if (StringUtils.startsWith(full, StringUtils.trimToEmpty(prefix))) {
            return true;
        }
    }
    return false;
}
 
Example 15
Project: athena   File: DefaultGraphiteMetricsReporter.java   View Source Code Vote up 5 votes
/**
 * Looks up whether the metric name contains the given prefix keywords.
 * Note that the keywords are separated with comma as delimiter
 *
 * @param full the original metric name that to be compared with
 * @param prefixes the prefix keywords that are matched against with the metric name
 * @return boolean value that denotes whether the metric name starts with the given prefix
 */
protected boolean containsName(String full, String prefixes) {
    String[] prefixArray = StringUtils.split(prefixes, ",");
    for (String prefix : prefixArray) {
        if (StringUtils.startsWith(full, StringUtils.trimToEmpty(prefix))) {
            return true;
        }
    }
    return false;
}
 
Example 16
Project: athena   File: DefaultInfluxDbMetricsReporter.java   View Source Code Vote up 5 votes
/**
 * Looks up whether the metric name contains the given prefix keywords.
 * Note that the keywords are separated with comma as delimiter.
 *
 * @param full the original metric name that to be compared with
 * @param prefixes the prefix keywords that are matched against with the metric name
 * @return boolean value that denotes whether the metric name starts with the given prefix
 */
protected boolean containsName(String full, String prefixes) {
    String[] prefixArray = StringUtils.split(prefixes, ",");
    for (String prefix : prefixArray) {
        if (StringUtils.startsWith(full, StringUtils.trimToEmpty(prefix))) {
            return true;
        }
    }
    return false;
}
 
Example 17
Project: kaltura-ce-sakai-extension   File: KalturaEntityProvider.java   View Source Code Vote up 4 votes
@EntityCustomAction(action="libraryadd", viewKey=EntityView.VIEW_NEW)
public Object addToLibrary(EntityView view, Search search, Map<String, Object> data) {
    // POST /kaltura/libraryadd/{keid}/site/{siteId}
    // POST /kaltura/libraryadd/{keid}/tool/{toolId}
    String locationId = null;
    String locType = view.getPathSegment(3);
    String locId = view.getPathSegment(4);

    if ("tool".equals(locType)) {
        locationId = getLocationIdFromToolId(locId);
    } else {
        locationId = "/"+locType+"/"+locId;
    }
    if (locationId == null) {
        locationId = developerHelperService.getCurrentLocationReference();
    }
    // SKE-222 check for user's workspace site lib and correct the location id
    if (StringUtils.startsWith(locationId, "/site/~")) {
        locationId = "/site/~" + external.getCurrentUserId();
    }
    if (data == null) {
        data = new HashMap<String, Object>();
    }
    String[] eids = null;

    // retrieve ids from the data structure
    Object eidsObj = data.get("eids[]");
    String mediaItemId = "";
    if (eidsObj == null) { // pull from command line
        eids = new String[1];
        eids[0] = view.getPathSegment(2);
    } else if (eidsObj instanceof String) { // only one eid
        eids = new String[1];
        eids[0] = (String) eidsObj;
    } else if (eidsObj instanceof String[]) { // multiple eids
        eids = (String[]) eidsObj;
    } else { // something is wrong if we get here
        throw new IllegalArgumentException("expects a URL like: POST /kaltura/libraryadd/{keid}/site/{locationId} OR POST /kaltura/libraryadd/{keid}/tool/{toolId}");
    }
    String collectionId = data.containsKey("collectionId") ? data.get("collectionId").toString() : null;
    for (String kalturaId : eids) {
        if (kalturaId == null || locType == null || locId == null) {
            throw new IllegalArgumentException("expects a URL like: POST /kaltura/libraryadd/{keid}/site/{locationId} OR POST /kaltura/libraryadd/{keid}/tool/{toolId}");
        }
        mediaItemId = service.addKalturaItemToLibrary(locationId, kalturaId);
        // add the item to the collection as well IF the collectionId is set
        if (StringUtils.isNotEmpty(collectionId) && !StringUtils.substringAfterLast(locationId, "/site/").equals(collectionId)) {
            service.addKalturaItemToCollection(collectionId, locationId, mediaItemId, 0);
        }
    }
    ActionReturn ar = new ActionReturn(mediaItemId);
    ar.setResponseCode(HttpServletResponse.SC_CREATED);
    return ar;
}
 
Example 18
Project: kaltura-ce-sakai-extension   File: KalturaAPIService.java   View Source Code Vote up 4 votes
/**
 * Decodes the permissions string into a map of values.
 * Keys: containerType, containerId, Owner, Hidden, Reusable, Remixable
 * 
 * @param permissionString the string representation of the permissions
 *      ("site:<siteId>::{<ownerId>}h,S,r" OR "playlist:<playlistId>::{<ownerId>}h,S,r")
 * @param failIfInvalid if true then this will throw an exception if the input string is invalid, otherwise it will return defaults
 * @return Map of permission data OR defaults if input string is invalid
 * @throws IllegalArgumentException if the string decoding fails
 */
protected Map<String, String> decodeMetadataPermissions(String permissionString, boolean failIfInvalid) {
    Map<String, String> decodedPermissions = new HashMap<String, String>(6);
    // check if permissions string is a valid format
    if (StringUtils.isNotEmpty(permissionString) 
            && StringUtils.contains(permissionString, "::{") 
            && (StringUtils.startsWith(permissionString, "site:") || StringUtils.startsWith(permissionString, "playlist:"))) {
        // first find the last "}" in the string (first from the right)
        int braceRight = StringUtils.lastIndexOf(permissionString, '}');
        if (braceRight == -1) {
            throw new IllegalArgumentException("Invalid format- no '}' (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        // find the last "::{" from the right of the brace
        int braceLeft = StringUtils.lastIndexOf(permissionString, "::{", braceRight);
        if (braceLeft == -1) {
            throw new IllegalArgumentException("Invalid format - no '::{' (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        // chop the string into the 3 parts dropping the braces and :: separators
        String containerStr = StringUtils.substring(permissionString, 0, braceLeft);
        braceLeft += 2; // shift over to the actual brace
        String ownerId = StringUtils.substring(permissionString, braceLeft+1, braceRight);
        if (StringUtils.isEmpty(ownerId)) {
            throw new IllegalArgumentException("Invalid format - no ownerId (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        decodedPermissions.put(METADATA_OWNER, ownerId);
        // get the containerId from the first piece
        if (StringUtils.startsWith(containerStr, "site:")) {
            decodedPermissions.put(METADATA_CONTAINER_TYPE, "site");
            decodedPermissions.put(METADATA_CONTAINER_ID, StringUtils.substring(containerStr, 5));
        } else if (StringUtils.startsWith(containerStr, "playlist:")) {
            decodedPermissions.put(METADATA_CONTAINER_TYPE, "playlist");
            decodedPermissions.put(METADATA_CONTAINER_ID, StringUtils.substring(containerStr, 9));
        } else {
            // should never really happen
            throw new IllegalArgumentException("Invalid format - bad prefix (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        if (StringUtils.isEmpty(decodedPermissions.get(METADATA_CONTAINER_ID))) {
            throw new IllegalArgumentException("Invalid format - no containerId (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        // split the permissions
        String perms = StringUtils.substring(permissionString, braceRight+1);
        if (StringUtils.isEmpty(perms)) {
            throw new IllegalArgumentException("Invalid format - no perms (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        // get the permissions ([0] = hidden, [1] = reusable, [2] = remixable)
        String[] permissions = StringUtils.split(perms, ',');
        decodedPermissions.put(METADATA_HIDDEN, permissions[0]);
        decodedPermissions.put(METADATA_REUSABLE, permissions[1]);
        decodedPermissions.put(METADATA_REMIXABLE, permissions[2]);

    } else { // load default metadata
        if (failIfInvalid) {
            throw new IllegalArgumentException("Invalid string format - fails to match basic rules (e.g. not empty, contains '::{' and starts with 'site' or 'playlist') for permissions string: "+permissionString);
        } else {
            decodedPermissions.put(METADATA_CONTAINER_TYPE, "");
            decodedPermissions.put(METADATA_CONTAINER_ID, "");
            decodedPermissions.put(METADATA_OWNER, null);
            decodedPermissions.put(METADATA_HIDDEN, DEFAULT_METADATA_HIDDEN);
            decodedPermissions.put(METADATA_REUSABLE, DEFAULT_METADATA_REUSABLE);
            decodedPermissions.put(METADATA_REMIXABLE, DEFAULT_METADATA_REMIXABLE);
        }
    }
    return decodedPermissions;
}
 
Example 19
Project: Hydrograph   File: Schema.java   View Source Code Vote up 2 votes
/**
 * Sets the external schema path.
 * 
 * @param externalSchemaPath
 *            the new external schema path
 */
public void setExternalSchemaPath(String externalSchemaPath) {
	if(StringUtils.startsWith(externalSchemaPath, RELATIVE_PATH_PREFIX))
		externalSchemaPath=StringUtils.replace(externalSchemaPath, RELATIVE_PATH_PREFIX,"");
	this.externalSchemaPath = externalSchemaPath;
}