Example usage for com.liferay.portal.kernel.theme ThemeDisplay getPathMain

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getPathMain

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay getPathMain.

Prototype

public String getPathMain() 

Source Link

Document

Returns the URL for the portal instance's main servlet.

Usage

From source file:com.liferay.blogs.web.internal.portlet.action.RSSAction.java

License:Open Source License

@Override
protected byte[] getRSS(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    long plid = ParamUtil.getLong(request, "p_l_id");

    if (plid == LayoutConstants.DEFAULT_PLID) {
        plid = themeDisplay.getPlid();/*from www  . j av a 2  s.  c  o m*/
    }

    long companyId = ParamUtil.getLong(request, "companyId");
    long groupId = ParamUtil.getLong(request, "groupId");
    long organizationId = ParamUtil.getLong(request, "organizationId");
    int status = WorkflowConstants.STATUS_APPROVED;
    int max = ParamUtil.getInteger(request, "max", SearchContainer.DEFAULT_DELTA);
    String type = ParamUtil.getString(request, "type", RSSUtil.FORMAT_DEFAULT);
    double version = ParamUtil.getDouble(request, "version", RSSUtil.VERSION_DEFAULT);
    String displayStyle = ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);

    String feedURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/blogs/find_entry?";

    String entryURL = feedURL;

    String rss = StringPool.BLANK;

    if (companyId > 0) {
        feedURL = StringPool.BLANK;

        rss = _blogsEntryService.getCompanyEntriesRSS(companyId, new Date(), status, max, type, version,
                displayStyle, feedURL, entryURL, themeDisplay);
    } else if (groupId > 0) {
        feedURL += "p_l_id=" + plid;

        entryURL = feedURL;

        rss = _blogsEntryService.getGroupEntriesRSS(groupId, new Date(), status, max, type, version,
                displayStyle, feedURL, entryURL, themeDisplay);
    } else if (organizationId > 0) {
        feedURL = StringPool.BLANK;

        rss = _blogsEntryService.getOrganizationEntriesRSS(organizationId, new Date(), status, max, type,
                version, displayStyle, feedURL, entryURL, themeDisplay);
    } else if (layout != null) {
        groupId = themeDisplay.getScopeGroupId();

        feedURL = themeDisplay.getPathMain() + "/blogs/rss";

        entryURL = feedURL;

        rss = _blogsEntryService.getGroupEntriesRSS(groupId, new Date(), status, max, type, version,
                displayStyle, feedURL, entryURL, themeDisplay);
    }

    return rss.getBytes(StringPool.UTF8);
}

From source file:com.liferay.bookmarks.web.internal.portlet.action.FindEntryAction.java

License:Open Source License

@Override
public String execute(StrutsAction originalStrutsAction, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

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

    long entryId = ParamUtil.getLong(request, "entryId");

    response.sendRedirect(themeDisplay.getPathMain() + "/bookmarks/open_entry?entryId=" + entryId);

    return null;/*from www  .  j av  a  2  s. c o  m*/
}

From source file:com.liferay.comment.taglib.servlet.taglib.DiscussionTag.java

License:Open Source License

protected String getFormAction(HttpServletRequest request) {
    if (_formAction != null) {
        return _formAction;
    }/*from w w w  . ja va  2  s .  c  o m*/

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

    return themeDisplay.getPathMain() + "/portal/comment/discussion/edit";
}

From source file:com.liferay.comment.taglib.servlet.taglib.DiscussionTag.java

License:Open Source License

protected String getPaginationURL(HttpServletRequest request) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    String portletId = portletDisplay.getId();

    return StringBundler.concat(themeDisplay.getPathMain(),
            "/portal/comment/discussion/get_comments?p_p_isolated=1&", "portletId=", portletId);
}

From source file:com.liferay.flags.taglib.servlet.taglib.soy.FlagsTag.java

License:Open Source License

@Override
public int doStartTag() {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    String randomNamespace = StringUtil.randomId() + StringPool.UNDERLINE;

    try {// ww w . j a  v  a  2  s  .  co  m
        Map<String, Object> context = getContext();

        boolean enabled = GetterUtil.getBoolean(context.get("enabled"), true);

        Company company = themeDisplay.getCompany();

        putValue("companyName", company.getName());

        putValue("flagsEnabled", _isFlagsEnabled(themeDisplay));

        putValue("formData", _getDataJSONObject(context));

        putValue("id", randomNamespace + "id");

        putValue("enabled", enabled);

        boolean label = GetterUtil.getBoolean(context.get("label"), true);

        putValue("label", label);

        String message = GetterUtil.getString(context.get("message"), LanguageUtil.get(request, "flag"));

        putValue("message", message);

        putValue("pathTermsOfUse", themeDisplay.getPathMain() + "/portal/terms_of_use");

        putValue("pathThemeImages", themeDisplay.getPathThemeImages());

        putValue("portletNamespace", PortalUtil.getPortletNamespace(PortletKeys.FLAGS));

        boolean signedIn = themeDisplay.isSignedIn();

        putValue("signedIn", signedIn);

        if (signedIn) {
            User user = themeDisplay.getUser();

            putValue("reporterEmailAddress", user.getEmailAddress());
        }

        String title = message;

        if (!enabled) {
            title = LanguageUtil.get(request,
                    "flags-are-disabled-because-this-entry-is-in-the-recycle-" + "bin");
        }

        putValue("title", title);

        putValue("uri", _getURI());

        putValue("reasons", _getReasons(themeDisplay.getCompanyId()));
    } catch (Exception e) {
        _log.error(e, e);
    }

    setTemplateNamespace("Flags.render");

    return super.doStartTag();
}

From source file:com.liferay.journal.util.impl.JournalUtil.java

License:Open Source License

private static void _populateTokens(Map<String, String> tokens, long articleGroupId, ThemeDisplay themeDisplay)
        throws PortalException {

    Layout layout = themeDisplay.getLayout();

    Group group = layout.getGroup();

    LayoutSet layoutSet = layout.getLayoutSet();

    String friendlyUrlCurrent = null;

    if (layout.isPublicLayout()) {
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPublic();
    } else if (group.isUserGroup()) {
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPrivateUser();
    } else {//from w w w  .ja  v  a2 s  . c  o m
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPrivateGroup();
    }

    String layoutSetFriendlyUrl = themeDisplay.getI18nPath();

    String virtualHostname = layoutSet.getVirtualHostname();

    if (Validator.isNull(virtualHostname) || !virtualHostname.equals(themeDisplay.getServerName())) {

        layoutSetFriendlyUrl = friendlyUrlCurrent + group.getFriendlyURL();
    }

    tokens.put("article_group_id", String.valueOf(articleGroupId));
    tokens.put("cdn_host", themeDisplay.getCDNHost());
    tokens.put("company_id", String.valueOf(themeDisplay.getCompanyId()));
    tokens.put("friendly_url_current", friendlyUrlCurrent);
    tokens.put("friendly_url_private_group", themeDisplay.getPathFriendlyURLPrivateGroup());
    tokens.put("friendly_url_private_user", themeDisplay.getPathFriendlyURLPrivateUser());
    tokens.put("friendly_url_public", themeDisplay.getPathFriendlyURLPublic());
    tokens.put("group_friendly_url", group.getFriendlyURL());
    tokens.put("image_path", themeDisplay.getPathImage());
    tokens.put("layout_set_friendly_url", layoutSetFriendlyUrl);
    tokens.put("main_path", themeDisplay.getPathMain());
    tokens.put("portal_ctx", themeDisplay.getPathContext());
    tokens.put("portal_url", HttpUtil.removeProtocol(themeDisplay.getURLPortal()));
    tokens.put("protocol", HttpUtil.getProtocol(themeDisplay.getURLPortal()));
    tokens.put("root_path", themeDisplay.getPathContext());
    tokens.put("scope_group_id", String.valueOf(themeDisplay.getScopeGroupId()));
    tokens.put("site_group_id", String.valueOf(themeDisplay.getSiteGroupId()));
    tokens.put("theme_image_path", themeDisplay.getPathThemeImages());

    _populateCustomTokens(tokens, themeDisplay.getCompanyId());

    // Deprecated tokens

    tokens.put("friendly_url", themeDisplay.getPathFriendlyURLPublic());
    tokens.put("friendly_url_private", themeDisplay.getPathFriendlyURLPrivateGroup());
    tokens.put("group_id", String.valueOf(articleGroupId));
    tokens.put("page_url", themeDisplay.getPathFriendlyURLPublic());
}

From source file:com.liferay.journal.web.util.JournalRSSUtil.java

License:Open Source License

protected String processURL(JournalFeed feed, String url, ThemeDisplay themeDisplay, SyndEntry syndEntry) {

    url = StringUtil.replace(url, new String[] { "@group_id@", "@image_path@", "@main_path@" }, new String[] {
            String.valueOf(feed.getGroupId()), themeDisplay.getPathImage(), themeDisplay.getPathMain() });

    List<SyndEnclosure> syndEnclosures = getDLEnclosures(themeDisplay.getURLPortal(), url);

    syndEnclosures.addAll(getIGEnclosures(themeDisplay.getURLPortal(), url));

    syndEntry.setEnclosures(syndEnclosures);

    List<SyndLink> syndLinks = getDLLinks(themeDisplay.getURLPortal(), url);

    syndLinks.addAll(getIGLinks(themeDisplay.getURLPortal(), url));

    syndEntry.setLinks(syndLinks);//from ww w.  j a v  a  2  s  .  com

    return url;
}

From source file:com.liferay.login.authentication.openid.web.internal.portlet.action.OpenIdLoginMVCActionCommand.java

License:Open Source License

@Override
public void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    if (!_openId.isEnabled(themeDisplay.getCompanyId())) {
        throw new PrincipalException.MustBeEnabled(themeDisplay.getCompanyId(), OpenId.class.getName());
    }//  w ww . j  a  va  2  s .  c om

    if (actionRequest.getRemoteUser() != null) {
        actionResponse.sendRedirect(themeDisplay.getPathMain());

        return;
    }

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

    try {
        if (cmd.equals(Constants.READ)) {
            String redirect = _openIdServiceHandler.readResponse(themeDisplay, actionRequest);

            if (Validator.isNull(redirect)) {
                redirect = themeDisplay.getURLSignIn();
            }

            redirect = _portal.escapeRedirect(redirect);

            actionResponse.sendRedirect(redirect);
        } else {
            _openIdServiceHandler.sendRequest(themeDisplay, actionRequest, actionResponse);
        }
    } catch (Exception e) {
        if (e instanceof OpenIdServiceException) {
            if (_log.isInfoEnabled()) {
                _log.info("Error communicating with OpenID provider: " + e.getMessage());
            }

            SessionErrors.add(actionRequest, e.getClass());
        } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) {

            SessionErrors.add(actionRequest, e.getClass());
        } else {
            _log.error("Error processing the OpenID login", e);

            _portal.sendError(e, actionRequest, actionResponse);
        }
    }
}

From source file:com.liferay.login.web.internal.portlet.action.CreateAnonymousAccountMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    PortletConfig portletConfig = (PortletConfig) actionRequest
            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

    String portletName = portletConfig.getPortletName();

    if (!portletName.equals(LoginPortletKeys.FAST_LOGIN)) {
        throw new PrincipalException("Unable to create anonymous account");
    }/*w ww .j  a v  a 2 s  .  co m*/

    if (actionRequest.getRemoteUser() != null) {
        actionResponse.sendRedirect(themeDisplay.getPathMain());

        return;
    }

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

    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");

    PortletURL portletURL = PortletURLFactoryUtil.create(actionRequest, LoginPortletKeys.FAST_LOGIN,
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/login/login_redirect");
    portletURL.setParameter("emailAddress", emailAddress);
    portletURL.setParameter("anonymousUser", Boolean.TRUE.toString());
    portletURL.setWindowState(LiferayWindowState.POP_UP);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {
        if (cmd.equals(Constants.ADD)) {
            addAnonymousUser(actionRequest, actionResponse);

            sendRedirect(actionRequest, actionResponse, portletURL.toString());
        } else if (cmd.equals(Constants.UPDATE)) {
            Company company = themeDisplay.getCompany();

            if (!company.isStrangers()) {
                throw new PrincipalException.MustBeEnabled(company.getCompanyId(),
                        PropsKeys.COMPANY_SECURITY_STRANGERS);
            }

            jsonObject = updateIncompleteUser(actionRequest, actionResponse);

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
        }
    } catch (Exception e) {
        if (cmd.equals(Constants.UPDATE)) {
            jsonObject.putException(e);

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
        } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) {

            User user = _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

            if (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) {
                SessionErrors.add(actionRequest, e.getClass());
            } else {
                sendRedirect(actionRequest, actionResponse, portletURL.toString());
            }
        } else if (e instanceof CaptchaConfigurationException || e instanceof CaptchaTextException
                || e instanceof CompanyMaxUsersException || e instanceof ContactNameException
                || e instanceof EmailAddressException || e instanceof GroupFriendlyURLException
                || e instanceof UserEmailAddressException) {

            SessionErrors.add(actionRequest, e.getClass(), e);
        } else {
            _log.error("Unable to create anonymous account", e);

            _portal.sendError(e, actionRequest, actionResponse);
        }
    }
}

From source file:com.liferay.login.web.internal.portlet.action.LoginMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    if (PropsValues.AUTH_LOGIN_DISABLED) {
        actionResponse.sendRedirect(themeDisplay.getPathMain() + PropsValues.AUTH_LOGIN_DISABLED_PATH);

        return;//from www.  j av  a 2s. co m
    }

    /*if (actionRequest.getRemoteUser() != null) {
       actionResponse.sendRedirect(themeDisplay.getPathMain());
            
       return;
    }*/

    try {
        login(themeDisplay, actionRequest, actionResponse);

        boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

        if (doActionAfterLogin) {
            LiferayPortletResponse liferayPortletResponse = _portal.getLiferayPortletResponse(actionResponse);

            PortletURL renderURL = liferayPortletResponse.createRenderURL();

            renderURL.setParameter("mvcRenderCommandName", "/login/login_redirect");

            actionRequest.setAttribute(WebKeys.REDIRECT, renderURL.toString());
        }
    } catch (Exception e) {
        if (e instanceof AuthException) {
            Throwable cause = e.getCause();

            if (cause instanceof PasswordExpiredException || cause instanceof UserLockoutException) {

                SessionErrors.add(actionRequest, cause.getClass(), cause);
            } else {
                if (_log.isInfoEnabled()) {
                    _log.info("Authentication failed");
                }

                SessionErrors.add(actionRequest, e.getClass());
            }
        } else if (e instanceof CompanyMaxUsersException || e instanceof CookieNotSupportedException
                || e instanceof NoSuchUserException || e instanceof PasswordExpiredException
                || e instanceof UserEmailAddressException || e instanceof UserIdException
                || e instanceof UserLockoutException || e instanceof UserPasswordException
                || e instanceof UserScreenNameException) {

            SessionErrors.add(actionRequest, e.getClass(), e);
        } else {
            _log.error(e, e);

            _portal.sendError(e, actionRequest, actionResponse);

            return;
        }

        postProcessAuthFailure(actionRequest, actionResponse);
    }
}