use of javax.jcr.RepositoryException in project jackrabbit-oak by apache.
the class DescendantSearchTest method beforeSuite.
@Override
public void beforeSuite() throws RepositoryException {
session = getRepository().login(getCredentials());
try {
// Jackrabbit 2 doesn't have the oak namespace
String o = session.getNamespaceURI("oak");
} catch (RepositoryException e) {
session.setNamespacePrefix("oak", "http://jackrabbit.apache.org/oak/ns/1.0");
}
try {
ensurePropertyIndex();
} catch (InvalidItemStateException e) {
// some other oak instance probably created the same
// index definition concurrently. refresh and try again
// do not catch exception if it fails again.
session.refresh(false);
ensurePropertyIndex();
}
root = session.getRootNode().addNode(testNodeName, "nt:unstructured");
for (int i = 0; i < NODE_COUNT; i++) {
Node node = root.addNode("node" + i, "nt:unstructured");
for (int j = 0; j < NODE_COUNT; j++) {
Node child = node.addNode("node" + j, "nt:unstructured");
child.setProperty("testcount", j);
}
session.save();
}
}
use of javax.jcr.RepositoryException in project jackrabbit-oak by apache.
the class PermissionHookTest method getEntry.
protected Tree getEntry(@Nonnull Principal principal, String accessControlledPath, long index) throws Exception {
Tree principalRoot = getPrincipalRoot(principal);
Tree parent = principalRoot.getChild(PermissionUtil.getEntryName(accessControlledPath));
Tree entry = parent.getChild(String.valueOf(index));
if (!entry.exists()) {
throw new RepositoryException("no such entry");
}
return entry;
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class RepositoryConfig method internalCreateWorkspaceConfig.
/**
* Creates a new workspace configuration with the specified name and the
* specified workspace <code>template</.
* <p>
* This method creates a workspace configuration subdirectory,
* copies the workspace configuration template into it, and finally
* adds the created workspace configuration to the repository.
* The initialized workspace configuration object is returned to
* the caller.
*
* @param name workspace name
* @param template the workspace template
* @param configContent optional stringbuffer that will have the content
* of workspace configuration file written in
* @return created workspace configuration
* @throws ConfigurationException if creating the workspace configuration
* failed
*/
private synchronized WorkspaceConfig internalCreateWorkspaceConfig(String name, Element template, StringBuffer configContent) throws ConfigurationException {
// The physical workspace home directory on disk (TODO encode name?)
File directory = new File(workspaceDirectory, name);
// or cannot be created
if (!directory.mkdir()) {
if (directory.exists()) {
throw new ConfigurationException("Workspace directory already exists: " + name);
} else {
throw new ConfigurationException("Failed to create workspace directory: " + name);
}
}
FileSystem virtualFS;
if (workspaceConfigDirectory != null) {
// virtual repository file system
try {
virtualFS = fsf.getFileSystem();
} catch (RepositoryException e) {
throw new ConfigurationException("File system configuration error", e);
}
} else {
// workspace configurations are maintained on disk
virtualFS = null;
}
try {
Writer configWriter;
// get a writer for the workspace configuration file
if (virtualFS != null) {
// a configuration directoy had been specified; create workspace
// configuration in virtual repository file system rather than
// on disk
String configDir = workspaceConfigDirectory + FileSystem.SEPARATOR + name;
String configFile = configDir + FileSystem.SEPARATOR + WORKSPACE_XML;
try {
// Create the directory
virtualFS.createFolder(configDir);
configWriter = new OutputStreamWriter(virtualFS.getOutputStream(configFile));
} catch (FileSystemException e) {
throw new ConfigurationException("failed to create workspace configuration at path " + configFile, e);
}
} else {
File file = new File(directory, WORKSPACE_XML);
try {
configWriter = new FileWriter(file);
} catch (IOException e) {
throw new ConfigurationException("failed to create workspace configuration at path " + file.getPath(), e);
}
}
// the configuration writer.
try {
template.setAttribute("name", name);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
if (configContent == null) {
transformer.transform(new DOMSource(template), new StreamResult(configWriter));
} else {
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(template), new StreamResult(writer));
String s = writer.getBuffer().toString();
configWriter.write(s);
configContent.append(s);
}
} catch (IOException e) {
throw new ConfigurationException("Cannot create a workspace configuration file", e);
} catch (TransformerConfigurationException e) {
throw new ConfigurationException("Cannot create a workspace configuration writer", e);
} catch (TransformerException e) {
throw new ConfigurationException("Cannot create a workspace configuration file", e);
} finally {
IOUtils.closeQuietly(configWriter);
}
// Load the created workspace configuration.
WorkspaceConfig wc;
if (virtualFS != null) {
String configDir = workspaceConfigDirectory + FileSystem.SEPARATOR + name;
wc = loadWorkspaceConfig(virtualFS, configDir);
} else {
wc = loadWorkspaceConfig(directory);
}
if (wc != null) {
addWorkspaceConfig(wc);
return wc;
} else {
throw new ConfigurationException("Failed to load the created configuration for workspace " + name + ".");
}
} finally {
try {
if (virtualFS != null) {
virtualFS.close();
}
} catch (FileSystemException ignore) {
}
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class RepositoryConfig method init.
/**
* Initializes the repository configuration. This method loads the
* configurations for all available workspaces.
*
* @throws ConfigurationException on initialization errors
* @throws IllegalStateException if the repository configuration has already
* been initialized
*/
public void init() throws ConfigurationException, IllegalStateException {
// fsf is used below and this might be a DatabaseAware FileSystem
try {
cf.registerDataSources(dsc);
} catch (RepositoryException e) {
throw new ConfigurationException("failed to register data sources", e);
}
if (!workspaces.isEmpty()) {
throw new IllegalStateException("Repository configuration has already been initialized.");
}
// Get the physical workspace root directory (create it if not found)
File directory = new File(workspaceDirectory);
if (!directory.exists()) {
directory.mkdirs();
}
// Get all workspace subdirectories
if (workspaceConfigDirectory != null) {
// rather than in physical workspace root directory on disk
try {
FileSystem fs = fsf.getFileSystem();
try {
if (!fs.exists(workspaceConfigDirectory)) {
fs.createFolder(workspaceConfigDirectory);
} else {
String[] dirNames = fs.listFolders(workspaceConfigDirectory);
for (String dir : dirNames) {
String configDir = workspaceConfigDirectory + FileSystem.SEPARATOR + dir;
WorkspaceConfig wc = loadWorkspaceConfig(fs, configDir);
if (wc != null) {
addWorkspaceConfig(wc);
}
}
}
} finally {
fs.close();
}
} catch (Exception e) {
throw new ConfigurationException("error while loading workspace configurations from path " + workspaceConfigDirectory, e);
}
} else {
// search for workspace configurations in physical workspace root
// directory on disk
File[] files = directory.listFiles();
if (files == null) {
throw new ConfigurationException("Invalid workspace root directory: " + workspaceDirectory);
}
for (File file : files) {
WorkspaceConfig wc = loadWorkspaceConfig(file);
if (wc != null) {
addWorkspaceConfig(wc);
}
}
}
if (!workspaces.containsKey(defaultWorkspace)) {
if (!workspaces.isEmpty()) {
log.warn("Potential misconfiguration. No configuration found " + "for default workspace: " + defaultWorkspace);
}
// create initial default workspace
createWorkspaceConfig(defaultWorkspace, (StringBuffer) null);
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class RepositoryConfigurationParser method getFileSystemFactory.
/**
* Creates and returns a factory object that creates {@link FileSystem}
* instances based on the bean configuration at the named element.
*
* @param parent parent element
* @param name name of the bean configuration element
* @return file system factory
* @throws ConfigurationException if the bean configuration is invalid
*/
protected FileSystemFactory getFileSystemFactory(Element parent, String name) throws ConfigurationException {
final BeanConfig config = parseBeanConfig(parent, name);
return new FileSystemFactory() {
public FileSystem getFileSystem() throws RepositoryException {
try {
FileSystem fs = config.newInstance(FileSystem.class);
fs.init();
return fs;
} catch (FileSystemException e) {
throw new RepositoryException("File system initialization failure.", e);
}
}
};
}
Aggregations