org.apache.jackrabbit.webdav.jcr.JcrDavSession Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackrabbit-jcr-server
Show all versions of jackrabbit-jcr-server
WebDAV server implementations for JCR
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jackrabbit.webdav.jcr;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.DavServletResponse;
import org.apache.jackrabbit.webdav.DavSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.Session;
/**
* JcrDavSession
specific base implementation of the
* DavSession
interface, which simply wraps a {@link Session}
* object. This implementation adds a utility method that allows to
* {@link #getRepositorySession() unwrap} the underlying repository session.
*
* Note, that in this basic implementation the following methods are simply
* forwarded to the corresponding call on Session
:
*
* - {@link #getLockTokens()} => {@link Session#getLockTokens()}
* - {@link #addLockToken(String)} => {@link Session#addLockToken(String)}
* - {@link #removeLockToken(String)} => {@link Session#removeLockToken(String)}
*
* Subclasses may overwrite or extend this behaviour.
*/
public abstract class JcrDavSession implements DavSession {
private static Logger log = LoggerFactory.getLogger(JcrDavSession.class);
/** the underlying jcr session */
private final Session session;
protected JcrDavSession(Session session) {
this.session = session;
}
/**
*
* @param davSession
* @throws DavException
*/
public static void checkImplementation(DavSession davSession) throws DavException {
if (!(davSession instanceof JcrDavSession)) {
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "JCR specific DavSession expected. Found: " + davSession);
}
}
/**
*
* @param davSession
* @return
* @throws DavException
*/
public static Session getRepositorySession(DavSession davSession) throws DavException {
checkImplementation(davSession);
return ((JcrDavSession)davSession).getRepositorySession();
}
/**
* Unwrap the {@link Session repository session} object.
*
* @return the session object wrapped by this DavSession
*/
public Session getRepositorySession() {
return session;
}
//---------------------------------------------------------< DavSession >---
/**
*
* @param token
* @see DavSession#addLockToken(String)
*/
public void addLockToken(String token) {
session.addLockToken(token);
}
/**
*
* @return
* @see DavSession#getLockTokens()
*/
public String[] getLockTokens() {
return session.getLockTokens();
}
/**
*
* @param token
* @see DavSession#removeLockToken(String)
*/
public void removeLockToken(String token) {
session.removeLockToken(token);
}
}