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