List of usage examples for org.springframework.util StringUtils hasLength
public static boolean hasLength(@Nullable String str)
From source file:org.patientview.patientview.logon.PasswordChangeAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { /**/* www . j av a2s.c o m*/ * This allows to change their email address, and forces them to change their password. * * Note: this is used upon first login for users to complete their account and when patients change * their password. * * Note: there is also struts validation, see validation.xml */ // receive data from submitted form User user = LegacySpringUtils.getUserManager().getLoggedInUser(); String suppliedOldPassword = BeanUtils.getProperty(form, "oldpassword"); String actualOldPassword = user.getPassword(); String hashedSuppliedOldPassword = LogonUtils.hashPassword(suppliedOldPassword); String emailAddress = BeanUtils.getProperty(form, "emailAddress"); String emailAddressAgain = BeanUtils.getProperty(form, "emailAddressAgain"); boolean errorFound = false; boolean sendVerificationEmail = true; // check the supplied current password matches what we have in the db if (!hashedSuppliedOldPassword.equals(actualOldPassword)) { request.setAttribute("passwordError", "Incorrect current password"); errorFound = true; } // if both email boxes empty -> fine, and no validation email sent (this if (!StringUtils.hasLength(emailAddress) && !StringUtils.hasLength(emailAddressAgain)) { sendVerificationEmail = false; } else if (!emailAddress.equals(emailAddressAgain)) { // emails supplied, they must match request.setAttribute("emailError", "Email addresses don't match"); errorFound = true; } else { // update the user's email with that supplied user.setEmail(emailAddress); } if (errorFound) { return mapping.findForward("input"); } else { // ok so it worked, update the password, set the user not see this screen again, and save the email // change if it was made. user.setPassword(LogonUtils.hashPassword(BeanUtils.getProperty(form, "passwordPwd"))); user.setFirstlogon(false); user.setUpdated(new Date()); LegacySpringUtils.getUserManager().save(user); // db logging AddLog.addLog(user.getUsername(), AddLog.PASSWORD_CHANGE, user.getUsername(), UserUtils.retrieveUsersRealNhsnoBestGuess(user.getUsername()), UserUtils.retrieveUsersRealUnitcodeBestGuess(user.getUsername()), ""); // email verification - only required if the user has supplied an email address // (regardless of if it is the same as the one used to create by the admin) if (sendVerificationEmail) { EmailVerificationUtils.createEmailVerification(user.getUsername(), user.getEmail(), request); request.setAttribute("verificationMailSent", true); } request.setAttribute("passwordMsg", "Password was updated successfully."); return mapping.findForward("success"); } }
From source file:org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList.java
public Object transform(final Object obj) { Object transformed = obj;//w w w.ja v a 2 s. c om if (obj instanceof SearchResult) { transformed = new HashSet(); Set valueSet = (Set) transformed; SearchResult res = (SearchResult) obj; if (SearchResultToAttrValueList.logger.isDebugEnabled()) { SearchResultToAttrValueList.logger.debug(Messages.getInstance().getString( "SearchResultToAttrValueList.DEBUG_ATTRIBUTES_FROM_SEARCHRESULT", (null != res.getAttributes()) ? res.getAttributes().toString() : "null")); //$NON-NLS-1$ //$NON-NLS-2$ } Attribute attr = res.getAttributes().get(attributeName); if (SearchResultToAttrValueList.logger.isDebugEnabled()) { SearchResultToAttrValueList.logger .debug(Messages.getInstance().getString("SearchResultToAttrValueList.DEBUG_ATTRIBUTE_VALUE", attributeName, (null != attr) ? attr.toString() : "null")); //$NON-NLS-1$ //$NON-NLS-2$ } if (attr != null) { // check for null as node might not have attribute we're looking for try { NamingEnumeration values = attr.getAll(); while (values.hasMore()) { // if tokenName was specified, extract from value; otherwise // store value unchanged Object value = values.next(); if (StringUtils.hasLength(tokenName)) { if ((null != value) && (value instanceof String)) { String tokenValue = extract((String) value, tokenName); if (null != tokenValue) { valueSet.add(tokenValue); } } else { if (SearchResultToAttrValueList.logger.isWarnEnabled()) { SearchResultToAttrValueList.logger.warn(Messages.getInstance() .getString("SearchResultToAttrValueList.WARN_ATTRIBUTE_NOT_A_STRING")); //$NON-NLS-1$ } } } else { if (null != value) { valueSet.add(value.toString()); } } } } catch (NamingException e) { if (SearchResultToAttrValueList.logger.isErrorEnabled()) { SearchResultToAttrValueList.logger.error(Messages.getInstance() .getErrorString("SearchResultToAttrValueList.ERROR_0001_NAMING_EXCEPTION"), e); //$NON-NLS-1$ } } } return transformed; } return transformed; }
From source file:org.pentaho.platform.repository.RepositoryFilenameUtils.java
/** * Concatenates a filename to a base path using normal command line style rules. * <p/>/*from w w w .j av a2 s . c om*/ * The effect is equivalent to resultant directory after changing directory to the first argument, followed by * changing directory to the second argument. * <p/> * The first argument is the base path, the second is the path to concatenate. The returned path is always * normalized via {@link #normalize(String)}, thus <code>..</code> is handled. * <p/> * If <code>pathToAdd</code> is absolute (has an absolute prefix), then it will be normalized and returned. * Otherwise, the paths will be joined, normalized and returned. * <p/> * * <pre> * /foo/ + bar --> /foo/bar * /foo + bar --> /foo/bar * /foo + /bar --> /bar * /foo/a/ + ../bar --> foo/bar * /foo/ + ../../bar --> null * /foo/ + /bar --> /bar * /foo/.. + /bar --> /bar * /foo + bar/c.txt --> /foo/bar/c.txt * /foo/c.txt + bar --> /foo/c.txt/bar (!) * </pre> * * (!) Note that the first parameter must be a path. If it ends with a name, then the name will be built into the * concatenated path. If this might be a problem, use {@link #getFullPath(String)} on the base path argument. * * @param basePath * the base path to attach to, always treated as a path * @param fullFilenameToAdd * the filename (or path) to attach to the base * @return the concatenated path, or null if invalid */ public static String concat(final String basePath, final String fullFilenameToAdd) { int prefix = 0; if (StringUtils.hasLength(fullFilenameToAdd)) { prefix = getPrefixLength(fullFilenameToAdd.replace(":", "_")); } if (prefix < 0) { return null; } if (prefix > 0) { return RepositoryFilenameUtils.normalize(fullFilenameToAdd); } if (basePath == null) { return null; } int len = basePath.length(); if (len == 0) { return RepositoryFilenameUtils.normalize(fullFilenameToAdd); } char ch = basePath.charAt(len - 1); if (SEPARATOR == ch) { return RepositoryFilenameUtils.normalize(basePath + fullFilenameToAdd); } else { return RepositoryFilenameUtils.normalize(basePath + SEPARATOR + fullFilenameToAdd); } }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileDao.java
/** * {@inheritDoc}//w ww . j av a 2 s . c om */ @Override public void undeleteFile(final Serializable fileId, final String versionMessage) { if (isKioskEnabled()) { throw new RuntimeException( Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED")); //$NON-NLS-1$ } Assert.notNull(fileId); jcrTemplate.execute(new JcrCallback() { @Override public Object doInJcr(final Session session) throws RepositoryException, IOException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session); String absOrigParentFolderPath = deleteHelper.getOriginalParentFolderPath(session, pentahoJcrConstants, fileId); Serializable origParentFolderId = null; RepositoryFile file = getFileById(fileId); RepositoryFileAcl acl = aclDao.getAcl(fileId); if (!accessVoterManager.hasAccess(file, RepositoryFilePermission.WRITE, acl, PentahoSessionHolder.getSession())) { return null; } // original parent folder path may no longer exist! if (session.itemExists(JcrStringHelper.pathEncode(absOrigParentFolderPath))) { origParentFolderId = ((Node) session .getItem(JcrStringHelper.pathEncode(absOrigParentFolderPath))).getIdentifier(); } else { // go through each of the segments of the original parent folder path, creating as necessary String[] segments = pathConversionHelper.absToRel(absOrigParentFolderPath) .split(RepositoryFile.SEPARATOR); RepositoryFile lastParentFolder = internalGetFile(session, ServerRepositoryPaths.getTenantRootFolderPath(), false, null); for (String segment : segments) { if (StringUtils.hasLength(segment)) { RepositoryFile tmp = internalGetFile(session, pathConversionHelper .relToAbs((lastParentFolder.getPath().equals(RepositoryFile.SEPARATOR) ? "" //$NON-NLS-1$ : lastParentFolder.getPath()) + RepositoryFile.SEPARATOR + segment), false, null); if (tmp == null) { lastParentFolder = internalCreateFolder(session, lastParentFolder.getId(), new RepositoryFile.Builder(segment).folder(true).build(), defaultAclHandler.createDefaultAcl(lastParentFolder), null); } else { lastParentFolder = tmp; } } } origParentFolderId = lastParentFolder.getId(); } JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, origParentFolderId); deleteHelper.undeleteFile(session, pentahoJcrConstants, fileId); session.save(); JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, origParentFolderId, versionMessage); return null; } }); }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileDaoInst.java
public void undeleteFile(final Session session, final Serializable fileId, final String versionMessage) throws RepositoryException, IOException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session); String absOrigParentFolderPath = deleteHelper.getOriginalParentFolderPath(session, pentahoJcrConstants, fileId);/*from w w w . j ava 2 s . c om*/ Serializable origParentFolderId = null; if (!hasAccess(session, fileId, RepositoryFilePermission.WRITE)) { return; } // original parent folder path may no longer exist! if (session.itemExists(JcrStringHelper.pathEncode(absOrigParentFolderPath))) { origParentFolderId = ((Node) session.getItem(JcrStringHelper.pathEncode(absOrigParentFolderPath))) .getIdentifier(); } else { // go through each of the segments of the original parent folder path, creating as necessary String[] segments = pathConversionHelper.absToRel(absOrigParentFolderPath) .split(RepositoryFile.SEPARATOR); RepositoryFile lastParentFolder = internalGetFile(session, ServerRepositoryPaths.getTenantRootFolderPath(), false, null); for (String segment : segments) { if (StringUtils.hasLength(segment)) { RepositoryFile tmp = internalGetFile(session, pathConversionHelper .relToAbs((lastParentFolder.getPath().equals(RepositoryFile.SEPARATOR) ? "" //$NON-NLS-1$ : lastParentFolder.getPath()) + RepositoryFile.SEPARATOR + segment), false, null); if (tmp == null) { lastParentFolder = internalCreateFolder(session, lastParentFolder.getId(), new RepositoryFile.Builder(segment).folder(true).build(), defaultAclHandler.createDefaultAcl(lastParentFolder), null); } else { lastParentFolder = tmp; } } } origParentFolderId = lastParentFolder.getId(); } JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, origParentFolderId); deleteHelper.undeleteFile(session, pentahoJcrConstants, fileId); session.save(); JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, origParentFolderId, versionMessage); }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileUtils.java
/** * Checks for presence of black listed chars as well as illegal permutations of legal chars. *//*from www. j a va 2 s . co m*/ public static void checkName(final String name) { Pattern containsReservedCharsPattern = makePattern(getReservedChars()); if (!StringUtils.hasLength(name) || // not null, not empty, and not all whitespace !name.trim().equals(name) || // no leading or trailing whitespace containsReservedCharsPattern.matcher(name).matches() || // no reserved characters ".".equals(name) || // no . //$NON-NLS-1$ "..".equals(name)) { // no .. //$NON-NLS-1$ throw new RepositoryFileDaoMalformedNameException(name); } }
From source file:org.shept.org.springframework.web.servlet.mvc.delegation.ComponentUtils.java
/** * // w w w.ja v a 2 s. co m * @param * @return the prefixed path name and append always the NESTED_PROPERTY_SEPARATOR to the end * * @param path * @return */ public static String getPropertyPathPrefix(String pathName) { if (StringUtils.hasLength(pathName) && !pathName.endsWith(PropertyAccessor.NESTED_PROPERTY_SEPARATOR)) { pathName = pathName + PropertyAccessor.NESTED_PROPERTY_SEPARATOR; } return pathName; }
From source file:org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.java
@Override public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException { Object cacheKey = getCacheKey(beanClass, beanName); if (!StringUtils.hasLength(beanName) || !this.targetSourcedBeans.contains(beanName)) { if (this.advisedBeans.containsKey(cacheKey)) { return null; }//w w w . j a v a 2 s .c o m if (isInfrastructureClass(beanClass) || shouldSkip(beanClass, beanName)) { this.advisedBeans.put(cacheKey, Boolean.FALSE); return null; } } // Create proxy here if we have a custom TargetSource. // Suppresses unnecessary default instantiation of the target bean: // The TargetSource will handle target instances in a custom fashion. TargetSource targetSource = getCustomTargetSource(beanClass, beanName); if (targetSource != null) { if (StringUtils.hasLength(beanName)) { this.targetSourcedBeans.add(beanName); } Object[] specificInterceptors = getAdvicesAndAdvisorsForBean(beanClass, beanName, targetSource); Object proxy = createProxy(beanClass, beanName, specificInterceptors, targetSource); this.proxyTypes.put(cacheKey, proxy.getClass()); return proxy; } return null; }
From source file:org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.java
/** * Build a cache key for the given bean class and bean name. * <p>Note: As of 4.2.3, this implementation does not return a concatenated * class/name String anymore but rather the most efficient cache key possible: * a plain bean name, prepended with {@link BeanFactory#FACTORY_BEAN_PREFIX} * in case of a {@code FactoryBean}; or if no bean name specified, then the * given bean {@code Class} as-is./*from ww w . j a v a 2s .com*/ * @param beanClass the bean class * @param beanName the bean name * @return the cache key for the given class and name */ protected Object getCacheKey(Class<?> beanClass, @Nullable String beanName) { if (StringUtils.hasLength(beanName)) { return (FactoryBean.class.isAssignableFrom(beanClass) ? BeanFactory.FACTORY_BEAN_PREFIX + beanName : beanName); } else { return beanClass; } }
From source file:org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.java
/** * Wrap the given bean if necessary, i.e. if it is eligible for being proxied. * @param bean the raw bean instance// ww w . j a v a2s . co m * @param beanName the name of the bean * @param cacheKey the cache key for metadata access * @return a proxy wrapping the bean, or the raw bean instance as-is */ protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) { if (StringUtils.hasLength(beanName) && this.targetSourcedBeans.contains(beanName)) { return bean; } if (Boolean.FALSE.equals(this.advisedBeans.get(cacheKey))) { return bean; } if (isInfrastructureClass(bean.getClass()) || shouldSkip(bean.getClass(), beanName)) { this.advisedBeans.put(cacheKey, Boolean.FALSE); return bean; } // Create proxy if we have advice. Object[] specificInterceptors = getAdvicesAndAdvisorsForBean(bean.getClass(), beanName, null); if (specificInterceptors != DO_NOT_PROXY) { this.advisedBeans.put(cacheKey, Boolean.TRUE); Object proxy = createProxy(bean.getClass(), beanName, specificInterceptors, new SingletonTargetSource(bean)); this.proxyTypes.put(cacheKey, proxy.getClass()); return proxy; } this.advisedBeans.put(cacheKey, Boolean.FALSE); return bean; }