001/* 002 * (C) Copyright 2002-2012 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 * Antoine Taillefer 016 */ 017package org.nuxeo.ecm.core.convert.plugins.text.extractors; 018 019import java.io.IOException; 020import java.io.Serializable; 021import java.util.Map; 022 023import org.apache.commons.logging.Log; 024import org.apache.commons.logging.LogFactory; 025import org.nuxeo.ecm.core.api.Blob; 026import org.nuxeo.ecm.core.api.Blobs; 027import org.nuxeo.ecm.core.api.blobholder.BlobHolder; 028import org.nuxeo.ecm.core.api.impl.blob.StringBlob; 029import org.nuxeo.ecm.core.convert.api.ConversionException; 030import org.nuxeo.ecm.core.convert.cache.SimpleCachableBlobHolder; 031import org.nuxeo.ecm.core.convert.extension.Converter; 032import org.nuxeo.ecm.core.convert.extension.ConverterDescriptor; 033 034/** 035 * Markdown to text converter. 036 * <p> 037 * It basically returns a {@link StringBlob} with the markdown text and the plain/text mime type. 038 * 039 * @author Antoine Taillefer (ataillefer@nuxeo.com) 040 * @since 5.6 041 */ 042public class MD2TextConverter implements Converter { 043 044 private static final Log LOGGER = LogFactory.getLog(MD2TextConverter.class); 045 046 @Override 047 public BlobHolder convert(BlobHolder blobHolder, Map<String, Serializable> parameters) throws ConversionException { 048 049 try { 050 Blob blob = blobHolder.getBlob(); 051 if (blob == null) { 052 LOGGER.warn("Trying to convert a blobHolder that has a null blob. Nothing to do, returning the blobHolder."); 053 return blobHolder; 054 } 055 String text = blob.getString(); 056 return new SimpleCachableBlobHolder(Blobs.createBlob(text)); 057 } catch (IOException e) { 058 throw new ConversionException("Error during MD2Text conversion", e); 059 } 060 } 061 062 @Override 063 public void init(ConverterDescriptor descriptor) { 064 } 065 066}