Contents Implementation & Administration Guide 1.1 Previous Next

Application Sample 3: Obtain a SAS® Workspace

A Java Server Page (JSP) called AppSample3.jsp is shown below. This JSP is shipped with the SAS Information Delivery Portal, and it can be found in the jsp\html\samples directory in the portal Web application.

The application shows how to use the Workspace Factory to obtain an IOM workspace on a SAS server. For a complete desscription of the workspace factory, refer to Using the Java Workspace Factory on the SAS Integration Technologies Web site.

 
<!-- Copyright (c) 2000 by SAS Institute Inc., Cary, NC 27513 -->
<%@ page
  language="java"
  import="com.sas.edir.Debug,
          com.sas.edir.EnterpriseDirectory,
          com.sas.edir.PortalPool,
          com.sas.edir.TrackedObject,
          com.sas.edir.WorkspaceFactoryManager,
          com.sas.edir.util.StringOp,
          com.sas.edir.webapp.Application,
          com.sas.edir.webapp.portal.PortalEnterpriseDirectory,
          com.sas.edir.webapp.portal.LogicBean,
          com.sas.edir.webapp.portal.ModelId,
          com.sas.edir.webapp.portal.RequestId,
          com.sas.edir.webapp.portal.samples.RB,
          com.sas.iom.SAS.IWorkspace,
          com.sas.iom.WorkspaceConnector,
          java.util.Hashtable,
          java.util.Locale,
          java.util.Map,
          java.util.Properties"
  errorPage="PortalError.jsp"
%>
The following code uses logicBean convenience methods to process the request that has been passed from the portal session. These methods use the information in the request to locate the portal user's enterprise directory and the requested application.
<%
LogicBean logicBean = new LogicBean();
PortalEnterpriseDirectory edir = logicBean.getEnterpriseDirectory(request);
Application app = logicBean.getApplication(request);
The following code checks for the existence of the EnterpriseDirectory and Application objects. If they exist, this means the user has accessed the application from within the portal.
// authorization check
if ((edir != null) && (app != null))
{
If the user is found to be authorized, the following code uses logicBean convenience methods to obtain the active locale setting and the names of currently active style sheets. It also obtains the application's name attribute from the enterprise directory, and it obtains the application's title text from the samples resource bundle.
    Locale locale = logicBean.getLocale(request);
    Map model = logicBean.getModel(request);
    String sasStyleSheet = logicBean.getSASStyleSheet(request);
    String styleSheet = logicBean.getStyleSheet(request);
    String name = app.getName();
    String title = RB.getString(locale,"appsample3.title.txt");
The following code uses a logicBean convenience method to obtain application parameters from the portal session. In this case, the parameter is a logical name, which the portal uses to identify the specific SAS server on which a workspace is to be obtained.
    // check for application parameters which may get passed in as a request
    // parameter or attribute
    String logicalName = logicBean.getValueFromRequest("com.sas.portal.AppSample3.LogicalName", request);
The following code uses the PortalTitle.jsp file to display the title at the top of the page. The appropriate style sheets and the application's title text are incorporated into the page.
    // display the title using PortalTitle.jsp
    request.setAttribute(RequestId.PortalTitle, title);
    request.setAttribute(RequestId.PortalTitleFragment, "true");

%>
<HTML>
  <HEAD>
    <TITLE><%= title %></TITLE>
    <LINK rel=stylesheet href="<%= sasStyleSheet %>" type="text/css">
    <LINK rel=stylesheet href="<%= styleSheet %>" type="text/css">
  </HEAD>
  <BODY>
  <jsp:include page="/jsp/html/portal/PortalTitle.jsp" flush="true" />
<%

The following code uses the workspace factory to connect to the SAS server and obtain a workspace on the server.
    // use the logical name passed in to determine where to create a workspace
    if (!StringOp.isEmpty(logicalName))
    {
        WorkspaceFactoryManager workspaceManager = (WorkspaceFactoryManager)model.get(ModelId.PortalWorkspaceFactoryManager);
        WorkspaceConnector connector = workspaceManager.getWorkspaceConnector(edir, logicalName);
        IWorkspace workspace = connector.getWorkspace();

        // This is where you use the workspace
        Object[] xArgs = new Object[2];
        xArgs[0] = workspace;
        xArgs[1] = logicalName;
The following code writes a message to the output page if the workspace operation was successful. The message text is obtained from the samples resource bundle.
		
%>
    <p><%= RB.formatString(locale, "appsample3.message.txt", xArgs) %>
The following code returns the workspace to the factory so that the object can be closed and the supporting connection can be either reused or canceled.
		
<%
        // cleanup
        try
        {
            workspace.Close();
        }
        catch (Exception ex)
        {
            // not a whole lot we can do
        }

        try
        {
            connector.close();
        }
        catch (Exception ex)
        {
            // not a whole lot we can do
        }
    }
}
else
{
The following code writes an error message if the authorization test failed. The message text is obtained from the samples resource bundle.
    // user is not authorized to view this content
%>
<HTML>
  <HEAD>
  </HEAD>
  <BODY>
<p align=center><%= RB.getString(logicBean.getLocale(request), "content.notauthorized.txt") %>
<%
}
%>
  </BODY>
</HTML>


Contents Implementation & Administration Guide 1.1 Previous Next