Package org.apache.cocoon.precept

Examples of org.apache.cocoon.precept.Instance


  public Map introspection(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters par) throws Exception {
    getLogger().debug("start of flow");

    Session session = createSession(objectModel);
    Instance instance = createInstance("feedback");

    session.setAttribute("form-feedback",instance);
    return(page(VIEW1));
  }
View Full Code Here


            if (TAG_INSERTINSTANCE.equals(name)) {
                if (session != null) {
                    String id = attributes.getValue(TAG_INSERTINSTANCE_ATTR_ID);
                    getLogger().debug("inserting instance [id=" + String.valueOf(id) + "]");

                    Instance instance = (Instance) session.getAttribute(id);
                    if (instance != null) {
                        instance.toSAX(this, true);
                    }
                    else {
                        getLogger().debug("could not find instance [id=" + String.valueOf(id) + "]");
                    }
                }
                else {
                    getLogger().debug("no session - no instance");
                }
            }
            else if (TAG_INSERTVIOLATIONS.equals(name)) {
                Collection violations = (Collection) request.getAttribute(AbstractPreceptorAction.PRECEPTORVIOLATIONS);
                if (violations != null) {
                    for (Iterator it = violations.iterator(); it.hasNext();) {
                        Constraint constraint = (Constraint) it.next();
                        super.startElement(uri, "constraint", prefix + ":" + "constraint", NOATTR);
                        String v = String.valueOf(constraint);
                        super.characters(v.toCharArray(), 0, v.length());
                        super.endElement(uri, "constraint", prefix + ":" + "constraint");
                    }
                }
            }
            else if (TAG_INSTANCE.equals(name)) {
                if (session != null) {
                    String id = attributes.getValue(TAG_INSTANCE_ATTR_ID);
                    defaultInstance = (Instance) session.getAttribute(id);
                    if (defaultInstance != null) {
                        getLogger().debug("using default instance [id=" + String.valueOf(id) + "]");
                    }
                    else {
                        getLogger().error("could not find instance [id=" + String.valueOf(id) + "]");
                    }
                }
            }
            else if (TAG_OUTPUT.equals(name) || TAG_TEXTBOX.equals(name) ||
                     TAG_PASSWORD.equals(name) || TAG_SELECTBOOLEAN.equals(name) ||
                     TAG_SELECTONE.equals(name)) {
                String ref = attributes.getValue(TAG_COMMON_ATTR_REF);
                String id = attributes.getValue(TAG_COMMON_ATTR_INSTANCE);

                getLogger().debug("[" + String.valueOf(name) + "] getting value from [" + String.valueOf(ref) + "]");

                if (ref != null) {
                    Instance instance = defaultInstance;

                    if (id != null) {
                        if (session != null) {
                            instance = (Instance) session.getAttribute(id);
                            if (instance != null) {
                                getLogger().debug("using instance [id=" + String.valueOf(id) + "]");
                            }
                            else {
                                getLogger().error("could not find instance [id=" + String.valueOf(id) + "]");
                            }
                        }
                    }

                    super.startElement(uri, name, raw, attributes);

                    try {
                        value = instance.getValue(ref);

                        getLogger().debug("[" + String.valueOf(ref) + "] = " + String.valueOf(value));

                        super.startElement(uri, "value", prefix + ":" + "value", NOATTR);
                        if (value != null) {
                            String v = String.valueOf(value);
                            super.characters(v.toCharArray(), 0, v.length());
                        }

                        super.endElement(uri, "value", prefix + ":" + "value");

                        if (instance.getPreceptor() != null) {
                            Collection constraints = instance.getPreceptor().getConstraintsFor(ref);
                            if (constraints != null) {
                                for (Iterator it = constraints.iterator(); it.hasNext();) {
                                    Constraint constraint = (Constraint) it.next();
                                    constraint.toSAX(this);
                                }
View Full Code Here

    public Map introspection(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters par) throws Exception {
        getLogger().debug("start of flow");

        Session session = createSession(objectModel);
        Instance instance = createInstance("feedback");

        session.setAttribute("form-feedback", instance);
        return (page(VIEW1));

    }
View Full Code Here

    }


    final protected Instance createInstance(String id) throws ServiceException {
        InstanceFactory factory = (InstanceFactory) manager.lookup(InstanceFactory.ROLE);
        Instance instance = factory.createInstance(id);
        manager.release(factory);
        return (instance);
    }
View Full Code Here

    final protected void populate(Map objectModel, String instanceId, String xpath) throws PreceptorViolationException, InvalidXPathSyntaxException {
        Request request = ObjectModelHelper.getRequest(objectModel);
        Session session = request.getSession(false);
        if (session != null) {
            Instance instance = (Instance) session.getAttribute(instanceId);
            if (instance != null) {
                String value = request.getParameter(xpath);
                //String[] values = request.getParameterValues(xpath);

                if (value == null) value = "false";

                getLogger().debug("populating into " + String.valueOf(xpath) + " = " + String.valueOf(value));

                instance.setValue(xpath, value);
            }
        }
    }
View Full Code Here

        }
    }


    final protected Collection validate(Map objectModel, String instanceId) throws InvalidXPathSyntaxException, NoSuchNodeException {
        Instance instance = getInstance(objectModel, instanceId);
        Preceptor preceptor = instance.getPreceptor();
        Collection violations = preceptor.validate(instance, null);
        return (violations);
    }
View Full Code Here

        return (violations);
    }


    final protected Collection validate(Map objectModel, String instanceId, String xpath) throws InvalidXPathSyntaxException, NoSuchNodeException {
        Instance instance = getInstance(objectModel, instanceId);
        Preceptor preceptor = instance.getPreceptor();
        Collection violations = preceptor.validate(instance, xpath, null);
        return (violations);
    }
View Full Code Here

        }
    }


    final protected Collection validate(Map objectModel, String instanceId, String[] xpaths) throws InvalidXPathSyntaxException, NoSuchNodeException {
        Instance instance = getInstance(objectModel, instanceId);
        Preceptor preceptor = instance.getPreceptor();
        ArrayList allErrors = null;
        for (int i = 0; i < xpaths.length; i++) {
            Collection errors = preceptor.validate(instance, xpaths[i], null);
            if (errors != null) {
                if (allErrors == null) allErrors = new ArrayList(1);
View Full Code Here

  public Map introspection(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters par) throws Exception {
    getLogger().debug("start of flow");

    Session session = createSession(objectModel);
    Instance instance = createInstance("feedback");

    session.setAttribute("form-feedback",instance);
    return(page(VIEW1));
  }
View Full Code Here

    public Map introspection(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters par) throws Exception {
        getLogger().debug("start of flow");

        Session session = createSession(objectModel);
        Instance instance = createInstance("feedback");

        session.setAttribute("form-feedback", instance);
        return (page(VIEW1));

    }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.precept.Instance

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.