JCRExportCommand execute()在木兰cms中引发异常错误

问题描述 投票:1回答:1

我想在我执行自定义操作的节点的本地文件夹中创建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();
    }

执行前是否必须为导出器设置其他方法?

magnolia
1个回答
0
投票

您必须通过JcrExportCommand#setRepository()设置要导出的工作空间的名称。例如:

exporter.setRepository("website");

导出网站工作区。

© www.soinside.com 2019 - 2024. All rights reserved.