protected void validate( Map<Locale, String> nameMap, String xsl, boolean smallImage, String smallImageURL, File smallImageFile, byte[] smallImageBytes) throws PortalException, SystemException { if (nameMap.isEmpty()) { throw new TemplateNameException(); } else if (Validator.isNull(xsl)) { throw new TemplateXslException(); } String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.JOURNAL_IMAGE_EXTENSIONS, StringPool.COMMA); if (smallImage && Validator.isNull(smallImageURL) && (smallImageFile != null) && (smallImageBytes != null)) { String smallImageName = smallImageFile.getName(); if (smallImageName != null) { boolean validSmallImageExtension = false; for (int i = 0; i < imageExtensions.length; i++) { if (StringPool.STAR.equals(imageExtensions[i]) || StringUtil.endsWith(smallImageName, imageExtensions[i])) { validSmallImageExtension = true; break; } } if (!validSmallImageExtension) { throw new TemplateSmallImageNameException(smallImageName); } } long smallImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.JOURNAL_IMAGE_SMALL_MAX_SIZE); if ((smallImageMaxSize > 0) && ((smallImageBytes == null) || (smallImageBytes.length > smallImageMaxSize))) { throw new TemplateSmallImageSizeException(); } } }
static { _allMediaGalleryMimeTypes.addAll( SetUtil.fromArray(PropsUtil.getArray(PropsKeys.DL_FILE_ENTRY_PREVIEW_AUDIO_MIME_TYPES))); _allMediaGalleryMimeTypes.addAll( SetUtil.fromArray(PropsUtil.getArray(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO_MIME_TYPES))); _allMediaGalleryMimeTypes.addAll( SetUtil.fromArray(PropsUtil.getArray(PropsKeys.DL_FILE_ENTRY_PREVIEW_IMAGE_MIME_TYPES))); _allMediaGalleryMimeTypesString = StringUtil.merge(_allMediaGalleryMimeTypes); String[] fileIcons = null; try { fileIcons = PropsUtil.getArray(PropsKeys.DL_FILE_ICONS); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } fileIcons = new String[] {StringPool.BLANK}; } for (int i = 0; i < fileIcons.length; i++) { // Only process non wildcard extensions if (!StringPool.STAR.equals(fileIcons[i])) { // Strip starting period String extension = fileIcons[i]; if (extension.length() > 0) { extension = extension.substring(1); } _fileIcons.add(extension); } } String[] genericNames = PropsUtil.getArray(PropsKeys.DL_FILE_GENERIC_NAMES); for (String genericName : genericNames) { _populateGenericNamesMap(genericName); } }
private void _includeIfUnique( BooleanQuery booleanQuery, boolean like, QueryParser queryParser, Query query, BooleanClause.Occur occur) { if (query instanceof TermQuery) { Set<Term> terms = new HashSet<Term>(); TermQuery termQuery = (TermQuery) query; termQuery.extractTerms(terms); float boost = termQuery.getBoost(); for (Term term : terms) { String termValue = term.text(); if (like) { termValue = termValue.toLowerCase(queryParser.getLocale()); term = term.createTerm(StringPool.STAR.concat(termValue).concat(StringPool.STAR)); query = new WildcardQuery(term); } else { query = new TermQuery(term); } query.setBoost(boost); boolean included = false; for (BooleanClause booleanClause : booleanQuery.getClauses()) { if (query.equals(booleanClause.getQuery())) { included = true; } } if (!included) { booleanQuery.add(query, occur); } } } else if (query instanceof BooleanQuery) { BooleanQuery curBooleanQuery = (BooleanQuery) query; BooleanQuery containerBooleanQuery = new BooleanQuery(); for (BooleanClause booleanClause : curBooleanQuery.getClauses()) { _includeIfUnique( containerBooleanQuery, like, queryParser, booleanClause.getQuery(), booleanClause.getOccur()); } if (containerBooleanQuery.getClauses().length > 0) { booleanQuery.add(containerBooleanQuery, occur); } } else { boolean included = false; for (BooleanClause booleanClause : booleanQuery.getClauses()) { if (query.equals(booleanClause.getQuery())) { included = true; } } if (!included) { booleanQuery.add(query, occur); } } }
protected void validate( long companyId, long itemId, String sku, String name, boolean smallImage, String smallImageURL, File smallImageFile, byte[] smallImageBytes, boolean mediumImage, String mediumImageURL, File mediumImageFile, byte[] mediumImageBytes, boolean largeImage, String largeImageURL, File largeImageFile, byte[] largeImageBytes) throws PortalException, SystemException { if (Validator.isNull(sku)) { throw new ItemSKUException(); } ShoppingItem item = shoppingItemPersistence.fetchByC_S(companyId, sku); if (item != null) { if (itemId > 0) { if (item.getItemId() != itemId) { throw new DuplicateItemSKUException(); } } else { throw new DuplicateItemSKUException(); } } if (Validator.isNull(name)) { throw new ItemNameException(); } String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.SHOPPING_IMAGE_EXTENSIONS, StringPool.COMMA); // Small image if (smallImage && Validator.isNull(smallImageURL) && (smallImageFile != null) && (smallImageBytes != null)) { String smallImageName = smallImageFile.getName(); if (smallImageName != null) { boolean validSmallImageExtension = false; for (int i = 0; i < imageExtensions.length; i++) { if (StringPool.STAR.equals(imageExtensions[i]) || StringUtil.endsWith(smallImageName, imageExtensions[i])) { validSmallImageExtension = true; break; } } if (!validSmallImageExtension) { throw new ItemSmallImageNameException(smallImageName); } } long smallImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE); if ((smallImageMaxSize > 0) && ((smallImageBytes == null) || (smallImageBytes.length > smallImageMaxSize))) { throw new ItemSmallImageSizeException(); } } // Medium image if (mediumImage && Validator.isNull(mediumImageURL) && (mediumImageFile != null) && (mediumImageBytes != null)) { String mediumImageName = mediumImageFile.getName(); if (mediumImageName != null) { boolean validMediumImageExtension = false; for (int i = 0; i < imageExtensions.length; i++) { if (StringPool.STAR.equals(imageExtensions[i]) || StringUtil.endsWith(mediumImageName, imageExtensions[i])) { validMediumImageExtension = true; break; } } if (!validMediumImageExtension) { throw new ItemMediumImageNameException(mediumImageName); } } long mediumImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE); if ((mediumImageMaxSize > 0) && ((mediumImageBytes == null) || (mediumImageBytes.length > mediumImageMaxSize))) { throw new ItemMediumImageSizeException(); } } // Large image if (!largeImage || Validator.isNotNull(largeImageURL) || (largeImageFile == null) || (largeImageBytes == null)) { return; } String largeImageName = largeImageFile.getName(); if (largeImageName != null) { boolean validLargeImageExtension = false; for (int i = 0; i < imageExtensions.length; i++) { if (StringPool.STAR.equals(imageExtensions[i]) || StringUtil.endsWith(largeImageName, imageExtensions[i])) { validLargeImageExtension = true; break; } } if (!validLargeImageExtension) { throw new ItemLargeImageNameException(largeImageName); } } long largeImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_LARGE_MAX_SIZE); if ((largeImageMaxSize > 0) && ((largeImageBytes == null) || (largeImageBytes.length > largeImageMaxSize))) { throw new ItemLargeImageSizeException(); } }