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

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


            }
        } else {
            node = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
        }

        Artifact a = info.artifacts.get(0);
        // Keep track of whether this file got modified
        boolean modified = false;
        // Set the jcr:data property
        ValueFactory factory = node.getSession().getValueFactory();
        Value value = factory.createValue(a.getInputStream());
        if (node.hasProperty(JcrConstants.JCR_DATA)) {
            Property data = node.getProperty(JcrConstants.JCR_DATA);
            if (!value.equals(data.getValue())) {
                data.setValue(value);
                // mark jcr:data as modified.
                importInfo.onModified(data.getPath());
                modified = true;
            }
        } else {
            Property data = node.setProperty(JcrConstants.JCR_DATA, value);
            // mark jcr:data as created
            importInfo.onCreated(data.getPath());
            modified = true;
        }

        // always update last modified if binary was modified (bug #22969)
        if (!node.hasProperty(JcrConstants.JCR_LASTMODIFIED) || modified) {
            Calendar lastModified = Calendar.getInstance();
            node.setProperty(JcrConstants.JCR_LASTMODIFIED, lastModified);
            modified = true;
        }
        // do not overwrite mimetype
        if (!node.hasProperty(JcrConstants.JCR_MIMETYPE)) {
            String mimeType = a.getContentType();
            if (mimeType == null) {
                mimeType = Text.getName(a.getRelativePath(), '.');
                mimeType = MimeTypes.getMimeType(mimeType, MimeTypes.APPLICATION_OCTET_STREAM);
            }
            node.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);
            modified = true;
        }
View Full Code Here


        public Value[] getValues(Session session)
                throws RepositoryException, IOException {
            Value[] values = new Value[artifacts.size()];
            for (int i=0; i<values.length; i++) {
                Artifact a = artifacts.get(i);
                values[i] = session.getValueFactory().createValue(a.getInputStream());
            }
            return values;
        }
View Full Code Here

            return values;
        }

        public Value getValue(Session session)
                throws RepositoryException, IOException {
            Artifact a = artifacts.get(0);
            return session.getValueFactory().createValue(a.getInputStream());
        }
View Full Code Here

                    repoName = repoName.substring(0, repoName.length() - 4);
                    repoPath = parentInfo.path + "/" + repoName;
                }
                TxInfo info = parentInfo.addChild(new TxInfo(parentInfo, repoPath));
                log.debug("Creating directory artifact for {}", repoName);
                Artifact parent = new DirectoryArtifact(repoName);
                info.artifacts.add(parent);

                Archive.Entry contentXml = file.getChild(Constants.DOT_CONTENT_XML);
                if (contentXml != null) {
                    if (contentXml.isDirectory()) {
View Full Code Here

     */
    protected ImportInfoImpl accept(WorkspaceFilter wspFilter, Node parent,
                                String name, ArtifactSetImpl artifacts)
            throws RepositoryException, IOException {
        // need at least one primary data
        Artifact primary = artifacts.getPrimaryData();
        if (primary == null) {
            return null;
        }
        if (artifacts.size() != 1) {
            return null;
        }
        if (primary.getSerializationType() != SerializationType.CND) {
            return null;
        }
        String path = PathUtil.getPath(parent, primary.getRelativePath());
        if (wspFilter.getImportMode(path) == ImportMode.MERGE) {
            ImportInfoImpl info = new ImportInfoImpl();
            info.onNop(path);
            return info;
        }
        // do import
        CNDImporter importer = new CNDImporter();
        InputStream in = primary.getInputStream();
        try {
            Reader r = new InputStreamReader(in, "utf-8");
            return importer.doImport(parent, primary.getRelativePath(), r, primary.getRelativePath());
        } finally {
            in.close();
        }
    }
View Full Code Here

     * Handles generic artifact sets
     */
    public ImportInfoImpl accept(WorkspaceFilter wspFilter, Node parent,
                                 String name, ArtifactSetImpl artifacts)
            throws RepositoryException, IOException {
        Artifact primary = artifacts.getPrimaryData();
        if (primary == null) {
            return null;
        }

        // check type of primary artifact
        ImportInfoImpl info = null;
        InputSource source = primary.getInputSource();
        if (source != null && primary.getSerializationType() == SerializationType.XML_DOCVIEW) {
            // primary docview artifact. don't except to have additional
            // extra content artifacts
            info = new ImportInfoImpl();
            String path = PathUtil.getPath(parent, name);
            if (name.length() == 0 || parent.hasNode(name)) {
View Full Code Here

        if (local.hasNode(JcrConstants.JCR_CONTENT)) {
            content = local.getNode(JcrConstants.JCR_CONTENT);
        } else {
            content = local.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
        }
        Artifact a = file.getArtifact();
        switch (a.getPreferredAccess()) {
            case NONE:
                throw new RepositoryException("Artifact has no content.");

            case SPOOL:
                // we can't support spool
            case STREAM:
                InputStream in = a.getInputStream();
                Binary b = content.getSession().getValueFactory().createBinary(in);
                content.setProperty(JcrConstants.JCR_DATA, b);
                b.dispose();
                in.close();
                break;
        }
        Calendar now = Calendar.getInstance();
        if (a.getLastModified() >= 0) {
            now.setTimeInMillis(a.getLastModified());
        }
        content.setProperty(JcrConstants.JCR_LASTMODIFIED, now);
        if (a.getContentType() != null) {
            content.setProperty(JcrConstants.JCR_MIMETYPE, a.getContentType());
        } else if (!content.hasProperty(JcrConstants.JCR_MIMETYPE)){
            content.setProperty(JcrConstants.JCR_MIMETYPE, "application/octet-stream");
        }
    }
View Full Code Here

            exportInfo.update(ExportInfo.Type.UPDATE, local.getPath());
        } else {
            exportInfo.update(ExportInfo.Type.ADD, local.getPath());
        }
        track("A", PathUtil.getRelativeFilePath(localParent.getAbsolutePath(), local.getAbsolutePath()));
        Artifact a = file.getArtifact();
        switch (a.getPreferredAccess()) {
            case NONE:
                throw new RepositoryException("Artifact has no content.");

            case SPOOL:
                FileOutputStream out = new FileOutputStream(local);
                a.spool(out);
                out.close();
                break;

            case STREAM:
                InputStream in = a.getInputStream();
                out = new FileOutputStream(local);
                IOUtils.copy(in, out);
                in.close();
                out.close();
                break;
        }
        if (a.getLastModified() >= 0) {
            local.setLastModified(a.getLastModified());
        }
    }
View Full Code Here

     * Handles generic artifact sets
     */
    public ImportInfoImpl accept(WorkspaceFilter wspFilter, Node parent, String name,
                             ArtifactSetImpl artifacts)
            throws RepositoryException, IOException {
        Artifact dir = artifacts.getDirectory();
        if (dir == null || artifacts.size() != 1) {
            return null;
        }
        ImportInfoImpl info = new ImportInfoImpl();
        if (dir.getRelativePath().length() == 0) {
            // special check if artifact addresses itself
            return info;
        }
        if (!parent.hasNode(dir.getRelativePath())) {
            Node node = parent.addNode(dir.getRelativePath(), nodeType);
            info.onCreated(node.getPath());
        } else {
            // sync nodes
            Set<String> hints = new HashSet<String>();
            String rootPath = parent.getPath();
            if (!rootPath.equals("/")) {
                rootPath += "/";
            }
            for (Artifact a: artifacts.values(ArtifactType.HINT)) {
                hints.add(rootPath + a.getRelativePath());
            }

            Node node = parent.getNode(dir.getRelativePath());
            NodeIterator iter = node.getNodes();
            while (iter.hasNext()) {
                Node child = iter.nextNode();
                String path = child.getPath();
                if (wspFilter.contains(path)) {
View Full Code Here

        }

        // need at least a file or binary artifact
        if (artifacts.size(ArtifactType.FILE) > 0 || artifacts.size(ArtifactType.BINARY) > 0) {
            // check if the generic handler can import something
            Artifact primary = artifacts.getPrimaryData();
            if (primary != null) {
                if (info == null) {
                    info = new ImportInfoImpl();
                }
                // check import mode
                ImportMode mode = ImportMode.REPLACE;
                String path = PathUtil.getPath(parent, primary.getRelativePath());
                if (primary.getRelativePath().length() == 0 || parent.hasNode(primary.getRelativePath())) {
                    mode = wspFilter.getImportMode(path);
                }
                // only update if not MERGE (i.e. is REPLACE or UPDATE)
                if (mode != ImportMode.MERGE) {
                    InputSource source = primary.getInputSource();
                    if (source != null) {
                        info.merge(importDocView(parent, source, artifacts, wspFilter));
                    }
                } else {
                    info.onNop(path);
View Full Code Here

TOP

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

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.