1 /*
   2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.css.parser;
  27 
  28 import javafx.css.Stylesheet;
  29 
  30 import java.io.File;
  31 import java.io.IOException;
  32 
  33 /** Css2Bin <input file> [<output file name>]
  34  * java com.sun.javafx.css.parser.Css2Bin input.css output.bss
  35  *  If no output file is given, then the input file name is used with an extension of 'bss'x
  36  */
  37 public final class Css2Bin {
  38     public static void main(String args[]) throws Exception {
  39 
  40         if ( args.length < 1 ) throw new IllegalArgumentException("expected file name as argument");
  41 
  42         try {
  43             String ifname = args[0];
  44             String ofname = (args.length > 1) ?
  45                 args[1] : ifname.substring(0, ifname.lastIndexOf('.')+1).concat("bss");
  46 
  47             convertToBinary(ifname, ofname);
  48 
  49         } catch (Exception e) {
  50             System.err.println(e.toString());
  51             e.printStackTrace(System.err);
  52             System.exit(-1);
  53         }
  54     }
  55 
  56     public static void convertToBinary(String ifname, String ofname) throws IOException {
  57 
  58         if (ifname == null || ofname == null) {
  59             throw new IllegalArgumentException("parameters cannot be null");
  60         }
  61 
  62         if (ifname.equals(ofname)) {
  63             throw new IllegalArgumentException("input file and output file cannot be the same");
  64         }
  65 
  66         final File source = new File(ifname);
  67         final File destination = new File(ofname);
  68         Stylesheet.convertToBinary(source, destination);
  69 
  70     }
  71 
  72 }