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.remoting.server;
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.platform.publisher.api.PublishedDocument;
026import org.nuxeo.ecm.platform.publisher.helper.VersioningHelper;
027import org.nuxeo.ecm.platform.publisher.remoting.marshaling.ExtendedDocumentLocation;
028
029/**
030 * {@link PublishedDocument} implementation that uses a {@link DocumentModel} to store the result of a remote
031 * publication.
032 *
033 * @author tiry
034 */
035public class ExternalCorePublishedDocument implements PublishedDocument {
036
037    private static final long serialVersionUID = 1L;
038
039    protected String sourceServer;
040
041    protected String repositoryName;
042
043    protected DocumentRef ref;
044
045    protected String versionLabel;
046
047    protected String path;
048
049    protected String parentPath;
050
051    protected boolean isPending;
052
053    public ExternalCorePublishedDocument(DocumentModel doc) {
054        ExtendedDocumentLocation xLoc = ExtendedDocumentLocation.extractFromDoc(doc);
055        this.sourceServer = xLoc.getOriginalServer();
056        this.repositoryName = xLoc.getServerName();
057        this.ref = xLoc.getDocRef();
058        versionLabel = VersioningHelper.getVersionLabelFor(doc);
059        Path p = doc.getPath();
060        path = p.toString();
061        parentPath = p.removeLastSegments(1).toString();
062    }
063
064    public DocumentRef getSourceDocumentRef() {
065        return ref;
066    }
067
068    public String getSourceRepositoryName() {
069        return repositoryName;
070    }
071
072    public String getSourceServer() {
073        return sourceServer;
074    }
075
076    public String getSourceVersionLabel() {
077        return versionLabel;
078    }
079
080    public String getPath() {
081        return path;
082    }
083
084    public String getParentPath() {
085        return parentPath;
086    }
087
088    public boolean isPending() {
089        return isPending;
090    }
091
092    public Type getType() {
093        return Type.REMOTE;
094    }
095
096}