// Path: com/sun/stylesheet/StylesheetException.java
// public class StylesheetException extends RuntimeException {
//     /** Creates a new <code>StylesheetException</code>. */
//     public StylesheetException() {
//     }
//     
//     
//     /** 
//      * Creates a new <code>StylesheetException</code> with the specified detail 
//      * message. 
//      *
//      *@param msg the exception's detail message
//      */
//     public StylesheetException(String msg) {
//         super(msg);
//     }
// 
//  
//     /**
//      * Creates a new <code>StylesheetException</code> with the specified cause.
//      *
//      *@param initCause the exception's initCause
//      */
//     public StylesheetException(Throwable initCause) {
//         super(initCause);
//     }
// 
// 
//     /**
//      * Creates a new <code>StylesheetException</code> with the specified detail 
//      * message and cause.
//      *
//      *@param msg the exception's detail message
//      *@param initCause the exception's initCause
//      */
//     public StylesheetException(String msg, Throwable initCause) {
//         super(msg, initCause);
//     }
// }


import java.util.Arrays;
import com.sun.stylesheet.StylesheetException;

/*
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

/* Modified by Volker Härtel, 8 Dec 2011 */ package com.sun.stylesheet.types;


 
/**
 * Abstract base class for converting strings into colors.  Because this CSS
 * engine must support two completely different color classes (AWT colors and
 * JavaFX colors), this base class handles the basic conversion of color strings
 * into red, green, blue, and alpha components without dictating any particular
 * final output class.
 * <p>
 * Supported strings are those defined by CSS3 (e.g. "#00ff00" or "rgb(0%, 100%, 
 * 0%)" with two minor additions.  The string "null" converts to a null 
 * reference, and an eight-digit hex format (e.g. "#00ff007f") is supported with
 * the final two digits controlling alpha.
 * <p>
 * Concrete subclasses are responsible for taking the computed color channel
 * values and storing them in the final output object, such as 
 * <code>java.awt.Color</code.
 *
 *@author Ethan Nicholas
 */
public abstract class AbstractColorConverter implements TypeConverter {
    public Object convertFromString(String string) {
        if (string.equals("null"))
            return null;
        else if (string.length() == 7 && string.charAt(0) == '#') {
            int r = Integer.parseInt(string.substring(1, 3), 16);
            int g = Integer.parseInt(string.substring(3, 5), 16);
            int b = Integer.parseInt(string.substring(5), 16);
            return createColor(r, g, b);
        }
        else if (string.length() == 9 && string.charAt(0) == '#') {
            int r = Integer.parseInt(string.substring(1, 3), 16);
            int g = Integer.parseInt(string.substring(3, 5), 16);
            int b = Integer.parseInt(string.substring(5, 7), 16);
            int a = Integer.parseInt(string.substring(7), 16);
            return createColor(r, g, b, a);
        }
        else if (string.equals("transparent"))
            return convertFromString("#00000000");
        else if (string.startsWith("rgb(") && string.endsWith(")")) {
            String[] args = TypeManager.parseArgs(
                string.substring("rgb(".length(), string.length() - 1));
            if (args.length != 3)

// Path: com/sun/stylesheet/StylesheetException.java
// public class StylesheetException extends RuntimeException {
//     /** Creates a new <code>StylesheetException</code>. */
//     public StylesheetException() {
//     }
//     
//     
//     /** 
//      * Creates a new <code>StylesheetException</code> with the specified detail 
//      * message. 
//      *
//      *@param msg the exception's detail message
//      */
//     public StylesheetException(String msg) {
//         super(msg);
//     }
// 
//  
//     /**
//      * Creates a new <code>StylesheetException</code> with the specified cause.
//      *
//      *@param initCause the exception's initCause
//      */
//     public StylesheetException(Throwable initCause) {
//         super(initCause);
//     }
// 
// 
//     /**
//      * Creates a new <code>StylesheetException</code> with the specified detail 
//      * message and cause.
//      *
//      *@param msg the exception's detail message
//      *@param initCause the exception's initCause
//      */
//     public StylesheetException(String msg, Throwable initCause) {
//         super(msg, initCause);
//     }
// }


// Path: com/sun/stylesheet/types/AbstractColorConverter.java
import java.util.Arrays;
import com.sun.stylesheet.StylesheetException;

/*
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

/* Modified by Volker Härtel, 8 Dec 2011 */ package com.sun.stylesheet.types;


 
/**
 * Abstract base class for converting strings into colors.  Because this CSS
 * engine must support two completely different color classes (AWT colors and
 * JavaFX colors), this base class handles the basic conversion of color strings
 * into red, green, blue, and alpha components without dictating any particular
 * final output class.
 * <p>
 * Supported strings are those defined by CSS3 (e.g. "#00ff00" or "rgb(0%, 100%, 
 * 0%)" with two minor additions.  The string "null" converts to a null 
 * reference, and an eight-digit hex format (e.g. "#00ff007f") is supported with
 * the final two digits controlling alpha.
 * <p>
 * Concrete subclasses are responsible for taking the computed color channel
 * values and storing them in the final output object, such as 
 * <code>java.awt.Color</code.
 *
 *@author Ethan Nicholas
 */
public abstract class AbstractColorConverter implements TypeConverter {
    public Object convertFromString(String string) {
        if (string.equals("null"))
            return null;
        else if (string.length() == 7 && string.charAt(0) == '#') {
            int r = Integer.parseInt(string.substring(1, 3), 16);
            int g = Integer.parseInt(string.substring(3, 5), 16);
            int b = Integer.parseInt(string.substring(5), 16);
            return createColor(r, g, b);
        }
        else if (string.length() == 9 && string.charAt(0) == '#') {
            int r = Integer.parseInt(string.substring(1, 3), 16);
            int g = Integer.parseInt(string.substring(3, 5), 16);
            int b = Integer.parseInt(string.substring(5, 7), 16);
            int a = Integer.parseInt(string.substring(7), 16);
            return createColor(r, g, b, a);
        }
        else if (string.equals("transparent"))
            return convertFromString("#00000000");
        else if (string.startsWith("rgb(") && string.endsWith(")")) {
            String[] args = TypeManager.parseArgs(
                string.substring("rgb(".length(), string.length() - 1));
            if (args.length != 3)

                throw new StylesheetException("rgb() takes 3 arguments, " +
