Package org.apache.shale.clay.config.beans

Examples of org.apache.shale.clay.config.beans.ComponentBean


        RolodexDao dao = (RolodexDao) getBean("rolodexDao");

        // return a list of tabs
        List tabs = dao.getTabs();

        ComponentBean root = (ComponentBean) displayElementRoot;
        root.setComponentType("javax.faces.HtmlPanelGroup");
        root.addChild(createVerbatimMetadata("<ul id=\"menu\">", context));

        for (int i = 0; i < tabs.size(); i++) {
            SelectItem item = (SelectItem) tabs.get(i);

            root.addChild(createVerbatimMetadata("<li id=\"", context));

            root.addChild(createVerbatimMetadata("nav-sel",
                    "#{@managed-bean-name.selectedTab == " + i + "}", context));
            root.addChild(createVerbatimMetadata("nav",
                    "#{@managed-bean-name.selectedTab != " + i + "}", context));

            root.addChild(createVerbatimMetadata("\">", context));
            root.addChild(createCommandLinkMetadata(item, context));
            root.addChild(createVerbatimMetadata("</li>", context));
        }

        root.addChild(createVerbatimMetadata("</ul>", context));

    }
View Full Code Here


        //
        // <clay:clay id="tabs" jsfid="RUNTIME"
        // shapeValidator="#{rolodex.createTabs}" managedBeanName="rolodex" />

        // create a fake clay root display element bean
        ComponentBean displayElementRoot = new ComponentBean();

        // create a mock component for the validator style/signature
        // of method binding
        Clay component = new Clay();
        component.setId("RUNTIME");
        component.setManagedBeanName("rolodex");
        component.setShapeValidator("#{rolodex.createTabs}");

        // make the last tab active
        viewController.setSelectedTab(RolodexDao.TAB_INDEX.length - 1);

        // simulate the the "shapeValidator" event is fired from the
        // beginEncode method of the Clay component on the view controller.
        viewController.createTabs(facesContext, component, displayElementRoot);

        // Check the number of children. Each tab has 6 nodes multiplied times
        // the
        // number of tabs plus two for the unordered list tags.
        int n = (RolodexDao.TAB_INDEX.length * 6) + 2;

        assertEquals("#Children", n, displayElementRoot.getChildren().size());

    }
View Full Code Here

                || !(component instanceof Clay)) {
            throw new RuntimeException(messages.getMessage("invalid.binding",
                    new Object[] { "clayOut" }));
        }

        ComponentBean text = (ComponentBean) displayElementRoot;
        Clay clay = (Clay) component;
        String value = (String) clay.getAttributes().get("value");
        value = tagUtils.evalString(value);
        if (value == null) {
            throw new IllegalArgumentException(messages.getMessage(
                    "missing.attribute", new Object[] { "value", "clayOut" }));
        }

        boolean escapeXml = false;
        String tmp = (String) clay.getAttributes().get("escapeXml");
        if (tmp != null) {
            escapeXml = tagUtils.evalBoolean(tmp).booleanValue();
        }

        if (!escapeXml) {
            value = decode(value);
        } else {
            value = encode(value);
        }

        text.setJsfid("outputText");
        text.setComponentType("javax.faces.HtmlOutputText");

        // add a value attribute
        AttributeBean attr = new AttributeBean();
        attr.setName("value");
        attr.setValue(value);
        text.addAttribute(attr);

        // add a escape attribute
        attr = new AttributeBean();
        attr.setName("escape");
        attr.setValue(Boolean.FALSE.toString());
        text.addAttribute(attr);

        // add a isTransient attribute
        attr = new AttributeBean();
        attr.setName("isTransient");
        attr.setValue(Boolean.TRUE.toString());
        text.addAttribute(attr);

    }
View Full Code Here

                || !(component instanceof Clay)) {
            throw new RuntimeException(messages.getMessage("invalid.binding",
                    new Object[] { "clayImport" }));
        }

        ComponentBean text = (ComponentBean) displayElementRoot;
        Clay clay = (Clay) component;
        String url = (String) clay.getAttributes().get("url");
        if (url == null) {
            throw new IllegalArgumentException(messages.getMessage(
                    "missing.attribute", new Object[] { "url", "clayImport" }));
        }
        url = tagUtils.evalString(url);

        boolean escapeXml = true;
        String escAttribute = (String) clay.getAttributes().get("escapeXml");
        if (escAttribute != null) {
            escapeXml = tagUtils.evalBoolean(escAttribute).booleanValue();
        }

        StringBuffer value = new StringBuffer();
        StringBuffer buff = new StringBuffer(url);

        // look for a classpath prefix.
        int i = buff.indexOf(Globals.CLASSPATH_PREFIX);
        if (i > -1) {
            buff.delete(0, i + Globals.CLASSPATH_PREFIX.length());
        }

        InputStream in = null;

        try {
            // if classpath prefix found, use the classloader
            if (i > -1) {
                // load form the classpath
                ClassLoader classloader = Thread.currentThread()
                        .getContextClassLoader();
                if (classloader == null) {
                    classloader = this.getClass().getClassLoader();
                }

                in = classloader.getResourceAsStream(buff.toString());

            } else {
                // load from the context root
                in = context.getExternalContext().getResourceAsStream(
                        buff.toString());
            }

            if (in != null) {
                int c = 0;
                done: while (true) {
                    c = in.read();
                    if (c > -1) {
                        value.append((char) c);
                    } else {
                        break done;
                    }

                }
            }
        } catch (IOException e) {
            throw new RuntimeException(messages.getMessage("invalid.attribute",
                    new Object[] { "url", "clayImport" }));
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    in = null;
                }
            }

        }

        if (escAttribute != null) {
            if (!escapeXml) {
                replace(value, decodeMap);
            } else {
                replace(value, encodeMap);
            }
        }

        text.setJsfid("outputText");
        text.setComponentType("javax.faces.HtmlOutputText");

        // add a value attribute
        AttributeBean attr = new AttributeBean();
        attr.setName("value");
        attr.setValue(value.toString());
        text.addAttribute(attr);

        // add a escape attribute
        attr = new AttributeBean();
        attr.setName("escape");
        attr.setValue(Boolean.FALSE.toString());
        text.addAttribute(attr);

        // add a isTransient attribute
        attr = new AttributeBean();
        attr.setName("isTransient");
        attr.setValue(Boolean.TRUE.toString());
        text.addAttribute(attr);
    }
View Full Code Here

            throw new NullPointerException(messages
                    .getMessage("clay.config.notloaded"));
        }

        // make sure it's parsed and cached
        ComponentBean b = config.getElement(bodyJsfid);
        if (b == null) {
            throw new NullPointerException(messages.getMessage(
                    "clay.jsfid.notfound", new Object[] { bodyJsfid }));
        }
View Full Code Here

            throw new NullPointerException(messages
                    .getMessage("clay.config.notloaded"));
        }

        // find the top-level display element associated with the subtree
        ComponentBean b = config.getElement(getJsfid());
        if (b == null) {
            throw new NullPointerException(messages.getMessage(
                    "clay.jsfid.notfound", new Object[] { getJsfid() }));
        }
View Full Code Here

        //The challenge here is that the symbol replacement happens after the
        //HTML node has been thrown out.  Look to see if the clayJsfid can be
        //found in the forming ComponentBean.
        if (getJsfid() == null) {
            String attrClayJsfid = "null";
            ComponentBean displayElement = (ComponentBean) getAttributes().get(Globals.CLAY_RESERVED_ATTRIBUTE);
            AttributeBean attr = displayElement.getAttribute("clayJsfid");
            if (displayElement != null && (attr != null)) {
                attrClayJsfid = attr.getValue();
            }
            throw new NullPointerException(messages.getMessage("clay.jsfid.null",
                  new Object[] { attrClayJsfid}));
        }

        if (getDisplayElementRoot() == null) {
            if (!getJsfid().equals(Globals.RUNTIME_ELEMENT_ID)) {
                displayElementRoot = getRootElement();
            } else {
                displayElementRoot = new ComponentBean();
                displayElementRoot.setComponentType("javax.faces.HtmlOutputText");
                displayElementRoot.setJsfid(getJsfid());

            }
View Full Code Here

        }
        AttributeBean attributeBean = clayContext.getAttribute();
        if (attributeBean == null) {
            throw new NullPointerException(getMessages().getMessage("clay.null.attributeBean"));
        }
        ComponentBean displayElement = clayContext.getDisplayElement();
        if (displayElement == null) {
            throw new NullPointerException(getMessages().getMessage("clay.null.componentBean"));
        }
        FacesContext facesContext = clayContext.getFacesContext();
        if (facesContext == null) {
View Full Code Here

        if (log.isInfoEnabled()) {
            log.info(messages.getMessage("loading.template",
                    new Object[] { templateName }));
        }

        ComponentBean root = new ComponentBean();
        root.setJsfid(templateName);
        root.setComponentType("javax.faces.HtmlOutputText");

        // generate the document

        StringBuffer buffer = loadTemplate(templateURL);

        List roots = new Parser().parse(buffer);
        Iterator ri = roots.iterator();
        while (ri.hasNext()) {
            Node node = (Node) ri.next();
            Builder renderer = getBuilder(node);
            ElementBean child = renderer.createElement(node);

            root.addChild(child);
            if (renderer.isChildrenAllowed()) {
                renderer.encode(node, child, child);
            } else {
                renderer.encode(node, child, root);
            }
View Full Code Here

        if (child == null) {
            throw new NullPointerException(getMessages()
                    .getMessage("clay.null.childComponent"));
        }

        ComponentBean displayElement = clayContext.getDisplayElement();
        if (displayElement == null) {
            throw new NullPointerException(getMessages()
                    .getMessage("clay.null.componentBean"));
        }

        EditableValueHolder parent = (EditableValueHolder) clayContext
                .getParent();
        if (parent == null) {
            throw new NullPointerException(getMessages()
                    .getMessage("clay.null.parentComponent"));
        }

        FacesContext facesContext = clayContext.getFacesContext();
        if (facesContext == null) {
            throw new NullPointerException(getMessages()
                    .getMessage("clay.null.facesContext"));
        }

        Validator validator = null;
        try {
            AttributeBean attr = displayElement.getAttribute("binding");
            if (attr != null && isValueReference(attr.getValue())) {
                clayContext.setAttribute(attr);
                String expr = replaceMnemonic(clayContext);
                ValueBinding vb = facesContext.getApplication()
                        .createValueBinding(expr);
                validator = (Validator) vb.getValue(facesContext);

            } else {
                validator = facesContext.getApplication().createValidator(
                        displayElement.getComponentType());
            }
        } catch (Exception e) {
            log.error(getMessages().getMessage("create.validator.error",
                    new Object[] { displayElement }), e);
            throw e;
View Full Code Here

TOP

Related Classes of org.apache.shale.clay.config.beans.ComponentBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.