Package org.apache.jackrabbit.vault.fs.impl.io

Examples of org.apache.jackrabbit.vault.fs.impl.io.InputSourceArtifact


        if (contentXml != null) {
            if (contentXml.isDirectory()) {
                throw new IllegalArgumentException(Constants.DOT_CONTENT_XML + " is not a file");
            }
            // in this case, create a new info
            root.artifacts.add(new InputSourceArtifact(
                    null,
                    "",
                    "",
                    ArtifactType.PRIMARY,
                    archive.getInputSource(contentXml),
View Full Code Here


                if (contentXml != null) {
                    if (contentXml.isDirectory()) {
                        throw new IllegalArgumentException(Constants.DOT_CONTENT_XML + " is not a file");
                    }
                    // in this case, create a new info
                    info.artifacts.add(new InputSourceArtifact(
                            parent,
                            Constants.DOT_CONTENT_XML,
                            "",
                            ArtifactType.PRIMARY,
                            archive.getInputSource(contentXml),
                            SerializationType.XML_DOCVIEW
                    ));
                } else {
                    // this is an empty directory and potential intermediate
                    info.isIntermediate = 1;
                    intermediates.put(repoPath, info);
                    log.debug("Detecting intermediate directory {}", repoName);
                }
                prepare(file, info, resolver);
            }
        }
        // second the files
        for (Archive.Entry file: files) {
            if (!file.isDirectory()) {
                String fileName = file.getName();
                if (isExcluded(fileName)) {
                    continue;
                }
                String repoName = PlatformNameFormat.getRepositoryName(fileName);
                String repoPath = parentInfo.path + "/" + repoName;
                if (file.getName().equals(Constants.DOT_CONTENT_XML)) {
                    continue;
                }
                if (opts.getPatchDirectory() != null && repoPath.startsWith(opts.getPatchParentPath())) {
                    patches.add(file);
                    if (!opts.isPatchKeepInRepo()) {
                        continue;
                    }
                }
                if (repoPath.startsWith("/etc/packages/") && (repoPath.endsWith(".jar") || repoPath.endsWith(".zip"))) {
                    subPackages.add(repoPath);
                }
                String repoBase = repoName;
                String ext = "";
                int idx = repoName.lastIndexOf('.');
                if (idx > 0) {
                    repoBase = repoName.substring(0, idx);
                    ext = repoName.substring(idx);
                }
                SerializationType serType = SerializationType.GENERIC;
                ArtifactType type = ArtifactType.PRIMARY;
                VaultInputSource is = archive.getInputSource(file);
                if (ext.equals(".xml")) {
                    // this can either be an generic exported docview or a 'user-xml' that is imported as file
                    // btw: this only works for input sources that can refetch their input stream
                    serType = XmlAnalyzer.analyze(is);
                    if (serType == SerializationType.XML_DOCVIEW) {
                        // in this case, the extension was added by the exporter.
                        repoName = repoBase;
                    } else {
                        ext = "";
                        serType = SerializationType.GENERIC;
                        type = ArtifactType.FILE;
                    }
                } else if (ext.equals(".cnd")) {
                    if (opts.getCndPattern().matcher(repoPath).matches()) {
                        InputStream in = is.getByteStream();
                        try {
                            Reader r = new InputStreamReader(in, "utf8");
                            CNDReader reader = ServiceProviderFactory.getProvider().getCNDReader();
                            // provide session namespaces
                            reader.read(r, is.getSystemId(), new NamespaceMapping(resolver));
                            nodeTypes.add(reader);
                            log.debug("Loaded nodetypes from {}.", repoPath);
                        } catch (IOException e1) {
                            log.error("Error while reading CND.", e1);
                        } finally {
                            IOUtils.closeQuietly(in);
                        }
                    }
                    ext = "";
                    type = ArtifactType.FILE;
                } else if (ext.equals(".xcnd")) {
                    serType = SerializationType.CND;
                    repoName = repoBase;
                } else if (ext.equals(".binary")) {
                    serType = SerializationType.GENERIC;
                    type = ArtifactType.BINARY;
                    repoName = repoBase;
                } else {
                    ext = "";
                    type = ArtifactType.FILE;
                }
                if (type != ArtifactType.PRIMARY) {
                    // check if info already exists (in case of .dir artifacts)
                    TxInfo parent = parentInfo.children().get(repoName);
                    if (parent == null) {
                        if (type == ArtifactType.BINARY) {
                            // search next parent for binary artifacts
                            parent = parentInfo;
                            while (parent != null && parent.isIntermediate > 0) {
                                parent = parent.parent;
                            }
                            if (parent == null) {
                                log.warn("No parent info found {}. using direct.");
                                parent = parentInfo;
                            }
                        } else {
                            // "normal" file
                            TxInfo tx = new TxInfo(parentInfo, parentInfo.path + "/" + repoName);
                            log.debug("Creating file artifact for {}", repoName);
                            tx.artifacts.add(new InputSourceArtifact(null,
                                    repoName, ext, type, is, serType
                            ));
                            parentInfo.addChild(tx);
                        }
                    }
                    if (parent != null) {
                        String path = parentInfo.path + "/" + repoName;
                        String relPath = parent.name + path.substring(parent.path.length());
                        log.debug("Attaching {} artifact {}", type, path);
                        parent.artifacts.add(new InputSourceArtifact(null,
                                relPath, ext, type, is, serType
                        ));
                    }
                }
                if (type == ArtifactType.PRIMARY) {
                    // if primary artifact, add new tx info
                    TxInfo tx = new TxInfo(parentInfo, parentInfo.path + "/" + repoName);
                    log.debug("Creating primary artifact for {}", repoName);
                    tx.artifacts.add(new InputSourceArtifact(null,
                            repoName, ext, type, is, serType
                    ));
                    parentInfo.addChild(tx);
                }
            }
View Full Code Here

                    }
                }, fs.getAggregateManager().getSession(), repoParentPath, input);
            // create artifact
            String parentExt = parentPath.endsWith(".dir") ? ".dir" : "";
            Artifact parent = new DirectoryArtifact(Text.getName(repoParentPath), parentExt);
            InputSourceArtifact isa = new InputSourceArtifact(
                    parent,
                    Constants.DOT_CONTENT_XML,
                    "",
                    ArtifactType.PRIMARY, input,
                    SerializationType.XML_DOCVIEW);
            isa.setContentType("text/xml");
            // attach to change
            change.isa = isa;
            return new VaultFileOutputImpl(change);

        } else {
            // normal file, detect type
            SerializationType serType = SerializationType.GENERIC;
            ArtifactType aType = ArtifactType.FILE;
            String extension = "";
            int idx = repoName.lastIndexOf('.');
            if (idx > 0) {
                String base = repoName.substring(0, idx);
                String ext = repoName.substring(idx);
                if (ext.equals(".xml")) {
                    // this can either be an generic exported docview or
                    // a 'user-xml' that is imported as file
                    // btw: this only works for input sources that can
                    //      refetch their input stream
                    serType = XmlAnalyzer.analyze(input);
                    if (serType == SerializationType.XML_DOCVIEW) {
                        // in this case, the extension was added by the exporter.
                        aType = ArtifactType.PRIMARY;
                        repoName = base;
                        extension = ext;
                    } else {
                        // force generic
                        serType = SerializationType.GENERIC;
                    }
                } else if (ext.equals(".xcnd")) {
                    aType = ArtifactType.PRIMARY;
                    serType = SerializationType.CND;
                    repoName = base;
                    extension = ext;
                } else if (ext.equals(".binary")) {
                    aType = ArtifactType.BINARY;
                    repoName = base;
                    extension = ext;
                }
            }
            InputSourceArtifact isa = new InputSourceArtifact(null, repoName,
                    extension, aType, input, serType);

            Change change = new Change(Type.ADDED, repoParentPath + "/" + repoName, path, input);
            change.isa = isa;
            changes.add(change);
View Full Code Here

                        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;
View Full Code Here

        if (contentXml != null) {
            if (contentXml.isDirectory()) {
                throw new IllegalArgumentException(Constants.DOT_CONTENT_XML + " is not a file");
            }
            // in this case, create a new info
            root.artifacts.add(new InputSourceArtifact(
                    null,
                    "",
                    "",
                    ArtifactType.PRIMARY,
                    archive.getInputSource(contentXml),
View Full Code Here

                if (contentXml != null) {
                    if (contentXml.isDirectory()) {
                        throw new IllegalArgumentException(Constants.DOT_CONTENT_XML + " is not a file");
                    }
                    // in this case, create a new info
                    info.artifacts.add(new InputSourceArtifact(
                            parent,
                            Constants.DOT_CONTENT_XML,
                            "",
                            ArtifactType.PRIMARY,
                            archive.getInputSource(contentXml),
                            SerializationType.XML_DOCVIEW
                    ));
                } else {
                    // this is an empty directory and potential intermediate
                    info.isIntermediate = 1;
                    intermediates.put(repoPath, info);
                    log.debug("Detecting intermediate directory {}", repoName);
                }
                prepare(file, info, resolver);
            }
        }
        // second the files
        for (Archive.Entry file: files) {
            if (!file.isDirectory()) {
                String fileName = file.getName();
                if (isExcluded(fileName)) {
                    continue;
                }
                String repoName = PlatformNameFormat.getRepositoryName(fileName);
                String repoPath = parentInfo.path + "/" + repoName;
                if (file.getName().equals(Constants.DOT_CONTENT_XML)) {
                    continue;
                }
                if (opts.getPatchDirectory() != null && repoPath.startsWith(opts.getPatchParentPath())) {
                    patches.add(file);
                    if (!opts.isPatchKeepInRepo()) {
                        continue;
                    }
                }
                if (repoPath.startsWith("/etc/packages/") && (repoPath.endsWith(".jar") || repoPath.endsWith(".zip"))) {
                    subPackages.add(repoPath);
                }
                String repoBase = repoName;
                String ext = "";
                int idx = repoName.lastIndexOf('.');
                if (idx > 0) {
                    repoBase = repoName.substring(0, idx);
                    ext = repoName.substring(idx);
                }
                SerializationType serType = SerializationType.GENERIC;
                ArtifactType type = ArtifactType.PRIMARY;
                VaultInputSource is = archive.getInputSource(file);
                if (ext.equals(".xml")) {
                    // this can either be an generic exported docview or a 'user-xml' that is imported as file
                    // btw: this only works for input sources that can refetch their input stream
                    serType = XmlAnalyzer.analyze(is);
                    if (serType == SerializationType.XML_DOCVIEW) {
                        // in this case, the extension was added by the exporter.
                        repoName = repoBase;
                    } else {
                        ext = "";
                        serType = SerializationType.GENERIC;
                        type = ArtifactType.FILE;
                    }
                } else if (ext.equals(".cnd")) {
                    if (opts.getCndPattern().matcher(repoPath).matches()) {
                        InputStream in = is.getByteStream();
                        try {
                            Reader r = new InputStreamReader(in, "utf8");
                            CNDReader reader = ServiceProviderFactory.getProvider().getCNDReader();
                            // provide session namespaces
                            reader.read(r, is.getSystemId(), new NamespaceMapping(resolver));
                            nodeTypes.add(reader);
                            log.debug("Loaded nodetypes from {}.", repoPath);
                        } catch (IOException e1) {
                            log.error("Error while reading CND.", e1);
                        } finally {
                            IOUtils.closeQuietly(in);
                        }
                    }
                    ext = "";
                    type = ArtifactType.FILE;
                } else if (ext.equals(".xcnd")) {
                    serType = SerializationType.CND;
                    repoName = repoBase;
                } else if (ext.equals(".binary")) {
                    serType = SerializationType.GENERIC;
                    type = ArtifactType.BINARY;
                    repoName = repoBase;
                } else {
                    ext = "";
                    type = ArtifactType.FILE;
                }
                if (type != ArtifactType.PRIMARY) {
                    // check if info already exists (in case of .dir artifacts)
                    TxInfo parent = parentInfo.children().get(repoName);
                    if (parent == null) {
                        if (type == ArtifactType.BINARY) {
                            // search next parent for binary artifacts
                            parent = parentInfo;
                            while (parent != null && parent.isIntermediate > 0) {
                                parent = parent.parent;
                            }
                            if (parent == null) {
                                log.warn("No parent info found {}. using direct.");
                                parent = parentInfo;
                            }
                        } else {
                            // "normal" file
                            TxInfo tx = new TxInfo(parentInfo, parentInfo.path + "/" + repoName);
                            log.debug("Creating file artifact for {}", repoName);
                            tx.artifacts.add(new InputSourceArtifact(null,
                                    repoName, ext, type, is, serType
                            ));
                            parentInfo.addChild(tx);
                        }
                    }
                    if (parent != null) {
                        String path = parentInfo.path + "/" + repoName;
                        String relPath = parent.name + path.substring(parent.path.length());
                        log.debug("Attaching {} artifact {}", type, path);
                        parent.artifacts.add(new InputSourceArtifact(null,
                                relPath, ext, type, is, serType
                        ));
                    }
                }
                if (type == ArtifactType.PRIMARY) {
                    // if primary artifact, add new tx info
                    TxInfo tx = new TxInfo(parentInfo, parentInfo.path + "/" + repoName);
                    log.debug("Creating primary artifact for {}", repoName);
                    tx.artifacts.add(new InputSourceArtifact(null,
                            repoName, ext, type, is, serType
                    ));
                    parentInfo.addChild(tx);
                }
            }
View Full Code Here

        if (contentXml != null) {
            if (contentXml.isDirectory()) {
                throw new IllegalArgumentException(Constants.DOT_CONTENT_XML + " is not a file");
            }
            // in this case, create a new info
            root.artifacts.add(new InputSourceArtifact(
                    null,
                    "",
                    "",
                    ArtifactType.PRIMARY,
                    archive.getInputSource(contentXml),
View Full Code Here

                if (contentXml != null) {
                    if (contentXml.isDirectory()) {
                        throw new IllegalArgumentException(Constants.DOT_CONTENT_XML + " is not a file");
                    }
                    // in this case, create a new info
                    info.artifacts.add(new InputSourceArtifact(
                            parent,
                            Constants.DOT_CONTENT_XML,
                            "",
                            ArtifactType.PRIMARY,
                            archive.getInputSource(contentXml),
                            SerializationType.XML_DOCVIEW
                    ));
                } else {
                    // this is an empty directory and potential intermediate
                    info.isIntermediate = 1;
                    intermediates.put(repoPath, info);
                    log.debug("Detecting intermediate directory {}", repoName);
                }
                prepare(file, info, resolver);
            }
        }
        // second the files
        for (Archive.Entry file: files) {
            if (!file.isDirectory()) {
                String fileName = file.getName();
                if (isExcluded(fileName)) {
                    continue;
                }
                String repoName = PlatformNameFormat.getRepositoryName(fileName);
                String repoPath = parentInfo.path + "/" + repoName;
                if (file.getName().equals(Constants.DOT_CONTENT_XML)) {
                    continue;
                }
                if (opts.getPatchDirectory() != null && repoPath.startsWith(opts.getPatchParentPath())) {
                    patches.add(file);
                    if (!opts.isPatchKeepInRepo()) {
                        continue;
                    }
                }
                if (repoPath.startsWith("/etc/packages/") && (repoPath.endsWith(".jar") || repoPath.endsWith(".zip"))) {
                    subPackages.add(repoPath);
                }
                String repoBase = repoName;
                String ext = "";
                int idx = repoName.lastIndexOf('.');
                if (idx > 0) {
                    repoBase = repoName.substring(0, idx);
                    ext = repoName.substring(idx);
                }
                SerializationType serType = SerializationType.GENERIC;
                ArtifactType type = ArtifactType.PRIMARY;
                VaultInputSource is = archive.getInputSource(file);
                if (ext.equals(".xml")) {
                    // this can either be an generic exported docview or a 'user-xml' that is imported as file
                    // btw: this only works for input sources that can refetch their input stream
                    serType = XmlAnalyzer.analyze(is);
                    if (serType == SerializationType.XML_DOCVIEW) {
                        // in this case, the extension was added by the exporter.
                        repoName = repoBase;
                    } else {
                        ext = "";
                        serType = SerializationType.GENERIC;
                        type = ArtifactType.FILE;
                    }
                } else if (ext.equals(".cnd")) {
                    if (opts.getCndPattern().matcher(repoPath).matches()) {
                        InputStream in = is.getByteStream();
                        try {
                            Reader r = new InputStreamReader(in, "utf8");
                            CNDReader reader = ServiceProviderFactory.getProvider().getCNDReader();
                            // provide session namespaces
                            reader.read(r, is.getSystemId(), new NamespaceMapping(resolver));
                            nodeTypes.add(reader);
                            log.debug("Loaded nodetypes from {}.", repoPath);
                        } catch (IOException e1) {
                            log.error("Error while reading CND.", e1);
                        } finally {
                            IOUtils.closeQuietly(in);
                        }
                    }
                    ext = "";
                    type = ArtifactType.FILE;
                } else if (ext.equals(".xcnd")) {
                    serType = SerializationType.CND;
                    repoName = repoBase;
                } else if (ext.equals(".binary")) {
                    serType = SerializationType.GENERIC;
                    type = ArtifactType.BINARY;
                    repoName = repoBase;
                } else {
                    ext = "";
                    type = ArtifactType.FILE;
                }
                if (type != ArtifactType.PRIMARY) {
                    // check if info already exists (in case of .dir artifacts)
                    TxInfo parent = parentInfo.children().get(repoName);
                    if (parent == null) {
                        if (type == ArtifactType.BINARY) {
                            // search next parent for binary artifacts
                            parent = parentInfo;
                            while (parent != null && parent.isIntermediate > 0) {
                                parent = parent.parent;
                            }
                            if (parent == null) {
                                log.warn("No parent info found {}. using direct.");
                                parent = parentInfo;
                            }
                        } else {
                            // "normal" file
                            TxInfo tx = new TxInfo(parentInfo, parentInfo.path + "/" + repoName);
                            log.debug("Creating file artifact for {}", repoName);
                            tx.artifacts.add(new InputSourceArtifact(null,
                                    repoName, ext, type, is, serType
                            ));
                            parentInfo.addChild(tx);
                        }
                    }
                    if (parent != null) {
                        String path = parentInfo.path + "/" + repoName;
                        String relPath = parent.name + path.substring(parent.path.length());
                        log.debug("Attaching {} artifact {}", type, path);
                        parent.artifacts.add(new InputSourceArtifact(null,
                                relPath, ext, type, is, serType
                        ));
                    }
                }
                if (type == ArtifactType.PRIMARY) {
                    // if primary artifact, add new tx info
                    TxInfo tx = new TxInfo(parentInfo, parentInfo.path + "/" + repoName);
                    log.debug("Creating primary artifact for {}", repoName);
                    tx.artifacts.add(new InputSourceArtifact(null,
                            repoName, ext, type, is, serType
                    ));
                    parentInfo.addChild(tx);
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.vault.fs.impl.io.InputSourceArtifact

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.