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.rice.krad.uif.util.ScriptUtils.java
/** * Convert a string to a javascript value - especially for use for options used to initialize * widgets such as the tree and rich table * //from w ww . j ava2 s. co m * @param value the string to be converted * @return the converted value */ public static String convertToJsValue(String value) { // save input value to preserve any whitespace formatting String originalValue = value; // remove whitespace for correct string matching value = StringUtils.strip(value); // If an option value starts with { or [, it would be a nested value // and it should not use quotes around it if (StringUtils.startsWith(value, "{") || StringUtils.startsWith(value, "[")) { return originalValue; } // need to be the base boolean value "false" is true in js - a non // empty string else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("true")) { return originalValue.toLowerCase(); } // if it is a call back function, do not add the quotes else if (StringUtils.startsWith(value, "function") && StringUtils.endsWith(value, "}")) { return originalValue; } // for numerics else if (NumberUtils.isNumber(value)) { return originalValue; } else { // String values require double quotes return "\"" + originalValue + "\""; } }
From source file:org.kuali.rice.krad.uif.view.DefaultExpressionEvaluator.java
/** * {@inheritDoc}//from w w w. j a v a2 s. c o m */ @Override public Object evaluateExpression(Map<String, Object> evaluationParameters, String expressionStr) { Object result = null; // 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); } try { Expression expression = retrieveCachedExpression(expressionStr); if (evaluationParameters != null) { evaluationContext.setVariables(evaluationParameters); } result = expression.getValue(evaluationContext); } 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.view.DefaultExpressionEvaluator.java
/** * {@inheritDoc}/* w w w.ja v a 2 s . com*/ */ @Override public void evaluatePropertyExpression(View view, Map<String, Object> evaluationParameters, UifDictionaryBean expressionConfigurable, String propertyName, boolean removeExpression) { Map<String, String> propertyExpressions = expressionConfigurable.getPropertyExpressions(); if ((propertyExpressions == null) || !propertyExpressions.containsKey(propertyName)) { return; } String expression = propertyExpressions.get(propertyName); // check whether expression should be evaluated or property should retain the expression if (CopyUtils.fieldHasAnnotation(expressionConfigurable.getClass(), propertyName, KeepExpression.class)) { // set expression as property value to be handled by the component ObjectPropertyUtils.setPropertyValue(expressionConfigurable, propertyName, expression); return; } Object propertyValue = null; // replace binding prefixes (lp, dp, fp) in expression before evaluation String adjustedExpression = replaceBindingPrefixes(view, expressionConfigurable, expression); // determine whether the expression is a string template, or evaluates to another object type if (StringUtils.startsWith(adjustedExpression, UifConstants.EL_PLACEHOLDER_PREFIX) && StringUtils.endsWith(adjustedExpression, UifConstants.EL_PLACEHOLDER_SUFFIX) && (StringUtils.countMatches(adjustedExpression, UifConstants.EL_PLACEHOLDER_PREFIX) == 1)) { propertyValue = evaluateExpression(evaluationParameters, adjustedExpression); } else { // treat as string template propertyValue = evaluateExpressionTemplate(evaluationParameters, adjustedExpression); } // if property name has the special indicator then we need to add the expression result to the property // value instead of replace if (StringUtils.endsWith(propertyName, ExpressionEvaluator.EMBEDDED_PROPERTY_NAME_ADD_INDICATOR)) { StringUtils.removeEnd(propertyName, ExpressionEvaluator.EMBEDDED_PROPERTY_NAME_ADD_INDICATOR); Collection collectionValue = ObjectPropertyUtils.getPropertyValue(expressionConfigurable, propertyName); if (collectionValue == null) { throw new RuntimeException("Property name: " + propertyName + " with collection type was not initialized. Cannot add expression result"); } collectionValue.add(propertyValue); } else { ObjectPropertyUtils.setPropertyValue(expressionConfigurable, propertyName, propertyValue); } if (removeExpression) { propertyExpressions.remove(propertyName); } }
From source file:org.kuali.rice.krad.uif.widget.QuickFinder.java
/** * Adjusts the path on the field conversion to property to match the binding path prefix of the * given {@link org.kuali.rice.krad.uif.component.BindingInfo}. * * @param bindingInfo binding info instance to copy binding path prefix from *//*w w w. ja v a2 s .com*/ protected void updateFieldConversions(BindingInfo bindingInfo) { Map<String, String> adjustedFieldConversions = new HashMap<String, String>(); for (String fromField : fieldConversions.keySet()) { String toField = fieldConversions.get(fromField); if (!StringUtils.startsWith(toField, bindingInfo.getBindingPathPrefix())) { String adjustedToFieldPath = bindingInfo.getPropertyAdjustedBindingPath(toField); adjustedFieldConversions.put(fromField, adjustedToFieldPath); } else { adjustedFieldConversions.put(fromField, toField); } } this.fieldConversions = adjustedFieldConversions; }
From source file:org.kuali.rice.krad.util.LegacyDetector.java
/** * Determines whether the given class is loaded into OJB. Accesses the OJB metadata manager via reflection to avoid * compile-time dependency. If null is passed to this method, it will always return false. * * @param dataObjectClass the data object class which may be loaded by the legacy framework * @return true if the legacy data framework is present and has loaded the specified class, false otherwise */// w ww.j ava 2 s . c o m public boolean isOjbLoadedClass(Class<?> dataObjectClass) { if (dataObjectClass == null) { return false; } // some OJB objects may come in as proxies, we need to clear the CGLIB portion of the generated class name // before we can check it properly String dataObjectClassName = dataObjectClass.getName() .replaceAll("\\$\\$EnhancerByCGLIB\\$\\$[0-9a-f]{0,8}", ""); try { dataObjectClass = Class.forName(dataObjectClassName); } catch (ClassNotFoundException ex) { LOG.warn("Unable to resolve converted class name: " + dataObjectClassName + " from original: " + dataObjectClass + " -- Using as is"); } Boolean isLegacyLoaded = legacyLoadedCache.get(dataObjectClass); if (isLegacyLoaded == null) { if (dataObjectClass.getPackage() != null && StringUtils.startsWith(dataObjectClass.getPackage().getName(), "org.apache.ojb.")) { isLegacyLoaded = Boolean.TRUE; } else { try { Class<?> metadataManager = Class.forName(OJB_METADATA_MANAGER_CLASS, false, ClassUtils.getDefaultClassLoader()); // determine, via reflection, whether the legacy persistence layer has loaded the given class Object metadataManagerInstance = ReflectionUtils.invokeViaReflection(metadataManager, (Object) null, "getInstance", null); Validate.notNull(metadataManagerInstance, "unable to obtain " + OJB_METADATA_MANAGER_CLASS + " instance"); Object descriptorRepository = ReflectionUtils.invokeViaReflection(metadataManagerInstance, "getGlobalRepository", null); Validate.notNull(descriptorRepository, "unable to invoke legacy metadata provider (" + OJB_METADATA_MANAGER_CLASS + ")"); isLegacyLoaded = ReflectionUtils.invokeViaReflection(descriptorRepository, "hasDescriptorFor", new Class[] { Class.class }, dataObjectClass); } catch (ClassNotFoundException e) { // the legacy provider does not exist, so this class can't possibly have been loaded through it isLegacyLoaded = Boolean.FALSE; } } legacyLoadedCache.put(dataObjectClass, isLegacyLoaded); } return isLegacyLoaded.booleanValue(); }
From source file:org.kuali.student.enrollment.class2.acal.service.impl.AcademicCalendarViewHelperServiceImpl.java
protected Date getStartDateWithUpdatedTime(TimeSetWrapper timeSetWrapper, boolean isSaveAction) { //If start time not blank, set that with the date. If it's empty, just update with default if (!timeSetWrapper.isAllDay()) { if (StringUtils.isNotBlank(timeSetWrapper.getStartTime())) { String startTime = timeSetWrapper.getStartTime(); String startTimeApPm = timeSetWrapper.getStartTimeAmPm(); //On save to DB, have to replace 12AM to 00AM insead of DB considers as 12PM if (isSaveAction && StringUtils.startsWith(startTime, "12:") && StringUtils.equalsIgnoreCase(startTimeApPm, "am")) { startTime = StringUtils.replace(startTime, "12:", "00:"); }/*from w w w . j av a2 s .c o m*/ return AcalCommonUtils.getDateWithTime(timeSetWrapper.getStartDate(), startTime, startTimeApPm); } else { return null; // should never get here. } } else { return timeSetWrapper.getStartDate(); } }
From source file:org.kuali.student.enrollment.class2.acal.service.impl.HolidayCalendarViewHelperServiceImpl.java
private Date getStartDateWithUpdatedTime(TimeSetWrapper timeSetWrapper, boolean isSaveAction) { //If start time not blank, set that with the date. If it's empty, just update with default if (!timeSetWrapper.isAllDay()) { if (StringUtils.isNotBlank(timeSetWrapper.getStartTime())) { String startTime = timeSetWrapper.getStartTime(); String startTimeApPm = timeSetWrapper.getStartTimeAmPm(); //On save to DB, have to replace 12AM to 00AM insead of DB considers as 12PM if (isSaveAction && StringUtils.startsWith(startTime, "12:") && StringUtils.equalsIgnoreCase(startTimeApPm, "am")) { startTime = StringUtils.replace(startTime, "12:", "00:"); }//from ww w . j ava 2 s . c o m return AcalCommonUtils.getDateWithTime(timeSetWrapper.getStartDate(), startTime, startTimeApPm); } else { timeSetWrapper.setStartTime("12:00"); timeSetWrapper.setStartTimeAmPm("AM"); return AcalCommonUtils.getDateWithTime(timeSetWrapper.getStartDate(), timeSetWrapper.getStartTime(), timeSetWrapper.getStartTimeAmPm()); } } else { return timeSetWrapper.getStartDate(); } }
From source file:org.kuali.student.r2.core.class1.search.CourseOfferingManagementSearchImpl.java
private boolean isConsiderSearchResult(String searchSubjectArea, String searchCourseCode, String division) { /*// ww w. j ava 2 s . c o m Both subject area and course code can be empty with schedule of classes as the search may be with other criterias like instructor, dept, title etc */ if (StringUtils.isBlank(searchSubjectArea) && StringUtils.isBlank(searchCourseCode)) { return true; } else if (StringUtils.equals(searchSubjectArea, division) || StringUtils.startsWith(searchCourseCode, division)) { /* This is to make sure we consider only the user entered subject area or division in Manage CO. */ return true; } return false; }
From source file:org.lfs.config.processor.TextFileReader.java
@Override public void readAndProcess(ConfigurableFile configurableFile) throws Exception { boolean error = false; // need to check if FileColumn indexes are overlapping to each others' if (!validateConfig(configurableFile)) { return;//from w w w.j a va 2 s . c o m } FileInputStream fstream = new FileInputStream( configurableFile.getSourceDir() + configurableFile.getFileNameInRegExpr()); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { if (StringUtils.startsWith(strLine, "#~")) { break; } if (userDebugMode != null) { userDebugMode.debugLine(configurableFile, strLine); } if (debugMode != null) { debugMode.debugLine(configurableFile, strLine); } if (!this.fileValidator.validateLine(configurableFile, strLine)) { error = true; break; } } //Close the input stream in.close(); }
From source file:org.mifosplatform.infrastructure.core.service.FileUtils.java
/** * Extracts Image from a Data URL/*from w ww .jav a 2 s. c om*/ * * @param mimeType */ public static Base64EncodedImage extractImageFromDataURL(String dataURL) { String fileExtension = ""; String base64EncodedString = null; if (StringUtils.startsWith(dataURL, IMAGE_DATA_URI_SUFFIX.GIF.getValue())) { base64EncodedString = dataURL.replaceAll(IMAGE_DATA_URI_SUFFIX.GIF.getValue(), ""); fileExtension = IMAGE_FILE_EXTENSION.GIF.getValue(); } else if (StringUtils.startsWith(dataURL, IMAGE_DATA_URI_SUFFIX.PNG.getValue())) { base64EncodedString = dataURL.replaceAll(IMAGE_DATA_URI_SUFFIX.PNG.getValue(), ""); fileExtension = IMAGE_FILE_EXTENSION.PNG.getValue(); } else if (StringUtils.startsWith(dataURL, IMAGE_DATA_URI_SUFFIX.JPEG.getValue())) { base64EncodedString = dataURL.replaceAll(IMAGE_DATA_URI_SUFFIX.JPEG.getValue(), ""); fileExtension = IMAGE_FILE_EXTENSION.JPEG.getValue(); } else { throw new ImageDataURLNotValidException(); } return new Base64EncodedImage(base64EncodedString, fileExtension); }