Search in sources :

Example 1 with ComponentType

use of com.sun.jsftemplating.layout.descriptors.ComponentType in project Payara by payara.

the class PluginHandlers method includeFirstIntegrationPoint.

/**
 *	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);
            }
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ComponentType(com.sun.jsftemplating.layout.descriptors.ComponentType) UIComponent(javax.faces.component.UIComponent) IntegrationPoint(org.glassfish.admingui.connector.IntegrationPoint) IOException(java.io.IOException) LayoutComponent(com.sun.jsftemplating.layout.descriptors.LayoutComponent) URL(java.net.URL) Handler(com.sun.jsftemplating.annotation.Handler) LayoutViewHandler(com.sun.jsftemplating.layout.LayoutViewHandler)

Aggregations

Handler (com.sun.jsftemplating.annotation.Handler)1 LayoutViewHandler (com.sun.jsftemplating.layout.LayoutViewHandler)1 ComponentType (com.sun.jsftemplating.layout.descriptors.ComponentType)1 LayoutComponent (com.sun.jsftemplating.layout.descriptors.LayoutComponent)1 IOException (java.io.IOException)1 URL (java.net.URL)1 UIComponent (javax.faces.component.UIComponent)1 FacesContext (javax.faces.context.FacesContext)1 IntegrationPoint (org.glassfish.admingui.connector.IntegrationPoint)1