001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.util;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.StringBundler;
020    import com.liferay.portal.kernel.util.Validator;
021    
022    import java.util.LinkedList;
023    import java.util.List;
024    import java.util.Properties;
025    
026    import jodd.util.StringPool;
027    
028    import org.im4java.core.ConvertCmd;
029    
030    /**
031     * @author Alexander Chow
032     */
033    public class LiferayConvertCmd extends ConvertCmd {
034    
035            public static void run(
036                            String globalSearchPath, Properties resourceLimitsProperties,
037                            List<String> commandArguments)
038                    throws Exception {
039    
040                    setGlobalSearchPath(globalSearchPath);
041    
042                    LinkedList<String> arguments = new LinkedList<String>();
043    
044                    arguments.addAll(_instance.getCommand());
045    
046                    for (Object key : resourceLimitsProperties.keySet()) {
047                            String value = (String)resourceLimitsProperties.get(key);
048    
049                            if (Validator.isNull(value)) {
050                                    continue;
051                            }
052    
053                            arguments.add("-limit");
054                            arguments.add((String)key);
055                            arguments.add(value);
056                    }
057    
058                    arguments.addAll(commandArguments);
059    
060                    if (_log.isInfoEnabled()) {
061                            StringBundler sb = new StringBundler(arguments.size() * 2);
062    
063                            for (String argument : arguments) {
064                                    sb.append(argument);
065                                    sb.append(StringPool.SPACE);
066                            }
067    
068                            _log.info("Excecuting command '" + sb.toString() + "'");
069                    }
070    
071                    _instance.run(arguments);
072            }
073    
074            private static Log _log = LogFactoryUtil.getLog(LiferayConvertCmd.class);
075    
076            private static LiferayConvertCmd _instance = new LiferayConvertCmd();
077    
078    }