Search in sources :

Example 71 with RepositoryException

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();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 72 with RepositoryException

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;
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) RepositoryException(javax.jcr.RepositoryException)

Example 73 with RepositoryException

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) {
        }
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) FileWriter(java.io.FileWriter) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) StringWriter(java.io.StringWriter) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) TransformerException(javax.xml.transform.TransformerException)

Example 74 with RepositoryException

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);
    }
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) RepositoryException(javax.jcr.RepositoryException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException) RepositoryException(javax.jcr.RepositoryException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException)

Example 75 with RepositoryException

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);
            }
        }
    };
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) RepositoryException(javax.jcr.RepositoryException) FileSystemFactory(org.apache.jackrabbit.core.fs.FileSystemFactory)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1236 Node (javax.jcr.Node)289 Session (javax.jcr.Session)182 IOException (java.io.IOException)156 ArrayList (java.util.ArrayList)106 Name (org.apache.jackrabbit.spi.Name)94 DavException (org.apache.jackrabbit.webdav.DavException)90 Test (org.junit.Test)87 Value (javax.jcr.Value)80 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)76 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)72 Path (org.apache.jackrabbit.spi.Path)67 ItemNotFoundException (javax.jcr.ItemNotFoundException)65 PathNotFoundException (javax.jcr.PathNotFoundException)65 NodeId (org.apache.jackrabbit.core.id.NodeId)64 Property (javax.jcr.Property)61 HashMap (java.util.HashMap)53 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)53 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)52 InvalidItemStateException (javax.jcr.InvalidItemStateException)50