Search in sources :

Example 6 with NamespaceException

use of javax.jcr.NamespaceException in project jackrabbit by apache.

the class PathConstraint method create.

static PathConstraint create(String jcrPath, PathResolver resolver) throws InvalidConstraintException {
    try {
        // constraint format: absolute or relative path with optional
        // trailing wild card
        boolean deep = jcrPath.endsWith(JCR_WILDCARD);
        Path path;
        if (JCR_WILDCARD.equals(jcrPath)) {
            path = PATH_FACTORY.getRootPath();
        } else {
            if (deep) {
                // trim trailing wild card before building path
                jcrPath = jcrPath.substring(0, jcrPath.length() - JCR_WILDCARD.length());
            }
            path = resolver.getQPath(jcrPath);
        }
        StringBuffer definition = new StringBuffer(path.getString());
        if (deep) {
            definition.append(WILDCARD);
        }
        return new PathConstraint(definition.toString(), path, deep);
    } catch (NameException e) {
        String msg = "Invalid path expression specified as value constraint: " + jcrPath;
        log.debug(msg);
        throw new InvalidConstraintException(msg, e);
    } catch (NamespaceException e) {
        String msg = "Invalid path expression specified as value constraint: " + jcrPath;
        log.debug(msg);
        throw new InvalidConstraintException(msg, e);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) InvalidConstraintException(org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException) NamespaceException(javax.jcr.NamespaceException)

Example 7 with NamespaceException

use of javax.jcr.NamespaceException in project jackrabbit by apache.

the class NodeTypeWriter method write.

/**
     * Writes a node type definition file. The file contents are written
     * to the given output stream and will contain the given node type
     * definitions. The given namespace registry is used for namespace
     * mappings.
     *
     * @param xml XML output stream
     * @param registry namespace registry
     * @param types node types
     * @throws IOException         if the node type definitions cannot
     *                             be written
     * @throws RepositoryException on repository errors
     */
public static void write(OutputStream xml, QNodeTypeDefinition[] types, NamespaceRegistry registry) throws IOException, RepositoryException {
    try {
        NodeTypeWriter writer = new NodeTypeWriter(registry);
        for (QNodeTypeDefinition type : types) {
            writer.addNodeTypeDef(type);
        }
        writer.write(xml);
    } catch (ParserConfigurationException e) {
        IOException e2 = new IOException(e.getMessage());
        e2.initCause(e);
        throw e2;
    } catch (NamespaceException e) {
        throw new RepositoryException("Invalid namespace reference in a node type definition", e);
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NamespaceException(javax.jcr.NamespaceException) RepositoryException(javax.jcr.RepositoryException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException)

Example 8 with NamespaceException

use of javax.jcr.NamespaceException in project jackrabbit by apache.

the class EventState method setupCachingPathResolver.

private static void setupCachingPathResolver() {
    if (cachingPathResolver != null) {
        return;
    }
    PathResolver pathResolver = new ParsingPathResolver(PathFactoryImpl.getInstance(), new NameResolver() {

        public Name getQName(String name) throws IllegalNameException, NamespaceException {
            return null;
        }

        public String getJCRName(Name name) throws NamespaceException {
            return name.getLocalName();
        }
    });
    cachingPathResolver = new CachingPathResolver(pathResolver);
}
Also used : NamespaceException(javax.jcr.NamespaceException) CachingPathResolver(org.apache.jackrabbit.spi.commons.conversion.CachingPathResolver) PathResolver(org.apache.jackrabbit.spi.commons.conversion.PathResolver) ParsingPathResolver(org.apache.jackrabbit.spi.commons.conversion.ParsingPathResolver) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) ParsingPathResolver(org.apache.jackrabbit.spi.commons.conversion.ParsingPathResolver) NameResolver(org.apache.jackrabbit.spi.commons.conversion.NameResolver) Name(org.apache.jackrabbit.spi.Name) CachingPathResolver(org.apache.jackrabbit.spi.commons.conversion.CachingPathResolver)

Example 9 with NamespaceException

use of javax.jcr.NamespaceException in project jackrabbit by apache.

the class AbstractSession method setNamespacePrefix.

/**
     * Modifies the session local namespace mappings to contain the given
     * prefix to URI mapping.
     * <p>
     * This behaviour is based on JSR 283 (JCR 2.0), but remains backwards
     * compatible with JCR 1.0.
     *
     * @param prefix namespace prefix
     * @param uri namespace URI
     * @throws NamespaceException if the mapping is illegal
     * @throws RepositoryException if a repository error occurs
     */
public void setNamespacePrefix(String prefix, String uri) throws NamespaceException, RepositoryException {
    if (prefix == null) {
        throw new IllegalArgumentException("Prefix must not be null");
    } else if (uri == null) {
        throw new IllegalArgumentException("Namespace must not be null");
    } else if (prefix.length() == 0) {
        throw new NamespaceException("Empty prefix is reserved and can not be remapped");
    } else if (uri.length() == 0) {
        throw new NamespaceException("Default namespace is reserved and can not be remapped");
    } else if (prefix.toLowerCase().startsWith("xml")) {
        throw new NamespaceException("XML prefixes are reserved: " + prefix);
    } else if (!XMLChar.isValidNCName(prefix)) {
        throw new NamespaceException("Prefix is not a valid XML NCName: " + prefix);
    }
    synchronized (namespaces) {
        // Remove existing mapping for the given prefix
        namespaces.remove(prefix);
        // Remove existing mapping(s) for the given URI
        Set<String> prefixes = new HashSet<String>();
        for (Map.Entry<String, String> entry : namespaces.entrySet()) {
            if (entry.getValue().equals(uri)) {
                prefixes.add(entry.getKey());
            }
        }
        namespaces.keySet().removeAll(prefixes);
        // Add the new mapping
        namespaces.put(prefix, uri);
    }
}
Also used : NamespaceException(javax.jcr.NamespaceException) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 10 with NamespaceException

use of javax.jcr.NamespaceException in project jackrabbit by apache.

the class ParserTest method fuzz.

public void fuzz(String query) throws Exception {
    for (int i = 0; i < 100; i++) {
        StringBuffer buff = new StringBuffer(query);
        int changes = 1 + (int) Math.abs(random.nextGaussian() * 2);
        for (int j = 0; j < changes; j++) {
            char newChar;
            if (random.nextBoolean()) {
                String s = "<>_.+\"*%&/()=?[]{}_:;,.-1234567890.qersdf";
                newChar = s.charAt(random.nextInt(s.length()));
            } else {
                newChar = (char) random.nextInt(255);
            }
            int pos = random.nextInt(buff.length());
            if (random.nextBoolean()) {
                // 50%: change one character
                buff.setCharAt(pos, newChar);
            } else {
                if (random.nextBoolean()) {
                    // 25%: delete one character
                    buff.deleteCharAt(pos);
                } else {
                    // 25%: insert one character
                    buff.insert(pos, newChar);
                }
            }
        }
        String q = buff.toString();
        try {
            parser.createQueryObjectModel(q);
        } catch (ValueFormatException e) {
        // OK
        } catch (InvalidQueryException e) {
        // OK
        } catch (NamespaceException e) {
        // OK?
        } catch (Throwable t) {
            t.printStackTrace();
            assertTrue("Unexpected exception for query " + q + ": " + t, false);
        }
    }
}
Also used : ValueFormatException(javax.jcr.ValueFormatException) NamespaceException(javax.jcr.NamespaceException) Constraint(javax.jcr.query.qom.Constraint) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Aggregations

NamespaceException (javax.jcr.NamespaceException)56 Name (org.apache.jackrabbit.spi.Name)26 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)17 Path (org.apache.jackrabbit.spi.Path)13 InvalidQueryException (javax.jcr.query.InvalidQueryException)10 RepositoryException (javax.jcr.RepositoryException)7 PathQueryNode (org.apache.jackrabbit.spi.commons.query.PathQueryNode)7 NamespaceRegistry (javax.jcr.NamespaceRegistry)6 IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)6 LocationStepQueryNode (org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode)6 IOException (java.io.IOException)5 Session (javax.jcr.Session)5 DerefQueryNode (org.apache.jackrabbit.spi.commons.query.DerefQueryNode)5 PropertyFunctionQueryNode (org.apache.jackrabbit.spi.commons.query.PropertyFunctionQueryNode)5 SAXException (org.xml.sax.SAXException)5 InvalidSerializedDataException (javax.jcr.InvalidSerializedDataException)4 NodeTypeQueryNode (org.apache.jackrabbit.spi.commons.query.NodeTypeQueryNode)4 NotQueryNode (org.apache.jackrabbit.spi.commons.query.NotQueryNode)4 OrderQueryNode (org.apache.jackrabbit.spi.commons.query.OrderQueryNode)4 QueryNode (org.apache.jackrabbit.spi.commons.query.QueryNode)4