List of usage examples for com.liferay.portal.kernel.util StringPool COMMA
String COMMA
To view the source code for com.liferay.portal.kernel.util StringPool COMMA.
Click Source Link
From source file:com.liferay.osb.scv.user.mapper.service.persistence.impl.UserMappingRulePersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, UserMappingRule> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }/*from ww w . j av a 2 s.c o m*/ Map<Serializable, UserMappingRule> map = new HashMap<Serializable, UserMappingRule>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); UserMappingRule userMappingRule = fetchByPrimaryKey(primaryKey); if (userMappingRule != null) { map.put(primaryKey, userMappingRule); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = entityCache.getResult(UserMappingRuleModelImpl.ENTITY_CACHE_ENABLED, UserMappingRuleImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (UserMappingRule) serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_USERMAPPINGRULE_WHERE_PKS_IN); for (Serializable primaryKey : uncachedPrimaryKeys) { query.append(String.valueOf(primaryKey)); query.append(StringPool.COMMA); } query.setIndex(query.index() - 1); query.append(StringPool.CLOSE_PARENTHESIS); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); for (UserMappingRule userMappingRule : (List<UserMappingRule>) q.list()) { map.put(userMappingRule.getPrimaryKeyObj(), userMappingRule); cacheResult(userMappingRule); uncachedPrimaryKeys.remove(userMappingRule.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { entityCache.putResult(UserMappingRuleModelImpl.ENTITY_CACHE_ENABLED, UserMappingRuleImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }
From source file:com.liferay.pokedex.service.persistence.impl.PokemonPersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, Pokemon> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }/*from ww w .j a va 2 s. com*/ Map<Serializable, Pokemon> map = new HashMap<Serializable, Pokemon>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); Pokemon pokemon = fetchByPrimaryKey(primaryKey); if (pokemon != null) { map.put(primaryKey, pokemon); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = entityCache.getResult(PokemonModelImpl.ENTITY_CACHE_ENABLED, PokemonImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (Pokemon) serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_POKEMON_WHERE_PKS_IN); for (Serializable primaryKey : uncachedPrimaryKeys) { query.append(String.valueOf(primaryKey)); query.append(StringPool.COMMA); } query.setIndex(query.index() - 1); query.append(StringPool.CLOSE_PARENTHESIS); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); for (Pokemon pokemon : (List<Pokemon>) q.list()) { map.put(pokemon.getPrimaryKeyObj(), pokemon); cacheResult(pokemon); uncachedPrimaryKeys.remove(pokemon.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { entityCache.putResult(PokemonModelImpl.ENTITY_CACHE_ENABLED, PokemonImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }
From source file:com.liferay.portlet.asset.util.AssetUtil.java
License:Open Source License
public static String getAssetKeywords(String className, long classPK) throws SystemException { List<AssetTag> tags = AssetTagLocalServiceUtil.getTags(className, classPK); List<AssetCategory> categories = AssetCategoryLocalServiceUtil.getCategories(className, classPK); StringBuffer sb = new StringBuffer(); sb.append(ListUtil.toString(tags, AssetTag.NAME_ACCESSOR)); if (!tags.isEmpty()) { sb.append(StringPool.COMMA); }/* w w w. j av a 2s.c o m*/ sb.append(ListUtil.toString(categories, AssetCategory.NAME_ACCESSOR)); return sb.toString(); }
From source file:com.liferay.portlet.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
protected void pingTrackbacks(BlogsEntry entry, String[] trackbacks, boolean pingOldTrackbacks, ServiceContext serviceContext) throws SystemException { if (!PropsValues.BLOGS_TRACKBACK_ENABLED || !entry.isAllowTrackbacks() || !entry.isApproved()) { return;// w w w . j a v a2 s .co m } String layoutFullURL = serviceContext.getLayoutFullURL(); if (Validator.isNull(layoutFullURL)) { return; } Map<String, String> parts = new HashMap<String, String>(); String excerpt = StringUtil.shorten(HtmlUtil.extractText(entry.getContent()), PropsValues.BLOGS_LINKBACK_EXCERPT_LENGTH); String url = layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs/" + entry.getUrlTitle(); parts.put("title", entry.getTitle()); parts.put("excerpt", excerpt); parts.put("url", url); parts.put("blog_name", entry.getUserName()); Set<String> trackbacksSet = null; if (Validator.isNotNull(trackbacks)) { trackbacksSet = SetUtil.fromArray(trackbacks); } else { trackbacksSet = new HashSet<String>(); } if (pingOldTrackbacks) { trackbacksSet.addAll(SetUtil.fromArray(StringUtil.split(entry.getTrackbacks()))); entry.setTrackbacks(StringPool.BLANK); blogsEntryPersistence.update(entry, false); } Set<String> oldTrackbacks = SetUtil.fromArray(StringUtil.split(entry.getTrackbacks())); Set<String> validTrackbacks = new HashSet<String>(); for (String trackback : trackbacksSet) { if (oldTrackbacks.contains(trackback)) { continue; } try { if (LinkbackProducerUtil.sendTrackback(trackback, parts)) { validTrackbacks.add(trackback); } } catch (Exception e) { _log.error("Error while sending trackback at " + trackback, e); } } if (!validTrackbacks.isEmpty()) { String newTrackbacks = StringUtil.merge(validTrackbacks); if (Validator.isNotNull(entry.getTrackbacks())) { newTrackbacks += StringPool.COMMA + entry.getTrackbacks(); } entry.setTrackbacks(newTrackbacks); blogsEntryPersistence.update(entry, false); } }
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(); }/*www . j av a2s .c om*/ 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.currencyconverter.util.CurrencyWebCacheItem.java
License:Open Source License
public Object convert(String key) throws WebCacheException { String symbol = _symbol;/*from www .j av a2s . c o m*/ double rate = 0.0; try { if (symbol.length() == 6) { String fromSymbol = symbol.substring(0, 3); String toSymbol = symbol.substring(3, 6); if (!CurrencyUtil.isCurrency(fromSymbol) || !CurrencyUtil.isCurrency(toSymbol)) { throw new WebCacheException(symbol); } } else if (symbol.length() == 3) { if (!CurrencyUtil.isCurrency(symbol)) { throw new WebCacheException(symbol); } } else { throw new WebCacheException(symbol); } String text = HttpUtil .URLtoString("http://finance.yahoo.com/d/quotes.csv?s=" + symbol + "=X&f=sl1d1t1c1ohgv&e=.csv"); StringTokenizer st = new StringTokenizer(text, StringPool.COMMA); // Skip symbol st.nextToken(); rate = GetterUtil.getDouble(st.nextToken().replace('"', ' ').trim()); } catch (Exception e) { throw new WebCacheException(e); } return new Currency(symbol, rate); }
From source file:com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryTypeFinderImpl.java
License:Open Source License
protected List<DLFileEntryType> findByC_G_N_D_S(long companyId, long[] groupIds, String[] names, String[] descriptions, boolean andOperator, boolean includeBasicFileEntryType, int start, int end, OrderByComparator orderByComparator) throws SystemException { names = CustomSQLUtil.keywords(names); descriptions = CustomSQLUtil.keywords(descriptions, false); Session session = null;/*from w w w .j a v a2 s .c om*/ try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_C_G_N_D_S); sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(includeBasicFileEntryType)); sql = StringUtil.replace(sql, "[$GROUP_ID$]", getGroupIds(groupIds)); sql = CustomSQLUtil.replaceKeywords(sql, "lower(name)", StringPool.LIKE, false, names); sql = CustomSQLUtil.replaceKeywords(sql, "description", StringPool.LIKE, false, descriptions); sql = CustomSQLUtil.replaceAndOperator(sql, andOperator); if (orderByComparator != null) { String orderByFields = StringUtil.merge(orderByComparator.getOrderByFields(), StringPool.COMMA); sql = StringUtil.replace(sql, "name ASC", orderByFields.concat(" DESC")); } SQLQuery q = session.createSQLQuery(sql); q.addEntity("DLFileEntryType", DLFileEntryTypeImpl.class); QueryPos qPos = QueryPos.getInstance(q); if (includeBasicFileEntryType) { qPos.add(names, 2); qPos.add(descriptions, 2); } qPos.add(companyId); qPos.add(groupIds); qPos.add(names, 2); qPos.add(descriptions, 2); return (List<DLFileEntryType>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
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); }//from w w w. j av a 2 s . c o 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); } } }
From source file:com.liferay.portlet.documentlibrary.util.DLFileEntryIndexer.java
License:Open Source License
@Override protected Document doGetDocument(Object obj) throws Exception { DLFileEntry dlFileEntry = (DLFileEntry) obj; _log.info("COGNIZANT@@@@doGetDocument::::: TILE::::" + dlFileEntry.getTitle() + "FileEntryID::::" + dlFileEntry.getFileEntryId()); if (_log.isDebugEnabled()) { _log.debug("Indexing document " + dlFileEntry); }//from w w w .jav a2s . co m boolean indexContent = true; InputStream is = null; try { if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) { indexContent = false; } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) { if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) { indexContent = false; } } if (indexContent) { String[] ignoreExtensions = PrefsPropsUtil .getStringArray(PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA); if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) { indexContent = false; } } if (indexContent) { is = dlFileEntry.getFileVersion().getContentStream(false); } } catch (Exception e) { _log.error("COGNIZANT@@@@doGetDocument@@CATCH1:::::" + dlFileEntry.getFileEntryId() + "@@@@@" + dlFileEntry.getTitle() + "@@@@", e); fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId()); try { fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath); } catch (IOException e1) { _log.error("Error Generating CSV", e1); } } DLFileVersion dlFileVersion = dlFileEntry.getFileVersion(); try { Document document = getBaseModelDocument(PORTLET_ID, dlFileEntry, dlFileVersion); if (indexContent) { if (is != null) { try { document.addFile(Field.CONTENT, is, dlFileEntry.getTitle()); } catch (IOException ioe) { throw new SearchException("Cannot extract text from file" + dlFileEntry); } } else if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " does not have any content"); } } document.addKeyword(Field.CLASS_TYPE_ID, dlFileEntry.getFileEntryTypeId()); document.addText(Field.DESCRIPTION, dlFileEntry.getDescription()); document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId()); document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder()); document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties()); document.addText(Field.TITLE, dlFileEntry.getTitle()); document.addKeyword(Field.TREE_PATH, StringUtil.split(dlFileEntry.getTreePath(), CharPool.SLASH)); document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId()); document.addText("ddmContent", extractContent(dlFileVersion, LocaleUtil.getSiteDefault())); document.addKeyword("extension", dlFileEntry.getExtension()); document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId()); document.addKeyword("mimeType", StringUtil.replace(dlFileEntry.getMimeType(), CharPool.FORWARD_SLASH, CharPool.UNDERLINE)); document.addKeyword("path", dlFileEntry.getTitle()); document.addKeyword("readCount", dlFileEntry.getReadCount()); document.addKeyword("size", dlFileEntry.getSize()); ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(dlFileEntry.getCompanyId(), DLFileEntry.class.getName(), dlFileVersion.getFileVersionId()); ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge); addFileEntryTypeAttributes(document, dlFileVersion); if (dlFileEntry.isInHiddenFolder()) { try { Repository repository = RepositoryLocalServiceUtil.getRepository(dlFileEntry.getRepositoryId()); String portletId = repository.getPortletId(); for (Indexer indexer : IndexerRegistryUtil.getIndexers()) { if (portletId.equals(indexer.getPortletId())) { indexer.addRelatedEntryFields(document, obj); } } } catch (Exception e) { _log.error("COGNIZANT@@@@doGetDocument@@CATCH2:::" + dlFileEntry.getFileEntryId() + "@@@@" + dlFileEntry.getTitle() + "@@@@", e); fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId()); try { fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath); } catch (IOException e1) { _log.error("Error Generating CSV", e1); } } } if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " indexed successfully"); } return document; } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { _log.error("COGNIZANT@@@@doGetDocument@@CATCH3:::" + dlFileEntry.getFileEntryId() + "@@@@" + dlFileEntry.getTitle() + "@@@@", ioe); fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId()); try { fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath); } catch (IOException e1) { _log.error("Error Generating CSV", e1); } } } } }
From source file:com.liferay.portlet.documentlibrary.util.DLIndexer.java
License:Open Source License
@Override protected Document doGetDocument(Object obj) throws Exception { DLFileEntry dlFileEntry = (DLFileEntry) obj; if (_log.isDebugEnabled()) { _log.debug("Indexing document " + dlFileEntry); }/*from w ww. j a v a 2 s . c o m*/ boolean indexContent = true; InputStream is = null; try { if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) { indexContent = false; } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) { if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) { indexContent = false; } } if (indexContent) { String[] ignoreExtensions = PrefsPropsUtil .getStringArray(PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA); if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) { indexContent = false; } } if (indexContent) { is = dlFileEntry.getFileVersion().getContentStream(false); } } catch (Exception e) { } if (indexContent && (is == null)) { if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " does not have any content"); } return null; } try { Document document = new DocumentImpl(); long fileEntryId = dlFileEntry.getFileEntryId(); document.addUID(PORTLET_ID, fileEntryId); List<AssetCategory> assetCategories = AssetCategoryLocalServiceUtil .getCategories(DLFileEntry.class.getName(), fileEntryId); long[] assetCategoryIds = StringUtil .split(ListUtil.toString(assetCategories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L); document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds); String[] assetCategoryNames = StringUtil .split(ListUtil.toString(assetCategories, AssetCategory.NAME_ACCESSOR)); document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames); String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(DLFileEntry.class.getName(), fileEntryId); document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames); document.addKeyword(Field.COMPANY_ID, dlFileEntry.getCompanyId()); if (indexContent) { try { document.addFile(Field.CONTENT, is, dlFileEntry.getTitle()); } catch (IOException ioe) { throw new SearchException("Cannot extract text from file" + dlFileEntry); } } document.addText(Field.DESCRIPTION, dlFileEntry.getDescription()); document.addKeyword(Field.ENTRY_CLASS_NAME, DLFileEntry.class.getName()); document.addKeyword(Field.ENTRY_CLASS_PK, fileEntryId); document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId()); document.addKeyword(Field.GROUP_ID, getParentGroupId(dlFileEntry.getGroupId())); document.addDate(Field.MODIFIED_DATE, dlFileEntry.getModifiedDate()); document.addKeyword(Field.PORTLET_ID, PORTLET_ID); document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties()); document.addKeyword(Field.SCOPE_GROUP_ID, dlFileEntry.getGroupId()); DLFileVersion dlFileVersion = dlFileEntry.getFileVersion(); document.addKeyword(Field.STATUS, dlFileVersion.getStatus()); document.addText(Field.TITLE, dlFileEntry.getTitle()); long userId = dlFileEntry.getUserId(); document.addKeyword(Field.USER_ID, userId); document.addKeyword(Field.USER_NAME, PortalUtil.getUserName(userId, dlFileEntry.getUserName()), true); document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId()); document.addKeyword("extension", dlFileEntry.getExtension()); document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId()); document.addKeyword("path", dlFileEntry.getTitle()); ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(dlFileEntry.getCompanyId(), DLFileEntry.class.getName(), dlFileVersion.getFileVersionId()); ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge); addFileEntryTypeAttributes(document, dlFileVersion); if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " indexed successfully"); } return document; } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { } } } }