I would like to create a YAML export file on my local folder for the node on which I executed the Custom Action. The code below gives me NullPointerException:
java.lang.NullPointerException at java.util.Hashtable.get(Hashtable.java:364)
info.magnolia.repository.WorkspaceMapping.getWorkspaceMapping(WorkspaceMapping.java:124)
info.magnolia.repository.DefaultRepositoryManager.getSession(DefaultRepositoryManager.java:308)
info.magnolia.context.DefaultRepositoryStrategy.internalGetSession(DefaultRepositoryStrategy.java:61)
info.magnolia.context.AbstractRepositoryStrategy.getSession(AbstractRepositoryStrategy.java:75) info.magnolia.context.AbstractContext.getJCRSession(AbstractContext.java:124) info.magnolia.importexport.command.JcrExportCommand.execute(JcrExportCommand.java:117)
ch.xxx.module.versioning.MyAction.execute(MyAction.java:60)
public class MyAction extends AbstractMultiItemAction<xxxVersioning> {
public MyAction(xxxVersioning definition, JcrItemAdapter item, UiContext uiContext) {
super(definition, item, uiContext);
// TODO Auto-generated constructor stub
}
@Override
public void execute() {
//export nodes from a JCR workspace
JcrExportCommand exporter = new JcrExportCommand();
//sets export format to yaml
exporter.setFormat("yaml");
//setup the root directory for exports
File rootDir = new File("/Users/asusti/Downloads/yamlExport");
// clean up first
rootDir.delete();
rootDir.mkdirs();
//get root node
Node node = (Node) getItems().get(0).getJcrItem();
try {
exporter.setPath(node.getPath());
File file = new File(rootDir+node.getName()+".yaml");
FileOutputStream out = new FileOutputStream(file);
exporter.setOutputStream(out);
exporter.execute(MgnlContext.getInstance());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Do I have to set some other methods for the exporter before I execute it?
You have to set the name of the workspace you want to export via JcrExportCommand#setRepository()
. E.g.
exporter.setRepository("website");
to export the web site workspace.