Search in sources :

Example 51 with Handler

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 52 with Handler

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());
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 53 with Handler

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();
        }
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) MalformedURLException(java.net.MalformedURLException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Handler(com.sun.jsftemplating.annotation.Handler)

Example 54 with Handler

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()]));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Handler(com.sun.jsftemplating.annotation.Handler)

Example 55 with Handler

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);
}
Also used : MalformedURLException(java.net.MalformedURLException) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) Handler(com.sun.jsftemplating.annotation.Handler)

Aggregations

Handler (com.sun.jsftemplating.annotation.Handler)167 ArrayList (java.util.ArrayList)85 Map (java.util.Map)85 List (java.util.List)82 HashMap (java.util.HashMap)81 TreeMap (java.util.TreeMap)14 IOException (java.io.IOException)12 Date (java.util.Date)9 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)8 LayoutViewHandler (com.sun.jsftemplating.layout.LayoutViewHandler)8 Image (com.sun.pkg.client.Image)8 ListIterator (java.util.ListIterator)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FacesContext (javax.faces.context.FacesContext)7 AttributeList (javax.management.AttributeList)7 RestResponse (org.glassfish.admingui.common.util.RestResponse)7 URL (java.net.URL)6 IntegrationPoint (org.glassfish.admingui.connector.IntegrationPoint)6 MultipleListDataProvider (com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider)5 TableRowGroup (com.sun.webui.jsf.component.TableRowGroup)5