Example usage for com.liferay.portal.kernel.util TextFormatter format

List of usage examples for com.liferay.portal.kernel.util TextFormatter format

Introduction

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

Prototype

public static String format(String s, int style) 

Source Link

Usage

From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java

License:Open Source License

public List<MyResult> getMyResults(String portfolioIds, int allocationBy) {

    List<MyResult> myResults = myResultFinder.findResults(portfolioIds);

    for (MyResult myResult : myResults) {

        String baseCurrency = myResult.getBaseCurrency();

        if (!baseCurrency.equalsIgnoreCase("USD")) {
            double conversionFactor = CurrencyServiceUtil.getConversion(baseCurrency);
            myResult.setPurchasedMarketValue(myResult.getPurchasedMarketValue() * conversionFactor);
            myResult.setCurrentMarketValue(myResult.getCurrentMarketValue() * conversionFactor);
            myResult.setGain_loss(myResult.getGain_loss() * conversionFactor);
        }//from ww w  . j  a v  a  2  s .c o m

        long countryOfRisk = myResult.getCountryOfRisk();

        if (countryOfRisk > 0l) {
            Country country = null;
            try {
                country = CountryServiceUtil.fetchCountry(countryOfRisk);
            } catch (SystemException e) {
                e.printStackTrace();
            }

            if (Validator.isNotNull(country)) {
                myResult.setCountryOfRiskName(TextFormatter.format(country.getName(), TextFormatter.J));
            }
        } else {
            myResult.setCountryOfRiskName(IConstants.UN_SPECIFIED);
        }

        if (Validator.isNull(myResult.getCurrency_())) {
            myResult.setCurrency_(IConstants.UN_SPECIFIED);
        }

        if (Validator.isNull(myResult.getIndustry_sector())) {
            myResult.setIndustry_sector(IConstants.UN_SPECIFIED);
        }

        if (allocationBy != IConstants.BREAKUP_BY_CURRENCY) {
            setCategoryFields(myResult, allocationBy);
        }
    }

    return myResults;
}

From source file:com.liferay.exportimport.resources.importer.internal.util.ImporterFactory.java

License:Open Source License

protected void configureImporter(long companyId, Importer importer, ServletContext servletContext,
        PluginPackageProperties pluginPackageProperties) throws Exception {

    importer.setAppendVersion(pluginPackageProperties.isAppendVersion());
    importer.setCompanyId(companyId);/*w ww.  j av a2 s . c om*/
    importer.setDeveloperModeEnabled(pluginPackageProperties.isDeveloperModeEnabled());
    importer.setIndexAfterImport(pluginPackageProperties.indexAfterImport());
    importer.setServletContext(servletContext);
    importer.setServletContextName(servletContext.getServletContextName());
    importer.setTargetClassName(pluginPackageProperties.getTargetClassName());

    String targetValue = pluginPackageProperties.getTargetValue();

    if (Validator.isNull(targetValue)) {
        targetValue = TextFormatter.format(servletContext.getServletContextName(), TextFormatter.J);
    }

    importer.setTargetValue(targetValue);

    importer.setUpdateModeEnabled(pluginPackageProperties.isUpdateModeEnabled());

    PluginPackage pluginPackage = DeployManagerUtil
            .getInstalledPluginPackage(servletContext.getServletContextName());

    importer.setVersion(pluginPackage.getVersion());

    importer.afterPropertiesSet();
}

From source file:com.liferay.frontend.editor.tinymce.web.editor.configuration.TinyMCEEditorConfigContributor.java

License:Open Source License

protected JSONArray getToolbarJSONArray(Map<String, Object> inputEditorTaglibAttributes,
        ThemeDisplay themeDisplay) {/*w w w.  j  a v a  2 s  .  c  o  m*/

    JSONObject toolbarsJSONObject = getToolbarsJSONObject(inputEditorTaglibAttributes);

    String toolbarSet = (String) inputEditorTaglibAttributes.get("liferay-ui:input-editor:toolbarSet");

    String currentToolbarSet = TextFormatter.format(HtmlUtil.escapeJS(toolbarSet), TextFormatter.M);

    if (BrowserSnifferUtil.isMobile(themeDisplay.getRequest())) {
        currentToolbarSet = "phone";
    }

    JSONArray toolbarJSONArray = toolbarsJSONObject.getJSONArray(currentToolbarSet);

    if (toolbarJSONArray == null) {
        toolbarJSONArray = toolbarsJSONObject.getJSONArray("liferay");
    }

    return toolbarJSONArray;
}

From source file:com.liferay.frontend.editor.tinymce.web.internal.editor.configuration.TinyMCEEditorConfigContributor.java

License:Open Source License

protected JSONArray getToolbarJSONArray(Map<String, Object> inputEditorTaglibAttributes,
        ThemeDisplay themeDisplay) {//from w  w  w .j  a v a 2 s .co  m

    JSONObject toolbarsJSONObject = getToolbarsJSONObject(inputEditorTaglibAttributes);

    String toolbarSet = (String) inputEditorTaglibAttributes.get("liferay-ui:input-editor:toolbarSet");

    String currentToolbarSet = TextFormatter.format(HtmlUtil.escapeJS(toolbarSet), TextFormatter.M);

    if (_browserSniffer.isMobile(themeDisplay.getRequest())) {
        currentToolbarSet = "phone";
    }

    JSONArray toolbarJSONArray = toolbarsJSONObject.getJSONArray(currentToolbarSet);

    if (toolbarJSONArray == null) {
        toolbarJSONArray = toolbarsJSONObject.getJSONArray("liferay");
    }

    return toolbarJSONArray;
}

From source file:com.liferay.portlet.expando.model.impl.ExpandoColumnImpl.java

License:Open Source License

public String getDisplayName(Locale locale) {
    String name = getName();/*from w w w  . ja v a2 s. com*/

    String displayName = LanguageUtil.get(locale, name);

    if (name.equals(displayName)) {
        displayName = TextFormatter.format(name, TextFormatter.J);
    }

    return displayName;
}

From source file:com.liferay.resourcesimporter.messaging.HotDeployMessageListener.java

License:Open Source License

protected void doReceive(Message message) throws Exception {
    String command = message.getString("command");

    if (!command.equals("deploy")) {
        return;/*from   w  w  w  .  ja v  a  2 s.co m*/
    }

    String servletContextName = message.getString("servletContextName");

    ServletContext servletContext = ServletContextPool.get(servletContextName);

    URL resourcesDirURL = servletContext.getResource(_RESOURCES_DIR);

    if (resourcesDirURL == null) {
        return;
    }

    Properties pluginPackageProperties = getPluginPackageProperties(servletContext);

    String targetClassName = pluginPackageProperties.getProperty("resources-importer-target-class-name",
            LayoutSetPrototype.class.getName());

    Set<String> resourcePaths = servletContext.getResourcePaths(_RESOURCES_DIR);

    URL privateLARURL = null;
    URL publicLARURL = servletContext.getResource(_RESOURCES_DIR.concat("archive.lar"));

    if (publicLARURL == null) {
        privateLARURL = servletContext.getResource(_RESOURCES_DIR.concat("private.lar"));
        publicLARURL = servletContext.getResource(_RESOURCES_DIR.concat("public.lar"));
    }

    List<Company> companies = CompanyLocalServiceUtil.getCompanies();

    for (Company company : companies) {
        long companyId = CompanyThreadLocal.getCompanyId();

        try {
            CompanyThreadLocal.setCompanyId(company.getCompanyId());

            Importer importer = null;

            if ((privateLARURL != null) || (publicLARURL != null)) {
                LARImporter larImporter = getLARImporter();

                URLConnection privateLARURLConnection = null;

                if (privateLARURL != null) {
                    privateLARURLConnection = privateLARURL.openConnection();

                    larImporter.setPrivateLARInputStream(privateLARURLConnection.getInputStream());
                }

                URLConnection publicLARURLConnection = null;

                if (publicLARURL != null) {
                    publicLARURLConnection = publicLARURL.openConnection();

                    larImporter.setPublicLARInputStream(publicLARURLConnection.getInputStream());
                }

                importer = larImporter;
            } else if ((resourcePaths != null) && !resourcePaths.isEmpty()) {
                importer = getResourceImporter();

                importer.setResourcesDir(_RESOURCES_DIR);
            } else {
                String resourcesDir = pluginPackageProperties.getProperty("resources-importer-external-dir");

                if (Validator.isNotNull(resourcesDir)) {
                    importer = getFileSystemImporter();

                    importer.setResourcesDir(resourcesDir);
                }
            }

            if (importer == null) {
                throw new ImporterException("No valid importer found");
            }

            importer.setCompanyId(company.getCompanyId());
            importer.setServletContext(servletContext);
            importer.setServletContextName(servletContextName);
            importer.setTargetClassName(targetClassName);

            String targetValue = pluginPackageProperties.getProperty("resources-importer-target-value");

            if (Validator.isNull(targetValue)) {
                targetValue = TextFormatter.format(servletContextName, TextFormatter.J);
            }

            importer.setTargetValue(targetValue);

            importer.afterPropertiesSet();

            boolean developerModeEnabled = GetterUtil.getBoolean(
                    pluginPackageProperties.getProperty("resources-importer-developer-mode-enabled"));

            if (!developerModeEnabled && importer.isExisting()) {
                if (_log.isInfoEnabled()) {
                    _log.info("Group or layout set prototype already exists " + "for company "
                            + company.getWebId());
                }

                continue;
            }

            long startTime = 0;

            if (_log.isInfoEnabled()) {
                startTime = System.currentTimeMillis();
            }

            importer.importResources();

            if (_log.isInfoEnabled()) {
                long endTime = System.currentTimeMillis() - startTime;

                _log.info("Importing resources from " + servletContextName + " to group "
                        + importer.getGroupId() + " takes " + endTime + " ms");
            }

            Message newMessage = new Message();

            newMessage.put("companyId", company.getCompanyId());
            newMessage.put("servletContextName", servletContextName);
            newMessage.put("targetClassName", targetClassName);
            newMessage.put("targetClassPK", importer.getTargetClassPK());

            if (message.getResponseId() != null) {
                Map<String, Object> responseMap = new HashMap<String, Object>();

                responseMap.put("groupId", importer.getTargetClassPK());

                newMessage.setPayload(responseMap);

                newMessage.setResponseId(message.getResponseId());
            }

            MessageBusUtil.sendMessage("liferay/resources_importer", newMessage);
        } catch (ImporterException ie) {
            Message newMessage = new Message();

            newMessage.put("companyId", company.getCompanyId());
            newMessage.put("error", ie.getMessage());
            newMessage.put("servletContextName", servletContextName);
            newMessage.put("targetClassName", targetClassName);
            newMessage.put("targetClassPK", 0);

            MessageBusUtil.sendMessage("liferay/resources_importer", newMessage);
        } finally {
            CompanyThreadLocal.setCompanyId(companyId);
        }
    }
}

From source file:com.liferay.resourcesimporter.servlet.ResourcesImporterServletContextListener.java

License:Open Source License

protected void initialize(Message message) throws Exception {
    String servletContextName = message.getString("servletContextName");

    ServletContext servletContext = ServletContextPool.get(servletContextName);

    URL url = servletContext.getResource(_RESOURCES_DIR);

    if (url == null) {
        return;//from  w ww.j  a  va 2  s .  c o m
    }

    Properties pluginPackageProperties = getPluginPackageProperties(servletContext);

    String targetClassName = pluginPackageProperties.getProperty("resources-importer-target-class-name",
            LayoutSetPrototype.class.getName());

    Set<String> resourcePaths = servletContext.getResourcePaths(_RESOURCES_DIR);

    URL privateLARURL = null;
    URL publicLARURL = servletContext.getResource(_RESOURCES_DIR.concat("archive.lar"));

    if (publicLARURL == null) {
        privateLARURL = servletContext.getResource(_RESOURCES_DIR.concat("private.lar"));
        publicLARURL = servletContext.getResource(_RESOURCES_DIR.concat("public.lar"));
    }

    List<Company> companies = CompanyLocalServiceUtil.getCompanies();

    for (Company company : companies) {
        long companyId = CompanyThreadLocal.getCompanyId();

        try {
            CompanyThreadLocal.setCompanyId(company.getCompanyId());

            Importer importer = null;

            if ((privateLARURL != null) || (publicLARURL != null)) {
                LARImporter larImporter = getLARImporter();

                URLConnection privateLARURLConnection = null;

                if (privateLARURL != null) {
                    privateLARURLConnection = privateLARURL.openConnection();

                    larImporter.setPrivateLARInputStream(privateLARURLConnection.getInputStream());
                }

                URLConnection publicLARURLConnection = null;

                if (publicLARURL != null) {
                    publicLARURLConnection = publicLARURL.openConnection();

                    larImporter.setPublicLARInputStream(publicLARURLConnection.getInputStream());
                }

                importer = larImporter;
            } else if ((resourcePaths != null) && !resourcePaths.isEmpty()) {
                importer = getResourceImporter();

                importer.setResourcesDir(_RESOURCES_DIR);
            } else {
                String resourcesDir = pluginPackageProperties.getProperty("resources-importer-external-dir");

                if (Validator.isNotNull(resourcesDir)) {
                    importer = getFileSystemImporter();

                    importer.setResourcesDir(resourcesDir);
                }
            }

            if (importer == null) {
                throw new ImporterException("No valid importer found");
            }

            importer.setCompanyId(company.getCompanyId());
            importer.setServletContext(servletContext);
            importer.setServletContextName(servletContextName);
            importer.setTargetClassName(targetClassName);

            String targetValue = pluginPackageProperties.getProperty("resources-importer-target-value");

            if (Validator.isNull(targetValue)) {
                targetValue = TextFormatter.format(servletContextName, TextFormatter.J);
            }

            importer.setTargetValue(targetValue);

            importer.afterPropertiesSet();

            boolean developerModeEnabled = GetterUtil.getBoolean(
                    pluginPackageProperties.getProperty("resources-importer-developer-mode-enabled"));

            if (!developerModeEnabled && importer.isExisting()) {
                if (_log.isInfoEnabled()) {
                    _log.info("Group or layout set prototype already exists " + "for company "
                            + company.getWebId());
                }

                continue;
            }

            long startTime = 0;

            if (_log.isInfoEnabled()) {
                startTime = System.currentTimeMillis();
            }

            importer.importResources();

            if (_log.isInfoEnabled()) {
                long endTime = System.currentTimeMillis() - startTime;

                _log.info("Importing resources from " + servletContextName + " to group "
                        + importer.getGroupId() + " takes " + endTime + " ms");
            }

            Message newMessage = new Message();

            newMessage.put("companyId", company.getCompanyId());
            newMessage.put("servletContextName", servletContextName);
            newMessage.put("targetClassName", targetClassName);
            newMessage.put("targetClassPK", importer.getTargetClassPK());

            if (message.getResponseId() != null) {
                Map<String, Object> responseMap = new HashMap<String, Object>();

                responseMap.put("groupId", importer.getTargetClassPK());

                newMessage.setPayload(responseMap);

                newMessage.setResponseId(message.getResponseId());
            }

            MessageBusUtil.sendMessage("liferay/resources_importer", newMessage);
        } catch (ImporterException ie) {
            Message newMessage = new Message();

            newMessage.put("companyId", company.getCompanyId());
            newMessage.put("error", ie.getMessage());
            newMessage.put("servletContextName", servletContextName);
            newMessage.put("targetClassName", targetClassName);
            newMessage.put("targetClassPK", 0);

            MessageBusUtil.sendMessage("liferay/resources_importer", newMessage);
        } finally {
            CompanyThreadLocal.setCompanyId(companyId);
        }
    }
}

From source file:com.liferay.resourcesimporter.util.ImporterFactory.java

License:Open Source License

protected void configureImporter(long companyId, Importer importer, ServletContext servletContext,
        PluginPackageProperties pluginPackageProperties) throws Exception {

    importer.setAppendVersion(pluginPackageProperties.isAppendVersion());

    importer.setCompanyId(companyId);//w  w  w .j a  v  a2 s.  co  m

    importer.setDeveloperModeEnabled(pluginPackageProperties.isDeveloperModeEnabled());

    importer.setServletContext(servletContext);
    importer.setServletContextName(servletContext.getServletContextName());

    importer.setTargetClassName(pluginPackageProperties.getTargetClassName());

    String targetValue = pluginPackageProperties.getTargetValue();

    if (Validator.isNull(targetValue)) {
        targetValue = TextFormatter.format(servletContext.getServletContextName(), TextFormatter.J);
    }

    importer.setTargetValue(targetValue);

    importer.setUpdateModeEnabled(pluginPackageProperties.isUpdateModeEnabled());

    PluginPackage pluginPackage = DeployManagerUtil
            .getInstalledPluginPackage(servletContext.getServletContextName());

    importer.setVersion(pluginPackage.getVersion());

    importer.afterPropertiesSet();
}

From source file:com.liferay.taglib.aui.FieldWrapperTag.java

License:Open Source License

@Override
protected void setAttributes(HttpServletRequest request) {
    super.setAttributes(request);

    String label = getLabel();//from   w  w w  .  j a v a 2  s  .  co  m

    if (label == null) {
        label = TextFormatter.format(getName(), TextFormatter.K);
    }

    setNamespacedAttribute(request, "label", label);
}

From source file:com.liferay.taglib.aui.InputTag.java

License:Open Source License

@Override
protected void setAttributes(HttpServletRequest request) {
    super.setAttributes(request);

    Object bean = getBean();//from w ww  . j  av  a  2  s  .  c  o m

    if (bean == null) {
        bean = pageContext.getAttribute("aui:model-context:bean");
    }

    String defaultLanguageId = getDefaultLanguageId();

    if (Validator.isNull(defaultLanguageId)) {
        defaultLanguageId = (String) pageContext.getAttribute("aui:model-context:defaultLanguageId");
    }

    if (Validator.isNull(defaultLanguageId)) {
        Locale defaultLocale = LocaleUtil.getDefault();

        defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);
    }

    String name = getName();

    int pos = name.indexOf(StringPool.DOUBLE_DASH);

    if (pos != -1) {
        name = name.substring(pos + 2, name.length() - 2);
    }

    String field = getField();

    if (Validator.isNull(field)) {
        field = getName();
    }

    String formName = getFormName();

    if (formName == null) {
        FormTag formTag = (FormTag) findAncestorWithClass(this, FormTag.class);

        if (formTag != null) {
            formName = formTag.getName();
        }
    }

    String id = getId();
    String type = getType();

    if (Validator.isNull(id)) {
        if (!Validator.equals(type, "assetTags") && !Validator.equals(type, "radio")) {

            id = name;
        } else {
            id = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
        }
    }

    String label = getLabel();

    if (label == null) {
        label = TextFormatter.format(name, TextFormatter.K);
    }

    Class<?> model = getModel();

    if (model == null) {
        model = (Class<?>) pageContext.getAttribute("aui:model-context:model");
    }

    _forLabel = id;
    _inputName = getName();

    String baseType = null;

    if ((model != null) && Validator.isNull(type)) {
        baseType = ModelHintsUtil.getType(model.getName(), field);

        String fieldParam = getFieldParam();

        if (Validator.isNotNull(fieldParam)) {
            _forLabel = fieldParam;
            _inputName = fieldParam;
        }

        if (ModelHintsUtil.isLocalized(model.getName(), field)) {
            _forLabel += StringPool.UNDERLINE + defaultLanguageId;
            _inputName += StringPool.UNDERLINE + defaultLanguageId;
        }
    } else if (Validator.isNotNull(type)) {
        if (Validator.equals(type, "checkbox") || Validator.equals(type, "radio")) {

            baseType = type;
        }
    }

    if (Validator.isNull(baseType)) {
        baseType = "text";
    }

    setNamespacedAttribute(request, "baseType", baseType);
    setNamespacedAttribute(request, "bean", bean);
    setNamespacedAttribute(request, "defaultLanguageId", defaultLanguageId);
    setNamespacedAttribute(request, "field", field);
    setNamespacedAttribute(request, "forLabel", _forLabel);
    setNamespacedAttribute(request, "formName", formName);
    setNamespacedAttribute(request, "id", id);
    setNamespacedAttribute(request, "label", label);
    setNamespacedAttribute(request, "model", model);

    request.setAttribute(getAttributeNamespace() + "value", getValue());
}