package com.der.engis; import info.magnolia.objectfactory.ComponentProvider; import info.magnolia.objectfactory.configuration.ComponentConfiguration; import info.magnolia.objectfactory.configuration.ComponentProviderConfiguration; import info.magnolia.objectfactory.configuration.ConfiguredComponentConfiguration; import info.magnolia.objectfactory.guice.AbstractGuiceComponentConfigurer; /** * {@link info.magnolia.objectfactory.configuration.ComponentConfigurer} that implements a workaround for * MAGNOLIA-5732.

* * In order to define a component bound to a different workspace than * {@link info.magnolia.repository.RepositoryConstants#CONFIG} use the {@code <path></path>} element to * specify a workspace in the following scheme: {@code workspacename:/path/to/node}.

* * Example for path {@code /test} in workspace {@code data}:
*

 * <component>
 *   <type>com.test.Test</type>
 *   <path>data:/test</path>
 *   <observed>true</observed>
 * </component>
 * 
* */ public class ComponentWorkspaceWorkaroundConfigurer extends AbstractGuiceComponentConfigurer { @Override public void doWithConfiguration(ComponentProvider parentComponentProvider, ComponentProviderConfiguration configuration) { for (ComponentConfiguration componentConfiguration : configuration.getComponents().values()) { if (componentConfiguration instanceof ConfiguredComponentConfiguration) { ConfiguredComponentConfiguration config = (ConfiguredComponentConfiguration) componentConfiguration; if (config.getPath().contains(":")) { String[] split = config.getPath().split(":"); String workspace = split[0]; String path = split[1]; config.setWorkspace(split[0]); config.setPath(path); } } } super.doWithConfiguration(parentComponentProvider, configuration); } }