package com.ebizwindow.crm.utils;

import java.security.Key;
import java.util.List; import javax.portlet.ActionRequest;
import javax.portlet.PortletMode;
import javax.portlet.PortletModeException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;
import javax.portlet.WindowState;
import javax.portlet.WindowStateException;
import javax.servlet.http.HttpServletRequest; import com.ebizwindow.crm.constants.PortletIDs;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.UnicodeProperties;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Layout;
import com.liferay.portal.model.PortletConstants;
import com.liferay.portal.model.User;
import com.liferay.portal.service.LayoutLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.PortletURLFactoryUtil;
import com.liferay.util.Encryptor;
import com.liferay.util.EncryptorException; /**
* @author Ivan Li
*
*/
public class PortletURLUtil { private static Log _log = LogFactoryUtil.getLog(PortletURLUtil.class); public static String getPortletURLWithinCurrentPage(
PortletRequest portletRequest, String portletId, int lifeCycle,
String windowState, String portletMode) throws PortalException,
SystemException {
String portletURL = null; HttpServletRequest request = PortalUtil
.getHttpServletRequest(portletRequest); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); String targetPortletId = null;
String rootPortletId = PortletConstants.getRootPortletId(portletId); Layout layout = themeDisplay.getLayout();
if (layout != null) { UnicodeProperties typeSettings = layout.getTypeSettingsProperties(); labelBreak: for (String key : typeSettings.keySet()) {
String value = typeSettings.get(key);
int idx = value.indexOf(rootPortletId);
if (idx >= 0) {
String[] portletIds = StringUtil.split(value);
for (String id : portletIds) {
if (id.contains(rootPortletId)) {
targetPortletId = id;
break labelBreak;
}
}
}
} StringBuilder sb = new StringBuilder();
String layoutURL = PortalUtil.getLayoutFriendlyURL(layout,
themeDisplay); sb.append(layoutURL);
sb.append(StringPool.QUESTION).append("p_p_id")
.append(StringPool.EQUAL).append(targetPortletId);
sb.append(StringPool.AMPERSAND).append("p_p_lifecycle")
.append(StringPool.EQUAL).append(lifeCycle);
sb.append(StringPool.AMPERSAND).append("p_p_state")
.append(StringPool.EQUAL).append(windowState);
sb.append(StringPool.AMPERSAND).append("p_p_mode")
.append(StringPool.EQUAL).append(portletMode); portletURL = sb.toString(); } else {
_log.debug("Get portlet URL by portletId within the current page!");
}
return portletURL;
} public static String getPortletURLByUserId(PortletRequest portletRequest,
long userId, String portletId) throws PortalException,
SystemException {
User user = UserLocalServiceUtil.getUserById(userId);
long groupId = user.getGroup().getGroupId(); return getPortletURLByGroupId(portletRequest, groupId, portletId, 1,
WindowState.MAXIMIZED.toString(), PortletMode.VIEW.toString());
} public static String getPortletURLByGroupId(PortletRequest portletRequest,
long groupId, String portletId, int lifeCycle, String state,
String mode) throws SystemException, PortalException {
String portletURL = null;
Layout selectedLayout = null;
String targetPortletId = null;
String rootPortletId = PortletConstants.getRootPortletId(portletId);
List<Layout> layouts = LayoutLocalServiceUtil
.getLayouts(groupId, false);
if (layouts != null) {
labelBreak: for (Layout layout : layouts) {
UnicodeProperties typeSettings = layout
.getTypeSettingsProperties();
for (String key : typeSettings.keySet()) {
String value = typeSettings.get(key);
int idx = value.indexOf(rootPortletId);
if (idx >= 0) {
String[] portletIds = StringUtil.split(value);
for (String id : portletIds) {
if (id.contains(rootPortletId)) {
selectedLayout = layout;
targetPortletId = id;
break labelBreak;
}
}
}
}
}
} if (selectedLayout != null) {
StringBuilder sb = new StringBuilder();
// HttpServletRequest request =
// PortalUtil.getHttpServletRequest(portletRequest);
ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest
.getAttribute(WebKeys.THEME_DISPLAY);
String layoutURL = PortalUtil.getLayoutFriendlyURL(selectedLayout,
themeDisplay); sb.append(layoutURL); // sb.append(StringPool.QUESTION).append("p_auth").append(StringPool.EQUAL);
// sb.append(processValue(null, AuthTokenUtil.getToken(request))); sb.append(StringPool.QUESTION).append("p_p_id")
.append(StringPool.EQUAL).append(targetPortletId);
sb.append(StringPool.AMPERSAND).append("p_p_lifecycle")
.append(StringPool.EQUAL).append(lifeCycle);
sb.append(StringPool.AMPERSAND).append("p_p_state")
.append(StringPool.EQUAL).append(state);
sb.append(StringPool.AMPERSAND).append("p_p_mode")
.append(StringPool.EQUAL).append(mode); portletURL = sb.toString();
} else {
_log.debug("Get Portlet URL By UserId and portletId with empty result!");
} return portletURL;
} public static PortletURL getPortletURL(ActionRequest actionRequest)
throws PortalException, SystemException {
long groupId = PortalUtil.getScopeGroupId(actionRequest);
String portletId = PortalUtil.getPortletId(actionRequest);
long plid = PortalUtil.getPlidFromPortletId(groupId, portletId);
PortletURL redirectURL = PortletURLFactoryUtil.create(
PortalUtil.getHttpServletRequest(actionRequest), portletId,
plid, PortletRequest.ACTION_PHASE);
try {
redirectURL.setPortletMode(actionRequest.getPortletMode());
redirectURL.setWindowState(actionRequest.getWindowState());
} catch (PortletModeException e) {
_log.error(e);
} catch (WindowStateException e) {
_log.error(e);
}
return redirectURL;
} public static PortletURL getPortletURL(PortletRequest actionRequest)
throws PortalException, SystemException {
long groupId = PortalUtil.getScopeGroupId(actionRequest);
String portletId = PortalUtil.getPortletId(actionRequest);
long plid = PortalUtil.getPlidFromPortletId(groupId, portletId);
PortletURL redirectURL = PortletURLFactoryUtil.create(
PortalUtil.getHttpServletRequest(actionRequest), portletId,
plid, PortletRequest.ACTION_PHASE);
try {
redirectURL.setPortletMode(actionRequest.getPortletMode());
redirectURL.setWindowState(actionRequest.getWindowState());
} catch (PortletModeException e) {
_log.error(e);
} catch (WindowStateException e) {
_log.error(e);
}
return redirectURL;
} public static PortletURL getPortletURLInLayout(ActionRequest actionRequest) {
String portletId = PortalUtil.getPortletId(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest
.getAttribute(WebKeys.THEME_DISPLAY);
Layout layout = themeDisplay.getLayout();
long plid = layout.getPlid(); PortletURL redirectURL = PortletURLFactoryUtil.create(
PortalUtil.getHttpServletRequest(actionRequest), portletId,
plid, PortletRequest.ACTION_PHASE);
try {
redirectURL.setPortletMode(actionRequest.getPortletMode());
redirectURL.setWindowState(actionRequest.getWindowState());
} catch (PortletModeException e) {
_log.error(e);
} catch (WindowStateException e) {
_log.error(e);
} _log.debug("redirectURL : " + redirectURL.toString());
return redirectURL;
} public static String getObjDetailURL(PortletRequest portletRequest,
String portletId, long entityId) throws SystemException,
PortalException {
long groupId = PortalUtil.getScopeGroupId(portletRequest);
int lifeCycle = 1;
String windowState = WindowState.NORMAL.toString();
String portletMode = PortletMode.VIEW.toString();
String detailURL = PortletURLUtil.getPortletURLByGroupId(
portletRequest, groupId, portletId, lifeCycle, windowState,
portletMode);
if (portletId.equals(PortletIDs.CUSTOMER_DETAIL)) {
detailURL = detailURL + "&customerId=" + entityId;
} else if (portletId.equals(PortletIDs.CONTACT_DETAIL)) {
detailURL = detailURL + "&contactId=" + entityId;
} else if (portletId.equals(PortletIDs.MARKET_DETAIL)) {
detailURL = detailURL + "&marketId=" + entityId;
} else if (portletId.equals(PortletIDs.CLUE_DETAIL)) {
detailURL = detailURL + "&clueId=" + entityId;
} else if (portletId.equals(PortletIDs.OPPORTUNITY_DETAIL)) {
detailURL = detailURL + "&opportunityId=" + entityId;
} else if (portletId.equals(PortletIDs.QUOTATION_DETAIL)) {
detailURL = detailURL + "&quotationId=" + entityId;
} else if (portletId.equals(PortletIDs.CONTRACT_DETAIL)) {
detailURL = detailURL + "&contractId=" + entityId;
} else if (portletId.equals(PortletIDs.ACTIVITY_DETAIL)) {
detailURL = detailURL + "&activityId=" + entityId;
} else if (portletId.equals(PortletIDs.PRODUCT)) {
detailURL = detailURL + "&productIds" + entityId;
} else if (portletId.equals(PortletIDs.ORDER_DETAIL)) {
detailURL = detailURL + "&orderId=" + entityId;
}
detailURL = detailURL + "&operation=load";
return detailURL;
} @SuppressWarnings("unused")
private static String processValue(Key key, String value) {
if (key == null) {
return HttpUtil.encodeURL(value);
} else {
try {
return HttpUtil.encodeURL(Encryptor.encrypt(key, value));
} catch (EncryptorException ee) {
return value;
}
}
} public static String getReturnUrl(ActionRequest actionRequest, String portletId, String layoutId)
throws PortalException, SystemException {
long groupId = PortalUtil.getScopeGroupId(actionRequest);
int lifeCycle = 0;
String portletMode = PortletMode.VIEW.toString();
String windowState = WindowState.NORMAL.toString();
String url = getPortletURLByGroupId(actionRequest, groupId, portletId, lifeCycle, windowState, portletMode);
StringBuffer sb = new StringBuffer(url);
sb.append("&layoutId=").append(layoutId)
.append("&fileLarge=fileLarge");
return sb.toString();
} }

  

CRM项目总结-封装PortletURLUtil的更多相关文章

  1. crm项目整理

    crm项目整理   一.开发背景 由于公司人员的增多,原来通过excel表格存取方式过于繁琐,而且对于公司人员的调配和绩效考核等不能做到精确处理,所以开发crm系统,开始开发只是针对销售人员和客户,后 ...

  2. crm项目整理概要

    一.开发背景 由于公司人员的增多,原来通过excel表格存取方式过于繁琐,而且对于公司人员的调配和绩效考核等不能做到精确处理,所以开发crm系统,开始开发只是针对销售人员和客户,后面陆续加上一些操作, ...

  3. crm项目-stark组件分析

    ###############    stark组件     ################ """ 这个stark组件是非常神奇的 1,独立的一个组件 2,没有mod ...

  4. 某CRM项目招投标工作的感悟

    最近参与了某公司的CRM项目招标工作, 由于此项目涉及到的二级单位比较多,以及项目金额比较大,所以此招标工作从准备到宣布中标一直持续了大概3个月时间,中间过程发生了一些颇有意思的事情,因为保密的原因无 ...

  5. CRM项目总结

                CRM项目总结      一:开发背景 在公司日益扩大的过程中,不可避免的会伴随着更多问题出现. 对外 : 如何更好的管理客户与公司的关系?如何更及时的了解客户日益发展的需求变 ...

  6. CRM项目之RBAC权限组件-day26

    写在前面 上课第26天,打卡: 世间安得双全法 不负如来不负卿 s17day26 CRM项目 项目概要:XX公司CRM - 权限管理,公共组件,app ***** - 熟悉增删改查,Low *** - ...

  7. 读《31天学会CRM项目开发》记录2 - 企业信息管理系统

    在信息技术的快速推动下,企业如果依然利用传统的管理方式,以人为主,那效率便会大打折扣.在此背景下,企业信息化系统得 到了高速发展.如我们常见的ERP系统.MES系统,都是提高公司运行效率,降低运营以及 ...

  8. 读《31天学会CRM项目开发》记录1 - 认识软件开发

    今天闲来无事,心中又对软件开发充满了向往和憧憬.一直认为实践是检验真知的唯一标准,也是快速提升的绝密方法,是巩固基础加深基础的好去处.故在JD上搜了下软件开发,看到了这本<31天学会CRM项目开 ...

  9. Linux下运行crm项目

    虚拟环境运行crm项目 1.进入虚拟环境 2.解决crm项目运行所需的依赖环境 1.手动解决 pip3 install django==1.11.14 pip3 install pymysql pip ...

随机推荐

  1. sencha touch 分享到微博扩展

    扩展代码: /* *分享到微博 */ Ext.define('ux.WeiboPicker', { extend: 'Ext.Picker', xtype: 'weiboPicker', config ...

  2. [原]Linux下清空文件内容的三种方法

    ========问题======== 有些文件需要清空内容而不改变属性 =======解决方案====== 1.直接删除,创建同名文件.(这种方法的弊端是有可能这个文件带着权限或者是属性,那么你新建这 ...

  3. 【JVM译文】JVM问题定位前的准备工作有哪些

    一.序 最近在学习jvm工具时,不少链接直指oracle官网.才发现有不少好东西. 本文翻译自: https://docs.oracle.com/javase/8/docs/technotes/gui ...

  4. Django配合MySQL学习Django模型外键的建立和使用

    Django 模型建立外键 在模型中建立外键是很简单的,基本操作如下 class Table(models.Model) column_name = models.ForeignKey(other-T ...

  5. 源码包安装Python3.6

    1,安装Python3.6的依赖包 # yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel r ...

  6. python编码问题总结

    最近利用python抓取一些网上的数据,遇到了编码的问题.非常头痛,总结一下用到的解决方案. linux中vim下查看文件编码的命令 set fileencoding python中一个强力的编码检测 ...

  7. PHPStorm 注册码&主题皮肤

    JetBrains PhpStorm 注册方法: 用浏览器打开 http://idea.lanyus.com/ 点击页面中的“获得注册码” 然后打开PhpStorm,在注册时切换至Activation ...

  8. iOS - 长按图片识别图中二维码

    长按图片识别图中二维码: // 长按图片识别二维码 UILongPressGestureRecognizer *QrCodeTap = [[UILongPressGestureRecognizer a ...

  9. codeforces 779D - String Game

    time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standa ...

  10. codeforces 892 - A/B/C

    题目链接:https://cn.vjudge.net/problem/CodeForces-892A Jafar has n cans of cola. Each can is described b ...