/**
 * Copyright 2011 Emmanuel Bourg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.pushingpixels.flamingo.api.svg;

import java.io.File;
import java.util.Arrays;

/**
 * Keeps the name of the image file and replaces illegal characters in Java class names.
 *
 * For example edit-copy.svg is turned into edit_copy
 *
 * @author Emmanuel Bourg
 * @version $Revision$, $Date$
 */
public class DefaultNamingStrategy implements NamingStrategy {

    public String getClassName(File file) {
        String name = file.getName().substring(0, file.getName().lastIndexOf("."));
        name = name.replaceAll("[-+ .]", "_");
        if (isKeyword(name)) {
            name = name + "_";
        }
        if (Character.isDigit(name.charAt(0))) {
            name = "_" + name;
        }
        return name;
    }

    private boolean isKeyword(String s) {
        return Arrays.asList("abstract",
                "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const","continue", "default",
                "do", "double", "else", "enum", "extends", "final","finally", "float","for", "goto", "if", "implements",
                "import", "instanceof", "int", "interface", "long", "native", "new", "package", "private", "protected",
                "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw",
                "throws", "transient", "try", "void", "volatile", "while").contains(s);
    }
}

@@ -683,16 +683,64 @@
 .Arrays;
+%0Aimport java.util.HashSet;%0Aimport java.util.Set;
 %0A%0A/**%0A *
@@ -1020,466 +1020,111 @@
    p
-ublic String getClassName(File file) %7B%0A        String name = file.getName().substring(0, file.getName().lastIndexOf(%22.%22));%0A        name = name.replaceAll(%22%5B-+ .%5D%22, %22_%22);%0A        if (isKeyword(name)) %7B%0A            name = name + %22_%22;%0A        %7D%0A        if (Character.isDigit(name.charAt(0))) %7B%0A            name = %22_%22 + name;%0A        %7D%0A        return name;%0A    %7D%0A%0A    private boolean isKeyword(String s) %7B%0A        return Arrays.asList(%22abstract%22,%0A               
+rivate static final Set%3CString%3E KEYWORDS = new HashSet%3C%3E(Arrays.asList(%0A                    %22abstract%22,
  %22as
@@ -1215,20 +1215,14 @@
 ue%22,
- %22default%22,%0A
+%0A     
     
@@ -1232,16 +1232,26 @@
         
+%22default%22,
  %22do%22, %22
@@ -1331,29 +1331,19 @@
 to%22,
- 
 %22if%22,
- %22implements%22,%0A
+%0A     
     
@@ -1353,16 +1353,29 @@
         
+%22implements%22,
  %22import
@@ -1461,21 +1461,8 @@
 te%22,
- %22protected%22,
 %0A   
@@ -1473,16 +1473,33 @@
         
+     %22protected%22,
  %22public
@@ -1576,16 +1576,36 @@
 onized%22,
+%0A                   
  %22this%22,
@@ -1613,32 +1613,16 @@
 %22throw%22,
-%0A               
  %22throws
@@ -1672,16 +1672,454 @@
 %22while%22)
+);%0A    %0A    public String getClassName(File file) %7B%0A        String name = file.getName().substring(0, file.getName().lastIndexOf(%22.%22));%0A        name = name.replaceAll(%22%5B-+ .%5D%22, %22_%22);%0A        if (isKeyword(name)) %7B%0A            name = name + %22_%22;%0A        %7D%0A        if (Character.isDigit(name.charAt(0))) %7B%0A            name = %22_%22 + name;%0A        %7D%0A        return name;%0A    %7D%0A%0A    private boolean isKeyword(String s) %7B%0A        return KEYWORDS
 .contain

Use a static set for the keywords in DefaultNamingStrategy