001/*
002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo
016 */
017
018package org.nuxeo.ecm.platform.publisher.impl.core;
019
020import org.nuxeo.common.utils.Path;
021import org.nuxeo.ecm.core.api.DocumentModel;
022import org.nuxeo.ecm.core.api.DocumentRef;
023import org.nuxeo.ecm.core.api.IdRef;
024import org.nuxeo.ecm.core.api.NuxeoException;
025import org.nuxeo.ecm.platform.publisher.api.PublishedDocument;
026import org.nuxeo.ecm.platform.publisher.helper.VersioningHelper;
027
028/**
029 * Implementations of the {@link PublishedDocument} on top of the Core, using simple proxies.
030 *
031 * @author tiry
032 */
033public class SimpleCorePublishedDocument implements PublishedDocument {
034
035    private static final long serialVersionUID = 1L;
036
037    protected DocumentModel proxy;
038
039    protected String versionLabel;
040
041    protected boolean isPending;
042
043    public SimpleCorePublishedDocument(DocumentModel doc) {
044        if (!doc.isProxy()) {
045            throw new NuxeoException("DocumentModel is not a proxy");
046        }
047        this.proxy = doc;
048        this.versionLabel = VersioningHelper.getVersionLabelFor(doc);
049    }
050
051    public DocumentRef getSourceDocumentRef() {
052        return new IdRef(proxy.getSourceId());
053    }
054
055    public String getSourceServer() {
056        return "local";
057    }
058
059    public String getSourceRepositoryName() {
060        return proxy.getRepositoryName();
061    }
062
063    public String getSourceVersionLabel() {
064        return versionLabel;
065    }
066
067    public DocumentModel getProxy() {
068        return proxy;
069    }
070
071    public String getPath() {
072        return proxy.getPathAsString();
073    }
074
075    public String getParentPath() {
076        Path path = proxy.getPath();
077        return path.removeLastSegments(1).toString();
078    }
079
080    public void setPending(boolean isPending) {
081        this.isPending = isPending;
082    }
083
084    public boolean isPending() {
085        return isPending;
086    }
087
088    public Type getType() {
089        return Type.LOCAL;
090    }
091
092}