List of usage examples for org.apache.commons.lang StringUtils startsWith
public static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
From source file:org.kuali.maven.plugins.externals.SVNUtils.java
protected SVNURL[] getSvnUrlArray(List<File> files) { String singleSlashPrefix = "file:/"; String doubleSlashPrefix = "file://"; SVNURL[] array = new SVNURL[files.size()]; for (int i = 0; i < files.size(); i++) { File file = files.get(i); String fileUrlString = file.toURI().toString(); boolean singleSlash = StringUtils.startsWith(fileUrlString, singleSlashPrefix); boolean doubleSlash = StringUtils.startsWith(fileUrlString, doubleSlashPrefix); if (singleSlash && !doubleSlash) { fileUrlString = StringUtils.replace(fileUrlString, singleSlashPrefix, doubleSlashPrefix); }//ww w . j av a2 s .c o m SVNURL fileUrl = getSvnUrl(fileUrlString); array[i] = fileUrl; } return array; }
From source file:org.kuali.rice.kim.util.KimCommonUtils.java
public static boolean doesPropertyNameMatch(String requestedDetailsPropertyName, String permissionDetailsPropertyName) { if (StringUtils.isBlank(permissionDetailsPropertyName)) { return true; }/*from w w w. j av a 2 s .c om*/ return StringUtils.equals(requestedDetailsPropertyName, permissionDetailsPropertyName) || (StringUtils.startsWith(requestedDetailsPropertyName, permissionDetailsPropertyName + ".")); }
From source file:org.kuali.rice.kns.util.WebUtils.java
/** * Attempts to reopen sub tabs which would have been closed for inactive records * * @param sections the list of Sections whose rows and fields to set the open tab state on * @param tabStates the map of tabKey->tabState. This map will be modified to set entries to "OPEN" * @param collectionName the name of the collection reopening *//* w ww . j av a2 s. c o m*/ public static void reopenInactiveRecords(List<Section> sections, Map<String, String> tabStates, String collectionName) { for (Section section : sections) { for (Row row : section.getRows()) { for (Field field : row.getFields()) { if (field != null) { if (Field.CONTAINER.equals(field.getFieldType()) && StringUtils.startsWith(field.getContainerName(), collectionName)) { final String tabKey = WebUtils .generateTabKey(FieldUtils.generateCollectionSubTabName(field)); tabStates.put(tabKey, KualiForm.TabState.OPEN.name()); } } } } } }
From source file:org.kuali.rice.krad.lookup.LookupUtils.java
/** * Retrieves the value for the given parameter name to send as a lookup parameter. * * @param form form instance to retrieve values from * @param request request object to retrieve parameters from * @param lookupObjectClass data object class associated with the lookup, used to check whether the * value needs to be encyrpted/*from ww w .jav a2s. co m*/ * @param propertyName name of the property associated with the parameter, used to check whether the * value needs to be encrypted * @param parameterName name of the parameter to retrieve the value for * @return String parameter value or empty string if no value was found */ public static String retrieveLookupParameterValue(UifFormBase form, HttpServletRequest request, Class<?> lookupObjectClass, String propertyName, String parameterName) { String parameterValue = ""; // get literal parameter values first if (StringUtils.startsWith(parameterName, "'") && StringUtils.endsWith(parameterName, "'")) { parameterValue = StringUtils.substringBetween(parameterName, "'"); } else if (parameterValue.startsWith( KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER)) { parameterValue = StringUtils.removeStart(parameterValue, KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER); } // check if parameter is in request else if (request.getParameterMap().containsKey(parameterName)) { parameterValue = request.getParameter(parameterName); } // get parameter value from form object else { parameterValue = ObjectPropertyUtils.getPropertyValueAsText(form, parameterName); } if (parameterValue != null && lookupObjectClass != null && KRADServiceLocatorWeb.getDataObjectAuthorizationService() .attributeValueNeedsToBeEncryptedOnFormsAndLinks(lookupObjectClass, propertyName)) { try { if (CoreApiServiceLocator.getEncryptionService().isEnabled()) { parameterValue = CoreApiServiceLocator.getEncryptionService().encrypt(parameterValue) + EncryptionService.ENCRYPTION_POST_PREFIX; } } catch (GeneralSecurityException e) { LOG.error("Unable to encrypt value for property name: " + propertyName); throw new RuntimeException(e); } } return parameterValue; }
From source file:org.kuali.rice.krad.service.impl.MaintainableXMLConversionServiceImpl.java
private void setRuleMaps() { setupConfigurationMaps();/*from w w w .j ava2s .c o m*/ try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); AbstractResource resource = null; Document doc = null; if (StringUtils.startsWith(this.getConversionRuleFile(), "classpath")) { resource = new ClassPathResource(this.getConversionRuleFile(), Thread.currentThread().getContextClassLoader()); } else { resource = new FileSystemResource(this.getConversionRuleFile()); } if (!resource.exists()) { doc = db.parse(this.getClass().getResourceAsStream(this.getConversionRuleFile())); } else { doc = db.parse(resource.getInputStream()); } doc.getDocumentElement().normalize(); XPath xpath = XPathFactory.newInstance().newXPath(); // Get the moved classes rules XPathExpression exprClassNames = xpath.compile("//*[@name='maint_doc_classname_changes']/pattern"); NodeList classNamesList = (NodeList) exprClassNames.evaluate(doc, XPathConstants.NODESET); for (int s = 0; s < classNamesList.getLength(); s++) { String matchText = xpath.evaluate("match/text()", classNamesList.item(s)); String replaceText = xpath.evaluate("replacement/text()", classNamesList.item(s)); classNameRuleMap.put(matchText, replaceText); } // Get the property changed rules XPathExpression exprClassProperties = xpath .compile("//*[@name='maint_doc_changed_class_properties']/pattern"); XPathExpression exprClassPropertiesPatterns = xpath.compile("pattern"); NodeList propertyClassList = (NodeList) exprClassProperties.evaluate(doc, XPathConstants.NODESET); for (int s = 0; s < propertyClassList.getLength(); s++) { String classText = xpath.evaluate("class/text()", propertyClassList.item(s)); Map<String, String> propertyRuleMap = new HashMap<String, String>(); NodeList classPropertiesPatterns = (NodeList) exprClassPropertiesPatterns .evaluate(propertyClassList.item(s), XPathConstants.NODESET); for (int c = 0; c < classPropertiesPatterns.getLength(); c++) { String matchText = xpath.evaluate("match/text()", classPropertiesPatterns.item(c)); String replaceText = xpath.evaluate("replacement/text()", classPropertiesPatterns.item(c)); propertyRuleMap.put(matchText, replaceText); } classPropertyRuleMap.put(classText, propertyRuleMap); } } catch (Exception e) { System.out.println("Error parsing rule xml file. Please check file. : " + e.getMessage()); e.printStackTrace(); } }
From source file:org.kuali.rice.krad.uif.field.InitializeDataFieldFromDictionaryTask.java
/** * Recursively drills down the property path (if nested) to find an AttributeDefinition, the * first attribute definition found will be returned * //from w w w.j a v a 2 s .c o m * <p> * e.g. suppose parentPath is 'document' and propertyPath is 'account.subAccount.name', first * the property type for document will be retrieved using the view metadata and used as the * dictionary entry, with the propertyPath as the dictionary attribute, if an attribute * definition exists it will be returned. Else, the first part of the property path is added to * the parent, making the parentPath 'document.account' and the propertyPath 'subAccount.name', * the method is then called again to perform the process with those parameters. The recursion * continues until an attribute field is found, or the propertyPath is no longer nested * </p> * * @param propertyPath path of the property to use as dictionary attribute and to drill down on * @return AttributeDefinition if found, or Null */ protected AttributeDefinition findNestedDictionaryAttribute(String propertyPath) { DataField field = (DataField) getElementState().getElement(); String fieldBindingPrefix = null; String dictionaryAttributePath = propertyPath; if (field.getBindingInfo().isBindToMap()) { fieldBindingPrefix = ""; if (!field.getBindingInfo().isBindToForm() && StringUtils.isNotBlank(field.getBindingInfo().getBindingObjectPath())) { fieldBindingPrefix = field.getBindingInfo().getBindingObjectPath(); } if (StringUtils.isNotBlank(field.getBindingInfo().getBindByNamePrefix())) { if (StringUtils.isNotBlank(fieldBindingPrefix)) { fieldBindingPrefix += "." + field.getBindingInfo().getBindByNamePrefix(); } else { fieldBindingPrefix = field.getBindingInfo().getBindByNamePrefix(); } } dictionaryAttributePath = field.getBindingInfo().getBindingName(); } if (StringUtils.isEmpty(dictionaryAttributePath)) { return null; } if (StringUtils.startsWith(dictionaryAttributePath, KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { dictionaryAttributePath = StringUtils.substringAfter(dictionaryAttributePath, KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX); } AttributePathEntry attributePathEntry = new AttributePathEntry(fieldBindingPrefix); ObjectPathExpressionParser.parsePathExpression(attributePathEntry, dictionaryAttributePath, attributePathEntry); // if a definition was found, update the fields dictionary properties if (attributePathEntry.attributeDefinition != null) { field.setDictionaryObjectEntry(attributePathEntry.dictionaryObjectEntry); field.setDictionaryAttributeName(attributePathEntry.dictionaryAttributeName); } return attributePathEntry.attributeDefinition; }
From source file:org.kuali.rice.krad.uif.lifecycle.initialize.InitializeDataFieldFromDictionaryTask.java
/** * Recursively drills down the property path (if nested) to find an AttributeDefinition, the * first attribute definition found will be returned * //from w w w .j av a 2 s.c om * <p> * e.g. suppose parentPath is 'document' and propertyPath is 'account.subAccount.name', first * the property type for document will be retrieved using the view metadata and used as the * dictionary entry, with the propertyPath as the dictionary attribute, if an attribute * definition exists it will be returned. Else, the first part of the property path is added to * the parent, making the parentPath 'document.account' and the propertyPath 'subAccount.name', * the method is then called again to perform the process with those parameters. The recursion * continues until an attribute field is found, or the propertyPath is no longer nested * </p> * * @param propertyPath path of the property to use as dictionary attribute and to drill down on * @return AttributeDefinition if found, or Null */ protected AttributeDefinition findNestedDictionaryAttribute(String propertyPath) { DataField field = (DataField) getElementState().getElement(); String fieldBindingPrefix = null; String dictionaryAttributePath = propertyPath; if (field.getBindingInfo().isBindToMap()) { fieldBindingPrefix = ""; if (!field.getBindingInfo().isBindToForm() && StringUtils.isNotBlank(field.getBindingInfo().getBindingObjectPath())) { fieldBindingPrefix = field.getBindingInfo().getBindingObjectPath(); } if (StringUtils.isNotBlank(field.getBindingInfo().getBindByNamePrefix())) { if (StringUtils.isNotBlank(fieldBindingPrefix)) { fieldBindingPrefix += "." + field.getBindingInfo().getBindByNamePrefix(); } else { fieldBindingPrefix = field.getBindingInfo().getBindByNamePrefix(); } } dictionaryAttributePath = field.getBindingInfo().getBindingName(); } if (StringUtils.isEmpty(dictionaryAttributePath)) { return null; } if (StringUtils.startsWith(dictionaryAttributePath, KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { dictionaryAttributePath = StringUtils.substringAfter(dictionaryAttributePath, KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX); } DataDictionaryService ddService = KRADServiceLocatorWeb.getDataDictionaryService(); String dictionaryAttributeName = ObjectPropertyUtils.getCanonicalPath(dictionaryAttributePath); String dictionaryEntryPrefix = fieldBindingPrefix; AttributeDefinition attribute = null; String dictionaryEntryName = null; int i = dictionaryAttributeName.indexOf('.'); while (attribute == null && i != -1) { if (dictionaryEntryPrefix != null) { dictionaryEntryName = getDictionaryEntryName(dictionaryEntryPrefix); dictionaryEntryPrefix += '.' + dictionaryAttributeName.substring(0, i); } else { dictionaryEntryName = null; dictionaryEntryPrefix = dictionaryAttributeName.substring(0, i); } if (dictionaryEntryName != null) { attribute = ddService.getAttributeDefinition(dictionaryEntryName, dictionaryAttributeName); } if (attribute == null) { dictionaryAttributeName = dictionaryAttributeName.substring(i + 1); i = dictionaryAttributeName.indexOf('.'); } } if (attribute == null && dictionaryEntryPrefix != null) { dictionaryEntryName = getDictionaryEntryName(dictionaryEntryPrefix); if (dictionaryEntryName != null) { attribute = ddService.getAttributeDefinition(dictionaryEntryName, dictionaryAttributeName); } } // if a definition was found, update the fields dictionary properties if (attribute != null) { field.setDictionaryObjectEntry(dictionaryEntryName); field.setDictionaryAttributeName(dictionaryAttributeName); } return attribute; }
From source file:org.kuali.rice.krad.uif.service.impl.ExpressionEvaluatorServiceImpl.java
/** * @see org.kuali.rice.krad.uif.service.ExpressionEvaluatorService#evaluateExpression(java.lang.Object, * java.util.Map, java.lang.String) *//* w ww.j a v a 2 s. co m*/ public Object evaluateExpression(Object contextObject, Map<String, Object> evaluationParameters, String expressionStr) { StandardEvaluationContext context = new StandardEvaluationContext(contextObject); context.setVariables(evaluationParameters); addCustomFunctions(context); // if expression contains placeholders remove before evaluating if (StringUtils.startsWith(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX) && StringUtils.endsWith(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX)) { expressionStr = StringUtils.removeStart(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX); expressionStr = StringUtils.removeEnd(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX); } ExpressionParser parser = new SpelExpressionParser(); Object result = null; try { Expression expression = parser.parseExpression(expressionStr); result = expression.getValue(context); } catch (Exception e) { LOG.error("Exception evaluating expression: " + expressionStr); throw new RuntimeException("Exception evaluating expression: " + expressionStr, e); } return result; }
From source file:org.kuali.rice.krad.uif.service.impl.ExpressionEvaluatorServiceImpl.java
/** * Retrieves the Map from the given object that containing the property expressions that should * be evaluated. Each expression is then evaluated and the result is used to set the property value * * <p>/* w w w . j av a2s. co m*/ * If the expression is an el template (part static text and part expression), only the expression * part will be replaced with the result. More than one expressions may be contained within the template * </p> * * @param object - object instance to evaluate expressions for * @param contextObject - object providing the default context for expressions * @param evaluationParameters - map of additional parameters that may be used within the expressions */ protected void evaluatePropertyExpressions(Object object, Object contextObject, Map<String, Object> evaluationParameters) { Map<String, String> propertyExpressions = new HashMap<String, String>(); if (Configurable.class.isAssignableFrom(object.getClass())) { propertyExpressions = ((Configurable) object).getPropertyExpressions(); } for (Entry<String, String> propertyExpression : propertyExpressions.entrySet()) { String propertyName = propertyExpression.getKey(); String expression = propertyExpression.getValue(); // check whether expression should be evaluated or property should retain the expression if (CloneUtils.fieldHasAnnotation(object.getClass(), propertyName, KeepExpression.class)) { // set expression as property value to be handled by the component ObjectPropertyUtils.setPropertyValue(object, propertyName, expression); continue; } Object propertyValue = null; // determine whether the expression is a string template, or evaluates to another object type if (StringUtils.startsWith(expression, UifConstants.EL_PLACEHOLDER_PREFIX) && StringUtils.endsWith(expression, UifConstants.EL_PLACEHOLDER_SUFFIX) && (StringUtils.countMatches(expression, UifConstants.EL_PLACEHOLDER_PREFIX) == 1)) { propertyValue = evaluateExpression(contextObject, evaluationParameters, expression); } else { // treat as string template propertyValue = evaluateExpressionTemplate(contextObject, evaluationParameters, expression); } ObjectPropertyUtils.setPropertyValue(object, propertyName, propertyValue); } }
From source file:org.kuali.rice.krad.uif.util.LookupInquiryUtils.java
public static String retrieveLookupParameterValue(UifFormBase form, HttpServletRequest request, Class<?> lookupObjectClass, String propertyName, String propertyValueName) { String parameterValue = ""; // get literal parameter values first if (StringUtils.startsWith(propertyValueName, "'") && StringUtils.endsWith(propertyValueName, "'")) { parameterValue = StringUtils.removeStart(propertyValueName, "'"); parameterValue = StringUtils.removeEnd(propertyValueName, "'"); } else if (parameterValue.startsWith( KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER)) { parameterValue = StringUtils.removeStart(parameterValue, KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER); }//from w ww . j a va2s .com // check if parameter is in request else if (request.getParameterMap().containsKey(propertyValueName)) { parameterValue = request.getParameter(propertyValueName); } // get parameter value from form object else { Object value = ObjectPropertyUtils.getPropertyValue(form, propertyValueName); if (value != null) { if (value instanceof String) { parameterValue = (String) value; } Formatter formatter = Formatter.getFormatter(value.getClass()); parameterValue = (String) formatter.format(value); } } if (parameterValue != null && lookupObjectClass != null && KRADServiceLocatorWeb.getDataObjectAuthorizationService() .attributeValueNeedsToBeEncryptedOnFormsAndLinks(lookupObjectClass, propertyName)) { try { if (CoreApiServiceLocator.getEncryptionService().isEnabled()) { parameterValue = CoreApiServiceLocator.getEncryptionService().encrypt(parameterValue) + EncryptionService.ENCRYPTION_POST_PREFIX; } } catch (GeneralSecurityException e) { LOG.error("Unable to encrypt value for property name: " + propertyName); throw new RuntimeException(e); } } return parameterValue; }