List of usage examples for com.liferay.portal.kernel.util SystemProperties get
public static String get(String key)
From source file:com.liferay.appadder.portlet.AppAdderPortlet.java
License:Open Source License
protected File getFile(String path, String fileName) throws Exception { String tempDir = SystemProperties.get(SystemProperties.TMP_DIR); File file = new File(tempDir + File.separator + fileName); ClassLoader classLoader = getClass().getClassLoader(); FileUtil.write(file, classLoader.getResourceAsStream(path + fileName)); return file;/*www . ja v a 2 s . co m*/ }
From source file:com.liferay.document.library.document.conversion.internal.DocumentConversionImpl.java
License:Open Source License
@Override public String getFilePath(String id, String targetExtension) { StringBundler sb = new StringBundler(5); sb.append(SystemProperties.get(SystemProperties.TMP_DIR)); sb.append("/liferay/document_conversion/"); sb.append(id);/*from w w w . j a v a 2 s . c o m*/ sb.append(StringPool.PERIOD); sb.append(targetExtension); return sb.toString(); }
From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java
License:Open Source License
protected ZipWriter getZipWriter(String fileName) { if (!ExportImportThreadLocal.isStagingInProcess() || (PropsValues.STAGING_DELETE_TEMP_LAR_ON_FAILURE && PropsValues.STAGING_DELETE_TEMP_LAR_ON_SUCCESS)) { return ZipWriterFactoryUtil.getZipWriter(); }/*from w w w . j a v a2s . c o m*/ return ZipWriterFactoryUtil.getZipWriter( new File(SystemProperties.get(SystemProperties.TMP_DIR) + StringPool.SLASH + fileName)); }
From source file:com.liferay.marketplace.service.impl.AppLocalServiceImpl.java
License:Open Source License
@Override public void installApp(long remoteAppId) throws PortalException { App app = appPersistence.findByRemoteAppId(remoteAppId); if (!DLStoreUtil.hasFile(app.getCompanyId(), CompanyConstants.SYSTEM, app.getFilePath())) { throw new NoSuchFileException(); }/* w w w . ja v a 2s .com*/ String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR) + StringPool.SLASH + Time.getTimestamp(); InputStream inputStream = null; ZipFile zipFile = null; try { inputStream = DLStoreUtil.getFileAsStream(app.getCompanyId(), CompanyConstants.SYSTEM, app.getFilePath()); if (inputStream == null) { throw new IOException("Unable to open file at " + app.getFilePath()); } File liferayPackageFile = FileUtil.createTempFile(inputStream); zipFile = new ZipFile(liferayPackageFile); Enumeration<ZipEntry> enu = (Enumeration<ZipEntry>) zipFile.entries(); while (enu.hasMoreElements()) { ZipEntry zipEntry = enu.nextElement(); String fileName = zipEntry.getName(); if (!fileName.endsWith(".jar") && !fileName.endsWith(".war") && !fileName.endsWith(".xml") && !fileName.endsWith(".zip") && !fileName.equals("liferay-marketplace.properties")) { continue; } if (_log.isInfoEnabled()) { _log.info("Extracting " + fileName + " from app " + app.getAppId()); } InputStream zipInputStream = null; try { zipInputStream = zipFile.getInputStream(zipEntry); if (fileName.equals("liferay-marketplace.properties")) { String propertiesString = StringUtil.read(zipInputStream); Properties properties = PropertiesUtil.load(propertiesString); processMarketplaceProperties(properties); } else { File pluginPackageFile = new File(tmpDir + StringPool.SLASH + fileName); FileUtil.write(pluginPackageFile, zipInputStream); String bundleSymbolicName = StringPool.BLANK; String bundleVersion = StringPool.BLANK; String contextName = StringPool.BLANK; AutoDeploymentContext autoDeploymentContext = new AutoDeploymentContext(); if (fileName.endsWith(".jar")) { Manifest manifest = BundleUtil.getManifest(pluginPackageFile); Attributes attributes = manifest.getMainAttributes(); bundleSymbolicName = GetterUtil.getString(attributes.getValue("Bundle-SymbolicName")); bundleVersion = GetterUtil.getString(attributes.getValue("Bundle-Version")); contextName = GetterUtil.getString(attributes.getValue("Web-ContextPath")); } else { contextName = getContextName(fileName); autoDeploymentContext.setContext(contextName); } autoDeploymentContext.setFile(pluginPackageFile); DeployManagerUtil.deploy(autoDeploymentContext); if (Validator.isNotNull(bundleSymbolicName) || Validator.isNotNull(contextName)) { moduleLocalService.addModule(app.getUserId(), app.getAppId(), bundleSymbolicName, bundleVersion, contextName); } } } finally { StreamUtil.cleanUp(zipInputStream); } } } catch (ZipException ze) { if (_log.isInfoEnabled()) { _log.info("Deleting corrupt package from app " + app.getAppId(), ze); } deleteApp(app); } catch (IOException ioe) { throw new PortalException(ioe.getMessage()); } catch (Exception e) { _log.error(e, e); } finally { FileUtil.deltree(tmpDir); if (zipFile != null) { try { zipFile.close(); } catch (IOException ioe) { } } StreamUtil.cleanUp(inputStream); clearInstalledAppsCache(); } }
From source file:com.liferay.portlet.documentlibrary.store.S3Store.java
License:Open Source License
@Override public void updateFile(long companyId, long repositoryId, long newRepositoryId, String fileName) throws SystemException { try {/*w ww. j a va2 s . c o m*/ S3Object[] s3Objects = _s3Service.listObjects(_s3Bucket, getKey(companyId, repositoryId, fileName), null); for (int i = 0; i < s3Objects.length; i++) { S3Object oldS3Object = s3Objects[i]; String oldKey = oldS3Object.getKey(); oldS3Object = _s3Service.getObject(_s3Bucket, oldKey); File tempFile = new File(SystemProperties.get(SystemProperties.TMP_DIR) + File.separator + PortalUUIDUtil.generate()); FileUtil.write(tempFile, oldS3Object.getDataInputStream()); InputStream is = new FileInputStream(tempFile); String newPrefix = getKey(companyId, newRepositoryId); int x = oldKey.indexOf(CharPool.SLASH); x = oldKey.indexOf(CharPool.SLASH, x + 1); String newKey = newPrefix + oldKey.substring(x + 1, oldKey.length()); S3Object newS3Object = new S3Object(_s3Bucket, newKey); newS3Object.setDataInputStream(is); _s3Service.putObject(_s3Bucket, newS3Object); _s3Service.deleteObject(_s3Bucket, oldKey); FileUtil.delete(tempFile); } } catch (IOException ioe) { throw new SystemException(ioe); } catch (S3ServiceException s3se) { throw new SystemException(s3se); } }
From source file:com.liferay.portlet.documentlibrary.store.S3Store.java
License:Open Source License
public void updateFile(long companyId, long repositoryId, String fileName, String newFileName) throws SystemException { try {/*w w w. ja v a2 s.c o m*/ S3Object[] s3Objects = _s3Service.listObjects(_s3Bucket, getKey(companyId, repositoryId, fileName), null); for (int i = 0; i < s3Objects.length; i++) { S3Object oldS3Object = s3Objects[i]; String oldKey = oldS3Object.getKey(); oldS3Object = _s3Service.getObject(_s3Bucket, oldKey); File tempFile = new File(SystemProperties.get(SystemProperties.TMP_DIR) + File.separator + PortalUUIDUtil.generate()); FileUtil.write(tempFile, oldS3Object.getDataInputStream()); InputStream is = new FileInputStream(tempFile); String newPrefix = getKey(companyId, repositoryId, newFileName); int x = oldKey.indexOf(StringPool.SLASH); x = oldKey.indexOf(CharPool.SLASH, x + 1); x = oldKey.indexOf(CharPool.SLASH, x + 1); String newKey = newPrefix + oldKey.substring(x + 1, oldKey.length()); S3Object newS3Object = new S3Object(_s3Bucket, newKey); newS3Object.setDataInputStream(is); _s3Service.putObject(_s3Bucket, newS3Object); _s3Service.deleteObject(_s3Bucket, oldKey); FileUtil.delete(tempFile); } } catch (IOException ioe) { throw new SystemException(ioe); } catch (S3ServiceException s3se) { throw new SystemException(s3se); } }
From source file:com.liferay.portlet.documentlibrary.util.DocumentConversionUtil.java
License:Open Source License
public static String getFilePath(String id, String targetExtension) { StringBundler sb = new StringBundler(5); sb.append(SystemProperties.get(SystemProperties.TMP_DIR)); sb.append("/liferay/document_conversion/"); sb.append(id);//from w w w .jav a2s . c o m sb.append(StringPool.PERIOD); sb.append(targetExtension); return sb.toString(); }
From source file:com.liferay.portlet.shopping.service.impl.ShoppingItemLocalServiceImpl.java
License:Open Source License
protected void doAddBookItems(long userId, long groupId, long categoryId, String[] isbns) throws IOException, PortalException, SystemException { if (!AmazonRankingsUtil.isEnabled()) { throw new AmazonException("Amazon integration is not enabled"); }/* www . j a va 2s . c om*/ String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR); for (int i = 0; (i < isbns.length) && (i < 50); i++) { String isbn = isbns[i]; AmazonRankings amazonRankings = AmazonRankingsUtil.getAmazonRankings(isbn); if (amazonRankings == null) { continue; } String name = amazonRankings.getProductName(); String description = StringPool.BLANK; String properties = getBookProperties(amazonRankings); int minQuantity = 0; int maxQuantity = 0; double price = amazonRankings.getListPrice(); double discount = 1 - amazonRankings.getOurPrice() / price; boolean taxable = true; double shipping = 0.0; boolean useShippingFormula = true; ShoppingItemPrice itemPrice = shoppingItemPricePersistence.create(0); itemPrice.setMinQuantity(minQuantity); itemPrice.setMaxQuantity(maxQuantity); itemPrice.setPrice(price); itemPrice.setDiscount(discount); itemPrice.setTaxable(taxable); itemPrice.setShipping(shipping); itemPrice.setUseShippingFormula(useShippingFormula); itemPrice.setStatus(ShoppingItemPriceConstants.STATUS_ACTIVE_DEFAULT); boolean requiresShipping = true; int stockQuantity = 0; boolean featured = false; Boolean sale = null; // Small image boolean smallImage = true; String smallImageURL = StringPool.BLANK; File smallImageFile = new File(tmpDir + File.separatorChar + PwdGenerator.getPassword(PwdGenerator.KEY1 + PwdGenerator.KEY2, 12) + ".jpg"); byte[] smallImageBytes = HttpUtil.URLtoByteArray(amazonRankings.getSmallImageURL()); if (smallImageBytes.length < 1024) { smallImage = false; } else { OutputStream os = new FileOutputStream(smallImageFile); os.write(smallImageBytes); os.close(); } // Medium image boolean mediumImage = true; String mediumImageURL = StringPool.BLANK; File mediumImageFile = new File(tmpDir + File.separatorChar + PwdGenerator.getPassword(PwdGenerator.KEY1 + PwdGenerator.KEY2, 12) + ".jpg"); byte[] mediumImageBytes = HttpUtil.URLtoByteArray(amazonRankings.getMediumImageURL()); if (mediumImageBytes.length < 1024) { mediumImage = false; } else { OutputStream os = new FileOutputStream(mediumImageFile); os.write(mediumImageBytes); os.close(); } // Large image boolean largeImage = true; String largeImageURL = StringPool.BLANK; File largeImageFile = new File(tmpDir + File.separatorChar + PwdGenerator.getPassword(PwdGenerator.KEY1 + PwdGenerator.KEY2, 12) + ".jpg"); byte[] largeImageBytes = HttpUtil.URLtoByteArray(amazonRankings.getLargeImageURL()); if (largeImageBytes.length < 1024) { largeImage = false; } else { OutputStream os = new FileOutputStream(largeImageFile); os.write(largeImageBytes); os.close(); } List<ShoppingItemField> itemFields = new ArrayList<ShoppingItemField>(); List<ShoppingItemPrice> itemPrices = new ArrayList<ShoppingItemPrice>(); itemPrices.add(itemPrice); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); addItem(userId, groupId, categoryId, isbn, name, description, properties, StringPool.BLANK, requiresShipping, stockQuantity, featured, sale, smallImage, smallImageURL, smallImageFile, mediumImage, mediumImageURL, mediumImageFile, largeImage, largeImageURL, largeImageFile, itemFields, itemPrices, serviceContext); smallImageFile.delete(); mediumImageFile.delete(); largeImageFile.delete(); } }
From source file:com.liferay.rtl.scripting.ruby.RubyExecutor.java
License:Open Source License
protected void initRubyGems() throws Exception { File rubyGemsJarFile = new File(PropsValues.LIFERAY_LIB_PORTAL_DIR, "ruby-gems.jar"); if (!rubyGemsJarFile.exists()) { if (_log.isWarnEnabled()) { _log.warn(rubyGemsJarFile + " does not exist"); }//from www . j a v a 2s . c om return; } String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR); File rubyDir = new File(tmpDir + "/liferay/ruby"); if (!rubyDir.exists() || (rubyDir.lastModified() < rubyGemsJarFile.lastModified())) { FileUtil.deltree(rubyDir); rubyDir.mkdirs(); ZipUtil.unzip(rubyGemsJarFile, rubyDir); rubyDir.setLastModified(rubyGemsJarFile.lastModified()); } }
From source file:com.liferay.server.manager.internal.executor.PluginExecutor.java
License:Open Source License
protected File getFileItemTempFile(HttpServletRequest request) throws Exception { FileItem fileItem = getFileItem(request); if (fileItem == null) { return null; }/*from w w w.j av a 2 s. c o m*/ File tempDir = new File(SystemProperties.get(SystemProperties.TMP_DIR), PortalUUIDUtil.generate()); if (!tempDir.mkdirs()) { return null; } File tempFile = new File(tempDir, fileItem.getName()); fileItem.write(tempFile); return tempFile; }