public VaultFileOutput add()

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


    public VaultFileOutput add(String path, VaultInputSource input)
            throws IOException, RepositoryException {

        String repoPath = PlatformNameFormat.getRepositoryPath(path, true);
        String repoName = Text.getName(repoPath);
        String parentPath = Text.getRelativeParent(path, 1);
        String repoParentPath = Text.getRelativeParent(repoPath, 1);

        if (repoName.equals(Constants.DOT_CONTENT_XML)) {
            // special handling for .content.xml
            final Change change = new Change(Type.ADDED_X, repoParentPath, path, input);
            changes.add(change);

            // analyze the xml to scan for added nodes
            DocViewAnalyzer.analyze(
                new DocViewAnalyzerListener(){
                    public void onNode(String path, boolean intermediate, String nodeType) {
                        if (!intermediate) {
                            dotXmlNodes.put(path, new DotXmlInfo(change, nodeType == null));
                        }
                    }
                }, 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
                    if (DocViewParser.isDocView(input)) {
                        // in this case, the extension was added by the exporter.
                        aType = ArtifactType.PRIMARY;
                        repoName = base;
                        extension = ext;
                        serType = SerializationType.XML_DOCVIEW;
                    } else {
                        // force generic
                        serType = SerializationType.GENERIC;
                    }
                } 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);
            return new VaultFileOutputImpl(change);
        }
    }