001    /**
002     * Copyright (c) 2000-2011 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.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    }