All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.jackrabbit.net.JCRURLHandler Maven / Gradle / Ivy

Go to download

The Jackrabbit Repository Classloader component provides support for loading Java classes from content repositories that implement the Content Repository for Java Technology API (JCR). The component is mostly independent of the underlying JCR implementation.

The newest version!
/*
 * 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.net;

import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;

import javax.jcr.Session;

/**
 * The JCRURLHandler is the URLStreamHandler for
 * JCR Repository URLs identified by the scheme jcr.
 * 

* JCR Repository URLs have not been standardized yet and may only be created * in the context of an existing Session. Therefore this handler * is not globally available and JCR Repository URLs may only be created through * the factory methods in the {@link org.apache.jackrabbit.net.URLFactory} * class. *

* This class is not intended to be subclassed or instantiated by clients. * * @author Felix Meschberger * * @see org.apache.jackrabbit.net.JCRURLConnection * @see org.apache.jackrabbit.net.URLFactory * @see org.apache.jackrabbit.net.URLFactory#createURL(Session, String) */ class JCRURLHandler extends URLStreamHandler { /** * The session used to create this handler, which is also used to open * the connection object. * * @see #getSession() */ private final Session session; /** * Creates a new instance of the JCRURLHandler with the * given session. * * @param session The Session supporting this handler. This * must not be null. * * @throws NullPointerException if session is null. */ JCRURLHandler(Session session) { if (session == null) { throw new NullPointerException("session"); } this.session = session; } /** * Returns the session supporting this handler. */ Session getSession() { return session; } //---------- URLStreamHandler abstracts ------------------------------------ /** * Gets a connection object to connect to an JCR Repository URL. * * @param url The JCR Repository URL to connect to. * * @return An instance of the {@link JCRURLConnection} class. * * @see JCRURLConnection */ protected URLConnection openConnection(URL url) { return new JCRURLConnection(url, this); } /** * Checks the new authority and path before * actually setting the values on the url calling the base class * implementation. *

* We check the authority to not have been modified from the original URL, * as the authority is dependent on the repository Session on * which this handler is based and which was used to create the original * URL. Likewise the repository and workspace name parts of the path must * not have changed. * * @param u the URL to modify. * @param protocol the protocol name. * @param host the remote host value for the URL. * @param port the port on the remote machine. * @param authority the authority part for the URL. * @param userInfo the userInfo part of the URL. * @param path the path component of the URL. * @param query the query part for the URL. * @param ref the reference. * * @throws IllegalArgumentException if the authority or the repository name * or workspace name parts of the path has changed. */ protected void setURL(URL u, String protocol, String host, int port, String authority, String userInfo, String path, String query, String ref) { // check for authority if (u.getAuthority() != authority) { if (u.getAuthority() == null) { if (authority != null) { throw new IllegalArgumentException("Authority " + authority + " not supported by this handler"); } } else if (!u.getAuthority().equals(authority)) { throw new IllegalArgumentException("Authority " + authority + " not supported by this handler"); } } // check for repository and/or workspace modifications FileParts newParts = new FileParts(path); if (!"_".equals(newParts.getRepository())) { throw new IllegalArgumentException("Repository " + newParts.getRepository() + " not supported by this handler"); } if (!session.getWorkspace().getName().equals(newParts.getWorkspace())) { throw new IllegalArgumentException("Workspace " + newParts.getWorkspace() + " not supported by this handler"); } // finally set the new values on the URL super.setURL(u, protocol, host, port, authority, userInfo, path, query, ref); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy