001: /*
002: * $Id: ControlResult.java,v 1.9 2007/09/18 08:45:08 agoubard Exp $
003: *
004: * Copyright 2003-2007 Orange Nederland Breedband B.V.
005: * See the COPYRIGHT file for redistribution and use restrictions.
006: */
007: package org.xins.server.frontend;
008:
009: import java.util.Iterator;
010: import java.util.Map;
011:
012: import org.xins.common.collections.PropertyReader;
013: import org.xins.common.text.DateConverter;
014: import org.xins.common.xml.ElementBuilder;
015: import org.xins.common.spec.FunctionSpec;
016: import org.xins.common.spec.InvalidSpecificationException;
017:
018: import org.xins.server.API;
019: import org.xins.server.FunctionResult;
020: import org.xins.server.Log;
021:
022: /**
023: * Result for the Control command.
024: *
025: * @version $Revision: 1.9 $ $Date: 2007/09/18 08:45:08 $
026: * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
027: */
028: class ControlResult extends FunctionResult {
029:
030: /**
031: * Creates the result for the Control command.
032: *
033: * @param api
034: * the API, cannot be <code>null</code>.
035: *
036: * @param sessionManager
037: * the sessionManager, cannot be <code>null</code>.
038: *
039: * @param redirectionMap
040: * the redirection map, cannot be <code>null</code>.
041: */
042: ControlResult(API api, SessionManager sessionManager,
043: Map redirectionMap) {
044:
045: // The versions
046: param("xinsCommonVersion", org.xins.common.Library.getVersion());
047: param("xinsServerVersion", org.xins.server.Library.getVersion());
048: param("apiName", api.getName());
049: param("apiStartUpTime", DateConverter.toDateString(api
050: .getStartupTimestamp()));
051:
052: // Some bootstrap properties
053: PropertyReader bootstrapProps = api.getBootstrapProperties();
054: param("apiVersion", bootstrapProps.get("org.xins.api.version"));
055: param("apiBuildVersion", bootstrapProps
056: .get("org.xins.api.build.version"));
057: param("apiBuildTime", bootstrapProps
058: .get("org.xins.api.build.time"));
059:
060: // The commands
061: try {
062: Map functions = api.getAPISpecification().getFunctions();
063: Iterator itFunctions = functions.entrySet().iterator();
064: while (itFunctions.hasNext()) {
065: Map.Entry nextFunction = (Map.Entry) itFunctions.next();
066: FunctionSpec functionSpec = (FunctionSpec) nextFunction
067: .getValue();
068: ElementBuilder builder = new ElementBuilder("command");
069: builder.setAttribute("name", (String) nextFunction
070: .getKey());
071: builder.setAttribute("description", functionSpec
072: .getDescription());
073: add(builder.createElement());
074: }
075: } catch (InvalidSpecificationException isex) {
076: Log.log_3705(isex.getMessage());
077: }
078: Iterator itVirtualFunctions = redirectionMap.keySet()
079: .iterator();
080: while (itVirtualFunctions.hasNext()) {
081: String nextFunction = (String) itVirtualFunctions.next();
082: ElementBuilder builder = new ElementBuilder("command");
083: builder.setAttribute("name", nextFunction);
084: add(builder.createElement());
085: }
086:
087: // The sessions
088: ElementBuilder builder = new ElementBuilder("sessionproperties");
089: Map sessionProperties = sessionManager.getProperties();
090: Iterator itSessions = sessionProperties.entrySet().iterator();
091: while (itSessions.hasNext()) {
092: Map.Entry nextSession = (Map.Entry) itSessions.next();
093: String nextKey = (String) nextSession.getKey();
094: Object nextValue = nextSession.getValue();
095: ElementBuilder builder2 = new ElementBuilder("property");
096: builder2.setAttribute("name", nextKey);
097: builder2.setText(nextValue.toString());
098: builder.addChild(builder2.createElement());
099: }
100: add(builder.createElement());
101: }
102:
103: /**
104: * Return the XSLT to use to display the data of the Control command.
105: *
106: * @return
107: * the XSLT to display the Control result, never <code>null</code>.
108: */
109: static String getControlTemplate() {
110: String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
111: + "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n"
112: + "<xsl:output method=\"html\" indent=\"yes\" encoding=\"US-ASCII\"\n"
113: + "doctype-public=\"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
114: + "doctype-system=\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"\n"
115: + "omit-xml-declaration=\"yes\" />\n"
116: + "<xsl:template match=\"commandresult\">\n"
117: + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n"
118: + "<body>\n"
119: + "<h2>\n"
120: + "<xsl:value-of select=\"parameter[@name='apiName']/text()\" />\n"
121: + "<xsl:text> Application</xsl:text>\n"
122: + "</h2>\n"
123: + "<h3>Versions</h3>\n"
124: + "<xsl:text>API: </xsl:text>\n"
125: + "<xsl:value-of select=\"parameter[@name='apiVersion']/text()\" />\n"
126: + "<br />\n"
127: + "<xsl:text>XINS server: </xsl:text>\n"
128: + "<xsl:value-of select=\"parameter[@name='xinsServerVersion']/text()\" />\n"
129: + "<br />\n"
130: + "<xsl:text>XINS common: </xsl:text>\n"
131: + "<xsl:value-of select=\"parameter[@name='xinsCommonVersion']/text()\" />\n"
132: + "<br />\n"
133: + "<xsl:text>XINS build version: </xsl:text>\n"
134: + "<xsl:value-of select=\"parameter[@name='apiBuildVersion']/text()\" />\n"
135: + "<br />\n"
136: + "<xsl:text>XINS build time: </xsl:text>\n"
137: + "<xsl:value-of select=\"parameter[@name='apiBuildTime']/text()\" />\n"
138: + "<br />\n"
139: + "<xsl:text>API start-up time: </xsl:text>\n"
140: + "<xsl:value-of select=\"parameter[@name='apiStartUpTime']/text()\" />\n"
141: + "<br />\n"
142: + "<h3>Functions</h3>\n"
143: + "<xsl:for-each select=\"data/command\">\n"
144: + "<xsl:if test=\"position() > 1\">\n"
145: + "<xsl:text>, </xsl:text>\n"
146: + "</xsl:if>\n"
147: + "<a href=\"?command={@name}\">\n"
148: + "<xsl:value-of select=\"@name\" />\n"
149: + "</a>\n"
150: + "</xsl:for-each>\n"
151: + "<h3>Session properties</h3>\n"
152: + "<table>\n"
153: + "<tr><td><strong>Key</strong></td><td><strong>Value</strong></td></tr>\n"
154: + "<xsl:for-each select=\"data/sessionproperties/property\">\n"
155: + "<tr><td>\n"
156: + "<xsl:value-of select=\"@name\" />\n"
157: + "</td><td>\n"
158: + "<xsl:value-of select=\"text()\" />\n"
159: + "</td></tr>\n"
160: + "</xsl:for-each>\n"
161: + "</table>\n"
162: + "<h3>Actions</h3>\n"
163: + "<p>Command template cache management:\n"
164: + "<a href=\"?command=Control&action=FlushCommandTemplateCache\">Flush</a>\n"
165: + "<a href=\"?command=Control&action=RefreshCommandTemplateCache\">Refresh</a>\n"
166: + "</p>\n"
167: + "<p>Session properties management:\n"
168: + "<a href=\"?command=Control&action=RemoveSessionProperties\">Remove all Session Properties</a>\n"
169: + "</p>\n"
170: + "<p>XINS meta functions: \n"
171: + "<a href=\"?_function=_GetVersion&_convention=_xins-std\">Version</a>,\n"
172: + "<a href=\"?_function=_GetStatistics&detailed=true&_convention=_xins-std\">Statistics</a>,\n"
173: + "<a href=\"?_function=_GetSettings&_convention=_xins-std\">Settings</a>\n"
174: + "</p>\n" + "</body>\n" + "</html>\n"
175: + "</xsl:template>\n" + "</xsl:stylesheet>";
176: return result;
177: }
178: }
|