JCRExportCommand execute() 在 magnolia cms 中抛出异常错误
JCRExportCommand execute() throws exception error in magnolia cms
我想在本地文件夹中为执行自定义操作的节点创建一个 YAML 导出文件。下面的代码给了我 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();
}
在执行之前是否必须为导出器设置一些其他方法?
您必须通过 JcrExportCommand#setRepository()
设置要导出的工作区的名称。例如
exporter.setRepository("website");
导出网站工作区。
我想在本地文件夹中为执行自定义操作的节点创建一个 YAML 导出文件。下面的代码给了我 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();
}
在执行之前是否必须为导出器设置一些其他方法?
您必须通过 JcrExportCommand#setRepository()
设置要导出的工作区的名称。例如
exporter.setRepository("website");
导出网站工作区。