Package org.apache.jackrabbit.vault.vlt.meta

Examples of org.apache.jackrabbit.vault.vlt.meta.VltEntryInfo


    public void setProperty(String name, String value) throws VltException {
        if (entry == null) {
            throw error("Can't set property to non controlled file.");
        }
        VltEntryInfo info = entry.work();
        if (info == null) {
            throw error("Can't set property to non controlled file.");
        }
        if (name.equals(PROP_CONTENT_TYPE)) {
            if (!file.isDirectory()) {
                // silently ignore directories
                info.setContentType(value);
                parent.getContext().printMessage(this, name + "=" + value);
            }
        } else {
            throw error("Generic properies not supported, yet");
        }
View Full Code Here


                                state = State.CLEAN;
                            } else {
                                state = State.OBSTRUCTED;
                            }
                        } else {
                            VltEntryInfo work = entry.work();
                            VltEntryInfo base = entry.base();
                            assert work != null;
                            assert base != null;

                            try {
                                work.update(file, false);
View Full Code Here

        }
    }

    public String getContentType() {
        if (entry != null && !file.isDirectory()) {
            VltEntryInfo work = entry.work();
            if (work != null) {
                return work.getContentType();
            }
        }
        return null;
    }
View Full Code Here

    public void diff() throws VltException {
        State state = getStatus();
        if (entry == null || entry.isDirectory()) {
            return;
        }
        VltEntryInfo work = entry.work();
        VltEntryInfo base = entry.base();
        if (work == null || base == null) {
            return;
        }
        switch (state) {
            case ADDED:
            case CONFLICTED:
            case DELETED:
            case MODIFIED:
                break;
            case IGNORED:
            case MISSING:
            case OBSTRUCTED:
            case REPLACED:
            case UNKNOWN:
            case VOID:
            case CLEAN:
                return;
        }
        if (MimeTypes.isBinary(work.getContentType()) || MimeTypes.isBinary(base.getContentType())) {
            PrintStream s = parent.getContext().getStdout();
            s.printf("Index: %s%n", getName());
            s.println("===================================================================");
            s.println("Cannot display: file marked as binary type.");
            s.printf("vlt:mime-type = %s%n", work.getContentType());
View Full Code Here

    }

    private FileAction doAdd(boolean force) throws VltException {
        assert entry == null;
        entry = parent.getEntries().update(getName(), null, null);
        VltEntryInfo work = entry.create(VltEntryInfo.Type.WORK);
        try {
            work.update(file, true);
        } catch (IOException e) {
            throw exception("Error while adding file", e);
        }
        String contentType = MimeTypes.getMimeType(file.getName(), MimeTypes.APPLICATION_OCTET_STREAM);
        work.setContentType(contentType);
        entry.put(work);
        return FileAction.ADDED;
    }
View Full Code Here

            return action;
        }
        MetaFile baseFile = getBaseFile(false);
        MetaFile tmpFile = getTmpFile();

        VltEntryInfo base = entry.base();
        VltEntryInfo work = entry.work();
        byte[] lineFeed = MimeTypes.isBinary(remoteFile.getContentType())
                ? null
                : LineOutputStream.LS_NATIVE;

        // get the remote file
        VaultFileCopy copy = null;
        boolean remoteUpdated = true;
        try {
            // first check size and last modified
            if (!base.checkModified(remoteFile)) {
                remoteUpdated = false;
            } else {
                File temp = tmpFile.openTempFile();
                copy = VaultFileCopy.copy(remoteFile, temp, lineFeed);
                // if tmp is equal to the base one, there was no update on the server
                if (copy.getMd5().equals(base.getMd5())) {
                    tmpFile.closeTempFile(tmpFile.length() >= 0);
                    remoteUpdated = false;
                } else {
                    tmpFile.closeTempFile(false);
                }
            }
        } catch (IOException e) {
            throw exception("Error while copying files.", e);
        }
        if (!remoteUpdated) {
            if (work.getMd5().equals(base.getMd5())) {
                // fix base
                base.setSize(work.getSize());
                base.setDate(work.getDate());
                return FileAction.VOID;
            } else if (remoteFile.lastModified() > 0) {
                // normal modification provided
                return action;
            }
        }

        try {
            // check if binary
            boolean remoteBT = getRemoteBinaryType(remoteFile, copy);
            boolean localBT = MimeTypes.isBinary(base.getContentType());
            if (remoteBT || localBT) {
                parent.getContext().printMessage(this, "can't merge. binary content");
                entry.conflict(file, baseFile, tmpFile);
                return FileAction.CONFLICTED;
            }

            // do a 3-way diff between the base, the local and the remote one.
            // we currently do not use document sources, since we don't really have
            // a label to provide (like rev. num, etc).
            Reader r0 = baseFile.getReader();
            Reader r1 = tmpFile.getReader();
            Document baseDoc = new Document(null, LineElementsFactory.create(new MetaFileDocSource(baseFile), r0, false));
            Document leftDoc = new Document(null, LineElementsFactory.create(new FileDocumentSource(file), false, Constants.ENCODING));
            Document rightDoc = new Document(null, LineElementsFactory.create(new MetaFileDocSource(tmpFile), r1, false));

            DocumentDiff3 diff;
            try {
                diff = baseDoc.diff3(leftDoc, rightDoc);
            } finally {
                IOUtils.closeQuietly(r0);
                IOUtils.closeQuietly(r1);
            }

            // save the diff output
            Writer out = new OutputStreamWriter(FileUtils.openOutputStream(file), Constants.ENCODING);
            try {
                diff.write(new DiffWriter(out), false);
            } catch (IOException e) {
                IOUtils.closeQuietly(out);
            }

            if (diff.hasConflicts()) {
                entry.conflict(file, baseFile, tmpFile);
                action = FileAction.CONFLICTED;
            } else {
                // make the tmp file the new base
                tmpFile.moveTo(baseFile);
                base.update(baseFile, true);
                action = FileAction.MERGED;
            }

            // and update the 'work'
            // check if MD5 changes and change action accordingly
            MD5 oldMd5 = work.getMd5();
            work.update(file, true);
            if (oldMd5.equals(work.getMd5())) {
                action = FileAction.VOID;
            }
            // check if remote file provided a last modified
            if (remoteFile.lastModified() == 0) {
                if (work.getMd5().equals(base.getMd5())) {
                    base.setDate(work.getDate());
                } else {
                    base.setDate(System.currentTimeMillis());
                }
            }
View Full Code Here

            return FileAction.VOID;
        }

        MetaFile tmpFile = getTmpFile();

        VltEntryInfo base = entry.base();

        // get the remote file
        byte[] lineFeed = MimeTypes.isBinary(remoteFile.getContentType())
                ? null
                : LineOutputStream.LS_NATIVE;
        VaultFileCopy copy;
        try {
            File temp = tmpFile.openTempFile();
            copy = VaultFileCopy.copy(remoteFile, temp, lineFeed);
            if (base == null) {
                tmpFile.closeTempFile(true);
                // if base is null, file was only added so check the work entry
                VltEntryInfo work = entry.work();
                if (copy.getMd5().equals(work.getMd5())) {
                    return FileAction.VOID;
                } else {
                    return FileAction.CONFLICTED;
                }
            }
View Full Code Here

                getBaseFile(false).copyTo(getFile(), true);
            } catch (IOException e) {
                throw exception("Error while copying files.", e);
            }
        }
        VltEntryInfo base = entry.base();
        entry.put(base.copyAs(VltEntryInfo.Type.WORK));
    }
View Full Code Here

                    // ignore
                }
            }
        }
        // if md5 is equal, no update
        VltEntryInfo base = entry.base();
        return copy.getMd5().equals(base.getMd5());
    }
View Full Code Here

    }

    private FileAction doUpdate(VaultFile remoteFile, boolean baseOnly)
            throws VltException {
        FileAction action;
        VltEntryInfo base;
        if (entry == null || entry.base() == null) {
            // new entry
            action = FileAction.ADDED;
            entry = parent.getEntries().update(getName(), remoteFile.getAggregatePath(), remoteFile.getRepoRelPath());
            base = entry.create(VltEntryInfo.Type.BASE);
            entry.put(base);
        } else {
            action = FileAction.UPDATED;
            base = entry.base();

            // quick check if modified
            if (!base.checkModified(remoteFile)) {
                return FileAction.VOID;
            }
        }
        long lastMod = remoteFile.lastModified();
        if (lastMod == 0) {
            lastMod = System.currentTimeMillis();
        }
        base.setDate(lastMod);

        if (remoteFile.isDirectory()) {
            if (!baseOnly) {
                // ensure controlled
                // todo: this does not belong here
                if (entry.work() != null) {
                    action = FileAction.VOID;
                } else {
                    entry.put(base.copyAs(VltEntryInfo.Type.WORK));
                }
                file.mkdir();
                file.setLastModified(base.getDate());
                VltDirectory dir = new VltDirectory(parent.getContext(), file);
                if (!dir.isControlled()) {
                    dir.control(remoteFile.getPath(), remoteFile.getControllingAggregate().getPath());
                    action = FileAction.ADDED;
                }
            }
        } else {
            MetaFile baseFile = getBaseFile(true);

            // copy file
            byte[] lineFeed = MimeTypes.isBinary(remoteFile.getContentType())
                    ? null
                    : LineOutputStream.LS_NATIVE;
            VaultFileCopy copy;
            try {
                File temp = baseFile.openTempFile();
                copy = VaultFileCopy.copy(remoteFile, temp, lineFeed);
                baseFile.closeTempFile(false);
            } catch (IOException e) {
                throw exception("Error while copying files.", e);
            }
            // if md5 is equal, no update
            if (copy.getMd5().equals(base.getMd5())) {
                action = FileAction.VOID;
            }

            if (action == FileAction.VOID
                    && (base.getContentType() != null || remoteFile.getContentType() != null)
                    && (base.getContentType() == null || !base.getContentType().equals(remoteFile.getContentType()))) {
                action = FileAction.UPDATED;
            }

            // update infos
            VltEntryInfo work = entry.work();
            base.setContentType(remoteFile.getContentType());
            base.setSize(copy.getLength());
            base.setMd5(copy.getMd5());
            if (!baseOnly) {
                // only copy if not equal
                if (work == null || !work.getMd5().equals(copy.getMd5()) || !getFile().exists()) {
                    try {
                        baseFile.copyTo(getFile(), true);
                        entry.put(base.copyAs(VltEntryInfo.Type.WORK));
                    } catch (IOException e) {
                        throw exception("Error while copying files.", e);
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.vault.vlt.meta.VltEntryInfo

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.