001/* 002 * (C) Copyright 2010 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 * Contributors: 016 * Nuxeo - initial API and implementation 017 */ 018package org.nuxeo.ecm.platform.rendition.publisher; 019 020import static org.nuxeo.ecm.platform.rendition.Constants.RENDITION_SOURCE_VERSIONABLE_ID_PROPERTY; 021 022import org.nuxeo.ecm.core.api.CoreSession; 023import org.nuxeo.ecm.core.api.DocumentModel; 024import org.nuxeo.ecm.core.api.IdRef; 025import org.nuxeo.ecm.core.api.UnrestrictedSessionRunner; 026 027/** 028 * Fetched the live doc for a given proxy on a Rendition 029 * 030 * @author <a href="mailto:[email protected]">Tiry</a> 031 */ 032public class RenditionLiveDocFetcher extends UnrestrictedSessionRunner { 033 034 protected final DocumentModel proxy; 035 036 protected final String sid; 037 038 protected DocumentModel liveDocument; 039 040 protected RenditionLiveDocFetcher(CoreSession session, DocumentModel source) { 041 super(session); 042 this.proxy = source; 043 this.sid = session.getSessionId(); 044 } 045 046 @Override 047 public void run() { 048 049 String targetUUID = (String) proxy.getPropertyValue(RENDITION_SOURCE_VERSIONABLE_ID_PROPERTY); 050 liveDocument = session.getDocument(new IdRef(targetUUID)); 051 liveDocument.detach(true); 052 liveDocument.attach(sid); 053 } 054 055 public DocumentModel getLiveDocument() { 056 return liveDocument; 057 } 058 059}