@Override protected Long getImportPortletPreferencesNewPrimaryKey( PortletDataContext portletDataContext, Class<?> clazz, long companyGroupId, Map<Long, Long> primaryKeys, String uuid) throws Exception { if (Validator.isNumber(uuid)) { long oldPrimaryKey = GetterUtil.getLong(uuid); return MapUtil.getLong(primaryKeys, oldPrimaryKey, oldPrimaryKey); } String className = clazz.getName(); if (className.equals(Organization.class.getName())) { Organization organization = OrganizationUtil.fetchByUuid_C_First(uuid, portletDataContext.getCompanyId(), null); if (organization != null) { return organization.getOrganizationId(); } } return null; }
protected void checkStringBundler(String line, String fileName, int lineCount) { if ((!line.startsWith("sb.append(") && !line.contains("SB.append(")) || !line.endsWith(");")) { return; } int pos = line.indexOf(".append("); line = line.substring(pos + 8, line.length() - 2); line = stripQuotes(line, CharPool.QUOTE); if (!line.contains(" + ")) { return; } String[] lineParts = StringUtil.split(line, " + "); for (String linePart : lineParts) { int closeParenthesesCount = StringUtil.count(linePart, StringPool.CLOSE_PARENTHESIS); int openParenthesesCount = StringUtil.count(linePart, StringPool.OPEN_PARENTHESIS); if (closeParenthesesCount != openParenthesesCount) { return; } if (Validator.isNumber(linePart)) { return; } } processErrorMessage(fileName, "plus: " + fileName + " " + lineCount); }
protected void updatePreferencesClassPKs(PortletPreferences preferences, String key) throws Exception { String[] oldValues = preferences.getValues(key, null); if (oldValues == null) { return; } String[] newValues = new String[oldValues.length]; for (int i = 0; i < oldValues.length; i++) { String oldValue = oldValues[i]; String newValue = oldValue; String[] oldPrimaryKeys = StringUtil.split(oldValue); for (String oldPrimaryKey : oldPrimaryKeys) { if (!Validator.isNumber(oldPrimaryKey)) { break; } Long newPrimaryKey = _ddmStructurePKs.get(GetterUtil.getLong(oldPrimaryKey)); if (Validator.isNotNull(newPrimaryKey)) { newValue = StringUtil.replace(newValue, oldPrimaryKey, String.valueOf(newPrimaryKey)); } } newValues[i] = newValue; } preferences.setValues(key, newValues); }
protected void validate(long roleId, long companyId, long classNameId, String name) throws PortalException, SystemException { if (classNameId == PortalUtil.getClassNameId(Role.class)) { if (Validator.isNull(name) || (name.indexOf(CharPool.COMMA) != -1) || (name.indexOf(CharPool.STAR) != -1)) { throw new RoleNameException(); } if (Validator.isNumber(name) && !PropsValues.ROLES_NAME_ALLOW_NUMERIC) { throw new RoleNameException(); } } try { Role role = roleFinder.findByC_N(companyId, name); if (role.getRoleId() != roleId) { throw new DuplicateRoleException(); } } catch (NoSuchRoleException nsre) { } }
protected String getFriendlyURL(String friendlyURL, long layoutId) { if (!Validator.isNumber(friendlyURL.substring(1))) { return friendlyURL; } return StringPool.SLASH + layoutId; }
protected void validate( long companyId, long groupId, String feedId, boolean autoFeedId, String name, String structureId, String targetLayoutFriendlyUrl, String contentField) throws PortalException, SystemException { if (!autoFeedId) { if ((Validator.isNull(feedId)) || (Validator.isNumber(feedId)) || (feedId.indexOf(CharPool.SPACE) != -1)) { throw new FeedIdException(); } JournalFeed feed = journalFeedPersistence.fetchByG_F(groupId, feedId); if (feed != null) { throw new DuplicateFeedIdException(); } } validate(companyId, groupId, name, structureId, targetLayoutFriendlyUrl, contentField); }
protected void validate(String templateId) throws PortalException { if ((Validator.isNull(templateId)) || (Validator.isNumber(templateId)) || (templateId.indexOf(CharPool.SPACE) != -1)) { throw new TemplateIdException(); } }
protected void validateStructureId(String structureId) throws PortalException { if ((Validator.isNull(structureId)) || (Validator.isNumber(structureId)) || (structureId.indexOf(CharPool.SPACE) != -1)) { throw new StructureIdException(); } }
@Override public boolean isValidVersion(String version) { if (version.equals(DLFileEntryConstants.PRIVATE_WORKING_COPY_VERSION)) { return true; } String[] versionParts = StringUtil.split(version, StringPool.PERIOD); if (versionParts.length != 2) { return false; } if (Validator.isNumber(versionParts[0]) && Validator.isNumber(versionParts[1])) { return true; } return false; }
protected void transformDateFieldValue(Element dynamicContentElement) { String value = dynamicContentElement.getText(); if (!Validator.isNumber(value)) { return; } Date date = new Date(GetterUtil.getLong(value)); dynamicContentElement.clearContent(); dynamicContentElement.addCDATA(_dateFormat.format(date)); }
protected void checkLanguageKeys(String fileName, String content, Pattern pattern) throws IOException { String fileExtension = fileUtil.getExtension(fileName); if (!portalSource || fileExtension.equals("vm")) { return; } if (_portalLanguageProperties == null) { _portalLanguageProperties = new Properties(); ClassLoader classLoader = BaseSourceProcessor.class.getClassLoader(); InputStream inputStream = classLoader.getResourceAsStream("content/Language.properties"); _portalLanguageProperties.load(inputStream); } Matcher matcher = pattern.matcher(content); while (matcher.find()) { String[] languageKeys = getLanguageKeys(matcher); for (String languageKey : languageKeys) { if (Validator.isNumber(languageKey) || languageKey.endsWith(StringPool.DASH) || languageKey.endsWith(StringPool.OPEN_BRACKET) || languageKey.endsWith(StringPool.PERIOD) || languageKey.endsWith(StringPool.UNDERLINE) || languageKey.startsWith(StringPool.DASH) || languageKey.startsWith(StringPool.OPEN_BRACKET) || languageKey.startsWith(StringPool.OPEN_CURLY_BRACE) || languageKey.startsWith(StringPool.PERIOD) || languageKey.startsWith(StringPool.UNDERLINE) || _portalLanguageProperties.containsKey(languageKey)) { continue; } Properties languageProperties = getLanguageProperties(fileName); if ((languageProperties == null) || !languageProperties.containsKey(languageKey)) { processErrorMessage( fileName, "missing language key: " + languageKey + StringPool.SPACE + fileName); } } } }
protected String fixHexColors(String content) { Matcher matcher = _hexColorPattern.matcher(content); while (matcher.find()) { String hexColor = matcher.group(1); if (Validator.isNumber(hexColor) || (hexColor.length() < 3)) { continue; } content = StringUtil.replace(content, hexColor, StringUtil.toUpperCase(hexColor)); } return content; }
/** See {@link com.liferay.knowledge.base.util.KnowledgeBaseUtil#getUrlTitle(long, String)} */ private String _getUrlTitle(long id, String title) { if (title == null) { return String.valueOf(id); } title = StringUtil.toLowerCase(title.trim()); if (Validator.isNull(title) || Validator.isNumber(title) || title.equals("rss")) { title = String.valueOf(id); } else { title = FriendlyURLNormalizerUtil.normalize(title, _normalizationFriendlyUrlPattern); } return title.substring(0, 75); }
/** @see com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter */ public static boolean hasFiles(HttpServletRequest request) { try { // Do not use permission checking since this may be called from // other contexts that are also managing the principal User user = _getUser(request); String path = HttpUtil.fixPath(request.getPathInfo()); String[] pathArray = StringUtil.split(path, CharPool.SLASH); if (pathArray.length == 0) { return true; } else if (_PATH_DDM.equals(pathArray[0])) { _checkDDMRecord(pathArray); } else if (Validator.isNumber(pathArray[0])) { _checkFileEntry(pathArray); } else { long groupId = _getGroupId(user.getCompanyId(), pathArray[0]); long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; for (int i = 1; i < pathArray.length; i++) { try { Folder folder = DLAppLocalServiceUtil.getFolder(groupId, folderId, pathArray[i]); folderId = folder.getFolderId(); } catch (NoSuchFolderException nsfe) { if (i != (pathArray.length - 1)) { return false; } pathArray = new String[] {String.valueOf(groupId), String.valueOf(folderId), pathArray[i]}; _checkFileEntry(pathArray); } } } } catch (Exception e) { return false; } return true; }
protected void validate(long userGroupId, long companyId, String name) throws PortalException { if (Validator.isNull(name) || (name.indexOf(CharPool.COMMA) != -1) || (name.indexOf(CharPool.STAR) != -1)) { throw new UserGroupNameException(); } if (Validator.isNumber(name) && !PropsValues.USER_GROUPS_NAME_ALLOW_NUMERIC) { throw new UserGroupNameException(); } UserGroup userGroup = fetchUserGroup(companyId, name); if ((userGroup != null) && (userGroup.getUserGroupId() != userGroupId)) { throw new DuplicateUserGroupException("{name=" + name + "}"); } }
protected void validate(long userGroupId, long companyId, String name) throws PortalException { if (Validator.isNull(name) || (name.indexOf(CharPool.COMMA) != -1) || (name.indexOf(CharPool.STAR) != -1)) { throw new UserGroupNameException(); } if (Validator.isNumber(name) && !PropsValues.USER_GROUPS_NAME_ALLOW_NUMERIC) { throw new UserGroupNameException(); } try { UserGroup userGroup = userGroupFinder.findByC_N(companyId, name); if (userGroup.getUserGroupId() != userGroupId) { throw new DuplicateUserGroupException("{userGroupId=" + userGroupId + "}"); } } catch (NoSuchUserGroupException nsuge) { } }
protected void validate(String comments) throws PortalException { if ((Validator.isNull(comments)) || (Validator.isNumber(comments))) { throw new MembershipRequestCommentsException(); } }
protected void login( ThemeDisplay themeDisplay, ActionRequest actionRequest, ActionResponse actionResponse, PortletPreferences preferences) throws Exception { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); String login = ParamUtil.getString(actionRequest, "login"); String password = actionRequest.getParameter("password"); boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe"); String authType = preferences.getValue("authType", null); // cusotm code ============= try { User tmp = null; UserEntry userEntryTmp = null; if (Validator.isEmailAddress(login)) { tmp = UserLocalServiceUtil.getUserByEmailAddress(PortalUtil.getCompanyId(request), login); login = String.valueOf(tmp.getUserId()); System.out.println("email:" + login); } else if (Validator.isNumber(login)) { // is mobile number // UserEntryLocalServiceUtil.get userEntryTmp = UserEntryLocalServiceUtil.findByMobilePhone(login); login = String.valueOf(userEntryTmp.getUserId()); System.out.println("mobile number:" + login); } else { // userEntryTmp = UserEntryLocalServiceUtil.findByUserName(login); tmp = UserLocalServiceUtil.getUserByScreenName(PortalUtil.getCompanyId(request), login); login = String.valueOf(tmp.getUserId()); System.out.println("userName:"******"/portal/protected"); } else { String redirect = ParamUtil.getString(actionRequest, "redirect"); if (Validator.isNotNull(redirect)) { redirect = PortalUtil.escapeRedirect(redirect); if (!redirect.startsWith(Http.HTTP)) { redirect = getCompleteRedirectURL(request, redirect); } actionResponse.sendRedirect(redirect); } else { boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin"); if (doActionAfterLogin) { return; } else { actionResponse.sendRedirect(themeDisplay.getPathMain()); } } } }
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { User user = null; try { user = _getUser(request); PrincipalThreadLocal.setName(user.getUserId()); PrincipalThreadLocal.setPassword(PortalUtil.getUserPassword(request)); PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user); PermissionThreadLocal.setPermissionChecker(permissionChecker); if (_lastModified) { long lastModified = getLastModified(request); if (lastModified > 0) { long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE); if ((ifModifiedSince > 0) && (ifModifiedSince == lastModified)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } } if (lastModified > 0) { response.setDateHeader(HttpHeaders.LAST_MODIFIED, lastModified); } } String path = HttpUtil.fixPath(request.getPathInfo()); String[] pathArray = StringUtil.split(path, CharPool.SLASH); if (pathArray.length == 0) { sendGroups(response, user, request.getServletPath() + StringPool.SLASH + path); } else { if (_PATH_DDM.equals(pathArray[0])) { sendDDMRecordFile(request, response, pathArray); } else if (Validator.isNumber(pathArray[0])) { sendFile(request, response, user, pathArray); } else { if (isLegacyImageGalleryImageId(request, response)) { return; } Image image = getImage(request, true); if (image != null) { writeImage(image, request, response); } else { sendDocumentLibrary( request, response, user, request.getServletPath() + StringPool.SLASH + path, pathArray); } } } } catch (NoSuchFileEntryException nsfee) { PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, nsfee, request, response); } catch (PrincipalException pe) { processPrincipalException(pe, user, request, response); } catch (Exception e) { PortalUtil.sendError(e, request, response); } }