001/*
002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo
018 */
019
020package org.nuxeo.ecm.platform.publisher.impl.core;
021
022import org.nuxeo.common.utils.Path;
023import org.nuxeo.ecm.core.api.DocumentModel;
024import org.nuxeo.ecm.core.api.DocumentRef;
025import org.nuxeo.ecm.core.api.IdRef;
026import org.nuxeo.ecm.core.api.NuxeoException;
027import org.nuxeo.ecm.platform.publisher.api.PublishedDocument;
028import org.nuxeo.ecm.platform.publisher.helper.VersioningHelper;
029
030/**
031 * Implementations of the {@link PublishedDocument} on top of the Core, using simple proxies.
032 *
033 * @author tiry
034 */
035public class SimpleCorePublishedDocument implements PublishedDocument {
036
037    private static final long serialVersionUID = 1L;
038
039    protected DocumentModel proxy;
040
041    protected String versionLabel;
042
043    protected boolean isPending;
044
045    public SimpleCorePublishedDocument(DocumentModel doc) {
046        if (!doc.isProxy()) {
047            throw new NuxeoException("DocumentModel is not a proxy");
048        }
049        this.proxy = doc;
050        this.versionLabel = VersioningHelper.getVersionLabelFor(doc);
051    }
052
053    @Override
054    public DocumentRef getSourceDocumentRef() {
055        return new IdRef(proxy.getSourceId());
056    }
057
058    @Override
059    public String getSourceRepositoryName() {
060        return proxy.getRepositoryName();
061    }
062
063    @Override
064    public String getSourceVersionLabel() {
065        return versionLabel;
066    }
067
068    public DocumentModel getProxy() {
069        return proxy;
070    }
071
072    @Override
073    public String getPath() {
074        return proxy.getPathAsString();
075    }
076
077    @Override
078    public String getParentPath() {
079        Path path = proxy.getPath();
080        return path.removeLastSegments(1).toString();
081    }
082
083    public void setPending(boolean isPending) {
084        this.isPending = isPending;
085    }
086
087    @Override
088    public boolean isPending() {
089        return isPending;
090    }
091
092}