Created
October 10, 2014 11:11
-
-
Save matteopelucco/396802652c9862ae5f82 to your computer and use it in GitHub Desktop.
Magnolia Activation Utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tinext.magnolia.nectar.utils; | |
import info.magnolia.context.SimpleContext; | |
import info.magnolia.module.activation.commands.ActivationCommand; | |
import info.magnolia.module.activation.commands.DeactivationCommand; | |
import javax.jcr.Node; | |
import javax.jcr.RepositoryException; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class ActivationUtils { | |
private static final Logger log = LoggerFactory.getLogger(ActivationUtils.class); | |
public static final boolean activate(Node node) throws RepositoryException { | |
ActivationCommand command = new ActivationCommand(); | |
command.setRepository(node.getSession().getWorkspace().getName()); | |
command.setPath(node.getPath()); | |
try { | |
command.execute(new SimpleContext()); | |
return true; | |
} catch (Exception e) { | |
log.error("Exception caught while executing activation command: {}", e.getMessage()); | |
e.printStackTrace(); | |
} | |
return false; | |
} | |
public static final boolean activateRecursively(Node node) throws RepositoryException { | |
ActivationCommand command = new ActivationCommand(); | |
command.setRepository(node.getSession().getWorkspace().getName()); | |
command.setPath(node.getPath()); | |
command.setRecursive(true); | |
try { | |
command.execute(new SimpleContext()); | |
return true; | |
} catch (Exception e) { | |
log.error("Exception caught while executing activation command: {}", e.getMessage()); | |
e.printStackTrace(); | |
} | |
return false; | |
} | |
public static final boolean deactivate(Node node) throws RepositoryException { | |
DeactivationCommand command = new DeactivationCommand(); | |
command.setRepository(node.getSession().getWorkspace().getName()); | |
command.setPath(node.getPath()); | |
try { | |
command.execute(new SimpleContext()); | |
return true; | |
} catch (Exception e) { | |
log.error("Exception caught while executing deactivation command: {}", e.getMessage()); | |
e.printStackTrace(); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment