Search in sources :

Example 1 with QueryHandlerFactory

use of org.apache.jackrabbit.core.query.QueryHandlerFactory in project jackrabbit by apache.

the class RepositoryConfigurationParser method parseRepositoryConfig.

/**
     * Parses repository configuration. Repository configuration uses the
     * following format:
     * <pre>
     *   &lt;Repository&gt;
     *     &lt;FileSystem ...&gt;
     *     &lt;Security appName="..."&gt;
     *       &lt;SecurityManager ...&gt;
     *       &lt;AccessManager ...&gt;
     *       &lt;LoginModule ... (optional)&gt;
     *     &lt;/Security&gt;
     *     &lt;Workspaces rootPath="..." defaultWorkspace="..."/&gt;
     *     &lt;Workspace ...&gt;
     *     &lt;Versioning ...&gt;
     *   &lt;/Repository&gt;
     * </pre>
     * <p>
     * The <code>FileSystem</code> element is a
     * {@link #parseBeanConfig(Element,String) bean configuration} element,
     * that specifies the file system implementation for storing global
     * repository information. The <code>Security</code> element contains
     * an <code>AccessManager</code> bean configuration element and the
     * JAAS name of the repository application. The <code>Workspaces</code>
     * element contains general workspace parameters, and the
     * <code>Workspace</code> element is a template for the individual
     * workspace configuration files. The <code>Versioning</code> element
     * contains
     * {@link #parseVersioningConfig(Element) versioning configuration} for
     * the repository.
     * <p>
     * In addition to the configured information, the returned repository
     * configuration object also contains the repository home directory path
     * that is given as the ${rep.home} parser variable. Note that the
     * variable <em>must</em> be available for the configuration document to
     * be correctly parsed.
     * <p>
     * {@link #replaceVariables(String) Variable replacement} is performed
     * on the security application name attribute, the general workspace
     * configuration attributes, and on the file system, access manager,
     * and versioning configuration information.
     * <p>
     * Note that the returned repository configuration object has not been
     * initialized.
     *
     * @param xml repository configuration document
     * @return repository configuration
     * @throws ConfigurationException if the configuration is broken
     * @see #parseBeanConfig(Element, String)
     * @see #parseVersioningConfig(Element)
     */
public RepositoryConfig parseRepositoryConfig(InputSource xml) throws ConfigurationException {
    Element root = parseXML(xml, true);
    // Repository home directory
    String home = getVariables().getProperty(REPOSITORY_HOME_VARIABLE);
    // File system implementation
    FileSystemFactory fsf = getFileSystemFactory(root, FILE_SYSTEM_ELEMENT);
    // Security configuration and access manager implementation
    Element security = getElement(root, SECURITY_ELEMENT);
    SecurityConfig securityConfig = parseSecurityConfig(security);
    // General workspace configuration
    Element workspaces = getElement(root, WORKSPACES_ELEMENT);
    String workspaceDirectory = replaceVariables(getAttribute(workspaces, ROOT_PATH_ATTRIBUTE));
    String workspaceConfigDirectory = getAttribute(workspaces, CONFIG_ROOT_PATH_ATTRIBUTE, null);
    String defaultWorkspace = replaceVariables(getAttribute(workspaces, DEFAULT_WORKSPACE_ATTRIBUTE));
    int maxIdleTime = Integer.parseInt(getAttribute(workspaces, MAX_IDLE_TIME_ATTRIBUTE, "0"));
    // Workspace configuration template
    Element template = getElement(root, WORKSPACE_ELEMENT);
    // Versioning configuration
    VersioningConfig vc = parseVersioningConfig(root);
    // Query handler implementation
    QueryHandlerFactory qhf = getQueryHandlerFactory(root);
    // Optional journal configuration
    ClusterConfig cc = parseClusterConfig(root, new File(home));
    // Optional data store factory
    DataStoreFactory dsf = getDataStoreFactory(root, home);
    RepositoryLockMechanismFactory rlf = getRepositoryLockMechanismFactory(root);
    // Optional data source configuration
    DataSourceConfig dsc = parseDataSourceConfig(root);
    return new RepositoryConfig(home, securityConfig, fsf, workspaceDirectory, workspaceConfigDirectory, defaultWorkspace, maxIdleTime, template, vc, qhf, cc, dsf, rlf, dsc, connectionFactory, this);
}
Also used : Element(org.w3c.dom.Element) FileSystemFactory(org.apache.jackrabbit.core.fs.FileSystemFactory) RepositoryLockMechanismFactory(org.apache.jackrabbit.core.util.RepositoryLockMechanismFactory) QueryHandlerFactory(org.apache.jackrabbit.core.query.QueryHandlerFactory) File(java.io.File) DataStoreFactory(org.apache.jackrabbit.core.data.DataStoreFactory)

Example 2 with QueryHandlerFactory

use of org.apache.jackrabbit.core.query.QueryHandlerFactory in project jackrabbit by apache.

the class RepositoryConfigurationParser method parseWorkspaceConfig.

/**
     * Parse workspace config.
     *
     * @param root root element of the workspace configuration
     * @return The workspace configuration
     * @throws ConfigurationException
     * @see #parseWorkspaceConfig(InputSource)
     */
protected WorkspaceConfig parseWorkspaceConfig(Element root) throws ConfigurationException {
    // Workspace home directory
    String home = getVariables().getProperty(WORKSPACE_HOME_VARIABLE);
    // Workspace name
    String name = getAttribute(root, "name", new File(home).getName());
    // Clustered attribute
    boolean clustered = Boolean.valueOf(getAttribute(root, CLUSTERED_ATTRIBUTE, "true"));
    // Create a temporary parser that contains the ${wsp.name} variable
    Properties tmpVariables = (Properties) getVariables().clone();
    tmpVariables.put(WORKSPACE_NAME_VARIABLE, name);
    RepositoryConfigurationParser tmpParser = createSubParser(tmpVariables);
    // File system implementation
    FileSystemFactory fsf = tmpParser.getFileSystemFactory(root, FILE_SYSTEM_ELEMENT);
    // Persistence manager implementation
    PersistenceManagerConfig pmc = tmpParser.parsePersistenceManagerConfig(root);
    // Query handler implementation
    QueryHandlerFactory qhf = tmpParser.getQueryHandlerFactory(root);
    // Item state manager locking configuration (optional)
    ISMLockingFactory ismLockingFactory = tmpParser.getISMLockingFactory(root);
    // workspace specific security configuration
    WorkspaceSecurityConfig workspaceSecurityConfig = tmpParser.parseWorkspaceSecurityConfig(root);
    // optional config for import handling
    ImportConfig importConfig = tmpParser.parseImportConfig(root);
    // default lock timeout
    String to = getAttribute(root, "defaultLockTimeout", new Long(Long.MAX_VALUE).toString());
    long defaultLockTimeout;
    try {
        defaultLockTimeout = Long.parseLong(to);
    } catch (NumberFormatException ex) {
        throw new ConfigurationException("defaultLockTimeout must be an integer value", ex);
    }
    return new WorkspaceConfig(home, name, clustered, fsf, pmc, qhf, ismLockingFactory, workspaceSecurityConfig, importConfig, defaultLockTimeout);
}
Also used : Properties(java.util.Properties) FileSystemFactory(org.apache.jackrabbit.core.fs.FileSystemFactory) QueryHandlerFactory(org.apache.jackrabbit.core.query.QueryHandlerFactory) ISMLockingFactory(org.apache.jackrabbit.core.state.ISMLockingFactory) File(java.io.File)

Example 3 with QueryHandlerFactory

use of org.apache.jackrabbit.core.query.QueryHandlerFactory in project jackrabbit by apache.

the class RepositoryConfigurationParser method getQueryHandlerFactory.

/**
     * Parses search index configuration. Search index configuration
     * uses the following format:
     * <pre>
     *   &lt;SearchIndex class="..."&gt;
     *     &lt;param name="..." value="..."&gt;
     *     ...
     *     &lt;FileSystem ...&gt;
     *   &lt;/Search&gt;
     * </pre>
     * <p>
     * Both the <code>SearchIndex</code> and <code>FileSystem</code>
     * elements are {@link #parseBeanConfig(Element,String) bean configuration}
     * elements. If the search implementation class is not given, then
     * a default implementation is used.
     * <p>
     * The search index is an optional feature of workspace configuration.
     * If the search configuration element is not found, then this method
     * returns <code>null</code>.
     * <p>
     * The FileSystem element in a search index configuration is optional.
     * However some implementations may require a FileSystem.
     *
     * @param parent parent of the <code>SearchIndex</code> element
     * @return query handler factory
     */
protected QueryHandlerFactory getQueryHandlerFactory(final Element parent) {
    NodeList children = parent.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        final Node child = children.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE && SEARCH_INDEX_ELEMENT.equals(child.getNodeName())) {
            return new QueryHandlerFactory() {

                public QueryHandler getQueryHandler(QueryHandlerContext context) throws RepositoryException {
                    Element element = (Element) child;
                    // Optional file system implementation
                    FileSystem fs = null;
                    if (getElement(element, FILE_SYSTEM_ELEMENT, false) != null) {
                        fs = getFileSystemFactory(element, FILE_SYSTEM_ELEMENT).getFileSystem();
                    }
                    // Search implementation class
                    String className = getAttribute(element, CLASS_ATTRIBUTE, DEFAULT_QUERY_HANDLER);
                    BeanConfig config = new BeanConfig(className, parseParameters(element));
                    QueryHandler handler = config.newInstance(QueryHandler.class);
                    try {
                        handler.init(fs, context);
                        return handler;
                    } catch (IOException e) {
                        throw new RepositoryException("Unable to initialize query handler: " + handler, e);
                    }
                }
            };
        }
    }
    return null;
}
Also used : QueryHandlerFactory(org.apache.jackrabbit.core.query.QueryHandlerFactory) QueryHandler(org.apache.jackrabbit.core.query.QueryHandler) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) Element(org.w3c.dom.Element) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) RepositoryException(javax.jcr.RepositoryException) QueryHandlerContext(org.apache.jackrabbit.core.query.QueryHandlerContext) IOException(java.io.IOException)

Aggregations

QueryHandlerFactory (org.apache.jackrabbit.core.query.QueryHandlerFactory)3 File (java.io.File)2 FileSystemFactory (org.apache.jackrabbit.core.fs.FileSystemFactory)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 Properties (java.util.Properties)1 RepositoryException (javax.jcr.RepositoryException)1 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)1 DataStoreFactory (org.apache.jackrabbit.core.data.DataStoreFactory)1 FileSystem (org.apache.jackrabbit.core.fs.FileSystem)1 QueryHandler (org.apache.jackrabbit.core.query.QueryHandler)1 QueryHandlerContext (org.apache.jackrabbit.core.query.QueryHandlerContext)1 ISMLockingFactory (org.apache.jackrabbit.core.state.ISMLockingFactory)1 RepositoryLockMechanismFactory (org.apache.jackrabbit.core.util.RepositoryLockMechanismFactory)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1