001/*
002 * (C) Copyright 2010 Nuxeo SAS (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 *     Nuxeo - initial API and implementation
016 */
017
018package org.nuxeo.ecm.platform.convert.plugins;
019
020import java.io.Serializable;
021import java.util.HashMap;
022import java.util.List;
023import java.util.Map;
024
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.convert.api.ConversionException;
029import org.nuxeo.ecm.core.convert.cache.SimpleCachableBlobHolder;
030import org.nuxeo.ecm.platform.commandline.executor.api.CmdParameters;
031
032public class WordPerfect2TextConverter extends CommandLineBasedConverter {
033
034    @Override
035    protected BlobHolder buildResult(List<String> cmdOutput, CmdParameters cmdParams) throws ConversionException {
036
037        StringBuilder sb = new StringBuilder();
038
039        if (cmdOutput != null) {
040            for (String out : cmdOutput) {
041                if (out != null && out.trim().length() > 0) {
042                    sb.append(out.trim());
043                    sb.append('\n');
044                }
045            }
046        }
047        return new SimpleCachableBlobHolder(Blobs.createBlob(sb.toString()));
048    }
049
050    @Override
051    protected Map<String, Blob> getCmdBlobParameters(BlobHolder blobHolder, Map<String, Serializable> parameters)
052            throws ConversionException {
053        Map<String, Blob> cmdBlobParams = new HashMap<String, Blob>();
054        cmdBlobParams.put("inFilePath", blobHolder.getBlob());
055        return cmdBlobParams;
056    }
057
058    @Override
059    protected Map<String, String> getCmdStringParameters(BlobHolder blobHolder, Map<String, Serializable> parameters)
060            throws ConversionException {
061        return new HashMap<String, String>();
062    }
063
064}