/** * Get default workspace name. * * @return default name if there are no workspaces defined or there is no workspace present with name "default", otherwise return same name as repository name. */ public static String getDefaultWorkspace(String repositoryId) { RepositoryDefinition mapping = getRepositoryMapping(repositoryId); if (mapping == null) { return DEFAULT_WORKSPACE; } Collection<String> workspaces = mapping.getWorkspaces(); if (workspaces.contains(getMappedWorkspaceName(repositoryId))) { return repositoryId; } return DEFAULT_WORKSPACE; }
/** * Registers a new node type for the given repository and type. * @throws RepositoryException when node type can't be registered. Most often this happens when the node type of given name already exists or when the definition is invalid */ public static void registerNodeType(TypeDefinition type) throws RepositoryException { String nodeTypes = null; nodeTypes = type.getNodeTypes(); // default value if (StringUtils.isEmpty(nodeTypes)) { nodeTypes = DataModule.NODE_TYPE_DEF_TEMPLATE.format(new String[] { type.getName() }); } ContentRepository.getRepositoryProvider(DataModule.WORKSPACE).registerNodeTypes(new ByteArrayInputStream(nodeTypes.getBytes())); }
/** * Adds a workspace mapping. * * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#addWorkspaceMapping(info.magnolia.repository.definition.WorkspaceMappingDefinition)} directly. */ public static void addMappedRepositoryName(String logicalWorkspaceName, String repositoryName) { addMappedRepositoryName(logicalWorkspaceName, repositoryName, null); }
@Override public void start(Cache cache) { for (Iterator iter = repositories.iterator(); iter.hasNext();) { final String repository = (String) iter.next(); if (ContentRepository.getRepositoryMapping(repository) != null) { final CacheCleaner cacheCleaner = new CacheCleaner(cache, repository); final EventListener listener = ObservationUtil.instanciateDeferredEventListener(cacheCleaner, 5000, 30000); try { ObservationUtil.registerChangeListener(repository, "/", listener); } catch (Exception e) { log.warn("Failed to register cache flushing observation for repository {} due to {}", repository, e.getMessage()); log.warn("Publishing any content to {} will not result in update of the cache. Please flush the cache manually."); } registeredListeners.put(repository, listener); } } }
/** * Returns the repository definition for a repository or the repository for a given workspace. * * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#getRepositoryDefinition(String)} directly. */ public static RepositoryDefinition getRepositoryMapping(String repositoryOrLogicalWorkspace) { RepositoryManager repositoryManager = Components.getComponent(RepositoryManager.class); if (!repositoryManager.hasRepository(repositoryOrLogicalWorkspace)) { repositoryOrLogicalWorkspace = getMappedRepositoryName(repositoryOrLogicalWorkspace); } return repositoryManager.getRepositoryDefinition(repositoryOrLogicalWorkspace); }
@Override public boolean execute(Context ctx) throws Exception { if (StringUtils.isNotBlank(getPath()) && isProperty(getPath())) { throw new UnsupportedOperationException("Deactivation is not supported for properties."); } Syndicator syndicator = Components.getComponentProvider().newInstance(Syndicator.class); syndicator.init(getUser(ctx), this.getRepository(), ContentRepository.getDefaultWorkspace(this.getRepository()), new Rule()); final Content node = getNode(ctx); syndicator.deactivate(node); return true; }
public Iterator getRepositories() { return ContentRepository.getAllRepositoryNames(); }
@Override protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { final InputStream xmlStreamNew = getClass().getResourceAsStream("/mgnl-nodetypes/magnolia-forum-nodetypes.xml"); final Repository repository = ContentRepository.getRepository("forum"); final SimpleCredentials credentials = new SimpleCredentials(ContentRepository.REPOSITORY_USER, ContentRepository.REPOSITORY_PSWD.toCharArray()); final Session jcrSession = repository.login(credentials); try { try { final Workspace workspace = jcrSession.getWorkspace(); final NodeTypeManager ntMgr = workspace.getNodeTypeManager(); ((NodeTypeManagerImpl) ntMgr).registerNodeTypes(xmlStreamNew, NodeTypeManagerImpl.TEXT_XML, true); } catch (Exception e) { throw new RepositoryException(e.getMessage(), e); } } finally { IOUtils.closeQuietly(xmlStreamNew); jcrSession.logout(); } } }
/** * Returns <code>true</code> if a mapping for the given repository name or workspace name exist. * * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#hasRepository(String)} directly. */ public static boolean hasRepositoryMapping(String repositoryOrLogicalWorkspace) { RepositoryManager repositoryManager = Components.getComponent(RepositoryManager.class); if (!repositoryManager.hasRepository(repositoryOrLogicalWorkspace)) { repositoryOrLogicalWorkspace = getMappedRepositoryName(repositoryOrLogicalWorkspace); } return repositoryManager.hasRepository(repositoryOrLogicalWorkspace); }
public Syndicator getSyndicator() { // lazy bound, but only if this is a clone if (syndicator == null) { syndicator = Components.getComponentProvider().newInstance(Syndicator.class); syndicator.init( getUser(), this.getRepository(), ContentRepository.getDefaultWorkspace(this.getRepository()), getRule()); } return syndicator; }
@Override protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { TypeDefinition type = new TypeDefinition(); type.setName(typeName); String nodeTypes = null; try { nodeTypes = type.getNodeTypes(); // default value if (StringUtils.isEmpty(nodeTypes)) { nodeTypes = DataModule.NODE_TYPE_DEF_TEMPLATE.format(new String[] { type.getName() }); } ContentRepository.getRepositoryProvider(DataModule.WORKSPACE).registerNodeTypes(new ByteArrayInputStream(nodeTypes.getBytes())); } catch (RepositoryException e) { log.error("Failed to register node type: {}", nodeTypes); throw new RuntimeException(e); } } }
/** * Returns the repository for a repository or a workspace. * * @throws IllegalArgumentException if there is no repository or workspace by this name * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#getRepository(String)} directly. */ public static Repository getRepository(String repositoryOrLogicalWorkspace) { RepositoryManager repositoryManager = Components.getComponent(RepositoryManager.class); if (!repositoryManager.hasRepository(repositoryOrLogicalWorkspace)) { repositoryOrLogicalWorkspace = getMappedRepositoryName(repositoryOrLogicalWorkspace); } return repositoryManager.getRepository(repositoryOrLogicalWorkspace); }
@Test @Ignore public void testUnknownRepositoryShouldAlsoYieldMeaningfulExceptionMessageForRepositoryProviders() { try { ContentRepository.getRepositoryProvider("dummy"); fail("should have failed, since we haven't set any repository at all"); } catch (Throwable t) { assertEquals("Failed to retrieve repository provider 'dummy' (mapped as 'dummy'). Your Magnolia instance might not have been initialized properly.", t.getMessage()); } } }
/** * Returns the repository provider for either a repository or the provider for the repository which contains the workspace. * * @throws IllegalArgumentException if there is no repository or workspace by this name * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#getRepositoryProvider(String)} directly. */ public static Provider getRepositoryProvider(String repositoryOrLogicalWorkspace) { RepositoryManager repositoryManager = Components.getComponent(RepositoryManager.class); if (!repositoryManager.hasRepository(repositoryOrLogicalWorkspace)) { repositoryOrLogicalWorkspace = getMappedRepositoryName(repositoryOrLogicalWorkspace); } return repositoryManager.getRepositoryProvider(repositoryOrLogicalWorkspace); }
@Test public void testAddMixin() throws IOException, RepositoryException { final Content content = getTestContent(); final String repoName = content.getWorkspace().getName(); final String mixDeleted = "mgnl:deleted"; final Provider repoProvider = ContentRepository.getRepositoryProvider(repoName); final String mgnlMixDeleted = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<nodeTypes" + " xmlns:rep=\"internal\"" + " xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"" + " xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\"" + " xmlns:mgnl=\"http://www.magnolia.info/jcr/mgnl\"" + " xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "<nodeType name=\"" + mixDeleted + "\" isMixin=\"true\" hasOrderableChildNodes=\"true\" primaryItemName=\"\">" + "<supertypes>" + "<supertype>nt:base</supertype>" + "</supertypes>" + "</nodeType>" + "</nodeTypes>"; try { repoProvider.registerNodeTypes(new ByteArrayInputStream(mgnlMixDeleted.getBytes())); } catch (RepositoryException e) { // ignore, either it's already registered and test will pass, or type can't be registered and test should fail } assertTrue(content.getJCRNode().canAddMixin(mixDeleted)); content.addMixin(mixDeleted); }