Commits

Takumi IINO committed 3c6b344

action.util: ActionForwad関連のユーティリティ ActionForwardUtil 追加

Comments (0)

Files changed (1)

sastruts-oreo/src/main/java/jp/troter/seasar/struts/action/util/ActionForwardUtil.java

+package jp.troter.seasar.struts.action.util;
+
+import org.apache.struts.action.ActionForward;
+import org.seasar.framework.util.StringUtil;
+
+public class ActionForwardUtil {
+
+    protected ActionForwardUtil() {
+    }
+
+    /**
+     * @param actionForward
+     * @return リダイレクトか
+     */
+    public static boolean isRedirect(ActionForward actionForward) {
+        return actionForward != null && actionForward.getRedirect() == true;
+    }
+
+    /**
+     * @param actionForward
+     * @return フォワードか
+     */
+    public static boolean isForward(ActionForward actionForward) {
+        return actionForward == null || actionForward.getRedirect() == false;
+    }
+
+    /**
+     * @param actionForward
+     * @return JSPへのフォワードか
+     */
+    public static boolean isForwardToJsp(ActionForward actionForward) {
+        return isForwardToSuffix(actionForward, "jsp");
+    }
+
+    /**
+     * @param actionForward
+     * @return HTMLへのフォワードか
+     */
+    public static boolean isForwardToHtml(ActionForward actionForward) {
+        return isForwardToSuffix(actionForward, "html");
+    }
+
+    /**
+     * @param actionForward
+     * @param suffix
+     * @return suffixへのフォワードか
+     */
+    public static boolean isForwardToSuffix(ActionForward actionForward, String suffix) {
+        return isForward(actionForward) && isSuffixPath(getPath(actionForward), suffix);
+    }
+
+    public static boolean isSuffixPath(String path, String suffix) {
+        return StringUtil.endsWithIgnoreCase(path, "." + suffix);
+    }
+
+    protected static String getPath(ActionForward actionForward) {
+        if (actionForward != null) {
+            return actionForward.getPath();
+        }
+        return null;
+    }
+}