Search in sources :

Example 21 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class QueryImpl method storeAsNode.

/**
     * @see Query#storeAsNode(String)
     */
public Node storeAsNode(String absPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
    NamePathResolver resolver = mgrProvider.getNamePathResolver();
    try {
        Path p = resolver.getQPath(absPath).getNormalizedPath();
        if (!p.isAbsolute()) {
            throw new RepositoryException(absPath + " is not an absolute path");
        }
        String jcrParent = resolver.getJCRPath(p.getAncestor(1));
        if (!session.itemExists(jcrParent)) {
            throw new PathNotFoundException(jcrParent);
        }
        String relPath = resolver.getJCRPath(p).substring(1);
        String ntName = resolver.getJCRName(NameConstants.NT_QUERY);
        Node queryNode = session.getRootNode().addNode(relPath, ntName);
        // set properties
        queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE), getLanguage());
        queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT), getStatement());
        node = queryNode;
        return node;
    } catch (NameException e) {
        throw new RepositoryException(e.getMessage(), e);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 22 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class AccessControlManagerImpl method getUniqueNodeName.

// copied from jackrabbit-core ACLEditor
/**
     * Create a unique valid name for the Permission nodes to be save.
     *
     * @param node a name for the child is resolved
     * @param name if missing the {@link #DEFAULT_ACE_NAME} is taken
     * @return the name
     * @throws RepositoryException if an error occurs
     */
private Name getUniqueNodeName(NodeState node, String name) throws RepositoryException {
    try {
        NameParser.checkFormat(name);
    } catch (NameException e) {
        log.debug("Invalid path name for Permission: " + name + ".");
    }
    int i = 0;
    String check = name;
    Name n = npResolver.getQName(check);
    while (node.hasChildNodeEntry(n, 1)) {
        check = name + i;
        n = npResolver.getQName(check);
        i++;
    }
    return n;
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Name(org.apache.jackrabbit.spi.Name)

Example 23 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class RepositoryServiceImpl method getQNodeTypeDefinitions.

/**
     * {@inheritDoc}
     */
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo) throws RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
    List<QNodeTypeDefinition> nodeTypes = new ArrayList<QNodeTypeDefinition>();
    try {
        for (NodeTypeIterator it = ntMgr.getAllNodeTypes(); it.hasNext(); ) {
            NodeType nt = it.nextNodeType();
            nodeTypes.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
        }
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
    return nodeTypes.iterator();
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) RepositoryException(javax.jcr.RepositoryException) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)

Example 24 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class RepositoryServiceImpl method getChildInfos.

/**
     * {@inheritDoc}
     */
public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws ItemNotFoundException, RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    NodeIterator children = getNode(parentId, sInfo).getNodes();
    List<ChildInfo> childInfos = new ArrayList<ChildInfo>();
    try {
        while (children.hasNext()) {
            childInfos.add(new ChildInfoImpl(children.nextNode(), sInfo.getNamePathResolver()));
        }
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
    return childInfos.iterator();
}
Also used : NodeIterator(javax.jcr.NodeIterator) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) ArrayList(java.util.ArrayList) ChildInfo(org.apache.jackrabbit.spi.ChildInfo) RepositoryException(javax.jcr.RepositoryException)

Example 25 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class RepositoryServiceImpl method getItemInfos.

/**
     * {@inheritDoc}
     */
public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId itemId) throws ItemNotFoundException, RepositoryException {
    if (!itemId.denotesNode()) {
        PropertyId propertyId = (PropertyId) itemId;
        PropertyInfo propertyInfo = getPropertyInfo(sessionInfo, propertyId);
        return Iterators.singleton(propertyInfo);
    } else {
        NodeId nodeId = (NodeId) itemId;
        final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
        Node node = getNode(nodeId, sInfo);
        Name ntName = null;
        try {
            ntName = sInfo.getNamePathResolver().getQName(node.getProperty(JcrConstants.JCR_PRIMARYTYPE).getString());
        } catch (NameException e) {
        // ignore. should never occur
        }
        int depth = batchReadConfig.getDepth(ntName);
        if (depth == BatchReadConfig.DEPTH_DEFAULT) {
            NodeInfo info;
            try {
                info = new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver());
            } catch (NameException e) {
                throw new RepositoryException(e);
            }
            return Collections.singletonList(info).iterator();
        } else {
            final List<ItemInfo> itemInfos = new ArrayList<ItemInfo>();
            ItemVisitor visitor = new TraversingItemVisitor(false, depth) {

                @Override
                protected void entering(Property property, int i) throws RepositoryException {
                    try {
                        itemInfos.add(new PropertyInfoImpl(property, idFactory, sInfo.getNamePathResolver(), getQValueFactory()));
                    } catch (NameException e) {
                        throw new RepositoryException(e);
                    }
                }

                @Override
                protected void entering(Node node, int i) throws RepositoryException {
                    try {
                        itemInfos.add(new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver()));
                    } catch (NameException e) {
                        throw new RepositoryException(e);
                    }
                }

                @Override
                protected void leaving(Property property, int i) {
                // nothing to do
                }

                @Override
                protected void leaving(Node node, int i) {
                // nothing to do
                }
            };
            visitor.visit(node);
            return itemInfos.iterator();
        }
    }
}
Also used : ItemInfo(org.apache.jackrabbit.spi.ItemInfo) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) PropertyId(org.apache.jackrabbit.spi.PropertyId) Name(org.apache.jackrabbit.spi.Name) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) ItemVisitor(javax.jcr.ItemVisitor) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Property(javax.jcr.Property)

Aggregations

NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)65 RepositoryException (javax.jcr.RepositoryException)44 Name (org.apache.jackrabbit.spi.Name)38 Path (org.apache.jackrabbit.spi.Path)20 NamespaceException (javax.jcr.NamespaceException)17 ArrayList (java.util.ArrayList)16 IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)9 SAXException (org.xml.sax.SAXException)8 Node (javax.jcr.Node)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)6 InvalidQueryException (javax.jcr.query.InvalidQueryException)6 NodeId (org.apache.jackrabbit.core.id.NodeId)6 IOException (java.io.IOException)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 PathNotFoundException (javax.jcr.PathNotFoundException)5 Value (javax.jcr.Value)5 LocationStepQueryNode (org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode)5 AccessDeniedException (javax.jcr.AccessDeniedException)4 NodeType (javax.jcr.nodetype.NodeType)4 VersionException (javax.jcr.version.VersionException)4