1 16 package com.google.gwt.i18n.rebind.util; 17 18 import com.google.gwt.i18n.client.Messages; 19 20 import java.io.File ; 21 import java.io.IOException ; 22 import java.text.MessageFormat ; 23 import java.text.ParseException ; 24 25 28 public class MessagesInterfaceCreator extends 29 AbstractLocalizableInterfaceCreator { 30 31 39 public static int numberOfMessageArgs(String template) throws ParseException { 40 String escapedDefault = template.replaceAll("'", "x"); 44 int numArgs = new MessageFormat (escapedDefault).parse(escapedDefault).length; 45 return numArgs; 46 } 47 48 57 public MessagesInterfaceCreator(String className, String packageName, 58 File resourceBundle, File targetLocation) throws IOException { 59 super(className, packageName, resourceBundle, targetLocation, 60 Messages.class); 61 } 62 63 protected void genMethodArgs(String defaultValue) { 64 try { 65 int numArgs = numberOfMessageArgs(defaultValue); 66 for (int i = 0; i < numArgs; i++) { 67 if (i > 0) { 68 composer.print(", "); 69 } 70 composer.print("String arg" + i); 71 } 72 } catch (ParseException e) { 73 throw new RuntimeException (defaultValue 74 + " could not be parsed as a MessageFormat string.", e); 75 } 76 } 77 78 protected String javaDocComment(String path) { 79 return "Interface to represent the messages contained in resource bundle:\n\t" 80 + path + "'."; 81 } 82 } 83 | Popular Tags |