List of usage examples for org.apache.commons.lang StringUtils chomp
public static String chomp(String str, String separator)
Removes separator
from the end of str
if it's there, otherwise leave it alone.
From source file:org.jboss.tools.openshift.reddeer.requirement.OpenShiftCommandLineToolsRequirement.java
private String extractArchive(String fileName, File outputDirectory) { if (StringUtils.isEmpty(fileName)) { return null; }//from w w w. j av a2 s. c o m LOGGER.info(NLS.bind("Extracting OpenShift archive {0}.", fileName)); String extractedDirectory = null; if (fileName.endsWith(SUFFIX_ZIP)) { extractedDirectory = StringUtils.chomp(fileName, SUFFIX_ZIP); FileHelper.unzipFile(new File(fileName), outputDirectory); } else if (fileName.endsWith(SUFFIX_TAR_GZ)) { extractedDirectory = StringUtils.chomp(fileName, SUFFIX_TAR_GZ); FileHelper.extractTarGz(new File(fileName), outputDirectory); } return extractedDirectory; }
From source file:org.kuali.rice.kew.actionrequest.ActionRequestFactory.java
/** * Generates an ActionRequest graph for the given KIM Responsibilities. This graph includes any associated delegations. * @param responsibilities/*www. j a v a 2s. c om*/ * @param approvePolicy */ public void addRoleResponsibilityRequest(List<ResponsibilityAction> responsibilities, String approvePolicy) { if (responsibilities == null || responsibilities.isEmpty()) { LOG.warn( "Didn't create action requests for action request description because no responsibilities were defined."); return; } // it's assumed the that all in the list have the same action type code, priority number, etc. String actionTypeCode = responsibilities.get(0).getActionTypeCode(); Integer priority = responsibilities.get(0).getPriorityNumber(); boolean forceAction = responsibilities.get(0).isForceAction(); KimRoleResponsibilityRecipient roleResponsibilityRecipient = new KimRoleResponsibilityRecipient( responsibilities); // Creation of a parent graph entry for ???? ActionRequestValue requestGraph = null; StringBuffer parentAnnotation = null; // set to allow for suppression of duplicate annotations on the parent action request Set<String> uniqueChildAnnotations = null; if (responsibilities.size() > 1) { requestGraph = createActionRequest(actionTypeCode, priority, roleResponsibilityRecipient, "", // description KewApiConstants.MACHINE_GENERATED_RESPONSIBILITY_ID, forceAction, approvePolicy, null, // ruleId null);// annotation requestGraphs.add(requestGraph); parentAnnotation = new StringBuffer(); uniqueChildAnnotations = new HashSet<String>(responsibilities.size()); } StringBuffer annotation = new StringBuffer(); for (ResponsibilityAction responsibility : responsibilities) { if (LOG.isDebugEnabled()) { LOG.debug("Processing Responsibility for action request: " + responsibility); } // KFSMI-2381 - pull information from KIM to populate annotation annotation.setLength(0); Role role = getRoleService().getRole(responsibility.getRoleId()); annotation.append(role.getNamespaceCode()).append(' ').append(role.getName()).append(' '); Map<String, String> qualifier = responsibility.getQualifier(); if (qualifier != null) { for (String key : qualifier.keySet()) { annotation.append(qualifier.get(key)).append(' '); } } if (responsibility.getPrincipalId() != null) { roleResponsibilityRecipient.setTarget(new KimPrincipalRecipient(responsibility.getPrincipalId())); } else if (responsibility.getGroupId() != null) { roleResponsibilityRecipient.setTarget(new KimGroupRecipient(responsibility.getGroupId())); } else { throw new RiceRuntimeException( "Failed to identify a group or principal on the given ResponsibilityResolutionInfo:" + responsibility); } String annotationStr = annotation.toString(); ActionRequestValue request = createActionRequest(responsibility.getActionTypeCode(), responsibility.getPriorityNumber(), roleResponsibilityRecipient, responsibility.getParallelRoutingGroupingCode(), // description responsibility.getResponsibilityId(), responsibility.isForceAction(), // If not nested in a parent action request, ensure that the request // is first approve so delegations of this request do not require // ALL_APPROVE as well (responsibilities.size() == 1) ? ActionRequestPolicy.FIRST.getCode() : approvePolicy, null, // ruleId annotationStr); // if there is only a single request, don't create the nesting structure if (responsibilities.size() > 1) { request.setParentActionRequest(requestGraph); requestGraph.getChildrenRequests().add(request); if (!uniqueChildAnnotations.contains(annotationStr)) { parentAnnotation.append(annotationStr).append(" -- "); uniqueChildAnnotations.add(annotationStr); } } else { requestGraphs.add(request); } generateKimRoleDelegationRequests(responsibility.getDelegates(), request); } if (responsibilities.size() > 1) { requestGraph.setAnnotation(StringUtils.chomp(parentAnnotation.toString(), " -- ")); } }
From source file:org.kuali.rice.kim.impl.permission.UberPermissionBo.java
public String getAssignedToRolesToDisplay() { StringBuffer assignedToRolesText = new StringBuffer(); for (RoleBo roleImpl : assignedToRoles) { assignedToRolesText.append(roleImpl.getNamespaceCode().trim()).append(" ") .append(roleImpl.getName().trim()).append(KimConstants.KimUIConstants.COMMA_SEPARATOR); }/*from ww w.j av a 2s. c o m*/ return StringUtils.chomp(assignedToRolesText.toString(), KimConstants.KimUIConstants.COMMA_SEPARATOR); }
From source file:org.kuali.rice.kim.impl.responsibility.UberResponsibilityBo.java
public String getAssignedToRolesToDisplay() { StringBuffer assignedToRolesToDisplay = new StringBuffer(); for (RoleBo roleImpl : assignedToRoles) { assignedToRolesToDisplay.append(getRoleDetailsToDisplay(roleImpl)); }// ww w . ja v a 2s.c o m return StringUtils.chomp(assignedToRolesToDisplay.toString(), KimConstants.KimUIConstants.COMMA_SEPARATOR); }
From source file:org.kuali.rice.krad.service.impl.DictionaryValidationServiceImpl.java
protected void validateUpdatabableReferencesRecursively(Object businessObject, int maxDepth, boolean validateRequired, boolean chompLastLetterSFromCollectionName, Set<Object> processedBOs) { // if null or already processed, return if (KRADUtils.isNull(businessObject) || processedBOs.contains(businessObject)) { return;/* w w w .j a va 2 s .c om*/ } processedBOs.add(businessObject); // add bo to list to prevent excessive looping Map<String, Class> references = getLegacyDataAdapter().listReferenceObjectFields(businessObject.getClass()); for (String referenceName : references.keySet()) { if (getLegacyDataAdapter().isReferenceUpdatable(businessObject.getClass(), referenceName)) { Object referenceObj = KradDataServiceLocator.getDataObjectService().wrap(businessObject) .getPropertyValueNullSafe(referenceName); if (KRADUtils.isNull(referenceObj) || !(referenceObj instanceof PersistableBusinessObject)) { continue; } BusinessObject referenceBusinessObject = (BusinessObject) referenceObj; GlobalVariables.getMessageMap().addToErrorPath(referenceName); validateBusinessObject(referenceBusinessObject, validateRequired); if (maxDepth > 0) { validateUpdatabableReferencesRecursively(referenceBusinessObject, maxDepth - 1, validateRequired, chompLastLetterSFromCollectionName, processedBOs); } GlobalVariables.getMessageMap().removeFromErrorPath(referenceName); } } Map<String, Class> collections = getLegacyDataAdapter() .listCollectionObjectTypes(businessObject.getClass()); for (String collectionName : collections.keySet()) { if (getLegacyDataAdapter().isCollectionUpdatable(businessObject.getClass(), collectionName)) { Object listObj = KradDataServiceLocator.getDataObjectService().wrap(businessObject) .getPropertyValueNullSafe(collectionName); if (KRADUtils.isNull(listObj)) { continue; } if (!(listObj instanceof List)) { if (LOG.isInfoEnabled()) { LOG.info("The reference named " + collectionName + " of BO class " + businessObject.getClass().getName() + " should be of type java.util.List to be validated properly."); } continue; } List list = (List) listObj; //should we materialize the proxied collection or just skip validation here assuming an unmaterialized objects are valid? KRADUtils.materializeObjects(list); for (int i = 0; i < list.size(); i++) { final Object o = list.get(i); if (KRADUtils.isNotNull(o) && o instanceof PersistableBusinessObject) { final BusinessObject element = (BusinessObject) o; final String errorPathAddition; if (chompLastLetterSFromCollectionName) { errorPathAddition = StringUtils.chomp(collectionName, "s") + "[" + Integer.toString(i) + "]"; } else { errorPathAddition = collectionName + "[" + Integer.toString(i) + "]"; } GlobalVariables.getMessageMap().addToErrorPath(errorPathAddition); validateBusinessObject(element, validateRequired); if (maxDepth > 0) { validateUpdatabableReferencesRecursively(element, maxDepth - 1, validateRequired, chompLastLetterSFromCollectionName, processedBOs); } GlobalVariables.getMessageMap().removeFromErrorPath(errorPathAddition); } } } } }
From source file:org.kuali.rice.krad.service.impl.DictionaryValidationServiceImpl.java
/** * iterates through the property descriptors looking for business objects or lists of business objects. calls * validate method/*from w ww. ja va 2 s. c o m*/ * for each bo found * * @param object * @param propertyDescriptors */ protected void validateBusinessObjectsFromDescriptors(Object object, PropertyDescriptor[] propertyDescriptors, int depth) { DataObjectWrapper<Object> wrapper = KradDataServiceLocator.getDataObjectService().wrap(object); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { // validate the properties that are descended from BusinessObject if (propertyDescriptor.getPropertyType() != null && PersistableBusinessObject.class.isAssignableFrom(propertyDescriptor.getPropertyType()) && wrapper.getPropertyValueNullSafe(propertyDescriptor.getName()) != null) { BusinessObject bo = (BusinessObject) wrapper.getPropertyValueNullSafe(propertyDescriptor.getName()); if (depth == 0) { GlobalVariables.getMessageMap().addToErrorPath(propertyDescriptor.getName()); validateBusinessObject(bo); GlobalVariables.getMessageMap().removeFromErrorPath(propertyDescriptor.getName()); } else { validateBusinessObjectsRecursively(bo, depth - 1); } } /* * if property is a List, then walk the list and do the validation on each contained object that is a descendent of * BusinessObject */ else if (propertyDescriptor.getPropertyType() != null && (List.class).isAssignableFrom(propertyDescriptor.getPropertyType()) && wrapper.getPropertyValueNullSafe(propertyDescriptor.getName()) != null) { List propertyList = (List) wrapper.getPropertyValueNullSafe(propertyDescriptor.getName()); for (int j = 0; j < propertyList.size(); j++) { if (propertyList.get(j) != null && propertyList.get(j) instanceof PersistableBusinessObject) { if (depth == 0) { GlobalVariables.getMessageMap() .addToErrorPath(StringUtils.chomp(propertyDescriptor.getName(), "s") + "[" + (new Integer(j)).toString() + "]"); validateBusinessObject((BusinessObject) propertyList.get(j)); GlobalVariables.getMessageMap() .removeFromErrorPath(StringUtils.chomp(propertyDescriptor.getName(), "s") + "[" + (new Integer(j)).toString() + "]"); } else { validateBusinessObjectsRecursively((BusinessObject) propertyList.get(j), depth - 1); } } } } } }
From source file:org.lockss.plugin.anthrosource.AnthroSourceUrlNormalizer.java
public String normalizeUrl(String url, ArchivalUnit au) throws PluginException { return StringUtils.chomp(url, SUFFIX); }
From source file:org.lockss.plugin.bioone.BioOneAtyponUrlNormalizer.java
@Override public String normalizeUrl(String url, ArchivalUnit au) throws PluginException { int ind;/*from ww w. j ava2 s.c om*/ // Normalize ending ind = url.indexOf('?'); if (ind >= 0) { for (String ending : endings) { url = StringUtils.chomp(url, ending); } } // Normalize ending // example: http://www.bioone.org/toc/brvo/512?seq=512 ind = url.indexOf("?seq="); if (ind >= 0) { url = url.substring(0, ind); } // call the parent to handle citation download URLs return super.normalizeUrl(url, au); }
From source file:org.lockss.plugin.nature.NaturePublishingGroupUrlNormalizer.java
public String normalizeUrl(String url, ArchivalUnit au) throws PluginException { return StringUtils.chomp(url, MESSAGE_ENDING); }
From source file:org.lockss.plugin.taylorandfrancis.TaylorAndFrancisUrlNormalizer.java
@Override public String normalizeUrl(String url, ArchivalUnit au) throws PluginException { // Normalize double-slash int ind = url.indexOf("://"); if (ind >= 0) { ind = url.indexOf("//", ind + 3); if (ind >= 0) { url = url.substring(0, ind) + url.substring(ind + 1); }/*w w w. j a va2s . c o m*/ } return StringUtils.chomp(url, "?cookieSet=1"); }