Package org.apache.cocoon.components.validation

Examples of org.apache.cocoon.components.validation.Violation


        // if we're immediately under the form tag
        // and parent "ref" attribute is not available
        if (refStack.isEmpty()) {
            for (Iterator it = violations.iterator(); it.hasNext(); ) {
                Violation violation = (Violation) it.next();

                // render <violation> tag

                // set the ref attribute
                AttributesImpl atts;

                if ((attributes==null) || (attributes.getLength()==0)) {
                    atts = new AttributesImpl();
                } else {
                    atts = new AttributesImpl(attributes);
                }
                // atts.addAttribute( NS, TAG_COMMON_ATTR_REF, NS_PREFIX + ":" + TAG_COMMON_ATTR_REF, "CDATA", violation.getPath());
                atts.addAttribute(null, TAG_COMMON_ATTR_REF,
                                  TAG_COMMON_ATTR_REF, "CDATA",
                                  violation.getPath());

                // now start the element
                super.startElement(uri, TAG_VIOLATION,
                                   NS_PREFIX+":"+TAG_VIOLATION, atts);

                // set message
                String vm = violation.getMessage();

                super.characters(vm.toCharArray(), 0, vm.length());

                super.endElement(uri, TAG_VIOLATION,
                                 NS_PREFIX+":"+TAG_VIOLATION);
            }
        } // end if (currentRef_ == null)
            else {
            Entry entry = (Entry) refStack.peek();
            String currentRef = (String) entry.getValue();
            Violation v = new Violation();

            v.setPath(currentRef);
            Collection restViolations = violations.tailSet(v);
            Iterator rviter = restViolations.iterator();

            while (rviter.hasNext()) {
                Violation nextViolation = (Violation) rviter.next();

                // we're only interested in violations
                // with matching reference
                if ( !currentRef.equals(nextViolation.getPath())) {
                    break;
                }

                // render <violation> tag
                super.startElement(uri, TAG_VIOLATION,
                                   NS_PREFIX+":"+TAG_VIOLATION, attributes);
                // set message
                String vm = nextViolation.getMessage();

                super.characters(vm.toCharArray(), 0, vm.length());
                super.endElement(uri, TAG_VIOLATION,
                                 NS_PREFIX+":"+TAG_VIOLATION);
            }
View Full Code Here


            Object[] values = (Object[]) entry.getValue();

            try {
                setValue(path, values);
            } catch (JXPathException ex) {
                Violation v = new Violation();

                v.setPath(path);
                v.setMessage(ex.getMessage());
                pviolations.add(v);
            }
        } // while

        // validate form model
View Full Code Here

        // if we're immediately under the form tag
        // and parent "ref" attribute is not available
        if (refStack.isEmpty()) {
            for (Iterator it = violations.iterator(); it.hasNext(); ) {
                Violation violation = (Violation) it.next();

                // render <violation> tag

                // set the ref attribute
                AttributesImpl atts;

                if ((attributes==null) || (attributes.getLength()==0)) {
                    atts = new AttributesImpl();
                } else {
                    atts = new AttributesImpl(attributes);
                }
                // atts.addAttribute( NS, TAG_COMMON_ATTR_REF, NS_PREFIX + ":" + TAG_COMMON_ATTR_REF, "CDATA", violation.getPath());
                atts.addAttribute(null, TAG_COMMON_ATTR_REF,
                                  TAG_COMMON_ATTR_REF, "CDATA",
                                  violation.getPath());

                // now start the element
                super.startElement(uri, TAG_VIOLATION,
                                   NS_PREFIX+":"+TAG_VIOLATION, atts);

                // set message
                String vm = violation.getMessage();

                super.characters(vm.toCharArray(), 0, vm.length());

                super.endElement(uri, TAG_VIOLATION,
                                 NS_PREFIX+":"+TAG_VIOLATION);
            }
        } // end if (currentRef_ == null)
            else {
            Entry entry = (Entry) refStack.peek();
            String currentRef = (String) entry.getValue();
            Violation v = new Violation();

            v.setPath(currentRef);
            Collection restViolations = violations.tailSet(v);
            Iterator rviter = restViolations.iterator();

            while (rviter.hasNext()) {
                Violation nextViolation = (Violation) rviter.next();

                // we're only interested in violations
                // with matching reference
                if ( !currentRef.equals(nextViolation.getPath())) {
                    break;
                }

                // render <violation> tag
                super.startElement(uri, TAG_VIOLATION,
                                   NS_PREFIX+":"+TAG_VIOLATION, attributes);
                // set message
                String vm = nextViolation.getMessage();

                super.characters(vm.toCharArray(), 0, vm.length());
                super.endElement(uri, TAG_VIOLATION,
                                 NS_PREFIX+":"+TAG_VIOLATION);
            }
View Full Code Here

            Object[] values = (Object[]) entry.getValue();

            try {
                setValue(path, values);
            } catch (JXPathException ex) {
                Violation v = new Violation();

                v.setPath(path);
                v.setMessage(ex.getMessage());
                pviolations.add(v);
            }
        } // while

        // validate form model
View Full Code Here

            Object[] values = (Object[]) entry.getValue();

            try {
                setValue(path, values);
            } catch (JXPathException ex) {
                Violation v = new Violation();

                v.setPath(path);
                v.setMessage(ex.getMessage());
                pviolations.add(v);
            }
        } // while

        // validate form model
View Full Code Here

                while (assertIter.hasNext()) {
                    Assert assertion = (Assert) assertIter.next();

                    // add the next assert to the violations set
                    Violation v = new Violation();

                    v.setPath(rule.getContext());
                    v.setMessage(assertion.getMessage());
                    violations.add(v);
                    // System.out.println("        Assert test: " + assertion.getTest() + ", message: " + assertion.getMessage() );
                }

                Iterator reportIter = rule.getReport().iterator();

                while (reportIter.hasNext()) {
                    Report report = (Report) reportIter.next();

                    // add the next report to the violations set
                    Violation v = new Violation();

                    v.setPath(rule.getContext());
                    v.setMessage(report.getMessage());
                    violations.add(v);
                    // System.out.println("        Report test: " + report.getTest() + ", message: " + report.getMessage() );
                }
            }
        }
View Full Code Here

        // if we're immediately under the form tag
        // and parent "ref" attribute is not available
        if (refStack.isEmpty()) {
            for (Iterator it = violations.iterator(); it.hasNext(); ) {
                Violation violation = (Violation) it.next();

                // render <violation> tag

                // set the ref attribute
                AttributesImpl atts;

                if ((attributes==null) || (attributes.getLength()==0)) {
                    atts = new AttributesImpl();
                } else {
                    atts = new AttributesImpl(attributes);
                }
                // atts.addAttribute( NS, TAG_COMMON_ATTR_REF, NS_PREFIX + ":" + TAG_COMMON_ATTR_REF, "CDATA", violation.getPath());
                atts.addAttribute(null, TAG_COMMON_ATTR_REF,
                                  TAG_COMMON_ATTR_REF, "CDATA",
                                  violation.getPath());

                // now start the element
                super.startElement(uri, TAG_VIOLATION,
                                   NS_PREFIX+":"+TAG_VIOLATION, atts);

                // set message
                String vm = violation.getMessage();

                super.characters(vm.toCharArray(), 0, vm.length());

                super.endElement(uri, TAG_VIOLATION,
                                 NS_PREFIX+":"+TAG_VIOLATION);
            }
        } // end if (currentRef_ == null)
            else {
            Entry entry = (Entry) refStack.peek();
            String currentRef = (String) entry.getValue();
            Violation v = new Violation();

            v.setPath(currentRef);
            Collection restViolations = violations.tailSet(v);
            Iterator rviter = restViolations.iterator();

            while (rviter.hasNext()) {
                Violation nextViolation = (Violation) rviter.next();

                // we're only interested in violations
                // with matching reference
                if ( !currentRef.equals(nextViolation.getPath())) {
                    break;
                }

                // render <violation> tag
                super.startElement(uri, TAG_VIOLATION,
                                   NS_PREFIX+":"+TAG_VIOLATION, attributes);
                // set message
                String vm = nextViolation.getMessage();

                super.characters(vm.toCharArray(), 0, vm.length());
                super.endElement(uri, TAG_VIOLATION,
                                 NS_PREFIX+":"+TAG_VIOLATION);
            }
View Full Code Here

            // everything ok?
            assertEquals("Violations count does not match",
                         violations.size(), vs.size());
            for (Iterator i = violations.iterator(); i.hasNext(); ) {
                Violation v = (Violation) i.next();
                boolean gotit = false;

                for (Iterator j = vs.iterator(); j.hasNext(); ) {
                    Violation w = (Violation) j.next();

                    if (v.getPath().equals(w.getPath()) &&
                        v.getMessage().equals(w.getMessage())) {
                        gotit = true;
                        break;
                    }
                }
                assertTrue("Expected violation "+v.getPath()+" '"+
                           v.getMessage()+"' not found", gotit);
            }
            for (Iterator i = vs.iterator(); i.hasNext(); ) {
                Violation v = (Violation) i.next();
                boolean gotit = false;

                for (Iterator j = violations.iterator(); j.hasNext(); ) {
                    Violation w = (Violation) j.next();

                    if (v.getPath().equals(w.getPath()) &&
                        v.getMessage().equals(w.getMessage())) {
                        gotit = true;
                        break;
                    }
                }
                assertTrue("Unexpected violation "+v.getPath()+" '"+
View Full Code Here

            fail("Got an exception "+e);
        }
    }

    public void testSchema() {
        Violation violation;
        List violations = new ArrayList();

        violation = new Violation();
        violation.setPath("/scope");
        violation.setMessage("Scope should be request or session.");
        violations.add(violation);

        violation = new Violation();
        violation.setPath("/name");
        violation.setMessage("Animal name should be at least 4 characters.");
        violations.add(violation);

        violation = new Violation();
        violation.setPath("/count");
        violation.setMessage("The counter should be > 0.");
        violations.add(violation);

        testSchema("zxmlform-sch-report-test.xml", null, violations);
    }
View Full Code Here

        testSchema("zxmlform-sch-report-test.xml", null, violations);
    }

    public void testSchema_PhaseNew() {
        Violation violation;
        List violations = new ArrayList();

        violation = new Violation();
        violation.setPath("/scope");
        violation.setMessage("Scope should be request or session.");
        violations.add(violation);

        violation = new Violation();
        violation.setPath("/name");
        violation.setMessage("Animal name should be at least 4 characters.");
        violations.add(violation);

        testSchema("zxmlform-sch-report-test.xml", "New", violations);
    }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.components.validation.Violation

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.