4.4.2.11. The view.jsp page

Now that we have implemented the content handler class, we have to provide the view.jsp page. Following an implemenation that just displays the content of the node as plain text:
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
<%@page contentType="text/html" pageEncoding="UTF-8"
session="true"
import="org.docma.plugin.*,org.docma.plugin.web.*"
%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="expires" content="0">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<title>View HTML</title>
<%
request.setCharacterEncoding("UTF-8");
String docsess = request.getParameter("docsess");
String nodeid = request.getParameter("nodeid");
 
WebUserSession webSess =
WebPluginUtil.getUserSession(application, docsess);
StoreConnection storeConn =
(webSess != null) ? webSess.getOpenedStore() : null;
 
String cont = "";
if (storeConn != null) {
Node node = storeConn.getNodeById(nodeid);
if (node instanceof Content) {
cont = ((Content) node).getContentString();
if (cont != null) {
cont = cont.replace("<", "&lt;").replace(">", "&gt;");
}
}
}
%>
</head>
<body>
<pre><%= cont %></pre>
</body>
</html>

Listing 4.4.4. view.jsp

First the session ID that is passed as URL parameter docsess is used to retrieve the session instance. This is done by calling the getUserSession method of the org.docma.plugin.web.WebPluginUtil class. Note that the passed application argument is an implicit Java Server Pages object of type javax.servlet.ServletContext. After the user session has been retrieved, the user's currently opened store is retrieved by invoking the getOpenedStore method on the session instance. The node to be viewed is retrieved by invoking the getNodeById method on the store connection. The node identifier, which needs to be supplied as argument, is passed as URL parameter nodeid. Finally, the characters < and > are encoded as character entities, before the content is included in the body part of the generated HTML page.