public class CmdDump extends AbstractJcrFsCommand {
protected void doExecute(VaultFsConsoleExecutionContext ctx, CommandLine cl)
throws Exception {
String path = (String) cl.getValue(argPath);
VaultFileSystem fs = ctx.getVaultFsApp().getVaultFileSystem();
if (fs == null) {
VaultFsApp.log.info("Not mounted.");
} else if (path != null && !path.equals("")) {
if (cl.hasOption(optConfig) || cl.hasOption(optFilter)) {
ConsoleFile f = ctx.getCurrentFile();
File file;
if (f instanceof PlatformFile) {
f = f.getFile(path, false);
file = (File) f.unwrap();
} else {
file = ctx.getVaultFsApp().getPlatformFile(path, false);
}
if (cl.hasOption(optConfig)) {
IOUtils.copy(
fs.getConfig().getSource(),
FileUtils.openOutputStream(file)
);
VaultFsApp.log.info("VaultFs config written to {}", file.getPath());
} else {
IOUtils.copy(
fs.getWorkspaceFilter().getSource(),
FileUtils.openOutputStream(file)
);
VaultFsApp.log.info("VaultFs workspace filter written to {}", file.getPath());
}
} else {
Object f = ctx.getCurrentFile().getFile(path, false).unwrap();
if (f instanceof Dumpable) {
DumpContext dCtx = new DumpContext(new PrintWriter(System.out));
((Dumpable) f).dump(dCtx, true);
dCtx.flush();
} else {
VaultFsApp.log.info("Object not dumpable: {}", f);
}
}
} else {
fs.getAggregateManager().dumpConfig(new PrintWriter(System.out));
}
}