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.localfs;
021
022import java.io.IOException;
023import java.util.Map;
024
025import org.dom4j.DocumentException;
026import org.nuxeo.ecm.core.api.DocumentModel;
027import org.nuxeo.ecm.core.api.NuxeoException;
028import org.nuxeo.ecm.platform.publisher.api.AbstractBasePublishedDocumentFactory;
029import org.nuxeo.ecm.platform.publisher.api.PublicationNode;
030import org.nuxeo.ecm.platform.publisher.api.PublishedDocument;
031import org.nuxeo.ecm.platform.publisher.api.PublishedDocumentFactory;
032
033public class FSPublishedDocumentFactory extends AbstractBasePublishedDocumentFactory implements
034        PublishedDocumentFactory {
035
036    public PublishedDocument publishDocument(DocumentModel doc, PublicationNode targetNode, Map<String, String> params)
037            {
038
039        try {
040            FSPublishedDocument pubDoc = new FSPublishedDocument("local", doc);
041            pubDoc.persist(targetNode.getPath());
042            return pubDoc;
043        } catch (DocumentException | IOException e) {
044            throw new NuxeoException("Error duning FS Publishing", e);
045        }
046    }
047
048    public PublishedDocument wrapDocumentModel(DocumentModel doc) {
049        try {
050
051            doc = snapshotDocumentBeforePublish(doc);
052            return new FSPublishedDocument("local", doc);
053        } catch (DocumentException e) {
054            throw new NuxeoException("Error while wrapping DocumentModel as FSPublishedDocument", e);
055        }
056    }
057
058}