[pal-cvs 3415] [1149] check string length.

svnno****@sourc***** svnno****@sourc*****
2008年 9月 10日 (水) 21:20:14 JST


Revision: 1149
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=pal&view=rev&rev=1149
Author:   shinsuke
Date:     2008-09-10 21:20:13 +0900 (Wed, 10 Sep 2008)

Log Message:
-----------
check string length.

Modified Paths:
--------------
    pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/WcmConstants.java
    pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/action/EditorAction.java
    pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/form/EditorForm.java
    pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/portlet/WcmEditorPortlet.java
    pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/portlet.xml

Added Paths:
-----------
    pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/view/editor/error.jsp

Removed Paths:
-------------
    pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/view/error/editor.jsp


-------------- next part --------------
Modified: pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/WcmConstants.java
===================================================================
--- pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/WcmConstants.java	2008-09-10 05:00:59 UTC (rev 1148)
+++ pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/WcmConstants.java	2008-09-10 12:20:13 UTC (rev 1149)
@@ -1,7 +1,5 @@
 package jp.sf.pal.wcm;
 
-import sun.management.counter.perf.PerfInstrumentation;
-
 /**
  * @author shinsuke
  *
@@ -86,4 +84,6 @@
     public static final String NAMESPACE_LIST = PREFIX + "NamespaceList";
 
     public static final String NAMESPACE_LIST_SIZE = "namespaceListSize";
+
+    public static final String MAX_CONTENT_LENGTH = "maxContentLength";
 }

Modified: pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/action/EditorAction.java
===================================================================
--- pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/action/EditorAction.java	2008-09-10 05:00:59 UTC (rev 1148)
+++ pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/action/EditorAction.java	2008-09-10 12:20:13 UTC (rev 1149)
@@ -19,8 +19,6 @@
 import java.util.List;
 
 import javax.portlet.PortletRequest;
-import javax.portlet.PortletResponse;
-import javax.portlet.RenderResponse;
 import javax.servlet.http.HttpServletRequest;
 
 import jp.sf.pal.wcm.WcmConstants;
@@ -71,7 +69,19 @@
         return null;
     }
 
-    @Execute(validator = false, input = "/error/editor.jsp")
+    private void checkContentLength() throws ActionMessagesException {
+        Integer maxContentLength = (Integer) request
+                .getAttribute(WcmConstants.MAX_CONTENT_LENGTH);
+        if (maxContentLength != null) {
+            if (editorForm.content != null &&
+                    editorForm.content.length() > maxContentLength.intValue()) {
+                throw new ActionMessagesException("errors.maxlength",
+                        new Object[] { "content", maxContentLength });//TODO i18n content
+            }
+        }
+    }
+
+    @Execute(validator = false, input = "error.jsp")
     public String index() {
         String path = getReceivedPath();
         if (path != null) {
@@ -104,7 +114,7 @@
         }
     }
 
-    @Execute(validator = false, input = "/error/editor.jsp", urlPattern = "list/{encodedPath}")
+    @Execute(validator = false, input = "error.jsp", urlPattern = "list/{encodedPath}")
     public String list() {
         if (editorForm.encodedPath != null) {
             editorForm.currentPath = PALWcmUtil
@@ -134,7 +144,7 @@
         }
     }
 
-    @Execute(validator = false, input = "/error/editor.jsp")
+    @Execute(validator = false, input = "error.jsp")
     public String parent() {
         if (editorForm.currentPath != null) {
             editorForm.currentPath = editorForm.currentPath.replaceFirst("/+$",
@@ -242,9 +252,10 @@
         return "edit.jsp";
     }
 
-    @Execute(validator = true, input = "/error/editor.jsp")
+    @Execute(validator = true, input = "edit.jsp")
     public String store() {
         try {
+            checkContentLength();
             contentService.storeContent(editorForm.getPagePath(), editorForm
                     .getFragmentId(), editorForm.title, editorForm.content,
                     editorForm.locale);
@@ -256,6 +267,8 @@
             // TODO log
             log.error(e.getMessage(), e);
             throw new ActionMessagesException(e.getMessageId(), e.getArgs());
+        } finally {
+            prerenderForEdit();
         }
         return edit();
     }

Modified: pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/form/EditorForm.java
===================================================================
--- pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/form/EditorForm.java	2008-09-10 05:00:59 UTC (rev 1148)
+++ pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/form/EditorForm.java	2008-09-10 12:20:13 UTC (rev 1149)
@@ -17,6 +17,7 @@
 
 import jp.sf.pal.wcm.WcmConstants;
 
+import org.seasar.struts.annotation.Maxlength;
 import org.seasar.struts.annotation.Required;
 
 /**
@@ -30,6 +31,7 @@
 
     public String encodedPagePath;
 
+    @Maxlength(maxlength = 100)
     public String title;
 
     public String content;

Modified: pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/portlet/WcmEditorPortlet.java
===================================================================
--- pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/portlet/WcmEditorPortlet.java	2008-09-10 05:00:59 UTC (rev 1148)
+++ pal-wcm/tags/pal-wcm-1.0/src/main/java/jp/sf/pal/wcm/portlet/WcmEditorPortlet.java	2008-09-10 12:20:13 UTC (rev 1149)
@@ -40,6 +40,8 @@
 
     private PortletRegistry portletRegistry;
 
+    private Integer maxContentLength = null;
+
     public void init() throws PortletException {
         super.init();
 
@@ -58,6 +60,12 @@
             throw new PortletException(
                     "Failed to find the portletRegistry on portlet initialization");
         }
+
+        String value = getPortletConfig().getInitParameter(
+                WcmConstants.MAX_CONTENT_LENGTH);
+        if (value != null) {
+            maxContentLength = Integer.parseInt(value);
+        }
     }
 
     public void destroy() {
@@ -70,6 +78,7 @@
             throws PortletException, IOException {
         request.setAttribute(WcmConstants.PAGE_MANAGER, pageManager);
         request.setAttribute(WcmConstants.PORTLET_REGISTRY, portletRegistry);
+        request.setAttribute(WcmConstants.MAX_CONTENT_LENGTH, maxContentLength);
         super.processAction(request, response);
     }
 
@@ -77,6 +86,7 @@
             throws PortletException, IOException {
         request.setAttribute(WcmConstants.PAGE_MANAGER, pageManager);
         request.setAttribute(WcmConstants.PORTLET_REGISTRY, portletRegistry);
+        request.setAttribute(WcmConstants.MAX_CONTENT_LENGTH, maxContentLength);
         super.render(request, response);
 
         // set user to session

Modified: pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/portlet.xml
===================================================================
--- pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/portlet.xml	2008-09-10 05:00:59 UTC (rev 1148)
+++ pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/portlet.xml	2008-09-10 12:20:13 UTC (rev 1149)
@@ -52,6 +52,10 @@
       <name>viewPage</name>
       <value>/editor/</value>
     </init-param>
+    <init-param>
+      <name>maxContentLength</name>
+      <value>5000</value>
+    </init-param>
     <expiration-cache>0</expiration-cache>
     <supports>
       <mime-type>text/html</mime-type>

Copied: pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/view/editor/error.jsp (from rev 1148, pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/view/error/editor.jsp)
===================================================================
--- pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/view/editor/error.jsp	                        (rev 0)
+++ pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/view/editor/error.jsp	2008-09-10 12:20:13 UTC (rev 1149)
@@ -0,0 +1,11 @@
+<%@page pageEncoding="UTF-8" %>
+<html>
+<head>
+<title></title>
+</head>
+<body>
+<html:errors/>
+<br>
+<s:link href="list/${f:u(encodedPath)}">Back</s:link>
+</body>
+</html>

Deleted: pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/view/error/editor.jsp
===================================================================
--- pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/view/error/editor.jsp	2008-09-10 05:00:59 UTC (rev 1148)
+++ pal-wcm/tags/pal-wcm-1.0/src/main/webapp/WEB-INF/view/error/editor.jsp	2008-09-10 12:20:13 UTC (rev 1149)
@@ -1,11 +0,0 @@
-<%@page pageEncoding="UTF-8" %>
-<html>
-<head>
-<title></title>
-</head>
-<body>
-<html:errors/>
-<br>
-<s:link href="/editor/">Back</s:link>
-</body>
-</html>


pal-cvs メーリングリストの案内