Commits

Takumi IINO committed c43c545

T4ActionCustomizer: フォーム名変換部分作成。必要に迫られていない機能をいったん削除

Comments (0)

Files changed (1)

sastruts-oreo/src/main/java/jp/troter/seasar/struts/customizer/T4ActionCustomizer.java

 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.util.HashMap;
-import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.Map;
 
 
     protected boolean formPackageLabel = true;
 
-    protected Map<String, String> abbreviationTable = new LinkedHashMap<String, String>();
-
     public T4ActionCustomizer() {
         super();
     }
         this.formPackageLabel = formPakcageLabel;
     }
 
-    /**
-     * @return パッケージ名の略称テーブルを取得します
-     */
-    public Map<String, String> getAbbreviationTable() {
-        return abbreviationTable;
-    }
-
-    public void putAbbreviationTable(String rootPackageName, String abbreviation) {
-        this.abbreviationTable.put(rootPackageName, abbreviation);
-    }
-
     @Override
     protected void setupValidator(S2ActionMapping actionMapping,
             S2ValidatorResources validatorResources) {
 
         // ラベルの差し替え処理
         props.put("arg0", createArg(l.getLabel()));
-        String longPropertyName = getActionFormName(actionMapping)+"."+propertyName;
-        logger.debug(String.format("アクションフォームのプロパティ(%s:%s[%s=%s])のラベルを設定します", longPropertyName, validatorName, l.getName(), l.getLabel()));
+        String actionFormName = getActionFormName(actionMapping);
+        logger.debug(String.format("アクションフォーム[%s]のプロパティ(%s:%s[%s=%s])のラベルを設定します", actionFormName, propertyName, validatorName, l.getName(), l.getLabel()));
     }
 
     /**
         LinkedList<String> labels = new LinkedList<String>();
         labels.add("labels."+propertyName);
 
-        String actionFormName = getActionFormName(actionMapping);
+        String actionFormName = convertActionFormName(getActionFormName(actionMapping));
         if (StringUtil.isNotEmpty(actionFormName)) {
             labels.addFirst("labels."+actionFormName+"."+propertyName);
         }
 
         for (String labelName : labels) {
-            String message = MessageResourcesUtil.getMessage(labelName);
+            String message = messageResourcesMessage(labelName);
             if (StringUtil.isNotEmpty(message)) {
-                return new LabelEntry(labelName, MessageResourcesUtil.getMessage(labelName));
+                return new LabelEntry(labelName, messageResourcesMessage(labelName));
             }
         }
 
         return null;
     }
 
+    public String messageResourcesMessage(String labelName) {
+        return MessageResourcesUtil.getMessage(labelName);
+    }
+
+    /**
+     * Form名取得
+     */
+    protected String getActionFormName(S2ActionMapping actionMapping) {
+        if (actionMapping.getActionFormBeanDesc().getBeanClass() == null) {
+            return "";
+        }
+        return actionMapping.getActionFormBeanDesc().getBeanClass().getName();
+    }
+
+    protected String convertActionFormName(String actionFormName) {
+        String converted = actionFormName.replaceAll(".*?\\.form\\.", "");
+        if (! actionFormName.equals(converted)) {
+            return converted;
+        }
+        return actionFormName;
+    }
+
     public static class LabelEntry {
         private String name;
         private String label;
     }
 
     /**
-     * Form名取得
-     */
-    protected String getActionFormName(S2ActionMapping actionMapping) {
-        if (actionMapping.getActionFormBeanDesc().getBeanClass() == null) {
-            return "";
-        }
-
-        String actionFormName = actionMapping.getActionFormBeanDesc().getBeanClass().getName();
-//        for (Map.Entry<String, String> e : getAbbreviationTable().entrySet()) {
-//            String pattern = "^"+Pattern.quote(e.getKey());
-//            Pattern.matches(regex, input)
-//            if (actionFormName.contains(e.getKey())) {
-//                
-//                actionFormName.replaceFirst(, replacement)
-//                return StringUtil.replace(actionFormName, e.getKey(), e.getValue());
-//            }
-//        }
-        return actionFormName;
-    }
-
-    /**
      * 指定したkey名を持つArgアノテーションのインスタンスを作成
      * key以外の値は固定(position=0,resource=fase,bundle=null)
      *