package at.ucs.magnolia.updates.util; import info.magnolia.cms.util.StringLengthComparator; import info.magnolia.importexport.BootstrapUtil; import info.magnolia.init.MagnoliaConfigurationProperties; import info.magnolia.objectfactory.Components; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.jcr.Node; import javax.jcr.RepositoryException; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.*; /** * This class is exactly working like the original BootstrapUtil class of Magnolia, * with the only difference, that it substitutes Magnolia Property placeholders * with their actual value, since this is not implemented for bootstrap yamls by Magnolia */ public class UcsBootstrapUtil { private static final Logger log = LoggerFactory.getLogger(BootstrapUtil.class); public static void bootstrap(String[] resourceNames, int importUUIDBehavior) throws IOException, RepositoryException { // sort by length --> import parent node firstsubPath List list = new ArrayList<>(Arrays.asList(resourceNames)); if (list.contains(null)) { throw new IllegalArgumentException("Resource names contain a entry that cannot be processed."); } Collections.sort(list, new StringLengthComparator()); for (Iterator iter = list.iterator(); iter.hasNext(); ) { bootstrap(iter.next(), null, importUUIDBehavior); } } public static void bootstrap(String resourceName, String subPath, int importUUIDBehavior) throws IOException, RepositoryException { final InputStream stream = BootstrapUtil.class.getResourceAsStream(resourceName); if (stream == null) { throw new IOException("Can't find resource to bootstrap at " + resourceName); } MagnoliaConfigurationProperties magnoliaConfiguration = Components.getComponent(MagnoliaConfigurationProperties.class); InputStream resolvedStream = MagnoliaPropertyResolver.resolve(magnoliaConfiguration, stream); // Verify if the node already exists and execute jcr import command bootstrap(resourceName, subPath, resolvedStream, importUUIDBehavior); } public static void bootstrap(String resourceName, String subPath, InputStream stream, int importUUIDBehavior) throws RepositoryException { BootstrapUtil.bootstrap(resourceName, subPath, stream, importUUIDBehavior); } public static void export(Node content, File directory) throws IOException, RepositoryException { BootstrapUtil.export(content, directory); } }