List of usage examples for com.liferay.portal.kernel.util Validator isChar
public static boolean isChar(String s)
true if string consists only of upper and lower case English letters. 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 w w .j a v a 2 s . c om*/ 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.liferay.knowledgebase.service.impl.KBStructureLocalServiceImpl.java
License:Open Source License
protected void validate(String title, List<KBStructureField> kbStructureFields) throws PortalException { if (Validator.isNull(title)) { throw new KBStructureTitleException(); }/*from ww w . jav a2 s .c om*/ List<String> kbStructureFieldNames = new ArrayList<String>(); List<String> kbStructureFieldLabels = new ArrayList<String>(); for (KBStructureField kbStructureField : kbStructureFields) { if (Validator.isNull(kbStructureField.getName())) { throw new KBStructureFieldNameException(); } if (kbStructureFieldNames.contains(kbStructureField.getName())) { throw new DuplicateKBStructureFieldNameException(); } for (char c : kbStructureField.getName().toCharArray()) { if (!Validator.isChar(c) && !Validator.isDigit(c) && (c != CharPool.DASH) && (c != CharPool.UNDERLINE)) { throw new KBStructureFieldNameException(); } } kbStructureFieldNames.add(kbStructureField.getName()); if (Validator.isNull(kbStructureField.getLabel())) { throw new KBStructureFieldLabelException(); } if (kbStructureFieldLabels.contains(kbStructureField.getLabel())) { throw new DuplicateKBStructureFieldLabelException(); } kbStructureFieldLabels.add(kbStructureField.getLabel()); List<String> kbStructureOptionLabels = new ArrayList<String>(); List<String> kbStructureOptionValues = new ArrayList<String>(); for (KBStructureOption kbStructureOption : kbStructureField.getKbStructureOptions()) { if (Validator.isNull(kbStructureOption.getLabel())) { throw new KBStructureOptionLabelException(); } if (kbStructureOptionLabels.contains(kbStructureOption.getLabel())) { throw new DuplicateKBStructureOptionLabelException(); } kbStructureOptionLabels.add(kbStructureOption.getLabel()); if (Validator.isNull(kbStructureOption.getValue())) { throw new KBStructureOptionValueException(); } if (kbStructureOptionValues.contains(kbStructureOption.getValue())) { throw new DuplicateKBStructureOptionValueException(); } kbStructureOptionValues.add(kbStructureOption.getValue()); } } }
From source file:com.liferay.portlet.journal.service.impl.JournalStructureLocalServiceImpl.java
License:Open Source License
protected void validate(List<Element> elements, Set<String> elNames) throws PortalException { for (Element element : elements) { if (element.getName().equals("meta-data")) { continue; }/* w ww. jav a 2s . com*/ String elName = element.attributeValue("name", StringPool.BLANK); String elType = element.attributeValue("type", StringPool.BLANK); if (Validator.isNull(elName) || elName.startsWith(JournalStructureConstants.RESERVED)) { throw new StructureXsdException(); } else { char[] c = elType.toCharArray(); for (int i = 0; i < c.length; i++) { if ((!Validator.isChar(c[i])) && (!Validator.isDigit(c[i])) && (c[i] != CharPool.DASH) && (c[i] != CharPool.UNDERLINE)) { throw new StructureXsdException(); } } String completePath = elName; Element parentElement = element.getParent(); while (!parentElement.isRootElement()) { completePath = parentElement.attributeValue("name", StringPool.BLANK) + StringPool.SLASH + completePath; parentElement = parentElement.getParent(); } String elNameLowerCase = completePath.toLowerCase(); if (elNames.contains(elNameLowerCase)) { throw new DuplicateStructureElementException(); } else { elNames.add(elNameLowerCase); } } if (Validator.isNull(elType)) { throw new StructureXsdException(); } validate(element.elements(), elNames); } }
From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java
License:Open Source License
protected String fixSessionKey(String fileName, String content, Pattern pattern) { Matcher matcher = pattern.matcher(content); if (!matcher.find()) { return content; }/*from w w w .java 2 s . com*/ String newContent = content; do { String match = matcher.group(); String s = null; if (pattern.equals(sessionKeyPattern)) { s = StringPool.COMMA; } else if (pattern.equals(taglibSessionKeyPattern)) { s = "key="; } int x = match.indexOf(s); if (x == -1) { continue; } x = x + s.length(); String substring = match.substring(x).trim(); String quote = StringPool.BLANK; if (substring.startsWith(StringPool.APOSTROPHE)) { quote = StringPool.APOSTROPHE; } else if (substring.startsWith(StringPool.QUOTE)) { quote = StringPool.QUOTE; } else { continue; } int y = match.indexOf(quote, x); int z = match.indexOf(quote, y + 1); if ((y == -1) || (z == -1)) { continue; } String prefix = match.substring(0, y + 1); String suffix = match.substring(z); String oldKey = match.substring(y + 1, z); boolean alphaNumericKey = true; for (char c : oldKey.toCharArray()) { if (!Validator.isChar(c) && !Validator.isDigit(c) && (c != CharPool.DASH) && (c != CharPool.UNDERLINE)) { alphaNumericKey = false; } } if (!alphaNumericKey) { continue; } String newKey = TextFormatter.format(oldKey, TextFormatter.O); newKey = TextFormatter.format(newKey, TextFormatter.M); if (newKey.equals(oldKey)) { continue; } String oldSub = prefix.concat(oldKey).concat(suffix); String newSub = prefix.concat(newKey).concat(suffix); newContent = StringUtil.replaceFirst(newContent, oldSub, newSub); } while (matcher.find()); return newContent; }
From source file:org.gnenc.internet.mycourses.portlet.MyCoursesAdminPortlet.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" })
public static boolean validateSite(Site site, List errors) {
boolean valid = true;
if (Validator.isNull(site.getSiteName())) {
errors.add("site-name-required");
valid = false;//from w ww. j ava2 s. c o m
}
if (Validator.isNull(site.getUrl())) {
errors.add("site-url-required");
valid = false;
} else if (Validator.isDomain(site.getUrl())) {
errors.add("site-invalid-url");
valid = false;
}
if (Validator.isNull(site.getEmailDomain())) {
errors.add("site-email-domain-required");
valid = false;
} else if (Validator.isChar(site.getEmailDomain())) {
errors.add("site-invalid-email-domain");
valid = false;
}
if (Validator.isNull(site.getDbServer())) {
errors.add("site-db-server-required");
valid = false;
} else {
// Validate URL
}
if (Validator.isNull(site.getDbName())) {
errors.add("site-db-name-required");
valid = false;
}
if (Validator.isNull(site.getDbUser())) {
errors.add("site-db-user-required");
valid = false;
}
if (Validator.isNull(site.getDbPass())) {
errors.add("site-db-pass-required");
valid = false;
}
return valid;
}
From source file:org.oep.cmon.portlet.ipmslist.business.TraKetQuaXuLy.java
License:Apache License
/** * This is function isNumber/* w w w . j av a 2 s . co m*/ * Version: 1.0 * * History: * DATE AUTHOR DESCRIPTION * ------------------------------------------------- * 3-March-2013 Nam Dinh Create new * @param stringPhone * @return boolean */ public boolean isNumber(String stringPhone) { char[] charPhone = null; if (stringPhone.trim().isEmpty()) { return false; } else { charPhone = stringPhone.toCharArray(); for (char ch : charPhone) { if (Validator.isChar(ch)) { return false; } } } return true; }