Compare commits

...

45 Commits

Author SHA1 Message Date
René Gielen 4b5f5619dd [maven-release-plugin] copy for tag STRUTS_2_3_4_1
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1@1368961 13f79535-47bb-0310-9956-ffa450edef68
2012-08-03 13:54:15 +00:00
René Gielen cd056f7d1b [maven-release-plugin] prepare release STRUTS_2_3_4_1
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/branches/STRUTS_2_3_4_X@1368960 13f79535-47bb-0310-9956-ffa450edef68
2012-08-03 13:54:02 +00:00
René Gielen 4b5f85f151 Reverted plugin management change
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/branches/STRUTS_2_3_4_X@1368951 13f79535-47bb-0310-9956-ffa450edef68
2012-08-03 13:42:36 +00:00
René Gielen 87935af56a Merged from trunk
WW-3860
Restrict accepted parameter name length
Thanks to Johno Crawford for the patch. [from revision 1368841]

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/branches/STRUTS_2_3_4_X@1368949 13f79535-47bb-0310-9956-ffa450edef68
2012-08-03 13:41:28 +00:00
René Gielen 1081c52be9 Merged from trunk
WW-3858
Decouple token names from their respective session attribute names [from revision 1368827]

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/branches/STRUTS_2_3_4_X@1368946 13f79535-47bb-0310-9956-ffa450edef68
2012-08-03 13:40:01 +00:00
René Gielen 5e99ed431e Added gpg-plugin version fix
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/branches/STRUTS_2_3_4_X@1368921 13f79535-47bb-0310-9956-ffa450edef68
2012-08-03 12:41:33 +00:00
René Gielen f2a8c9ffc1 Branch versions fixes
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/branches/STRUTS_2_3_4_X@1368909 13f79535-47bb-0310-9956-ffa450edef68
2012-08-03 12:10:50 +00:00
René Gielen a19144c5fc Branch
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/branches/STRUTS_2_3_4_X@1368902 13f79535-47bb-0310-9956-ffa450edef68
2012-08-03 11:53:35 +00:00
René Gielen 3a5c6fcfef Branch preparation
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/branches/STRUTS_2_3_4_X@1368894 13f79535-47bb-0310-9956-ffa450edef68
2012-08-03 11:21:43 +00:00
René Gielen 676a011b4f Fixed ignores
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4@1368890 13f79535-47bb-0310-9956-ffa450edef68
2012-08-03 11:15:11 +00:00
Lukasz Lenart 954c21481f [maven-release-plugin] copy for tag STRUTS_2_3_4
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4@1337582 13f79535-47bb-0310-9956-ffa450edef68
2012-05-12 16:06:38 +00:00
Lukasz Lenart 4e61119eab [maven-release-plugin] prepare release STRUTS_2_3_4
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1337581 13f79535-47bb-0310-9956-ffa450edef68
2012-05-12 16:06:29 +00:00
Lukasz Lenart 7eb6cdbeaa WW-3813 Prepares for release
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1337576 13f79535-47bb-0310-9956-ffa450edef68
2012-05-12 15:45:50 +00:00
Lukasz Lenart f75cc72633 WW-3812 wraps Arrays.asList with new ArrayList() to allow add() operation
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1337447 13f79535-47bb-0310-9956-ffa450edef68
2012-05-12 05:44:27 +00:00
Lukasz Lenart 517de353c1 WW-3763 adds setter to inject missing UrlHelper
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1336486 13f79535-47bb-0310-9956-ffa450edef68
2012-05-10 05:54:36 +00:00
Lukasz Lenart 02a84be2c7 WW-3810 reverts support for JBoss 5.1
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1335463 13f79535-47bb-0310-9956-ffa450edef68
2012-05-08 12:28:02 +00:00
Lukasz Lenart 5af2eda14c Reverts site target
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1333786 13f79535-47bb-0310-9956-ffa450edef68
2012-05-04 07:15:29 +00:00
Lukasz Lenart 997c577d4f WW-3805 solves problem with reloading configuration on each request even no changes to file
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1331402 13f79535-47bb-0310-9956-ffa450edef68
2012-04-27 12:56:02 +00:00
Lukasz Lenart b382c5c021 WW-3803 improves support for JAR inside EAR package when used with JBoss 7
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1331373 13f79535-47bb-0310-9956-ffa450edef68
2012-04-27 12:12:03 +00:00
Lukasz Lenart 0e5d4f3e9f Updated tag version and name
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1331339 13f79535-47bb-0310-9956-ffa450edef68
2012-04-27 10:22:26 +00:00
Lukasz Lenart 37ebc858a3 Improves logging messages
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1330502 13f79535-47bb-0310-9956-ffa450edef68
2012-04-25 19:25:03 +00:00
Lukasz Lenart 495753e1aa WW-3801 adds logic to clean ups uploaded files
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1328528 13f79535-47bb-0310-9956-ffa450edef68
2012-04-20 22:23:26 +00:00
Lukasz Lenart 0b2069dba0 WW-3803 solves problem with package name contains the package locator
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1328527 13f79535-47bb-0310-9956-ffa450edef68
2012-04-20 22:21:40 +00:00
Lukasz Lenart 0d8f4d43bd WW-3804 adds support of dynamic attributes to <s:radio/> tag and extends support for dynamic attributes with expression evaluation
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1328526 13f79535-47bb-0310-9956-ffa450edef68
2012-04-20 22:19:41 +00:00
Lukasz Lenart 5a9048065f WW-3282 Changes logic to add namespace only once when building urls and cleans up code
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1327601 13f79535-47bb-0310-9956-ffa450edef68
2012-04-18 18:13:57 +00:00
Lukasz Lenart 73e763faf8 WW-3799 converts FileManager into a bean, adds default implementation and defines new extension point
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1326928 13f79535-47bb-0310-9956-ffa450edef68
2012-04-17 05:03:45 +00:00
Lukasz Lenart 73c976a028 [maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1326479 13f79535-47bb-0310-9956-ffa450edef68
2012-04-16 04:34:52 +00:00
Lukasz Lenart 6411771bb0 [maven-release-plugin] prepare release STRUTS_2_3_3
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1326477 13f79535-47bb-0310-9956-ffa450edef68
2012-04-16 04:34:13 +00:00
Lukasz Lenart f45597252f WW-3798 changes params for wget to download just WW spaces
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1326396 13f79535-47bb-0310-9956-ffa450edef68
2012-04-15 18:49:00 +00:00
Lukasz Lenart 6a4240bdf0 WW-3791 prepares test build
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1326342 13f79535-47bb-0310-9956-ffa450edef68
2012-04-15 14:02:27 +00:00
Lukasz Lenart e9a12de7ee Reverst site link to dev one
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1326062 13f79535-47bb-0310-9956-ffa450edef68
2012-04-14 07:07:49 +00:00
Lukasz Lenart abd628ea09 WW-3442 adds additional initialisation of HttpSession
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1324893 13f79535-47bb-0310-9956-ffa450edef68
2012-04-11 17:49:35 +00:00
Lukasz Lenart 78ee4b8ba2 WW-3796 Changes logic to set encoding on HttpServletRequest if differs from configured
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1324888 13f79535-47bb-0310-9956-ffa450edef68
2012-04-11 17:41:06 +00:00
Lukasz Lenart 4f07559dc1 WW-3431 Solves problem with array initialization
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1324871 13f79535-47bb-0310-9956-ffa450edef68
2012-04-11 17:13:42 +00:00
Lukasz Lenart f064937984 WW-3059 Changes logic to set encoding for XMLHttpRequest type
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1324870 13f79535-47bb-0310-9956-ffa450edef68
2012-04-11 17:12:35 +00:00
Maurizio Cucchiara a99dadfebf Update commons lang3 reference
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1324674 13f79535-47bb-0310-9956-ffa450edef68
2012-04-11 09:42:13 +00:00
Lukasz Lenart 5c15306366 WW-3442 adds Session initialisation method to solve problem with missing session and allow to initialise session on its own in test cases
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1311951 13f79535-47bb-0310-9956-ffa450edef68
2012-04-10 19:33:51 +00:00
Lukasz Lenart ecc0e56440 WW-3432 pushes messages variables to allow customize validation messages
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1311945 13f79535-47bb-0310-9956-ffa450edef68
2012-04-10 19:29:09 +00:00
Lukasz Lenart b90fe0996f WW-3418 solves problem with excludePackages
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1311931 13f79535-47bb-0310-9956-ffa450edef68
2012-04-10 19:04:57 +00:00
Lukasz Lenart 2dacf99394 Removes strange file
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1311908 13f79535-47bb-0310-9956-ffa450edef68
2012-04-10 18:28:32 +00:00
Lukasz Lenart c8850cb558 WW-3413 removes unneeded dependencies
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1311903 13f79535-47bb-0310-9956-ffa450edef68
2012-04-10 18:22:01 +00:00
Lukasz Lenart a377ce5c40 WW-3173 adds additional test case to proof that there is no error
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1311902 13f79535-47bb-0310-9956-ffa450edef68
2012-04-10 18:20:25 +00:00
Lukasz Lenart 7146f389c7 WW-3795 allows specify location as a relative for result type plainText and add possibility to extend class by overriding protected methods
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1311895 13f79535-47bb-0310-9956-ffa450edef68
2012-04-10 18:07:16 +00:00
Lukasz Lenart 73da07e6af WW-3793 corrects name of PlainText Result in documentation to be plainText and not plaintext
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1311872 13f79535-47bb-0310-9956-ffa450edef68
2012-04-10 17:15:38 +00:00
Lukasz Lenart cbb55e9793 [maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1310831 13f79535-47bb-0310-9956-ffa450edef68
2012-04-07 19:28:23 +00:00
167 changed files with 2347 additions and 1731 deletions
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-blank</artifactId>
@@ -34,9 +34,9 @@
<name>Blank Webapp</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps/blank</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps/blank</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/apps/blank</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps/blank</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps/blank</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/apps/blank</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-jboss-blank</artifactId>
@@ -34,9 +34,9 @@
<name>JBoss Blank Webapp</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps/jboss-blank</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps/jboss-blank</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/apps/jboss-blank</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps/jboss-blank</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps/jboss-blank</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/apps/jboss-blank</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-mailreader</artifactId>
@@ -34,9 +34,9 @@
<name>Mail Reader Webapp</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps/mailreader</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps/mailreader</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/apps/mailreader</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps/mailreader</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps/mailreader</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/apps/mailreader</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
@@ -42,9 +42,9 @@
</modules>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/apps</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/apps</url>
</scm>
<profiles>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-portlet</artifactId>
@@ -34,9 +34,9 @@
<name>Portlet Webapp</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps/portlet</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps/portlet</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/apps/portlet</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps/portlet</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps/portlet</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/apps/portlet</url>
</scm>
<profiles>
+2 -2
View File
@@ -26,13 +26,13 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-rest-showcase</artifactId>
<packaging>war</packaging>
<version>2.3.2</version>
<version>2.3.4.1</version>
<name>Struts 2 Rest Showcase Example</name>
<description>Struts 2 Rest Showcase Example</description>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-showcase</artifactId>
@@ -34,9 +34,9 @@
<name>Showcase Webapp</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps/showcase</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/apps/showcase</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/apps/showcase</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps/showcase</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/apps/showcase</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/apps/showcase</url>
</scm>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 Maven Archetypes</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes</url>
</scm>
<modules>
+5 -5
View File
@@ -3,19 +3,19 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>struts2-archetype-blank</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
<packaging>jar</packaging>
<name>Struts 2 Archetypes - Blank</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-blank</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-blank</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-blank</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-blank</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-blank</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-blank</url>
</scm>
<properties>
@@ -46,20 +46,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
@@ -2,19 +2,19 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>struts2-archetype-convention</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
<packaging>jar</packaging>
<name>Struts 2 Archetypes - Blank Convention</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-convention</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-convention</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-convention</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-convention</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-convention</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-convention</url>
</scm>
<properties>
@@ -2,19 +2,19 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>struts2-archetype-dbportlet</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
<packaging>jar</packaging>
<name>Struts 2 Archetypes - Database Portlet</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-dbportlet</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-dbportlet</developerConnection>
<url>svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-dbportlet</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-dbportlet</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-dbportlet</developerConnection>
<url>svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-dbportlet</url>
</scm>
<properties>
+5 -5
View File
@@ -2,19 +2,19 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>struts2-archetype-plugin</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
<packaging>jar</packaging>
<name>Struts 2 Archetypes - Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-plugin</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-plugin</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-plugin</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-plugin</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-plugin</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-plugin</url>
</scm>
<properties>
+5 -5
View File
@@ -2,19 +2,19 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>struts2-archetype-portlet</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
<packaging>jar</packaging>
<name>Struts 2 Archetypes - Portlet</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-portlet</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-portlet</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-portlet</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-portlet</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-portlet</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-portlet</url>
</scm>
<properties>
+5 -5
View File
@@ -4,19 +4,19 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-archetypes</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>struts2-archetype-starter</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
<packaging>jar</packaging>
<name>Struts 2 Archetypes - Starter</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-starter</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-starter</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/archetypes/struts2-archetype-starter</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-starter</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-starter</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/archetypes/struts2-archetype-starter</url>
</scm>
<properties>
+6 -4
View File
@@ -11,13 +11,13 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/assembly</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/assembly</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/assembly</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/assembly</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/assembly</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/assembly</url>
</scm>
<profiles>
@@ -276,6 +276,8 @@
<arg value="-nv" />
<arg value="-E" />
<arg value="-L" />
<arg value="-l 0" />
<arg value="-np" />
<arg value="--directory-prefix=${project.build.directory}/cwiki" />
<arg value="--no-check-certificate" />
<arg value="-r" />
+4 -4
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-bundles</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-admin-bundle</artifactId>
@@ -12,9 +12,9 @@
<name>Struts 2 OSGi Admin Bundle</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/bundles/admin</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/bundles/admin</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/bundles/admin</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/bundles/admin</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/bundles/admin</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/bundles/admin</url>
</scm>
<dependencies>
+4 -4
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-bundles</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-demo-bundle</artifactId>
@@ -12,9 +12,9 @@
<name>Struts 2 OSGi Demo Bundle</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/bundles/demo</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/bundles/demo</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/bundles/demo</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/bundles/demo</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/bundles/demo</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/bundles/demo</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-bundles</artifactId>
@@ -34,9 +34,9 @@
<name>Struts OSGi Bundles</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/bundles</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/bundles</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/bundles</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/bundles</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/bundles</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/bundles</url>
</scm>
<modules>
+6 -6
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
@@ -34,13 +34,13 @@
<name>Struts 2 Core</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/core</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/core</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/core</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/core</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/core</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/core</url>
</scm>
<properties>
<tlib.version>2.2</tlib.version>
<tlib.version>2.3</tlib.version>
</properties>
<build>
@@ -50,7 +50,7 @@
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.15</version>
<configuration>
<A>uri=/struts-tags,tlibVersion=${tlib.version},jspVersion=2.0,shortName=s,displayName="Struts Tags",
<A>uri=/struts-tags,tlibVersion=${tlib.version},jspVersion=2.0,shortName=s,displayName=Struts Tags,
outFile=${basedir}/target/classes/META-INF/struts-tags.tld,
description="To make it easier to access dynamic data;
the Apache Struts framework includes a library of custom tags.
@@ -64,6 +64,9 @@ public final class StrutsConstants {
/** The com.opensymphony.xwork2.ObjectFactory implementation class */
public static final String STRUTS_OBJECTFACTORY = "struts.objectFactory";
/** The com.opensymphony.xwork2.util.FileManager implementation class */
public static final String STRUTS_FILEMANAGER = "struts.fileManager";
/** The com.opensymphony.xwork2.util.ObjectTypeDeterminer implementation class */
public static final String STRUTS_OBJECTTYPEDETERMINER = "struts.objectTypeDeterminer";
@@ -22,6 +22,7 @@
package org.apache.struts2.config;
import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.TextProvider;
import com.opensymphony.xwork2.UnknownHandlerManager;
@@ -189,6 +190,14 @@ import java.util.StringTokenizer;
* <td>singleton</td>
* <td>Helper class used with URLRenderer to provide exact logic for building URLs</td>
* </tr>
* <tr>
* <td>com.opensymphony.xwork2.FileManager</td>
* <td>struts.fileManager</td>
* <td>singleton</td>
* <td>Used to access files on the File System as also to monitor if reload is needed,
* can be implemented / overwritten to meet specific an application server needs
* </td>
* </tr>
* </table>
*
* <!-- END SNIPPET: extensionPoints -->
@@ -234,6 +243,7 @@ public class BeanSelectionProvider implements ConfigurationProvider {
public void register(ContainerBuilder builder, LocatableProperties props) {
alias(ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY, builder, props);
alias(FileManager.class, StrutsConstants.STRUTS_FILEMANAGER, builder, props);
alias(XWorkConverter.class, StrutsConstants.STRUTS_XWORKCONVERTER, builder, props);
alias(TextProvider.class, StrutsConstants.STRUTS_XWORKTEXTPROVIDER, builder, props, Scope.DEFAULT);
alias(ActionProxyFactory.class, StrutsConstants.STRUTS_ACTIONPROXYFACTORY, builder, props);
@@ -306,20 +316,20 @@ public class BeanSelectionProvider implements ConfigurationProvider {
String foundName = props.getProperty(key, DEFAULT_BEAN_NAME);
if (builder.contains(type, foundName)) {
if (LOG.isInfoEnabled()) {
LOG.info("Choosing bean (#1) for (#2)", foundName, type.getName());
LOG.info("Choosing bean (#0) for (#1)", foundName, type.getName());
}
builder.alias(type, foundName, Container.DEFAULT_NAME);
} else {
try {
Class cls = ClassLoaderUtil.loadClass(foundName, this.getClass());
if (LOG.isDebugEnabled()) {
LOG.debug("Choosing bean (#1) for (#2)", cls.getName(), type.getName());
LOG.debug("Choosing bean (#0) for (#1)", cls.getName(), type.getName());
}
builder.factory(type, cls, scope);
} catch (ClassNotFoundException ex) {
// Perhaps a spring bean id, so we'll delegate to the object factory at runtime
if (LOG.isDebugEnabled()) {
LOG.debug("Choosing bean (#1) for (#2) to be loaded from the ObjectFactory", foundName, type.getName());
LOG.debug("Choosing bean (#0) for (#1) to be loaded from the ObjectFactory", foundName, type.getName());
}
if (DEFAULT_BEAN_NAME.equals(foundName)) {
// Probably an optional bean, will ignore
@@ -334,7 +344,7 @@ public class BeanSelectionProvider implements ConfigurationProvider {
}
} else {
if (LOG.isWarnEnabled()) {
LOG.warn("Unable to alias bean type (#1), default mapping already assigned.", type.getName());
LOG.warn("Unable to alias bean type (#0), default mapping already assigned.", type.getName());
}
}
}
@@ -24,6 +24,7 @@ package org.apache.struts2.dispatcher;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.config.Configuration;
@@ -39,7 +40,6 @@ import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.FileManager;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
@@ -397,7 +397,8 @@ public class Dispatcher {
}
private void init_CheckConfigurationReloading(Container container) {
FileManager.setReloadingConfigs("true".equals(container.getInstance(String.class,
FileManager fileManager = container.getInstance(FileManager.class);
fileManager.setReloadingConfigs("true".equals(container.getInstance(String.class,
StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD)));
}
@@ -679,6 +680,10 @@ public class Dispatcher {
if (defaultEncoding != null) {
encoding = defaultEncoding;
}
// check for Ajax request to use UTF-8 encoding strictly http://www.w3.org/TR/XMLHttpRequest/#the-send-method
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) {
encoding = "utf-8";
}
Locale locale = null;
if (defaultLocale != null) {
@@ -686,11 +691,7 @@ public class Dispatcher {
}
if (encoding != null) {
try {
request.setCharacterEncoding(encoding);
} catch (Exception e) {
LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
}
applyEncoding(request, encoding);
}
if (locale != null) {
@@ -702,6 +703,18 @@ public class Dispatcher {
}
}
private void applyEncoding(HttpServletRequest request, String encoding) {
try {
if (!encoding.equals(request.getCharacterEncoding())) {
// if the encoding is already correctly set and the parameters have been already read
// do not try to set encoding because it is useless and will cause an error
request.setCharacterEncoding(encoding);
}
} catch (Exception e) {
LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
}
}
/**
* Wrap and return the given request or return the original request object.
* </p>
@@ -27,6 +27,7 @@ import com.opensymphony.xwork2.util.logging.LoggerFactory;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
@@ -35,7 +36,7 @@ import java.nio.charset.Charset;
/**
* <!-- START SNIPPET: description -->
*
* A result that send the content out as plain text. Usefull typically when needed
* A result that send the content out as plain text. Useful typically when needed
* to display the raw content of a JSP or Html file for example.
*
* <!-- END SNIPPET: description -->
@@ -57,12 +58,12 @@ import java.nio.charset.Charset;
* <!-- START SNIPPET: example -->
*
* &lt;action name="displayJspRawContent" &gt;
* &lt;result type="plaintext"&gt;/myJspFile.jsp&lt;/result&gt;
* &lt;result type="plainText"&gt;/myJspFile.jsp&lt;/result&gt;
* &lt;/action&gt;
*
*
* &lt;action name="displayJspRawContent" &gt;
* &lt;result type="plaintext"&gt;
* &lt;result type="plainText"&gt;
* &lt;param name="location"&gt;/myJspFile.jsp&lt;/param&gt;
* &lt;param name="charSet"&gt;UTF-8&lt;/param&gt;
* &lt;/result&gt;
@@ -112,53 +113,27 @@ public class PlainTextResult extends StrutsResultSupport {
* @see org.apache.struts2.dispatcher.StrutsResultSupport#doExecute(java.lang.String, com.opensymphony.xwork2.ActionInvocation)
*/
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
// verify charset
Charset charset = null;
if (charSet != null) {
if (Charset.isSupported(charSet)) {
charset = Charset.forName(charSet);
}
else {
if (LOG.isWarnEnabled()) {
LOG.warn("charset ["+charSet+"] is not recognized ");
}
charset = null;
}
}
Charset charset = readCharset();
HttpServletResponse response = (HttpServletResponse) invocation.getInvocationContext().get(HTTP_RESPONSE);
ServletContext servletContext = (ServletContext) invocation.getInvocationContext().get(SERVLET_CONTEXT);
if (charset != null) {
response.setContentType("text/plain; charset="+charSet);
}
else {
response.setContentType("text/plain");
}
response.setHeader("Content-Disposition", "inline");
applyCharset(charset, response);
applyAdditionalHeaders(response);
String location = adjustLocation(finalLocation);
PrintWriter writer = response.getWriter();
InputStreamReader reader = null;
try {
InputStream resourceAsStream = servletContext.getResourceAsStream(finalLocation);
InputStream resourceAsStream = readStream(invocation, location);
logWrongStream(finalLocation, resourceAsStream);
if (charset != null) {
reader = new InputStreamReader(resourceAsStream, charset);
} else {
reader = new InputStreamReader(resourceAsStream);
}
if (resourceAsStream == null) {
if (LOG.isWarnEnabled()) {
LOG.warn("resource at location ["+finalLocation+"] cannot be obtained (return null) from ServletContext !!! ");
}
} else {
char[] buffer = new char[BUFFER_SIZE];
int charRead;
while((charRead = reader.read(buffer)) != -1) {
writer.write(buffer, 0, charRead);
}
if (resourceAsStream != null) {
sendStream(writer, reader);
}
} finally {
if (reader != null)
@@ -169,4 +144,60 @@ public class PlainTextResult extends StrutsResultSupport {
}
}
}
protected InputStream readStream(ActionInvocation invocation, String location) {
ServletContext servletContext = (ServletContext) invocation.getInvocationContext().get(SERVLET_CONTEXT);
return servletContext.getResourceAsStream(location);
}
protected void logWrongStream(String finalLocation, InputStream resourceAsStream) {
if (resourceAsStream == null) {
if (LOG.isWarnEnabled()) {
LOG.warn("Resource at location [" + finalLocation + "] cannot be obtained (return null) from ServletContext !!! ");
}
}
}
protected void sendStream(PrintWriter writer, InputStreamReader reader) throws IOException {
char[] buffer = new char[BUFFER_SIZE];
int charRead;
while((charRead = reader.read(buffer)) != -1) {
writer.write(buffer, 0, charRead);
}
}
protected String adjustLocation(String location) {
if (location.charAt(0) != '/') {
return "/" + location;
}
return location;
}
protected void applyAdditionalHeaders(HttpServletResponse response) {
response.setHeader("Content-Disposition", "inline");
}
protected void applyCharset(Charset charset, HttpServletResponse response) {
if (charset != null) {
response.setContentType("text/plain; charset=" + charSet);
} else {
response.setContentType("text/plain");
}
}
protected Charset readCharset() {
Charset charset = null;
if (charSet != null) {
if (Charset.isSupported(charSet)) {
charset = Charset.forName(charSet);
} else {
if (LOG.isWarnEnabled()) {
LOG.warn("charset [" + charSet + "] is not recognized ");
}
charset = null;
}
}
return charset;
}
}
@@ -25,7 +25,7 @@ import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsStatics;
@@ -20,23 +20,22 @@
*/
package org.apache.struts2.dispatcher.ng;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.StrutsException;
import org.apache.struts2.RequestUtils;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.struts2.RequestUtils;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.StrutsException;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
@@ -47,6 +46,8 @@ import java.util.regex.Pattern;
*/
public class PrepareOperations {
private static final Logger LOG = LoggerFactory.getLogger(PrepareOperations.class);
private ServletContext servletContext;
private Dispatcher dispatcher;
private static final String STRUTS_ACTION_MAPPING_KEY = "struts.actionMapping";
@@ -98,10 +99,18 @@ public class PrepareOperations {
return;
}
}
// always clean up the thread request, even if an action hasn't been executed
ActionContext.setContext(null);
Dispatcher.setInstance(null);
try {
dispatcher.cleanUpRequest(request);
} catch (IOException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Cannot clean up the request, some files can still remain in #0 after upload!", e,
StrutsConstants.STRUTS_MULTIPART_SAVEDIR);
}
} finally {
ActionContext.setContext(null);
Dispatcher.setInstance(null);
}
}
/**
@@ -173,7 +182,7 @@ public class PrepareOperations {
*/
public void cleanupDispatcher() {
if (dispatcher == null) {
throw new StrutsException("something is seriously wrong, Dispatcher is not initialized (null) ");
throw new StrutsException("Something is seriously wrong, Dispatcher is not initialized (null) ");
} else {
try {
dispatcher.cleanup();
@@ -72,7 +72,7 @@ public class CheckboxInterceptor extends AbstractInterceptor {
iterator.remove();
if (values != null && values instanceof String[] && ((String[])values).length > 1) {
if (LOG.isDebugEnabled()) {
LOG.debug("Bypassing automatic checkbox detection due to multiple checkboxes of the same name: #1", name);
LOG.debug("Bypassing automatic checkbox detection due to multiple checkboxes of the same name: #0", name);
}
continue;
}
@@ -257,8 +257,9 @@ public class ExecuteAndWaitInterceptor extends MethodFilterInterceptor {
if ((!executeAfterValidationPass || !secondTime) && bp != null && !bp.isDone()) {
actionInvocation.getStack().push(bp.getAction());
if (TokenHelper.getToken() != null) {
session.put(TokenHelper.getTokenName(), TokenHelper.getToken());
final String token = TokenHelper.getToken();
if (token != null) {
TokenHelper.setSessionToken(TokenHelper.getTokenName(), token);
}
Map results = proxy.getConfig().getResults();
@@ -121,7 +121,8 @@ public class TokenSessionStoreInterceptor extends TokenInterceptor {
params.remove(tokenName);
params.remove(TokenHelper.TOKEN_NAME_FIELD);
ActionInvocation savedInvocation = InvocationSessionStore.loadInvocation(tokenName, token);
String sessionTokenName = TokenHelper.buildTokenSessionAttributeName(tokenName);
ActionInvocation savedInvocation = InvocationSessionStore.loadInvocation(sessionTokenName, token);
if (savedInvocation != null) {
// set the valuestack to the request scope
@@ -157,7 +158,8 @@ public class TokenSessionStoreInterceptor extends TokenInterceptor {
// we know the token name and token must be there
String key = TokenHelper.getTokenName();
String token = TokenHelper.getToken(key);
InvocationSessionStore.storeInvocation(key, token, invocation);
String sessionTokenName = TokenHelper.buildTokenSessionAttributeName(key);
InvocationSessionStore.storeInvocation(sessionTokenName, token, invocation);
return invocation.invoke();
}
@@ -25,6 +25,7 @@ import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
@@ -148,6 +149,10 @@ public class StrutsUtil {
return (request == null)? "" : request.getContextPath();
}
public String translateVariables(String expression) {
return TextParseUtil.translateVariables(expression, stack);
}
/**
* the selectedList objects are matched to the list.listValue
* <p/>
@@ -36,10 +36,15 @@ import com.opensymphony.xwork2.util.logging.LoggerFactory;
*/
public class TokenHelper {
/**
/**
* The default namespace for storing token session values
*/
public static final String TOKEN_NAMESPACE = "struts.tokens";
/**
* The default name to map the token value
*/
public static final String DEFAULT_TOKEN_NAME = "struts.token";
public static final String DEFAULT_TOKEN_NAME = "token";
/**
* The name of the field which will hold the token name
@@ -58,31 +63,53 @@ public class TokenHelper {
return setToken(DEFAULT_TOKEN_NAME);
}
/**
* Sets a transaction token into the session using the provided token name.
*
* @param tokenName the name to store into the session with the token as the value
* @return the token string
*/
public static String setToken(String tokenName) {
Map session = ActionContext.getContext().getSession();
String token = generateGUID();
try {
session.put(tokenName, token);
}
catch(IllegalStateException e) {
// WW-1182 explain to user what the problem is
String msg = "Error creating HttpSession due response is commited to client. You can use the CreateSessionInterceptor or create the HttpSession from your action before the result is rendered to the client: " + e.getMessage();
LOG.error(msg, e);
throw new IllegalArgumentException(msg);
}
/**
* Sets a transaction token into the session based on the provided token name.
*
* @param tokenName the token name based on which a generated token value is stored into session; for actual session
* store, this name will be prefixed by a namespace.
*
* @return the token string
*/
public static String setToken( String tokenName ) {
String token = generateGUID();
setSessionToken(tokenName, token);
return token;
}
return token;
}
/**
* Put a given named token into the session map. The token will be stored with a namespace prefix prepended.
*
* @param tokenName the token name based on which given token value is stored into session; for actual session store,
* this name will be prefixed by a namespace.
* @param token the token value to store
*/
public static void setSessionToken( String tokenName, String token ) {
Map<String, Object> session = ActionContext.getContext().getSession();
try {
session.put(buildTokenSessionAttributeName(tokenName), token);
} catch ( IllegalStateException e ) {
// WW-1182 explain to user what the problem is
String msg = "Error creating HttpSession due response is commited to client. You can use the CreateSessionInterceptor or create the HttpSession from your action before the result is rendered to the client: " + e.getMessage();
LOG.error(msg, e);
throw new IllegalArgumentException(msg);
}
}
/**
* Gets a transaction token into the session using the default token name.
/**
* Build a name-spaced token session attribute name based on the given token name.
*
* @param tokenName the token name to prefix
*
* @return the name space prefixed session token name
*/
public static String buildTokenSessionAttributeName( String tokenName ) {
return TOKEN_NAMESPACE + "." + tokenName;
}
/**
* Gets a transaction token from the params in the ServletActionContext using the default token name.
*
* @return token
*/
@@ -175,7 +202,8 @@ public class TokenHelper {
}
Map session = ActionContext.getContext().getSession();
String sessionToken = (String) session.get(tokenName);
String tokenSessionName = buildTokenSessionAttributeName(tokenName);
String sessionToken = (String) session.get(tokenSessionName);
if (!token.equals(sessionToken)) {
if (LOG.isWarnEnabled()) {
@@ -188,7 +216,7 @@ public class TokenHelper {
}
// remove the token so it won't be used again
session.remove(tokenName);
session.remove(tokenSessionName);
return true;
}
@@ -21,9 +21,10 @@
package org.apache.struts2.views.freemarker;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.FileManager;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
@@ -176,6 +177,8 @@ public class FreemarkerManager {
protected String templateUpdateDelay;
protected Map<String,TagLibrary> tagLibraries;
private FileManager fileManager;
@Inject(StrutsConstants.STRUTS_I18N_ENCODING)
public void setEncoding(String encoding) {
this.encoding = encoding;
@@ -211,6 +214,11 @@ public class FreemarkerManager {
this.tagLibraries = Collections.unmodifiableMap(map);
}
@Inject
public void setFileManager(FileManager fileManager) {
this.fileManager = fileManager;
}
public boolean getNoCharsetInContentType() {
return noCharsetInContentType;
}
@@ -427,7 +435,8 @@ public class FreemarkerManager {
InputStream in = null;
try {
in = FileManager.loadFile("freemarker.properties", FreemarkerManager.class);
in = fileManager.loadFile(ClassLoaderUtil.getResource("freemarker.properties", getClass()));
if (in != null) {
Properties p = new Properties();
@@ -38,6 +38,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -308,7 +309,7 @@ public class DefaultUrlHelper implements UrlHelper {
} else {
String currentParamValues[] = (String[]) currentParam;
if (currentParamValues != null) {
List<String> paramList = Arrays.asList(currentParamValues);
List<String> paramList = new ArrayList<String>(Arrays.asList(currentParamValues));
paramList.add(translatedParamValue);
queryParams.put(paramName, paramList.toArray(new String[paramList.size()]));
} else {
@@ -29,6 +29,9 @@
<bean class="com.opensymphony.xwork2.ObjectFactory" name="xwork" />
<bean type="com.opensymphony.xwork2.ObjectFactory" name="struts" class="org.apache.struts2.impl.StrutsObjectFactory" />
<bean type="com.opensymphony.xwork2.FileManager" class="com.opensymphony.xwork2.util.fs.DefaultFileManager" name="xwork"/>
<bean type="com.opensymphony.xwork2.FileManager" class="com.opensymphony.xwork2.util.fs.DefaultFileManager" name="struts"/>
<bean type="com.opensymphony.xwork2.ActionProxyFactory" name="xwork" class="com.opensymphony.xwork2.DefaultActionProxyFactory"/>
<bean type="com.opensymphony.xwork2.ActionProxyFactory" name="struts" class="org.apache.struts2.impl.StrutsActionProxyFactory"/>
@@ -23,6 +23,8 @@
<#if (parameters.dynamicAttributes?? && parameters.dynamicAttributes?size > 0)><#rt/>
<#assign aKeys = parameters.dynamicAttributes.keySet()><#rt/>
<#list aKeys as aKey><#rt/>
${aKey}="${parameters.dynamicAttributes[aKey]?html}"<#rt/>
<#assign keyValue = parameters.dynamicAttributes[aKey]/>
<#assign value = struts.translateVariables(keyValue)!keyValue/>
${aKey}="${value?html}"<#rt/>
</#list><#rt/>
</#if><#rt/>
@@ -61,6 +61,7 @@
</#if>
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
<#include "/${parameters.templateDir}/simple/dynamic-attributes.ftl" />
/><#rt/>
<label for="${parameters.id?html}${itemKeyStr?html}"><#rt/>
${itemValue}<#t/>
@@ -21,28 +21,9 @@
package org.apache.struts2.dispatcher;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.StrutsTestCase;
import org.apache.struts2.dispatcher.FilterDispatcherTest.InnerActionMapper;
import org.apache.struts2.dispatcher.FilterDispatcherTest.InnerDestroyableObjectFactory;
import org.apache.struts2.dispatcher.FilterDispatcherTest.InnerDispatcher;
import org.springframework.mock.web.MockFilterConfig;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
import com.mockobjects.dynamic.C;
import com.mockobjects.dynamic.Mock;
import com.mockobjects.servlet.MockFilterChain;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationManager;
@@ -50,11 +31,21 @@ import com.opensymphony.xwork2.config.entities.InterceptorMapping;
import com.opensymphony.xwork2.config.entities.InterceptorStackConfig;
import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.inject.Context;
import com.opensymphony.xwork2.inject.Factory;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.opensymphony.xwork2.util.fs.DefaultFileManager;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.StrutsTestCase;
import org.apache.struts2.dispatcher.FilterDispatcherTest.InnerDestroyableObjectFactory;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* Test case for Dispatcher.
@@ -81,7 +72,7 @@ public class DispatcherTest extends StrutsTestCase {
HttpServletRequest req = new MockHttpServletRequest();
HttpServletResponse res = new MockHttpServletResponse();
Dispatcher du = initDispatcher(new HashMap() {{
Dispatcher du = initDispatcher(new HashMap<String, String>() {{
put(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8");
}});
du.prepare(req, res);
@@ -89,12 +80,54 @@ public class DispatcherTest extends StrutsTestCase {
assertEquals(req.getCharacterEncoding(), "utf-8");
}
public void testEncodingForXMLHttpRequest() throws Exception {
// given
MockHttpServletRequest req = new MockHttpServletRequest();
req.addHeader("X-Requested-With", "XMLHttpRequest");
req.setCharacterEncoding("utf-8");
HttpServletResponse res = new MockHttpServletResponse();
Dispatcher du = initDispatcher(new HashMap<String, String>() {{
put(StrutsConstants.STRUTS_I18N_ENCODING, "latin-2");
}});
// when
du.prepare(req, res);
// then
assertEquals(req.getCharacterEncoding(), "utf-8");
}
public void testSetEncodingIfDiffer() throws Exception {
// given
Mock mock = new Mock(HttpServletRequest.class);
mock.expectAndReturn("getCharacterEncoding", "utf-8");
mock.expectAndReturn("getHeader", "X-Requested-With", "");
mock.expectAndReturn("getLocale", Locale.getDefault());
mock.expectAndReturn("getCharacterEncoding", "utf-8");
HttpServletRequest req = (HttpServletRequest) mock.proxy();
HttpServletResponse res = new MockHttpServletResponse();
Dispatcher du = initDispatcher(new HashMap<String, String>() {{
put(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8");
}});
// when
du.prepare(req, res);
// then
assertEquals(req.getCharacterEncoding(), "utf-8");
mock.verify();
}
public void testPrepareSetEncodingPropertyWithMultipartRequest() throws Exception {
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
req.setContentType("multipart/form-data");
Dispatcher du = initDispatcher(new HashMap() {{
Dispatcher du = initDispatcher(new HashMap<String, String>() {{
put(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8");
}});
du.prepare(req, res);
@@ -130,7 +163,7 @@ public class DispatcherTest extends StrutsTestCase {
public void testConfigurationManager() {
Dispatcher du = null;
Dispatcher du;
InternalConfigurationManager configurationManager = new InternalConfigurationManager();
try {
du = new Dispatcher(new MockServletContext(), new HashMap<String, String>());
@@ -148,7 +181,7 @@ public class DispatcherTest extends StrutsTestCase {
}
finally {
du.setInstance(null);
Dispatcher.setInstance(null);
}
}
@@ -163,6 +196,11 @@ public class DispatcherTest extends StrutsTestCase {
Mock mockContainer = new Mock(Container.class);
mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy());
mockContainer.expectAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), destroyedObjectFactory);
mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy());
mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy());
FileManager fileManager = new DefaultFileManager();
mockContainer.expectAndReturn("getInstance", C.args(C.eq(FileManager.class)), fileManager);
mockContainer.expectAndReturn("getInstance", C.args(C.eq(FileManager.class)), fileManager);
mockConfiguration.expect("destroy");
mockConfiguration.matchAndReturn("getPackageConfigs", new HashMap<String, PackageConfig>());
@@ -190,7 +228,8 @@ public class DispatcherTest extends StrutsTestCase {
Mock mockContainer = new Mock(Container.class);
mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new ObjectFactory());
mockContainer.matchAndReturn("getInstance", C.args(C.eq(FileManager.class)), new DefaultFileManager());
Mock mockConfiguration = new Mock(Configuration.class);
mockConfiguration.matchAndReturn("getPackageConfigs", packageConfigs);
mockConfiguration.matchAndReturn("getContainer", mockContainer.proxy());
@@ -21,17 +21,10 @@
package org.apache.struts2.dispatcher;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.StrutsConstants;
import com.mockobjects.servlet.MockFilterChain;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
import org.apache.struts2.StrutsTestCase;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
@@ -41,14 +34,13 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
import com.mockobjects.servlet.MockFilterChain;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.inject.Context;
import com.opensymphony.xwork2.inject.Factory;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
/**
* FilterDispatcher TestCase.
@@ -21,23 +21,19 @@
package org.apache.struts2.dispatcher;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import junit.framework.TestCase;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.mock.MockActionInvocation;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.StrutsTestCase;
import org.apache.struts2.views.jsp.AbstractUITagTest;
import org.apache.struts2.views.jsp.StrutsMockHttpServletResponse;
import org.apache.struts2.views.jsp.StrutsMockServletContext;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.ValueStackFactory;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.mock.MockActionInvocation;
import com.opensymphony.xwork2.util.ValueStack;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* Test case for PlainTextResult.
@@ -80,6 +76,29 @@ public class PlainTextResultTest extends StrutsTestCase {
}
}
public void testPlainTextWithoutSlash() throws Exception {
PlainTextResult result = new PlainTextResult();
result.setLocation("someJspFile.jsp");
response.setExpectedContentType("text/plain");
response.setExpectedHeader("Content-Disposition", "inline");
InputStream jspResourceInputStream =
ClassLoaderUtil.getResourceAsStream("org/apache/struts2/dispatcher/someJspFile.jsp", PlainTextResultTest.class);
try {
servletContext.setResourceAsStream(jspResourceInputStream);
result.execute(invocation);
String r = AbstractUITagTest.normalize(stringWriter.getBuffer().toString(), true);
String e = AbstractUITagTest.normalize(readAsString("org/apache/struts2/dispatcher/someJspFile.jsp"), true);
assertEquals(r, e);
}
finally {
jspResourceInputStream.close();
}
}
public void testPlainTextWithEncoding() throws Exception {
PlainTextResult result = new PlainTextResult();
result.setLocation("/someJspFile.jsp");
@@ -21,24 +21,19 @@
package org.apache.struts2.util;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.StrutsTestCase;
import org.apache.struts2.TestAction;
import org.apache.struts2.util.ListEntry;
import org.apache.struts2.util.StrutsUtil;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockRequestDispatcher;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.util.ArrayList;
import java.util.List;
/**
* Test case for StrutsUtil.
@@ -184,6 +179,18 @@ public class StrutsUtilTest extends StrutsTestCase {
assertEquals(strutsUtil.toString(11l), "11");
}
public void testTranslateVariables() throws Exception {
stack.push(new Object() {
public String getFoo() {
return "bar";
}
});
Object obj1 = strutsUtil.translateVariables("try: %{foo}");
assertNotNull(obj1);
assertTrue(obj1 instanceof String);
assertEquals(obj1, "try: bar");
}
// === Junit Hook
@@ -38,22 +38,38 @@ public class TokenHelperTest extends TestCase {
private Map session;
public void testTokenSessionNameBuilding() throws Exception {
String name = "foo";
String sessionName = TokenHelper.buildTokenSessionAttributeName(name);
assertEquals(TokenHelper.TOKEN_NAMESPACE + "." + name, sessionName);
}
public void testSetToken() {
String token = TokenHelper.setToken();
assertEquals(token, session.get(TokenHelper.DEFAULT_TOKEN_NAME));
final String defaultSessionTokenName = TokenHelper.buildTokenSessionAttributeName(TokenHelper.DEFAULT_TOKEN_NAME);
assertEquals(token, session.get(defaultSessionTokenName));
}
public void testSetTokenWithName() {
String tokenName = "myTestToken";
String token = TokenHelper.setToken(tokenName);
assertEquals(token, session.get(tokenName));
final String sessionTokenName = TokenHelper.buildTokenSessionAttributeName(tokenName);
assertEquals(token, session.get(sessionTokenName));
}
public void testValidToken() {
public void testSetSessionToken() {
String tokenName = "myOtherTestToken";
String token = "foobar";
TokenHelper.setSessionToken(tokenName, token);
final String sessionTokenName = TokenHelper.buildTokenSessionAttributeName(tokenName);
assertEquals(token, session.get(sessionTokenName));
}
public void testValidToken() {
String tokenName = "validTokenTest";
String token = TokenHelper.setToken(tokenName);
assertEquals(token, session.get(tokenName));
final String sessionTokenName = TokenHelper.buildTokenSessionAttributeName(tokenName);
assertEquals(token, session.get(sessionTokenName));
ActionContext.getContext().getParameters().put(TokenHelper.TOKEN_NAME_FIELD, new String[]{tokenName});
ActionContext.getContext().getParameters().put(tokenName, new String[]{token});
assertTrue(TokenHelper.validToken());
@@ -24,6 +24,7 @@ package org.apache.struts2.views.freemarker;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.mock.MockActionInvocation;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.fs.DefaultFileManager;
import com.opensymphony.xwork2.util.ValueStack;
import freemarker.template.Configuration;
import freemarker.template.TemplateExceptionHandler;
@@ -219,10 +220,53 @@ public class FreeMarkerResultTest extends StrutsTestCase {
assertEquals(expected, stringWriter.toString());
}
public void testManualListInTemplate() throws Exception {
FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
Configuration freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
File file = new File(FreeMarkerResultTest.class.getResource("manual-list.ftl").toURI());
EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/manual-list.ftl")).andReturn(file.getAbsolutePath());
file = new File(ClassLoaderUtil.getResource("template/simple/radiomap.ftl", getClass()).toURI());
EasyMock.expect(servletContext.getRealPath("/template/simple/radiomap.ftl")).andReturn(file.getAbsolutePath());
file = new File(ClassLoaderUtil.getResource("template/simple/css.ftl", getClass()).toURI());
EasyMock.expect(servletContext.getRealPath("/template/simple/css.ftl")).andReturn(file.getAbsolutePath());
file = new File(ClassLoaderUtil.getResource("template/simple/scripting-events.ftl", getClass()).toURI());
EasyMock.expect(servletContext.getRealPath("/template/simple/scripting-events.ftl")).andReturn(file.getAbsolutePath());
file = new File(ClassLoaderUtil.getResource("template/simple/common-attributes.ftl", getClass()).toURI());
EasyMock.expect(servletContext.getRealPath("/template/simple/common-attributes.ftl")).andReturn(file.getAbsolutePath());
file = new File(ClassLoaderUtil.getResource("template/simple/dynamic-attributes.ftl", getClass()).toURI());
EasyMock.expect(servletContext.getRealPath("/template/simple/dynamic-attributes.ftl")).andReturn(file.getAbsolutePath());
EasyMock.expect(servletContext.getAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY)).andReturn(freemarkerConfig).anyTimes();
EasyMock.replay(servletContext);
freemarkerConfig.setServletContextForTemplateLoading(servletContext, null);
ServletActionContext.setServletContext(servletContext);
request.setRequestURI("/tutorial/test7.action");
Dispatcher dispatcher = Dispatcher.getInstance();
ActionMapping mapping = dispatcher.getContainer().getInstance(ActionMapper.class).getMapping(request, dispatcher.getConfigurationManager());
dispatcher.serviceAction(request, response, servletContext, mapping);
String expected =
"<input type=\"radio\" name=\"client\" id=\"client_foo\" value=\"foo\"/><label for=\"client_foo\">foo</label>\n" +
"<input type=\"radio\" name=\"client\" id=\"client_bar\" value=\"bar\"/><label for=\"client_bar\">bar</label>\n";
assertEquals(expected, stringWriter.toString());
}
protected void setUp() throws Exception {
super.setUp();
mgr = new FreemarkerManager();
mgr.setEncoding("UTF-8");
mgr.setFileManager(new DefaultFileManager());
stringWriter = new StringWriter();
writer = new PrintWriter(stringWriter);
response = new StrutsMockHttpServletResponse();
@@ -21,6 +21,7 @@
package org.apache.struts2.views.freemarker;
import com.opensymphony.xwork2.util.fs.DefaultFileManager;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.StrutsTestCase;
import org.apache.struts2.views.jsp.StrutsMockServletContext;
@@ -33,6 +34,7 @@ public class FreemarkerManagerTest extends StrutsTestCase {
public void testIfStrutsEncodingIsSetProperty() throws Exception {
FreemarkerManager mgr = new FreemarkerManager();
mgr.setEncoding("UTF-8");
mgr.setFileManager(new DefaultFileManager());
StrutsMockServletContext servletContext = new StrutsMockServletContext();
servletContext.setAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY, null);
freemarker.template.Configuration conf = mgr.getConfiguration(servletContext);
@@ -21,12 +21,19 @@
package org.apache.struts2.views.jsp.ui;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.config.RuntimeConfiguration;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Scope.Strategy;
import com.opensymphony.xwork2.validator.ValidationInterceptor;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.TestAction;
import org.apache.struts2.TestConfigurationProvider;
@@ -35,14 +42,11 @@ import org.apache.struts2.views.jsp.AbstractUITagTest;
import org.apache.struts2.views.jsp.ActionTag;
import org.easymock.EasyMock;
import com.opensymphony.xwork2.*;
import com.opensymphony.xwork2.config.RuntimeConfiguration;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Scope.Strategy;
import com.opensymphony.xwork2.validator.ValidationInterceptor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@@ -205,7 +209,7 @@ public class FormTagTest extends AbstractUITagTest {
public void removeScopeStrategy() {}
public void setScopeStrategy(Strategy scopeStrategy) {}
public <T> T getInstance(Class<T> type, String name) {return null;}
public <T> T getInstance(Class<T> type) {return null;}
public <T> T getInstance(Class<T> type) {return cont.getInstance(type);}
public Set<String> getInstanceNames(Class<?> type) {return null;}
public void inject(Object o) {
@@ -292,7 +296,7 @@ public class FormTagTest extends AbstractUITagTest {
public void removeScopeStrategy() {}
public void setScopeStrategy(Strategy scopeStrategy) {}
public <T> T getInstance(Class<T> type, String name) {return null;}
public <T> T getInstance(Class<T> type) {return null;}
public <T> T getInstance(Class<T> type) {return cont.getInstance(type);}
public Set<String> getInstanceNames(Class<?> type) {return null;}
public void inject(Object o) {
@@ -376,7 +380,7 @@ public class FormTagTest extends AbstractUITagTest {
public void removeScopeStrategy() {}
public void setScopeStrategy(Strategy scopeStrategy) {}
public <T> T getInstance(Class<T> type, String name) {return null;}
public <T> T getInstance(Class<T> type) {return null;}
public <T> T getInstance(Class<T> type) {return cont.getInstance(type);}
public Set<String> getInstanceNames(Class<?> type) {return null;}
public void inject(Object o) {
@@ -457,7 +461,7 @@ public class FormTagTest extends AbstractUITagTest {
public void removeScopeStrategy() {}
public void setScopeStrategy(Strategy scopeStrategy) {}
public <T> T getInstance(Class<T> type, String name) {return null;}
public <T> T getInstance(Class<T> type) {return null;}
public <T> T getInstance(Class<T> type) {return cont.getInstance(type);}
public Set<String> getInstanceNames(Class<?> type) {return null;}
public void inject(Object o) {
@@ -21,14 +21,14 @@
package org.apache.struts2.views.jsp.ui;
import org.apache.struts2.TestAction;
import org.apache.struts2.views.jsp.AbstractUITagTest;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
import org.apache.struts2.TestAction;
import org.apache.struts2.views.jsp.AbstractUITagTest;
/**
*/
@@ -175,6 +175,30 @@ public class RadioTest extends AbstractUITagTest {
verifyGenericProperties(tag, "xhtml", new String[]{"id","value"});
}
public void testDynamicAttributes() throws Exception {
TestAction testAction = (TestAction) action;
testAction.setFoo("bar");
testAction.setList(new String[][]{
{"hello", "world"},
{"foo", "bar"}
});
RadioTag tag = new RadioTag();
tag.setPageContext(pageContext);
tag.setLabel("mylabel");
tag.setName("myname");
tag.setValue("");
tag.setList("list");
tag.setListKey("top[0]");
tag.setListValue("top[1]");
tag.setDynamicAttribute(null, "dojo", "checked: %{top[0]}");
tag.doStartTag();
tag.doEndTag();
verify(RadioTag.class.getResource("Radio-7.txt"));
}
private void prepareTagGeneric(RadioTag tag) {
TestAction testAction = (TestAction) action;
testAction.setFoo("bar");
@@ -63,7 +63,7 @@ public class TokenTagTest extends AbstractUITagTest {
doTokenTest(tokenName, tag);
String s = writer.toString();
assertTrue(s.indexOf("name=\"" + TokenHelper.DEFAULT_TOKEN_NAME) > -1);
assertTrue(s.indexOf("name=\"" + TokenHelper.TOKEN_NAME_FIELD) > -1);
assertTrue(s.indexOf("value=\"" + tokenName + "\"") > -1);
assertTrue(s.indexOf("name=\"" + tokenName + "\"") > -1);
@@ -87,8 +87,9 @@ public class TokenTagTest extends AbstractUITagTest {
tag.doEndTag();
token = (String) context.get(tokenName);
assertNotNull(token);
assertEquals(token, pageContext.getSession().getAttribute(tokenName));
assertNotNull(token);
final String sessionTokenName = TokenHelper.buildTokenSessionAttributeName(tokenName);
assertEquals(token, pageContext.getSession().getAttribute(sessionTokenName));
} catch (JspException e) {
e.printStackTrace();
fail();
@@ -0,0 +1,23 @@
<#--
/*
* $Id: someFreeMarkerFile.ftl 590812 2007-10-31 20:32:54Z apetrelli $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
-->
<@s.radio name="client" id="client_" list='{"foo", "bar"}' />
@@ -0,0 +1,7 @@
<tr>
<td class="tdLabel"><label for="myname" class="label">mylabel:</label></td>
<td>
<input type="radio" name="myname" id="mynamehello" value="hello" dojo="checked:hello"/><label for="mynamehello">world</label>
<input type="radio" name="myname" id="mynamefoo" value="foo" dojo="checked:foo"/><label for="mynamefoo">bar</label>
</td>
</tr>
+6
View File
@@ -69,6 +69,12 @@
</result>
</action>
<action name="test7" class="com.opensymphony.xwork2.ActionSupport">
<result type="freemarker">
<param name="location">org/apache/struts2/views/freemarker/manual-list.ftl</param>
</result>
</action>
</package>
<package name="sitegraph" namespace="/tutorial/sitegraph" extends="struts-default">
+1 -1
View File
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-codebehind-plugin</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 Codebehind Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/codebehind</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/codebehind</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/codebehind</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/codebehind</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/codebehind</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/codebehind</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-config-browser-plugin</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 Configuration Browser Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/config-browser</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/config-browser</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/config-browser</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/config-browser</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/config-browser</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/config-browser</url>
</scm>
</project>
+4 -4
View File
@@ -3,7 +3,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
@@ -11,9 +11,9 @@
<name>Struts 2 Convention Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/sandbox/tags/STRUTS_2_3_2/trunk/struts2-convention-plugin</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/sandbox/tags/STRUTS_2_3_2/trunk/struts2-convention-plugin</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/sandbox/tags/STRUTS_2_3_2/trunk/struts2-convention-plugin</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/sandbox/branches/STRUTS_2_3_4_X/tags/STRUTS_2_3_4_1/trunk/struts2-convention-plugin</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/sandbox/branches/STRUTS_2_3_4_X/tags/STRUTS_2_3_4_1/trunk/struts2-convention-plugin</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/sandbox/branches/STRUTS_2_3_4_X/tags/STRUTS_2_3_4_1/trunk/struts2-convention-plugin</url>
</scm>
<build>
@@ -21,6 +21,7 @@
package org.apache.struts2.convention;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationException;
@@ -31,8 +32,8 @@ import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.FileManager;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.WildcardHelper;
import com.opensymphony.xwork2.util.classloader.ReloadingClassLoader;
import com.opensymphony.xwork2.util.finder.ClassFinder;
import com.opensymphony.xwork2.util.finder.ClassFinder.ClassInfo;
@@ -108,6 +109,8 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
private static final String DEFAULT_METHOD = "execute";
private boolean eagerLoading = false;
private FileManager fileManager;
/**
* Constructs actions based on a list of packages.
*
@@ -292,6 +295,11 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
this.eagerLoading = "true".equals(eagerLoading);
}
@Inject
public void setFileManager(FileManager fileManager) {
this.fileManager = fileManager;
}
protected void initReloadClassLoader() {
//when the configuration is reloaded, a new classloader will be setup
if (isReloadEnabled() && reloadingClassLoader == null)
@@ -486,6 +494,20 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
String classPackageName = StringUtils.substringBeforeLast(className, ".");
if(excludePackages != null && excludePackages.length > 0) {
WildcardHelper wildcardHelper = new WildcardHelper();
//we really don't care about the results, just the boolean
Map<String, String> matchMap = new HashMap<String, String>();
for(String packageExclude : excludePackages) {
int[] packagePattern = wildcardHelper.compilePattern(packageExclude);
if(wildcardHelper.match(matchMap, classPackageName, packagePattern)) {
return false;
}
}
}
if (actionPackages != null) {
for (String packageName : actionPackages) {
String strictPackageName = packageName + ".";
@@ -745,12 +767,13 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
if (pkgPart == null && packageLocators != null) {
for (String packageLocator : packageLocators) {
int index = pkg.lastIndexOf(packageLocator);
// check subpackage and not a part of package name, eg. actions -> my.actions.transactions - WW-3803
int index = pkg.lastIndexOf("." + packageLocator + ".");
// This ensures that the match is at the end, beginning or has a dot on each side of it
if (index >= 0 && (index + packageLocator.length() == pkg.length() || index == 0 ||
(pkg.charAt(index - 1) == '.' && pkg.charAt(index + packageLocator.length()) == '.'))) {
pkgPart = actionClass.getName().substring(index + packageLocator.length() + 1);
(pkg.charAt(index) == '.' && pkg.charAt(index + 1 + packageLocator.length()) == '.'))) {
pkgPart = actionClass.getName().substring(index + packageLocator.length() + 2);
}
}
}
@@ -896,7 +919,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
//watch class file
if (isReloadEnabled()) {
URL classFile = actionClass.getResource(actionClass.getSimpleName() + ".class");
FileManager.loadFile(classFile, false);
fileManager.monitorFile(classFile);
loadedFileUrls.add(classFile.toString());
}
}
@@ -1052,7 +1075,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
public boolean needsReload() {
if (devMode && reload) {
for (String url : loadedFileUrls) {
if (FileManager.fileNeedsReloading(url)) {
if (fileManager.fileNeedsReloading(url)) {
if (LOG.isDebugEnabled())
LOG.debug("File [#0] changed, configuration will be reloaded", url);
return true;
@@ -80,8 +80,10 @@ import org.apache.struts2.convention.actions.result.OverrideResultAction;
import org.apache.struts2.convention.actions.resultpath.ClassLevelResultPathAction;
import org.apache.struts2.convention.actions.resultpath.PackageLevelResultPathAction;
import org.apache.struts2.convention.actions.skip.Index;
import org.apache.struts2.convention.actions.transactions.TransNameAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.dontfind.DontFindMeAction;
import org.apache.struts2.dispatcher.ServletDispatcherResult;
import org.easymock.EasyMock;
@@ -115,6 +117,10 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
run(null, "actions,dontfind", null);
}
public void testExcludedPackages() throws MalformedURLException {
run(null, "actions", "dontfind");
}
private void run(String actionPackages, String packageLocators, String excludePackages) throws MalformedURLException {
//setup interceptors
List<InterceptorConfig> defaultInterceptors = new ArrayList<InterceptorConfig>();
@@ -188,6 +194,8 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
"/skip", strutsDefault, null);
PackageConfig chainPkg = makePackageConfig("org.apache.struts2.convention.actions.chain#struts-default#/chain",
"/chain", strutsDefault, null);
PackageConfig transPkg = makePackageConfig("org.apache.struts2.convention.actions.transactions#struts-default#/transactions",
"/transactions", strutsDefault, null);
ResultMapBuilder resultMapBuilder = createStrictMock(ResultMapBuilder.class);
checkOrder(resultMapBuilder, false);
@@ -288,6 +296,10 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
expect(resultMapBuilder.build(ChainedAction.class, getAnnotation(ChainedAction.class, "foo", Action.class), "foo", chainPkg)).andReturn(results);
expect(resultMapBuilder.build(ChainedAction.class, getAnnotation(ChainedAction.class, "bar", Action.class), "foo-bar", chainPkg)).andReturn(results);
/* org.apache.struts2.convention.actions.transactions */
expect(resultMapBuilder.build(TransNameAction.class, getAnnotation(TransNameAction.class, "trans1", Action.class), "trans1", transPkg)).andReturn(results);
expect(resultMapBuilder.build(TransNameAction.class, getAnnotation(TransNameAction.class, "trans2", Action.class), "trans2", transPkg)).andReturn(results);
EasyMock.replay(resultMapBuilder);
final DummyContainer mockContainer = new DummyContainer();
@@ -337,6 +349,7 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
assertEquals(14, pkgConfig.getActionConfigs().size());
verifyActionConfig(pkgConfig, "action1", ActionNameAction.class, "run1", pkgConfig.getName());
verifyActionConfig(pkgConfig, "action2", ActionNameAction.class, "run2", pkgConfig.getName());
verifyMissingActionConfig(pkgConfig, "foo", DontFindMeAction.class, "foo", pkgConfig.getName());
verifyActionConfig(pkgConfig, "action3", "someClassName", "run1", pkgConfig.getName());
verifyActionConfig(pkgConfig, "actions1", ActionNamesAction.class, "run", pkgConfig.getName());
verifyActionConfig(pkgConfig, "actions2", ActionNamesAction.class, "run", pkgConfig.getName());
@@ -350,6 +363,7 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
verifyActionConfig(pkgConfig, "class4", ClassLevelAnnotationsDefaultMethodAction.class, "execute", pkgConfig.getName());
verifyActionConfig(pkgConfig, "class5", ClassLevelAnnotationAction.class, null, pkgConfig.getName());
verifyActionConfig(pkgConfig, "class6", ClassLevelAnnotationDefaultMethodAction.class, "execute", pkgConfig.getName());
verifyActionConfig(pkgConfig, "class6", ClassLevelAnnotationDefaultMethodAction.class, "execute", pkgConfig.getName());
/* org.apache.struts2.convention.actions.namespace3 */
//action on namespace1 (action level)
@@ -545,6 +559,11 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
verifyActionConfig(pkgConfig, "idx", org.apache.struts2.convention.actions.idx.Index.class, "execute",
"org.apache.struts2.convention.actions.idx#struts-default#/idx");
/* org.apache.struts2.convention.actions.transactions */
pkgConfig = configuration.getPackageConfig("org.apache.struts2.convention.actions.transactions#struts-default#/transactions");
verifyActionConfig(pkgConfig, "trans1", TransNameAction.class, "trans1", pkgConfig.getName());
verifyActionConfig(pkgConfig, "trans2", TransNameAction.class, "trans2", pkgConfig.getName());
//test unknown handler automatic chaining
pkgConfig = configuration.getPackageConfig("org.apache.struts2.convention.actions.chain#struts-default#/chain");
ServletContext context = EasyMock.createNiceMock(ServletContext.class);
@@ -571,6 +590,12 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
assertEquals(packageName, ac.getPackageName());
}
private void verifyMissingActionConfig(PackageConfig pkgConfig, String actionName, Class<?> actionClass,
String methodName, String packageName) {
ActionConfig ac = pkgConfig.getAllActionConfigs().get(actionName);
assertNull(ac);
}
private void verifyActionConfig(PackageConfig pkgConfig, String actionName, String actionClass, String methodName, String packageName) {
ActionConfig ac = pkgConfig.getAllActionConfigs().get(actionName);
assertNotNull(ac);
@@ -0,0 +1,40 @@
/*
* $Id: ActionNameAction.java 655902 2008-05-13 15:15:12Z bpontarelli $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.struts2.convention.actions.transactions;
import org.apache.struts2.convention.annotation.Action;
/**
* <p>
* This is a test action.
* </p>
*/
public class TransNameAction {
@Action("trans1")
public String trans1() {
return null;
}
@Action("trans2")
public String trans2() {
return null;
}
}
+4 -4
View File
@@ -25,7 +25,7 @@
<parent>
<artifactId>struts2-plugins</artifactId>
<groupId>org.apache.struts</groupId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.struts</groupId>
@@ -33,9 +33,9 @@
<name>Struts 2 Dojo Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/dojo</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/dojo</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/dojo</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/dojo</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/dojo</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/dojo</url>
</scm>
<profiles>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-dwr-plugin</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 DWR Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/dwr</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/dwr</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/dwr</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/dwr</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/dwr</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/dwr</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
@@ -35,9 +35,9 @@
<name>Struts 2 Embedded JSP Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/embeddedjsp</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/embeddedjsp</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/embeddedjsp</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/embeddedjsp</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/embeddedjsp</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/embeddedjsp</url>
</scm>
<dependencies>
+4 -4
View File
@@ -3,7 +3,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
@@ -13,9 +13,9 @@
<url>http://struts.apache.org</url>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/sandbox/tags/STRUTS_2_3_2/trunk/struts2-gxp-plugin</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/sandbox/tags/STRUTS_2_3_2/trunk/struts2-gxp-plugin</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/sandbox/tags/STRUTS_2_3_2/trunk/struts2-gxp-plugin</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/sandbox/branches/STRUTS_2_3_4_X/tags/STRUTS_2_3_4_1/trunk/struts2-gxp-plugin</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/sandbox/branches/STRUTS_2_3_4_X/tags/STRUTS_2_3_4_1/trunk/struts2-gxp-plugin</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/sandbox/branches/STRUTS_2_3_4_X/tags/STRUTS_2_3_4_1/trunk/struts2-gxp-plugin</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-jasperreports-plugin</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 Jasper Reports Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/jasperreports</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/jasperreports</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/jasperreports</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/jasperreports</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/jasperreports</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/jasperreports</url>
</scm>
<dependencies>
+4 -4
View File
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-javatemplates-plugin</artifactId>
@@ -33,9 +33,9 @@
<name>Struts 2 Java Templates Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/javatemplates</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/javatemplates</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/javatemplates</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/javatemplates</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/javatemplates</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/javatemplates</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-jfreechart-plugin</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 JFreeChart Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/jfreechart</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/jfreechart</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/jfreechart</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/jfreechart</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/jfreechart</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/jfreechart</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-jsf-plugin</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 JSF Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/jsf</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/jsf</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/jsf</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/jsf</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/jsf</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/jsf</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 JSON Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/json</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/json</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/json</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/json</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/json</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/json</url>
</scm>
<build>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-junit-plugin</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 JUnit Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/junit</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/junit</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/junit</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/junit</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/junit</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/junit</url>
</scm>
<dependencies>
@@ -36,6 +36,7 @@ import org.apache.struts2.util.StrutsTestCaseHelper;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.mock.web.MockPageContext;
import org.springframework.mock.web.MockServletContext;
@@ -149,17 +150,23 @@ public abstract class StrutsTestCase extends XWorkTestCase {
return proxy;
}
private void initActionContext(ActionContext actionContext) {
actionContext.setParameters(new HashMap(request.getParameterMap()));
initMockPortletContext(actionContext);
protected void initActionContext(ActionContext actionContext) {
actionContext.setParameters(new HashMap<String, Object>(request.getParameterMap()));
initSession(actionContext);
initPortletContext(actionContext);
applyAdditionalParams(actionContext);
// set the action context to the one used by the proxy
ActionContext.setContext(actionContext);
}
private void initMockPortletContext(ActionContext actionContext) {
protected void initSession(ActionContext actionContext) {
if (actionContext.getSession() == null) {
actionContext.setSession(new HashMap<String, Object>());
request.setSession(new MockHttpSession(servletContext));
}
}
protected void initPortletContext(ActionContext actionContext) {
try {
ClassLoaderUtil.loadClass("javax.portlet.PortletContext", getClass());
Class mockClazz = ClassLoaderUtil.loadClass("org.springframework.mock.web.portlet.MockPortletContext", getClass());
+4 -4
View File
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-plugin</artifactId>
@@ -12,9 +12,9 @@
<name>Struts 2 OSGi Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/osgi</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/osgi</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/osgi</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/osgi</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/osgi</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/osgi</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-oval-plugin</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 OVal Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/oval</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/oval</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/oval</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/oval</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/oval</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/oval</url>
</scm>
<dependencies>
@@ -1,7 +1,8 @@
package org.apache.struts2.oval.interceptor;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.FileManager;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import net.sf.oval.configuration.Configurer;
@@ -9,6 +10,7 @@ import net.sf.oval.configuration.annotation.AnnotationsConfigurer;
import net.sf.oval.configuration.annotation.JPAAnnotationsConfigurer;
import net.sf.oval.configuration.xml.XMLConfigurer;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -26,12 +28,19 @@ public class DefaultOValValidationManager implements OValValidationManager {
protected boolean validateJPAAnnotations;
private FileManager fileManager;
@Inject
public void setFileManager(FileManager fileManager) {
this.fileManager = fileManager;
}
public synchronized List<Configurer> getConfigurers(Class clazz, String context, boolean validateJPAAnnotations) {
this.validateJPAAnnotations =validateJPAAnnotations;
final String validatorKey = buildValidatorKey(clazz, context);
if (validatorCache.containsKey(validatorKey)) {
if (FileManager.isReloadingConfigs()) {
if (fileManager.isReloadingConfigs()) {
List<Configurer> configurers = buildXMLConfigurers(clazz, context, true, null);
//add an annotation configurer
@@ -133,11 +142,12 @@ public class DefaultOValValidationManager implements OValValidationManager {
}
protected XMLConfigurer loadFile(String fileName, Class clazz, boolean checkFile) {
if ((checkFile && FileManager.fileNeedsReloading(fileName, clazz)) || !validatorFileCache.containsKey(fileName)) {
URL fileUrl = ClassLoaderUtil.getResource(fileName, clazz);
if ((checkFile && fileManager.fileNeedsReloading(fileUrl)) || !validatorFileCache.containsKey(fileName)) {
java.io.InputStream is = null;
try {
is = FileManager.loadFile(fileName, clazz);
is = fileManager.loadFile(fileUrl);
if (is != null) {
if (LOG.isDebugEnabled()) {
@@ -170,7 +170,7 @@ public class OValValidationInterceptor extends MethodFilterInterceptor {
//perform validation
List<ConstraintViolation> violations = validator.validate(action);
addValidationErrors(violations.toArray(new ConstraintViolation[0]), action, valueStack, null);
addValidationErrors(violations.toArray(new ConstraintViolation[violations.size()]), action, valueStack, null);
}
private void addValidationErrors(ConstraintViolation[] violations, Object action, ValueStack valueStack, String parentFieldname) {
@@ -180,13 +180,16 @@ public class OValValidationInterceptor extends MethodFilterInterceptor {
//translate message
String key = violation.getMessage();
String message = key;
// push context variable into stack, to allow use ${max}, ${min} etc in error messages
valueStack.push(violation.getMessageVariables());
//push the validator into the stack
valueStack.push(violation.getContext());
String message = key;
try {
message = validatorContext.getText(key);
} finally {
valueStack.pop();
valueStack.pop();
}
if (isActionError(violation)) {
@@ -24,14 +24,12 @@ import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ValidationAware;
import com.opensymphony.xwork2.XWorkTestCase;
import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
import net.sf.oval.configuration.Configurer;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Locale;
import net.sf.oval.configuration.Configurer;
import org.apache.struts2.oval.interceptor.OValValidationManager;
import java.util.Map;
public class OValValidationInterceptorTest extends XWorkTestCase {
public void testSimpleFieldsXML() throws Exception {
@@ -126,6 +124,20 @@ public class OValValidationInterceptorTest extends XWorkTestCase {
assertEquals(0, fieldErrors.size());
}
public void testSimpleFieldTooLong() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("oval", "simpleFieldTooLong", null, null);
SimpleField action = (SimpleField) baseActionProxy.getAction();
action.setName("12367");
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = action.getFieldErrors();
assertNotNull(fieldErrors);
assertEquals(1, fieldErrors.size());
assertValue(fieldErrors, "name", Arrays.asList("name is not between 0 and 3 characters long"));
assertValue(fieldErrors, "name", Arrays.asList("name is not between 0 and 3 characters long"));
}
public void testSimpleFieldMultipleValidators() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("oval", "simpleField", null, null);
SimpleField action = (SimpleField) baseActionProxy.getAction();
@@ -195,6 +207,19 @@ public class OValValidationInterceptorTest extends XWorkTestCase {
assertValue(fieldErrors, "name", Arrays.asList("name cannot be null"));
}
public void testSimpleFieldI18n2() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("oval", "simpleFieldI18n", null, null);
SimpleFieldI18n action = (SimpleFieldI18n) baseActionProxy.getAction();
action.setName("123123");
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = action.getFieldErrors();
assertNotNull(fieldErrors);
assertEquals(1, fieldErrors.size());
assertValue(fieldErrors, "name", Arrays.asList("name value is too long, allowed length is 3"));
}
public void testSimpleFieldI18nDefaultKey() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("oval", "simpleFieldI18nDefaultKey", null, null);
SimpleFieldI18nDefaultKey action = (SimpleFieldI18nDefaultKey) baseActionProxy.getAction();
@@ -21,12 +21,12 @@
package org.apache.struts2.oval.interceptor;
import com.opensymphony.xwork2.ActionSupport;
import net.sf.oval.constraint.NotNull;
import net.sf.oval.constraint.NotEmpty;
import net.sf.oval.constraint.Length;
import net.sf.oval.constraint.NotNull;
public class SimpleFieldI18n extends ActionSupport {
@NotNull(message = "notnull.field")
@Length(max = 3, message = "field.too.long")
private String name;
public String getName() {
@@ -1 +1,2 @@
notnull.field=${field.name} cannot be null
notnull.field=${field.name} cannot be null
field.too.long=${field.name} value is too long, allowed length is ${max}
@@ -46,6 +46,10 @@
<interceptor-ref name="ovalValidation"/>
<result type="void"></result>
</action>
<action name="simpleFieldTooLong" class="org.apache.struts2.oval.interceptor.SimpleField">
<interceptor-ref name="ovalValidation"/>
<result type="void"></result>
</action>
<action name="simpleMethod" class="org.apache.struts2.oval.interceptor.SimpleMethod">
<interceptor-ref name="ovalValidation"/>
<result type="void"></result>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-pell-multipart-plugin</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 Pell Multipart Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/pell-multipart</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/pell-multipart</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/pell-multipart</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/pell-multipart</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/pell-multipart</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/pell-multipart</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plexus-plugin</artifactId>
@@ -34,9 +34,9 @@
<name>Struts 2 Plexus Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/plexus</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/plexus</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/plexus</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/plexus</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/plexus</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/plexus</url>
</scm>
<dependencies>
+4 -4
View File
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
@@ -34,9 +34,9 @@
<name>Struts Plugins</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins</developerConnection>
<url>http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins</url>
</scm>
<modules>
+4 -4
View File
@@ -3,7 +3,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.3.2</version>
<version>2.3.4.1</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-portlet-plugin</artifactId>
@@ -11,9 +11,9 @@
<name>Struts 2 Portlet Plugin</name>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/portlet</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_2/plugins/portlet</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_2/plugins/portlet</url>
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/portlet</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_3_4_1/plugins/portlet</developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_3_4_1/plugins/portlet</url>
</scm>
<dependencies>
@@ -23,15 +23,15 @@ package org.apache.struts2.components;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.StrutsException;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.portlet.context.PortletActionContext;
import org.apache.struts2.portlet.util.PortletUrlHelper;
import org.apache.struts2.portlet.util.PortletUrlHelperJSR286;
import org.apache.struts2.views.util.UrlHelper;
import javax.portlet.PortletMode;
import java.io.IOException;
import java.io.Writer;
@@ -42,12 +42,10 @@ import java.io.Writer;
*/
public class PortletUrlRenderer implements UrlRenderer {
private static final Logger LOG = LoggerFactory.getLogger(PortletUrlRenderer.class);
/**
* The servlet renderer used when not executing in a portlet context.
*/
private UrlRenderer servletRenderer = null;
private ServletUrlRenderer servletRenderer = null;
private PortletUrlHelper portletUrlHelper = null;
public PortletUrlRenderer() {
@@ -65,24 +63,44 @@ public class PortletUrlRenderer implements UrlRenderer {
servletRenderer.setActionMapper(actionMapper);
}
@Inject
public void setUrlHelper(UrlHelper urlHelper) {
servletRenderer.setUrlHelper(urlHelper);
}
/**
* {@inheritDoc}
*/
public void renderUrl(Writer writer, UrlProvider urlComponent) {
if (PortletActionContext.getPortletContext() == null || "none".equalsIgnoreCase(urlComponent.getPortletUrlType())) {
if (PortletActionContext.getPortletContext() == null) {
servletRenderer.renderUrl(writer, urlComponent);
return;
}
String result;
urlComponent.setNamespace(urlComponent.determineNamespace(urlComponent.getNamespace(), urlComponent.getStack(), urlComponent.getHttpServletRequest()));
if (onlyActionSpecified(urlComponent)) {
result = portletUrlHelper.buildUrl(urlComponent.getAction(), urlComponent.getNamespace(), urlComponent.getMethod(),
urlComponent.getParameters(), urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
} else if (onlyValueSpecified(urlComponent)) {
result = portletUrlHelper.buildResourceUrl(urlComponent.getValue(), urlComponent.getParameters());
if (isPortletModeChange(urlComponent,PortletActionContext.getRequest().getPortletMode())
&& StringUtils.isEmpty(urlComponent.getNamespace()))
{
String mode = urlComponent.getPortletMode();
PortletMode portletMode = new PortletMode(mode);
String action = urlComponent.getAction();
if (StringUtils.isEmpty(action)) {
action = PortletActionContext.getModeActionMap().get(portletMode).getName();
}
String modeNamespace = PortletActionContext.getModeNamespaceMap().get(portletMode);
result = portletUrlHelper.buildUrl(action, modeNamespace, urlComponent.getMethod(),
urlComponent.getParameters(), urlComponent.getPortletUrlType(), mode, urlComponent.getWindowState());
} else {
result = createDefaultUrl(urlComponent);
String namespace = urlComponent.determineNamespace(urlComponent.getNamespace(), urlComponent.getStack(), urlComponent.getHttpServletRequest());
urlComponent.setNamespace(namespace);
if (onlyActionSpecified(urlComponent)) {
result = portletUrlHelper.buildUrl(urlComponent.getAction(), urlComponent.getNamespace(), urlComponent.getMethod(),
urlComponent.getParameters(), urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
} else if (onlyValueSpecified(urlComponent)) {
result = portletUrlHelper.buildResourceUrl(urlComponent.getValue(), urlComponent.getParameters());
} else {
result = createDefaultUrl(urlComponent);
}
}
final String anchor = urlComponent.getAnchor();
if (anchor != null && anchor.length() > 0) {
@@ -105,14 +123,19 @@ public class PortletUrlRenderer implements UrlRenderer {
}
}
boolean isPortletModeChange(UrlProvider urlComponent,PortletMode currentMode) {
if (StringUtils.isNotEmpty(urlComponent.getPortletMode())) {
PortletMode newPortletMode = new PortletMode(urlComponent.getPortletMode());
return !(newPortletMode.equals(currentMode));
}
return false;
}
private String createDefaultUrl(UrlProvider urlComponent) {
String result;
ActionInvocation ai = (ActionInvocation) urlComponent.getStack().getContext().get(
ActionContext.ACTION_INVOCATION);
ActionInvocation ai = (ActionInvocation) urlComponent.getStack().getContext().get(ActionContext.ACTION_INVOCATION);
String action = ai.getProxy().getActionName();
result = portletUrlHelper.buildUrl(action, urlComponent.getNamespace(), urlComponent.getMethod(), urlComponent.getParameters(),
return portletUrlHelper.buildUrl(action, urlComponent.getNamespace(), urlComponent.getMethod(), urlComponent.getParameters(),
urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
return result;
}
private boolean onlyValueSpecified(UrlProvider urlComponent) {
@@ -133,7 +156,7 @@ public class PortletUrlRenderer implements UrlRenderer {
}
String namespace = formComponent.determineNamespace(formComponent.namespace, formComponent.getStack(),
formComponent.request);
String action = null;
String action;
if (formComponent.action != null) {
action = formComponent.findString(formComponent.action);
} else {
@@ -1,140 +0,0 @@
/*
* $Id: PortletActionConstants.java 671156 2008-06-24 12:33:59Z nilsga $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.struts2.portlet;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.portlet.dispatcher.DispatcherServlet;
/**
* Interface defining some constants used in the Struts portlet implementation
*
*/
public interface PortletActionConstants {
/**
* Default action name to use when no default action has been configured in the portlet
* init parameters.
*/
String DEFAULT_ACTION_NAME = "default";
/**
* Action name parameter name
*/
String ACTION_PARAM = "struts.portlet.action";
/**
* Key for parameter holding the last executed portlet mode.
*/
String MODE_PARAM = "struts.portlet.mode";
/**
* Key used for looking up and storing the portlet phase
*/
String PHASE = "struts.portlet.phase";
/**
* Constant used for the render phase (
* {@link javax.portlet.Portlet#render(javax.portlet.RenderRequest, javax.portlet.RenderResponse)})
*/
Integer RENDER_PHASE = new Integer(1);
/**
* Constant used for the action phase (
* {@link javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)})
*/
Integer ACTION_PHASE = new Integer(2);
/**
* Key used for looking up and storing the
* {@link javax.portlet.PortletRequest}
*/
String REQUEST = "struts.portlet.request";
/**
* Key used for looking up and storing the
* {@link javax.portlet.PortletResponse}
*/
String RESPONSE = "struts.portlet.response";
/**
* Key used for looking up and storing the action that was invoked in the event phase.
*/
String EVENT_ACTION = "struts.portlet.eventAction";
/**
* Key used for looking up and storing the
* {@link javax.portlet.PortletConfig}
*/
String PORTLET_CONFIG = "struts.portlet.config";
/**
* Name of the action used as error handler
*/
String ERROR_ACTION = "errorHandler";
/**
* Key for the portlet namespace stored in the
* {@link org.apache.struts2.portlet.context.PortletActionContext}.
*/
String PORTLET_NAMESPACE = "struts.portlet.portletNamespace";
/**
* Key for the mode-to-namespace map stored in the
* {@link org.apache.struts2.portlet.context.PortletActionContext}.
*/
String MODE_NAMESPACE_MAP = "struts.portlet.modeNamespaceMap";
/**
* Key for the default action name for the portlet, stored in the
* {@link org.apache.struts2.portlet.context.PortletActionContext}.
*/
String DEFAULT_ACTION_FOR_MODE = "struts.portlet.defaultActionForMode";
/**
* Key for request attribute indicating if the action has been reset.
*/
String ACTION_RESET = "struts.portlet.actionReset";
/**
* Key for session attribute indicating the location of the render direct action.
*/
String RENDER_DIRECT_LOCATION = "struts.portlet.renderDirectLocation";
/**
* Key for the dispatch instruction for the {@link DispatcherServlet}
*/
String DISPATCH_TO = "struts.portlet.dispatchTo";
/**
* Session key where the value stack from the event phase is stored.
*/
String STACK_FROM_EVENT_PHASE = "struts.portlet.valueStackFromEventPhase";
/**
* Default name of dispatcher servlet in web.xml
*/
String DEFAULT_DISPATCHER_SERVLET_NAME = "Struts2PortletDispatcherServlet";
/**
* Key for the action mapping in the context
*/
String ACTION_MAPPING = ServletActionContext.ACTION_MAPPING;
}
@@ -20,6 +20,7 @@
*/
package org.apache.struts2.portlet;
import javax.portlet.PortletContext;
import java.io.Serializable;
import java.util.AbstractMap;
import java.util.Enumeration;
@@ -27,20 +28,18 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.portlet.PortletContext;
/**
* Portlet specific {@link java.util.Map} implementation representing the
* {@link javax.portlet.PortletContext} of a Portlet.
*
*/
public class PortletApplicationMap extends AbstractMap implements Serializable {
public class PortletApplicationMap extends AbstractMap<String, Object> implements Serializable {
private static final long serialVersionUID = 2296107511063504414L;
private PortletContext context;
private Set<Object> entries;
private Set<Entry<String, Object>> entries;
/**
* Creates a new map object given the {@link PortletContext}.
@@ -72,9 +71,9 @@ public class PortletApplicationMap extends AbstractMap implements Serializable {
* @return a Set of all portlet context attributes as well as context init
* parameters.
*/
public Set entrySet() {
public Set<Entry<String, Object>> entrySet() {
if (entries == null) {
entries = new HashSet<Object>();
entries = new HashSet<Entry<String, Object>>();
// Add portlet context attributes
Enumeration enumeration = context.getAttributeNames();
@@ -82,7 +81,7 @@ public class PortletApplicationMap extends AbstractMap implements Serializable {
while (enumeration.hasMoreElements()) {
final String key = enumeration.nextElement().toString();
final Object value = context.getAttribute(key);
entries.add(new Map.Entry() {
entries.add(new Entry<String, Object>() {
public boolean equals(Object obj) {
Map.Entry entry = (Map.Entry) obj;
@@ -97,7 +96,7 @@ public class PortletApplicationMap extends AbstractMap implements Serializable {
^ ((value == null) ? 0 : value.hashCode());
}
public Object getKey() {
public String getKey() {
return key;
}
@@ -106,7 +105,7 @@ public class PortletApplicationMap extends AbstractMap implements Serializable {
}
public Object setValue(Object obj) {
context.setAttribute(key.toString(), obj);
context.setAttribute(key, obj);
return value;
}
@@ -119,7 +118,7 @@ public class PortletApplicationMap extends AbstractMap implements Serializable {
while (enumeration.hasMoreElements()) {
final String key = enumeration.nextElement().toString();
final Object value = context.getInitParameter(key);
entries.add(new Map.Entry() {
entries.add(new Entry<String, Object>() {
public boolean equals(Object obj) {
Map.Entry entry = (Map.Entry) obj;
@@ -134,7 +133,7 @@ public class PortletApplicationMap extends AbstractMap implements Serializable {
^ ((value == null) ? 0 : value.hashCode());
}
public Object getKey() {
public String getKey() {
return key;
}
@@ -143,7 +142,7 @@ public class PortletApplicationMap extends AbstractMap implements Serializable {
}
public Object setValue(Object obj) {
context.setAttribute(key.toString(), obj);
context.setAttribute(key, obj);
return value;
}
@@ -163,13 +162,12 @@ public class PortletApplicationMap extends AbstractMap implements Serializable {
* @return the portlet context attribute or init parameter or <tt>null</tt>
* if the entry is not found.
*/
public Object get(Object key) {
public Object get(String key) {
// Try context attributes first, then init params
// This gives the proper shadowing effects
String keyString = key.toString();
Object value = context.getAttribute(keyString);
Object value = context.getAttribute(key);
return (value == null) ? context.getInitParameter(keyString) : value;
return (value == null) ? context.getInitParameter(key) : value;
}
/**
@@ -181,9 +179,9 @@ public class PortletApplicationMap extends AbstractMap implements Serializable {
* the value to set.
* @return the attribute that was just set.
*/
public Object put(Object key, Object value) {
public Object put(String key, Object value) {
entries = null;
context.setAttribute(key.toString(), value);
context.setAttribute(key, value);
return get(key);
}
@@ -195,11 +193,11 @@ public class PortletApplicationMap extends AbstractMap implements Serializable {
* the attribute to remove.
* @return the entry that was just removed.
*/
public Object remove(Object key) {
public Object remove(String key) {
entries = null;
Object value = get(key);
context.removeAttribute(key.toString());
context.removeAttribute(key);
return value;
}
@@ -1,5 +1,6 @@
package org.apache.struts2.portlet;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.portlet.dispatcher.DispatcherServlet;
public class PortletConstants {
@@ -24,28 +25,6 @@ public class PortletConstants {
*/
public static String PHASE = "struts.portlet.phase";
/**
* Constant used for the render phase (
* {@link javax.portlet.Portlet#render(javax.portlet.RenderRequest, javax.portlet.RenderResponse)})
*/
public static Integer RENDER_PHASE = new Integer(1);
/**
* Constant used for the action phase (
* {@link javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)})
*/
public static Integer ACTION_PHASE = new Integer(2);
/**
* Constant used for the event phase
*/
public static Integer EVENT_PHASE = new Integer(3);
/**
*
*/
public static Integer SERVE_RESOURCE_PHASE = new Integer(4);
/**
* Key used for looking up and storing the
* {@link javax.portlet.PortletRequest}
@@ -86,6 +65,12 @@ public class PortletConstants {
*/
public static String MODE_NAMESPACE_MAP = "struts.portlet.modeNamespaceMap";
/**
* Key for the mode-to-default-action map stored in the
* {@link org.apache.struts2.portlet.context.PortletActionContext}.
*/
public static String DEFAULT_ACTION_MAP = "struts.portlet.modeActionMap";
/**
* Key for the default action name for the portlet, stored in the
* {@link org.apache.struts2.portlet.context.PortletActionContext}.
@@ -101,7 +86,12 @@ public class PortletConstants {
* Key for session attribute indicating the location of the render direct action.
*/
public static String RENDER_DIRECT_LOCATION = "struts.portlet.renderDirectLocation";
/**
* Namespace use for executing the renderDirect action. Necessary to get the namespaces on s:urls correct.
*/
public static String RENDER_DIRECT_NAMESPACE = "struts.portlet.renderDirectNamespace";
/**
* Key for the dispatch instruction for the {@link DispatcherServlet}
*/
@@ -116,4 +106,10 @@ public class PortletConstants {
* Default name of dispatcher servlet in web.xml
*/
public static String DEFAULT_DISPATCHER_SERVLET_NAME = "Struts2PortletDispatcherServlet";
/**
* Key for the action mapping in the context
*/
public static String ACTION_MAPPING = ServletActionContext.ACTION_MAPPING;
}
@@ -0,0 +1,46 @@
package org.apache.struts2.portlet;
/**
* TODO lukaszlenart: add a comment
*/
public enum PortletPhase {
/**
* Constant used for the render phase (
* {@link javax.portlet.Portlet#render(javax.portlet.RenderRequest, javax.portlet.RenderResponse)})
*/
RENDER_PHASE,
/**
* Constant used for the action phase (
* {@link javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)})
*/
ACTION_PHASE,
/**
* Constant used for the event phase
*/
EVENT_PHASE,
/**
*
*/
SERVE_RESOURCE_PHASE;
public boolean isRender() {
return this.equals(RENDER_PHASE);
}
public boolean isAction() {
return this.equals(ACTION_PHASE);
}
public boolean isEvent() {
return this.equals(EVENT_PHASE);
}
public boolean isResource() {
return this.equals(SERVE_RESOURCE_PHASE);
}
}
@@ -20,25 +20,19 @@
*/
package org.apache.struts2.portlet;
import javax.portlet.PortletRequest;
import java.util.AbstractMap;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import javax.portlet.PortletRequest;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
/**
* A simple implementation of the {@link java.util.Map} interface to handle a collection of request attributes.
*
*/
public class PortletRequestMap extends AbstractMap {
public class PortletRequestMap extends AbstractMap<String, Object> {
private static final Logger LOG = LoggerFactory.getLogger(PortletRequestMap.class);
private Set<Object> entries = null;
private Set<Entry<String, Object>> entries = null;
private PortletRequest request = null;
/**
@@ -69,16 +63,16 @@ public class PortletRequestMap extends AbstractMap {
*
* @return a Set of attributes from the portlet request.
*/
public Set entrySet() {
public Set<Entry<String, Object>> entrySet() {
if (entries == null) {
entries = new HashSet<Object>();
entries = new HashSet<Entry<String, Object>>();
Enumeration enumeration = request.getAttributeNames();
Enumeration<String> enumeration = request.getAttributeNames();
while (enumeration.hasMoreElements()) {
final String key = enumeration.nextElement().toString();
final String key = enumeration.nextElement();
final Object value = request.getAttribute(key);
entries.add(new Entry() {
entries.add(new Entry<String, Object>() {
public boolean equals(Object obj) {
Entry entry = (Entry) obj;
@@ -93,7 +87,7 @@ public class PortletRequestMap extends AbstractMap {
^ ((value == null) ? 0 : value.hashCode());
}
public Object getKey() {
public String getKey() {
return key;
}
@@ -131,9 +125,9 @@ public class PortletRequestMap extends AbstractMap {
* @param value the value to set.
* @return the object that was just set.
*/
public Object put(Object key, Object value) {
public Object put(String key, Object value) {
entries = null;
request.setAttribute(key.toString(), value);
request.setAttribute(key, value);
return get(key);
}
@@ -20,30 +20,24 @@
*/
package org.apache.struts2.portlet;
import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;
import java.util.AbstractMap;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
/**
* A simple implementation of the {@link java.util.Map} interface to handle a collection of portlet session
* attributes. The {@link #entrySet()} method enumerates over all session attributes and creates a Set of entries.
* Note, this will occur lazily - only when the entry set is asked for.
*
*/
public class PortletSessionMap extends AbstractMap {
public class PortletSessionMap extends AbstractMap<String, Object> {
private static final Logger LOG = LoggerFactory.getLogger(PortletSessionMap.class);
private PortletSession session = null;
private Set<Object> entries = null;
private final PortletSession session;
private Set<Entry<String, Object>> entries = null;
/**
* Creates a new session map given a portlet request.
@@ -57,17 +51,17 @@ public class PortletSessionMap extends AbstractMap {
/**
* @see java.util.Map#entrySet()
*/
public Set entrySet() {
public Set<Entry<String, Object>> entrySet() {
synchronized (session) {
if (entries == null) {
entries = new HashSet<Object>();
entries = new HashSet<Entry<String, Object>>();
Enumeration enumeration = session.getAttributeNames();
while (enumeration.hasMoreElements()) {
final String key = enumeration.nextElement().toString();
final Object value = session.getAttribute(key);
entries.add(new Map.Entry() {
entries.add(new Entry<String, Object>() {
public boolean equals(Object obj) {
Map.Entry entry = (Map.Entry) obj;
@@ -82,7 +76,7 @@ public class PortletSessionMap extends AbstractMap {
^ ((value == null) ? 0 : value.hashCode());
}
public Object getKey() {
public String getKey() {
return key;
}
@@ -123,10 +117,10 @@ public class PortletSessionMap extends AbstractMap {
* @param value the value to set.
* @return the object that was just set.
*/
public Object put(Object key, Object value) {
public Object put(String key, Object value) {
synchronized (session) {
entries = null;
session.setAttribute(key.toString(), value);
session.setAttribute(key, value);
return get(key);
}
@@ -23,28 +23,27 @@ package org.apache.struts2.portlet.context;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.portlet.PortletConstants;
import org.apache.struts2.portlet.PortletPhase;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletMode;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import java.util.Map;
import static org.apache.struts2.portlet.PortletConstants.ACTION_PHASE;
import static org.apache.struts2.portlet.PortletConstants.DEFAULT_ACTION_FOR_MODE;
import static org.apache.struts2.portlet.PortletConstants.EVENT_PHASE;
import static org.apache.struts2.portlet.PortletConstants.MODE_NAMESPACE_MAP;
import static org.apache.struts2.portlet.PortletConstants.PHASE;
import static org.apache.struts2.portlet.PortletConstants.PORTLET_CONFIG;
import static org.apache.struts2.portlet.PortletConstants.PORTLET_NAMESPACE;
import static org.apache.struts2.portlet.PortletConstants.RENDER_PHASE;
import static org.apache.struts2.portlet.PortletConstants.REQUEST;
import static org.apache.struts2.portlet.PortletConstants.RESPONSE;
import static org.apache.struts2.portlet.PortletConstants.SERVE_RESOURCE_PHASE;
/**
@@ -70,9 +69,8 @@ public class PortletActionContext {
* @throws IllegalStateException If the method is invoked in the wrong phase.
*/
public static RenderRequest getRenderRequest() {
if (!isRender()) {
throw new IllegalStateException(
"RenderRequest cannot be obtained in event phase");
if (!getPhase().isRender()) {
throw new IllegalStateException("RenderRequest cannot be obtained in event phase");
}
return (RenderRequest) getContext().get(REQUEST);
}
@@ -84,9 +82,8 @@ public class PortletActionContext {
* @throws IllegalStateException If the method is invoked in the wrong phase.
*/
public static RenderResponse getRenderResponse() {
if (!isRender()) {
throw new IllegalStateException(
"RenderResponse cannot be obtained in event phase");
if (!getPhase().isRender()) {
throw new IllegalStateException("RenderResponse cannot be obtained in event phase");
}
return (RenderResponse) getContext().get(RESPONSE);
}
@@ -98,9 +95,8 @@ public class PortletActionContext {
* @throws IllegalStateException If the method is invoked in the wrong phase.
*/
public static ActionRequest getActionRequest() {
if (!isAction()) {
throw new IllegalStateException(
"ActionRequest cannot be obtained in render phase");
if (!getPhase().isAction()) {
throw new IllegalStateException("ActionRequest cannot be obtained in render phase");
}
return (ActionRequest) getContext().get(REQUEST);
}
@@ -112,9 +108,8 @@ public class PortletActionContext {
* @throws IllegalStateException If the method is invoked in the wrong phase.
*/
public static ActionResponse getActionResponse() {
if (!isAction()) {
throw new IllegalStateException(
"ActionResponse cannot be obtained in render phase");
if (!getPhase().isAction()) {
throw new IllegalStateException("ActionResponse cannot be obtained in render phase");
}
return (ActionResponse) getContext().get(RESPONSE);
}
@@ -150,32 +145,11 @@ public class PortletActionContext {
/**
* Get the phase that the portlet is executing in.
*
* @return {@link PortletActionConstants#RENDER_PHASE} in render phase, and
* {@link PortletActionConstants#ACTION_PHASE} in the event phase.
* @return {@link PortletPhase#RENDER_PHASE} in render phase, and
* {@link PortletPhase#ACTION_PHASE} in the event phase.
*/
public static Integer getPhase() {
return (Integer) getContext().get(PHASE);
}
/**
* @return <code>true</code> if the Portlet is executing in render phase.
*/
public static boolean isRender() {
return RENDER_PHASE.equals(getPhase());
}
/**
* @return <code>true</code> if the Portlet is executing in the event phase.
*/
public static boolean isAction() {
return ACTION_PHASE.equals(getPhase());
}
/**
* @return <code>true</code> if the Portlet is executing in the resource phase.
*/
public static boolean isResource() {
return SERVE_RESOURCE_PHASE.equals(getPhase());
public static PortletPhase getPhase() {
return (PortletPhase) getContext().get(PHASE);
}
/**
@@ -208,8 +182,19 @@ public class PortletActionContext {
*
* @return The map of the namespaces for each mode.
*/
public static Map getModeNamespaceMap() {
return (Map) getContext().get(MODE_NAMESPACE_MAP);
@SuppressWarnings("unchecked")
public static Map<PortletMode,String> getModeNamespaceMap() {
return (Map<PortletMode,String>) getContext().get(MODE_NAMESPACE_MAP);
}
/**
* Get the mode to default action mappings.
*
* @return The map of default action mapping for each mode
*/
@SuppressWarnings("unchecked")
public static Map<PortletMode,ActionMapping> getModeActionMap() {
return (Map<PortletMode,ActionMapping>) getContext().get(PortletConstants.DEFAULT_ACTION_MAP);
}
/**
@@ -221,10 +206,6 @@ public class PortletActionContext {
return (PortletContext) getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
}
public static boolean isEvent() {
return EVENT_PHASE.equals(getPhase());
}
/**
* Whether JSR286 features are supported.
*
@@ -21,13 +21,12 @@
package org.apache.struts2.portlet.dispatcher;
import com.opensymphony.xwork2.Action;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.portlet.PortletConstants;
import java.io.Serializable;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.portlet.PortletActionConstants;
/**
* When a portlet is targetted for an <code>event</code>, the portlet will receive two
* portlet requests, one for the <code>event</code> phase, and then followed by a <code>render</code>
@@ -42,7 +41,7 @@ import org.apache.struts2.portlet.PortletActionConstants;
* specifying this action and the location of the view, which then will be executed in the
* following render request.
*/
public class DirectRenderFromEventAction implements SessionAware, PortletActionConstants, Action, Serializable {
public class DirectRenderFromEventAction implements SessionAware, Action, Serializable {
private static final long serialVersionUID = -1814807772308405785L;
@@ -67,6 +66,6 @@ public class DirectRenderFromEventAction implements SessionAware, PortletActionC
}
public void setSession(Map session) {
location = (String)session.get(RENDER_DIRECT_LOCATION);
location = (String)session.get(PortletConstants.RENDER_DIRECT_LOCATION);
}
}
@@ -20,24 +20,23 @@
*/
package org.apache.struts2.portlet.dispatcher;
import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.dispatcher.StrutsRequestWrapper;
import org.apache.struts2.portlet.PortletConstants;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.dispatcher.StrutsRequestWrapper;
import org.apache.struts2.portlet.PortletActionConstants;
public class DispatcherServlet extends HttpServlet implements PortletActionConstants {
public class DispatcherServlet extends HttpServlet {
private static final long serialVersionUID = -266147033645951967L;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String dispatchTo = (String) request.getAttribute(DISPATCH_TO);
String dispatchTo = (String) request.getAttribute(PortletConstants.DISPATCH_TO);
HttpServletRequest wrapper = wrapRequestIfNecessary(request);
if(StringUtils.isNotEmpty(dispatchTo)) {
request.getRequestDispatcher(dispatchTo).include(wrapper, response);
@@ -24,9 +24,9 @@ package org.apache.struts2.portlet.dispatcher;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.util.FileManager;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
@@ -41,8 +41,9 @@ import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
import org.apache.struts2.portlet.PortletActionConstants;
import org.apache.struts2.portlet.PortletApplicationMap;
import org.apache.struts2.portlet.PortletConstants;
import org.apache.struts2.portlet.PortletPhase;
import org.apache.struts2.portlet.PortletRequestMap;
import org.apache.struts2.portlet.PortletSessionMap;
import org.apache.struts2.portlet.context.PortletActionContext;
@@ -72,16 +73,13 @@ import java.util.Locale;
import java.util.Map;
import static org.apache.struts2.portlet.PortletConstants.ACTION_PARAM;
import static org.apache.struts2.portlet.PortletConstants.ACTION_PHASE;
import static org.apache.struts2.portlet.PortletConstants.ACTION_RESET;
import static org.apache.struts2.portlet.PortletConstants.DEFAULT_ACTION_FOR_MODE;
import static org.apache.struts2.portlet.PortletConstants.DEFAULT_ACTION_NAME;
import static org.apache.struts2.portlet.PortletConstants.MODE_NAMESPACE_MAP;
import static org.apache.struts2.portlet.PortletConstants.MODE_PARAM;
import static org.apache.struts2.portlet.PortletConstants.PHASE;
import static org.apache.struts2.portlet.PortletConstants.PORTLET_CONFIG;
import static org.apache.struts2.portlet.PortletConstants.PORTLET_NAMESPACE;
import static org.apache.struts2.portlet.PortletConstants.RENDER_PHASE;
import static org.apache.struts2.portlet.PortletConstants.REQUEST;
import static org.apache.struts2.portlet.PortletConstants.RESPONSE;
@@ -179,18 +177,13 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
private static final Logger LOG = LoggerFactory.getLogger(Jsr168Dispatcher.class);
protected String portletNamespace = null;
private ActionProxyFactory factory = null;
private Map<PortletMode,String> modeMap = new HashMap<PortletMode,String>(3);
private Map<PortletMode,ActionMapping> actionMap = new HashMap<PortletMode,ActionMapping>(3);
String portletNamespace = null;
private Map<PortletMode, String> modeMap = new HashMap<PortletMode, String>(3);
private Map<PortletMode, ActionMapping> actionMap = new HashMap<PortletMode, ActionMapping>(3);
private Dispatcher dispatcherUtils;
private ActionMapper actionMapper;
private Container container;
/**
@@ -198,9 +191,11 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
*/
public void init(PortletConfig cfg) throws PortletException {
super.init(cfg);
if (LOG.isDebugEnabled()) LOG.debug("Initializing portlet " + getPortletName());
if (LOG.isDebugEnabled()) {
LOG.debug("Initializing portlet " + getPortletName());
}
Map<String,String> params = new HashMap<String,String>();
Map<String, String> params = new HashMap<String, String>();
for (Enumeration e = cfg.getInitParameterNames(); e.hasMoreElements(); ) {
String name = (String) e.nextElement();
String value = cfg.getInitParameter(name);
@@ -215,7 +210,9 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
factory = dispatcherUtils.getConfigurationManager().getConfiguration().getContainer().getInstance(ActionProxyFactory.class);
}
portletNamespace = cfg.getInitParameter("portletNamespace");
if (LOG.isDebugEnabled()) LOG.debug("PortletNamespace: " + portletNamespace);
if (LOG.isDebugEnabled()) {
LOG.debug("PortletNamespace: " + portletNamespace);
}
parseModeConfig(actionMap, cfg, PortletMode.VIEW, "viewNamespace",
"defaultViewAction");
parseModeConfig(actionMap, cfg, PortletMode.EDIT, "editNamespace",
@@ -235,13 +232,13 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
if (StringUtils.isEmpty(portletNamespace)) {
portletNamespace = "";
}
LocalizedTextUtil
.addDefaultResourceBundle("org/apache/struts2/struts-messages");
LocalizedTextUtil.addDefaultResourceBundle("org/apache/struts2/struts-messages");
container = dispatcherUtils.getContainer();
//check for configuration reloading
if ("true".equalsIgnoreCase(container.getInstance(String.class, StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD))) {
FileManager.setReloadingConfigs(true);
FileManager fileManager = container.getInstance(FileManager.class);
fileManager.setReloadingConfigs(true);
}
actionMapper = container.getInstance(ActionMapper.class);
@@ -258,24 +255,23 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
* execute for the mode is configured.
*/
void parseModeConfig(Map<PortletMode, ActionMapping> actionMap, PortletConfig portletConfig,
PortletMode portletMode, String nameSpaceParam,
String defaultActionParam) {
PortletMode portletMode, String nameSpaceParam,
String defaultActionParam) {
String namespace = portletConfig.getInitParameter(nameSpaceParam);
if (StringUtils.isEmpty(namespace)) {
namespace = "";
}
modeMap.put(portletMode, namespace);
String defaultAction = portletConfig
.getInitParameter(defaultActionParam);
String defaultAction = portletConfig.getInitParameter(defaultActionParam);
String method = null;
if (StringUtils.isEmpty(defaultAction)) {
defaultAction = DEFAULT_ACTION_NAME;
}
if(defaultAction.indexOf('!') >= 0) {
method = defaultAction.substring(defaultAction.indexOf('!') + 1);
defaultAction = defaultAction.substring(0, defaultAction.indexOf('!'));
if (defaultAction.indexOf('!') >= 0) {
method = defaultAction.substring(defaultAction.indexOf('!') + 1);
defaultAction = defaultAction.substring(0, defaultAction.indexOf('!'));
}
StringBuffer fullPath = new StringBuffer();
StringBuilder fullPath = new StringBuilder();
if (StringUtils.isNotEmpty(portletNamespace)) {
fullPath.append(portletNamespace);
}
@@ -288,8 +284,8 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
ActionMapping mapping = new ActionMapping();
mapping.setName(getActionName(fullPath.toString()));
mapping.setNamespace(getNamespace(fullPath.toString()));
if(method != null) {
mapping.setMethod(method);
if (method != null) {
mapping.setMethod(method);
}
actionMap.put(portletMode, mapping);
}
@@ -302,12 +298,14 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
*/
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {
if (LOG.isDebugEnabled()) LOG.debug("Entering processAction");
if (LOG.isDebugEnabled()) {
LOG.debug("Entering processAction in mode ", request.getPortletMode().toString());
}
resetActionContext();
try {
serviceAction(request, response, getRequestMap(request), getParameterMap(request),
getSessionMap(request), getApplicationMap(),
portletNamespace, ACTION_PHASE);
portletNamespace, PortletPhase.ACTION_PHASE);
if (LOG.isDebugEnabled()) LOG.debug("Leaving processAction");
} finally {
ActionContext.setContext(null);
@@ -323,19 +321,21 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
public void render(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
if (LOG.isDebugEnabled()) LOG.debug("Entering render");
if (LOG.isDebugEnabled()) {
LOG.debug("Entering render in mode ", request.getPortletMode().toString());
}
resetActionContext();
response.setTitle(getTitle(request));
if(!request.getWindowState().equals(WindowState.MINIMIZED)) {
try {
// Check to see if an event set the render to be included directly
serviceAction(request, response, getRequestMap(request), getParameterMap(request),
getSessionMap(request), getApplicationMap(),
portletNamespace, RENDER_PHASE);
if (LOG.isDebugEnabled()) LOG.debug("Leaving render");
} finally {
resetActionContext();
}
if (!request.getWindowState().equals(WindowState.MINIMIZED)) {
try {
// Check to see if an event set the render to be included directly
serviceAction(request, response, getRequestMap(request), getParameterMap(request),
getSessionMap(request), getApplicationMap(),
portletNamespace, PortletPhase.RENDER_PHASE);
if (LOG.isDebugEnabled()) LOG.debug("Leaving render");
} finally {
resetActionContext();
}
}
}
@@ -358,15 +358,17 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
* @param response the PortletResponse object.
* @param portletConfig the PortletConfig object.
* @param phase The portlet phase (render or action, see
* {@link PortletActionConstants})
* {@link PortletConstants})
* @return a HashMap representing the <tt>Action</tt> context.
*/
public HashMap<String, Object> createContextMap(Map<String, Object> requestMap, Map<String, String[]> parameterMap,
Map<String, Object> sessionMap, Map<String, Object> applicationMap, PortletRequest request,
PortletResponse response, HttpServletRequest servletRequest, HttpServletResponse servletResponse, ServletContext servletContext, PortletConfig portletConfig, Integer phase) throws IOException {
Map<String, Object> sessionMap, Map<String, Object> applicationMap,
PortletRequest request, PortletResponse response, HttpServletRequest servletRequest,
HttpServletResponse servletResponse, ServletContext servletContext,
PortletConfig portletConfig, PortletPhase phase) throws IOException {
// TODO Must put http request/response objects into map for use with
container.inject(servletRequest);
container.inject(servletRequest);
// ServletActionContext
HashMap<String, Object> extraContext = new HashMap<String, Object>();
@@ -380,7 +382,7 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
extraContext.put(ActionContext.APPLICATION, applicationMap);
String defaultLocale = dispatcherUtils.getContainer().getInstance(String.class, StrutsConstants.STRUTS_LOCALE);
Locale locale = null;
Locale locale;
if (defaultLocale != null) {
locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
} else {
@@ -400,8 +402,9 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
extraContext.put("application", applicationMap);
extraContext.put("parameters", parameterMap);
extraContext.put(MODE_NAMESPACE_MAP, modeMap);
extraContext.put(PortletConstants.DEFAULT_ACTION_MAP, actionMap);
extraContext.put(PHASE, phase);
extraContext.put(PortletConstants.PHASE, phase);
AttributeMap attrMap = new AttributeMap(extraContext);
extraContext.put("attr", attrMap);
@@ -422,50 +425,55 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
* @param sessionMap a Map of all session attributes.
* @param applicationMap a Map of all application attributes.
* @param portletNamespace the namespace or context of the action.
* @param phase The portlet phase (render or action, see
* {@link PortletActionConstants})
* @param phase The portlet phase (render or action, see {@link PortletConstants})
*/
public void serviceAction(PortletRequest request, PortletResponse response, Map<String, Object> requestMap, Map<String, String[]> parameterMap,
Map<String, Object> sessionMap, Map<String, Object> applicationMap, String portletNamespace,
Integer phase) throws PortletException {
Map<String, Object> sessionMap, Map<String, Object> applicationMap, String portletNamespace,
PortletPhase phase) throws PortletException {
if (LOG.isDebugEnabled()) LOG.debug("serviceAction");
Dispatcher.setInstance(dispatcherUtils);
String actionName = null;
String namespace = null;
String namespace;
try {
ServletContext servletContext = new PortletServletContext(getPortletContext());
HttpServletRequest servletRequest = new PortletServletRequest(request, getPortletContext());
HttpServletResponse servletResponse = createPortletServletResponse(response);
if(ACTION_PHASE.equals(phase)) {
servletRequest = dispatcherUtils.wrapRequest(servletRequest, servletContext);
if(servletRequest instanceof MultiPartRequestWrapper) {
// Multipart request. Request parameters are encoded in the multipart data,
// so we need to manually add them to the parameter map.
parameterMap.putAll(servletRequest.getParameterMap());
}
}
if (phase.isAction()) {
servletRequest = dispatcherUtils.wrapRequest(servletRequest, servletContext);
if (servletRequest instanceof MultiPartRequestWrapper) {
// Multipart request. Request parameters are encoded in the multipart data,
// so we need to manually add them to the parameter map.
parameterMap.putAll(servletRequest.getParameterMap());
}
}
container.inject(servletRequest);
ActionMapping mapping = getActionMapping(request, servletRequest);
actionName = mapping.getName();
namespace = mapping.getNamespace();
if ("renderDirect".equals(actionName)) {
namespace = request.getParameter(PortletConstants.RENDER_DIRECT_NAMESPACE);
} else {
namespace = mapping.getNamespace();
}
HashMap<String, Object> extraContext = createContextMap(requestMap, parameterMap,
sessionMap, applicationMap, request, response, servletRequest, servletResponse,
servletContext, getPortletConfig(), phase);
extraContext.put(PortletActionConstants.ACTION_MAPPING, mapping);
LOG.debug("Creating action proxy for name = " + actionName
+ ", namespace = " + namespace);
ActionProxy proxy = factory.createActionProxy(namespace,
actionName, mapping.getMethod(), extraContext);
request.setAttribute("struts.valueStack", proxy.getInvocation()
.getStack());
extraContext.put(PortletConstants.ACTION_MAPPING, mapping);
if (LOG.isDebugEnabled()) {
LOG.debug("Creating action proxy for name = " + actionName + ", namespace = " + namespace);
}
ActionProxy proxy = factory.createActionProxy(namespace, actionName, mapping.getMethod(), extraContext);
request.setAttribute("struts.valueStack", proxy.getInvocation().getStack());
proxy.execute();
} catch (ConfigurationException e) {
LOG.error("Could not find action", e);
if (LOG.isErrorEnabled()) {
LOG.error("Could not find action", e);
}
throw new PortletException("Could not find action " + actionName, e);
} catch (Exception e) {
LOG.error("Could not execute action", e);
throw new PortletException("Error executing action " + actionName,
e);
if (LOG.isErrorEnabled()) {
LOG.error("Could not execute action", e);
}
throw new PortletException("Error executing action " + actionName, e);
} finally {
Dispatcher.setInstance(null);
}
@@ -477,7 +485,7 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
*
* @return a Map of all application attributes.
*/
protected Map getApplicationMap() {
protected Map<String, Object> getApplicationMap() {
return new PortletApplicationMap(getPortletContext());
}
@@ -493,15 +501,14 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
* @return the namespace of the action.
*/
protected ActionMapping getActionMapping(final PortletRequest portletRequest, final HttpServletRequest servletRequest) {
ActionMapping mapping = null;
ActionMapping mapping;
String actionPath = getDefaultActionPath(portletRequest);
if (resetAction(portletRequest)) {
mapping = (ActionMapping) actionMap.get(portletRequest.getPortletMode());
mapping = actionMap.get(portletRequest.getPortletMode());
} else {
actionPath = servletRequest.getParameter(ACTION_PARAM);
if (StringUtils.isEmpty(actionPath)) {
mapping = (ActionMapping) actionMap.get(portletRequest
.getPortletMode());
mapping = actionMap.get(portletRequest.getPortletMode());
} else {
// Use the usual action mapper, but it is expecting an action extension
@@ -512,13 +519,12 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
}
if (mapping == null) {
throw new StrutsException("Unable to locate action mapping for request, probably due to " +
"an invalid action path: "+actionPath);
throw new StrutsException("Unable to locate action mapping for request, probably due to an invalid action path: " + actionPath);
}
return mapping;
}
protected String getDefaultActionPath( PortletRequest portletRequest ) {
protected String getDefaultActionPath(PortletRequest portletRequest) {
return null;
}
@@ -571,7 +577,7 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
* @param request the PortletRequest object.
* @return a Map of all request attributes.
*/
protected Map getRequestMap(PortletRequest request) {
protected Map<String, Object> getRequestMap(PortletRequest request) {
return new PortletRequestMap(request);
}
@@ -583,7 +589,7 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
* @param request the PortletRequest object.
* @return a Map of all session attributes.
*/
protected Map getSessionMap(PortletRequest request) {
protected Map<String, Object> getSessionMap(PortletRequest request) {
return new PortletSessionMap(request);
}
@@ -614,20 +620,21 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
reset = true;
}
}
if(reset) {
request.setAttribute(ACTION_RESET, Boolean.TRUE);
}
else {
request.setAttribute(ACTION_RESET, Boolean.FALSE);
if (reset) {
request.setAttribute(ACTION_RESET, Boolean.TRUE);
} else {
request.setAttribute(ACTION_RESET, Boolean.FALSE);
}
return reset;
}
public void destroy() {
if (dispatcherUtils == null) {
LOG.warn("something is seriously wrong, DispatcherUtil is not initialized (null) ");
} else {
if (dispatcherUtils != null) {
dispatcherUtils.cleanup();
} else {
if (LOG.isWarnEnabled()) {
LOG.warn("Something is seriously wrong, DispatcherUtil is not initialized (null) ");
}
}
}
@@ -3,55 +3,61 @@ package org.apache.struts2.portlet.dispatcher;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.struts2.portlet.PortletPhase;
import org.apache.struts2.portlet.servlet.PortletServletResponse;
import org.apache.struts2.portlet.servlet.PortletServletResponseJSR286;
import javax.portlet.*;
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import java.io.IOException;
import static org.apache.struts2.portlet.PortletConstants.EVENT_PHASE;
import static org.apache.struts2.portlet.PortletConstants.SERVE_RESOURCE_PHASE;
public class Jsr286Dispatcher extends Jsr168Dispatcher {
private final static Logger LOG = LoggerFactory.getLogger(Jsr286Dispatcher.class);
private final static Logger LOG = LoggerFactory.getLogger(Jsr286Dispatcher.class);
@Override
public void processEvent( EventRequest request, EventResponse response)
throws PortletException, IOException {
if (LOG.isDebugEnabled()) LOG.debug("Entering processEvent");
resetActionContext();
try {
// We'll use the event name as the "action"
serviceAction(request, response,
getRequestMap(request), getParameterMap(request),
getSessionMap(request), getApplicationMap(),
portletNamespace, EVENT_PHASE);
if (LOG.isDebugEnabled()) LOG.debug("Leaving processEvent");
} finally {
ActionContext.setContext(null);
}
}
@Override
public void serveResource( ResourceRequest request, ResourceResponse response)
throws PortletException, IOException {
if (LOG.isDebugEnabled()) LOG.debug("Entering serveResource");
resetActionContext();
try {
serviceAction(request, response,
getRequestMap(request), getParameterMap(request),
getSessionMap(request), getApplicationMap(),
portletNamespace, SERVE_RESOURCE_PHASE);
}
finally {
ActionContext.setContext(null);
}
}
@Override
protected String getDefaultActionPath( PortletRequest portletRequest ) {
public void processEvent(EventRequest request, EventResponse response) throws PortletException, IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("Entering processEvent");
}
resetActionContext();
try {
// We'll use the event name as the "action"
serviceAction(request, response,
getRequestMap(request), getParameterMap(request),
getSessionMap(request), getApplicationMap(),
portletNamespace, PortletPhase.EVENT_PHASE);
if (LOG.isDebugEnabled()) LOG.debug("Leaving processEvent");
} finally {
ActionContext.setContext(null);
}
}
@Override
public void serveResource(ResourceRequest request, ResourceResponse response)
throws PortletException, IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("Entering serveResource");
}
resetActionContext();
try {
serviceAction(request, response,
getRequestMap(request), getParameterMap(request),
getSessionMap(request), getApplicationMap(),
portletNamespace, PortletPhase.SERVE_RESOURCE_PHASE);
} finally {
ActionContext.setContext(null);
}
}
@Override
protected String getDefaultActionPath(PortletRequest portletRequest) {
if (portletRequest instanceof EventRequest) {
return ((EventRequest) portletRequest).getEvent().getName();
}
@@ -59,7 +65,8 @@ public class Jsr286Dispatcher extends Jsr168Dispatcher {
}
@Override
protected PortletServletResponse createPortletServletResponse( PortletResponse response ) {
protected PortletServletResponse createPortletServletResponse(PortletResponse response) {
return new PortletServletResponseJSR286(response);
}
}
@@ -20,21 +20,20 @@
*/
package org.apache.struts2.portlet.interceptor;
import javax.portlet.PortletContext;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.interceptor.PrincipalAware;
import org.apache.struts2.portlet.PortletActionConstants;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.interceptor.PrincipalAware;
import org.apache.struts2.portlet.PortletConstants;
public class PortletAwareInterceptor extends AbstractInterceptor implements PortletActionConstants, StrutsStatics {
import javax.portlet.PortletContext;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
public class PortletAwareInterceptor extends AbstractInterceptor implements StrutsStatics {
private static final long serialVersionUID = 2476509721059587700L;
@@ -52,24 +51,24 @@ public class PortletAwareInterceptor extends AbstractInterceptor implements Port
final ActionContext context = invocation.getInvocationContext();
if (action instanceof PortletRequestAware) {
PortletRequest request = (PortletRequest) context.get(REQUEST);
PortletRequest request = (PortletRequest) context.get(PortletConstants.REQUEST);
((PortletRequestAware) action).setPortletRequest(request);
}
if (action instanceof PortletResponseAware) {
PortletResponse response = (PortletResponse) context.get(RESPONSE);
PortletResponse response = (PortletResponse) context.get(PortletConstants.RESPONSE);
((PortletResponseAware) action).setPortletResponse(response);
}
if (action instanceof PrincipalAware) {
PortletRequest request = (PortletRequest) context.get(REQUEST);
PortletRequest request = (PortletRequest) context.get(PortletConstants.REQUEST);
((PrincipalAware) action).setPrincipalProxy(new PortletPrincipalProxy(request));
}
if (action instanceof PortletContextAware) {
PortletContext portletContext = (PortletContext) context.get(STRUTS_PORTLET_CONTEXT);
PortletContext portletContext = (PortletContext) context.get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
((PortletContextAware) action).setPortletContext(portletContext);
}
if (action instanceof PortletPreferencesAware) {
PortletRequest request = (PortletRequest) context.get(REQUEST);
PortletRequest request = (PortletRequest) context.get(PortletConstants.REQUEST);
// Check if running in a servlet environment
if (request == null) {
@@ -20,28 +20,25 @@
*/
package org.apache.struts2.portlet.interceptor;
import static org.apache.struts2.portlet.PortletConstants.ACTION_PHASE;
import static org.apache.struts2.portlet.PortletConstants.EVENT_ACTION;
import static org.apache.struts2.portlet.PortletConstants.PHASE;
import static org.apache.struts2.portlet.PortletConstants.RENDER_PHASE;
import static org.apache.struts2.portlet.PortletConstants.REQUEST;
import static org.apache.struts2.portlet.PortletConstants.RESPONSE;
import static org.apache.struts2.portlet.PortletConstants.STACK_FROM_EVENT_PHASE;
import java.util.Map;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.CompoundRoot;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.portlet.PortletConstants;
import org.apache.struts2.portlet.PortletPhase;
import org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
import java.util.Map;
import static org.apache.struts2.portlet.PortletConstants.EVENT_ACTION;
import static org.apache.struts2.portlet.PortletConstants.REQUEST;
import static org.apache.struts2.portlet.PortletConstants.RESPONSE;
import static org.apache.struts2.portlet.PortletConstants.STACK_FROM_EVENT_PHASE;
public class PortletStateInterceptor extends AbstractInterceptor {
@@ -51,11 +48,11 @@ public class PortletStateInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
Integer phase = (Integer) invocation.getInvocationContext().get(PHASE);
if (RENDER_PHASE.equals(phase)) {
PortletPhase phase = (PortletPhase) invocation.getInvocationContext().get(PortletConstants.PHASE);
if (phase.isRender()) {
restoreStack(invocation);
return invocation.invoke();
} else if (ACTION_PHASE.equals(phase)) {
} else if (phase.isAction()) {
try {
return invocation.invoke();
} finally {
@@ -20,25 +20,21 @@
*/
package org.apache.struts2.portlet.result;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.portlet.PortletMode;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.dispatcher.ServletActionRedirectResult;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.portlet.PortletActionConstants;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.inject.Inject;
import org.apache.struts2.dispatcher.ServletActionRedirectResult;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.portlet.PortletConstants;
import org.apache.struts2.views.util.UrlHelper;
import javax.portlet.PortletMode;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
*
* Portlet modification of the {@link ServletActionRedirectResult}.
@@ -178,7 +174,7 @@ public class PortletActionRedirectResult extends PortletResult {
*/
public void execute(ActionInvocation invocation) throws Exception {
actionName = conditionalParse(actionName, invocation);
String portletNamespace = (String)invocation.getInvocationContext().get(PortletActionConstants.PORTLET_NAMESPACE);
String portletNamespace = (String)invocation.getInvocationContext().get(PortletConstants.PORTLET_NAMESPACE);
if (portletMode != null) {
Map<PortletMode, String> namespaceMap = getNamespaceMap(invocation);
namespace = namespaceMap.get(portletMode);
@@ -216,7 +212,7 @@ public class PortletActionRedirectResult extends PortletResult {
@SuppressWarnings("unchecked")
private Map<PortletMode, String> getNamespaceMap(ActionInvocation invocation) {
return (Map<PortletMode, String>) invocation.getInvocationContext().get(PortletActionConstants.MODE_NAMESPACE_MAP);
return (Map<PortletMode, String>) invocation.getInvocationContext().get(PortletConstants.MODE_NAMESPACE_MAP);
}
/**
@@ -20,9 +20,16 @@
*/
package org.apache.struts2.portlet.result;
import java.io.IOException;
import java.util.Map;
import java.util.StringTokenizer;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.StrutsResultSupport;
import org.apache.struts2.portlet.PortletConstants;
import org.apache.struts2.portlet.PortletPhase;
import org.apache.struts2.portlet.context.PortletActionContext;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
@@ -35,29 +42,21 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.StrutsResultSupport;
import org.apache.struts2.portlet.PortletActionConstants;
import org.apache.struts2.portlet.context.PortletActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import java.io.IOException;
import java.util.Map;
import java.util.StringTokenizer;
/**
* Result type that includes a JSP to render.
*
*/
public class PortletResult extends StrutsResultSupport implements PortletActionConstants {
public class PortletResult extends StrutsResultSupport {
private static final long serialVersionUID = 434251393926178567L;
private boolean useDispatcherServlet;
private String dispatcherServletName = DEFAULT_DISPATCHER_SERVLET_NAME;
private String dispatcherServletName = PortletConstants.DEFAULT_DISPATCHER_SERVLET_NAME;
/**
* Logger instance.
@@ -99,9 +98,10 @@ public class PortletResult extends StrutsResultSupport implements PortletActionC
*/
public void doExecute(String finalLocation, ActionInvocation actionInvocation) throws Exception {
if (PortletActionContext.isRender() || PortletActionContext.isResource()) {
PortletPhase phase = PortletActionContext.getPhase();
if (phase.isRender() || phase.isResource()) {
executeMimeResult(finalLocation);
} else if (PortletActionContext.isAction() || PortletActionContext.isEvent()) {
} else if (phase.isAction() || phase.isEvent()) {
executeActionResult(finalLocation, actionInvocation);
} else {
executeRegularServletResult(finalLocation, actionInvocation);
@@ -110,9 +110,6 @@ public class PortletResult extends StrutsResultSupport implements PortletActionC
/**
* Executes the regular servlet result.
*
* @param finalLocation
* @param actionInvocation
*/
private void executeRegularServletResult(String finalLocation, ActionInvocation actionInvocation)
throws ServletException, IOException {
@@ -137,30 +134,36 @@ public class PortletResult extends StrutsResultSupport implements PortletActionC
* @param invocation
*/
protected void executeActionResult(String finalLocation, ActionInvocation invocation) throws Exception {
String phase = (PortletActionContext.isEvent()) ? "Event" : "Action";
if (LOG.isDebugEnabled()) LOG.debug("Executing result in "+phase+" phase");
Map sessionMap = invocation.getInvocationContext().getSession();
if (LOG.isDebugEnabled()) LOG.debug("Setting event render parameter: " + finalLocation);
if (finalLocation.indexOf('?') != -1) {
convertQueryParamsToRenderParams(finalLocation.substring(finalLocation.indexOf('?') + 1));
finalLocation = finalLocation.substring(0, finalLocation.indexOf('?'));
String location = finalLocation;
String namespace = invocation.getProxy().getNamespace();
if (LOG.isDebugEnabled()) {
String phase = (PortletActionContext.getPhase().isEvent()) ? "Event" : "Action";
LOG.debug("Executing result in "+phase+" phase");
LOG.debug("Setting event render parameter location : " + location);
LOG.debug("Setting event render parameter namespace: " + namespace);
}
Map<String, Object> sessionMap = invocation.getInvocationContext().getSession();
if (location.indexOf('?') != -1) {
convertQueryParamsToRenderParams(location.substring(location.indexOf('?') + 1));
location = location.substring(0, location.indexOf('?'));
}
PortletResponse response = PortletActionContext.getResponse();
if (finalLocation.endsWith(".action")) {
if (location.endsWith(".action")) {
// View is rendered with a view action...luckily...
finalLocation = finalLocation.substring(0, finalLocation.lastIndexOf("."));
resultHelper.setRenderParameter(response, ACTION_PARAM, finalLocation);
location = location.substring(0, location.lastIndexOf("."));
resultHelper.setRenderParameter(response, PortletConstants.ACTION_PARAM, location);
} else {
// View is rendered outside an action...uh oh...
resultHelper.setRenderParameter(response, ACTION_PARAM, "renderDirect");
sessionMap.put(RENDER_DIRECT_LOCATION, finalLocation);
resultHelper.setRenderParameter(response, PortletConstants.ACTION_PARAM, "renderDirect");
sessionMap.put(PortletConstants.RENDER_DIRECT_LOCATION, location);
}
resultHelper.setRenderParameter(response, PortletConstants.RENDER_DIRECT_NAMESPACE, namespace);
if(portletMode != null) {
resultHelper.setPortletMode(response, portletMode);
resultHelper.setRenderParameter(response, PortletActionConstants.MODE_PARAM, portletMode.toString());
resultHelper.setRenderParameter(response, PortletConstants.MODE_PARAM, portletMode.toString());
}
else {
resultHelper.setRenderParameter(response, PortletActionConstants.MODE_PARAM, PortletActionContext.getRequest().getPortletMode()
resultHelper.setRenderParameter(response, PortletConstants.MODE_PARAM, PortletActionContext.getRequest().getPortletMode()
.toString());
}
}
@@ -168,7 +171,6 @@ public class PortletResult extends StrutsResultSupport implements PortletActionC
/**
* Converts the query params to render params.
*
* @param response
* @param queryParams
*/
protected void convertQueryParamsToRenderParams(String queryParams) {
@@ -200,7 +202,7 @@ public class PortletResult extends StrutsResultSupport implements PortletActionC
if (LOG.isDebugEnabled()) LOG.debug("Location: " + finalLocation);
PortletRequestDispatcher dispatcher;
if (useDispatcherServlet) {
req.setAttribute(DISPATCH_TO, finalLocation);
req.setAttribute(PortletConstants.DISPATCH_TO, finalLocation);
dispatcher = ctx.getNamedDispatcher(dispatcherServletName);
if(dispatcher == null) {
throw new PortletException("Could not locate dispatcher servlet \"" + dispatcherServletName + "\". Please configure it in your web.xml file");
@@ -20,8 +20,23 @@
*/
package org.apache.struts2.portlet.result;
import java.io.OutputStreamWriter;
import java.io.Writer;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.dispatcher.StrutsResultSupport;
import org.apache.struts2.portlet.PortletConstants;
import org.apache.struts2.portlet.PortletPhase;
import org.apache.struts2.portlet.context.PortletActionContext;
import org.apache.struts2.views.JspSupportServlet;
import org.apache.struts2.views.velocity.VelocityManager;
import org.apache.velocity.Template;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;
import javax.portlet.ActionResponse;
import javax.servlet.Servlet;
@@ -30,24 +45,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.PageContext;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.dispatcher.StrutsResultSupport;
import org.apache.struts2.portlet.PortletActionConstants;
import org.apache.struts2.portlet.context.PortletActionContext;
import org.apache.struts2.views.JspSupportServlet;
import org.apache.struts2.views.velocity.VelocityManager;
import org.apache.velocity.Template;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import java.io.OutputStreamWriter;
import java.io.Writer;
/**
* <!-- START SNIPPET: description -->
@@ -118,11 +117,11 @@ public class PortletVelocityResult extends StrutsResultSupport {
/* (non-Javadoc)
* @see org.apache.struts2.dispatcher.StrutsResultSupport#doExecute(java.lang.String, com.opensymphony.xwork2.ActionInvocation)
*/
public void doExecute(String location, ActionInvocation invocation)
throws Exception {
if (PortletActionContext.isAction()) {
public void doExecute(String location, ActionInvocation invocation) throws Exception {
PortletPhase phase = PortletActionContext.getPhase();
if (phase.isAction()) {
executeActionResult(location, invocation);
} else if (PortletActionContext.isRender()) {
} else if (phase.isRender()) {
executeRenderResult(location, invocation);
}
}
@@ -133,16 +132,12 @@ public class PortletVelocityResult extends StrutsResultSupport {
* @param location The location string
* @param invocation The action invocation
*/
private void executeActionResult(String location,
ActionInvocation invocation) {
private void executeActionResult(String location, ActionInvocation invocation) {
ActionResponse res = PortletActionContext.getActionResponse();
// View is rendered outside an action...uh oh...
res.setRenderParameter(PortletActionConstants.ACTION_PARAM,
"freemarkerDirect");
res.setRenderParameter(PortletConstants.ACTION_PARAM, "freemarkerDirect");
res.setRenderParameter("location", location);
res.setRenderParameter(PortletActionConstants.MODE_PARAM, PortletActionContext
.getRequest().getPortletMode().toString());
res.setRenderParameter(PortletConstants.MODE_PARAM, PortletActionContext.getRequest().getPortletMode().toString());
}
/**
@@ -155,27 +150,22 @@ public class PortletVelocityResult extends StrutsResultSupport {
* loading or executing the template or writing output to the
* servlet response stream.
*/
public void executeRenderResult(String finalLocation,
ActionInvocation invocation) throws Exception {
public void executeRenderResult(String finalLocation, ActionInvocation invocation) throws Exception {
ValueStack stack = ActionContext.getContext().getValueStack();
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
ServletContext servletContext = ServletActionContext
.getServletContext();
ServletContext servletContext = ServletActionContext.getServletContext();
Servlet servlet = JspSupportServlet.jspSupportServlet;
velocityManager.init(servletContext);
boolean usedJspFactory = false;
PageContext pageContext = (PageContext) ActionContext.getContext().get(
ServletActionContext.PAGE_CONTEXT);
PageContext pageContext = (PageContext) ActionContext.getContext().get(ServletActionContext.PAGE_CONTEXT);
if (pageContext == null && servlet != null) {
pageContext = jspFactory.getPageContext(servlet, request, response,
null, true, 8192, true);
ActionContext.getContext().put(ServletActionContext.PAGE_CONTEXT,
pageContext);
pageContext = jspFactory.getPageContext(servlet, request, response, null, true, 8192, true);
ActionContext.getContext().put(ServletActionContext.PAGE_CONTEXT, pageContext);
usedJspFactory = true;
}
@@ -187,14 +177,10 @@ public class PortletVelocityResult extends StrutsResultSupport {
contentType = contentType + ";charset=" + encoding;
}
response.setContentType(contentType);
Template t = getTemplate(stack,
velocityManager.getVelocityEngine(), invocation,
finalLocation, encoding);
Template t = getTemplate(stack, velocityManager.getVelocityEngine(), invocation, finalLocation, encoding);
Context context = createContext(velocityManager, stack, request,
response, finalLocation);
Writer writer = new OutputStreamWriter(response.getOutputStream(),
encoding);
Context context = createContext(velocityManager, stack, request, response, finalLocation);
Writer writer = new OutputStreamWriter(response.getOutputStream(), encoding);
t.merge(context, writer);
@@ -204,16 +190,13 @@ public class PortletVelocityResult extends StrutsResultSupport {
// deprecated, we'll oblige :)
writer.flush();
} catch (Exception e) {
LOG.error("Unable to render Velocity Template, '" + finalLocation
+ "'", e);
LOG.error("Unable to render Velocity Template, '" + finalLocation + "'", e);
throw e;
} finally {
if (usedJspFactory) {
jspFactory.releasePageContext(pageContext);
}
}
return;
}
/**
@@ -259,16 +242,12 @@ public class PortletVelocityResult extends StrutsResultSupport {
* @return the template to render
* @throws Exception when the requested template could not be found
*/
protected Template getTemplate(ValueStack stack,
VelocityEngine velocity, ActionInvocation invocation,
String location, String encoding) throws Exception {
protected Template getTemplate(ValueStack stack, VelocityEngine velocity, ActionInvocation invocation,
String location, String encoding) throws Exception {
if (!location.startsWith("/")) {
location = invocation.getProxy().getNamespace() + "/" + location;
}
Template template = velocity.getTemplate(location, encoding);
return template;
return velocity.getTemplate(location, encoding);
}
/**
@@ -280,8 +259,7 @@ public class PortletVelocityResult extends StrutsResultSupport {
* @param location the name of the template that is being used
* @return the a minted Velocity context.
*/
protected Context createContext(VelocityManager velocityManager,
ValueStack stack, HttpServletRequest request,
protected Context createContext(VelocityManager velocityManager, ValueStack stack, HttpServletRequest request,
HttpServletResponse response, String location) {
return velocityManager.createContext(stack, request, response);
}
@@ -88,11 +88,11 @@ public class PortletUrlHelper {
public String buildUrl(String action, String namespace, String method, Map<String, Object> params,
String scheme, String type, String portletMode, String windowState,
boolean includeContext, boolean encodeResult) {
StringBuffer resultingAction = new StringBuffer();
StringBuilder resultingAction = new StringBuilder();
PortletRequest request = PortletActionContext.getRequest();
LOG.debug("Creating url. Action = " + action + ", Namespace = "
+ namespace + ", Type = " + type);
namespace = prependNamespace(namespace, portletMode, !URLTYPE_NAME_RESOURCE.equalsIgnoreCase(type));
namespace = prependNamespace(namespace, portletMode, false);
if (StringUtils.isEmpty(portletMode)) {
portletMode = PortletActionContext.getRequest().getPortletMode().toString();
}
@@ -137,7 +137,7 @@ public class PortletUrlHelper {
String result = url.toString();
// TEMP BUG-WORKAROUND FOR DOUBLE ESCAPING OF AMPERSAND
if(result.indexOf("&amp;") >= 0) {
if(result.contains("&amp;")) {
result = result.replace("&amp;", "&");
}
return result;
@@ -179,14 +179,14 @@ public class PortletUrlHelper {
* @return prepended namespace.
*/
private String prependNamespace(String namespace, String portletMode, boolean prependModeNamespace) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
String modeNamespace;
if (prependModeNamespace) {
PortletMode mode = PortletActionContext.getRequest().getPortletMode();
if(StringUtils.isNotEmpty(portletMode)) {
mode = new PortletMode(portletMode);
}
modeNamespace = (String)PortletActionContext.getModeNamespaceMap().get(mode);
modeNamespace = PortletActionContext.getModeNamespaceMap().get(mode);
} else {
modeNamespace = null;
}
@@ -20,37 +20,34 @@
*/
package org.apache.struts2.views.freemarker;
import java.io.IOException;
import java.io.Writer;
import java.util.Locale;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.StrutsResultSupport;
import org.apache.struts2.portlet.PortletActionConstants;
import org.apache.struts2.portlet.context.PortletActionContext;
import org.apache.struts2.views.util.ResourceUtil;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.ValueStack;
import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.StrutsResultSupport;
import org.apache.struts2.portlet.PortletConstants;
import org.apache.struts2.portlet.PortletPhase;
import org.apache.struts2.portlet.context.PortletActionContext;
import org.apache.struts2.views.util.ResourceUtil;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
import java.util.Locale;
/**
*/
public class PortletFreemarkerResult extends StrutsResultSupport implements PortletActionConstants {
public class PortletFreemarkerResult extends StrutsResultSupport {
private static final long serialVersionUID = -5570612389289887543L;
@@ -104,39 +101,26 @@ public class PortletFreemarkerResult extends StrutsResultSupport implements Port
*/
public void doExecute(String location, ActionInvocation invocation)
throws IOException, TemplateException, PortletException {
if (PortletActionContext.isAction()) {
PortletPhase phase = PortletActionContext.getPhase();
if (phase.isAction()) {
executeActionResult(location, invocation);
} else if (PortletActionContext.isRender()) {
} else if (phase.isRender()) {
executeRenderResult(location, invocation);
}
}
/**
* @param location
* @param invocation
*/
private void executeActionResult(String location,
ActionInvocation invocation) {
private void executeActionResult(String location, ActionInvocation invocation) {
ActionResponse res = PortletActionContext.getActionResponse();
// View is rendered outside an action...uh oh...
invocation.getInvocationContext().getSession().put(RENDER_DIRECT_LOCATION, location);
res.setRenderParameter(PortletActionConstants.ACTION_PARAM, "freemarkerDirect");
invocation.getInvocationContext().getSession().put(PortletConstants.RENDER_DIRECT_LOCATION, location);
res.setRenderParameter(PortletConstants.ACTION_PARAM, "freemarkerDirect");
res.setRenderParameter("location", location);
res.setRenderParameter(PortletActionConstants.MODE_PARAM, PortletActionContext
.getRequest().getPortletMode().toString());
res.setRenderParameter(PortletConstants.MODE_PARAM, PortletActionContext.getRequest().getPortletMode().toString());
}
/**
* @param location
* @param invocation
* @throws TemplateException
* @throws IOException
* @throws TemplateModelException
*/
private void executeRenderResult(String location,
ActionInvocation invocation) throws TemplateException, IOException,
TemplateModelException, PortletException {
private void executeRenderResult(String location, ActionInvocation invocation)
throws TemplateException, IOException, PortletException {
this.location = location;
this.invocation = invocation;
this.configuration = getConfiguration();
@@ -173,8 +157,7 @@ public class PortletFreemarkerResult extends StrutsResultSupport implements Port
* from the ConfigurationManager instance. </b>
*/
protected Configuration getConfiguration() throws TemplateException {
return freemarkerManager.getConfiguration(
ServletActionContext.getServletContext());
return freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
}
/**
@@ -218,11 +201,8 @@ public class PortletFreemarkerResult extends StrutsResultSupport implements Port
.getServletContext();
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
ValueStack stack = ServletActionContext.getContext()
.getValueStack();
return freemarkerManager.buildTemplateModel(stack,
invocation.getAction(), servletContext, request, response,
wrapper);
ValueStack stack = ServletActionContext.getContext().getValueStack();
return freemarkerManager.buildTemplateModel(stack, invocation.getAction(), servletContext, request, response, wrapper);
}
/**
@@ -239,8 +219,7 @@ public class PortletFreemarkerResult extends StrutsResultSupport implements Port
* the default implementation of postTemplateProcess applies the contentType
* parameter
*/
protected void postTemplateProcess(Template template, TemplateModel data)
throws IOException {
protected void postTemplateProcess(Template template, TemplateModel data) throws IOException {
}
/**
@@ -253,8 +232,7 @@ public class PortletFreemarkerResult extends StrutsResultSupport implements Port
* @return true to process the template, false to suppress template
* processing.
*/
protected boolean preTemplateProcess(Template template, TemplateModel model)
throws IOException {
protected boolean preTemplateProcess(Template template, TemplateModel model) throws IOException {
Object attrContentType = template.getCustomAttribute("content_type");
if (attrContentType != null) {
@@ -11,6 +11,8 @@ import org.springframework.mock.web.portlet.MockPortletContext;
import org.springframework.mock.web.portlet.MockPortletRequest;
import javax.portlet.PortletContext;
import javax.portlet.PortletMode;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Collections;
@@ -46,5 +48,14 @@ public class PortletUrlRendererTest extends StrutsTestCase {
// then
assertTrue("/portlettest".equals(component.getNamespace()));
}
public void testIsPortelModeChanged() {
PortletUrlRenderer renderer = new PortletUrlRenderer();
PortletMode mode = new PortletMode("test");
UrlProvider provider = new ComponentUrlProvider(null, null);
provider.setPortletMode("test2");
assertTrue(renderer.isPortletModeChange(provider, mode));
}
}

Some files were not shown because too many files have changed in this diff Show More