org.xins.server.frontend.ControlResult Maven / Gradle / Ivy
/*
* $Id: ControlResult.java,v 1.13 2010/11/18 20:35:05 agoubard Exp $
*
* See the COPYRIGHT file for redistribution and use restrictions.
*/
package org.xins.server.frontend;
import java.util.Iterator;
import java.util.Map;
import org.w3c.dom.Element;
import org.xins.common.text.DateConverter;
import org.xins.common.spec.FunctionSpec;
import org.xins.common.spec.InvalidSpecificationException;
import org.xins.server.API;
import org.xins.server.FunctionResult;
import org.xins.server.Log;
/**
* Result for the Control command.
*
* @version $Revision: 1.13 $ $Date: 2010/11/18 20:35:05 $
* @author Anthony Goubard
*/
class ControlResult extends FunctionResult {
/**
* Creates the result for the Control command.
*
* @param api
* the API, cannot be null
.
*
* @param sessionManager
* the sessionManager, cannot be null
.
*
* @param redirectionMap
* the redirection map, cannot be null
.
*/
ControlResult(API api, SessionManager sessionManager, Map redirectionMap) {
// The versions
param("xinsCommonVersion", org.xins.common.Library.getVersion());
param("xinsServerVersion", org.xins.server.Library.getVersion());
param("apiName", api.getName());
param("apiStartUpTime", DateConverter.toDateString(api.getStartupTimestamp()));
// Some bootstrap properties
Map bootstrapProps = api.getBootstrapProperties();
param("apiVersion", bootstrapProps.get("org.xins.api.version"));
param("apiBuildVersion", bootstrapProps.get("org.xins.api.build.version"));
param("apiBuildTime", bootstrapProps.get("org.xins.api.build.time"));
// The commands
try {
Map functions = api.getAPISpecification().getFunctions();
Iterator itFunctions = functions.entrySet().iterator();
while (itFunctions.hasNext()) {
Map.Entry nextFunction = (Map.Entry) itFunctions.next();
FunctionSpec functionSpec = (FunctionSpec) nextFunction.getValue();
Element builder = getDataElementBuilder().createElement("command");
builder.setAttribute("name", (String) nextFunction.getKey());
builder.setAttribute("description", functionSpec.getDescription());
add(builder);
}
} catch (InvalidSpecificationException isex) {
Log.log_3705(isex.getMessage());
}
Iterator itVirtualFunctions = redirectionMap.keySet().iterator();
while (itVirtualFunctions.hasNext()) {
String nextFunction = (String) itVirtualFunctions.next();
Element builder = getDataElementBuilder().createElement("command");
builder.setAttribute("name", nextFunction);
add(builder);
}
// The sessions
Element builder = getDataElementBuilder().createElement("sessionproperties");
Map sessionProperties = sessionManager.getProperties();
Iterator itSessions = sessionProperties.entrySet().iterator();
while (itSessions.hasNext()) {
Map.Entry nextSession = (Map.Entry) itSessions.next();
String nextKey = (String) nextSession.getKey();
Object nextValue = nextSession.getValue();
Element builder2 = getDataElementBuilder().createElement("property");
builder2.setAttribute("name", nextKey);
builder2.setTextContent(nextValue.toString());
builder.appendChild(builder2);
}
add(builder);
}
/**
* Return the XSLT to use to display the data of the Control command.
*
* @return
* the XSLT to display the Control result, never null
.
*/
static String getControlTemplate() {
String result = "\n" +
"\n" +
" \n" +
"\n" +
"\n" +
"\n" +
"\n" +
" \n" +
" Application \n" +
"
\n" +
"Versions
\n" +
"API: \n" +
" \n" +
"
\n" +
"XINS server: \n" +
" \n" +
"
\n" +
"XINS common: \n" +
" \n" +
"
\n" +
"XINS build version: \n" +
" \n" +
"
\n" +
"XINS build time: \n" +
" \n" +
"
\n" +
"API start-up time: \n" +
" \n" +
"
\n" +
"Functions
\n" +
"\n" +
" 1\">\n" +
", \n" +
" \n" +
"\n" +
" \n" +
"\n" +
" \n" +
"Session properties
\n" +
"\n" +
"Key Value \n" +
"\n" +
"\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
"
\n" +
"Actions
\n" +
"Command template cache management:\n" +
"Flush\n" +
"Refresh\n" +
"
\n" +
"Session properties management:\n" +
"Remove all Session Properties\n" +
"
\n" +
"XINS meta functions: \n" +
"Version,\n" +
"Statistics,\n" +
"Settings\n" +
"
\n" +
"\n" +
"\n" +
" \n" +
" ";
return result;
}
}