/** * Convenience method that wraps the configuration input stream into an * {@link InputSource} and invokes the * {@link #create(InputSource, String)} method. * * @param input repository configuration input stream * @param home repository home directory * @return repository configuration * @throws ConfigurationException on configuration errors * @see #create(InputSource, String) */ public static RepositoryConfig create(InputStream input, String home) throws ConfigurationException { return create(new InputSource(input), home); }
/** * Creates a transient repository proxy that will use a copy of the given * repository configuration to initialize the underlying repository * instance. * * @param config repository configuration */ public TransientRepository(final RepositoryConfig config) { this(new RepositoryFactory() { public RepositoryImpl getRepository() throws RepositoryException { return RepositoryImpl.create(RepositoryConfig.create(config)); } }, config.getHomeDir()); }
/** * @return The <code>SecurityManagerConfig</code> configured for the * repository this manager has been created for. */ protected SecurityManagerConfig getConfig() { return repository.getConfig().getSecurityConfig().getSecurityManagerConfig(); }
/** * Copies the contents of the repository in the given source directory * to a repository in the given target directory. * * @param source source repository directory * @param target target repository directory * @throws RepositoryException if the copy operation fails * @throws IOException if the target repository can not be initialized */ public static void copy(File source, File target) throws RepositoryException, IOException { copy(RepositoryConfig.create(source), RepositoryConfig.install(target)); }
repLock = repConfig.getRepositoryLockMechanism(); repLock.init(repConfig.getHomeDir()); repLock.acquire(); context.setFileSystem(repConfig.getFileSystem()); DataStore dataStore = repConfig.getDataStore(); if (dataStore != null) { context.setDataStore(dataStore); nodeIdFactory = new NodeIdFactory(repConfig.getHomeDir()); nodeIdFactory.open(); context.setNodeIdFactory(nodeIdFactory); for (WorkspaceConfig config : repConfig.getWorkspaceConfigs()) { WorkspaceInfo info = createWorkspaceInfo(config); wspInfos.put(config.getName(), info); if (repConfig.getClusterConfig() != null) { clusterNode = createClusterNode(); context.setClusterNode(clusterNode); repConfig.getVersioningConfig(), delegatingDispatcher); context.setInternalVersionManager(vMgr); if (clusterNode != null) { getSystemSearchManager(repConfig.getDefaultWorkspaceName()); virtNTMgr.setSession(getSystemSession(repConfig.getDefaultWorkspaceName()));
private void assertRepositoryConfiguration(RepositoryConfig config) throws ConfigurationException { assertEquals(DIR.getPath(), config.getHomeDir()); assertEquals("default", config.getDefaultWorkspaceName()); assertEquals( new File(DIR, "workspaces").getPath(), new File(config.getWorkspacesConfigRootDir()).getPath()); assertEquals("Jackrabbit", config.getSecurityConfig().getAppName()); config.getSecurityConfig().getSecurityManagerConfig(); assertEquals( "org.apache.jackrabbit.core.DefaultSecurityManager", config.getSecurityConfig().getAccessManagerConfig(); assertEquals( "org.apache.jackrabbit.core.security.DefaultAccessManager", assertTrue(amc.getParameters().isEmpty()); VersioningConfig vc = config.getVersioningConfig(); assertEquals(new File(DIR, "version"), vc.getHomeDir()); assertEquals(
logger.info("Copying repository content from {} to Oak", config.getHomeDir()); try { NodeBuilder targetBuilder = target.getRoot().builder(); source.getRepositoryConfig().getDefaultWorkspaceName(); SecurityProvider security = SecurityProviderBuilder.newBuilder() .with(mapSecurityConfig(config.getSecurityConfig())).build(); } else { logger.info("Initializing initial repository content from {}", config.getHomeDir()); new InitialContent().initialize(targetBuilder); if (initializer != null) { initializer.initialize(targetBuilder); logger.debug("InitialContent completed from {}", config.getHomeDir()); logger.debug("Repository initializer '" + ri.getClass().getName() + "' completed", config.getHomeDir()); logger.debug("Workspace initializer '" + wi.getClass().getName() + "' completed", config.getHomeDir());
/** * Returns the configuration of a repository in a given repository * directory. The repository configuration is read from a "repository.xml" * file inside the repository directory. * <p> * The directory is created if it does not exist. If the repository * configuration file does not exist, then it is created using the * default Jackrabbit configuration settings. * * @param dir repository home directory * @return repository configuration * @throws ConfigurationException on configuration errors * @throws java.io.IOException If an error occurs. * @since Apache Jackrabbit 1.6 */ public static RepositoryConfig install(File dir) throws IOException, ConfigurationException { return install(new File(dir, REPOSITORY_XML), dir); }
/** * Initialize startup workspaces. Base implementation will initialize the * default workspace. Derived classes may initialize their own startup * workspaces <b>after</b> having called the base implementation. * * @throws RepositoryException if an error occurs */ protected void initStartupWorkspaces() throws RepositoryException { String wspName = repConfig.getDefaultWorkspaceName(); String secWspName = null; SecurityManagerConfig smc = repConfig.getSecurityConfig().getSecurityManagerConfig(); if (smc != null) { secWspName = smc.getWorkspaceName(); } try { (wspInfos.get(wspName)).initialize(); if (secWspName != null && !wspInfos.containsKey(secWspName)) { createWorkspace(secWspName); log.info("created system workspace: {}", secWspName); } } catch (RepositoryException e) { // if default workspace failed to initialize, shutdown again log.error("Failed to initialize workspace '" + wspName + "'", e); log.error("Unable to start repository, forcing shutdown..."); shutdown(); throw e; } }
/** * Returns the name of the default workspace. * * @return default workspace name */ public String getDefaultWorkspaceName() { return repository.getConfig().getDefaultWorkspaceName(); }
@Override protected AccessManager createAccessManager(Subject subject) throws AccessDeniedException, RepositoryException { AccessManagerConfig amConfig = context.getRepository().getConfig().getAccessManagerConfig(); try { HippoAMContext ctx = new HippoAMContext( new File((context.getRepository()).getConfig().getHomeDir()), context.getRepositoryContext().getFileSystem(), this, subject, context.getHierarchyManager(), context.getPrivilegeManager(), this, getWorkspace().getName(), context.getNodeTypeManager(), getItemStateManager()); AccessManager accessMgr = amConfig.newInstance(AccessManager.class); accessMgr.init(ctx); if (accessMgr instanceof ItemStateListener) { context.getItemStateManager().addListener((ItemStateListener) accessMgr); } return accessMgr; } catch (AccessDeniedException ex) { throw ex; } catch (Exception ex) { String msg = "failed to instantiate AccessManager implementation: "+amConfig.getClassName(); log.error(msg, ex); throw new RepositoryException(msg, ex); } }
/** * Copies the contents of the repository in the given source directory * to a repository in the given target directory. * * @param source source repository directory * @param target target repository directory * @throws RepositoryException if the copy operation fails * @throws IOException if the target repository can not be initialized */ public static void copy(File source, File target) throws RepositoryException, IOException { copy(RepositoryConfig.create(source), RepositoryConfig.install(target)); }
repLock = repConfig.getRepositoryLockMechanism(); repLock.init(repConfig.getHomeDir()); repLock.acquire(); context.setFileSystem(repConfig.getFileSystem()); DataStore dataStore = repConfig.getDataStore(); if (dataStore != null) { context.setDataStore(dataStore); nodeIdFactory = new NodeIdFactory(repConfig.getHomeDir()); nodeIdFactory.open(); context.setNodeIdFactory(nodeIdFactory); for (WorkspaceConfig config : repConfig.getWorkspaceConfigs()) { WorkspaceInfo info = createWorkspaceInfo(config); wspInfos.put(config.getName(), info); if (repConfig.getClusterConfig() != null) { clusterNode = createClusterNode(); context.setClusterNode(clusterNode); repConfig.getVersioningConfig(), delegatingDispatcher); context.setInternalVersionManager(vMgr); if (clusterNode != null) { getSystemSearchManager(repConfig.getDefaultWorkspaceName()); virtNTMgr.setSession(getSystemSession(repConfig.getDefaultWorkspaceName()));
logger.info("Copying repository content from {} to Oak", config.getHomeDir()); try { NodeBuilder targetBuilder = target.getRoot().builder(); source.getRepositoryConfig().getDefaultWorkspaceName(); SecurityProvider security = SecurityProviderBuilder.newBuilder() .with(mapSecurityConfig(config.getSecurityConfig())).build(); } else { logger.info("Initializing initial repository content from {}", config.getHomeDir()); new InitialContent().initialize(targetBuilder); if (initializer != null) { initializer.initialize(targetBuilder); logger.debug("InitialContent completed from {}", config.getHomeDir()); logger.debug("Repository initializer '" + ri.getClass().getName() + "' completed", config.getHomeDir()); logger.debug("Workspace initializer '" + wi.getClass().getName() + "' completed", config.getHomeDir());
/** * Returns the configuration of a repository in a given repository * directory. The repository configuration is read from a "repository.xml" * file inside the repository directory. * <p> * The directory is created if it does not exist. If the repository * configuration file does not exist, then it is created using the * default Jackrabbit configuration settings. * * @param dir repository home directory * @return repository configuration * @throws ConfigurationException on configuration errors * @throws java.io.IOException If an error occurs. * @since Apache Jackrabbit 1.6 */ public static RepositoryConfig install(File dir) throws IOException, ConfigurationException { return install(new File(dir, REPOSITORY_XML), dir); }
/** * Initialize startup workspaces. Base implementation will initialize the * default workspace. Derived classes may initialize their own startup * workspaces <b>after</b> having called the base implementation. * * @throws RepositoryException if an error occurs */ protected void initStartupWorkspaces() throws RepositoryException { String wspName = repConfig.getDefaultWorkspaceName(); String secWspName = null; SecurityManagerConfig smc = repConfig.getSecurityConfig().getSecurityManagerConfig(); if (smc != null) { secWspName = smc.getWorkspaceName(); } try { (wspInfos.get(wspName)).initialize(); if (secWspName != null && !wspInfos.containsKey(secWspName)) { createWorkspace(secWspName); log.info("created system workspace: {}", secWspName); } } catch (RepositoryException e) { // if default workspace failed to initialize, shutdown again log.error("Failed to initialize workspace '" + wspName + "'", e); log.error("Unable to start repository, forcing shutdown..."); shutdown(); throw e; } }
/** * Returns the name of the default workspace. * * @return default workspace name */ public String getDefaultWorkspaceName() { return repository.getConfig().getDefaultWorkspaceName(); }
@Override protected AccessManager createAccessManager(Subject subject) throws AccessDeniedException, RepositoryException { AccessManagerConfig amConfig = context.getRepository().getConfig().getAccessManagerConfig(); try { HippoAMContext ctx = new HippoAMContext( new File((context.getRepository()).getConfig().getHomeDir()), context.getRepositoryContext().getFileSystem(), this, subject, context.getHierarchyManager(), context.getPrivilegeManager(), this, getWorkspace().getName(), context.getNodeTypeManager(), getItemStateManager()); AccessManager accessMgr = amConfig.newInstance(AccessManager.class); accessMgr.init(ctx); if (accessMgr instanceof ItemStateListener) { context.getItemStateManager().addListener((ItemStateListener) accessMgr); } return accessMgr; } catch (AccessDeniedException ex) { throw ex; } catch (Exception ex) { String msg = "failed to instantiate AccessManager implementation: "+amConfig.getClassName(); log.error(msg, ex); throw new RepositoryException(msg, ex); } }
/** * Convenience method that wraps the configuration URI into an * {@link InputSource} and invokes the * {@link #create(InputSource, String)} method. * * @param uri repository configuration URI * @param home repository home directory * @return repository configuration * @throws ConfigurationException on configuration errors * @see #create(InputSource, String) */ public static RepositoryConfig create(URI uri, String home) throws ConfigurationException { return create(new InputSource(uri.toString()), home); }
private void backup(File sourceDir) throws Exception { RepositoryConfig source; if (command.hasOption("conf")) { source = RepositoryConfig.create( new File(command.getOptionValue("conf")), sourceDir); } else { source = RepositoryConfig.create(sourceDir); } File targetDir; if (command.hasOption("backup-repo")) { targetDir = new File(command.getOptionValue("backup-repo")); } else { int i = 1; do { targetDir = new File("jackrabbit-backup" + i++); } while (targetDir.exists()); } RepositoryConfig target; if (command.hasOption("backup-conf")) { target = RepositoryConfig.install( new File(command.getOptionValue("backup-conf")), targetDir); } else { target = RepositoryConfig.install(targetDir); } message("Creating a repository copy in " + targetDir); RepositoryCopier.copy(source, target); message("The repository has been successfully copied."); }