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;
}
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");
}
}
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;
}
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>
* <SearchIndex class="...">
* <param name="..." value="...">
* ...
* <FileSystem ...>
* </Search>
* </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;
}
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();
}
}
Aggregations