Example usage for com.liferay.portal.kernel.util StringPool SPACE

List of usage examples for com.liferay.portal.kernel.util StringPool SPACE

Introduction

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

Prototype

String SPACE

To view the source code for com.liferay.portal.kernel.util StringPool SPACE.

Click Source Link

Usage

From source file:com.liferay.stocks.portlet.StocksPortlet.java

License:Open Source License

protected void updatePreferences(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
        return;//w  w w  .j av a2  s .  c  o  m
    }

    PortletPreferences portletPreferences = null;

    try {
        portletPreferences = PortletPreferencesFactoryUtil
                .getPortletPreferences(PortalUtil.getHttpServletRequest(actionRequest), PortletKeys.STOCKS);
    } catch (Exception e) {
        throw new PortletException(e);
    }

    String[] symbols = StringUtil.split(StringUtil.toUpperCase(ParamUtil.getString(actionRequest, "symbols")),
            StringPool.SPACE);

    Arrays.sort(symbols);

    portletPreferences.setValues("symbols", symbols);

    try {
        portletPreferences.store();
    } catch (ValidatorException ve) {
        SessionErrors.add(actionRequest, ValidatorException.class.getName(), ve);

        return;
    }

    SessionMessages.add(actionRequest,
            PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_UPDATED_PREFERENCES);
}

From source file:com.liferay.sync.model.SyncDLObjectUpdateTest.java

License:Open Source License

@Test
public void testToString() {
    List<SyncDLObject> syncDLObjects = new ArrayList<>(3);

    SyncDLObject syncDLObject = new SyncDLObjectImpl();

    syncDLObject.setDescription("These values should be escaped: \", \\, \\b, \\f, \\n, \\r, \\t");
    syncDLObject.setLockExpirationDate(new Date());

    syncDLObjects.add(syncDLObject);// w  w w .  j a  va 2s. c o m
    syncDLObjects.add(syncDLObject);
    syncDLObjects.add(syncDLObject);

    SyncDLObjectUpdate syncDLObjectUpdate = new SyncDLObjectUpdate(syncDLObjects, syncDLObjects.size(),
            System.currentTimeMillis());

    String expectedJSON = JSONFactoryUtil.looseSerializeDeep(syncDLObjectUpdate);

    String actualJSON = syncDLObjectUpdate.toString();

    Assert.assertEquals(expectedJSON.replace(StringPool.SPACE, StringPool.BLANK),
            actualJSON.replace(StringPool.SPACE, StringPool.BLANK));
}

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

License:Open Source License

public static String buildCss(String prefix, String baseTypeCss, boolean inlineField, boolean disabled,
        boolean choiceField, boolean first, boolean last, String cssClass) {

    StringBundler sb = new StringBundler();

    sb.append(prefix);/*from w  ww  .  j av a2s  . c  om*/

    if (choiceField) {
        sb.append(StringPool.SPACE);
        sb.append(prefix);
        sb.append("-choice");
    } else if (baseTypeCss.equals("button")) {
    } else if (baseTypeCss.equals("password") || baseTypeCss.equals("string")
            || baseTypeCss.equals("textarea")) {

        sb.append(StringPool.SPACE);
        sb.append(prefix);
        sb.append("-text");
    } else if (baseTypeCss.equals("select")) {
        sb.append(StringPool.SPACE);
        sb.append(prefix);
        sb.append("-select");
        sb.append(StringPool.SPACE);
        sb.append(prefix);
        sb.append("-menu");
    } else {
        sb.append(StringPool.SPACE);
        sb.append(prefix);
        sb.append("-");
        sb.append(baseTypeCss);
    }

    if (inlineField) {
        sb.append(StringPool.SPACE);
        sb.append(prefix);
        sb.append("-inline");
    }

    if (disabled) {
        sb.append(StringPool.SPACE);
        sb.append(prefix);
        sb.append("-disabled");
    }

    if (first) {
        sb.append(StringPool.SPACE);
        sb.append(prefix);
        sb.append("-first");
    } else if (last) {
        sb.append(StringPool.SPACE);
        sb.append(prefix);
        sb.append("-last");
    }

    if (Validator.isNotNull(cssClass)) {
        sb.append(StringPool.SPACE);
        sb.append(cssClass);
    }

    return sb.toString();
}

From source file:com.liferay.tool.datamanipulator.handler.content.JournalArticleHandler.java

License:Open Source License

@Override
protected Map<String, Object> getAddEntrySpecifiedArgs(RequestContext requestContext) throws Exception {

    boolean autoArticleId = requestContext.getBoolean(getDisplayFieldName(AUTO_ARTICLE_ID));

    String articleId;/*  ww w  .  ja va 2s.c  om*/
    if (autoArticleId) {
        articleId = StringPool.BLANK;
    } else {
        StringBuilder sb = new StringBuilder();
        sb.append(requestContext.getString("entryName"));
        sb.append(requestContext.getString("entryCount"));
        sb.append("-ARTICLE-ID-");
        sb.append(RandomUtil.nextString());

        articleId = sb.toString().toUpperCase();
        articleId = articleId.replace(StringPool.SPACE, StringPool.DASH);
    }

    long structureId = requestContext.getLong(getDisplayFieldName(STRUCTURE_LIST));

    long templateId = 0;

    String structureKey = StringPool.BLANK;
    String templateKey = StringPool.BLANK;

    if (structureId != 0) {
        DDMStructure strucrute = DDMStructureLocalServiceUtil.getStructure(structureId);

        structureKey = strucrute.getStructureKey();

        List<DDMTemplate> templates = DDMTemplateLocalServiceUtil.getTemplates(structureId);

        DDMTemplate template = templates.get(0);

        if (Validator.isNotNull(templates) && templates.size() > 0) {
            templateId = template.getTemplateId();
        }

        if (templateId != 0) {
            try {
                templateKey = (String) BeanUtil.getProperty(template, "templateKey");
            } catch (Exception e) {
                templateKey = String.valueOf(templateId);
            }
        }
    }

    //int index = RandomUtil.nextInt(JournalArticleConstants.TYPES.length);
    //String type = JournalArticleConstants.TYPES[index];

    Map<String, Object> args = new HashMap<String, Object>();

    args.put("articleId", articleId);
    args.put("articleURL", requestContext.getString("createURL"));
    args.put("autoArticleId", autoArticleId);
    args.put("classNameId", (long) 0);
    args.put("classPK", (long) 0);
    args.put("content", StringUtil.getLocalizedContent(""));
    args.put("layoutUuid", null);
    //args.put("neverExpire", RandomUtil.nextBoolean());
    args.put("neverExpire", true);
    //args.put("neverReview", RandomUtil.nextBoolean());
    args.put("neverReview", true);
    args.put("structureId", structureKey);
    args.put("structureKey", structureKey);
    args.put("ddmStructureKey", structureKey);
    args.put("templateId", structureKey);
    args.put("templateKey", templateKey);
    args.put("ddmTemplateKey", templateKey);
    //args.put("type", type);
    args.put("version", JournalArticleConstants.VERSION_DEFAULT);

    return args;
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected void checkLanguageKeys(String fileName, String content, Pattern pattern) throws IOException {

    String fileExtension = fileUtil.getExtension(fileName);

    if (!portalSource || fileExtension.equals("vm")) {
        return;/*from  w  w  w .j a  v a 2 s .c o m*/
    }

    if (_portalLanguageProperties == null) {
        _portalLanguageProperties = new Properties();

        ClassLoader classLoader = BaseSourceProcessor.class.getClassLoader();

        InputStream inputStream = classLoader.getResourceAsStream("content/Language.properties");

        _portalLanguageProperties.load(inputStream);
    }

    Matcher matcher = pattern.matcher(content);

    while (matcher.find()) {
        String[] languageKeys = getLanguageKeys(matcher);

        for (String languageKey : languageKeys) {
            if (Validator.isNumber(languageKey) || languageKey.endsWith(StringPool.DASH)
                    || languageKey.endsWith(StringPool.OPEN_BRACKET) || languageKey.endsWith(StringPool.PERIOD)
                    || languageKey.endsWith(StringPool.UNDERLINE) || languageKey.startsWith(StringPool.DASH)
                    || languageKey.startsWith(StringPool.OPEN_BRACKET)
                    || languageKey.startsWith(StringPool.OPEN_CURLY_BRACE)
                    || languageKey.startsWith(StringPool.PERIOD) || languageKey.startsWith(StringPool.UNDERLINE)
                    || _portalLanguageProperties.containsKey(languageKey)) {

                continue;
            }

            Properties languageProperties = getLanguageProperties(fileName);

            if ((languageProperties == null) || !languageProperties.containsKey(languageKey)) {

                processErrorMessage(fileName,
                        "missing language key: " + languageKey + StringPool.SPACE + fileName);
            }
        }
    }
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected boolean hasRedundantParentheses(String s) {
    if (!s.contains("&&") && !s.contains("||")) {
        for (int x = 0;;) {
            x = s.indexOf(StringPool.CLOSE_PARENTHESIS);

            if (x == -1) {
                break;
            }/*from   ww  w . jav  a 2  s.  c  om*/

            int y = s.substring(0, x).lastIndexOf(StringPool.OPEN_PARENTHESIS);

            if (y == -1) {
                break;
            }

            s = s.substring(0, y) + s.substring(x + 1);
        }
    }

    if (Validator.isNotNull(s) && !s.contains(StringPool.SPACE)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected String sortAttributes(String fileName, String line, int lineCount, boolean allowApostropheDelimeter) {

    String s = line;//  w  w w  . j  a  v  a  2 s. c  om

    int x = s.indexOf(StringPool.SPACE);

    if (x == -1) {
        return line;
    }

    s = s.substring(x + 1);

    String previousAttribute = null;
    String previousAttributeAndValue = null;

    boolean wrongOrder = false;

    for (x = 0;;) {
        x = s.indexOf(StringPool.EQUAL);

        if ((x == -1) || (s.length() <= (x + 1))) {
            return line;
        }

        String attribute = s.substring(0, x);

        if (!isAttributName(attribute)) {
            return line;
        }

        if (Validator.isNotNull(previousAttribute) && (previousAttribute.compareTo(attribute) > 0)) {

            wrongOrder = true;
        }

        s = s.substring(x + 1);

        char delimeter = s.charAt(0);

        if ((delimeter != CharPool.APOSTROPHE) && (delimeter != CharPool.QUOTE)) {

            if (delimeter != CharPool.AMPERSAND) {
                processErrorMessage(fileName, "delimeter: " + fileName + " " + lineCount);
            }

            return line;
        }

        s = s.substring(1);

        String value = null;

        int y = -1;

        while (true) {
            y = s.indexOf(delimeter, y + 1);

            if ((y == -1) || (s.length() <= (y + 1))) {
                return line;
            }

            value = s.substring(0, y);

            if (value.startsWith("<%")) {
                int endJavaCodeSignCount = StringUtil.count(value, "%>");
                int startJavaCodeSignCount = StringUtil.count(value, "<%");

                if (endJavaCodeSignCount == startJavaCodeSignCount) {
                    break;
                }
            } else {
                int greaterThanCount = StringUtil.count(value, StringPool.GREATER_THAN);
                int lessThanCount = StringUtil.count(value, StringPool.LESS_THAN);

                if (greaterThanCount == lessThanCount) {
                    break;
                }
            }
        }

        if (delimeter == CharPool.APOSTROPHE) {
            if (!value.contains(StringPool.QUOTE)) {
                line = StringUtil.replace(line, StringPool.APOSTROPHE + value + StringPool.APOSTROPHE,
                        StringPool.QUOTE + value + StringPool.QUOTE);

                return sortAttributes(fileName, line, lineCount, allowApostropheDelimeter);
            } else if (!allowApostropheDelimeter) {
                String newValue = StringUtil.replace(value, StringPool.QUOTE, "&quot;");

                line = StringUtil.replace(line, StringPool.APOSTROPHE + value + StringPool.APOSTROPHE,
                        StringPool.QUOTE + newValue + StringPool.QUOTE);

                return sortAttributes(fileName, line, lineCount, allowApostropheDelimeter);
            }
        }

        StringBundler sb = new StringBundler(5);

        sb.append(attribute);
        sb.append(StringPool.EQUAL);
        sb.append(delimeter);
        sb.append(value);
        sb.append(delimeter);

        String currentAttributeAndValue = sb.toString();

        if (wrongOrder) {
            if ((StringUtil.count(line, currentAttributeAndValue) == 1)
                    && (StringUtil.count(line, previousAttributeAndValue) == 1)) {

                line = StringUtil.replaceFirst(line, previousAttributeAndValue, currentAttributeAndValue);

                line = StringUtil.replaceLast(line, currentAttributeAndValue, previousAttributeAndValue);

                return sortAttributes(fileName, line, lineCount, allowApostropheDelimeter);
            }

            return line;
        }

        s = s.substring(y + 1);

        if (s.startsWith(StringPool.GREATER_THAN)) {
            x = s.indexOf(StringPool.SPACE);

            if (x == -1) {
                return line;
            }

            s = s.substring(x + 1);

            previousAttribute = null;
            previousAttributeAndValue = null;
        } else {
            s = StringUtil.trimLeading(s);

            previousAttribute = attribute;
            previousAttributeAndValue = currentAttributeAndValue;
        }
    }
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected String trimLine(String line, boolean allowLeadingSpaces) {
    if (line.trim().length() == 0) {
        return StringPool.BLANK;
    }/*from   w  ww. j a  va 2  s  .c om*/

    line = StringUtil.trimTrailing(line);

    if (allowLeadingSpaces || !line.startsWith(StringPool.SPACE) || line.startsWith(" *")) {

        return line;
    }

    if (!line.startsWith(StringPool.FOUR_SPACES)) {
        while (line.startsWith(StringPool.SPACE)) {
            line = StringUtil.replaceFirst(line, StringPool.SPACE, StringPool.BLANK);
        }
    } else {
        int pos = 0;

        String temp = line;

        while (temp.startsWith(StringPool.FOUR_SPACES)) {
            line = StringUtil.replaceFirst(line, StringPool.FOUR_SPACES, StringPool.TAB);

            pos++;

            temp = line.substring(pos);
        }
    }

    return line;
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessorTestCase.java

License:Open Source License

protected void test(String fileName, String[] expectedErrorMessages, Integer[] lineNumbers) throws Exception {

    String fullFileName = _DIR_NAME + StringPool.SLASH + fileName;

    Tuple tuple = sourceFormatter.format(fullFileName);

    if (tuple == null) {
        return;/*from w  ww  . ja  v a  2  s.co m*/
    }

    List<String> errorMessages = (List<String>) tuple.getObject(1);

    if (!errorMessages.isEmpty() || (expectedErrorMessages.length > 0)) {
        Assert.assertEquals(expectedErrorMessages.length, errorMessages.size());

        for (int i = 0; i < errorMessages.size(); i++) {
            String actualErrorMessage = errorMessages.get(i);
            String expectedErrorMessage = expectedErrorMessages[i];

            StringBundler sb = new StringBundler(5);

            sb.append(expectedErrorMessage);
            sb.append(StringPool.SPACE);
            sb.append(fullFileName);

            if (lineNumbers != null) {
                sb.append(StringPool.SPACE);
                sb.append(lineNumbers[i]);
            }

            Assert.assertEquals(sb.toString(), actualErrorMessage);
        }
    } else {
        String actualFormattedContent = (String) tuple.getObject(0);

        try {
            File file = new File(_DIR_NAME + "/expected/" + fileName);

            String expectedFormattedContent = FileUtils.readFileToString(file, StringPool.UTF8);

            expectedFormattedContent = StringUtil.replace(expectedFormattedContent, StringPool.RETURN_NEW_LINE,
                    StringPool.NEW_LINE);

            Assert.assertEquals(expectedFormattedContent, actualFormattedContent);
        } catch (FileNotFoundException fnfe) {
            Assert.fail();
        }
    }
}

From source file:com.liferay.tools.sourceformatter.JavaClass.java

License:Open Source License

protected String getClassName(String line) {
    int pos = line.indexOf(" extends ");

    if (pos == -1) {
        pos = line.indexOf(" implements ");
    }/*from   w  w  w.ja v  a2 s.co  m*/

    if (pos == -1) {
        pos = line.indexOf(StringPool.OPEN_CURLY_BRACE);
    }

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

    pos = line.indexOf(StringPool.LESS_THAN);

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

    line = line.trim();

    pos = line.lastIndexOf(StringPool.SPACE);

    return line.substring(pos + 1);
}