List of usage examples for com.liferay.portal.kernel.util StringPool PERIOD
String PERIOD
To view the source code for com.liferay.portal.kernel.util StringPool PERIOD.
Click Source Link
From source file:br.com.thiagomoreira.liferay.plugins.fixvirtualhost.FixVirtualHostAction.java
License:Apache License
private String fixVirtualHost(String virtualHost, String virtualHostOldPrefix, String virtualHostNewPrefix) { if (Validator.isNotNull(virtualHost) && !virtualHost.startsWith(virtualHostNewPrefix)) { if (virtualHost.startsWith(virtualHostOldPrefix)) { return virtualHost.replaceFirst(virtualHostOldPrefix, virtualHostNewPrefix); } else {// ww w . j ava 2 s .c o m return virtualHostNewPrefix + StringPool.PERIOD + virtualHost; } } return null; }
From source file:ch.inofix.referencemanager.model.impl.ReferenceImpl.java
License:Open Source License
private String getNameFormatted(String[] nameParts) { // names[0] = first; // names[1] = von; // names[2] = last; // names[3] = jr; StringBuilder sb = new StringBuilder(); if (Validator.isNotNull(nameParts[2])) { sb.append(nameParts[2]);/* ww w . jav a2 s .c o m*/ } if (Validator.isNotNull(nameParts[0])) { sb.append(StringPool.COMMA); sb.append(StringPool.SPACE); sb.append(nameParts[0].trim().substring(0, 1)); sb.append(StringPool.PERIOD); if (Validator.isNotNull(nameParts[1])) { sb.append(StringPool.SPACE); sb.append(nameParts[1]); } } if (Validator.isNotNull(nameParts[3])) { // TODO: how do we handle the jr part? // sb.append(nameParts[3]); } return sb.toString(); }
From source file:com.cd.learning.hook.MBUtil.java
License:Open Source License
public static String getReplyToAddress(long categoryId, long messageId, String mx, String defaultMailingListAddress) { if (PropsUtil.get(PropsKeys.POP_SERVER_SUBDOMAIN).length() <= 0) { return defaultMailingListAddress; }//ww w .j a v a 2s. co m StringBundler sb = new StringBundler(8); sb.append(MESSAGE_POP_PORTLET_PREFIX); sb.append(categoryId); sb.append(StringPool.PERIOD); sb.append(messageId); sb.append(StringPool.AT); sb.append(PropsUtil.get(PropsKeys.POP_SERVER_SUBDOMAIN)); sb.append(StringPool.PERIOD); sb.append(mx); return sb.toString(); }
From source file:com.evolveum.liferay.usercreatehook.screenname.CustomScreenNameGenerator.java
License:Apache License
public String generate(long companyId, long userId, String emailAddress) throws Exception { String screenName = null;//w ww .j a va 2 s .co m if (Validator.isNotNull(emailAddress)) { // XXX change 1 // screenName = StringUtil.extractFirst(emailAddress, CharPool.AT).toLowerCase(); screenName = emailAddress.toLowerCase(); for (char c : screenName.toCharArray()) { // XXX change 2 // if (!Validator.isChar(c) && !Validator.isDigit(c) && (c != CharPool.DASH) && (c != CharPool.PERIOD)) // { if (!Validator.isChar(c) && !Validator.isDigit(c) && (c != CharPool.DASH)) { // XXX change 3 // screenName = StringUtil.replace(screenName, c, CharPool.PERIOD); screenName = StringUtil.replace(screenName, c, CharPool.DASH); } } if (screenName.equals(DefaultScreenNameValidator.CYRUS) || screenName.equals(DefaultScreenNameValidator.POSTFIX)) { screenName += StringPool.PERIOD + userId; } } else { screenName = String.valueOf(userId); } if (!_USERS_SCREEN_NAME_ALLOW_NUMERIC && Validator.isNumber(screenName)) { screenName = _NON_NUMERICAL_PREFIX + screenName; } String[] reservedScreenNames = PrefsPropsUtil.getStringArray(companyId, PropsKeys.ADMIN_RESERVED_SCREEN_NAMES, StringPool.NEW_LINE, _ADMIN_RESERVED_SCREEN_NAMES); for (String reservedScreenName : reservedScreenNames) { if (screenName.equalsIgnoreCase(reservedScreenName)) { return getUnusedScreenName(companyId, screenName); } } try { UserLocalServiceUtil.getUserByScreenName(companyId, screenName); } catch (NoSuchUserException nsue) { try { GroupLocalServiceUtil.getFriendlyURLGroup(companyId, StringPool.SLASH + screenName); } catch (NoSuchGroupException nsge) { return screenName; } } return getUnusedScreenName(companyId, screenName); }
From source file:com.evolveum.liferay.usercreatehook.screenname.CustomScreenNameGenerator.java
License:Apache License
protected String getUnusedScreenName(long companyId, String screenName) throws PortalException, SystemException { for (int i = 1;; i++) { String tempScreenName = screenName + StringPool.PERIOD + i; try {/* w w w.ja va 2 s. c o m*/ UserLocalServiceUtil.getUserByScreenName(companyId, tempScreenName); } catch (NoSuchUserException nsue) { try { GroupLocalServiceUtil.getFriendlyURLGroup(companyId, StringPool.SLASH + tempScreenName); } catch (NoSuchGroupException nsge) { screenName = tempScreenName; break; } } } return screenName; }
From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java
private boolean verifyJobTitle(ActionRequest actionRequest) { boolean isValid = true; String jobTitle = ParamUtil.getString(actionRequest, "jobTitle", StringPool.BLANK); jobTitle = jobTitle.replace(StringPool.PERIOD, StringPool.BLANK).replace(StringPool.MINUS, StringPool.BLANK);/* w ww . ja v a 2s . com*/ if (isInputLengthValid(jobTitle)) { SessionErrors.add(actionRequest, "job-title-invalid-length-error"); isValid = false; } if (!isAlphaSpaceStringInput(jobTitle)) { SessionErrors.add(actionRequest, "job-title-invalid-characters-error"); isValid = false; } return isValid; }
From source file:com.fingence.slayer.service.impl.BridgeServiceImpl.java
License:Open Source License
private int getType(String className, String type) { int _type = 0; try {/*from w w w . ja v a 2 s . c o m*/ List<ListType> listTypes = ListTypeServiceUtil.getListTypes(className + StringPool.PERIOD + type); for (ListType listType : listTypes) { if (listType.getName().equalsIgnoreCase("business")) { _type = listType.getListTypeId(); break; } } } catch (SystemException e) { e.printStackTrace(); } return _type; }
From source file:com.fmdp.webform.action.ConfigurationActionImpl.java
License:Open Source License
protected void validateFields(ActionRequest actionRequest) throws Exception { // Locale defaultLocale = LocaleUtil.getDefault(); // String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale); boolean sendAsEmail = GetterUtil.getBoolean(getParameter(actionRequest, "sendAsEmail")); String subject = getParameter(actionRequest, "subject"); boolean sendThanksEmail = GetterUtil.getBoolean(getParameter(actionRequest, "sendThanksEmail")); String thanksSubject = getParameter(actionRequest, "thanks-subject"); boolean saveToDatabase = GetterUtil.getBoolean(getParameter(actionRequest, "saveToDatabase")); boolean showPreviousPosts = GetterUtil.getBoolean(getParameter(actionRequest, "showPreviousPosts")); boolean saveToFile = GetterUtil.getBoolean(getParameter(actionRequest, "saveToFile")); if (!sendAsEmail && !saveToDatabase && !saveToFile) { SessionErrors.add(actionRequest, "handlingRequired"); }/*from w ww . j av a 2 s. c o m*/ if (sendAsEmail) { if (Validator.isNull(subject)) { SessionErrors.add(actionRequest, "subjectRequired"); } String[] emailAdresses = WebFormUtil.split(getParameter(actionRequest, "emailAddress")); if (emailAdresses.length == 0) { SessionErrors.add(actionRequest, "emailAddressRequired"); } for (String emailAdress : emailAdresses) { emailAdress = emailAdress.trim(); if (!Validator.isEmailAddress(emailAdress)) { SessionErrors.add(actionRequest, "emailAddressInvalid"); } } if (sendThanksEmail) { if (Validator.isNull(thanksSubject)) { SessionErrors.add(actionRequest, "thanksSubjectRequired"); } } } boolean uploadToDisk = GetterUtil.getBoolean(getParameter(actionRequest, "uploadToDisk")); if (uploadToDisk) { String uploadDiskDir = getParameter(actionRequest, "uploadDiskDir"); boolean pathIsValid = true; try { File checkFolder = null; checkFolder = new File(uploadDiskDir); if (!checkFolder.isDirectory()) { pathIsValid = false; SessionErrors.add(actionRequest, "pathNameInvalid"); } } catch (SecurityException se) { pathIsValid = false; SessionErrors.add(actionRequest, "pathNameInvalid"); } catch (NullPointerException ne) { pathIsValid = false; SessionErrors.add(actionRequest, "pathNameInvalid"); } if (pathIsValid) { StringBundler tmpFile = new StringBundler(3); tmpFile.append(StringUtil.randomString()); tmpFile.append(StringPool.PERIOD); tmpFile.append("tmp"); String tmpFileName = uploadDiskDir + File.separator + tmpFile.toString(); // Check if server can create a file as specified try { FileOutputStream fileOutputStream = new FileOutputStream(tmpFileName, true); fileOutputStream.close(); } catch (SecurityException se) { SessionErrors.add(actionRequest, "pathNameInvalid"); } catch (FileNotFoundException fnfe) { SessionErrors.add(actionRequest, "pathNameInvalid"); } } } if (saveToFile) { String fileName = getParameter(actionRequest, "fileName"); // Check if server can create a file as specified try { FileOutputStream fileOutputStream = new FileOutputStream(fileName, true); fileOutputStream.close(); } catch (SecurityException se) { SessionErrors.add(actionRequest, "fileNameInvalid"); } catch (FileNotFoundException fnfe) { SessionErrors.add(actionRequest, "fileNameInvalid"); } } if (saveToDatabase) { int i = 1; String languageId = LocaleUtil.toLanguageId(actionRequest.getLocale()); String fieldLabel = ParamUtil.getString(actionRequest, "fieldLabel" + i + "_" + languageId); while ((i == 1) || Validator.isNotNull(fieldLabel)) { if (fieldLabel.length() > 75) { SessionErrors.add(actionRequest, "fieldSizeInvalid" + i); } i++; fieldLabel = ParamUtil.getString(actionRequest, "fieldLabel" + i + "_" + languageId); } } if (!saveToDatabase && showPreviousPosts) { SessionErrors.add(actionRequest, "noPreviousPosts"); } if (!validateUniqueFieldNames(actionRequest)) { SessionErrors.add(actionRequest, DuplicateColumnNameException.class.getName()); } }
From source file:com.fmdp.webform.portlet.WebFormPortlet.java
License:Open Source License
public void saveData(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); String portletId = PortalUtil.getPortletId(actionRequest); PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletId); boolean requireCaptcha = GetterUtil.getBoolean(preferences.getValue("requireCaptcha", StringPool.BLANK)); String successURL = GetterUtil.getString(preferences.getValue("successURL", StringPool.BLANK)); boolean sendAsEmail = GetterUtil.getBoolean(preferences.getValue("sendAsEmail", StringPool.BLANK)); boolean sendThanksEmail = GetterUtil.getBoolean(preferences.getValue("sendThanksEmail", StringPool.BLANK)); boolean saveToDatabase = GetterUtil.getBoolean(preferences.getValue("saveToDatabase", StringPool.BLANK)); String databaseTableName = GetterUtil .getString(preferences.getValue("databaseTableName", StringPool.BLANK)); boolean saveToFile = GetterUtil.getBoolean(preferences.getValue("saveToFile", StringPool.BLANK)); boolean uploadToDisk = GetterUtil.getBoolean(preferences.getValue("uploadToDisk", StringPool.BLANK)); boolean uploadToDM = GetterUtil.getBoolean(preferences.getValue("uploadToDM", StringPool.BLANK)); long newFolderId = GetterUtil.getLong(preferences.getValue("newFolderId", StringPool.BLANK)); String fileName = GetterUtil.getString(preferences.getValue("fileName", StringPool.BLANK)); String uploadDiskDir = GetterUtil.getString(preferences.getValue("uploadDiskDir", StringPool.BLANK)); if (requireCaptcha) { try {/*from w w w. j a v a2 s . c o m*/ CaptchaUtil.check(actionRequest); } catch (CaptchaTextException cte) { SessionErrors.add(actionRequest, CaptchaTextException.class.getName()); return; } } UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest); Map<String, String> fieldsMap = new LinkedHashMap<String, String>(); String fileAttachment = ""; for (int i = 1; true; i++) { String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK); String fieldType = preferences.getValue("fieldType" + i, StringPool.BLANK); if (Validator.isNull(fieldLabel)) { break; } if (StringUtil.equalsIgnoreCase(fieldType, "paragraph")) { continue; } if (StringUtil.equalsIgnoreCase(fieldType, "file")) { if (_log.isDebugEnabled()) { _log.debug("Field name for file: " + fieldLabel); } File file = uploadRequest.getFile("field" + i); String sourceFileName = uploadRequest.getFileName("field" + i); if (_log.isDebugEnabled()) { _log.debug("File attachment: " + sourceFileName); } JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); if (Validator.isNotNull(sourceFileName) && !"".equals(sourceFileName)) { if (uploadRequest.getSize("field" + i) == 0) { SessionErrors.add(actionRequest, "uploadToDiskError", "Uploaded file size is 0"); if (_log.isDebugEnabled()) { _log.debug("Uploaded file size is 0"); } return; } // List<String> uploadResults = new ArrayList<String>(); String uploadResult = ""; if (uploadToDisk) { uploadResult = uploadFile(file, sourceFileName, uploadDiskDir); if (uploadResult.equalsIgnoreCase("File Upload Error")) { SessionErrors.add(actionRequest, "uploadToDiskError", uploadResult); return; } fileAttachment = uploadDiskDir + File.separator + uploadResult; //uploadResults.add(uploadResult); jsonObject.put("fsOriginalName", sourceFileName); jsonObject.put("fsName", uploadResult); } if (uploadToDM) { uploadResult = ""; String contentType = MimeTypesUtil.getContentType(file); Folder folderName = DLAppLocalServiceUtil.getFolder(newFolderId); if (_log.isDebugEnabled()) { _log.debug("DM Folder: " + folderName.getName()); } InputStream inputStream = new FileInputStream(file); long repositoryId = folderName.getRepositoryId(); try { String selectedFileName = sourceFileName; while (true) { try { DLAppLocalServiceUtil.getFileEntry(themeDisplay.getScopeGroupId(), newFolderId, selectedFileName); StringBundler sb = new StringBundler(5); sb.append(FileUtil.stripExtension(selectedFileName)); sb.append(StringPool.DASH); sb.append(StringUtil.randomString()); sb.append(StringPool.PERIOD); sb.append(FileUtil.getExtension(selectedFileName)); selectedFileName = sb.toString(); } catch (Exception e) { break; } } FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), repositoryId, newFolderId, selectedFileName, //file.getName(), contentType, selectedFileName, "", "", inputStream, file.length(), serviceContext); if (_log.isDebugEnabled()) { _log.debug("DM file uploade: " + fileEntry.getTitle()); } //Map<String, Serializable> workflowContext = new HashMap<String, Serializable>(); //workflowContext.put("event",DLSyncConstants.EVENT_UPDATE); //DLFileEntryLocalServiceUtil.updateStatus(themeDisplay.getUserId(), fileEntry.getFileVersion().getFileVersionId(), WorkflowConstants.STATUS_APPROVED, workflowContext, serviceContext); uploadResult = String.valueOf(fileEntry.getFileEntryId()); //uploadResults.add(uploadResult); String docUrl = themeDisplay.getPortalURL() + "/c/document_library/get_file?uuid=" + fileEntry.getUuid() + "&groupId=" + themeDisplay.getScopeGroupId(); jsonObject.put("fe", uploadResult); jsonObject.put("feOriginalName", sourceFileName); jsonObject.put("feName", fileEntry.getTitle()); jsonObject.put("feUrl", docUrl); } catch (PortalException pe) { SessionErrors.add(actionRequest, "uploadToDmError"); _log.error("The upload to DM failed", pe); return; } catch (Exception e) { _log.error("The upload to DM failed", e); return; } } jsonObject.put("Status", "With Attachment"); } else { jsonObject.put("Status", "No Attachment"); } fieldsMap.put(fieldLabel, jsonObject.toString()); } else { fieldsMap.put(fieldLabel, uploadRequest.getParameter("field" + i)); } } Set<String> validationErrors = null; try { validationErrors = validate(fieldsMap, preferences); } catch (Exception e) { SessionErrors.add(actionRequest, "validationScriptError", e.getMessage().trim()); return; } User currentUser = PortalUtil.getUser(actionRequest); String userEmail = ""; if (!Validator.isNull(currentUser)) { userEmail = currentUser.getEmailAddress(); if (_log.isDebugEnabled()) { _log.debug("User email for the form author: " + userEmail); } fieldsMap.put("email-from", userEmail); } else { fieldsMap.put("email-from", "guest"); } DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone(themeDisplay.getTimeZone().getID())); Date dateobj = new Date(); fieldsMap.put("email-sent-on", df.format(dateobj)); if (validationErrors.isEmpty()) { boolean emailSuccess = true; boolean databaseSuccess = true; boolean fileSuccess = true; boolean emailThanksSuccess = true; if (sendAsEmail) { emailSuccess = WebFormUtil.sendEmail(themeDisplay.getCompanyId(), fieldsMap, preferences, fileAttachment); } if (sendThanksEmail && !Validator.isNull(currentUser)) { emailThanksSuccess = WebFormUtil.sendThanksEmail(themeDisplay.getCompanyId(), fieldsMap, preferences, userEmail); } if (saveToDatabase) { if (Validator.isNull(databaseTableName)) { databaseTableName = WebFormUtil.getNewDatabaseTableName(portletId); preferences.setValue("databaseTableName", databaseTableName); preferences.store(); } databaseSuccess = saveDatabase(themeDisplay.getCompanyId(), fieldsMap, preferences, databaseTableName); } if (saveToFile) { fileSuccess = saveFile(fieldsMap, fileName); } if (emailSuccess && emailThanksSuccess && databaseSuccess && fileSuccess) { if (Validator.isNull(successURL)) { SessionMessages.add(actionRequest, "success"); } else { SessionMessages.add(actionRequest, portletId + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); } } else { SessionErrors.add(actionRequest, "error"); } } else { for (String badField : validationErrors) { SessionErrors.add(actionRequest, "error" + badField); } } if (SessionErrors.isEmpty(actionRequest) && Validator.isNotNull(successURL)) { actionResponse.sendRedirect(successURL); } }
From source file:com.inikah.slayer.model.impl.ProfileImpl.java
License:Open Source License
/** * /*w ww .j a va 2s . c o m*/ * @return */ public double getComputeAge() { double age = 0.0d; int bornOn = getBornOn(); if (bornOn == 0) return age; Calendar now = Calendar.getInstance(); int nowYear = now.get(Calendar.YEAR); int nowMonth = now.get(Calendar.MONTH); int bornYear = Integer.valueOf(String.valueOf(bornOn).substring(0, 4)); int bornMonth = Integer.valueOf(String.valueOf(bornOn).substring(4)); int decimalPart = nowMonth - bornMonth; int wholePart = nowYear - bornYear; if (decimalPart < 0) { decimalPart += 12; --wholePart; } return Double.valueOf(wholePart + StringPool.PERIOD + decimalPart); }