use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UtilHandlers method forLoop.
/**
* <p> A utility handler that resembles the for() method in Java. Handler inside the for loop will be executed
* in a loop. start index is specified by "start", till less than "end".
* eg. forLoop(start="1" end="3" varName="foo"){}, handler inside the {} will be executed 2 times.
*
* <p> Input value: "start" -- Type: <code>Integer</code> Start index, default to Zero is not specified
* <p> Input value: "end" -- Type: <code>Integer</code> End index.
* <p> Input value: "varName" -- Type: <code>String</code> Variable to be replaced in the for loop by the index.
* @param handlerCtx The HandlerContext.
* @return
*/
@Handler(id = "forLoop", input = { @HandlerInput(name = "start", type = String.class), @HandlerInput(name = "end", type = Integer.class, required = true), @HandlerInput(name = "varName", type = String.class, required = true) })
public static boolean forLoop(HandlerContext handlerCtx) {
String startInt = (String) handlerCtx.getInputValue("start");
int start = (startInt == null) ? 0 : Integer.parseInt(startInt);
int end = ((Integer) handlerCtx.getInputValue("end"));
String varName = ((String) handlerCtx.getInputValue("varName"));
List<com.sun.jsftemplating.layout.descriptors.handler.Handler> handlers = handlerCtx.getHandler().getChildHandlers();
if (handlers.size() > 0) {
LayoutElement elt = handlerCtx.getLayoutElement();
Map<String, Object> requestMap = handlerCtx.getFacesContext().getExternalContext().getRequestMap();
for (int ix = start; ix <= end; ix++) {
requestMap.put(varName, ix);
// ignore whats returned by the handler.
elt.dispatchHandlers(handlerCtx, handlers);
}
}
return false;
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class RestApiHandlers method restRequest.
/**
* <p> This handler can be used to execute a generic REST request. It
* will return a Java data structure based on the response of the
* REST request. 'data' and 'attrs' are mutually exclusive. 'data'
* is used to pass RAW data to the endpoint (such as JSON).</p>
*/
@Handler(id = "gf.restRequest", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "attrs", type = Map.class, required = false), @HandlerInput(name = "data", type = Object.class, required = false), @HandlerInput(name = "contentType", type = String.class, required = false), @HandlerInput(name = "method", type = String.class, defaultValue = "post"), @HandlerInput(name = "quiet", type = boolean.class, defaultValue = "false"), @HandlerInput(name = "throwException", type = boolean.class, defaultValue = "true") }, output = { @HandlerOutput(name = "result", type = Map.class) })
public static void restRequest(HandlerContext handlerCtx) {
Map<String, Object> attrs = (Map<String, Object>) handlerCtx.getInputValue("attrs");
String endpoint = (String) handlerCtx.getInputValue("endpoint");
String method = (String) handlerCtx.getInputValue("method");
boolean quiet = (Boolean) handlerCtx.getInputValue("quiet");
boolean throwException = (Boolean) handlerCtx.getInputValue("throwException");
// refer to bug#6942284. Some of the faulty URL may get here with endpoint set to null
if (GuiUtil.isEmpty(endpoint)) {
handlerCtx.setOutputValue("result", new HashMap());
} else {
try {
Map result = RestUtil.restRequest(endpoint, attrs, method, handlerCtx, quiet, throwException);
handlerCtx.setOutputValue("result", result);
} catch (Exception ex) {
Logger logger = GuiUtil.getLogger();
if (logger.isLoggable(Level.FINE)) {
ex.printStackTrace();
}
Map maskedAttr = RestUtil.maskOffPassword(attrs);
GuiUtil.getLogger().log(Level.SEVERE, "{0};\n{1};\n{2}", new Object[] { ex.getMessage(), ex.getCause(), GuiUtil.getCommonMessage("LOG_REST_REQUEST_INFO", new Object[] { endpoint, maskedAttr, method }) });
GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.error.checkLog"));
return;
}
}
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class GadgetHandlers method getGadgetModule.
/**
* <p> This handler returns a {@link GadgetModule} for the named
* gadget. The <code>name</code> should either be a complete URL,
* or a context-root relative path to the gadget XML file (this
* also includes .xml files stored in .jar's / plugins).</p>
*/
@Handler(id = "gf.getGadgetModule", input = { @HandlerInput(name = "name", type = String.class, required = true) }, output = { @HandlerOutput(name = "module", type = GadgetModule.class) })
public static void getGadgetModule(HandlerContext handlerCtx) {
String gadgetName = (String) handlerCtx.getInputValue("name");
URL url = null;
try {
if (!gadgetName.contains("://")) {
// Treat as a path...
url = FileUtil.searchForFile(gadgetName, null);
}
if (url == null) {
url = new URL(gadgetName);
}
} catch (Exception ex) {
throw new IllegalArgumentException("Cannot creaqte URL from '" + gadgetName + "'!", ex);
}
GadgetModule module = getGadgetModule(url);
handlerCtx.setOutputValue("module", module);
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class DeploymentHandler method getDeploymentDescriptorList.
/**
* <p> This method returns the deployment descriptors for a given app. </p>
*
* <p> Output value: "descriptors" -- Type: <code>java.util.List</code>/</p>
* @param handlerCtx The HandlerContext.
*/
@Handler(id = "gf.getDeploymentDescriptorList", input = { @HandlerInput(name = "data", type = List.class, required = true) }, output = { @HandlerOutput(name = "descriptors", type = List.class) })
public static void getDeploymentDescriptorList(HandlerContext handlerCtx) {
List<Map<String, Object>> ddList = (List) handlerCtx.getInputValue("data");
List result = new ArrayList();
if ((ddList != null) && ddList.size() > 0) {
for (Map<String, Object> oneDD : ddList) {
HashMap oneRow = new HashMap();
Map<String, String> props = (Map) oneDD.get("properties");
final String mName = props.get(MODULE_NAME_KEY);
oneRow.put("moduleName", (mName == null) ? "" : mName);
final String ddPath = props.get(DD_PATH_KEY);
oneRow.put("ddPath", (ddPath == null) ? "" : ddPath);
result.add(oneRow);
}
}
handlerCtx.setOutputValue("descriptors", result);
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class JdbcTempHandler method updateJdbcConnectionPoolWizardStep2.
/**
* <p> updates the wizard map properties on step 2
*/
@Handler(id = "updateJdbcConnectionPoolWizardStep2")
public static void updateJdbcConnectionPoolWizardStep2(HandlerContext handlerCtx) {
Map extra = (Map) handlerCtx.getFacesContext().getExternalContext().getSessionMap().get("wizardPoolExtra");
Map attrs = (Map) handlerCtx.getFacesContext().getExternalContext().getSessionMap().get("wizardMap");
String resType = (String) extra.get("resType");
String classname = (String) extra.get("datasourceClassname");
String driver = (String) extra.get("driverClassname");
String name = (String) extra.get("name");
String classnamefield = (String) extra.get("DatasourceClassnameField");
String driverfield = (String) extra.get("DriverClassnameField");
attrs.put("name", name);
attrs.put("resType", resType);
if ("".equals(attrs.get("transactionIsolationLevel"))) {
attrs.remove("transactionIsolationLevel");
}
if (!GuiUtil.isEmpty(classnamefield) || !GuiUtil.isEmpty(driverfield)) {
attrs.put("datasourceClassname", classnamefield);
attrs.put("driverClassname", driverfield);
} else if (!GuiUtil.isEmpty(classname) || !GuiUtil.isEmpty(driver)) {
attrs.put("datasourceClassname", classname);
attrs.put("driverClassname", driver);
} else {
GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("org.glassfish.jdbc.admingui.Strings", "msg.Error.classNameCannotBeEmpty"));
return;
}
}
Aggregations