Package org.apache.jackrabbit.vault.fs.api

Examples of org.apache.jackrabbit.vault.fs.api.VaultFile


        return file.getPath();
    }

    public ConsoleFile getFile(String path, boolean mustExist) throws IOException {
        try {
            VaultFile ret = file.getFileSystem().getFile(file, path);
            if (ret == null) {
                throw new FileNotFoundException(path);
            }
            return new VaultFsCFile(ret);
        } catch (RepositoryException e) {
View Full Code Here


        if (excludeList != null && excludeList.size() > 0) {
            excludes = (String[]) excludeList.toArray(new String[excludeList.size()]);
        }
        */
        File localFile = ctx.getVaultFsApp().getPlatformFile(localPath, false);
        VaultFile vaultFile = ctx.getVaultFsApp().getVaultFile(jcrPath, true);
        VaultFsApp.log.info("Importing {} to {}", localFile.getCanonicalPath(), vaultFile.getPath());
        Archive archive;
        if (localFile.isFile()) {
            archive = new ZipArchive(localFile);
        } else {
            archive = new FileArchive(localFile);
        }
        Importer importer = new Importer();
        if (verbose) {
            importer.getOptions().setListener(new DefaultProgressListener());
        }

        Session s = vaultFile.getFileSystem().getAggregateManager().getSession();
        Node importRoot = s.getNode(vaultFile.getPath());
        importer.run(archive, importRoot);
        VaultFsApp.log.info("Importing done.");
    }
View Full Code Here

    protected void doExecute(VaultFsConsoleExecutionContext ctx, CommandLine cl) throws Exception {
        String jcrPath = (String) cl.getValue(argJcrPath);

        ConsoleFile wo = ctx.getFile(jcrPath, true);
        if (wo instanceof VaultFsCFile) {
            VaultFile file = (VaultFile) wo.unwrap();
            try {
                String ct = file.getContentType();
                if (ct == null) {
                    ct = "application/octet-stream";
                }
                if (ct.startsWith("text/")) {
                    file.getArtifact().spool(System.out);
                    System.out.flush();
                } else {
                    System.out.printf("Refusing to print contents of a '%s' file.%n", ct);
                }
            } catch (IOException e) {
View Full Code Here

                IOUtils.closeQuietly(ins);
            }
        }


        VaultFile vaultFile = vCtx.getFileSystem(addr).getFile(jcrPath);

        VaultFsApp.log.info("Importing {} to {}", localFile.getCanonicalPath(), vaultFile.getPath());
        Archive archive;
        if (localFile.isFile()) {
            archive = new ZipArchive(localFile);
        } else {
            if (cl.hasOption(optSync)) {
                VaultFsApp.log.warn("--sync is not supported yet");
            }
            archive = new FileArchive(localFile);
        }
        archive.open(false);
        try {
            Importer importer = new Importer();
            if (verbose) {
                importer.getOptions().setListener(new DefaultProgressListener());
            }
            Session s = vaultFile.getFileSystem().getAggregateManager().getSession();
            Node importRoot = s.getNode(vaultFile.getPath());
            importer.run(archive, importRoot);
        } finally {
            archive.close();
        }
        VaultFsApp.log.info("Importing done.");
View Full Code Here

        } else {
            throw new Exception("Type " + type + " not supported");
        }

        vCtx.setVerbose(cl.hasOption(OPT_VERBOSE));
        VaultFile vaultFile = vCtx.getFileSystem(addr).getFile(jcrPath);
        if (vaultFile == null) {
            VaultFsApp.log.error("Not such remote file: {}", jcrPath);
            return;
        }

        VaultFsApp.log.info("Exporting {} to {}", vaultFile.getPath(), localFile.getCanonicalPath());
        if (verbose) {
            exporter.setVerbose(new DefaultProgressListener());
        }
        exporter.export(vaultFile);
        VaultFsApp.log.info("Exporting done.");
View Full Code Here

    protected void doExecute(VaultFsConsoleExecutionContext ctx, CommandLine cl) throws Exception {
        String localPath = (String) cl.getValue(argLocalPath);
        String jcrPath = (String) cl.getValue(argJcrPath);
        boolean verbose = cl.hasOption(OPT_VERBOSE);
        String type = (String) cl.getValue(optType, "platform");
        VaultFile vaultFile = ctx.getVaultFsApp().getVaultFile(jcrPath, true);
        if (localPath == null) {
            localPath = vaultFile.getName();
        }
        File localFile = ctx.getVaultFsApp().getPlatformFile(localPath, false);

        AbstractExporter exporter;
        if (type.equals("platform")) {
            if (!localFile.exists()) {
                localFile.mkdirs();
            }
            exporter = new PlatformExporter(localFile);
            ((PlatformExporter) exporter).setPruneMissing(cl.hasOption(optPrune));
        } else if (type.equals("jar")) {
            exporter = new JarExporter(localFile);
        } else {
            throw new Exception("Type " + type + " not supported");
        }
        if (jcrPath == null || !jcrPath.startsWith("/")) {
            exporter.setRelativePaths(true);
        }
        VaultFsApp.log.info("Exporting {} to {}", vaultFile.getPath(), localFile.getCanonicalPath());
        if (verbose) {
            exporter.setVerbose(new DefaultProgressListener());
        }
        exporter.export(vaultFile);
        VaultFsApp.log.info("Exporting done.");
View Full Code Here

            throws Exception {
        // overwrite this, since it takes the mounted vault fs into account
        String jcrPath = (String) cl.getValue(argJcrPath);
        String localPath = (String) cl.getValue(argLocalPath);

        VaultFile remoteFile = ctx.getVaultFsApp().getVaultFile(jcrPath, true);
        RepositoryAddress addr = remoteFile.getAggregate().getManager().getMountpoint();

        if (localPath == null) {
            if (jcrPath == null) {
                localPath = Text.getName(addr.toString());
            } else {
View Full Code Here

    protected void doExecute(VaultFsConsoleExecutionContext ctx, CommandLine cl) throws Exception {
        String name = (String) cl.getValue(argLocalPath);
        String jcrPath = (String) cl.getValue(argJcrPath);

        VaultFile file;
        if (jcrPath == null) {
            jcrPath = Text.getName(name);
            if (jcrPath.equals("")) {
                jcrPath = name;
            }
        }
        File local = ctx.getVaultFsApp().getPlatformFile(name, true);
        VaultFile cwd = ctx.getVaultFsApp().getVaultFile("", true);
        file = cwd.getFileSystem().getFile(cwd, jcrPath);
        if (file == null) {
            // do add
            jcrPath = PathUtil.makePath(cwd.getPath(), jcrPath);
            doAdd(local, cwd, jcrPath);
        } else {
            doPut(local, file);
        }
    }
View Full Code Here

                .create();
    }


    protected void formatFile(ConsoleFile file, Table.Row row, int flags) {
            VaultFile f = (VaultFile) file.unwrap();
            if ((flags & F_FLAG_TIME) > 0) {
                row.addCol(formatDate(f.lastModified()), true);
            }
            if ((flags & F_FLAG_SIZE) > 0) {
                row.addCol(formatSize(f.length()), true);
            }
            if ((flags & F_FLAG_MIME) > 0) {
                row.addCol(f.getContentType() == null ? "" : f.getContentType());
            }
            row.addCol(f.getName() + (f.isDirectory() ? "/" : ""));
    }
View Full Code Here

                // filePath: /vltTest/foo/.content.xml
                // repoPath: /vltTest/foo

                // parentPath: /vltTest/foo
                String parentPath = Text.getRelativeParent(change.filePath, 1);
                VaultFile parent = fs.getFile(parentPath);
                TxInfo txInfo;
                String repoPath;
                if (parent == null) {
                    // parentPath: /vltTest
                    parentPath = Text.getRelativeParent(parentPath, 1);
                    parent = fs.getFile(parentPath);
                    repoPath = change.repoPath;
                    String repoName = Text.getName(repoPath);
                    if (parent == null) {
                        // special case if parent is an intermediate directory
                        // that is not created yet. for example _jcr_content
                        // /header.png/_jcr_content/renditions

                        // check if parent node exists
                        if (!fs.getAggregateManager().getSession().nodeExists(Text.getRelativeParent(repoPath, 1))) {
                            return false;
                        }
                        while ((parent == null || parent.getAggregate() == null)
                                && parentPath.length() > 0) {
                            String parentName = Text.getName(parentPath);
                            if (parentName.endsWith(".dir")) {
                                parentName = parentName.substring(0, parentName.length() - 4);
                            }
                            repoName = PlatformNameFormat.getRepositoryName(parentName) + "/" + repoName;
                            parentPath = Text.getRelativeParent(parentPath, 1);
                            parent = fs.getFile(parentPath);
                        }
                        if (parent == null || parent.getAggregate() == null) {
                            return false;
                        }
                        String repoRelPath = Text.getName(parentPath) + "/" + repoName;
                        txInfo = modified.get(parent.getAggregate().getPath());
                        if (txInfo == null) {
                            txInfo = new TxInfo(parent.getAggregate());
                            modified.put(parent.getAggregate().getPath(), txInfo);
                        }
                        txInfo.out.getArtifacts().add(new InputSourceArtifact(null,
                                repoRelPath, change.isa.getExtension(),
                                ArtifactType.FILE,
                                change.isa.getInputSource(), change.isa.getSerializationType()
                        ));
                    } else {
                        // repoPath: /vltTest.foo
                        assertInFilter(repoPath);
                        txInfo = modified.get(repoPath);
                        if (txInfo == null) {
                            txInfo = new TxInfo(repoPath,
                                    ((AggregateImpl) parent.getAggregate()).create(repoName));
                            txInfo.parentFile = parent;
                            modified.put(repoPath, txInfo);
                        }
                        txInfo.out.getArtifacts().add(change.isa);
                    }
                } else {
                    // repoPath: /vltTest/foo
                    repoPath = parent.getAggregate().getPath();
                    assertInFilter(repoPath);
                    txInfo = modified.get(repoPath);
                    if (txInfo == null) {
                        txInfo = new TxInfo(parent.getAggregate());
                        txInfo.parentFile = parent;
                        modified.put(repoPath, txInfo);
                    }
                    txInfo.out.getArtifacts().add(change.isa);
                }
                if (txInfo == null) {
                    return false;
                }
                // add sub changes
                if (change.subChanges != null) {
                    for (Change sc: change.subChanges) {
                        // need to adjust relative path of input
                        // repoPath    = /vltTest/foo
                        // sc.repoPath = /vltTest/foo/text/file
                        // relPath     = foo/text/file
                        String relPath = PathUtil.getRelativePath(repoPath, sc.repoPath);
                        relPath  = Text.getName(repoPath) + "/" + relPath;
                        if (!relPath.equals(sc.isa.getRelativePath())) {
                            // todo: check if correct platform path
                            sc.isa = new InputSourceArtifact(
                                    null,
                                    relPath,
                                    "",
                                    sc.isa.getType(),
                                    sc.isa.getInputSource(),
                                    sc.isa.getSerializationType()
                            );
                        }
                        txInfo.out.getArtifacts().add(sc.isa);
                    }
                }
                if (verbose) {
                    log.info("...scheduling ADD {}/{}", parent.getPath(), Constants.DOT_CONTENT_XML);
                }
            } break;
            case ADDED: {
                // get parent file
                String parentPath = Text.getRelativeParent(change.filePath, 1);

                // stop processing if parent file does not exist.
                VaultFile parent = fs.getFile(parentPath);
                String repoName = change.isa.getRelativePath();
                if (parent == null || parent.getAggregate() == null) {
                    if (ignoreMP) {
                        return false;
                    }
                    // Hack: if parent is intermediate directory, search
                    // next valid parent and modify its artifact set.
                    // since we cannot easily determine if the parent is an
                    // intermediate directory, we just process all failing ones
                    // at the end.
                    while ((parent == null || parent.getAggregate() == null)
                            && parentPath.length() > 0) {
                        String parentName = Text.getName(parentPath);
                        if (parentName.endsWith(".dir")) {
                            parentName = parentName.substring(0, parentName.length() - 4);
                        }
                        repoName = PlatformNameFormat.getRepositoryName(parentName) + "/" + repoName;
                        parentPath = Text.getRelativeParent(parentPath, 1);
                        parent = fs.getFile(parentPath);
                    }
                    if (parent == null) {
                        // no parent found ?
                        return false;
                    }
                    String repoPath = parent.getAggregate().getPath();
                    String repoRelPath = Text.getName(repoPath) + "/" + repoName;
                    if (!repoPath.endsWith("/")) {
                        repoPath += "/";
                    }
                    repoPath += repoName;
                    assertInFilter(repoPath);
                    if (false && change.isa.getSerializationType() == SerializationType.XML_DOCVIEW) {
                        // special case that full coverage is below a intermediate
                        // ignore and wait for next cycle
                    } else {
                        TxInfo txInfo = modified.get(parent.getAggregate().getPath());
                        if (txInfo == null) {
                            txInfo = new TxInfo(parent.getAggregate());
                            modified.put(parent.getAggregate().getPath(), txInfo);
                        }
                        txInfo.out.getArtifacts().add(new InputSourceArtifact(null,
                                repoRelPath, change.isa.getExtension(),
                                ArtifactType.FILE,
                                change.isa.getInputSource(), change.isa.getSerializationType()
                        ));
                    }
                } else {
                    String repoPath = parent.getAggregate().getPath();

                    if (!repoPath.endsWith("/")) {
                        repoPath += "/";
                    }
                    repoPath += repoName;
                    assertInFilter(repoPath);
                    TxInfo txInfo = modified.get(repoPath);
                    if (txInfo == null) {
                        txInfo = new TxInfo(repoPath, ((AggregateImpl) parent.getAggregate()).create(repoName));
                        txInfo.setParentFile(parent);
                        modified.put(repoPath, txInfo);
                    }
                    txInfo.out.getArtifacts().add(change.isa);

                }
                if (verbose) {
                    log.info("...scheduling ADD {}/{}", parent.getPath(), repoName);
                }
            } break;
            case MKDIR:{
                // get parent file
                String parentPath = Text.getRelativeParent(change.filePath, 1);
                String name = Text.getName(change.filePath);
                VaultFile parent = fs.getFile(parentPath);
                if (parent == null || parent.isTransient()) {
                    return false;
                }
                String repoName = PlatformNameFormat.getRepositoryName(name);
                int idx = repoName.lastIndexOf('.');
                if (idx > 0) {
                    String base = repoName.substring(0, idx);
                    String ext = repoName.substring(idx);
                    if (ext.equals(".dir")) {
                        // assume no directories with .dir extension
                        repoName = base;
                    }
                }
                String repoPath = parent.getAggregate().getPath();
                if (!repoPath.endsWith("/")) {
                    repoPath += "/";
                }
                repoPath += repoName;
                assertInFilter(repoPath);
                TxInfo txInfo = modified.get(repoPath);
                if (txInfo == null) {
                    txInfo = new TxInfo(repoPath, ((AggregateImpl) parent.getAggregate()).create(repoName));
                    txInfo.setParentFile(parent);
                    modified.put(repoPath, txInfo);
                }
                txInfo.out.addArtifact(new DirectoryArtifact(repoName));
                if (verbose) {
                    log.info("...scheduling MKD {}/{}", parent.getPath(), repoName);
                }
            } break;
            case DELETED: {
                Aggregate an = change.file.getAggregate();
                if (an == null) {
                    // intermediate directory
                    // can't handle here
                    assertInFilter(change.repoPath);
                    TxInfo txInfo = new TxInfo(change.repoPath, null);
                    txInfo.original.put(change.file.getPath(), change.file);
                    modified.put(txInfo.artifactsPath, txInfo);
                } else {
                    assertInFilter(an.getPath());
                    TxInfo txInfo = modified.get(an.getPath());
                    if (txInfo == null) {
                        txInfo = new TxInfo(an);
                        VaultFile dir = null;
                        for (VaultFile rel : change.file.getRelated()) {
                            txInfo.original.put(rel.getPath(), rel);
                            if (rel.isDirectory()) {
                                dir = rel;
                            }
                        }
                        modified.put(txInfo.artifactsPath, txInfo);
                        // set parent file
                        if (dir == null) {
                            txInfo.parentFile = change.file.getParent();
                        } else {
                            txInfo.parentFile = dir.getParent();
                        }
                    }
                    txInfo.out.getArtifacts().remove(change.file.getArtifact());
                    if (verbose) {
                        log.info("...scheduling DEL {}", an.getPath());
                    }
                }
            } break;
            case MODIFIED: {
                Aggregate an = change.file.getAggregate();
                TxInfo txInfo = modified.get(an.getPath());
                if (txInfo == null) {
                    txInfo = new TxInfo(an);
                    VaultFile dir = null;
                    for (VaultFile rel: change.file.getRelated()) {
                        txInfo.original.put(rel.getPath(), rel);
                        if (rel.isDirectory()) {
                            dir = rel;
                        }
                    }
                    modified.put(txInfo.artifactsPath, txInfo);
                    // set parent file
                    if (dir == null) {
                        txInfo.parentFile = change.file.getParent();
                    } else {
                        txInfo.parentFile = dir.getParent();
                    }
                }
                InputSourceArtifact isa = new InputSourceArtifact(change.file.getArtifact(), change.input);
                txInfo.out.getArtifacts().put(isa);
                // add sub changes
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.vault.fs.api.VaultFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.