Search in sources :

Example 6 with FileSystem

use of org.apache.jackrabbit.core.fs.FileSystem in project jackrabbit by apache.

the class RetentionRegistryImplTest method createFileSystem.

private FileSystem createFileSystem() {
    FileSystem fs = new MemoryFileSystem();
    BufferedWriter writer = null;
    try {
        fs.createFolder("/");
        FileSystemResource file = new FileSystemResource(fs, "/retention");
        writer = new BufferedWriter(new OutputStreamWriter(file.getOutputStream()));
        writer.write(((NodeImpl) childN).getNodeId().toString());
    } catch (FileSystemException e) {
        log.error(e.getMessage());
    } catch (IOException e) {
        log.error(e.getMessage());
    } finally {
        IOUtils.closeQuietly(writer);
    }
    return fs;
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) MemoryFileSystem(org.apache.jackrabbit.core.fs.mem.MemoryFileSystem) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) MemoryFileSystem(org.apache.jackrabbit.core.fs.mem.MemoryFileSystem) OutputStreamWriter(java.io.OutputStreamWriter) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 7 with FileSystem

use of org.apache.jackrabbit.core.fs.FileSystem in project jackrabbit by apache.

the class CustomPrivilegeTest method testCustomEquivalentDefinitions.

public void testCustomEquivalentDefinitions() throws RepositoryException, FileSystemException, IOException {
    // setup the custom privilege file with cyclic references
    FileSystem fs = ((RepositoryImpl) superuser.getRepository()).getConfig().getFileSystem();
    FileSystemResource resource = new FileSystemResource(fs, "/privileges/custom_privileges.xml");
    if (!resource.exists()) {
        resource.makeParentDirs();
    }
    NameFactory nf = NameFactoryImpl.getInstance();
    Name test = nf.create(Name.NS_DEFAULT_URI, "test");
    Name test2 = nf.create(Name.NS_DEFAULT_URI, "test2");
    Name test3 = nf.create(Name.NS_DEFAULT_URI, "test3");
    Name test4 = nf.create(Name.NS_DEFAULT_URI, "test4");
    Name test5 = nf.create(Name.NS_DEFAULT_URI, "test5");
    Name test6 = nf.create(Name.NS_DEFAULT_URI, "test6");
    OutputStream out = resource.getOutputStream();
    try {
        List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
        defs.add(new PrivilegeDefinitionImpl(test, false, createNameSet(test2, test3)));
        defs.add(new PrivilegeDefinitionImpl(test2, true, Collections.singleton(test4)));
        defs.add(new PrivilegeDefinitionImpl(test3, true, Collections.singleton(test5)));
        defs.add(new PrivilegeDefinitionImpl(test4, true, Collections.<Name>emptySet()));
        defs.add(new PrivilegeDefinitionImpl(test5, true, Collections.<Name>emptySet()));
        // the equivalent definition to 'test'
        defs.add(new PrivilegeDefinitionImpl(test6, false, createNameSet(test2, test5)));
        PrivilegeDefinitionWriter pdw = new PrivilegeDefinitionWriter("text/xml");
        pdw.writeDefinitions(out, defs.toArray(new PrivilegeDefinition[defs.size()]), Collections.<String, String>emptyMap());
        new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
        fail("Equivalent definitions must be detected upon registry startup.");
    } catch (RepositoryException e) {
    // success
    } finally {
        out.close();
        fs.deleteFolder("/privileges");
    }
}
Also used : PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) PrivilegeDefinitionWriter(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter) NameFactory(org.apache.jackrabbit.spi.NameFactory) Name(org.apache.jackrabbit.spi.Name)

Example 8 with FileSystem

use of org.apache.jackrabbit.core.fs.FileSystem in project jackrabbit-oak by apache.

the class RepositoryUpgrade method loadProperties.

private Properties loadProperties(String path) throws RepositoryException {
    Properties properties = new Properties();
    FileSystem filesystem = source.getFileSystem();
    try {
        if (filesystem.exists(path)) {
            InputStream stream = filesystem.getInputStream(path);
            try {
                properties.load(stream);
            } finally {
                stream.close();
            }
        }
    } catch (FileSystemException e) {
        throw new RepositoryException(e);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
    return properties;
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) InputStream(java.io.InputStream) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) NodeStateCopier.copyProperties(org.apache.jackrabbit.oak.upgrade.nodestate.NodeStateCopier.copyProperties) Properties(java.util.Properties)

Example 9 with FileSystem

use of org.apache.jackrabbit.core.fs.FileSystem 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)

Example 10 with FileSystem

use of org.apache.jackrabbit.core.fs.FileSystem in project jackrabbit by apache.

the class RetentionRegistryImplTest method testWriteFile.

public void testWriteFile() throws RepositoryException {
    PathResolver resolver = (SessionImpl) superuser;
    FileSystem fs = createFileSystem();
    RetentionRegistryImpl re = new RetentionRegistryImpl((SessionImpl) superuser, fs);
    try {
        // write the changes to the fs
        re.close();
        // create a new dummy registry again.
        re = new RetentionRegistryImpl((SessionImpl) superuser, fs);
        // test holds
        assertTrue(re.hasEffectiveHold(resolver.getQPath(childNPath), false));
        assertTrue(re.hasEffectiveHold(resolver.getQPath(childN3.getPath()), false));
        assertTrue(re.hasEffectiveHold(resolver.getQPath(childNPath + "/somechild"), false));
        assertTrue(re.hasEffectiveHold(resolver.getQPath(childNPath + "/hold/is/deep"), false));
        // test policies
        assertTrue(re.hasEffectiveRetention(resolver.getQPath(childNPath), false));
        assertTrue(re.hasEffectiveRetention(resolver.getQPath(childNPath + "/somechild"), true));
    } finally {
        re.close();
    }
}
Also used : FileSystem(org.apache.jackrabbit.core.fs.FileSystem) MemoryFileSystem(org.apache.jackrabbit.core.fs.mem.MemoryFileSystem) PathResolver(org.apache.jackrabbit.spi.commons.conversion.PathResolver) RetentionRegistryImpl(org.apache.jackrabbit.core.retention.RetentionRegistryImpl)

Aggregations

FileSystem (org.apache.jackrabbit.core.fs.FileSystem)13 RepositoryException (javax.jcr.RepositoryException)8 IOException (java.io.IOException)5 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)5 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)4 File (java.io.File)3 OutputStreamWriter (java.io.OutputStreamWriter)3 MemoryFileSystem (org.apache.jackrabbit.core.fs.mem.MemoryFileSystem)3 PrivilegeDefinitionWriter (org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter)3 OutputStream (java.io.OutputStream)2 Writer (java.io.Writer)2 ArrayList (java.util.ArrayList)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 RetentionRegistryImpl (org.apache.jackrabbit.core.retention.RetentionRegistryImpl)2 Name (org.apache.jackrabbit.spi.Name)2 NameFactory (org.apache.jackrabbit.spi.NameFactory)2 PrivilegeDefinition (org.apache.jackrabbit.spi.PrivilegeDefinition)2 PathResolver (org.apache.jackrabbit.spi.commons.conversion.PathResolver)2 PrivilegeDefinitionImpl (org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl)2