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 public DocumentRef getSourceDocumentRef() { 054 return new IdRef(proxy.getSourceId()); 055 } 056 057 public String getSourceRepositoryName() { 058 return proxy.getRepositoryName(); 059 } 060 061 public String getSourceVersionLabel() { 062 return versionLabel; 063 } 064 065 public DocumentModel getProxy() { 066 return proxy; 067 } 068 069 public String getPath() { 070 return proxy.getPathAsString(); 071 } 072 073 public String getParentPath() { 074 Path path = proxy.getPath(); 075 return path.removeLastSegments(1).toString(); 076 } 077 078 public void setPending(boolean isPending) { 079 this.isPending = isPending; 080 } 081 082 public boolean isPending() { 083 return isPending; 084 } 085 086}