001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.tools;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portal.util.FileImpl;
020    
021    import java.io.File;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class CSSFormatter {
027    
028            public static void main(String[] args) {
029                    if (args.length == 1) {
030                            new CSSFormatter(new File(args[0]));
031                    }
032                    else {
033                            throw new IllegalArgumentException();
034                    }
035            }
036    
037            public CSSFormatter(File file) {
038                    try {
039                            String content = _fileUtil.read(file);
040    
041                            content = StringUtil.replace(
042                                    content,
043                                    new String[] {
044                                            "*/\n", "*/ /*", "*/" + StringPool.FOUR_SPACES + "/*"
045                                    },
046                                    new String[] {
047                                            "*/\n\n", "*/\n\n/*", "*/\n\n/*"
048                                    });
049    
050                            _fileUtil.write(file, content, true);
051                    }
052                    catch (Exception e) {
053                            e.printStackTrace();
054                    }
055            }
056    
057            private static FileImpl _fileUtil = FileImpl.getInstance();
058    
059    }