001/* 002 * (C) Copyright 2014 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-2.1.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 * Vladimir Pasquier <vpasquier@nuxeo.com> 016 */ 017package org.nuxeo.ecm.automation.io.services.enricher; 018 019import java.io.IOException; 020 021import org.codehaus.jackson.JsonGenerator; 022import org.nuxeo.ecm.core.api.DocumentModel; 023import org.nuxeo.ecm.platform.preview.helper.PreviewHelper; 024import org.nuxeo.ecm.platform.preview.io.PreviewJsonEnricher; 025import org.nuxeo.runtime.api.Framework; 026 027/** 028 * This content enricher adds a document Preview URL. 029 * 030 * @since 6.0 031 * @deprecated This enricher was migrated to {@link PreviewJsonEnricher} 032 */ 033@Deprecated 034public class PreviewContentEnricher extends AbstractContentEnricher { 035 036 public static final String PREVIEW_URL_LABEL = "url"; 037 038 public static final String PREVIEW_CONTENT_ID = "preview"; 039 040 @Override 041 public void enrich(JsonGenerator jg, RestEvaluationContext ec) throws IOException { 042 DocumentModel doc = ec.getDocumentModel(); 043 String relativeUrl = PreviewHelper.getPreviewURL(doc); 044 jg.writeStartObject(); 045 if (relativeUrl != null && !relativeUrl.isEmpty()) { 046 String url = Framework.getProperty("nuxeo.url") + "/" + PreviewHelper.getPreviewURL(doc); 047 jg.writeStringField(PREVIEW_URL_LABEL, url); 048 } else { 049 writeEmptyURL(jg); 050 } 051 jg.writeEndObject(); 052 jg.flush(); 053 } 054 055 private void writeEmptyURL(JsonGenerator jg) throws IOException { 056 jg.writeStringField(PREVIEW_URL_LABEL, null); 057 } 058 059}