Search in sources :

Example 66 with VersionException

use of javax.jcr.version.VersionException in project jackrabbit by apache.

the class SessionImpl method importXML.

/**
     * @see javax.jcr.Session#importXML(String, java.io.InputStream, int)
     */
@Override
public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, PathNotFoundException, ItemExistsException, ConstraintViolationException, VersionException, InvalidSerializedDataException, LockException, RepositoryException {
    // NOTE: checks are performed by 'getImportContentHandler'
    ImportHandler handler = (ImportHandler) getImportContentHandler(parentAbsPath, uuidBehavior);
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
        SAXParser parser = factory.newSAXParser();
        parser.parse(new InputSource(in), handler);
    } catch (SAXException se) {
        // check for wrapped repository exception
        Exception e = se.getException();
        if (e != null && e instanceof RepositoryException) {
            throw (RepositoryException) e;
        } else {
            String msg = "failed to parse XML stream";
            log.debug(msg);
            throw new InvalidSerializedDataException(msg, se);
        }
    } catch (ParserConfigurationException e) {
        throw new RepositoryException("SAX parser configuration error", e);
    } finally {
        // JCR-2903
        in.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) ImportHandler(org.apache.jackrabbit.jcr2spi.xml.ImportHandler) SAXParser(javax.xml.parsers.SAXParser) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) RepositoryException(javax.jcr.RepositoryException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ItemExistsException(javax.jcr.ItemExistsException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) VersionException(javax.jcr.version.VersionException) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemNotFoundException(javax.jcr.ItemNotFoundException) LoginException(javax.jcr.LoginException) SAXException(org.xml.sax.SAXException) AccessControlException(java.security.AccessControlException) AccessDeniedException(javax.jcr.AccessDeniedException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) NamespaceException(javax.jcr.NamespaceException) IOException(java.io.IOException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 67 with VersionException

use of javax.jcr.version.VersionException in project jackrabbit by apache.

the class VersionHistoryImpl method getVersionState.

/**
     *
     * @param versionName
     * @return
     * @throws VersionException
     * @throws RepositoryException
     */
private NodeState getVersionState(String versionName) throws VersionException, RepositoryException {
    try {
        Name vName = session.getNameResolver().getQName(versionName);
        refreshEntry(vhEntry);
        NodeEntry vEntry = vhEntry.getNodeEntry(vName, Path.INDEX_DEFAULT, true);
        if (vEntry == null) {
            throw new VersionException("Version '" + versionName + "' does not exist in this version history.");
        } else {
            return vEntry.getNodeState();
        }
    } catch (org.apache.jackrabbit.spi.commons.conversion.NameException e) {
        throw new RepositoryException(e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) VersionException(javax.jcr.version.VersionException)

Example 68 with VersionException

use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.

the class VersionHistoryDelegate method getVersion.

/**
     * Gets the version with the given name.
     *
     * @param versionName a version name.
     * @return the version delegate.
     * @throws VersionException if there is no version with the given name.
     * @throws RepositoryException if another error occurs.
     */
@Nonnull
public VersionDelegate getVersion(@Nonnull String versionName) throws VersionException, RepositoryException {
    checkNotNull(versionName);
    Tree version = getTree().getChild(versionName);
    if (!version.exists()) {
        throw new VersionException("No such Version: " + versionName);
    }
    return VersionDelegate.create(sessionDelegate, version);
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) LabelExistsVersionException(javax.jcr.version.LabelExistsVersionException) VersionException(javax.jcr.version.VersionException) Nonnull(javax.annotation.Nonnull)

Example 69 with VersionException

use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.

the class QueryImpl method storeAsNode.

@Override
public Node storeAsNode(String absPath) throws RepositoryException {
    manager.ensureIsAlive();
    String oakPath = sessionContext.getOakPathOrThrow(absPath);
    String parent = PathUtils.getParentPath(oakPath);
    NodeDelegate parentDelegate = sessionContext.getSessionDelegate().getNode(parent);
    if (parentDelegate == null) {
        throw new PathNotFoundException("The specified path does not exist: " + parent);
    }
    Node parentNode = NodeImpl.createNode(parentDelegate, sessionContext);
    if (!parentNode.isCheckedOut()) {
        throw new VersionException("Cannot store query. Node at " + absPath + " is checked in.");
    }
    String nodeName = PathUtils.getName(oakPath);
    ValueFactory vf = sessionContext.getValueFactory();
    Node n = parentNode.addNode(nodeName, JcrConstants.NT_QUERY);
    n.setProperty(JcrConstants.JCR_STATEMENT, vf.createValue(statement));
    n.setProperty(JcrConstants.JCR_LANGUAGE, vf.createValue(language));
    setStoredQueryPath(oakPath);
    return n;
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) ValueFactory(javax.jcr.ValueFactory) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) VersionException(javax.jcr.version.VersionException)

Example 70 with VersionException

use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.

the class VersionHistoryDelegate method getVersionByLabel.

@Nonnull
public VersionDelegate getVersionByLabel(@Nonnull String label) throws VersionException, RepositoryException {
    checkNotNull(label);
    Tree versionLabels = getVersionLabelsTree();
    PropertyState p = versionLabels.getProperty(label);
    if (p == null) {
        throw new VersionException("Unknown label: " + label);
    }
    String id = p.getValue(Type.REFERENCE);
    Tree version = sessionDelegate.getIdManager().getTree(id);
    if (version == null || !version.exists()) {
        throw new VersionException("Invalid label: " + label + '(' + id + ')');
    }
    return VersionDelegate.create(sessionDelegate, version);
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) LabelExistsVersionException(javax.jcr.version.LabelExistsVersionException) VersionException(javax.jcr.version.VersionException) Nonnull(javax.annotation.Nonnull)

Aggregations

VersionException (javax.jcr.version.VersionException)78 Node (javax.jcr.Node)25 Version (javax.jcr.version.Version)25 RepositoryException (javax.jcr.RepositoryException)19 Name (org.apache.jackrabbit.spi.Name)8 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)7 Property (javax.jcr.Property)6 Session (javax.jcr.Session)6 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)6 VersionIterator (javax.jcr.version.VersionIterator)5 VersionManager (javax.jcr.version.VersionManager)5 NodeId (org.apache.jackrabbit.core.id.NodeId)5 Nonnull (javax.annotation.Nonnull)4 ItemExistsException (javax.jcr.ItemExistsException)4 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)4 RetentionManager (javax.jcr.retention.RetentionManager)4 LabelExistsVersionException (javax.jcr.version.LabelExistsVersionException)4 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)4 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4