📄 graphicorgchartaction.java
字号:
/*
* OPIAM Suite
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package opiam.admin.applis.demo.actions;
import opiam.admin.applis.demo.beans.Person;
import opiam.admin.faare.persistence.LdapObjectFilter;
import opiam.admin.faare.persistence.javabeans.JBTop;
import opiam.admin.faare.service.UserContext;
import opiam.admin.faare.service.services.StandardService;
import opiam.admin.faare.service.services.views.ViewGenerator;
import opiam.admin.faare.service.services.views.orgchart.OrgChartPanel;
import opiam.admin.faare.struts.actions.SecureAction;
import opiam.admin.faare.struts.utils.SessionContext;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
/**
* This class allows to generate a graphic orgchart.
*/
public class GraphicOrgChartAction extends SecureAction
{
/** Instance of the log4j logger.
* Used to generate the execution traces. */
private static Logger _logger =
Logger.getLogger(GraphicOrgChartAction.class.getName());
/**
* This method is called to execute the action.
*
* @param mapping Struts mapping data.
* @param actionForm FormBean associated with the action.
* @param request HTTP request.
* @param httpServletResponse HTTP response.
*
* @return An ActionForward.
*
* @throws IOException An I/O exception if failed or interrupted I/O operations occurs.
* @throws ServletException A ServletException if the servlet has a problem.
*/
public ActionForward secureExecute(ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse httpServletResponse
) throws IOException, ServletException
{
SessionContext sessionContext = null;
UserContext userContext = null;
ActionMessages msgErrors = new ActionMessages();
try
{
// Gets the session.
HttpSession session = request.getSession();
// Gets the session context.
sessionContext = SessionContext.getInstance(session);
// Gets the user context.
userContext = sessionContext.getUserContext();
String type = (String) request.getParameter("type");
String viewName = (String) request.getParameter("viewName");
String levelStr = (String) request.getParameter("levelStr");
int level = Integer.parseInt(levelStr);
String direction = (String) request.getParameter("direction");
String mode = (String) request.getParameter("mode");
String dn = (String) request.getParameter("dn");
JBTop loadedObj = StandardService.load(dn, userContext);
// Converts the entry in Person entry.
Person person = (Person) loadedObj;
userContext.getParameters().put(LdapObjectFilter.VAR_CURRENT_ITEM,
person
);
_logger.debug("current_item = " + person.getDn());
List lresult =
ViewGenerator.generateOrgChartAsJpgOrPng(person, viewName,
level, direction,
mode, userContext, type
);
session.setAttribute("IMG", lresult.get(0));
Iterator iter = ((List) lresult.get(1)).iterator();
StringBuffer map = new StringBuffer("<map name='orgchart'>");
while (iter.hasNext())
{
Hashtable info = (Hashtable) iter.next();
int x1 = ((Integer) info.get(OrgChartPanel.XCOORD)).intValue();
int y1 = ((Integer) info.get(OrgChartPanel.YCOORD)).intValue();
int w = ((Integer) info.get(OrgChartPanel.WIDTH)).intValue();
int h = ((Integer) info.get(OrgChartPanel.HEIGHT)).intValue();
int x2 = x1 + w;
int y2 = y1 + h;
map.append("<area shape='rect' coords='" + x1 + "," + y1 + "," +
x2 + "," + y2 + "'href='" +
"showPerson.do?dn=" + info.get(OrgChartPanel.DN) +
"'>"
);
}
map.append("</map>");
session.setAttribute("orgmap", map.toString());
_logger.debug("orgmap");
// puts the parameters in the request to enable to create a pdf orgchart.
request.setAttribute("viewName", viewName);
request.setAttribute("levelStr", levelStr);
request.setAttribute("direction", direction);
request.setAttribute("mode", mode);
request.setAttribute("dn", dn);
return (mapping.findForward("success"));
}
catch (Exception se)
{
_logger.error(se.getMessage());
msgErrors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("error.service.unknown")
);
saveErrors(request, msgErrors);
return (mapping.findForward("service_error"));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -