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

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

Introduction

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

Prototype

String DASH

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

Click Source Link

Usage

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 .  ja  v a  2s . 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.JavaSourceProcessor.java

License:Open Source License

protected String getCombinedLinesContent(String content, String fileName, String absolutePath, String line,
        String trimmedLine, int lineLength, int lineCount, String previousLine, int lineTabCount,
        int previousLineTabCount) {

    if (Validator.isNull(line) || Validator.isNull(previousLine)
            || isExcluded(_fitOnSingleLineExclusions, absolutePath, lineCount)) {

        return null;
    }//  w w w  . java2  s .c o  m

    String trimmedPreviousLine = StringUtil.trimLeading(previousLine);

    if (line.contains("// ") || line.contains("*/") || line.contains("*/") || previousLine.contains("// ")
            || previousLine.contains("*/") || previousLine.contains("*/")) {

        return null;
    }

    int tabDiff = lineTabCount - previousLineTabCount;

    if (previousLine.endsWith(" extends")) {
        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                previousLine, "extends", tabDiff, false, false, false);
    }

    if (previousLine.endsWith(" implements")) {
        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                previousLine, "implements ", tabDiff, false, false, false);
    }

    if (trimmedLine.startsWith("+ ") || trimmedLine.startsWith("- ") || trimmedLine.startsWith("|| ")
            || trimmedLine.startsWith("&& ")) {

        int pos = trimmedLine.indexOf(StringPool.SPACE);

        String linePart = trimmedLine.substring(0, pos);

        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                previousLine, linePart, tabDiff, true, true, false);
    }

    int previousLineLength = getLineLength(previousLine);

    if ((trimmedLine.length() + previousLineLength) < _MAX_LINE_LENGTH) {
        if (trimmedPreviousLine.startsWith("for ") && previousLine.endsWith(StringPool.COLON)
                && line.endsWith(StringPool.OPEN_CURLY_BRACE)) {

            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, true, false);
        }

        if (line.endsWith(StringPool.SEMICOLON) && !previousLine.endsWith(StringPool.COLON)
                && !previousLine.endsWith(StringPool.OPEN_BRACKET)
                && !previousLine.endsWith(StringPool.OPEN_CURLY_BRACE)
                && !previousLine.endsWith(StringPool.OPEN_PARENTHESIS)
                && !previousLine.endsWith(StringPool.PERIOD) && (lineTabCount == (previousLineTabCount + 1))) {

            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, true, false);
        }

        if ((trimmedPreviousLine.startsWith("if ") || trimmedPreviousLine.startsWith("else "))
                && (previousLine.endsWith("||") || previousLine.endsWith("&&"))
                && line.endsWith(StringPool.OPEN_CURLY_BRACE)) {

            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, true, false);
        }

        if ((trimmedLine.startsWith("extends ") || trimmedLine.startsWith("implements ")
                || trimmedLine.startsWith("throws"))
                && (line.endsWith(StringPool.OPEN_CURLY_BRACE) || line.endsWith(StringPool.SEMICOLON))
                && (lineTabCount == (previousLineTabCount + 1))) {

            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, true, false);
        }

        if (previousLine.endsWith(StringPool.EQUAL) && line.endsWith(StringPool.OPEN_PARENTHESIS)) {

            String nextLine = getNextLine(content, lineCount);

            if (nextLine.endsWith(StringPool.SEMICOLON)) {
                return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                        previousLine, null, tabDiff, false, true, true);
            }
        }
    }

    if (((trimmedLine.length() + previousLineLength) <= _MAX_LINE_LENGTH)
            && (previousLine.endsWith(StringPool.OPEN_BRACKET)
                    || previousLine.endsWith(StringPool.OPEN_PARENTHESIS)
                    || previousLine.endsWith(StringPool.PERIOD))
            && line.endsWith(StringPool.SEMICOLON)) {

        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                previousLine, null, tabDiff, false, false, false);
    }

    if (previousLine.endsWith(StringPool.EQUAL) && line.endsWith(StringPool.SEMICOLON)) {

        String tempLine = trimmedLine;

        for (int pos = 0;;) {
            pos = tempLine.indexOf(StringPool.DASH);

            if (pos == -1) {
                pos = tempLine.indexOf(StringPool.PLUS);
            }

            if (pos == -1) {
                pos = tempLine.indexOf(StringPool.SLASH);
            }

            if (pos == -1) {
                pos = tempLine.indexOf(StringPool.STAR);
            }

            if (pos == -1) {
                pos = tempLine.indexOf("||");
            }

            if (pos == -1) {
                pos = tempLine.indexOf("&&");
            }

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

            String linePart = tempLine.substring(0, pos);

            int openParenthesisCount = StringUtil.count(linePart, StringPool.OPEN_PARENTHESIS);
            int closeParenthesisCount = StringUtil.count(linePart, StringPool.CLOSE_PARENTHESIS);

            if (openParenthesisCount == closeParenthesisCount) {
                return null;
            }

            tempLine = tempLine.substring(0, pos) + tempLine.substring(pos + 1);
        }

        int x = trimmedLine.indexOf(StringPool.OPEN_PARENTHESIS);

        if (x == 0) {
            x = trimmedLine.indexOf(StringPool.OPEN_PARENTHESIS, 1);
        }

        if (x != -1) {
            int y = trimmedLine.indexOf(StringPool.CLOSE_PARENTHESIS, x);
            int z = trimmedLine.indexOf(StringPool.QUOTE);

            if (((x + 1) != y) && ((z == -1) || (z > x))) {
                char previousChar = trimmedLine.charAt(x - 1);

                if ((previousChar != CharPool.CLOSE_PARENTHESIS) && (previousChar != CharPool.OPEN_PARENTHESIS)
                        && (previousChar != CharPool.SPACE)
                        && (previousLineLength + 1 + x) < _MAX_LINE_LENGTH) {

                    String linePart = trimmedLine.substring(0, x + 1);

                    if (linePart.startsWith(StringPool.OPEN_PARENTHESIS)
                            && !linePart.contains(StringPool.CLOSE_PARENTHESIS)) {

                        return null;
                    }

                    return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                            previousLine, linePart, tabDiff, true, true, false);
                }
            }
        }
    }

    if (previousLine.endsWith(StringPool.COMMA) && (previousLineTabCount == lineTabCount)
            && !previousLine.contains(StringPool.CLOSE_CURLY_BRACE)
            && (line.endsWith(") {") || !line.endsWith(StringPool.OPEN_CURLY_BRACE))) {

        int x = trimmedLine.indexOf(StringPool.COMMA);

        if (x != -1) {
            while ((previousLineLength + 1 + x) < _MAX_LINE_LENGTH) {
                String linePart = trimmedLine.substring(0, x + 1);

                if (isValidJavaParameter(linePart)) {
                    if (trimmedLine.equals(linePart)) {
                        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength,
                                lineCount, previousLine, null, tabDiff, false, true, false);
                    } else {
                        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength,
                                lineCount, previousLine, linePart + StringPool.SPACE, tabDiff, true, true,
                                false);
                    }
                }

                String partAfterComma = trimmedLine.substring(x + 1);

                int pos = partAfterComma.indexOf(StringPool.COMMA);

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

                x = x + pos + 1;
            }
        } else if (!line.endsWith(StringPool.OPEN_PARENTHESIS) && !line.endsWith(StringPool.PLUS)
                && !line.endsWith(StringPool.PERIOD)
                && (!trimmedLine.startsWith("new ") || !line.endsWith(StringPool.OPEN_CURLY_BRACE))
                && ((trimmedLine.length() + previousLineLength) < _MAX_LINE_LENGTH)) {

            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, true, false);
        }
    }

    if (!previousLine.endsWith(StringPool.OPEN_PARENTHESIS)) {
        return null;
    }

    if (StringUtil.count(previousLine, StringPool.OPEN_PARENTHESIS) > 1) {
        int pos = trimmedPreviousLine.lastIndexOf(StringPool.OPEN_PARENTHESIS,
                trimmedPreviousLine.length() - 2);

        if ((pos > 0) && Character.isLetterOrDigit(trimmedPreviousLine.charAt(pos - 1))) {

            String filePart = trimmedPreviousLine.substring(pos + 1);

            if (!filePart.contains(StringPool.CLOSE_PARENTHESIS) && !filePart.contains(StringPool.QUOTE)) {

                return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                        previousLine, filePart, tabDiff, false, false, false);
            }
        }
    }

    if ((trimmedLine.length() + previousLineLength) > _MAX_LINE_LENGTH) {
        return null;
    }

    if (line.endsWith(StringPool.COMMA)) {
        String strippedQuotesLine = stripQuotes(trimmedLine, CharPool.QUOTE);

        int openParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.OPEN_PARENTHESIS);
        int closeParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.CLOSE_PARENTHESIS);

        if (closeParenthesisCount > openParenthesisCount) {
            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, false, false);
        }
    }

    if (((line.endsWith(StringPool.OPEN_CURLY_BRACE) && !trimmedLine.startsWith("new "))
            || line.endsWith(StringPool.CLOSE_PARENTHESIS))
            && (trimmedPreviousLine.startsWith("else ") || trimmedPreviousLine.startsWith("if ")
                    || trimmedPreviousLine.startsWith("private ")
                    || trimmedPreviousLine.startsWith("protected ")
                    || trimmedPreviousLine.startsWith("public "))) {

        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                previousLine, null, tabDiff, false, false, false);
    }

    return null;
}

From source file:com.liferay.util.format.USAPhoneNumberFormat.java

License:Open Source License

public String format(String phoneNumber) {
    if (phoneNumber == null) {
        return StringPool.BLANK;
    }/*from  w  ww . j a  v a  2  s.c  om*/

    if (phoneNumber.length() > 10) {
        StringBundler sb = new StringBundler(8);

        sb.append(StringPool.OPEN_PARENTHESIS);
        sb.append(phoneNumber.substring(0, 3));
        sb.append(") ");
        sb.append(phoneNumber.substring(3, 6));
        sb.append(StringPool.DASH);
        sb.append(phoneNumber.substring(6, 10));
        sb.append(" x");
        sb.append(phoneNumber.substring(10));

        return sb.toString();
    } else if (phoneNumber.length() == 10) {
        StringBundler sb = new StringBundler(6);

        sb.append(StringPool.OPEN_PARENTHESIS);
        sb.append(phoneNumber.substring(0, 3));
        sb.append(") ");
        sb.append(phoneNumber.substring(3, 6));
        sb.append(StringPool.DASH);
        sb.append(phoneNumber.substring(6));

        return sb.toString();
    } else if (phoneNumber.length() == 7) {
        return phoneNumber.substring(0, 3).concat(StringPool.DASH).concat(phoneNumber.substring(3));
    } else {
        return phoneNumber;
    }
}

From source file:com.liferay.wiki.engine.creole.internal.antlrwiki.translator.XhtmlTranslator.java

License:Open Source License

protected String getHeadingMarkup(String prefix, String text) {
    StringBundler sb = new StringBundler(4);

    sb.append(_HEADING_ANCHOR_PREFIX);//from   w ww  . j  av a2 s  .c  om
    sb.append(prefix);
    sb.append(StringPool.DASH);
    sb.append(text.trim());

    return StringUtil.replace(sb.toString(), CharPool.SPACE, CharPool.PLUS);
}

From source file:com.liferay.wol.jira.social.JIRAActivityInterpreter.java

License:Open Source License

protected String interpretJIRAChangeItem(JSONObject jiraChangeItem, ThemeDisplay themeDisplay) {

    String field = jiraChangeItem.getString("field");

    field = StringUtil.replace(field.toLowerCase(), StringPool.SPACE, StringPool.DASH);

    String newString = jiraChangeItem.getString("newString");
    String newValue = jiraChangeItem.getString("newValue");

    if (Validator.isNull(newString)) {
        return StringPool.BLANK;
    }/*from   w  w  w  .j  a  va2  s.co m*/

    StringBuilder sb = new StringBuilder();

    if (field.equals("description") || field.equals("summary")) {
        sb.append(themeDisplay.translate("activity-wol-jira-add-change-" + field));
        sb.append("<br />");
    } else if (field.equals("assignee") || field.equals("attachment") || field.equals("fix-version")
            || field.equals("issuetype") || field.equals("priority") || field.equals("resolution")
            || field.equals("status") || field.equals("version")) {

        sb.append(themeDisplay.translate("activity-wol-jira-add-change-" + field, new Object[] { newString }));
        sb.append("<br />");
    } else if (field.equals("link") && newValue.startsWith("LEP-")) {
        sb.append(themeDisplay.translate("activity-wol-jira-add-change-" + field, new Object[] { newValue }));
        sb.append("<br />");
    }

    return sb.toString();
}

From source file:com.liferay.wsrp.consumer.portlet.ConsumerFriendlyURLMapper.java

License:Open Source License

@Override
protected void addParameter(Map<String, String[]> parameterMap, String name, String value) {

    if (value.equals(StringPool.DASH)) {
        return;/*w  w  w. ja  v  a 2  s  .c  om*/
    }

    try {
        parameterMap.put(name, new String[] { value });
    } catch (Exception e) {
        _log.error(e, e);
    }
}

From source file:com.liferay.wsrp.consumer.portlet.ConsumerFriendlyURLMapper.java

License:Open Source License

protected void addPathElement(StringBuilder sb, String value) {
    sb.append(StringPool.SLASH);
    sb.append(GetterUtil.get(HttpUtil.encodeURL(value), StringPool.DASH));
}

From source file:com.liferay.wsrp.portlet.ConsumerFriendlyURLMapper.java

License:Open Source License

protected void addParameter(Map<String, String[]> parameterMap, String name, String value) {

    if (value.equals(StringPool.DASH)) {
        return;//from   w  ww  .  j av a2  s  .co m
    }

    try {
        parameterMap.put(name, new String[] { value });
    } catch (Exception e) {
        _log.error(e, e);
    }
}

From source file:com.rivetlogic.tout.portlet.ToutConfigPortlet.java

License:Open Source License

private void displayMatchingPages(ResourceRequest request, ResourceResponse response) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    PortletConfig portletConfig = (PortletConfig) request.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
    try {/* ww w  .  j a  va 2  s. c o  m*/
        String sitesIdsParam = ParamUtil.getString(request, ToutPortletConstants.ATTR_TOUT_SITES);
        String pagesRegex = ParamUtil.getString(request, ToutPortletConstants.ATTR_TOUT_PAGES);
        if (null == pagesRegex || pagesRegex.isEmpty()) {
            printJsonResponse(
                    LanguageUtil.get(portletConfig, themeDisplay.getLocale(),
                            ToutPortletConstants.ERROR_BAD_PARAMETER_REGEX),
                    String.valueOf(HttpServletResponse.SC_BAD_REQUEST), response);
            return;
        }
        Pattern pattern = null;
        try {
            pattern = Pattern.compile(pagesRegex.toLowerCase());
        } catch (PatternSyntaxException e) {
            logger.error(e);
            printJsonResponse(
                    LanguageUtil.get(portletConfig, themeDisplay.getLocale(),
                            ToutPortletConstants.ERROR_BAD_PARAMETER_REGEX),
                    String.valueOf(HttpServletResponse.SC_BAD_REQUEST), response);
            return;
        }
        String[] sitesIdsArr = (null != sitesIdsParam && !sitesIdsParam.isEmpty()
                ? sitesIdsParam.split(StringPool.COMMA)
                : null);
        Set<Layout> pages = getSitesPages(sitesIdsArr, themeDisplay.getCompanyId());
        Set<String> matchingSitesPagesStr = new HashSet<String>();
        if (null != pages)
            for (Layout layout : pages) {
                if (pattern.matcher(layout.getNameCurrentValue().toLowerCase()).find()) {
                    String matchingSitePageStr = layout.getGroup().getDescriptiveName() + StringPool.SPACE
                            + StringPool.DASH + StringPool.SPACE + layout.getNameCurrentValue();
                    matchingSitesPagesStr.add(matchingSitePageStr);
                }
            }
        if (!matchingSitesPagesStr.isEmpty()) {
            JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
            for (String item : matchingSitesPagesStr) {
                jsonArray.put(JSONFactoryUtil.serialize(item));
            }
            printJsonResponse(jsonArray.toString(), String.valueOf(HttpServletResponse.SC_OK), response);
        } else {
            printJsonResponse(
                    LanguageUtil.get(portletConfig, themeDisplay.getLocale(),
                            ToutPortletConstants.ERROR_NO_MATCHING_PAGES),
                    String.valueOf(HttpServletResponse.SC_NOT_FOUND), response);
        }
    } catch (Exception e) {
        logger.error(e);
        printJsonResponse(
                LanguageUtil.get(portletConfig, themeDisplay.getLocale(),
                        ToutPortletConstants.ERROR_RETRIEVING_MATCHING_PAGES),
                String.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR), response);
    }
}

From source file:com.slemarchand.quick.sign.up.web.portlet.QuickSignUpPortlet.java

License:Open Source License

protected User addUser(ActionRequest actionRequest, ActionResponse actionResponse, String password)
        throws SystemException, PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Company company = themeDisplay.getCompany();

    String authType = company.getAuthType();

    boolean autoPassword = false;
    String password1 = null;//from   ww  w .j  a  v  a 2s .co  m
    String password2 = null;
    boolean autoScreenName = !authType.equals(CompanyConstants.AUTH_TYPE_SN);
    String screenName = ParamUtil.getString(actionRequest, "screenName");
    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");
    long facebookId = 0;
    String openId = StringPool.BLANK;
    String firstName = ParamUtil.getString(actionRequest, "firstName");
    String middleName = StringPool.BLANK;
    String lastName = ParamUtil.getString(actionRequest, "lastName");
    int prefixId = 0;
    int suffixId = 0;
    boolean male = ParamUtil.getBoolean(actionRequest, "male", true);
    int birthdayMonth = 1;
    int birthdayDay = 1;
    int birthdayYear = 1970;
    String jobTitle = StringPool.BLANK;
    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    long[] userGroupIds = null;
    boolean sendEmail = true;

    ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    password1 = password;
    password2 = password;

    User user = UserServiceUtil.addUser(company.getCompanyId(), autoPassword, password1, password2,
            autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(), firstName,
            middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle,
            groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

    long userId = user.getUserId();

    user = UserLocalServiceUtil.updatePasswordReset(userId, false);

    PasswordPolicy passwordPolicy = PasswordPolicyLocalServiceUtil.getPasswordPolicyByUserId(userId);
    passwordPolicy.setChangeRequired(false);
    PasswordPolicyLocalServiceUtil.updatePasswordPolicy(passwordPolicy);

    if (_USERS_REMINDER_QUERIES_ENABLED) {
        user = UserLocalServiceUtil.updateReminderQuery(userId, StringPool.DASH, UUID.randomUUID().toString());
    }

    user = UserLocalServiceUtil.updateAgreedToTermsOfUse(userId, true);

    return user;
}