@Handler( id = "calculateHelpUrl", input = { @HandlerInput(name = "pluginId", type = String.class, required = true), @HandlerInput(name = "helpKey", type = String.class, required = true) }, output = {@HandlerOutput(name = "url", type = String.class)}) public static void calculateHelpUrl(HandlerContext handlerCtx) { String pluginId = (String) handlerCtx.getInputValue("pluginId"); String helpKey = (String) handlerCtx.getInputValue("helpKey"); ConsolePluginService cps = getPluginService(handlerCtx.getFacesContext()); ClassLoader cl = cps.getModuleClassLoader(pluginId); // Try the viewRoot locale first String path = getHelpPathForResource(helpKey, handlerCtx.getFacesContext().getViewRoot().getLocale(), cl); if (path == null) { // Try the default locale path = getHelpPathForResource(helpKey, Locale.getDefault(), cl); // Default to en if (path == null) { path = "/en/help/" + helpKey; } } handlerCtx.setOutputValue("url", path); }
@Handler( id = "getPluginIdFromViewId", input = {@HandlerInput(name = "viewId", type = String.class, required = true)}, output = {@HandlerOutput(name = "pluginId", type = String.class)}) public static void getPluginIdFromViewId(HandlerContext handlerCtx) { String viewId = (String) handlerCtx.getInputValue("viewId"); if (viewId == null) { return; } ConsolePluginService cps = getPluginService(handlerCtx.getFacesContext()); String pluginId = "common"; int next = viewId.indexOf("/", 1); if (next > -1) { pluginId = viewId.substring(0, next); String resource = viewId.substring(next); if (pluginId.startsWith("/")) { pluginId = pluginId.substring(1); } ClassLoader cl = cps.getModuleClassLoader(pluginId); URL url = null; if (cl != null) { url = cl.getResource(resource); } if (url == null) { pluginId = "common"; } } handlerCtx.setOutputValue("pluginId", pluginId); }
/** * Finds the integration point of the specified type. Returns the contents of this IP type as a * list. The content can be a comma separated String. This is useful for the case such as dropdown * or list box to allow additional options in the component. */ @Handler( id = "getContentOfIntegrationPoints", input = {@HandlerInput(name = "type", type = String.class, required = true)}, output = { @HandlerOutput(name = "labels", type = List.class), @HandlerOutput(name = "values", type = List.class) }) public static void getContentOfIntegrationPoints(HandlerContext handlerCtx) throws java.io.IOException { // Get the input String type = (String) handlerCtx.getInputValue("type"); // Get the IntegrationPoints FacesContext ctx = handlerCtx.getFacesContext(); Set<IntegrationPoint> points = getSortedIntegrationPoints(getIntegrationPoints(ctx, type)); List labels = new ArrayList(); List values = new ArrayList(); if (points != null) { for (IntegrationPoint it : points) { String content = it.getContent(); if (GuiUtil.isEmpty(content)) { GuiUtil.getLogger() .warning( "No Content specified for Integration Point: " + type + " id : " + it.getId()); continue; } List<String> labelsAndValues = GuiUtil.parseStringList(content, "|"); values.add(labelsAndValues.get(0)); labels.add(GuiUtil.getMessage(labelsAndValues.get(1), labelsAndValues.get(2))); } } handlerCtx.setOutputValue("labels", labels); handlerCtx.setOutputValue("values", values); }
/** * This handler is used for the navigation nodes that request content from an external URL. This * handler pulls the "real url" from from the component specified by the <code>compId</code> * parameter (this necessarily depends on the presence of the navigation container in the view for * the component look up to work). Once the component has been found, the url is retrieved from * the attribute map, and its contents retrieved. If <code>processPage</code> is true, the URL * contents are interpretted and the resulting component(s) are added to the component tree (This * feature is not currently supported).. Otherwise, the contents are returned in the output * parameter <code>pluginPage</code> to be output as-is on the page. * * @param handlerCtx The <code>HandlerContext</code>. */ @Handler( id = "retrievePluginPageContents", input = {@HandlerInput(name = "compId", type = String.class, required = true)}, output = {@HandlerOutput(name = "pluginPage", type = String.class)}) public static void retrievePluginPageContents(HandlerContext handlerCtx) { String id = (String) handlerCtx.getInputValue("compId"); UIComponent comp = handlerCtx.getFacesContext().getViewRoot().findComponent(id); String urlContents = ""; if (comp != null) { String url = (String) comp.getAttributes().get(NavigationNodeFactory.REAL_URL); try { // Read from the URL... URL contentUrl = FileUtil.searchForFile(url, null); if (contentUrl == null) { throw new IOException("Unable to locate file: " + url); } urlContents = new String(FileUtil.readFromURL(contentUrl)); // FIXME: Implement processPage support /* if (processPage) { // probably do something like what includeIntegrations does ... } */ } catch (IOException ex) { Logger.getLogger(PluginHandlers.class.getName()) .log(Level.SEVERE, "Unable to read url: " + url, ex); } } // Set the content to output... handlerCtx.setOutputValue("pluginPage", urlContents); }
/** * This handler provides access to {@link IntegrationPoint}s for the requested key. * * @param handlerCtx The <code>HandlerContext</code>. */ @Handler( id = "getIntegrationPoints", input = {@HandlerInput(name = "type", type = String.class, required = true)}, output = {@HandlerOutput(name = "points", type = List.class)}) public static void getIntegrationPoints(HandlerContext handlerCtx) { String type = (String) handlerCtx.getInputValue("type"); List<IntegrationPoint> value = getIntegrationPoints(handlerCtx.getFacesContext(), type); handlerCtx.setOutputValue("points", value); }
/** * This handler returns a <code>Map<String id, List<URL>></code> containing all the * matches of the requested resource. Each <code>List</code> in the <code>Map</code> is associated * with a GUI Plugin, and the key to the <code>Map</code> is the plugin id. * * @param handlerCtx The <code>HandlerContext</code>. */ @Handler( id = "getPluginResources", input = {@HandlerInput(name = "name", type = String.class, required = true)}, output = {@HandlerOutput(name = "resources", type = Map.class)}) public static void getPluginResources(HandlerContext handlerCtx) { String name = (String) handlerCtx.getInputValue("name"); ConsolePluginService cps = getPluginService(handlerCtx.getFacesContext()); handlerCtx.setOutputValue("resources", cps.getResources(name)); }
/** * Includes the first IP based on priority for the given type. It adds the content to the given * UIComponent root. If the IP content looks like a URL (contains ://), a StaticText component * will be added with the value of the content from the URL. */ @Handler( id = "includeFirstIntegrationPoint", input = { @HandlerInput(name = "type", type = String.class, required = true), @HandlerInput(name = "root", type = UIComponent.class, required = false) }) public static void includeFirstIntegrationPoint(HandlerContext handlerCtx) throws java.io.IOException { // Get the input String type = (String) handlerCtx.getInputValue("type"); UIComponent root = (UIComponent) handlerCtx.getInputValue("root"); // Get the IntegrationPoints FacesContext ctx = handlerCtx.getFacesContext(); Set<IntegrationPoint> points = getSortedIntegrationPoints(getIntegrationPoints(ctx, type)); if (points != null) { Iterator<IntegrationPoint> it = points.iterator(); if (it.hasNext()) { // Get the first one... IntegrationPoint point = it.next(); root = getIntegrationPointParent(ctx, root, point); // Check to see if IP points to an external URL... if (point.getContent().lastIndexOf("://", 15) != -1) { // Treat content as a url... URL contentURL = FileUtil.searchForFile(point.getContent(), null); if (contentURL == null) { throw new IOException("Unable to locate file: " + point.getContent()); } // Read the content... String content = new String(FileUtil.readFromURL(contentURL)); // Create a StaticText component and add it under the // "root" component. LayoutComponent stDesc = new LayoutComponent( null, "externalContent", new ComponentType( "tmpTextCT", "com.sun.jsftemplating.component.factory.basic.StaticTextFactory")); stDesc.addOption("value", content); ComponentUtil.getInstance(ctx).createChildComponent(ctx, stDesc, root); } else { // Include the first one... includeIntegrationPoint(ctx, root, point); } } } }
/** * This handler adds {@link IntegrationPoint}s of a given type to a <code>UIComponent</code> tree. * It looks for {@link IntegrationPoint}s using the given <code>type</code>. It then sorts the * results (if any) by <code>parentId</code>, and then by priority. It next interates over each * one looking for a <code>UIComponent</code> with an <code>id</code> which matches the its own * <code>parentId</code> value. It then uses the content of the {@link IntegrationPoint} to * attempt to include the .jsf page it refers to under the identified parent component. */ @Handler( id = "includeIntegrations", input = { @HandlerInput(name = "type", type = String.class, required = true), @HandlerInput(name = "root", type = UIComponent.class, required = false) }) public static void includeIntegrations(HandlerContext handlerCtx) { // Get the input String type = (String) handlerCtx.getInputValue("type"); UIComponent root = (UIComponent) handlerCtx.getInputValue("root"); // Get the IntegrationPoints FacesContext ctx = handlerCtx.getFacesContext(); List<IntegrationPoint> points = getIntegrationPoints(ctx, type); // Include them includeIntegrationPoints(ctx, root, getSortedIntegrationPoints(points)); }
@Handler( id = "getAppEditIntegrationPoint", input = {@HandlerInput(name = "type", type = String.class, required = true)}, output = {@HandlerOutput(name = "appEditPageMap", type = Map.class)}) public static void getAppEditIntegrationPoint(HandlerContext handlerCtx) throws java.io.IOException { // Get the input String type = (String) handlerCtx.getInputValue("type"); // Get the IntegrationPoints FacesContext ctx = handlerCtx.getFacesContext(); Set<IntegrationPoint> points = getSortedIntegrationPoints(getIntegrationPoints(ctx, type)); Map result = new HashMap(); if (points != null) { for (IntegrationPoint it : points) { String content = it.getContent(); if (GuiUtil.isEmpty(content)) { GuiUtil.getLogger() .warning( "No Content specified for Integration Point: " + type + " id : " + it.getId()); continue; } List<String> vv = GuiUtil.parseStringList(content, ":"); if (vv.size() != 2) { GuiUtil.getLogger() .warning( "Invalid content specified for Integration Point: " + type + " id : " + it.getId()); continue; } result.put(vv.get(0), vv.get(1)); } } handlerCtx.setOutputValue("appEditPageMap", result); }