public ArtifactSet createArtifacts()

in vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/aggregator/FileAggregator.java [155:242]


    public ArtifactSet createArtifacts(Aggregate aggregate) throws RepositoryException {
        ArtifactSetImpl artifacts = new ArtifactSetImpl();
        Node node = aggregate.getNode();
        aggregate.getManager().addNodeTypes(node);
        Node content = node;
        if (content.isNodeType(JcrConstants.NT_FILE)) {
            content = node.getNode(JcrConstants.JCR_CONTENT);
            aggregate.getManager().addNodeTypes(content);
        }
        // retrieve basic properties
        long lastModified = 0;
        String encoding = null;
        try {
            lastModified = content.getProperty(JcrConstants.JCR_LASTMODIFIED).getDate().getTimeInMillis();
        } catch (RepositoryException e) {
            // ignore
        }
        String mimeType = null;
        if (content.hasProperty(JcrConstants.JCR_MIMETYPE)) {
            try {
                mimeType = content.getProperty(JcrConstants.JCR_MIMETYPE).getString();
            } catch (RepositoryException e) {
                // ignore
            }
        }
        if (mimeType == null) {
            // guess mime type from name
            mimeType = MimeTypes.getMimeType(node.getName(), MimeTypes.APPLICATION_OCTET_STREAM);
        }

        if (content.hasProperty(JcrConstants.JCR_ENCODING)) {
            try {
                encoding = content.getProperty(JcrConstants.JCR_ENCODING).getString();
            } catch (RepositoryException e) {
                // ignore
            }
        }
        // check needs .dir artifact nt:file. we trust that the repository does
        // not add other properties than the one defined in JCR.
        boolean needsDir = !node.getPrimaryNodeType().getName().equals(JcrConstants.NT_FILE);
        if (!needsDir) {
            // suppress mix:lockable (todo: make configurable)
            if (node.hasProperty(JcrConstants.JCR_MIXINTYPES)) {
                for (Value v: node.getProperty(JcrConstants.JCR_MIXINTYPES).getValues()) {
                    if (!v.getString().equals(JcrConstants.MIX_LOCKABLE)) {
                        needsDir = true;
                        break;
                    }
                }
            }
        }
        if (!needsDir) {
            needsDir = !content.getPrimaryNodeType().getName().equals(JcrConstants.NT_RESOURCE);
        }
        if (!needsDir) {
            if (content.hasProperty(JcrConstants.JCR_MIXINTYPES)) {
                for (Value v: content.getProperty(JcrConstants.JCR_MIXINTYPES).getValues()) {
                    if (!v.getString().equals(JcrConstants.MIX_LOCKABLE)) {
                        needsDir = true;
                        break;
                    }
                }
            }
        }
        if (!needsDir) {
            needsDir = !MimeTypes.matches(node.getName(), mimeType, MimeTypes.APPLICATION_OCTET_STREAM);
        }
        if (!needsDir && encoding != null) {
            needsDir = !"utf-8".equals(encoding) || MimeTypes.isBinary(mimeType);
        }

        // create file artifact
        String name = aggregate.getName();
        artifacts.add(null, name, "", ArtifactType.FILE,
                content.getProperty(JcrConstants.JCR_DATA), lastModified);

        // create .dir artifact
        if (needsDir) {
            // in this case, we create a directory artifact
            Artifact parent = new DirectoryArtifact(name, ".dir");
            artifacts.add(parent);
            // and extra
            Serializer ser = new DocViewSerializer(aggregate);
            // hack: do better
            artifacts.add(parent, "", Constants.DOT_CONTENT_XML, ArtifactType.PRIMARY, ser, 0);
        }
        return artifacts;
    }