Example usage for com.liferay.portal.kernel.util PrefsPropsUtil getString

List of usage examples for com.liferay.portal.kernel.util PrefsPropsUtil getString

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PrefsPropsUtil getString.

Prototype

public static String getString(String name) 

Source Link

Usage

From source file:com.liferay.faces.demos.bean.DocUploadBackingBean.java

License:Open Source License

public String getMaxFileSizeKB() {

    if (maxFileSizeKB == null) {

        try {/*  w  w  w. jav  a2 s . c  o m*/
            long maxFileSizeBytes = GetterUtil.getLong(PrefsPropsUtil.getString(PropsKeys.DL_FILE_MAX_SIZE));
            maxFileSizeKB = MessageFormat.format("{0}", (maxFileSizeBytes / 1024L));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }

    return maxFileSizeKB;
}

From source file:com.liferay.marketplace.app.manager.web.internal.portlet.MarketplaceAppManagerPortlet.java

License:Open Source License

public void installLocalApp(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

    String fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file"));

    File file = uploadPortletRequest.getFile("file");

    byte[] bytes = FileUtil.getBytes(file);

    if (ArrayUtil.isEmpty(bytes)) {
        SessionErrors.add(actionRequest, UploadException.class.getName());
    } else if (!fileName.endsWith(".jar") && !fileName.endsWith(".lpkg") && !fileName.endsWith(".war")) {

        throw new FileExtensionException();
    } else {/*from   ww w.  jav  a  2  s  .c o m*/
        String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR);

        FileUtil.copyFile(file.toString(), deployDir + StringPool.SLASH + fileName);

        SessionMessages.add(actionRequest, "pluginUploaded");
    }

    sendRedirect(actionRequest, actionResponse);
}

From source file:com.liferay.marketplace.app.manager.web.internal.portlet.MarketplaceAppManagerPortlet.java

License:Open Source License

protected int doInstallRemoteApp(String url, ActionRequest actionRequest, boolean failOnError)
        throws Exception {

    int responseCode = HttpServletResponse.SC_OK;

    try {/*from w  w  w  . j  a  va  2 s .c om*/
        String fileName = null;

        Http.Options options = new Http.Options();

        options.setFollowRedirects(false);
        options.setLocation(url);
        options.setPost(false);

        byte[] bytes = HttpUtil.URLtoByteArray(options);

        Http.Response response = options.getResponse();

        responseCode = response.getResponseCode();

        if ((responseCode == HttpServletResponse.SC_OK) && (bytes.length > 0)) {

            String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR);

            String destination = deployDir + StringPool.SLASH + fileName;

            File destinationFile = new File(destination);

            FileUtil.write(destinationFile, bytes);

            SessionMessages.add(actionRequest, "pluginDownloaded");
        } else {
            if (failOnError) {
                SessionErrors.add(actionRequest, UploadException.class.getName());
            }

            responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        }
    } catch (MalformedURLException murle) {
        SessionErrors.add(actionRequest, "invalidUrl", murle);
    } catch (IOException ioe) {
        SessionErrors.add(actionRequest, "errorConnectingToUrl", ioe);
    }

    return responseCode;
}

From source file:com.liferay.marketplace.appmanager.portlet.AppManagerPortlet.java

License:Open Source License

public void installApp(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    String installMethod = ParamUtil.getString(uploadPortletRequest, "installMethod");

    if (installMethod.equals("local")) {
        String fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file"));

        File file = uploadPortletRequest.getFile("file");

        byte[] bytes = FileUtil.getBytes(file);

        if (ArrayUtil.isEmpty(bytes)) {
            SessionErrors.add(actionRequest, UploadException.class.getName());
        } else {/*from   w  w w  . jav  a  2  s  .  c  o  m*/
            String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR);

            FileUtil.copyFile(file.toString(), deployDir + StringPool.SLASH + fileName);

            SessionMessages.add(actionRequest, "pluginUploaded");
        }
    } else {
        try {
            String url = ParamUtil.getString(uploadPortletRequest, "url");

            URL urlObj = new URL(url);

            String host = urlObj.getHost();

            if (host.endsWith("sf.net") || host.endsWith("sourceforge.net")) {

                doInstallSourceForgeApp(urlObj.getPath(), uploadPortletRequest, actionRequest);
            } else {
                doInstallRemoteApp(url, uploadPortletRequest, actionRequest, true);
            }
        } catch (MalformedURLException murle) {
            SessionErrors.add(actionRequest, "invalidUrl", murle);
        }
    }

    String redirect = ParamUtil.getString(uploadPortletRequest, "redirect");

    actionResponse.sendRedirect(redirect);
}

From source file:com.liferay.marketplace.appmanager.portlet.AppManagerPortlet.java

License:Open Source License

protected int doInstallRemoteApp(String url, UploadPortletRequest uploadPortletRequest,
        ActionRequest actionRequest, boolean failOnError) throws Exception {

    int responseCode = HttpServletResponse.SC_OK;

    String deploymentContext = ParamUtil.getString(uploadPortletRequest, "deploymentContext");

    try {/*from   ww w  . j  ava 2  s .  c o m*/
        String fileName = null;

        if (Validator.isNotNull(deploymentContext)) {
            fileName = DEPLOY_TO_PREFIX + deploymentContext + ".war";
        } else {
            fileName = url.substring(url.lastIndexOf(CharPool.SLASH) + 1);

            int pos = fileName.lastIndexOf(CharPool.PERIOD);

            if (pos != -1) {
                deploymentContext = fileName.substring(0, pos);
            }
        }

        Http.Options options = new Http.Options();

        options.setFollowRedirects(false);
        options.setLocation(url);
        options.setPortletRequest(actionRequest);
        options.setPost(false);

        String progressId = ParamUtil.getString(uploadPortletRequest, Constants.PROGRESS_ID);

        options.setProgressId(progressId);

        byte[] bytes = HttpUtil.URLtoByteArray(options);

        Http.Response response = options.getResponse();

        responseCode = response.getResponseCode();

        if ((responseCode == HttpServletResponse.SC_OK) && (bytes.length > 0)) {

            String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR);

            String destination = deployDir + StringPool.SLASH + fileName;

            File destinationFile = new File(destination);

            FileUtil.write(destinationFile, bytes);

            SessionMessages.add(actionRequest, "pluginDownloaded");
        } else {
            if (failOnError) {
                SessionErrors.add(actionRequest, UploadException.class.getName());
            }

            responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        }
    } catch (MalformedURLException murle) {
        SessionErrors.add(actionRequest, "invalidUrl", murle);
    } catch (IOException ioe) {
        SessionErrors.add(actionRequest, "errorConnectingToUrl", ioe);
    }

    return responseCode;
}

From source file:com.liferay.portlet.PortletBagFactory.java

License:Open Source License

protected void initScheduler(SchedulerEntry schedulerEntry) throws Exception {

    String propertyKey = schedulerEntry.getPropertyKey();

    if (Validator.isNotNull(propertyKey)) {
        String triggerValue = null;

        if (_warFile) {
            triggerValue = getPluginPropertyValue(propertyKey);
        } else {//from   w w w  . j  av a  2 s. co  m
            triggerValue = PrefsPropsUtil.getString(propertyKey);
        }

        if (_log.isDebugEnabled()) {
            _log.debug("Scheduler property key " + propertyKey + " has trigger value " + triggerValue);
        }

        if (Validator.isNull(triggerValue)) {
            throw new SchedulerException("Property key " + propertyKey + " requires a value");
        }

        schedulerEntry.setTriggerValue(triggerValue);
    }

    SchedulerEngineUtil.schedule(schedulerEntry, StorageType.MEMORY_CLUSTERED, _classLoader, 0);
}

From source file:com.liferay.shopping.service.impl.ShoppingItemLocalServiceImpl.java

License:Open Source License

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, Exception {

    if (Validator.isNull(sku)) {
        throw new ItemSKUException();
    }//from  w  ww. j a  v a 2  s.  com

    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 = GetterUtil
                .getLong(PrefsPropsUtil.getString(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 = GetterUtil
                .getLong(PrefsPropsUtil.getString(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE));

        if ((mediumImageMaxSize > 0)
                && ((mediumImageBytes == null) || (mediumImageBytes.length > mediumImageMaxSize))) {

            throw new ItemMediumImageSizeException();
        }
    }

    // Large image

    if (largeImage && Validator.isNull(largeImageURL) && largeImageFile != null && largeImageBytes != null) {

        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 = GetterUtil
                .getLong(PrefsPropsUtil.getString(PropsKeys.SHOPPING_IMAGE_LARGE_MAX_SIZE));

        if ((largeImageMaxSize > 0)
                && ((largeImageBytes == null) || (largeImageBytes.length > largeImageMaxSize))) {

            throw new ItemLargeImageSizeException();
        }
    }
}

From source file:com.sohlman.profiler.liferay.ProfilerFilter.java

License:Apache License

@Override
public void init(FilterConfig filterConfig) {
    super.init(filterConfig);
    try {/*from   w w w .ja v  a 2  s. co  m*/

        long thresHoldMillis = GetterUtil.get(PrefsPropsUtil.getString(PROFILE_THRESHOLDMILLIS), 5000);
        String rowIdentifier = GetterUtil.get(PrefsPropsUtil.getString(PROFILE_ROWIDENTIFIER),
                "THREADLOCALPROFILER");
        String thresholdReached = GetterUtil.get(PrefsPropsUtil.getString(PROFILE_THRESHOLDREACHED_IDENTIFIER),
                "THRESHOLD-REACHED");
        ThreadLocalProfiler.setDisabled(GetterUtil.get(PrefsPropsUtil.getString(PROFILE_DISABLED), true));

        LiferayLogReporter liferayLogReporter = new LiferayLogReporter(thresHoldMillis, rowIdentifier,
                thresholdReached, getLog());

        ThreadLocalProfiler.setReporter(liferayLogReporter);

    } catch (Exception exception) {
        getLog().error("Problem while reading properties", exception);
    }
}

From source file:com.stoxx.logout.post.action.LogoutPostAction.java

License:Open Source License

@Override
public void run(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = null;//from www .ja  v  a2  s  .c  o m
    LastPath lastPathnew = null;
    try {
        session = request.getSession();
        String contextPath = "/web";
        lastPathnew = new LastPath(contextPath, "/stoxxcom/home");
        User _user = PortalUtil.getUser(request);
        if (Validator.isNotNull(_user)) {
            List<UserGroup> userGroups = UserGroupLocalServiceUtil.getUserUserGroups(_user.getUserId());
            _log.info(
                    ">>>>>>>>> logout url " + request.getRequestURL() + " user is " + _user.getEmailAddress());
            String lastPathAction = (String) request.getSession().getAttribute("lasPathString");
            _log.info("custom last path" + lastPathAction);
            Object lastPath = request.getSession().getAttribute("LAST_PATH");
            if (Validator.isNotNull(lastPath)) {
                _log.info("The last path is " + lastPath.toString());
            } else {
                _log.info("Last Path is null");
            }

            for (UserGroup userGroup : userGroups) {
                _log.info("the usergroup names is " + userGroup.getName());
                if (userGroup.getName()
                        .equalsIgnoreCase(PrefsPropsUtil.getString("stoxx.usergroup.customer"))) {
                    lastPathnew = new LastPath(contextPath, "/stoxxcom/home");
                    break;
                } else if (userGroup.getName()
                        .equalsIgnoreCase(PrefsPropsUtil.getString("stoxx.usergroup.translator"))
                        || userGroup.getName()
                                .equalsIgnoreCase(PrefsPropsUtil.getString("stoxx.usergroup.staff.user"))) {
                    lastPathnew = new LastPath(contextPath, "/stoxxnet/login");
                    break;
                } else if (userGroup.getName()
                        .equalsIgnoreCase(PrefsPropsUtil.getString("dax.usergroup.user"))) {
                    lastPathnew = new LastPath(contextPath, "/dax/login");
                    break;
                } else {
                    lastPathnew = new LastPath(contextPath, "/stoxxcom/home");
                }
            }
        }
        session.setAttribute(WebKeys.LAST_PATH, lastPathnew);
    } catch (Exception e) {
        _log.info(e.getMessage(), e);
    }
}

From source file:com.stoxx.portlet.accountdetails.controller.AccountDetailsController.java

@ActionMapping(params = "action=deleteUser")
public void deleteUser(final ActionRequest request, final ActionResponse response,
        @ModelAttribute("accountDetails") AccountDetails accountDetails, final Model model) {
    Map<String, Object> emailBodyMap = new HashMap<String, Object>();
    try {/*from w  w  w . j a v a 2s . co m*/
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
        String emailTemplateFolder = "templates";
        String emailVelocityTemplate = StringPool.BLANK;
        emailVelocityTemplate = emailTemplateFolder + "/" + "keyAccHolderDeactivationMail.vm";
        String deleteEmail = request.getParameter("deleteEmail");

        log.info("accountDetails.getKeyAccHolderName()>>>>> " + accountDetails.getKeyAccHolderName());
        log.info("deleteEmail>>>>> " + deleteEmail);

        if (StringUtils.isNotBlank(accountDetails.getKeyAccHolderName())
                && StringUtils.isNotBlank(deleteEmail)) {
            emailBodyMap.put(TO_NAME, deleteEmail);
            emailBodyMap.put(FROM_NAME, PrefsPropsUtil.getString("stoxx-mail-from-name"));
            emailBodyMap.put(FROM_ADDRESS, PropsUtil.get(STOXX_MAIL_FROM_ADDRESS));
            emailBodyMap.put(PORTAL_URL, PrefsPropsUtil.getString("stoxx-mail-from-url"));

            emailBodyMap.put(MESSAGE_SECTION,
                    LanguageUtil.get(themeDisplay.getLocale(), "stoxx-accountDetails-delete-licenced-user")
                            + StringPool.SPACE + accountDetails.getKeyAccHolderName());

            log.info(emailBodyMap.get(TO_NAME) + "  " + emailBodyMap.get(FROM_NAME) + "  "
                    + emailBodyMap.get(FROM_ADDRESS) + "  " + emailBodyMap.get(PORTAL_URL) + "  "
                    + emailBodyMap.get(MESSAGE_SECTION));

            accountDetailsDelegate.deleteUserByEmail(themeDisplay.getCompanyId(), deleteEmail,
                    themeDisplay.getUser());

            stoxxMailUtil.sendEmailNotification(
                    deleteEmail, PropsUtil.get(STOXX_MAIL_FROM_ADDRESS), emailVelocityTemplate, LanguageUtil
                            .get(themeDisplay.getLocale(), "stoxx-accountDetails-delete-licenced-user-subject"),
                    emailBodyMap);
        }
        request.setAttribute("deleteusermsg", "SUCCESS");
    } catch (SystemException e) {
        log.error(e.getMessage() + e);
    } catch (MessagingException e) {
        log.error(e.getMessage() + e);
    }
}