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.
/*
* eXist-db Open Source Native XML Database
* Copyright (C) 2001 The eXist-db Authors
*
* [email protected]
* http://www.exist-db.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.exist.collections;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.exist.EXistException;
import org.exist.Namespaces;
import org.exist.collections.triggers.TriggerException;
import org.exist.dom.persistent.BinaryDocument;
import org.exist.dom.persistent.DocumentImpl;
import org.exist.dom.memtree.SAXAdapter;
import org.exist.security.PermissionDeniedException;
import org.exist.storage.*;
import org.exist.storage.lock.Lock.LockMode;
import org.exist.storage.lock.ManagedLock;
import org.exist.storage.txn.TransactionManager;
import org.exist.storage.txn.Txn;
import org.exist.util.LockException;
import org.exist.util.MimeType;
import org.exist.util.StringInputSource;
import org.exist.util.XMLReaderPool;
import org.exist.util.sanity.SanityCheck;
import org.exist.xmldb.XmldbURI;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.*;
import java.util.concurrent.locks.ReadWriteLock;
/**
* Manages index configurations. Index configurations are stored in a collection
* hierarchy below /db/system/config. CollectionConfigurationManager is called
* by {@link org.exist.collections.Collection} to retrieve the
* {@link org.exist.collections.CollectionConfiguration} instance for a given
* collection.
*
* @author wolf
*/
public class CollectionConfigurationManager implements BrokerPoolService {
private static final Logger LOG = LogManager.getLogger(CollectionConfigurationManager.class);
public static final String CONFIG_COLLECTION = XmldbURI.SYSTEM_COLLECTION + "/config";
/** /db/system/config **/
public static final XmldbURI CONFIG_COLLECTION_URI = XmldbURI.create(CONFIG_COLLECTION);
/** /db/system/config/db **/
public static final XmldbURI ROOT_COLLECTION_CONFIG_URI = CONFIG_COLLECTION_URI.append(XmldbURI.ROOT_COLLECTION_NAME);
public static final CollectionURI COLLECTION_CONFIG_PATH = new CollectionURI(CONFIG_COLLECTION_URI.getRawCollectionPath());
private final Map configurations = new HashMap<>();
private final ReadWriteLock lock = new java.util.concurrent.locks.ReentrantReadWriteLock();
private final CollectionConfiguration defaultConfig;
public CollectionConfigurationManager(final BrokerPool brokerPool) {
this.defaultConfig = new CollectionConfiguration(brokerPool);
}
@Override
public void startSystem(final DBBroker systemBroker, final Txn transaction) throws BrokerPoolServiceException {
try {
checkCreateCollection(systemBroker, transaction, CONFIG_COLLECTION_URI);
checkCreateCollection(systemBroker, transaction, ROOT_COLLECTION_CONFIG_URI);
loadAllConfigurations(systemBroker);
defaultConfig.setIndexConfiguration(systemBroker.getIndexConfiguration());
} catch(final EXistException | CollectionConfigurationException | PermissionDeniedException | LockException e) {
throw new BrokerPoolServiceException(e);
}
}
/**
* Add a new collection configuration. The XML document is passed as a
* string.
*
* @param txn The transaction that will hold the WRITE locks until they are
* released by commit()/abort()
* @param broker the eXist-db broker
* @param collection the collection to which the configuration applies.
* @param config the xconf document as a String.
* @throws CollectionConfigurationException if config is invalid
*/
public void addConfiguration(final Txn txn, final DBBroker broker, final Collection collection, final String config) throws CollectionConfigurationException {
try {
final XmldbURI path = CONFIG_COLLECTION_URI.append(collection.getURI());
final Collection confCol = broker.getOrCreateCollection(txn, path);
if (confCol == null) {
throw new CollectionConfigurationException("Failed to create config collection: " + path);
}
XmldbURI configurationDocumentName = null;
// Replaces the current configuration file if there is one
final CollectionConfiguration conf = getConfiguration(collection);
if (conf != null) {
configurationDocumentName = conf.getDocName();
if (configurationDocumentName != null) {
LOG.warn("Replacing current configuration file '{}'", configurationDocumentName);
}
}
if (configurationDocumentName == null) {
configurationDocumentName = CollectionConfiguration.DEFAULT_COLLECTION_CONFIG_FILE_URI;
}
broker.saveCollection(txn, confCol);
broker.storeDocument(txn, configurationDocumentName, new StringInputSource(config), MimeType.XML_TYPE, confCol);
// broker.sync(Sync.MAJOR_SYNC);
} catch (final CollectionConfigurationException e) {
throw e;
} catch (final Exception e) {
throw new CollectionConfigurationException("Failed to store collection configuration: " + e.getMessage(), e);
}
}
/**
* Check the passed collection configuration. Throws an exception if errors
* are detected in the configuration document. Note: some configuration
* settings depend on the current environment, in particular the
* availability of trigger or index classes.
*
* @param broker DBBroker
* @param config the configuration to test
* @throws CollectionConfigurationException if errors were detected
*/
public void testConfiguration(DBBroker broker, String config) throws CollectionConfigurationException {
try {
final SAXAdapter adapter = new SAXAdapter();
final InputSource src = new InputSource(new StringReader(config));
final XMLReaderPool parserPool = broker.getBrokerPool().getParserPool();
XMLReader reader = null;
try {
reader = parserPool.borrowXMLReader();
reader.setContentHandler(adapter);
reader.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter);
reader.parse(src);
} finally {
if (reader != null) {
parserPool.returnXMLReader(reader);
}
}
final Document doc = adapter.getDocument();
final CollectionConfiguration conf = new CollectionConfiguration(broker.getBrokerPool());
conf.read(broker, doc, true, null, null);
} catch (final Exception e) {
throw new CollectionConfigurationException(e);
}
}
public List