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