Example usage for com.liferay.portal.kernel.util Validator isEmailAddress

List of usage examples for com.liferay.portal.kernel.util Validator isEmailAddress

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util Validator isEmailAddress.

Prototype

public static boolean isEmailAddress(String emailAddress) 

Source Link

Document

Returns true if the string is a valid email address.

Usage

From source file:com.demo.one.service.impl.EntryLocalServiceImpl.java

License:Open Source License

protected void validate(String name, String email, String entry) throws PortalException {
    if (Validator.isNull(name)) {
        throw new EntryNameException();
    }//from w  w w. j  av a2s  .com

    if (!Validator.isEmailAddress(email)) {
        throw new EntryEmailException();
    }

    if (Validator.isNull(entry)) {
        throw new EntryMessageException();
    }
}

From source file:com.evolveum.liferay.usercreatehook.screenname.CustomScreenNameValidator.java

License:Apache License

public boolean validate(long companyId, String screenName) {
    if (Validator.isEmailAddress(screenName) || screenName.equalsIgnoreCase(CYRUS)
            || screenName.equalsIgnoreCase(POSTFIX) || (screenName.indexOf(CharPool.SLASH) != -1)
            || (screenName.indexOf(CharPool.UNDERLINE) != -1)) {

        return false;
    } else {//from   w  w w. j ava  2 s. c o m
        return true;
    }
}

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  w  w  . java 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.liferay.adduser.service.impl.UserInfoLocalServiceImpl.java

License:Open Source License

protected void validate(String code, String username, String email, String phone) throws PortalException {
    if (Validator.isNull(code)) {
        throw new UserInfoCodeException();
    }/* w w  w. j a va 2  s  .  co  m*/

    if (!Validator.isAlphanumericName(code)) {
        throw new UserInfoCodeException();
    }

    if (Validator.isNull(username)) {
        throw new UserInfoUsernameException();
    }

    if (!Validator.isEmailAddress(email)) {
        throw new UserInfoEmailException();
    }

    if (!Validator.isPhoneNumber(phone)) {
        throw new UserInfoPhoneException();
    }
}

From source file:com.liferay.contacts.service.impl.EntryLocalServiceImpl.java

License:Open Source License

protected void validate(long companyId, long entryId, long userId, String fullName, String emailAddress)
        throws PortalException {

    if (Validator.isNull(fullName)) {
        throw new ContactFullNameException();
    }/*  w w  w .  j  a  v a 2  s  .c  o m*/

    if (Validator.isNull(emailAddress)) {
        throw new RequiredEntryEmailAddressException();
    }

    if (!Validator.isEmailAddress(emailAddress)) {
        throw new EntryEmailAddressException();
    }

    if (entryId > 0) {
        Entry entry = entryPersistence.findByPrimaryKey(entryId);

        if (!StringUtil.equalsIgnoreCase(emailAddress, entry.getEmailAddress())) {

            validateEmailAddress(companyId, userId, emailAddress);
        }
    } else {
        validateEmailAddress(companyId, userId, emailAddress);
    }
}

From source file:com.liferay.docs.guestbook.service.impl.GuestbookEntryLocalServiceImpl.java

License:Open Source License

protected void validate(String name, String email, String entry) throws PortalException {

    if (Validator.isNull(name)) {
        throw new GuestbookEntryNameException();
    }/* ww  w  . j av  a  2s.c o  m*/

    if (!Validator.isEmailAddress(email)) {
        throw new GuestbookEntryEmailException();
    }

    if (Validator.isNull(entry)) {
        throw new GuestbookEntryMessageException();
    }
}

From source file:com.liferay.dynamic.data.mapping.form.evaluator.functions.IsEmailAddressFunction.java

License:Open Source License

@Override
public Object evaluate(Object... parameters) {
    if (parameters.length != 1) {
        throw new IllegalArgumentException("One parameter is expected");
    }/*  w w  w  .java2  s  . c o  m*/

    return Validator.isEmailAddress(parameters[0].toString());
}

From source file:com.liferay.flags.service.impl.FlagsEntryServiceImpl.java

License:Open Source License

@Override
public void addEntry(String className, long classPK, String reporterEmailAddress, long reportedUserId,
        String contentTitle, String contentURL, String reason, ServiceContext serviceContext)
        throws PortalException {

    if (!Validator.isEmailAddress(reporterEmailAddress)) {
        throw new EmailAddressException();
    }/*from  ww  w  . j  ava  2s.c o m*/

    FlagsRequest flagsRequest = new FlagsRequest(className, classPK, reporterEmailAddress, reportedUserId,
            contentTitle, contentURL, reason, serviceContext);

    MessageBusUtil.sendMessage(DestinationNames.FLAGS, flagsRequest);
}

From source file:com.liferay.invitation.invite.members.service.impl.MemberRequestLocalServiceImpl.java

License:Open Source License

@Override
public void addMemberRequests(long userId, long groupId, String[] emailAddresses, long invitedRoleId,
        long invitedTeamId, ServiceContext serviceContext) throws PortalException {

    for (String emailAddress : emailAddresses) {
        if (!Validator.isEmailAddress(emailAddress)) {
            continue;
        }//from www . j ava  2 s .  co m

        addMemberRequest(userId, groupId, 0, emailAddress, invitedRoleId, invitedTeamId, serviceContext);
    }
}

From source file:com.liferay.jbpm.WorkflowComponentImpl.java

License:Open Source License

protected String validate(TaskFormElement taskFormElement, Map parameterMap) {

    String error = null;//ww w  .j a  v a  2s.  c o m

    String type = taskFormElement.getType();
    String name = taskFormElement.getDisplayName();
    String value = getParamValue(parameterMap, name);

    if (type.equals(TaskFormElement.TYPE_CHECKBOX)) {
        if (taskFormElement.isRequired() && value.equals("false")) {
            error = "required-value";
        }
    } else if (type.equals(TaskFormElement.TYPE_DATE)) {
        value = getParamValue(parameterMap, JS.getSafeName(name));

        if (taskFormElement.isRequired()) {
            try {
                formatDate(value);

                String[] dateValues = StringUtil.split(value, "/");

                int month = GetterUtil.getInteger(dateValues[0]) - 1;
                int day = GetterUtil.getInteger(dateValues[1]);
                int year = GetterUtil.getInteger(dateValues[2]);

                if (!Validator.isDate(month, day, year)) {
                    error = "invalid-date";
                }
            } catch (Exception e) {
                error = "invalid-date";
            }
        }
    } else if (type.equals(TaskFormElement.TYPE_EMAIL)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        } else if (!Validator.isNull(value) && !Validator.isEmailAddress(value)) {

            error = "invalid-email";
        }
    } else if (type.equals(TaskFormElement.TYPE_NUMBER)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        } else if (!Validator.isNull(value) && !Validator.isNumber(value)) {
            error = "invalid-number";
        }
    } else if (type.equals(TaskFormElement.TYPE_PASSWORD)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        }
    } else if (type.equals(TaskFormElement.TYPE_PHONE)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        } else if (!Validator.isNull(value) && !Validator.isPhoneNumber(value)) {

            error = "invalid-phone";
        }
    } else if (type.equals(TaskFormElement.TYPE_RADIO)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        }
    } else if (type.equals(TaskFormElement.TYPE_SELECT)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        }
    } else if (type.equals(TaskFormElement.TYPE_TEXT)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        }
    } else if (type.equals(TaskFormElement.TYPE_TEXTAREA)) {
        if (taskFormElement.isRequired() && Validator.isNull(value)) {
            error = "required-value";
        }
    }

    return error;
}