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

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

Introduction

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

Prototype

String FORWARD_SLASH

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

Click Source Link

Usage

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

License:Open Source License

protected String formatJSP(String fileName, String absolutePath, String content) throws IOException {

    StringBundler sb = new StringBundler();

    String currentAttributeAndValue = null;
    String previousAttribute = null;
    String previousAttributeAndValue = null;

    String currentException = null;
    String previousException = null;

    boolean hasUnsortedExceptions = false;

    try (UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(
            new UnsyncStringReader(content))) {

        _checkedForIncludesFileNames = new HashSet<String>();
        _includeFileNames = new HashSet<String>();

        int lineCount = 0;

        String line = null;/* ww  w . j  av a  2  s  . co  m*/

        String previousLine = StringPool.BLANK;

        boolean readAttributes = false;

        boolean javaSource = false;

        while ((line = unsyncBufferedReader.readLine()) != null) {
            lineCount++;

            if (portalSource && hasUnusedTaglib(fileName, line)) {
                continue;
            }

            if (!fileName.contains("jsonw") || !fileName.endsWith("action.jsp")) {

                line = trimLine(line, false);
            }

            if (line.contains("<aui:button ") && line.contains("type=\"button\"")) {

                processErrorMessage(fileName, "aui:button " + fileName + " " + lineCount);
            }

            if (line.contains("debugger.")) {
                processErrorMessage(fileName, "debugger " + fileName + " " + lineCount);
            }

            String trimmedLine = StringUtil.trimLeading(line);
            String trimmedPreviousLine = StringUtil.trimLeading(previousLine);

            checkStringBundler(trimmedLine, fileName, lineCount);

            checkEmptyCollection(trimmedLine, fileName, lineCount);

            if (trimmedLine.equals("<%") || trimmedLine.equals("<%!")) {
                javaSource = true;
            } else if (trimmedLine.equals("%>")) {
                javaSource = false;
            }

            if (javaSource || trimmedLine.contains("<%= ")) {
                checkInefficientStringMethods(line, fileName, absolutePath, lineCount);
            }

            if (javaSource && portalSource && !isExcluded(_unusedVariablesExclusions, absolutePath, lineCount)
                    && !_jspContents.isEmpty() && hasUnusedVariable(fileName, trimmedLine)) {

                continue;
            }

            // LPS-47179

            if (line.contains(".sendRedirect(") && !fileName.endsWith("_jsp.jsp")) {

                processErrorMessage(fileName, "Do not use sendRedirect in jsp: " + fileName + " " + lineCount);
            }

            if (!trimmedLine.equals("%>") && line.contains("%>") && !line.contains("--%>")
                    && !line.contains(" %>")) {

                line = StringUtil.replace(line, "%>", " %>");
            }

            if (line.contains("<%=") && !line.contains("<%= ")) {
                line = StringUtil.replace(line, "<%=", "<%= ");
            }

            if (trimmedPreviousLine.equals("%>") && Validator.isNotNull(line) && !trimmedLine.equals("-->")) {

                sb.append("\n");
            } else if (Validator.isNotNull(previousLine) && !trimmedPreviousLine.equals("<!--")
                    && trimmedLine.equals("<%")) {

                sb.append("\n");
            } else if (trimmedPreviousLine.equals("<%") && Validator.isNull(line)) {

                continue;
            } else if (trimmedPreviousLine.equals("<%") && trimmedLine.startsWith("//")) {

                sb.append("\n");
            } else if (Validator.isNull(previousLine) && trimmedLine.equals("%>") && (sb.index() > 2)) {

                String lineBeforePreviousLine = sb.stringAt(sb.index() - 3);

                if (!lineBeforePreviousLine.startsWith("//")) {
                    sb.setIndex(sb.index() - 1);
                }
            }

            if ((trimmedLine.startsWith("if (") || trimmedLine.startsWith("else if (")
                    || trimmedLine.startsWith("while (")) && trimmedLine.endsWith(") {")) {

                checkIfClauseParentheses(trimmedLine, fileName, lineCount);
            }

            if (readAttributes) {
                if (!trimmedLine.startsWith(StringPool.FORWARD_SLASH)
                        && !trimmedLine.startsWith(StringPool.GREATER_THAN)) {

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

                    if (pos != -1) {
                        String attribute = trimmedLine.substring(0, pos);

                        if (!trimmedLine.endsWith(StringPool.APOSTROPHE)
                                && !trimmedLine.endsWith(StringPool.GREATER_THAN)
                                && !trimmedLine.endsWith(StringPool.QUOTE)) {

                            processErrorMessage(fileName, "attribute: " + fileName + " " + lineCount);

                            readAttributes = false;
                        } else if (trimmedLine.endsWith(StringPool.APOSTROPHE)
                                && !trimmedLine.contains(StringPool.QUOTE)) {

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

                            readAttributes = false;
                        } else if (Validator.isNotNull(previousAttribute)) {
                            if (!isAttributName(attribute) && !attribute.startsWith(StringPool.LESS_THAN)) {

                                processErrorMessage(fileName, "attribute: " + fileName + " " + lineCount);

                                readAttributes = false;
                            } else if (Validator.isNull(previousAttributeAndValue)
                                    && (previousAttribute.compareTo(attribute) > 0)) {

                                previousAttributeAndValue = previousLine;
                                currentAttributeAndValue = line;
                            }
                        }

                        if (!readAttributes) {
                            previousAttribute = null;
                            previousAttributeAndValue = null;
                        } else {
                            previousAttribute = attribute;
                        }
                    }
                } else {
                    previousAttribute = null;

                    readAttributes = false;
                }
            }

            if (!hasUnsortedExceptions) {
                int x = line.indexOf("<liferay-ui:error exception=\"<%=");

                if (x != -1) {
                    int y = line.indexOf(".class %>", x);

                    if (y != -1) {
                        currentException = line.substring(x, y);

                        if (Validator.isNotNull(previousException)
                                && (previousException.compareTo(currentException) > 0)) {

                            currentException = line;
                            previousException = previousLine;

                            hasUnsortedExceptions = true;
                        }
                    }
                }

                if (!hasUnsortedExceptions) {
                    previousException = currentException;
                    currentException = null;
                }
            }

            if (trimmedLine.startsWith(StringPool.LESS_THAN) && !trimmedLine.startsWith("<%")
                    && !trimmedLine.startsWith("<!")) {

                if (!trimmedLine.contains(StringPool.GREATER_THAN) && !trimmedLine.contains(StringPool.SPACE)) {

                    readAttributes = true;
                } else {
                    line = sortAttributes(fileName, line, lineCount, true);
                }
            }

            if (!trimmedLine.contains(StringPool.DOUBLE_SLASH) && !trimmedLine.startsWith(StringPool.STAR)) {

                while (trimmedLine.contains(StringPool.TAB)) {
                    line = StringUtil.replaceLast(line, StringPool.TAB, StringPool.SPACE);

                    trimmedLine = StringUtil.replaceLast(trimmedLine, StringPool.TAB, StringPool.SPACE);
                }

                while (trimmedLine.contains(StringPool.DOUBLE_SPACE)
                        && !trimmedLine.contains(StringPool.QUOTE + StringPool.DOUBLE_SPACE)
                        && !fileName.endsWith(".vm")) {

                    line = StringUtil.replaceLast(line, StringPool.DOUBLE_SPACE, StringPool.SPACE);

                    trimmedLine = StringUtil.replaceLast(trimmedLine, StringPool.DOUBLE_SPACE,
                            StringPool.SPACE);
                }
            }

            if (!fileName.endsWith("/touch.jsp")) {
                int x = line.indexOf("<%@ include file");

                if (x != -1) {
                    x = line.indexOf(StringPool.QUOTE, x);

                    int y = line.indexOf(StringPool.QUOTE, x + 1);

                    if (y != -1) {
                        String includeFileName = line.substring(x + 1, y);

                        Matcher matcher = _jspIncludeFilePattern.matcher(includeFileName);

                        if (!matcher.find()) {
                            processErrorMessage(fileName, "include: " + fileName + " " + lineCount);
                        }
                    }
                }
            }

            line = replacePrimitiveWrapperInstantiation(fileName, line, lineCount);

            previousLine = line;

            sb.append(line);
            sb.append("\n");
        }
    }

    content = sb.toString();

    if (content.endsWith("\n")) {
        content = content.substring(0, content.length() - 1);
    }

    content = formatTaglibQuotes(fileName, content, StringPool.QUOTE);
    content = formatTaglibQuotes(fileName, content, StringPool.APOSTROPHE);

    if (Validator.isNotNull(previousAttributeAndValue)) {
        content = StringUtil.replaceFirst(content, previousAttributeAndValue + "\n" + currentAttributeAndValue,
                currentAttributeAndValue + "\n" + previousAttributeAndValue);
    }

    if (hasUnsortedExceptions) {
        if ((StringUtil.count(content, currentException) > 1)
                || (StringUtil.count(content, previousException) > 1)) {

            processErrorMessage(fileName, "unsorted exceptions: " + fileName);
        } else {
            content = StringUtil.replaceFirst(content, previousException, currentException);

            content = StringUtil.replaceLast(content, currentException, previousException);
        }
    }

    return content;
}

From source file:com.rivetlogic.event.notification.messagelistener.NotificationListener.java

License:Open Source License

private String[] processRegularInvitation(Message message, MessageSenderImpl messageSender)
        throws AddressException, PortalException, SystemException {

    messageSender.setRecipients(message.getString(NotificationConstants.RECIPIENTS));
    Long eventId = message.getLong(NotificationConstants.EVENT_ID);
    Long participantId = message.getLong(NotificationConstants.PARTICIPANT_ID);
    Event event = EventLocalServiceUtil.getEvent(eventId);
    Participant participant = ParticipantLocalServiceUtil.getParticipant(participantId);
    String confirmationURL = PropsValues.CONFIRMATION_LINK;
    String portalURL = message.getString(NotificationConstants.PORTAL_URL) + StringPool.FORWARD_SLASH;
    Token token = TokenLocalServiceUtil.createToken(participant);

    confirmationURL = StringUtil.replace(confirmationURL,
            new String[] { PATTERN_REPLACE_ZERO, PATTERN_REPLACE_ONE },
            new String[] { Long.toString(eventId), token.getUuid() });

    if (_log.isDebugEnabled())
        _log.debug(LOG_DEBUG_CONFIRMATION_URL + confirmationURL);

    String[] data = new String[] { messageSender.getSender().getAddress(),
            messageSender.getSender().getPersonal(), event.getName(),
            NotificationConstants.CDF.format(event.getEventDate()), participant.getFullName(),
            messageSender.getRecipients()[0].toString(), event.getLocation(), event.getDescription(),
            portalURL + message.getString(NotificationConstants.PUBLIC_URL),
            portalURL + message.getString(NotificationConstants.PUBLIC_URL) + confirmationURL
                    + EventConstant.STATUS_GOING,
            portalURL + message.getString(NotificationConstants.PUBLIC_URL) + confirmationURL
                    + EventConstant.STATUS_NOT_GOING,
            portalURL };//from  w  ww  .  j ava 2s.  c om

    return data;
}

From source file:com.rivetlogic.event.notification.messagelistener.NotificationListener.java

License:Open Source License

private String[] processManualEvent(Message message, MessageSenderImpl messageSender)
        throws PortalException, SystemException, AddressException {

    message.put(NotificationConstants.DONT_UPDATE_USER, true);
    messageSender.setRecipients(message.getString(NotificationConstants.RECIPIENTS));
    Participant participant = (Participant) message.get(NotificationConstants.PARTICIPANT);

    Event event = EventLocalServiceUtil.getEvent(participant.getEventId());
    Token token = TokenLocalServiceUtil.createToken(participant);
    String confirmationURL = PropsValues.CONFIRMATION_LINK;
    boolean addSlash = !message.getString(NotificationConstants.PUBLIC_URL)
            .startsWith(StringPool.FORWARD_SLASH);

    String portalURL = message.getString(NotificationConstants.PORTAL_URL)
            + (addSlash ? StringPool.FORWARD_SLASH : StringPool.BLANK);
    confirmationURL = StringUtil.replace(confirmationURL,
            new String[] { PATTERN_REPLACE_ZERO, PATTERN_REPLACE_ONE },
            new String[] { Long.toString(event.getEventId()), token.getUuid() });

    if (_log.isDebugEnabled())
        _log.debug(LOG_DEBUG_CONFIRMATION_URL + confirmationURL);

    String[] data = new String[] { messageSender.getSender().getAddress(),
            messageSender.getSender().getPersonal(), event.getName(),
            NotificationConstants.CDF.format(event.getEventDate()), participant.getFullName(),
            messageSender.getRecipients()[0].toString(), event.getLocation(), event.getDescription(),
            portalURL + message.getString(NotificationConstants.PUBLIC_URL),
            portalURL + message.getString(NotificationConstants.PUBLIC_URL) + confirmationURL
                    + EventConstant.STATUS_GOING,
            portalURL + message.getString(NotificationConstants.PUBLIC_URL) + confirmationURL
                    + EventConstant.STATUS_NOT_GOING,
            portalURL };/*  ww  w.  j  av a  2s.c  om*/

    return data;
}

From source file:com.rivetlogic.event.notification.messagelistener.NotificationListener.java

License:Open Source License

private void processUpdatedEvent(Message message, MessageSenderImpl messageSender)
        throws PortalException, SystemException, AddressException {

    Long eventId = message.getLong(NotificationConstants.EVENT_ID);
    Event event = EventLocalServiceUtil.getEvent(eventId);
    List<Participant> participants = event.getParticipants(new int[] { EventConstant.EVENT_STATUS_ACCEPTER,
            EventConstant.EVENT_STATUS_SENT, EventConstant.EVENT_STATUS_NOT_SENT });

    String portalURL = message.getString(NotificationConstants.PORTAL_URL) + StringPool.FORWARD_SLASH;

    for (Participant p : participants) {

        String confirmationURL = PropsValues.CONFIRMATION_LINK;
        Token token = TokenLocalServiceUtil.createToken(p);
        confirmationURL = StringUtil.replace(confirmationURL,
                new String[] { PATTERN_REPLACE_ZERO, PATTERN_REPLACE_ONE },
                new String[] { Long.toString(event.getEventId()), token.getUuid() });

        String[] data = new String[] { messageSender.getSender().getAddress(),
                messageSender.getSender().getPersonal(), event.getName(),
                NotificationConstants.CDF.format(event.getEventDate()), p.getFullName(), p.getEmail(),
                event.getLocation(), event.getDescription(),
                portalURL + message.getString(NotificationConstants.PUBLIC_URL),
                portalURL + message.getString(NotificationConstants.PUBLIC_URL) + confirmationURL
                        + EventConstant.STATUS_GOING,
                portalURL + message.getString(NotificationConstants.PUBLIC_URL) + confirmationURL
                        + EventConstant.STATUS_NOT_GOING,
                message.getString(NotificationConstants.PORTAL_URL) };

        processTemplate(messageSender, data);
        try {// www .ja v a2 s .c o m
            messageSender.setRecipients(p.getEmail());
            EmailNotificationUtil.sendEmailNotification(messageSender);

        } catch (AddressException e) {
            _log.error(String.format(LOG_EROR_PARTICIPANT_WRONG_EMAIL, p.getFullName(), p.getEmail()), e);
        }

        setCommonFields(message, messageSender);// Set a clean template
    }
}

From source file:com.rivetlogic.event.notification.messagelistener.NotificationListener.java

License:Open Source License

@SuppressWarnings("unchecked")
private void processCancelledEvent(Message message, MessageSenderImpl messageSender)
        throws PortalException, SystemException, AddressException {

    Event event = (Event) message.get(NotificationConstants.EVENT);
    List<Participant> participants = (List<Participant>) message.get(NotificationConstants.PARTICIPANTS);
    String portalURL = message.getString(NotificationConstants.PORTAL_URL) + StringPool.FORWARD_SLASH;
    if (participants == null)
        participants = event.getParticipants(
                new int[] { EventConstant.EVENT_STATUS_ACCEPTER, EventConstant.EVENT_STATUS_SENT });

    for (Participant p : participants) {
        String[] data = new String[] { messageSender.getSender().getAddress(),
                messageSender.getSender().getPersonal(), event.getName(),
                NotificationConstants.CDF.format(event.getEventDate()), p.getFullName(), p.getEmail(),
                event.getLocation(), event.getDescription(),
                portalURL + message.getString(NotificationConstants.PUBLIC_URL), StringPool.BLANK,
                StringPool.BLANK, portalURL };

        processTemplate(messageSender, data);
        try {//from  w w  w. ja  v  a2s . co  m
            messageSender.setRecipients(p.getEmail());
            EmailNotificationUtil.sendEmailNotification(messageSender);
        } catch (Exception e) {
            _log.error(String.format(LOG_EROR_PARTICIPANT_WRONG_EMAIL, p.getFullName(), p.getEmail()));
        }
        setCommonFields(message, messageSender);// Set a clean template
    }
}

From source file:com.rivetlogic.event.notification.messagelistener.NotificationListener.java

License:Open Source License

private String[] processSingleUpdatedEvent(Message message, MessageSenderImpl messageSender)
        throws PortalException, SystemException, AddressException {

    Participant p = (Participant) message.get(NotificationConstants.PARTICIPANT);
    Event event = EventLocalServiceUtil.getEvent(p.getEventId());

    message.put(NotificationConstants.PARTICIPANT_ID, p.getParticipantId());

    Token token = TokenLocalServiceUtil.createToken(p);
    String confirmationURL = PropsValues.CONFIRMATION_LINK;
    String portalURL = message.getString(NotificationConstants.PORTAL_URL) + StringPool.FORWARD_SLASH;
    confirmationURL = StringUtil.replace(confirmationURL,
            new String[] { PATTERN_REPLACE_ZERO, PATTERN_REPLACE_ONE },
            new String[] { Long.toString(event.getEventId()), token.getUuid() });

    String[] data = new String[] { messageSender.getSender().getAddress(),
            messageSender.getSender().getPersonal(), event.getName(),
            NotificationConstants.CDF.format(event.getEventDate()), p.getFullName(), p.getEmail(),
            event.getLocation(), event.getDescription(),
            portalURL + message.getString(NotificationConstants.PUBLIC_URL),
            portalURL + message.getString(NotificationConstants.PUBLIC_URL) + confirmationURL
                    + EventConstant.STATUS_GOING,
            portalURL + message.getString(NotificationConstants.PUBLIC_URL) + confirmationURL
                    + EventConstant.STATUS_NOT_GOING,
            portalURL };//from   ww w.  j a v  a2 s.com

    messageSender.setRecipients(p.getEmail());

    return data;
}

From source file:com.rivetlogic.event.notification.messagelistener.NotificationListener.java

License:Open Source License

private void processSingleCancelledEvent(Message message, MessageSenderImpl messageSender)
        throws AddressException, PortalException, SystemException {

    Participant p = (Participant) message.get(NotificationConstants.PARTICIPANT);
    Event event = EventLocalServiceUtil.getEvent(p.getEventId());
    String portalURL = message.getString(NotificationConstants.PORTAL_URL) + StringPool.FORWARD_SLASH;
    ;/*  www. ja  va2  s .com*/
    String[] data = new String[] { messageSender.getSender().getAddress(),
            messageSender.getSender().getPersonal(), event.getName(),
            NotificationConstants.CDF.format(event.getEventDate()), p.getFullName(), p.getEmail(),
            event.getLocation(), event.getDescription(),
            portalURL + message.getString(NotificationConstants.PUBLIC_URL), StringPool.BLANK, StringPool.BLANK,
            portalURL };

    messageSender.setRecipients(p.getEmail());
    processTemplate(messageSender, data);
    EmailNotificationUtil.sendEmailNotification(messageSender);
}

From source file:com.rivetlogic.event.notification.messagelistener.NotificationListener.java

License:Open Source License

private void processReminderMessage(Message message, MessageSenderImpl messageSender)
        throws PortalException, SystemException, AddressException {

    Long eventId = message.getLong(NotificationConstants.EVENT_ID);
    Event event = EventLocalServiceUtil.getEvent(eventId);
    List<Participant> participants = event.getParticipants(new int[] { EventConstant.EVENT_STATUS_ACCEPTER });
    String portalURL = message.getString(NotificationConstants.PORTAL_URL) + StringPool.FORWARD_SLASH;

    for (Participant p : participants) {

        String confirmationURL = PropsValues.CONFIRMATION_LINK;
        Token token = TokenLocalServiceUtil.createToken(p);
        confirmationURL = StringUtil.replace(confirmationURL,
                new String[] { PATTERN_REPLACE_ZERO, PATTERN_REPLACE_ONE },
                new String[] { Long.toString(event.getEventId()), token.getUuid() });

        String[] data = new String[] { messageSender.getSender().getAddress(),
                messageSender.getSender().getPersonal(), event.getName(),
                NotificationConstants.CDF.format(event.getEventDate()), p.getFullName(), p.getEmail(),
                event.getLocation(), event.getDescription(),
                portalURL + message.getString(NotificationConstants.PUBLIC_URL),
                portalURL + message.getString(NotificationConstants.PUBLIC_URL) + confirmationURL
                        + EventConstant.STATUS_GOING,
                portalURL + message.getString(NotificationConstants.PUBLIC_URL) + confirmationURL
                        + EventConstant.STATUS_NOT_GOING,
                portalURL };/*  www .  j  a v  a 2  s . co m*/

        processTemplate(messageSender, data);

        try {
            messageSender.setRecipients(p.getEmail());
            EmailNotificationUtil.sendEmailNotification(messageSender);
        } catch (AddressException ae) {
            _log.error(String.format(LOG_EROR_PARTICIPANT_WRONG_EMAIL, p.getFullName(), p.getEmail()));
        }

        setCommonFields(message, messageSender);// Set a clean template
    }
}

From source file:com.rivetlogic.geo.util.GeoUtility.java

License:Open Source License

public static String getIP_CIDR(String ip, int maskLenght) {
    return ip + StringPool.FORWARD_SLASH + getSubnetMask(maskLenght);
}

From source file:com.rivetlogic.microsite.util.MicroSiteUtil.java

License:Open Source License

public static String getMicroSiteURL(PortletRequest request, long groupId)
        throws PortalException, SystemException {
    String scheme = request.getScheme();
    String serverName = request.getServerName();
    int serverPort = request.getServerPort();
    Group liveGroup = GroupLocalServiceUtil.getGroup(groupId);
    int layoutCount = LayoutLocalServiceUtil.getLayoutsCount(liveGroup, false);
    if (layoutCount > 0) {
        return scheme + HTTP_PREFIX + serverName + StringPool.COLON + serverPort + StringPool.FORWARD_SLASH
                + PUBLIC_PAGE_PREFIX + liveGroup.getFriendlyURL();
    }//www .j  a v a 2  s . c om
    layoutCount = LayoutLocalServiceUtil.getLayoutsCount(liveGroup, true);
    if (layoutCount > 0) {
        return scheme + HTTP_PREFIX + serverName + StringPool.COLON + serverPort + StringPool.FORWARD_SLASH
                + PRIVATE_PAGE_PREFIX + liveGroup.getFriendlyURL();
    }
    return StringPool.POUND;
}