com.liferay.users.admin.web.internal.portlet.MyOrganizationsPortlet.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.users.admin.web.internal.portlet.MyOrganizationsPortlet.java

Source

/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.users.admin.web.internal.portlet;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.security.auth.PrincipalException;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.security.permission.PermissionThreadLocal;
import com.liferay.portal.kernel.service.permission.PortalPermissionUtil;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.users.admin.constants.UsersAdminPortletKeys;

import java.io.IOException;

import javax.portlet.Portlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.osgi.service.component.annotations.Component;

/**
 * @author Jorge Ferrer
 */
@Component(immediate = true, property = { "com.liferay.portlet.css-class-wrapper=portlet-users-admin",
        "com.liferay.portlet.display-category=category.hidden",
        "com.liferay.portlet.header-portlet-css=/css/main.css", "com.liferay.portlet.icon=/icons/users_admin.png",
        "com.liferay.portlet.preferences-owned-by-group=true",
        "com.liferay.portlet.private-request-attributes=false",
        "com.liferay.portlet.private-session-attributes=false", "com.liferay.portlet.render-weight=50",
        "com.liferay.portlet.struts-path=users_admin", "com.liferay.portlet.use-default-template=true",
        "javax.portlet.display-name=My Organizations", "javax.portlet.expiration-cache=0",
        "javax.portlet.init-param.template-path=/", "javax.portlet.init-param.view-template=/view.jsp",
        "javax.portlet.name=" + UsersAdminPortletKeys.MY_ORGANIZATIONS,
        "javax.portlet.resource-bundle=content.Language", "javax.portlet.security-role-ref=administrator",
        "javax.portlet.supports.mime-type=text/html" }, service = Portlet.class)
public class MyOrganizationsPortlet extends UsersAdminPortlet {

    @Override
    protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
            throws IOException, PortletException {

        String path = getPath(renderRequest, renderResponse);

        if (path.equals("/edit_organization.jsp")) {
            try {
                long organizationId = ParamUtil.getLong(renderRequest, "organizationId");

                if (organizationId == 0) {
                    PortalPermissionUtil.check(PermissionThreadLocal.getPermissionChecker(),
                            ActionKeys.ADD_ORGANIZATION);
                }
            } catch (PrincipalException pe) {
                if (_log.isDebugEnabled()) {
                    _log.debug(pe, pe);
                }

                SessionErrors.add(renderRequest, pe.getClass());

                path = "/error.jsp";
            }

            include(path, renderRequest, renderResponse);
        } else {
            super.doDispatch(renderRequest, renderResponse);
        }
    }

    private static final Log _log = LogFactoryUtil.getLog(MyOrganizationsPortlet.class);

}