Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.spi.commons;
import java.io.InputStream;
import java.io.Reader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.jcr.AccessDeniedException;
import javax.jcr.Credentials;
import javax.jcr.GuestCredentials;
import javax.jcr.InvalidItemStateException;
import javax.jcr.ItemExistsException;
import javax.jcr.ItemNotFoundException;
import javax.jcr.LoginException;
import javax.jcr.MergeException;
import javax.jcr.NamespaceException;
import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.PathNotFoundException;
import javax.jcr.PropertyType;
import javax.jcr.ReferentialIntegrityException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.SimpleCredentials;
import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.ValueFormatException;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.InvalidNodeTypeDefinitionException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.nodetype.NodeTypeExistsException;
import javax.jcr.query.InvalidQueryException;
import javax.jcr.version.VersionException;
import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader;
import org.apache.jackrabbit.commons.cnd.ParseException;
import org.apache.jackrabbit.spi.Batch;
import org.apache.jackrabbit.spi.EventBundle;
import org.apache.jackrabbit.spi.EventFilter;
import org.apache.jackrabbit.spi.IdFactory;
import org.apache.jackrabbit.spi.ItemId;
import org.apache.jackrabbit.spi.LockInfo;
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.NameFactory;
import org.apache.jackrabbit.spi.NodeId;
import org.apache.jackrabbit.spi.Path;
import org.apache.jackrabbit.spi.PathFactory;
import org.apache.jackrabbit.spi.PropertyId;
import org.apache.jackrabbit.spi.QNodeDefinition;
import org.apache.jackrabbit.spi.QNodeTypeDefinition;
import org.apache.jackrabbit.spi.QPropertyDefinition;
import org.apache.jackrabbit.spi.QValue;
import org.apache.jackrabbit.spi.QValueFactory;
import org.apache.jackrabbit.spi.QueryInfo;
import org.apache.jackrabbit.spi.RepositoryService;
import org.apache.jackrabbit.spi.SessionInfo;
import org.apache.jackrabbit.spi.Subscription;
import org.apache.jackrabbit.spi.Tree;
import org.apache.jackrabbit.spi.commons.identifier.IdFactoryImpl;
import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
import org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping;
import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeStorage;
import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeStorageImpl;
import org.apache.jackrabbit.spi.commons.nodetype.QDefinitionBuilderFactory;
import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
/**
* AbstractRepositoryService provides an abstract base class for
* repository service implementations. This class provides default
* implementations for the following methods:
*
*
{@link #getIdFactory()}
*
{@link #getNameFactory()}
*
{@link #getPathFactory()}
*
{@link #getQValueFactory()}
*
*/
public abstract class AbstractRepositoryService implements RepositoryService {
/**
* The repository descriptors.
*/
protected final Map descriptors = new HashMap();
/**
* The fixed set of namespaces known to the repository service.
*/
protected final NamespaceMapping namespaces = new NamespaceMapping();
/**
* The fixed set of node type definitions known to the repository service.
*/
protected final NodeTypeStorage nodeTypeDefs = new NodeTypeStorageImpl();
/**
* The node definition of the root node.
*/
protected QNodeDefinition rootNodeDefinition;
/**
* @return {@link IdFactoryImpl#getInstance()}.
* @throws RepositoryException if an error occurs.
*/
public IdFactory getIdFactory() throws RepositoryException {
return IdFactoryImpl.getInstance();
}
/**
* @return {@link NameFactoryImpl#getInstance()}.
* @throws RepositoryException if an error occurs.
*/
public NameFactory getNameFactory() throws RepositoryException {
return NameFactoryImpl.getInstance();
}
/**
* @return {@link PathFactoryImpl#getInstance()}.
* @throws RepositoryException if an error occurs.
*/
public PathFactory getPathFactory() throws RepositoryException {
return PathFactoryImpl.getInstance();
}
/**
* @return {@link QValueFactoryImpl#getInstance()}.
* @throws RepositoryException if an error occurs.
*/
public QValueFactory getQValueFactory() throws RepositoryException {
return QValueFactoryImpl.getInstance();
}
protected AbstractRepositoryService() throws RepositoryException {
QValueFactory qvf = QValueFactoryImpl.getInstance();
QValue[] vFalse = new QValue[] {qvf.create(false)};
descriptors.put(Repository.WRITE_SUPPORTED, vFalse);
descriptors.put(Repository.IDENTIFIER_STABILITY,
new QValue[] {qvf.create(Repository.IDENTIFIER_STABILITY_SAVE_DURATION, PropertyType.STRING)});
descriptors.put(Repository.OPTION_XML_IMPORT_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_XML_EXPORT_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_UNFILED_CONTENT_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_VERSIONING_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_SIMPLE_VERSIONING_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_ACCESS_CONTROL_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_LOCKING_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_OBSERVATION_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_JOURNALED_OBSERVATION_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_RETENTION_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_LIFECYCLE_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_TRANSACTIONS_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_UPDATE_PRIMARY_NODE_TYPE_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_UPDATE_MIXIN_NODE_TYPES_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_SHAREABLE_NODES_SUPPORTED, vFalse);
descriptors.put(Repository.OPTION_NODE_TYPE_MANAGEMENT_SUPPORTED, vFalse);
descriptors.put(Repository.QUERY_LANGUAGES, new QValue[0]);
descriptors.put(Repository.QUERY_STORED_QUERIES_SUPPORTED, vFalse);
descriptors.put(Repository.QUERY_FULL_TEXT_SEARCH_SUPPORTED, vFalse);
descriptors.put(Repository.QUERY_JOINS,
new QValue[] {qvf.create(Repository.QUERY_JOINS_NONE, PropertyType.STRING)});
descriptors.putAll(descriptors);
}
public AbstractRepositoryService(Map descriptors,
Map namespaces,
QNodeTypeDefinition[] nodeTypeDefs)
throws RepositoryException {
this();
this.descriptors.putAll(descriptors);
for (Map.Entry entry : namespaces.entrySet()) {
this.namespaces.setMapping(entry.getKey(), entry.getValue());
}
this.nodeTypeDefs.registerNodeTypes(nodeTypeDefs, true);
}
public AbstractRepositoryService(Map descriptors,
Map namespaces,
Reader cnd)
throws RepositoryException {
this();
this.descriptors.putAll(descriptors);
for (Map.Entry entry : namespaces.entrySet()) {
this.namespaces.setMapping(entry.getKey(), entry.getValue());
}
CompactNodeTypeDefReader reader;
try {
reader = new CompactNodeTypeDefReader(cnd, "",
this.namespaces, new QDefinitionBuilderFactory());
List ntds = reader.getNodeTypeDefinitions();
nodeTypeDefs.registerNodeTypes(ntds.toArray(new QNodeTypeDefinition[ntds.size()]), true);
}
catch (ParseException e) {
throw new RepositoryException("Error reading node type definitions", e);
}
}
//---------------------------< subclass responsibility >--------------------
/**
* Create the root node definition.
* @param sessionInfo the session info.
* @return the root node definition for a workspace.
* @throws RepositoryException if an error occurs.
*/
protected abstract QNodeDefinition createRootNodeDefinition(SessionInfo sessionInfo)
throws RepositoryException;
//---------------------< may be overwritten by subclasses>------------------
/**
* Checks if the given credentials are valid. This default
* implementation is empty thus allowing all credentials.
*
* @param credentials the credentials to check.
* @param workspaceName the workspace to access.
* @throws LoginException if the credentials are invalid.
*/
protected void checkCredentials(Credentials credentials, String workspaceName) throws LoginException {
// empty
}
/**
* Checks if the given workspace is available. The default implementation is empty
* thus admitting every workspace name.
* @param workspaceName Name of the workspace to check
* @throws NoSuchWorkspaceException If workspaceName is not available.
*/
protected void checkWorkspace(String workspaceName) throws NoSuchWorkspaceException {
// empty
}
/**
* Creates a session info instance for the given credentials and
* workspaceName. This default implementation creates a
* {@link SessionInfoImpl} instance and sets the userId and
* workspaceName. The user userId is null or the
* userId from credentials if it is of type
* {@link SimpleCredentials}.
*
* @param credentials the credentials.
* @param workspaceName the name of the workspace to access or null
* for the default workspace.
* @return a session info instance for the given credentials and
* workspaceName.
* @throws RepositoryException
*/
protected SessionInfo createSessionInfo(Credentials credentials, String workspaceName)
throws RepositoryException {
String userId = null;
if (credentials instanceof SimpleCredentials) {
userId = ((SimpleCredentials) credentials).getUserID();
}
else if (credentials instanceof GuestCredentials) {
userId = "anonymous";
}
SessionInfoImpl s = new SessionInfoImpl();
s.setUserID(userId);
s.setWorkspacename(workspaceName);
return s;
}
/**
* Creates a session info instance for the given sessionInfo and
* workspaceName. This default implementation creates a
* {@link SessionInfoImpl} instance and sets the userId and
* workspaceName. The user userId is set to the return value of
* {@link SessionInfo#getUserID()}.
*
* @param sessionInfo the sessionInfo.
* @param workspaceName the name of the workspace to access.
* @return a session info instance for the given credentials and
* workspaceName.
* @throws RepositoryException
*/
protected SessionInfo createSessionInfo(SessionInfo sessionInfo, String workspaceName)
throws RepositoryException {
String userId = sessionInfo.getUserID();
SessionInfoImpl s = new SessionInfoImpl();
s.setUserID(userId);
s.setWorkspacename(workspaceName);
return s;
}
/**
* Checks the type of the sessionInfo instance. This default
* implementation checks if sessionInfo is of type
* {@link SessionInfoImpl}, otherwise throws a {@link RepositoryException}.
*
* @param sessionInfo the session info to check.
* @throws RepositoryException if the given sessionInfo is not
* of the required type for this repository
* service implementation.
*/
protected void checkSessionInfo(SessionInfo sessionInfo)
throws RepositoryException {
if (sessionInfo instanceof SessionInfoImpl) {
return;
}
throw new RepositoryException("SessionInfo not of type "
+ SessionInfoImpl.class.getName());
}
//--------------------------< descriptors >---------------------------------
/**
* This default implementation returns the descriptors that were passed
* to the constructor of this repository service.
*/
public Map getRepositoryDescriptors() throws RepositoryException {
return descriptors;
}
//----------------------------< login >-------------------------------------
/**
* This default implementation does:
*