private boolean processChange()

in vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/TransactionImpl.java [362:666]


    private boolean processChange(Change change, Map<String, TxInfo> modified, boolean ignoreMP)
            throws RepositoryException, IOException {
        switch (change.type) {
            case ADDED_X: {
                // special handling for .content.xml
                // 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
                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(change.repoPath, sc.repoPath);
                        relPath  = Text.getName(change.repoPath) + "/" + relPath;
                        if (!relPath.equals(sc.isa.getRelativePath())) {
                            // todo: check if correct platform path
                            sc.isa = new InputSourceArtifact(
                                    null,
                                    relPath,
                                    sc.isa.getExtension(),
                                    sc.isa.getType(),
                                    sc.isa.getInputSource(),
                                    sc.isa.getSerializationType()
                            );
                        }
                        txInfo.out.getArtifacts().add(sc.isa);
                    }
                }

                if (verbose) {
                    log.info("...scheduling UPD {}/{}", isa.getRelativePath());
                }
            } break;
            case MOVED:
            case ERROR:
                break;
        }
        return true;
    }