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();
}
}
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);
}
}
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);
}
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;
}
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);
}
Aggregations