use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class ApplicationHandlers method getTargetListInfo.
@Handler(id = "gf.getTargetListInfo", input = { @HandlerInput(name = "appName", type = String.class, required = true) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void getTargetListInfo(HandlerContext handlerCtx) {
String appName = (String) handlerCtx.getInputValue("appName");
String prefix = (String) GuiUtil.getSessionValue("REST_URL");
List clusters = TargetUtil.getClusters();
List standalone = TargetUtil.getStandaloneInstances();
List dgs = TargetUtil.getDeploymentGroups();
standalone.add("server");
List<String> targetList = DeployUtil.getApplicationTarget(appName, "application-ref");
List result = new ArrayList();
Map attrs = null;
String endpoint = "";
for (String oneTarget : targetList) {
HashMap oneRow = new HashMap();
if (clusters.contains(oneTarget)) {
endpoint = prefix + "/clusters/cluster/" + oneTarget + "/application-ref/" + appName;
attrs = RestUtil.getAttributesMap(endpoint);
} else if (standalone.contains(oneTarget)) {
endpoint = prefix + "/servers/server/" + oneTarget + "/application-ref/" + appName;
attrs = RestUtil.getAttributesMap(endpoint);
} else {
endpoint = prefix + "/deployment-groups/deployment-group/" + oneTarget + "/application-ref/" + appName;
attrs = RestUtil.getAttributesMap(endpoint);
}
oneRow.put("name", appName);
oneRow.put("selected", false);
oneRow.put("endpoint", endpoint.replaceAll("/application-ref/.*", "/update-application-ref"));
oneRow.put("targetName", oneTarget);
oneRow.put("enabled", attrs.get("enabled"));
oneRow.put("lbEnabled", attrs.get("lbEnabled"));
result.add(oneRow);
}
handlerCtx.setOutputValue("result", result);
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UtilHandlers method mapEntrySet.
/**
* <p> This handler returns the <code>Set</code> of entries for the given
* <code>Map</code>.</p>
* @param handlerCtx
*/
@Handler(id = "mapEntrySet", input = { @HandlerInput(name = "map", type = Map.class, required = true) }, output = { @HandlerOutput(name = "set", type = Set.class) })
public static void mapEntrySet(HandlerContext handlerCtx) {
Map map = (Map) handlerCtx.getInputValue("map");
handlerCtx.setOutputValue("set", map.entrySet());
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UtilHandlers method roundTo2DecimalPoint.
@Handler(id = "roundTo2DecimalPoint", input = { @HandlerInput(name = "input", type = Double.class) }, output = { @HandlerOutput(name = "output", type = String.class) })
public static void roundTo2DecimalPoint(HandlerContext handlerCtx) {
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
try {
Double input = (Double) handlerCtx.getInputValue("input");
String output = (input == null) ? "" : df.format(input);
handlerCtx.setOutputValue("output", output);
} catch (Exception ex) {
handlerCtx.setOutputValue("output", "");
GuiUtil.getLogger().info(GuiUtil.getCommonMessage("log.error.roundTo2DecimalPoint") + ex.getLocalizedMessage());
if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
ex.printStackTrace();
}
}
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UtilHandlers method convertListToArray.
@Handler(id = "convertListToArray", input = { @HandlerInput(name = "list", type = List.class, required = true) }, output = { @HandlerOutput(name = "array", type = String[].class) })
public static void convertListToArray(HandlerContext handlerCtx) {
List list = (List) handlerCtx.getInputValue("list");
handlerCtx.setOutputValue("array", list.toArray(new String[list.size()]));
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UtilHandlers method serveResource.
/**
* <p> This handler serves a resource via JSFTemplating's FileStreamer.</p>
* @param ctx
* @throws java.io.IOException
*/
@Handler(id = "gf.serveResource", input = { @HandlerInput(name = "path", type = String.class, required = true) }, output = { @HandlerOutput(name = "content", type = String.class) })
public static void serveResource(HandlerContext ctx) throws java.io.IOException {
/*
JSF 2.0 impl used to set the writer before the render response phase
(in apply request values). So we couldn't control the output of an
Ajax request. :( Therefor the following is commented out. On
10/6/2009 rlubke fixed this, we need to adjust the JS to handle a
direct response then this can be enabled.
FacesContext facesCtx = ctx.getFacesContext();
UIViewRoot root = new UIViewRoot();
root.setRenderKitId("dummy");
facesCtx.setViewRoot(root);
LayoutViewHandler.serveResource(facesCtx,
(String) ctx.getInputValue("path"));
*/
String path = (String) ctx.getInputValue("path");
int idx = path.lastIndexOf("://");
String port = null;
if (idx != -1) {
// Strip off protocol
path = path.substring(idx + 3);
// FIXME: port 80 may be omitted (or 443 for https)
if ((idx = path.indexOf(':')) != -1) {
path = path.substring(idx + 1);
if ((idx = path.indexOf('/')) != -1) {
port = path.substring(0, idx);
path = path.substring(idx);
}
}
}
URL url = FileUtil.searchForFile(path, null);
if ((url == null) && (port != null)) {
// Attempt to read from localhost
path = "http://localhost:" + port + path;
try {
url = new URL(path);
} catch (MalformedURLException ex) {
url = null;
}
}
String content = "";
if (url != null) {
try {
content = new String(FileUtil.readFromURL(url));
} catch (FileNotFoundException fnfe) {
//
}
}
// Set the output
ctx.setOutputValue("content", content);
}
Aggregations