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.remoting.marshaling.io; 019 020import java.io.IOException; 021 022import org.nuxeo.common.utils.Path; 023import org.nuxeo.ecm.core.api.CoreSession; 024import org.nuxeo.ecm.core.api.DocumentLocation; 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.core.api.DocumentRef; 027import org.nuxeo.ecm.core.io.DocumentTranslationMap; 028import org.nuxeo.ecm.core.io.ExportedDocument; 029import org.nuxeo.ecm.core.io.impl.AbstractDocumentModelWriter; 030import org.nuxeo.ecm.core.io.impl.DocumentTranslationMapImpl; 031import org.nuxeo.ecm.core.io.impl.plugins.DocumentModelWriter; 032 033/** 034 * {@link DocumentModelWriter} that creates a shallow DocumentModel (ie: no path and no uuid). 035 * 036 * @author tiry 037 */ 038public class SingleShadowDocumentWriter extends AbstractDocumentModelWriter { 039 040 protected DocumentModel dm; 041 042 public SingleShadowDocumentWriter(CoreSession session, String parentPath) { 043 super(session, "/"); 044 } 045 046 @Override 047 public DocumentTranslationMap write(ExportedDocument doc) throws IOException { 048 dm = createDocument(doc, null); 049 // keep location unchanged 050 DocumentLocation oldLoc = doc.getSourceLocation(); 051 String oldServerName = oldLoc.getServerName(); 052 DocumentRef oldDocRef = oldLoc.getDocRef(); 053 DocumentTranslationMap map = new DocumentTranslationMapImpl(oldServerName, oldServerName); 054 map.put(oldDocRef, oldDocRef); 055 return map; 056 } 057 058 @Override 059 protected DocumentModel createDocument(ExportedDocument xdoc, Path toPath) { 060 String docType = xdoc.getType(); 061 dm = session.createDocumentModel(docType); 062 // then load schemas data 063 loadSchemas(xdoc, dm, xdoc.getDocument()); 064 return dm; 065 } 066 067 public DocumentModel getShadowDocument() { 068 return dm; 069 } 070}