Search in sources :

Example 1 with JcrName

use of org.apache.jackrabbit.spi.commons.name.JcrName in project jackrabbit by apache.

the class NameParserTest method testCheckFormat.

public void testCheckFormat() throws Exception {
    for (JcrName t : tests) {
        long t1 = System.currentTimeMillis();
        for (int j = 0; j < NUM_TESTS; j++) {
            // check just creation
            boolean isValid = true;
            try {
                NameParser.checkFormat(t.jcrName);
            } catch (IllegalNameException e) {
                isValid = false;
            }
            assertEquals("\"" + t.jcrName + "\".checkFormat()", t.isValid(), isValid);
        }
        long t2 = System.currentTimeMillis();
        if (NUM_TESTS > 1) {
            System.out.println("testCheckFormat():\t" + t + "\t" + (t2 - t1) + "\tms");
        }
    }
}
Also used : JcrName(org.apache.jackrabbit.spi.commons.name.JcrName)

Example 2 with JcrName

use of org.apache.jackrabbit.spi.commons.name.JcrName in project jackrabbit by apache.

the class NameParserTest method testExpandedJcrNames.

public void testExpandedJcrNames() throws NamespaceException, IllegalNameException {
    NamespaceResolver resolver = new TestNamespaceResolver();
    List<String[]> valid = new ArrayList<String[]>();
    // valid qualified jcr-names:
    // String-array consisting of { jcrName , uri , localName }
    valid.add(new String[] { "abc:{c}", "abc", "{c}" });
    valid.add(new String[] { "abc:}c", "abc", "}c" });
    valid.add(new String[] { "abc:c}", "abc", "c}" });
    valid.add(new String[] { "{ab", "", "{ab" });
    valid.add(new String[] { "ab}", "", "ab}" });
    valid.add(new String[] { "a}bc", "", "a}bc" });
    valid.add(new String[] { "{", "", "{" });
    valid.add(new String[] { "}", "", "}" });
    valid.add(new String[] { "abc", "", "abc" });
    valid.add(new String[] { "abc{abc}", "", "abc{abc}" });
    valid.add(new String[] { "{{abc}", "", "{{abc}" });
    valid.add(new String[] { "{abc{abc}", "", "{abc{abc}" });
    valid.add(new String[] { "abc {", "", "abc {" });
    valid.add(new String[] { "abc { }", "", "abc { }" });
    valid.add(new String[] { "{ ab }", "", "{ ab }" });
    valid.add(new String[] { "{ }abc", "", "{ }abc" });
    // unknown uri -> but valid non-prefixed jcr-name
    valid.add(new String[] { "{test}abc", "", "{test}abc" });
    valid.add(new String[] { "{ab}", "", "{ab}" });
    valid.add(new String[] { ".{.}", "", ".{.}" });
    // valid expanded jcr-names:
    // String-array consisting of { jcrName , uri , localName }
    valid.add(new String[] { "{http://jackrabbit.apache.org}abc", "http://jackrabbit.apache.org", "abc" });
    valid.add(new String[] { "{http://jackrabbit.apache.org:80}abc", "http://jackrabbit.apache.org:80", "abc" });
    valid.add(new String[] { "{http://jackrabbit.apache.org/info}abc", "http://jackrabbit.apache.org/info", "abc" });
    valid.add(new String[] { "{jcr:jackrabbit}abc", "jcr:jackrabbit", "abc" });
    valid.add(new String[] { "{abc:}def", "abc:", "def" });
    valid.add(new String[] { "{}abc", "", "abc" });
    for (Object aValid : valid) {
        String[] strs = (String[]) aValid;
        try {
            Name n = NameParser.parse(strs[0], resolver, factory);
            assertEquals("URI mismatch", strs[1], n.getNamespaceURI());
            assertEquals("Local name mismatch", strs[2], n.getLocalName());
        } catch (Exception e) {
            fail(e.getMessage() + " -> " + strs[0]);
        }
    }
    // invalid jcr-names (neither expanded nor qualified form)
    List<String> invalid = new ArrayList<String>();
    // invalid prefix
    invalid.add("{a:b");
    invalid.add("}a:b");
    invalid.add("a{b:c");
    invalid.add("a}b:c");
    // unknown uri -> but invalid local name with ':' and or '/'
    invalid.add("{http//test.apache.org}abc");
    invalid.add("{test/test/test}abc");
    // invalid local name containing '/'
    invalid.add("{http://jackrabbit.apache.org}abc/dfg");
    // invalid local name containing ':'
    invalid.add("{http://jackrabbit.apache.org}abc:dfg");
    // invalid local name containing ':' and '/'
    invalid.add("{{http://jackrabbit.apache.org}abc:dfg}");
    // invalid local name containing '/'
    invalid.add("/a/b/c");
    // known uri but local name missing -> must fail.
    invalid.add("{http://jackrabbit.apache.org}");
    invalid.add("{}");
    for (Object anInvalid : invalid) {
        String jcrName = (String) anInvalid;
        try {
            NameParser.parse(jcrName, resolver, factory);
            fail("Parsing '" + jcrName + "' should fail. Not a valid jcr name.");
        } catch (IllegalNameException e) {
        //ok
        }
    }
}
Also used : ArrayList(java.util.ArrayList) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) NamespaceException(javax.jcr.NamespaceException) Name(org.apache.jackrabbit.spi.Name) JcrName(org.apache.jackrabbit.spi.commons.name.JcrName)

Example 3 with JcrName

use of org.apache.jackrabbit.spi.commons.name.JcrName in project jackrabbit by apache.

the class NameParserTest method testParse.

public void testParse() throws Exception {
    for (JcrName t : tests) {
        long t1 = System.currentTimeMillis();
        for (int j = 0; j < NUM_TESTS; j++) {
            try {
                Name n = NameParser.parse(t.jcrName, resolver, factory);
                if (!t.isValid()) {
                    fail("Should throw IllegalNameException: " + t.jcrName);
                }
                assertEquals("\"" + t.jcrName + "\".uri", t.prefix, n.getNamespaceURI());
                assertEquals("\"" + t.jcrName + "\".localName", t.name, n.getLocalName());
            } catch (IllegalNameException e) {
                if (t.isValid()) {
                    throw e;
                }
            } catch (NamespaceException e) {
                if (t.isValid()) {
                    throw e;
                }
            }
        }
        long t2 = System.currentTimeMillis();
        if (NUM_TESTS > 1) {
            System.out.println("testCreate():\t" + t + "\t" + (t2 - t1) + "\tms");
        }
    }
}
Also used : NamespaceException(javax.jcr.NamespaceException) JcrName(org.apache.jackrabbit.spi.commons.name.JcrName) Name(org.apache.jackrabbit.spi.Name) JcrName(org.apache.jackrabbit.spi.commons.name.JcrName)

Aggregations

JcrName (org.apache.jackrabbit.spi.commons.name.JcrName)3 NamespaceException (javax.jcr.NamespaceException)2 Name (org.apache.jackrabbit.spi.Name)2 ArrayList (java.util.ArrayList)1 NamespaceResolver (org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver)1