Search in sources :

Example 56 with NameException

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

the class IdFactoryImpl method createPropertyId.

/**
     * Creates a <code>PropertyId</code> for the given <code>property</code>.
     *
     * @param property   the JCR Property.
     * @param resolver
     * @return the <code>PropertyId</code> for <code>property</code>.
     * @throws RepositoryException if an error occurs while reading from
     *                             <code>property</code>.
     */
public PropertyId createPropertyId(Property property, NamePathResolver resolver) throws RepositoryException {
    Node parent = property.getParent();
    NodeId nodeId = createNodeId(parent);
    String jcrName = property.getName();
    Name name;
    try {
        name = resolver.getQName(jcrName);
    } catch (NameException e) {
        throw new RepositoryException(e.getMessage(), e);
    }
    return createPropertyId(nodeId, name);
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Node(javax.jcr.Node) NodeId(org.apache.jackrabbit.spi.NodeId) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 57 with NameException

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

the class RepositoryServiceImpl method getNodeInfo.

/**
     * {@inheritDoc}
     */
public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws ItemNotFoundException, RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    Node node = getNode(nodeId, sInfo);
    try {
        return new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver());
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 58 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, Name[] nodetypeNames) throws RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
    List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>();
    for (Name nodetypeName : nodetypeNames) {
        try {
            String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeName);
            NodeType nt = ntMgr.getNodeType(ntName);
            defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
            // in addition pack all supertypes into the return value
            NodeType[] supertypes = nt.getSupertypes();
            for (NodeType supertype : supertypes) {
                defs.add(new QNodeTypeDefinitionImpl(supertype, sInfo.getNamePathResolver(), getQValueFactory()));
            }
        } catch (NameException e) {
            throw new RepositoryException(e);
        }
    }
    return defs.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) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)

Example 59 with NameException

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

the class AddNodeOperation method perform.

public Node perform(SessionContext context) throws RepositoryException {
    ItemManager itemMgr = context.getItemManager();
    // Get the canonical path of the new node
    Path path;
    try {
        path = PathFactoryImpl.getInstance().create(node.getPrimaryPath(), context.getQPath(relPath), true);
    } catch (NameException e) {
        throw new RepositoryException("Failed to resolve path " + relPath + " relative to " + node, e);
    }
    // Check that the last path element is a simple name
    if (!path.denotesName() || path.getIndex() != Path.INDEX_UNDEFINED) {
        throw new RepositoryException("Invalid last path element for adding node " + relPath + " relative to " + node);
    }
    // Get the parent node instance
    NodeImpl parentNode;
    Path parentPath = path.getAncestor(1);
    try {
        parentNode = itemMgr.getNode(parentPath);
    } catch (PathNotFoundException e) {
        if (itemMgr.propertyExists(parentPath)) {
            throw new ConstraintViolationException("Unable to add a child node to property " + context.getJCRPath(parentPath));
        }
        throw e;
    } catch (AccessDeniedException ade) {
        throw new PathNotFoundException("Failed to resolve path " + relPath + " relative to " + node);
    }
    // Resolve node type name (if any)
    Name typeName = null;
    if (nodeTypeName != null) {
        typeName = context.getQName(nodeTypeName);
    }
    // Check that the given UUID (if any) does not already exist
    NodeId id = null;
    if (uuid != null) {
        id = new NodeId(uuid);
        if (itemMgr.itemExists(id)) {
            throw new ItemExistsException("A node with this UUID already exists: " + uuid);
        }
    }
    return parentNode.addNode(path.getName(), typeName, id);
}
Also used : Path(org.apache.jackrabbit.spi.Path) AccessDeniedException(javax.jcr.AccessDeniedException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeImpl(org.apache.jackrabbit.core.NodeImpl) ItemManager(org.apache.jackrabbit.core.ItemManager) ItemExistsException(javax.jcr.ItemExistsException) NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Name(org.apache.jackrabbit.spi.Name)

Example 60 with NameException

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

the class ObservationManagerImpl method createEventFilter.

/**
     * Creates an SPI event filter from the given list of constraints.
     *
     * @param eventTypes    the event types.
     * @param absPath       an absolute path.
     * @param isDeep        whether to include events for descendant items of
     *                      the node at absPath.
     * @param uuids         uuid filters.
     * @param nodeTypeNames node type filters.
     * @param noLocal       whether to exclude changes from the local session.
     * @return the SPI event filter instance.
     * @throws RepositoryException if an error occurs while creating the event
     *                             filter.
     */
private EventFilter createEventFilter(int eventTypes, String absPath, boolean isDeep, String[] uuids, String[] nodeTypeNames, boolean noLocal) throws RepositoryException {
    Path path;
    try {
        path = resolver.getQPath(absPath).getCanonicalPath();
    } catch (NameException e) {
        throw new RepositoryException("Malformed path: " + absPath);
    }
    // create NodeType instances from names
    Name[] qNodeTypeNames;
    if (nodeTypeNames == null) {
        qNodeTypeNames = null;
    } else {
        try {
            qNodeTypeNames = new Name[nodeTypeNames.length];
            for (int i = 0; i < nodeTypeNames.length; i++) {
                Name ntName = resolver.getQName(nodeTypeNames[i]);
                if (!ntRegistry.isRegistered(ntName)) {
                    throw new RepositoryException("unknown node type: " + nodeTypeNames[i]);
                }
                qNodeTypeNames[i] = ntName;
            }
        } catch (NameException e) {
            throw new RepositoryException(e.getMessage());
        }
    }
    return wspManager.createEventFilter(eventTypes, path, isDeep, uuids, qNodeTypeNames, noLocal);
}
Also used : Path(org.apache.jackrabbit.spi.Path) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

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