List of usage examples for org.apache.commons.lang StringUtils stripEnd
public static String stripEnd(String str, String stripChars)
Strips any of a set of characters from the end of a String.
From source file:org.kuali.rice.core.framework.persistence.jpa.type.HibernateKualiHashType.java
/** * sets the hash value on the PreparedStatement * //ww w .j av a2s . com * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int) */ public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { Object converted = value; if (converted != null) { // don't convert if already a hashed value if (converted.toString().endsWith(EncryptionService.HASH_POST_PREFIX)) { converted = StringUtils.stripEnd(converted.toString(), EncryptionService.HASH_POST_PREFIX); } else { try { converted = CoreApiServiceLocator.getEncryptionService().hash(converted); } catch (GeneralSecurityException e) { throw new RuntimeException("Unable to hash value to db: " + e.getMessage()); } } } if (converted == null) { st.setNull(index, Types.VARCHAR); } else { st.setString(index, (String) converted); } }
From source file:org.kuali.rice.core.framework.persistence.ojb.conversion.OjbKualiHashFieldConversion.java
/** * @see FieldConversion#javaToSql(Object) *//*from w w w . j a va 2 s .com*/ public Object javaToSql(Object source) { Object converted = source; if (converted != null) { // don't convert if already a hashed value if (converted.toString().endsWith(EncryptionService.HASH_POST_PREFIX)) { converted = StringUtils.stripEnd(converted.toString(), EncryptionService.HASH_POST_PREFIX); } else { try { converted = CoreApiServiceLocator.getEncryptionService().hash(converted); } catch (GeneralSecurityException e) { throw new RuntimeException("Unable to hash value to db: " + e.getMessage()); } } } return converted; }
From source file:org.kuali.rice.kns.maintenance.KualiMaintainableImpl.java
/** * Special hidden parameters are set on the maintenance jsp starting with a * prefix that tells us which fields have been encrypted. This field finds * the those parameters in the map, whose value gives us the property name * that has an encrypted value. We then need to decrypt the value in the Map * before the business object is populated. * * @param fieldValues/* ww w . j a v a2s . com*/ * - possibly with encrypted values * @return Map fieldValues - with no encrypted values */ protected Map<String, String> decryptEncryptedData(Map<String, String> fieldValues, MaintenanceDocument maintenanceDocument, String methodToCall) { try { MaintenanceDocumentRestrictions auths = KNSServiceLocator.getBusinessObjectAuthorizationService() .getMaintenanceDocumentRestrictions(maintenanceDocument, GlobalVariables.getUserSession().getPerson()); for (Iterator<String> iter = fieldValues.keySet().iterator(); iter.hasNext();) { String fieldName = iter.next(); String fieldValue = (String) fieldValues.get(fieldName); if (fieldValue != null && !"".equals(fieldValue) && fieldValue.endsWith(EncryptionService.ENCRYPTION_POST_PREFIX)) { if (shouldFieldBeEncrypted(maintenanceDocument, fieldName, auths, methodToCall)) { String encryptedValue = fieldValue; // take off the postfix encryptedValue = StringUtils.stripEnd(encryptedValue, EncryptionService.ENCRYPTION_POST_PREFIX); if (CoreApiServiceLocator.getEncryptionService().isEnabled()) { String decryptedValue = getEncryptionService().decrypt(encryptedValue); fieldValues.put(fieldName, decryptedValue); } } else throw new RuntimeException( "The field value for field name " + fieldName + " should not be encrypted."); } else if (fieldValue != null && !"".equals(fieldValue) && auths.hasRestriction(fieldName) && shouldFieldBeEncrypted(maintenanceDocument, fieldName, auths, methodToCall)) throw new RuntimeException( "The field value for field name " + fieldName + " should be encrypted."); } } catch (GeneralSecurityException e) { throw new RuntimeException("Unable to decrypt secure data: " + e.getMessage()); } return fieldValues; }
From source file:org.kuali.rice.krad.dao.jdbc.PostDataLoadEncryptionDaoJdbc.java
protected String getSelectBackupTableColumnsSql(String tableName, List<String> columnNames, int numberOfRowsToCommitAfter) { tableName = tableName + BACKUP_TABLE_EXTENSION; StringBuffer columnsNamesBuf = new StringBuffer(); for (String columnName : columnNames) { columnsNamesBuf.append(columnName).append(COMMA_SEPARATOR); }/*from w ww . j av a 2 s .c om*/ String selectColumns = StringUtils.stripEnd(columnsNamesBuf.toString(), COMMA_SEPARATOR); return new StringBuffer("SELECT ").append(selectColumns).append(" FROM ").append(tableName) .append(" WHERE ").append(BACKUP_TABLE_ENCRYPT_IND).append(" IS NULL AND ROWNUM<=") .append(numberOfRowsToCommitAfter).toString(); }
From source file:org.kuali.rice.krad.data.jpa.converters.HashConverter.java
/** * {@inheritDoc}// w w w . j a v a 2 s . c om * * This implementation hashes the value going to the database. */ @Override public String convertToDatabaseColumn(String objectValue) { // don't attempt to encrypt nulls or empty strings if (objectValue == null) { return null; } if (StringUtils.isEmpty(objectValue.toString())) { return ""; } // don't convert if already a hashed value if (objectValue.toString().endsWith(EncryptionService.HASH_POST_PREFIX)) { return StringUtils.stripEnd(objectValue.toString(), EncryptionService.HASH_POST_PREFIX); } else { try { return CoreApiServiceLocator.getEncryptionService().hash(objectValue); } catch (Exception e) { throw new RuntimeException("Exception while attempting to hash value for DB: ", e); } } }
From source file:org.kuali.student.enrollment.class2.courseoffering.service.impl.CourseOfferingMaintainableImpl.java
/** * This method populates {@link CourseCrossListingInfo} in to the {@link CourseOfferingInfo} * based on the user selection at create or edit CO. Note: If the <code>kuali.ks.enrollment.options.selective-crosslisting-allowed</code> * property is enabled, this method creates cross listing dtos for all the alternate course codes. * * @param wrapper either {@link CourseOfferingCreateWrapper} or {@link org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper} * @param coInfo course offering dto//w ww . j a va 2 s . c om */ protected void loadCrossListedCOs(CourseOfferingWrapper wrapper, CourseOfferingInfo coInfo) { coInfo.getCrossListings().clear(); if (wrapper.isSelectCrossListingAllowed()) { List<String> alternateCodes = null; if (wrapper instanceof CourseOfferingCreateWrapper) { alternateCodes = wrapper.getAlternateCOCodes(); } else if (wrapper instanceof CourseOfferingEditWrapper) { alternateCodes = ((CourseOfferingEditWrapper) wrapper).getAlternateCourseCodesSuffixStripped(); } for (String alternateCode : alternateCodes) { String alternateCourseCodesSuffixStripped = StringUtils.stripEnd(alternateCode, coInfo.getCourseNumberSuffix()); for (CourseCrossListingInfo crossInfo : wrapper.getCourse().getCrossListings()) { if (StringUtils.equals(crossInfo.getCode(), alternateCourseCodesSuffixStripped)) { CourseOfferingCrossListingInfo crossListingInfo = new CourseOfferingCrossListingInfo(); crossListingInfo.setCode(crossInfo.getCode()); crossListingInfo.setCourseNumberSuffix(crossInfo.getCourseNumberSuffix()); crossListingInfo.setSubjectOrgId(crossInfo.getSubjectOrgId()); crossListingInfo.setSubjectArea(crossInfo.getSubjectArea()); crossListingInfo.setStateKey(LuiServiceConstants.LUI_CO_STATE_DRAFT_KEY); crossListingInfo.setTypeKey(LuiServiceConstants.LUI_IDENTIFIER_CROSSLISTED_TYPE_KEY); coInfo.getCrossListings().add(crossListingInfo); } } } } else { // get all the crosslisted COs CourseInfo courseInfo = wrapper.getCourse(); for (CourseCrossListingInfo crossInfo : courseInfo.getCrossListings()) { CourseOfferingCrossListingInfo crossListingInfo = new CourseOfferingCrossListingInfo(); crossListingInfo.setCode(crossInfo.getCode()); crossListingInfo.setCourseNumberSuffix(crossInfo.getCourseNumberSuffix()); crossListingInfo.setSubjectOrgId(crossInfo.getSubjectOrgId()); crossListingInfo.setSubjectArea(crossInfo.getSubjectArea()); crossListingInfo.setStateKey(LuiServiceConstants.LUI_CO_STATE_DRAFT_KEY); crossListingInfo.setTypeKey(LuiServiceConstants.LUI_IDENTIFIER_CROSSLISTED_TYPE_KEY); coInfo.getCrossListings().add(crossListingInfo); } } }
From source file:org.kuali.student.r2.core.class1.search.CourseOfferingManagementSearchImpl.java
/** * Builds the Result Row and add it to the resultset. * * @param result data array from a search result row * @param searchSubjectArea/*from w ww.j av a 2 s. c o m*/ * @param searchCourseCode * @param enableCrossListSearch * @param includePassFailAndAuditRecords * @param luiIds2ResultRow * @param luiIds2OrgCells * @param luiIds2AlternateCodes * @param resultInfo */ private void buildSearchResultRow(Object[] result, String searchSubjectArea, String searchCourseCode, boolean enableCrossListSearch, boolean includePassFailAndAuditRecords, Map<String, SearchResultRowInfo> luiIds2ResultRow, Map<String, SearchResultCellInfo> luiIds2OrgCells, Map<String, String> luiIds2AlternateCodes, SearchResultInfo resultInfo) { SearchResultRowInfo row = new SearchResultRowInfo(); int i = 0; String coCode = (String) result[i++]; row.addCell(SearchResultColumns.CODE, coCode); row.addCell(SearchResultColumns.DESC, (String) result[i++]); row.addCell(SearchResultColumns.STATE, (String) result[i++]); row.addCell(SearchResultColumns.CREDIT_OPTION, (String) result[i++]); String graditOption = (String) result[i++]; row.addCell(SearchResultColumns.GRADING_OPTION, graditOption); String courseOfferingId = (String) result[i++]; String division = (String) result[i++]; String luiIdentifierType = (String) result[i++]; boolean isCrossListed = false; if (StringUtils.equals(luiIdentifierType, LuiServiceConstants.LUI_IDENTIFIER_CROSSLISTED_TYPE_KEY)) { isCrossListed = true; } row.addCell(SearchResultColumns.CO_ID, courseOfferingId); row.addCell(SearchResultColumns.SUBJECT_AREA, division); boolean includeCurrentRow = isConsiderSearchResult(searchSubjectArea, searchCourseCode, division); row.addCell(SearchResultColumns.IS_CROSS_LISTED, "" + isCrossListed); //Roll up the org ids (if the org cell exists already then String deploymentOrg = (String) result[i++]; String creditNameForDisplay = StringUtils.stripEnd(StringUtils.lowerCase((String) result[i++]), " credits"); creditNameForDisplay = StringUtils.stripEnd(creditNameForDisplay, " credit"); row.addCell(SearchResultColumns.CREDIT_OPTION_NAME, creditNameForDisplay); String gradingName = (String) result[i++]; row.addCell(SearchResultColumns.GRADING_OPTION_NAME, gradingName); String courseDesc = (String) result[i++]; SearchResultCellInfo defaultPassFailFlag = row.addCell(SearchResultColumns.HAS_STUDENT_SELECTABLE_PASSFAIL, Boolean.FALSE.toString()); SearchResultCellInfo defaultAuditFlag = row.addCell(SearchResultColumns.CAN_AUDIT_COURSE, Boolean.FALSE.toString()); SearchResultCellInfo defaultHonorsFlag = row.addCell(SearchResultColumns.IS_HONORS_COURSE, Boolean.FALSE.toString()); if (includeCurrentRow && includePassFailAndAuditRecords) { String luCodeType = (String) result[i++]; String luCodeValue = (String) result[i++]; boolean continueWithNextRow = processPassFailAndAuditDetails(graditOption, courseOfferingId, isCrossListed, deploymentOrg, defaultPassFailFlag, defaultAuditFlag, luiIds2ResultRow, luiIds2OrgCells, defaultHonorsFlag, luCodeType, luCodeValue); if (continueWithNextRow) { return; } } row.addCell(SearchResultColumns.DESC_FORMATTED, courseDesc); //Rollup all the units deployment as a comma separated string. if (includeCurrentRow && luiIds2OrgCells.containsKey(courseOfferingId)) { //Only do this for the root lui to avoid duplication SearchResultCellInfo orgCell = luiIds2OrgCells.get(courseOfferingId); orgCell.setValue(orgCell.getValue() + "," + deploymentOrg); //Skip processing the rest of this record because multiple orgIDs are rolled up in the query return; } if (includeCurrentRow) { resultInfo.getRows().add(row); //Put the value into the search result row, and save it in the mapping luiIds2OrgCells.put(courseOfferingId, row.addCell(SearchResultColumns.DEPLOYMENT_ORG_ID, deploymentOrg)); if (includePassFailAndAuditRecords) { luiIds2ResultRow.put(courseOfferingId, row); } } if (enableCrossListSearch) { String alternateCodes = luiIds2AlternateCodes.get(courseOfferingId); String currentCode = getAlternateCodeUI(coCode, luiIdentifierType); if (!StringUtils.contains(alternateCodes, currentCode)) { String buildAlternateCodes = StringUtils.defaultString(alternateCodes) + currentCode; luiIds2AlternateCodes.put(courseOfferingId, buildAlternateCodes + ","); } } }
From source file:org.locationtech.udig.tools.internal.CursorPosition.java
/** * transforms a String value to a Coordinate considering Locale setting and the supplied crs. * /* w w w . ja va 2 s . com*/ * @param value * @param crs * @return */ public static Coordinate parse(String value, CoordinateReferenceSystem crs) { char decimalSeparator = DecimalFormatSymbols.getInstance(Locale.getDefault()).getDecimalSeparator(); String modifiedvalue = value.trim(); boolean latlong = false; String upperCase = modifiedvalue.toUpperCase(); String tmp = modifiedvalue; modifiedvalue = stripCode(modifiedvalue, upperCase); if (tmp.length() != modifiedvalue.length()) latlong = true; modifiedvalue = StringUtils.removeStart(modifiedvalue.trim(), "("); modifiedvalue = StringUtils.removeStart(modifiedvalue.trim(), "["); modifiedvalue = StringUtils.removeEnd(modifiedvalue.trim(), ")"); modifiedvalue = StringUtils.removeEnd(modifiedvalue.trim(), "]"); String[] components = StringUtils.split(modifiedvalue, decimalSeparator == ',' ? " " : ","); //$NON-NLS-1$ if (components.length == 1) { components = StringUtils.split(modifiedvalue, " "); //$NON-NLS-1$ } if (components.length == 1) { components = StringUtils.split(modifiedvalue, ","); } if (components.length <= 1) { return null; } try { components[0] = StringUtils.stripEnd(components[0].trim(), ", "); double arg1 = components[0].contains(".") ? Double.parseDouble(components[0]) : NumberFormat.getInstance().parse(components[0]).doubleValue(); components[1] = StringUtils.stripEnd(components[1].trim(), ", "); double arg0 = components[1].contains(".") ? Double.parseDouble(components[1]) : NumberFormat.getInstance().parse(components[1]).doubleValue(); Coordinate coord = new Coordinate(arg1, arg0); if (latlong && crs != null) { try { JTS.transform(coord, coord, CRS.findMathTransform(DefaultGeographicCRS.WGS84, crs, true)); } catch (Exception e) { ToolsPlugin.log(Messages.CursorPosition_transformError, e); } } return coord; } catch (NumberFormatException e) { return null; } catch (ParseException e1) { return null; } catch (Exception e1) { return null; } }
From source file:org.nuxeo.ecm.core.opencmis.bindings.NuxeoCmisAtomPubServlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String baseUrl = VirtualHostHelper.getBaseURL(request); if (baseUrl != null) { baseUrl = StringUtils.stripEnd(baseUrl, "/") + request.getServletPath() + "/" + AbstractAtomPubServiceCall.REPOSITORY_PLACEHOLDER + "/"; request.setAttribute(Dispatcher.BASE_URL_ATTRIBUTE, baseUrl); }//from w ww. j a va2s .c om super.service(request, response); }
From source file:org.nuxeo.ecm.core.opencmis.bindings.NuxeoCmisBrowserBindingServlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String baseUrl = VirtualHostHelper.getBaseURL(request); if (baseUrl != null) { baseUrl = StringUtils.stripEnd(baseUrl, "/") + request.getServletPath() + "/" + AbstractBrowserServiceCall.REPOSITORY_PLACEHOLDER + "/"; request.setAttribute(Dispatcher.BASE_URL_ATTRIBUTE, baseUrl); }//from w ww . j a va2s.c o m super.service(request, response); }