List of usage examples for com.liferay.portal.kernel.util StringUtil endsWith
public static boolean endsWith(String s, String end)
true if the string ends with the string end, ignoring case. From source file:com.dtt.portal.dao.vbpq.util.VanBanPhapQuyUtils.java
License:Open Source License
public static String getExtensionFile(String fileName) { String extensionFile = StringPool.BLANK; if (StringUtil.endsWith(fileName, ".pdf") || StringUtil.endsWith(fileName, ".PDF")) { extensionFile = "PDF"; }/*from www .j ava 2s. com*/ if (StringUtil.endsWith(fileName, ".doc") || StringUtil.endsWith(fileName, ".DOC")) { extensionFile = "DOC"; } if (StringUtil.endsWith(fileName, ".docx") || StringUtil.endsWith(fileName, ".DOCX")) { extensionFile = "DOC"; } if (StringUtil.endsWith(fileName, ".xls") || StringUtil.endsWith(fileName, ".XLS")) { extensionFile = "XLS"; } if (StringUtil.endsWith(fileName, ".xlsx") || StringUtil.endsWith(fileName, ".XLSX")) { extensionFile = "XLS"; } return extensionFile; }
From source file:com.dtt.portal.dao.vbpq.util.VanBanPhapQuyUtils.java
License:Open Source License
public static boolean validateFile(String videoFileName, byte[] vanBanFileBytes) throws VanBanFileException { boolean flag = false; String[] validFileExtensions = PortletPropsValues.VAN_BAN_FILE_EXTENSIONS; // Validate upload file extension for (int i = 0; i < validFileExtensions.length; i++) { String validExtension = validFileExtensions[i].toLowerCase(); if (!Validator.equals(validExtension, StringPool.STAR) && StringUtil.endsWith(videoFileName, validExtension)) { flag = true;//from w ww .j av a 2s. c o m break; } } if (!flag) { throw new VanBanFileException(); } long fileMaxSize = PortletPropsValues.VAN_BAN_FILE_MAX_SIZE; // Validate upload file size if (vanBanFileBytes != null) { if (vanBanFileBytes.length > 0 && fileMaxSize > 0 && vanBanFileBytes.length > fileMaxSize) { flag = false; throw new VanBanFileException(); } } return flag; }
From source file:com.liferay.calendarimporter.source.LotusNotesImportSource.java
License:Open Source License
@Override protected void doExecuteImport(Calendar calendar, UnicodeProperties typeSettingsProperties) throws Exception { String url = typeSettingsProperties.getProperty("url"); String userName = typeSettingsProperties.getProperty("user-name"); String password = typeSettingsProperties.getProperty("password"); if (!StringUtil.endsWith(url, CharPool.SLASH)) { url += CharPool.SLASH;//from www . ja va 2s . c o m } url += _EVENTS_PATH; Http.Options options = new Http.Options(); options.setAuth(null, 0, null, userName, password); options.setLocation(url); String json = HttpUtil.URLtoString(options); if (Validator.isNull(json)) { return; } JSONObject jsonObject = JSONFactoryUtil.createJSONObject(json); JSONArray eventsJSON = jsonObject.getJSONArray("events"); importEvents(calendar, eventsJSON); }
From source file:com.liferay.document.library.internal.util.DLValidatorImpl.java
License:Open Source License
@Override public void validateFileExtension(String fileName) throws FileExtensionException { boolean validFileExtension = false; String[] fileExtensions = _dlConfiguration.fileExtensions(); for (String fileExtension : fileExtensions) { if (StringPool.STAR.equals(fileExtension) || StringUtil.endsWith(fileName, fileExtension)) { validFileExtension = true;//from ww w. j a v a 2 s.c o m break; } } if (!validFileExtension) { throw new FileExtensionException(fileName); } }
From source file:com.liferay.dynamic.data.mapping.service.impl.DDMTemplateLocalServiceImpl.java
License:Open Source License
protected void validate(long groupId, Map<Locale, String> nameMap, String script, boolean smallImage, String smallImageURL, File smallImageFile, byte[] smallImageBytes) throws PortalException { validate(groupId, nameMap, script);//ww w. j a va 2 s . co m if (!smallImage || Validator.isNotNull(smallImageURL) || (smallImageFile == null) || (smallImageBytes == null)) { return; } String smallImageName = smallImageFile.getName(); boolean validSmallImageExtension = false; DDMGroupServiceConfiguration ddmGroupServiceConfiguration = getDDMGroupServiceConfiguration(groupId); for (String smallImageExtension : ddmGroupServiceConfiguration.smallImageExtensions()) { if (StringPool.STAR.equals(smallImageExtension) || StringUtil.endsWith(smallImageName, smallImageExtension)) { validSmallImageExtension = true; break; } } if (!validSmallImageExtension) { throw new TemplateSmallImageNameException(smallImageName); } long smallImageMaxSize = ddmGroupServiceConfiguration.smallImageMaxSize(); if ((smallImageMaxSize > 0) && (smallImageBytes.length > smallImageMaxSize)) { throw new TemplateSmallImageSizeException( StringBundler.concat("Image ", smallImageName, " has ", String.valueOf(smallImageBytes.length), " bytes and exceeds the maximum size of ", String.valueOf(smallImageMaxSize))); } }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected void validate(long companyId, long groupId, long classNameId, Map<Locale, String> titleMap, String content, String ddmStructureKey, String ddmTemplateKey, Date displayDate, Date expirationDate, boolean smallImage, String smallImageURL, File smallImageFile, byte[] smallImageBytes, ServiceContext serviceContext) throws PortalException { Locale articleDefaultLocale = LocaleUtil.fromLanguageId(LocalizationUtil.getDefaultLanguageId(content)); if (!ExportImportThreadLocal.isImportInProcess()) { if (!LanguageUtil.isAvailableLocale(groupId, articleDefaultLocale)) { LocaleException le = new LocaleException(LocaleException.TYPE_CONTENT, "The locale " + articleDefaultLocale + " is not available in site with groupId" + groupId); le.setSourceAvailableLocales(Collections.singleton(articleDefaultLocale)); le.setTargetAvailableLocales(LanguageUtil.getAvailableLocales(groupId)); throw le; }/* ww w .j a v a 2s.c o m*/ if ((expirationDate != null) && (expirationDate.before(new Date()) || ((displayDate != null) && expirationDate.before(displayDate)))) { throw new ArticleExpirationDateException("Expiration date " + expirationDate + " is in the past"); } } if ((classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) && (titleMap.isEmpty() || Validator.isNull(titleMap.get(articleDefaultLocale)))) { throw new ArticleTitleException("Title is null"); } validateContent(content); DDMStructure ddmStructure = ddmStructureLocalService.getStructure(PortalUtil.getSiteGroupId(groupId), classNameLocalService.getClassNameId(JournalArticle.class), ddmStructureKey, true); validateDDMStructureFields(ddmStructure, classNameId, content, articleDefaultLocale); if (Validator.isNotNull(ddmTemplateKey)) { DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(PortalUtil.getSiteGroupId(groupId), classNameLocalService.getClassNameId(DDMStructure.class), ddmTemplateKey, true); if (ddmTemplate.getClassPK() != ddmStructure.getStructureId()) { throw new NoSuchTemplateException("{templateKey=" + ddmTemplateKey + "}"); } } else if (classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) { throw new NoSuchTemplateException("DDM template key is null"); } if (!smallImage || Validator.isNotNull(smallImageURL) || (smallImageFile == null) || (smallImageBytes == null)) { return; } String smallImageName = smallImageFile.getName(); boolean validSmallImageExtension = false; for (String imageExtension : _journalFileUploadsConfiguration.imageExtensions()) { if (StringPool.STAR.equals(imageExtension) || StringUtil.endsWith(smallImageName, imageExtension)) { validSmallImageExtension = true; break; } } if (!validSmallImageExtension) { throw new ArticleSmallImageNameException(smallImageName); } long smallImageMaxSize = _journalFileUploadsConfiguration.smallImageMaxSize(); if ((smallImageMaxSize > 0) && (smallImageBytes.length > smallImageMaxSize)) { throw new ArticleSmallImageSizeException(smallImageBytes.length + " exceeds " + smallImageMaxSize); } }
From source file:com.liferay.knowledgebase.admin.importer.util.KBArticleImporterUtil.java
License:Open Source License
public static void validateImageFileExtension(String imageFileName) throws KBArticleImportException { boolean validImageFileExtension = false; for (String fileExtension : PortletPropsValues.MARKDOWN_IMPORTER_IMAGE_FILE_EXTENSIONS) { if (StringPool.STAR.equals(fileExtension) || StringUtil.endsWith(imageFileName, fileExtension)) { validImageFileExtension = true; break; }//from w w w. j a v a 2 s . c o m } if (!validImageFileExtension) { throw new KBArticleImportException(imageFileName); } }
From source file:com.liferay.knowledgebase.admin.util.AdminUtil.java
License:Open Source License
public static String[] unescapeSections(String sections) { String[] sectionsArray = StringUtil.split(sections); for (int i = 0; i < sectionsArray.length; i++) { String section = sectionsArray[i]; if (StringUtil.startsWith(section, StringPool.UNDERLINE) && StringUtil.endsWith(section, StringPool.UNDERLINE)) { sectionsArray[i] = section.substring(1, section.length() - 1); }/*from w w w . j a va 2 s .c o m*/ } return sectionsArray; }
From source file:com.liferay.portlet.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
protected void validate(String title, String content, boolean smallImage, String smallImageURL, String smallImageFileName, byte[] smallImageBytes) throws PortalException, SystemException { if (Validator.isNull(title)) { throw new EntryTitleException(); } else if (Validator.isNull(content)) { throw new EntryContentException(); }/*w ww . ja v a 2s . co m*/ String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.BLOGS_IMAGE_EXTENSIONS, StringPool.COMMA); if (smallImage && Validator.isNull(smallImageURL) && (smallImageBytes != null)) { if (smallImageFileName != null) { boolean validSmallImageExtension = false; for (String _imageExtension : imageExtensions) { if (StringPool.STAR.equals(_imageExtension) || StringUtil.endsWith(smallImageFileName, _imageExtension)) { validSmallImageExtension = true; break; } } if (!validSmallImageExtension) { throw new EntrySmallImageNameException(smallImageFileName); } } long smallImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.BLOGS_IMAGE_SMALL_MAX_SIZE); if ((smallImageMaxSize > 0) && ((smallImageBytes == null) || (smallImageBytes.length > smallImageMaxSize))) { throw new EntrySmallImageSizeException(); } } }
From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java
License:Open Source License
public void validate(String fileName, boolean validateFileExtension) throws PortalException, SystemException { if (!isValidName(fileName)) { throw new FileNameException(fileName); }// w ww . ja v a 2 s . co m if (validateFileExtension) { boolean validFileExtension = false; String[] fileExtensions = PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA); for (String fileExtension : fileExtensions) { if (StringPool.STAR.equals(fileExtension) || StringUtil.endsWith(fileName, fileExtension) //Looks like Liferay's bug. Original file name should be checked! //But in this place we have changed fileName. //So, also checked original name. || StringUtil.endsWith(fileName, fileExtension + "_temp.tmp")) { validFileExtension = true; break; } } if (!validFileExtension) { throw new FileExtensionException(fileName); } } }