![]() | ![]() | ![]() | ![]() | ![]() |
This sample shows a JSP VisualDataExplorer connecting to data via a SAS® Foundation Services connection, and it shows how to programmatically create a calculated measure by using the VisualDataExplorer.
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 in 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.
<%@ 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";
private static final String EXPRESSION_STRING = "<<root.your_first_measure>> + <<root.your_second_measure>>";
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 com.sas.actionprovider.HttpActionProvider;
import com.sas.iquery.metadata.business.BusinessModel;
import com.sas.iquery.metadata.business.BusinessQuery;
import com.sas.iquery.metadata.business.DataItem;
import com.sas.iquery.metadata.business.DataItemReference;
import com.sas.iquery.metadata.business.Role;
import com.sas.iquery.metadata.expr.ExpressionInterface;
import com.sas.iquery.metadata.expr.ExpressionTypes;
import com.sas.iquery.metadata.expr.ResourceScope;
import com.sas.iquery.metadata.expr.StringExpressionUtil;
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.VisualDataExplorer;
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";
private static final String EXPRESSION_STRING = "<<root.your_first_measure>> + <<root.your_second_measure>>";
/*
* 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);
BusinessQuery data = (BusinessQuery) vde.getDataModel();
BusinessModel busModel = data.getBusinessModel();
DataItemReference dataItemRef;
ExpressionInterface expr = StringExpressionUtil
.getInstance().newExpression(busModel,
EXPRESSION_STRING,
ExpressionTypes.EXP_TYPE_NUMERIC,
ResourceScope.BUSINESS_SCOPE);
DataItem newMeasure = busModel.newDataItem();
newMeasure.setExpression(expr);
newMeasure.setLabel("MyTestMeasure");
busModel.addBusinessItem((DataItem) newMeasure);
dataItemRef = busModel
.newDataItemReference((DataItem) newMeasure);
busModel.addBusinessItem(dataItemRef);
data.addResultItem((DataItem) dataItemRef, Role.COLUMN);
vde.setActionProvider(sas_actionProvider);
vde.setId(VISUAL_DATA_EXPLORER);
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);
}
}
|
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.
The new calculated measure, MyTestMeasure, appears on the columns.

| Type: | Sample |
| Date Modified: | 2008-07-29 10:17:38 |
| Date Created: | 2006-04-20 15:56:24 |
| 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 Server 2003 Datacenter Edition | 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 2000 Server | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows 2000 Datacenter Server | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows 2000 Advanced Server | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft® Windows® for x64 | 3.2 | 9.1 TS1M3 SP4 | ||||
| Windows Vista | 3.2 | 9.1 TS1M3 SP4 | ||||




