/** * Removes the prefix if the given String starts with {@link I_CmsPrincipal#PRINCIPAL_GROUP} followed by a dot.<p> * * <ul> * <li>Works if the given String is <code>null</code>. * <li>If the given String does not start with {@link I_CmsPrincipal#PRINCIPAL_GROUP} followed by a dot it is returned unchanged. * <li>Removes white spaces around the group name. * <li>Also works with prefixes not being in upper case. * <li>Does not check if the group after the prefix actually exists. * </ul> * * @param principalName the group name to remove the prefix from * * @return the given String with the prefix {@link I_CmsPrincipal#PRINCIPAL_GROUP} with the following dot removed */ public static String removePrefix(String principalName) { String result = principalName; if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(principalName)) { if (hasPrefix(principalName)) { result = principalName.trim().substring(I_CmsPrincipal.PRINCIPAL_GROUP.length() + 1); } } return result; }
if (CmsGroup.hasPrefix(key)) {
/** * Utility function to read a prefixed principal from the OpenCms database using the * provided OpenCms user context.<p> * * The principal must be either prefixed with <code>{@link I_CmsPrincipal#PRINCIPAL_GROUP}.</code> or * <code>{@link I_CmsPrincipal#PRINCIPAL_USER}.</code>.<p> * * @param cms the OpenCms user context to use when reading the principal * @param name the prefixed principal name * * @return the principal read from the OpenCms database * * @throws CmsException in case the principal could not be read */ public static I_CmsPrincipal readPrefixedPrincipal(CmsObject cms, String name) throws CmsException { if (CmsGroup.hasPrefix(name)) { // this principal is a group return cms.readGroup(CmsGroup.removePrefix(name)); } else if (CmsUser.hasPrefix(name)) { // this principal is a user return cms.readUser(CmsUser.removePrefix(name)); } // invalid principal name was given throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_INVALID_PRINCIPAL_1, name)); }