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}. The content enricher service doesn't work 032 * anymore. 033 */ 034@Deprecated 035public class PreviewContentEnricher extends AbstractContentEnricher { 036 037 public static final String PREVIEW_URL_LABEL = "url"; 038 039 public static final String PREVIEW_CONTENT_ID = "preview"; 040 041 @Override 042 public void enrich(JsonGenerator jg, RestEvaluationContext ec) throws IOException { 043 DocumentModel doc = ec.getDocumentModel(); 044 String relativeUrl = PreviewHelper.getPreviewURL(doc); 045 jg.writeStartObject(); 046 if (relativeUrl != null && !relativeUrl.isEmpty()) { 047 String url = Framework.getProperty("nuxeo.url") + "/" + PreviewHelper.getPreviewURL(doc); 048 jg.writeStringField(PREVIEW_URL_LABEL, url); 049 } else { 050 writeEmptyURL(jg); 051 } 052 jg.writeEndObject(); 053 jg.flush(); 054 } 055 056 private void writeEmptyURL(JsonGenerator jg) throws IOException { 057 jg.writeStringField(PREVIEW_URL_LABEL, null); 058 } 059 060}