📄 commonevents.java
字号:
/*
* $Id: CommonEvents.java,v 1.2 2003/09/26 17:06:17 jonesde Exp $
*
* Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package org.ofbiz.common;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilCache;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.security.Security;
/**
* Common Services
*
* @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
* @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
* @version $Revision: 1.2 $
* @since 2.1
*/
public class CommonEvents {
public static final String module = CommonEvents.class.getName();
public static UtilCache appletSessions = new UtilCache("AppletSessions", 0, 600000, true);
public static String checkAppletRequest(HttpServletRequest request, HttpServletResponse response) {
GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
String sessionId = request.getParameter("sessionId");
String visitId = request.getParameter("visitId");
sessionId = sessionId.trim();
visitId = visitId.trim();
String responseString = "";
GenericValue visit = null;
try {
visit = delegator.findByPrimaryKey("Visit", UtilMisc.toMap("visitId", visitId));
} catch (GenericEntityException e) {
Debug.logError(e, "Cannot Visit Object", module);
}
if (visit != null && visit.getString("sessionId").equals(sessionId) && appletSessions.containsKey(sessionId)) {
Map sessionMap = (Map) appletSessions.get(sessionId);
if (sessionMap != null && sessionMap.containsKey("followPage"))
responseString = (String) sessionMap.remove("followPage");
}
try {
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
out.println(responseString);
out.close();
} catch (IOException e) {
Debug.logError(e, "Problems writing servlet output!", module);
}
return "success";
}
public static String receiveAppletRequest(HttpServletRequest request, HttpServletResponse response) {
GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
String sessionId = request.getParameter("sessionId");
String visitId = request.getParameter("visitId");
sessionId = sessionId.trim();
visitId = visitId.trim();
String responseString = "ERROR";
GenericValue visit = null;
try {
visit = delegator.findByPrimaryKey("Visit", UtilMisc.toMap("visitId", visitId));
} catch (GenericEntityException e) {
Debug.logError(e, "Cannot Visit Object", module);
}
if (visit.getString("sessionId").equals(sessionId)) {
String currentPage = (String) request.getParameter("currentPage");
if (appletSessions.containsKey(sessionId)) {
Map sessionMap = (Map) appletSessions.get(sessionId);
String followers = (String) sessionMap.get("followers");
List folList = StringUtil.split(followers, ",");
Iterator i = folList.iterator();
while (i.hasNext()) {
String follower = (String) i.next();
Map folSesMap = UtilMisc.toMap("followPage", currentPage);
appletSessions.put(follower, folSesMap);
}
}
responseString = "OK";
}
try {
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
out.println(responseString);
out.close();
} catch (IOException e) {
Debug.logError(e, "Problems writing servlet output!", module);
}
return "success";
}
public static String setAppletFollower(HttpServletRequest request, HttpServletResponse response) {
Security security = (Security) request.getAttribute("security");
GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
String visitId = request.getParameter("visitId");
if (visitId != null) request.setAttribute("visitId", visitId);
if (security.hasPermission("SEND_CONTROL_APPLET", userLogin)) {
String followerSessionId = request.getParameter("followerSid");
String followSessionId = request.getParameter("followSid");
Map follow = (Map) appletSessions.get(followSessionId);
if (follow == null) follow = new HashMap();
String followerListStr = (String) follow.get("followers");
if (followerListStr == null) {
followerListStr = followerSessionId;
} else {
followerListStr = followerListStr + "," + followerSessionId;
}
appletSessions.put(followSessionId, follow);
appletSessions.put(followerSessionId, null);
}
return "success";
}
public static String setFollowerPage(HttpServletRequest request, HttpServletResponse response) {
Security security = (Security) request.getAttribute("security");
GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
String visitId = request.getParameter("visitId");
if (visitId != null) request.setAttribute("visitId", visitId);
if (security.hasPermission("SEND_CONTROL_APPLET", userLogin)) {
String followerSessionId = request.getParameter("followerSid");
String pageUrl = request.getParameter("pageUrl");
Map follow = (Map) appletSessions.get(followerSessionId);
if (follow == null) follow = new HashMap();
follow.put("followPage", pageUrl);
appletSessions.put(followerSessionId, follow);
}
return "success";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -