![]() | ![]() | ![]() | ![]() | ![]() |
This sample shows a JSP VisualDataExplorer connecting to data via a Foundation Services connection. It shows how to override the show detail action in order to display another jsp page with information about the cell clicked.
The VisualDataExplorer is a TransformationBeanTM that generates the appropriate HTML 4.0 and JavaScript for viewing either relational or OLAP InformationMaps. The VisualDataExplorer can display the information map data by using tables and graphs.
Here are the steps for creating a simple VisualDataExplorer:
The sample is based on the Information Map Viewer Servlet (Uses SAS Visual Data Explorer) template, which is available in SAS® AppDev Studio. The Full Code tab of this sample contains instructions for modifying the template project.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Tip: For help with building a Web application project and testing a Web application, see SAS Note 32218.
<%
java.util.Enumeration params = request.getParameterNames();
String paramName = "";
while (params.hasMoreElements())
{
paramName = (String)params.nextElement();
out.println(paramName + " = ");
out.println((String)request.getParameter(paramName));
out.println("<br>");
}
%>
|
<%@ taglib uri="http://www.sas.com/taglib/sas" prefix="sas" %>
<%@page import="com.sas.servlet.tbeans.dataexplorer.html.VisualDataExplorer"%>
<%@ page pageEncoding="UTF-8"%>
<html>
<head>
<link href="styles/sasComponents.css" rel="STYLESHEET" type="text/css">
</head>
<body style="margin: 0px;">
<%
VisualDataExplorer vde = (VisualDataExplorer)session.getAttribute("vde");
if( null == vde ){
throw new RuntimeException( "The Visual Data Explorer does not exist on the session. " +
"Be sure that you executed the servlet, and not the jsp directly " );
}
vde.setRequest(request);
vde.setResponse(response);
vde.write(out);
%>
</body>
</html>
|
private static final String MAP_NAME = "SBIP://Foundation/BIP Tree/ReportStudio/Maps/OrionStar Map";
package servlets;
public class InfoMapViewerExampleControllerServlet ...sas_actionProvider.setControllerURL(request.getContextPath()+ "/InfoMapViewerExample");
package servlets;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import listeners.ExamplesSessionBindingListener;
import olap.MetaDataCellStrategy;
import com.sas.actionprovider.ActionOrderList;
import com.sas.actionprovider.HttpAction;
import com.sas.actionprovider.HttpActionProvider;
import com.sas.actionprovider.strategies.ActionStrategyInterface;
import com.sas.dataexplorer.actionprovider.support.olaptableview.HttpOLAPTableViewSupport;
import com.sas.services.discovery.DiscoveryService;
import com.sas.services.discovery.DiscoveryServiceInterface;
import com.sas.services.discovery.ServiceTemplate;
import com.sas.services.session.SessionContextInterface;
import com.sas.services.session.SessionServiceInterface;
import com.sas.services.user.UserContextInterface;
import com.sas.services.user.UserServiceInterface;
import com.sas.servlet.tbeans.dataexplorer.html.DataViewer;
import com.sas.servlet.tbeans.dataexplorer.html.VisualDataExplorer;
import com.sas.servlet.tbeans.olaptableview.html.OLAPTableView;
import com.sas.servlet.tbeans.olaptableview.html.OLAPTableViewComposite;
import com.sas.servlet.util.BaseUtil;
import com.sas.web.keys.ComponentKeys;
public class InfoMapViewerExampleControllerServlet extends
javax.servlet.http.HttpServlet {
// Declare a default version ID since parent class implements
// java.io.Serializable
private static final long serialVersionUID = 1L;
private static final String ACTION_PROVIDER = "sas_actionProvider_InfoMapViewerExample";
private static final String VISUAL_DATA_EXPLORER = "vde";
// Edit this path to point to an information map
private static final String MAP_NAME = "SBIP://Foundation/BIP Tree/ReportStudio/Maps/OrionStar Map";
/*
* doPost() Respond to the Post message.
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Note: Calling doGet to provide same behavior to POST and GET HTTP
// methods.
doGet(request, response);
}
/*
* doGet() Respond to the Get message.
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Note: Add User DO_GET code here
HttpSession session = request.getSession();
// Ensure character set is specified before calling
// response.getWriter().
String charset = BaseUtil.getOutputCharacterEncoding(request);
response.setContentType("text/html; charset=" + charset);
// Setup the ActionProvider
HttpActionProvider sas_actionProvider = null;
synchronized (session) {
if (session != null) {
sas_actionProvider = (HttpActionProvider) session
.getAttribute(ACTION_PROVIDER);
}
// if ActionProvider is null, create one and put it on the session
if (sas_actionProvider == null) {
sas_actionProvider = new HttpActionProvider();
sas_actionProvider.setLocale(request.getLocale());
sas_actionProvider.setControllerURL(request.getContextPath()
+ "/InfoMapViewerExample");
sas_actionProvider.setName(ACTION_PROVIDER);
// store object in its scope
if (session != null)
session.setAttribute(ACTION_PROVIDER, sas_actionProvider);
}
// else execute the ActionProvider command
else {
sas_actionProvider.executeCommand(request, response, response
.getWriter());
}
}
synchronized (session) {
// Setup the InformationServicesSelector
VisualDataExplorer vde = null;
if (session != null) {
vde = (VisualDataExplorer) session
.getAttribute(VISUAL_DATA_EXPLORER);
}
if (vde == null) {
try {
// Obtain the local discovery service
DiscoveryServiceInterface discoveryService = DiscoveryService
.defaultInstance();
// Use the discovery services to find a user service.
UserServiceInterface userService = (UserServiceInterface) discoveryService
.findService(new ServiceTemplate(
new Class[] { UserServiceInterface.class }));
// Get a user context from the user service by logging in.
// The initial parameters are obtained from the web.xml
// file.
// Note: A password must be set in the web.xml file.
ServletConfig sc = getServletConfig();
String domain = sc.getInitParameter("metadata-domain");
String username = sc.getInitParameter("metadata-userid");
String password = sc.getInitParameter("metadata-password");
UserContextInterface userContext = userService.newUser(
username, password, domain);
if (session != null) {
ExamplesSessionBindingListener.getInstance(session)
.addUserContext(userContext);
}
// Use the discovery services to find a session service.
SessionServiceInterface sessionService = (SessionServiceInterface) discoveryService
.findService(new ServiceTemplate(
new Class[] { SessionServiceInterface.class }));
// Create a session for this user and bind it to the user
// context.
SessionContextInterface sessionContext = sessionService
.newSessionContext(userContext);
userContext.setSessionContext(sessionContext);
if (session != null) {
ExamplesSessionBindingListener.getInstance(session)
.addSessionContext(sessionContext,
"InfoMapViewerExample_lock");
}
// Create the Visual Data Explorer, and add it to the
// session
// Change the value of the MAP_NAME constant to instantiate
// the Visual Data Explorer
// With data
vde = new VisualDataExplorer(sessionContext, MAP_NAME);
vde.setActionProvider(sas_actionProvider);
vde.setId(VISUAL_DATA_EXPLORER);
DataViewer dv = (DataViewer) vde
.getComponent(VisualDataExplorer.VISUALDATAEXPLORER_DATAVIEWER);
OLAPTableViewComposite otvc = (OLAPTableViewComposite) dv
.getTable();
// need to set the model here for the table data to be
// returned below
otvc.setModel(dv.getOLAPBusinessQueryAdapter());
OLAPTableView otv = (OLAPTableView) otvc
.getComponent(OLAPTableViewComposite.OLAPTABLEVIEW_TABLEDATA);
HttpAction tupleAction = new HttpAction();
tupleAction.setExternal(true);
tupleAction.setActionType("TUPLE_ACTION");
tupleAction.setURLBase("tuple.jsp");
ActionStrategyInterface asi = new MetaDataCellStrategy();
tupleAction.setActionStrategy(asi);
asi.initializeAction(tupleAction,
HttpOLAPTableViewSupport.DATA_CELL_AREA, null);
com.sas.actionprovider.Area dataCellArea = new com.sas.actionprovider.Area(
HttpOLAPTableViewSupport.DATA_CELL_AREA);
java.util.Vector vector = new java.util.Vector();
vector.add(otv);
vde.getActionProvider().setAction(tupleAction, vector,
dataCellArea);
ActionOrderList newAOL = new ActionOrderList();
newAOL.add("TUPLE_ACTION");
vde.getActionProvider().setActionOrderList(
"VDE_OLAP_TABLEVIEW_SUPPORT", newAOL, null,
HttpOLAPTableViewSupport.DATA_CELL_AREA);
if (session != null) {
session.setAttribute(VISUAL_DATA_EXPLORER, vde);
}
} catch (Exception e) {
throw new ServletException(e);
}
}
}
// Forward the request to the JSP for display
String sas_forwardLocation = request
.getParameter(ComponentKeys.FORWARD_LOCATION);
if (sas_forwardLocation == null) {
sas_forwardLocation = "/InfoMapViewerExampleViewer.jsp";
}
RequestDispatcher rd = getServletContext().getRequestDispatcher(
sas_forwardLocation);
rd.forward(request, response);
}
}
|
package olap;
import java.util.Locale;
import com.sas.actionprovider.ActionSupportFilter;
import com.sas.actionprovider.BaseAction;
import com.sas.actionprovider.strategies.olap.BaseOLAPStrategy;
import com.sas.actionprovider.util.olap.HttpOLAPActionUtil;
import com.sas.actionprovider.util.olap.OLAPActionUtil;
import com.sas.actionprovider.util.olap.OLAPDynamicValueKeys;
import com.sas.servlet.tbeans.tableview.TableViewActionSupportFilter;
import com.sas.storage.olap.OLAPException;
import com.sas.storage.olap.TupleElementInterface;
import com.sas.storage.olap.TupleInterface;
import com.sas.swing.util.Action;
/**
*
*/
public class MetaDataCellStrategy extends BaseOLAPStrategy {
public static final String DATA_VALUE = OLAPDynamicValueKeys.DATA_VALUE;
public static final String ROW_TUPLES = OLAPDynamicValueKeys.ROW_TUPLES;
public static final String COLUMN_TUPLES = OLAPDynamicValueKeys.COLUMN_TUPLES;
private static OLAPActionUtil defaultUtil;
static {
defaultUtil = new HttpOLAPActionUtil();
}
/**
* Default constructor. Calls the other constructor for specifying strategy
* type.
*/
public MetaDataCellStrategy() {
this(false, defaultUtil);
}
/**
* Constructor for specifying type ( swing/http ) of strategy object.
*
* @param swing
* boolean indicating whether the strategy will be used in a
* swing environment. If false, the strategy is http type.
*/
public MetaDataCellStrategy(boolean swing, OLAPActionUtil util) {
super(swing, util);
}
protected void initializeActionAttributes(BaseAction action,
String areaType, Locale locale) {
super.initializeActionAttributes(action, areaType, locale);
action.putValue(DATA_VALUE, null);
action.putValue(Action.NAME, null);
return;
}
public void setActionAttributes(BaseAction action,
ActionSupportFilter filter) {
super.setActionAttributes(action, filter);
if (!(filter instanceof TableViewActionSupportFilter)) {
return;
}
// Apply attributes representing row metadata
TupleInterface[] rowTuples = (TupleInterface[]) filter
.getAttribute(ROW_TUPLES);
int tupleIndex = ((TableViewActionSupportFilter) filter).getRow();
String[][] rowAttributes = getMetaDataAttributes(rowTuples[tupleIndex]);
for (int i = 0; i < rowAttributes.length; i++) {
String metaDataAttributeName = rowAttributes[i][0];
// metaDataAttributeName will be null for datacells in a 'totals'
// row.
if (metaDataAttributeName != null)
action.putValue(metaDataAttributeName, rowAttributes[i][1]);
// action.putValue( rowAttributes[i][0], rowAttributes[i][1] );
}
// Apply attributes representing column metadata
TupleInterface[] columnTuples = (TupleInterface[]) filter
.getAttribute(COLUMN_TUPLES);
tupleIndex = ((TableViewActionSupportFilter) filter).getColumn();
String[][] columnAttributes = getMetaDataAttributes(columnTuples[tupleIndex]);
for (int i = 0; i < columnAttributes.length; i++) {
String metaDataAttributeName = columnAttributes[i][0];
// metaDataAttributeName will be null for datacells in a 'totals'
// column.
if (metaDataAttributeName != null)
action.putValue(metaDataAttributeName, columnAttributes[i][1]);
// action.putValue( columnAttributes[i][0], columnAttributes[i][1]
// );
}
}
private String[][] getMetaDataAttributes(TupleInterface tuple) {
TupleElementInterface[] tupleElements = null;
try {
tupleElements = tuple.getElements(0, -1);
} catch (OLAPException oe) {
}
if (tupleElements == null) {
return null;
}
String[][] attrs = new String[tupleElements.length][2];
for (int i = 0; i < tupleElements.length; i++) {
try {
attrs[i][0] = getCategoryName(tupleElements[i]);
attrs[i][1] = tupleElements[i].getLabel();
} catch (OLAPException oe) {
oe.printStackTrace();
}
}
return attrs;
}
private static String getCategoryName(TupleElementInterface tupleElement) {
try {
String uniqueLevelName = tupleElement.getUniqueLevelName();
String[] uniqueLevelNames = tupleElement.getTuple().getAxis()
.getUniqueLevelNames();
int position = -1;
for (int i = 0; i < uniqueLevelNames.length; i++) {
if (uniqueLevelName != null
&& uniqueLevelName.equals(uniqueLevelNames[i])) {
position = i;
break;
}
}
if (position >= 0)
return tupleElement.getTuple().getAxis().getAxisHeaders()[position];
} catch (OLAPException oe) {
oe.printStackTrace();
}
return null;
}
protected void initialize() {
super.initialize();
addDynamicValueInfo(DATA_VALUE, null, null);
addDynamicValueInfo(Action.NAME, null, DATA_VALUE);
}
public int getActionStatus(BaseAction action, ActionSupportFilter filter) {
return ENABLED;
}
}
|
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.


| Type: | Sample |
| Date Modified: | 2008-07-10 11:33:07 |
| Date Created: | 2006-02-22 14:28:37 |
| Product Family | Product | Host | Product Release | SAS Release | ||
| Starting | Ending | Starting | Ending | |||
| SAS System | SAS AppDev Studio | Microsoft Windows XP Professional | 3.2 | 9.1 TS1M3 SP4 | ||
| Microsoft Windows Server 2003 Standard Edition | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows Server 2003 Enterprise Edition | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft® Windows® for x64 | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows 2000 Datacenter Server | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows 2000 Server | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows 2000 Advanced Server | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows NT Workstation | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows 2000 Professional | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows Server 2003 Datacenter Edition | 3.2 | 9.1 TS1M3 SP4 | ||||
| Windows Vista | 3.2 | 9.1 TS1M3 SP4 | ||||




