Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Chapter 4 Using the Sample HTML Interface : Generating HTML Pages from the XML Stream Using JSTL in JSP

Generating HTML Pages from the XML Stream Using JSTL in JSP
The sample HTML interface is an example of transforming the XML stream in HawkXml.xml into a format that can be used by an XML-aware application. This allows the XML data to be easily integrated with any application using XML with HTTP transport.
JSTL is an important specification of the Java Web platform that works with JSP version 1.2 and higher. This section explains how JSTL was used in the file HAWK_HOME/webconsole/tomcat/webapps/http/jsp/alldomain.jsp to create the Enterprise View HTML page. It illustrates the use of JSTL XML and Code tag libraries and expression language to retrieve XML content, parse it, and present in HTML.
You can refer to alldomain.jsp when reading this section. The JSPs are located in the HAWK_HOME/webconsole/tomcat/webapps/http/jsp directory. All JSPs included with TIBCO Hawk HTTP Adapter follow the same programming pattern and are documented in the code.
JSTL
JSTL consists of a collection of tag libraries designed to meet particular needs.
The tag libraries are divided into four groups, available separately:
XML processing library
All JSPs make use of the first three tag libraries.
Importing the Tag Libraries
The first step in using JSTL is importing the tag libraries. In the following code fragment from alldomain.jsp, the Core, XML and Internationalization tag libraries are imported.
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
Constructing the Relative URL
The following code fragment constructs the relative URL (Agents) to be invoked to retrieve the XML stream, and applies the stylesheet named Nnames.xsl to resulting XML document.

 
<% if ( aUrl == null )
{
aUrl = new StringBuffer( request.getScheme() );
aUrl.append( "://" + request.getServerName() + ":" + request.getServerPort
() );
aUrl.append( request.getContextPath() + "/Agents" + "?Style=Nnames.xsl" );
 
}
%>

 
Importing XML Content
In the following code fragment, the Core library tag is used to import XML content from the Agents URL. The retrieved content is in raw XML text and is stored in a variable named xml.
<C:import var="xml" url="${AURL}" />
Parsing the XML
Raw XML content is not very useful and needs to be parsed. Parsing an XML document converts the raw XML into a format that can be handled with XSLT, XPATH, or other standard XML manipulation technologies.
The following code fragment parses the retrieved XML document and stores the result in a variable named AgentDom. It uses the tag named parse from the XML tag library.
<x:parse var="AgentDom" xml="${xml}" />
Applying a Cascading Stylesheet
After the above line of code, JSP sets up the HTML page and uses the cascading stylesheet named index.css to set the HTML properties.
Retrieving the TIBCO Hawk Agent Data
The following code fragment retrieves the total number of TIBCO Hawk agents in all configured Hawk domains. It uses the XML tag x:out and the XPATH function count. You can use XPATH to select any nodes desired.
Total Agents: <x:out select="count($AgentDom//Agent)" />
Following code iterates through all Agent nodes using the XML tag x:forEach. It also uses the XML tag x:out to retrieve content for the selected nodes and store it in variables.

 
<x:forEach select="$AgentDom//Agent" >
 
<c:set var="NameOfDomain" >
<x:out select="HawkDomain"/>
</c:set>
 
 
 
<%--
*******************************************************************
Setting Up varibale AgentState to "RuleBaseEngineState" node using Xpath.
*******************************************************************
--%>
<c:set var="AgentState">
<x:out select="RuleBaseEngineState" />
</c:set>
 
<%--
*******************************************************************
Retrieving from DomainMap, current "State" of Cluster
*******************************************************************
--%>
<c:set var="OldAgentState" >
<c:out value="${DomainMap[NameOfDomain]}" />
</c:set>
 
…..
……..
</x:forEach>

 
All retrieved information is stored in a HashMap named DomainMap, and later shown in tabular format. HashMap stores the domain name as a key and the highest alert state within the domain as a value.

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved