Application Sample 2: Locate an Entity
A Java Server Page (JSP) called AppSample2.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 Enterprise Directory classes to list content entities that match specific filtering criteria.
<!-- Copyright (c) 2000 by SAS Institute Inc., Cary, NC 27513 -->
<%@ page
language="java"
import="com.sas.edir.Debug,
com.sas.edir.FilteredEntityCollection,
com.sas.edir.TrackedObject,
com.sas.edir.util.StringOp,
com.sas.edir.webapp.Application,
com.sas.edir.webapp.ContentDocument,
com.sas.edir.webapp.ContentDocumentFilter,
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,
java.util.Iterator,
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))
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);
String sasStyleSheet = logicBean.getSASStyleSheet(request);
String styleSheet = logicBean.getStyleSheet(request);
String name = app.getName();
String title = RB.getString(locale,"appsample2.title.txt");
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 searches the enterprise directory to find portal content items which are documents and which have names beginning with the characters "Demo Document." |
//
// locate all the documents by creating a filtered collection
//
// the EnterpriseDirectory is a factory that uses reflection to create objects
// by looking up the object implementation in PortalRegistry.properties
String filterMapping = edir.CLASS_MAPPING + "com.sas.edir.webapp.ContentDocumentFilter";
ContentDocumentFilter filter = (ContentDocumentFilter)edir.newObject(filterMapping);
// search the entire cn=sas tree
filter.setContext(logicBean.getPortalContext(edir.APPLICATION_CONTEXT, request));
filter.setName("Demo Document *");
// the filtered entity collection allows us to iterate over all the entities
// that match the filter
String collectionMapping = edir.CLASS_MAPPING + "com.sas.edir.FilteredEntityCollection";
Object[] args = { edir, new String("") };
FilteredEntityCollection collection = collection = (FilteredEntityCollection)edir.newObject(collectionMapping, args);
collection.setFilter(filter);
The following code iterates over the search results and obtains the name and description of each document that met the filter criteria. The names and descriptions are written to the output page. |
// iterate over the results
ContentDocument doc = null;
Iterator itor = collection.listIterator();
while (itor.hasNext())
{
doc = (ContentDocument)itor.next();
%>
<p><b><%= doc.getName() %></b> - <%= doc.getDescription() %>
<%
}
}
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>