|
From: <fg...@us...> - 2008-12-11 16:15:25
|
Revision: 949
http://openutils.svn.sourceforge.net/openutils/?rev=949&view=rev
Author: fgiust
Date: 2008-12-11 16:15:12 +0000 (Thu, 11 Dec 2008)
Log Message:
-----------
new projects
Added Paths:
-----------
trunk/openutils-elfunctions/
trunk/openutils-elfunctions/pom.xml
trunk/openutils-elfunctions/src/
trunk/openutils-elfunctions/src/main/
trunk/openutils-elfunctions/src/main/java/
trunk/openutils-elfunctions/src/main/java/net/
trunk/openutils-elfunctions/src/main/java/net/sourceforge/
trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/
trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/
trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/ElStringUtils.java
trunk/openutils-elfunctions/src/main/resources/
trunk/openutils-elfunctions/src/main/resources/META-INF/
trunk/openutils-elfunctions/src/main/resources/META-INF/stringutils.tld
trunk/openutils-mgnlstruts11/
trunk/openutils-mgnlstruts11/pom.xml
trunk/openutils-mgnlstruts11/src/
trunk/openutils-mgnlstruts11/src/main/
trunk/openutils-mgnlstruts11/src/main/java/
trunk/openutils-mgnlstruts11/src/main/java/it/
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/pages/
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/pages/StrutsConfigurationPage.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlFormFile.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlMultipartRequestHandler.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlRequestProcessor.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlRequestProcessorHelper.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlStrutsUtils.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/render/
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/render/MgnlStrutsServlet.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/render/StrutsParagraph.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/render/StrutsParagraphRegister.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/render/StrutsProcessingException.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/render/StrutsRenderer.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/setup/
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/setup/MgnlStrutsModuleVersionHandler.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/taglib/
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/taglib/MgnlFormTag.java
trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/taglib/MgnlLinkTag.java
trunk/openutils-mgnlstruts11/src/main/resources/
trunk/openutils-mgnlstruts11/src/main/resources/META-INF/
trunk/openutils-mgnlstruts11/src/main/resources/META-INF/magnolia/
trunk/openutils-mgnlstruts11/src/main/resources/META-INF/magnolia/struts11.xml
trunk/openutils-mgnlstruts11/src/main/resources/META-INF/mgnlstruts-html.tld
trunk/openutils-mgnlstruts11/src/main/resources/it/
trunk/openutils-mgnlstruts11/src/main/resources/it/openutils/
trunk/openutils-mgnlstruts11/src/main/resources/it/openutils/mgnlstruts11/
trunk/openutils-mgnlstruts11/src/main/resources/it/openutils/mgnlstruts11/pages/
trunk/openutils-mgnlstruts11/src/main/resources/it/openutils/mgnlstruts11/pages/StrutsConfigurationPage.html
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-bootstrap/
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-bootstrap/struts11/
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-bootstrap/struts11/config.modules.adminInterface.config.menu.tools.struts.xml
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-bootstrap/struts11/config.modules.adminInterface.config.menu.tools.strutsjcr.xml
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-bootstrap/struts11/config.modules.struts11.pages.struts.xml
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-bootstrap/struts11/config.modules.struts11.paragraph-renderers.struts.xml
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-bootstrap/struts11/config.server.filters.cms.bypasses.struts.xml
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-bootstrap/struts11/config.server.filters.gzip.bypasses.struts.xml
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-resources/
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-resources/struts/
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-resources/struts/struts-ico.png
trunk/openutils-mgnlstruts11/src/main/resources/mgnl-resources/struts/struts.png
trunk/openutils-mgnlstruts11/src/test/
trunk/openutils-mgnlstruts11/src/test/java/
trunk/openutils-mgnlstruts11/src/test/resources/
Property changes on: trunk/openutils-elfunctions
___________________________________________________________________
Added: svn:ignore
+
.settings
target
.checkstyle
.classpath
.project
Added: trunk/openutils-elfunctions/pom.xml
===================================================================
--- trunk/openutils-elfunctions/pom.xml (rev 0)
+++ trunk/openutils-elfunctions/pom.xml 2008-12-11 16:15:12 UTC (rev 949)
@@ -0,0 +1,32 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>net.sourceforge.openutils</groupId>
+ <artifactId>openutils</artifactId>
+ <version>10</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>jar</packaging>
+ <artifactId>openutils-elfunctions</artifactId>
+ <name>openutils-elfunctions</name>
+ <dependencies>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <classifier>jdk15</classifier>
+ <version>5.1</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+</project>
Property changes on: trunk/openutils-elfunctions/pom.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/ElStringUtils.java
===================================================================
--- trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/ElStringUtils.java (rev 0)
+++ trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/ElStringUtils.java 2008-12-11 16:15:12 UTC (rev 949)
@@ -0,0 +1,110 @@
+/*
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * Licensed 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 net.sourceforge.openutils.elfunctions;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
+
+
+/**
+ * Utility methods mapped to EL functions to allow usage in jsp pages.
+ * @author fgiust
+ * @version $Id$
+ */
+public class ElStringUtils
+{
+
+ public static String escapeXml(String value)
+ {
+ String esc = StringEscapeUtils.escapeXml(value);
+ return StringUtils.replace(esc, "'", "'");
+ }
+
+ /**
+ * The space character.
+ * @return the space character
+ */
+ public static String space()
+ {
+ return " ";
+ }
+
+ /**
+ * The tab character.
+ * @return the tab character
+ */
+ public static String tab()
+ {
+ return "\t";
+ }
+
+ /**
+ * The newline (<code>\n</code>) character.
+ * @return the newline (<code>\n</code>) character
+ */
+ public static String newline()
+ {
+ return "\n";
+ }
+
+ public static String escapeJsText(String text, boolean dbl)
+ {
+ String repl = dbl ? "\"" : "'";
+ String with = "\\" + repl;
+ return repl + (text != null ? StringUtils.replace(text, repl, with) : "") + repl;
+ }
+
+ public static String adaptStringLength(String value, int maxLength, String ellipses)
+ {
+ if (value != null && value.length() > maxLength)
+ {
+ return value.substring(0, maxLength) + ellipses;
+ }
+
+ return value;
+ }
+
+ public static String stripHtmlTags(String string)
+ {
+ if (StringUtils.isNotBlank(string))
+ {
+ return StringUtils.remove(StringUtils.remove(string.replaceAll("<(.|\n)+?>", ""), '\r'), '\n').trim();
+
+ }
+ return null;
+ }
+
+ /**
+ * Splits the given strings on newlines (<code>\n</code>)
+ * @param string string to be splitted
+ * @return splitted string
+ */
+ public static String[] splitNewlines(String string)
+ {
+ return StringUtils.splitPreserveAllTokens(string, '\n');
+ }
+
+ /**
+ * Splits the given strings on tabs (<code>\t</code>)
+ * @param string string to be splitted
+ * @return splitted string
+ */
+ public static String[] splitOnTabs(String string)
+ {
+ return StringUtils.splitPreserveAllTokens(string, '\t');
+ }
+
+}
Property changes on: trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/ElStringUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/openutils-elfunctions/src/main/resources/META-INF/stringutils.tld
===================================================================
--- trunk/openutils-elfunctions/src/main/resources/META-INF/stringutils.tld (rev 0)
+++ trunk/openutils-elfunctions/src/main/resources/META-INF/stringutils.tld 2008-12-11 16:15:12 UTC (rev 949)
@@ -0,0 +1,99 @@
+<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
+ version="2.0">
+ <description>Openutils EL functions: stringutils</description>
+ <display-name>Openutils EL functions: stringutils</display-name>
+ <tlib-version>1.0</tlib-version>
+ <short-name>su</short-name>
+ <uri>http://openutils.sf.net/openutils-stringutils</uri>
+ <function>
+ <name>capitaliseAllWords</name>
+ <function-class>org.apache.commons.lang.StringUtils</function-class>
+ <function-signature>java.lang.String capitaliseAllWords(java.lang.String)</function-signature>
+ </function>
+ <function>
+ <name>substringAfterLast</name>
+ <function-class>org.apache.commons.lang.StringUtils</function-class>
+ <function-signature>java.lang.String substringAfterLast(java.lang.String, java.lang.String)</function-signature>
+ </function>
+ <function>
+ <name>substringBeforeLast</name>
+ <function-class>org.apache.commons.lang.StringUtils</function-class>
+ <function-signature>java.lang.String substringBeforeLast(java.lang.String, java.lang.String)</function-signature>
+ </function>
+ <function>
+ <name>isBlank</name>
+ <function-class>org.apache.commons.lang.StringUtils</function-class>
+ <function-signature>boolean isBlank(java.lang.String )</function-signature>
+ </function>
+ <function>
+ <name>randomAlphanumeric</name>
+ <function-class>org.apache.commons.lang.RandomStringUtils</function-class>
+ <function-signature>java.lang.String randomAlphanumeric(int)</function-signature>
+ </function>
+ <function>
+ <name>escapeXml</name>
+ <function-class>net.sourceforge.openutils.elfunctions.ElStringUtils</function-class>
+ <function-signature>java.lang.String escapeXml(java.lang.String)</function-signature>
+ </function>
+ <function>
+ <description>Unescapes a String</description>
+ <name>unescapeXml</name>
+ <function-class>org.apache.commons.lang.StringEscapeUtils</function-class>
+ <function-signature>java.lang.String unescapeXml(java.lang.String)</function-signature>
+ </function>
+ <function>
+ <name>space</name>
+ <function-class>net.sourceforge.openutils.elfunctions.ElStringUtils</function-class>
+ <function-signature>java.lang.String space()</function-signature>
+ </function>
+ <function>
+ <name>tab</name>
+ <function-class>net.sourceforge.openutils.elfunctions.ElStringUtils</function-class>
+ <function-signature>java.lang.String tab()</function-signature>
+ </function>
+ <function>
+ <name>newline</name>
+ <function-class>net.sourceforge.openutils.elfunctions.ElStringUtils</function-class>
+ <function-signature>java.lang.String newline()</function-signature>
+ </function>
+ <function>
+ <name>escJsTxt</name>
+ <function-class>net.sourceforge.openutils.elfunctions.ElStringUtils</function-class>
+ <function-signature>java.lang.String escapeJsText(java.lang.String, boolean)</function-signature>
+ </function>
+ <function>
+ <name>adaptStringLength</name>
+ <function-class>net.sourceforge.openutils.elfunctions.ElStringUtils</function-class>
+ <function-signature>java.lang.String adaptStringLength(java.lang.String, int, java.lang.String)</function-signature>
+ </function>
+ <function>
+ <name>stripHtmlTags</name>
+ <function-class>net.sourceforge.openutils.elfunctions.ElStringUtils</function-class>
+ <function-signature>java.lang.String stripHtmlTags(java.lang.String)</function-signature>
+ </function>
+ <function>
+ <description>Splits the given strings on newlines</description>
+ <name>splitNewlines</name>
+ <function-class>net.sourceforge.openutils.elfunctions.ElStringUtils</function-class>
+ <function-signature>java.lang.String[] splitNewlines(java.lang.String)</function-signature>
+ </function>
+ <function>
+ <description>Splits the given string on tab characters</description>
+ <name>splitOnTabs</name>
+ <function-class>net.sourceforge.openutils.elfunctions.ElStringUtils</function-class>
+ <function-signature>java.lang.String[] splitOnTabs(java.lang.String)</function-signature>
+ </function>
+ <function>
+ <description>Strips whitespaces from the start and the end of a String</description>
+ <name>strip</name>
+ <function-class>org.apache.commons.lang.StringUtils</function-class>
+ <function-signature>java.lang.String strip(java.lang.String)</function-signature>
+ </function>
+ <function>
+ <description>Returns either the passed in String, or if the String is empty or null, the value of defaultStr</description>
+ <name>defaultIfEmpty</name>
+ <function-class>org.apache.commons.lang.StringUtils</function-class>
+ <function-signature>java.lang.String defaultIfEmpty(java.lang.String, java.lang.String)</function-signature>
+ </function>
+</taglib>
\ No newline at end of file
Property changes on: trunk/openutils-elfunctions/src/main/resources/META-INF/stringutils.tld
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:keywords
+ Author Date Id Revision
Property changes on: trunk/openutils-mgnlstruts11
___________________________________________________________________
Added: svn:ignore
+
.settings
.checkstyle
.classpath
.project
target
Added: trunk/openutils-mgnlstruts11/pom.xml
===================================================================
--- trunk/openutils-mgnlstruts11/pom.xml (rev 0)
+++ trunk/openutils-mgnlstruts11/pom.xml 2008-12-11 16:15:12 UTC (rev 949)
@@ -0,0 +1,82 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sourceforge.openutils</groupId>
+ <artifactId>openutils</artifactId>
+ <version>10</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>openutils-mgnlstruts11</artifactId>
+ <packaging>jar</packaging>
+ <name>openutils-mgnlstruts11</name>
+ <version>1.0-SNAPSHOT</version>
+ <licenses>
+ <license>
+ <name>GPLv3</name>
+ <url>http://www.gnu.org/licenses/gpl-3.0.txt</url>
+ </license>
+ </licenses>
+ <build>
+ <resources>
+ <resource>
+ <filtering>false</filtering>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ <resource>
+ <filtering>true</filtering>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>META-INF/magnolia/*</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>info.magnolia</groupId>
+ <artifactId>magnolia-core</artifactId>
+ <version>3.6.3</version>
+ </dependency>
+ <dependency>
+ <groupId>info.magnolia</groupId>
+ <artifactId>magnolia-module-admininterface</artifactId>
+ <version>3.6.3</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.openutils</groupId>
+ <artifactId>openutils-mgnltasks</artifactId>
+ <version>3.5.5</version>
+ </dependency>
+ <dependency>
+ <groupId>struts</groupId>
+ <artifactId>struts</artifactId>
+ <version>1.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.sql</groupId>
+ <artifactId>jdbc-stdext</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Property changes on: trunk/openutils-mgnlstruts11/pom.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/pages/StrutsConfigurationPage.java
===================================================================
--- trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/pages/StrutsConfigurationPage.java (rev 0)
+++ trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/pages/StrutsConfigurationPage.java 2008-12-11 16:15:12 UTC (rev 949)
@@ -0,0 +1,101 @@
+/**
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package it.openutils.mgnlstruts11.pages;
+
+import info.magnolia.cms.beans.config.ParagraphManager;
+import info.magnolia.cms.i18n.Messages;
+import info.magnolia.cms.i18n.TemplateMessagesUtil;
+import info.magnolia.module.admininterface.DialogHandlerManager;
+import info.magnolia.module.admininterface.DialogMVCHandler;
+import info.magnolia.module.admininterface.InvalidDialogHandlerException;
+import info.magnolia.module.admininterface.TemplatedMVCHandler;
+import it.openutils.mgnlstruts11.render.StrutsParagraph;
+import it.openutils.mgnlstruts11.render.StrutsParagraphRegister;
+
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+
+
+/**
+ * A magnolia page that lists all the Struts paragraphs.
+ * @author fgiust
+ * @version $Id$
+ */
+public class StrutsConfigurationPage extends TemplatedMVCHandler
+{
+
+ /**
+ * Required constructor.
+ * @param name page name
+ * @param request HttpServletRequest
+ * @param response HttpServletResponse
+ */
+ public StrutsConfigurationPage(String name, HttpServletRequest request, HttpServletResponse response)
+ {
+ super(name, request, response);
+ }
+
+ public Set<StrutsParagraph> getStrutsParagraphs()
+ {
+ return StrutsParagraphRegister.getParagraphs();
+ }
+
+ public Messages getMessages()
+ {
+ return TemplateMessagesUtil.getMessages();
+ }
+
+ public ParagraphManager getParagraphManager()
+ {
+ return ParagraphManager.getInstance();
+ }
+
+ public boolean isDialogConfigured(String dialogName)
+ {
+ DialogMVCHandler handler = null;
+ try
+ {
+ handler = DialogHandlerManager.getInstance().getDialogHandler(dialogName, request, response);
+ }
+ catch (InvalidDialogHandlerException e)
+ {
+ return false;
+ }
+
+ return handler != null;
+ }
+
+ public String getDialogPath(String dialogName)
+ {
+ DialogMVCHandler handler = null;
+ try
+ {
+ handler = DialogHandlerManager.getInstance().getDialogHandler(dialogName, request, response);
+ }
+ catch (InvalidDialogHandlerException e)
+ {
+ return StringUtils.EMPTY;
+ }
+
+ return handler.getConfigNode().getHandle();
+ }
+}
Property changes on: trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/pages/StrutsConfigurationPage.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlFormFile.java
===================================================================
--- trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlFormFile.java (rev 0)
+++ trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlFormFile.java 2008-12-11 16:15:12 UTC (rev 949)
@@ -0,0 +1,181 @@
+/**
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package it.openutils.mgnlstruts11.process;
+
+import info.magnolia.cms.beans.runtime.Document;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.struts.upload.FormFile;
+
+
+/**
+ * A FormFile implementation that wraps a Magnolia Multipart Document.
+ * @author fgiust
+ * @version $Id$
+ */
+class MgnlFormFile implements FormFile
+{
+
+ /**
+ * The <code>document</code> instance wrapped by this object.
+ */
+ private Document mgnlDocument;
+
+ public MgnlFormFile(Document fileItem)
+ {
+ this.mgnlDocument = fileItem;
+ }
+
+ /**
+ * Returns the content type for this file.
+ * @return A String representing content type.
+ */
+ public String getContentType()
+ {
+ return mgnlDocument.getExtension();
+ }
+
+ /**
+ * Sets the content type for this file.
+ * <p>
+ * NOTE: This method is not supported in this implementation.
+ * @param contentType A string representing the content type.
+ */
+ public void setContentType(String contentType)
+ {
+ throw new UnsupportedOperationException("The setContentType() method is not supported.");
+ }
+
+ /**
+ * Returns the size, in bytes, of this file.
+ * @return The size of the file, in bytes.
+ */
+ public int getFileSize()
+ {
+ return (int) mgnlDocument.getFile().length();
+ }
+
+ /**
+ * Sets the size, in bytes, for this file.
+ * <p>
+ * NOTE: This method is not supported in this implementation.
+ * @param filesize The size of the file, in bytes.
+ */
+ public void setFileSize(int filesize)
+ {
+ throw new UnsupportedOperationException("The setFileSize() method is not supported.");
+ }
+
+ /**
+ * Returns the (client-side) file name for this file.
+ * @return The client-size file name.
+ */
+ public String getFileName()
+ {
+ return getBaseFileName(mgnlDocument.getFileName());
+ }
+
+ /**
+ * Sets the (client-side) file name for this file.
+ * <p>
+ * NOTE: This method is not supported in this implementation.
+ * @param fileName The client-side name for the file.
+ */
+ public void setFileName(String fileName)
+ {
+ throw new UnsupportedOperationException("The setFileName() method is not supported.");
+ }
+
+ /**
+ * Returns the data for this file as a byte array. Note that this may result in excessive memory usage for large
+ * uploads. The use of the {@link #getInputStream() getInputStream} method is encouraged as an alternative.
+ * @return An array of bytes representing the data contained in this form file.
+ * @exception FileNotFoundException If some sort of file representation cannot be found for the FormFile
+ * @exception IOException If there is some sort of IOException
+ */
+ public byte[] getFileData() throws FileNotFoundException, IOException
+ {
+ return FileUtils.readFileToByteArray(mgnlDocument.getFile());
+ }
+
+ /**
+ * Get an InputStream that represents this file. This is the preferred method of getting file data.
+ * @exception FileNotFoundException If some sort of file representation cannot be found for the FormFile
+ * @exception IOException If there is some sort of IOException
+ */
+ public InputStream getInputStream() throws FileNotFoundException, IOException
+ {
+ return mgnlDocument.getStream();
+ }
+
+ /**
+ * Destroy all content for this form file. Implementations should remove any temporary files or any temporary file
+ * data stored somewhere
+ */
+ public void destroy()
+ {
+ mgnlDocument.delete();
+ }
+
+ /**
+ * Returns the base file name from the supplied file path. On the surface, this would appear to be a trivial task.
+ * Apparently, however, some Linux JDKs do not implement <code>File.getName()</code> correctly for Windows paths, so
+ * we attempt to take care of that here.
+ * @param filePath The full path to the file.
+ * @return The base file name, from the end of the path.
+ */
+ protected String getBaseFileName(String filePath)
+ {
+
+ // First, ask the JDK for the base file name.
+ String fileName = new File(filePath).getName();
+
+ // Now check for a Windows file name parsed incorrectly.
+ int colonIndex = fileName.indexOf(":");
+ if (colonIndex == -1)
+ {
+ // Check for a Windows SMB file path.
+ colonIndex = fileName.indexOf("\\\\");
+ }
+ int backslashIndex = fileName.lastIndexOf("\\");
+
+ if (colonIndex > -1 && backslashIndex > -1)
+ {
+ // Consider this filename to be a full Windows path, and parse it
+ // accordingly to retrieve just the base file name.
+ fileName = fileName.substring(backslashIndex + 1);
+ }
+
+ return fileName;
+ }
+
+ /**
+ * Returns the (client-side) file name for this file.
+ * @return The client-size file name.
+ */
+ @Override
+ public String toString()
+ {
+ return getFileName();
+ }
+}
\ No newline at end of file
Property changes on: trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlFormFile.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlMultipartRequestHandler.java
===================================================================
--- trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlMultipartRequestHandler.java (rev 0)
+++ trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlMultipartRequestHandler.java 2008-12-11 16:15:12 UTC (rev 949)
@@ -0,0 +1,200 @@
+/**
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package it.openutils.mgnlstruts11.process;
+
+import info.magnolia.cms.beans.runtime.Document;
+import info.magnolia.cms.beans.runtime.MultipartForm;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.Globals;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionServlet;
+import org.apache.struts.config.ModuleConfig;
+import org.apache.struts.upload.FormFile;
+import org.apache.struts.upload.MultipartRequestHandler;
+
+
+/**
+ * A <code>MultipartRequestHandler</code> implementation that delegates to the stadard Magnolia Multipart parser.
+ * @author fgiust
+ * @version $Id$
+ */
+public class MgnlMultipartRequestHandler implements MultipartRequestHandler
+{
+
+ /**
+ * Commons Logging instance.
+ */
+ protected static Log log = LogFactory.getLog(MgnlMultipartRequestHandler.class);
+
+ /**
+ * The combined text and file request parameters.
+ */
+ private Hashtable elementsAll;
+
+ /**
+ * The file request parameters.
+ */
+ private Hashtable<String, FormFile> elementsFile;
+
+ /**
+ * The action mapping with which this handler is associated.
+ */
+ private ActionMapping mapping;
+
+ /**
+ * The servlet with which this handler is associated.
+ */
+ private ActionServlet servlet;
+
+ /**
+ * Magnolia multipart form
+ */
+ private MultipartForm mpf;
+
+ /**
+ * Retrieves the servlet with which this handler is associated.
+ * @return The associated servlet.
+ */
+ public ActionServlet getServlet()
+ {
+ return this.servlet;
+ }
+
+ /**
+ * Sets the servlet with which this handler is associated.
+ * @param servlet The associated servlet.
+ */
+ public void setServlet(ActionServlet servlet)
+ {
+ this.servlet = servlet;
+ }
+
+ /**
+ * Retrieves the action mapping with which this handler is associated.
+ * @return The associated action mapping.
+ */
+ public ActionMapping getMapping()
+ {
+ return this.mapping;
+ }
+
+ /**
+ * Sets the action mapping with which this handler is associated.
+ * @param mapping The associated action mapping.
+ */
+ public void setMapping(ActionMapping mapping)
+ {
+ this.mapping = mapping;
+ }
+
+ /**
+ * Parses the input stream and partitions the parsed items into a set of form fields and a set of file items. In the
+ * process, the parsed items are translated from Commons FileUpload <code>FileItem</code> instances to Struts
+ * <code>FormFile</code> instances.
+ * @param request The multipart request to be processed.
+ * @throws ServletException if an unrecoverable error occurs.
+ */
+ @SuppressWarnings("unchecked")
+ public void handleRequest(HttpServletRequest request) throws ServletException
+ {
+
+ // always made available by the renderer
+ mpf = (MultipartForm) request.getAttribute(MultipartForm.REQUEST_ATTRIBUTE_NAME);
+
+ // Create the hash tables to be populated.
+ elementsFile = new Hashtable<String, FormFile>();
+ elementsAll = new Hashtable();
+
+ Map<String, Document> docs = mpf.getDocuments();
+ for (Map.Entry<String, Document> doc : docs.entrySet())
+ {
+ addFileParameter(doc.getKey(), doc.getValue());
+ }
+
+ elementsAll.putAll(getTextElements());
+ elementsAll.putAll(elementsFile);
+
+ }
+
+ /**
+ * Returns a hash table containing the text (that is, non-file) request parameters.
+ * @return The text request parameters.
+ */
+ @SuppressWarnings("unchecked")
+ public Hashtable<String, String[]> getTextElements()
+ {
+ // not really safe, but internally mpf uses hashtables instances
+ return ((Hashtable<String, String[]>) mpf.getParameters());
+ }
+
+ /**
+ * Returns a hash table containing the file (that is, non-text) request parameters.
+ * @return The file request parameters.
+ */
+ @SuppressWarnings("unchecked")
+ public Hashtable getFileElements()
+ {
+ return this.elementsFile;
+ }
+
+ /**
+ * Returns a hash table containing both text and file request parameters.
+ * @return The text and file request parameters.
+ */
+ @SuppressWarnings("unchecked")
+ public Hashtable getAllElements()
+ {
+
+ return this.elementsAll;
+ }
+
+ /**
+ * Cleans up when a problem occurs during request processing.
+ */
+ public void rollback()
+ {
+ // nothing to do
+ }
+
+ /**
+ * Cleans up at the end of a request.
+ */
+ public void finish()
+ {
+ // nothing to do
+ }
+
+ /**
+ * Adds a file parameter to the set of file parameters for this request and also to the list of all parameters.
+ * @param item The file item for the parameter to add.
+ */
+ protected void addFileParameter(String name, Document item)
+ {
+ FormFile formFile = new MgnlFormFile(item);
+ elementsFile.put(name, formFile);
+ }
+
+}
Property changes on: trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlMultipartRequestHandler.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlRequestProcessor.java
===================================================================
--- trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlRequestProcessor.java (rev 0)
+++ trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlRequestProcessor.java 2008-12-11 16:15:12 UTC (rev 949)
@@ -0,0 +1,98 @@
+/**
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package it.openutils.mgnlstruts11.process;
+
+import it.openutils.mgnlstruts11.render.StrutsRenderer;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.RequestProcessor;
+import org.apache.struts.config.ForwardConfig;
+
+
+/**
+ * A request processor implementation that makes struts dispatching work inside magnolia.
+ * @author fgiust
+ * @version $Id$
+ */
+public class MgnlRequestProcessor extends RequestProcessor
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String processPath(HttpServletRequest request, HttpServletResponse response) throws IOException
+ {
+
+ String path = (String) request.getAttribute(StrutsRenderer.PARAGRAPH_PATH);
+ if (path != null)
+ {
+ log.debug("Processing path " + path);
+ return (path);
+ }
+
+ return super.processPath(request, response);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void processForwardConfig(HttpServletRequest request, HttpServletResponse response, ForwardConfig forward)
+ throws IOException, ServletException
+ {
+ MgnlRequestProcessorHelper.doProcessForwardConfig(request, response, forward);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doForward(String uri, HttpServletRequest request, HttpServletResponse response) throws IOException,
+ ServletException
+ {
+ // forwards are translated to include when running inside magnolia
+ doInclude(uri, request, response);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doInclude(String uri, HttpServletRequest request, HttpServletResponse response) throws IOException,
+ ServletException
+ {
+ MgnlRequestProcessorHelper.doInclude(uri, request, response);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ActionMapping processMapping(HttpServletRequest request, HttpServletResponse response, String path)
+ throws IOException
+ {
+ return MgnlRequestProcessorHelper.doProcessMapping(request, response, path, moduleConfig);
+ }
+}
Property changes on: trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlRequestProcessor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlRequestProcessorHelper.java
===================================================================
--- trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlRequestProcessorHelper.java (rev 0)
+++ trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlRequestProcessorHelper.java 2008-12-11 16:15:12 UTC (rev 949)
@@ -0,0 +1,180 @@
+/**
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package it.openutils.mgnlstruts11.process;
+
+import info.magnolia.cms.beans.config.ServerConfiguration;
+import info.magnolia.context.MgnlContext;
+import info.magnolia.context.WebContext;
+import it.openutils.mgnlstruts11.render.StrutsRenderer;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.struts.Globals;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.config.ActionConfig;
+import org.apache.struts.config.ForwardConfig;
+import org.apache.struts.config.ModuleConfig;
+import org.apache.struts.upload.MultipartRequestWrapper;
+import org.apache.struts.util.RequestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author fgiust
+ * @version $Id: MgnlRequestProcessorHelper.java 86 2008-11-04 08:37:44Z fgiust
+ * $
+ */
+public class MgnlRequestProcessorHelper {
+
+ /**
+ * Logger.
+ */
+ private static Logger log = LoggerFactory
+ .getLogger(MgnlRequestProcessorHelper.class);
+
+ public static void doProcessForwardConfig(HttpServletRequest request,
+ HttpServletResponse response, ForwardConfig forward)
+ throws IOException, ServletException {
+
+ log.info("processForwardConfig " + forward);
+ if (forward == null) {
+ return;
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("processForwardConfig(" + forward + ")");
+ }
+
+ String forwardPath = forward.getPath();
+ String uri = null;
+
+ // paths not starting with / should be passed through without any
+ // processing
+ // (ie. they're absolute)
+ if (forwardPath.startsWith("/")) {
+ uri = RequestUtils.forwardURL(request, forward); // get module
+ // relative uri
+ } else {
+ uri = forwardPath;
+ }
+
+ if (forward.getRedirect() && !uri.endsWith(".jsp")) {
+ // @todo redirect in templates
+ // only prepend context path for relative uri
+ if (uri.startsWith("/")) {
+ uri = request.getContextPath() + uri;
+ }
+ response.sendRedirect(response.encodeRedirectURL(uri));
+
+ } else {
+ doInclude(uri, request, response);
+ }
+
+ }
+
+ public static void doInclude(String uri, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+
+ // needed for chained forwards, avoid loops!
+ request.setAttribute(StrutsRenderer.PARAGRAPH_PATH, uri);
+
+ // Unwrap the multipart request, if there is one.
+ if (request instanceof MultipartRequestWrapper) {
+ request = ((MultipartRequestWrapper) request).getRequest();
+ }
+
+ RequestDispatcher rd = getWebContext().getServletContext()
+ .getRequestDispatcher(uri);
+
+ getWebContext().include(uri, getOut());
+ }
+
+ public static ActionMapping doProcessMapping(HttpServletRequest request,
+ HttpServletResponse response, String path, ModuleConfig moduleConfig)
+ throws IOException {
+
+ log.info("Process mapping " + path);
+
+ // Is there a directly defined mapping for this path?
+ ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig(path);
+
+ if (mapping == null) {
+ // @todo This is almost a copy-paste of the end of RequestProcessor.processPath method, it should be refactored in a "simplify path" somewhere else.
+ // This is a temporary patch to handle forwards correctly.
+ String retryPath = StringUtils.defaultString(StringUtils.substringAfterLast(StringUtils.substringBeforeLast(path, "."), "/"));
+ retryPath = retryPath.startsWith("/") ? retryPath : ("/" + retryPath);
+ mapping = (ActionMapping) moduleConfig.findActionConfig(retryPath);
+ }
+
+ if (mapping != null) {
+ request.setAttribute(Globals.MAPPING_KEY, mapping);
+ return (mapping);
+ }
+
+ // Locate the mapping for unknown paths (if any)
+ ActionConfig configs[] = moduleConfig.findActionConfigs();
+ for (int i = 0; i < configs.length; i++) {
+ if (configs[i].getUnknown()) {
+ mapping = (ActionMapping) configs[i];
+ request.setAttribute(Globals.MAPPING_KEY, mapping);
+ return (mapping);
+ }
+ }
+
+ // No mapping can be found to process this request
+ log.error("Invalid path: " + path);
+
+ // debug only on admin instances
+ if (ServerConfiguration.getInstance().isAdmin()) {
+ getOut().write("Invalid path: " + path);
+ }
+
+ return (null);
+
+ }
+
+ private static WebContext getWebContext() {
+ return ((WebContext) MgnlContext.getInstance());
+ }
+
+ /**
+ * @return
+ * @throws IOException
+ */
+ private static Writer getOut() throws IOException {
+ Writer out = null;
+
+ PageContext pageContext = getWebContext().getPageContext();
+
+ if (pageContext != null) {
+ out = pageContext.getOut();
+ } else {
+ out = getWebContext().getResponse().getWriter();
+ }
+ return out;
+ }
+
+}
Property changes on: trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlRequestProcessorHelper.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlStrutsUtils.java
===================================================================
--- trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlStrutsUtils.java (rev 0)
+++ trunk/openutils-mgnlstruts11/src/main/java/it/openutils/mgnlstruts11/process/MgnlStrutsUtils.java 2008-12-11 16:15:12 UTC (rev 949)
@@ -0,0 +1,457 @@
+/**
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package it.openutils.mgnlstruts11.process;
+
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URLEncoder;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.UnavailableException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.struts.Globals;
+import org.apache.struts.action.ActionServlet;
+import org.apache.struts.action.RequestProcessor;
+import org.apache.struts.config.ForwardConfig;
+import org.apache.struts.config.ModuleConfig;
+import org.apache.struts.util.MessageResources;
+import org.apache.struts.util.RequestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Magnolia-Struts utility methods.
+ * @author fgiust
+ * @version $Id$
+ */
+public final class MgnlStrutsUtils
+{
+
+ /**
+ * Request parameter containing the current magnolia action.
+ */
+ public static final String PARAMETER_MGNLACTION = "_mgnlaction";
+
+ /**
+ *
+ */
+ public static final String ATTRIBUTE_ORIGINALURI = "_originaluri";
+
+ /**
+ * Logger.
+ */
+ private static Logger log = LoggerFactory.getLogger(MgnlStrutsUtils.class);
+
+ /**
+ * The message resources for this package.
+ */
+ private static MessageResources messages = MessageResources
+ .getMessageResources("org.apache.struts.util.LocalStrings");
+
+ /**
+ * Look up and return the {@link RequestProcessor} responsible for the specified module, creating a new one if
+ * necessary.
+ * @param config The module configuration for which to acquire and return a RequestProcessor.
+ * @exception ServletException if we cannot instantiate a RequestProcessor instance
+ * @since Struts 1.1
+ */
+ public static RequestProcessor getRequestProcessor(ModuleConfig config, ServletContext servletContext,
+ ActionServlet dispatcher, Class mgnlProcessorClass) throws ServletException
+ {
+
+ String key = Globals.REQUEST_PROCESSOR_KEY + config.getPrefix();
+ RequestProcessor processor = (RequestProcessor) servletContext.getAttribute(key);
+
+ if (processor == null)
+ {
+ String processorClass = config.getControllerConfig().getProcessorClass();
+ try
+ {
+ processor = (RequestProcessor) RequestUtils.applicationInstance(StringUtils.isNotBlank(processorClass)
+ ? processorClass
+ : mgnlProcessorClass.getName());
+
+ if (!processor.getClass().isAssignableFrom(mgnlProcessorClass))
+ {
+ if (StringUtils.equalsIgnoreCase(
+ org.apache.struts.action.RequestProcessor.class.getName(),
+ processorClass))
+ {
+ // It's safe to replace the default processor
+ log.warn("The default processor class ("
+ + processorClass
+ + ") has been specified for struts module, this will be replaced by "
+ + mgnlProcessorClass.getName()
+ + " to enable the magnolia integration");
+ }
+ else
+ {
+ // It's NOT safe to replace a custom class, should stop the application...
+ log.error("A custom processor class ("
+ + processorClass
+ + ") has been specified for struts module, this will be replaced by "
+ + mgnlProcessorClass.getName()
+ + " to enable the magnolia integration");
+ }
+ processor = (RequestProcessor) RequestUtils.applicationInstance(mgnlProcessorClass.getName());
+ }
+ }
+ catch (Exception e)
+ {
+ throw new UnavailableException("Cannot initialize RequestProcessor of class "
+ + config.getControllerConfig().getProcessorClass()
+ + ": "
+ + e);
+ }
+
+ processor.init(dispatcher, config);
+ servletContext.setAttribute(key, processor);
+
+ }
+ return (processor);
+
+ }
+
+ /**
+ * Compute a hyperlink URL based on the <code>forward</code>, <code>href</code>, <code>action</code> or
+ * <code>page</code> parameter that is not null. The returned URL will have already been passed to
+ * <code>response.encodeURL()</code> for adding a session identifier.
+ * @param pageContext PageContext for the tag making this call
+ * @param forward Logical forward name for which to look up the context-relative URI (if specified)
+ * @param href URL to be utilized unmodified (if specified)
+ * @param page Module-relative page for which a URL should be created (if specified)
+ * @param action Logical action name for which to look up the context-relative URI (if specified)
+ * @param params Map of parameters to be dynamically included (if any)
+ * @param anchor Anchor to be dynamically included (if any)
+ * @param redirect Is this URL for a <code>response.sendRedirect()</code>?
+ * @param encodeSeparator This is only checked if redirect is set to false (never encoded for a redirect). If true,
+ * query string parameter separators are encoded as >amp;, else & is used.
+ * @return URL with session identifier
+ * @exception MalformedURLException if a URL cannot be created for the specified parameters
+ */
+ public static String computeURL(PageContext pageContext, String forward, String href, String page, String action,
+ Map<String, String> params, String anchor, boolean redirect, boolean encodeSeparator, String destinationPage)
+ throws MalformedURLException
+ {
+
+ // TODO All the computeURL() methods need refactoring!
+
+ // Validate that exactly one specifier was included
+ int n = 0;
+ if (forward != null)
+ {
+ n++;
+ }
+ if (href != null)
+ {
+ n++;
+ }
+ if (page != null)
+ {
+ n++;
+ }
+ if (action != null)
+ {
+ n++;
+ }
+ if (n != 1)
+ {
+ throw new MalformedURLException(messages.getMessage("computeURL.specifier"));
+ }
+
+ // Look up the module configuration for this request
+ ModuleConfig config = (ModuleConfig) pageContext.getRequest().getAttribute(Globals.MODULE_KEY);
+ if (config == null)
+ { // Backwards compatibility hack
+ config = (ModuleConfig) pageContext.getServletContext().getAttribute(Globals.MODULE_KEY);
+ pageContext.getRequest().setAttribute(Globals.MODULE_KEY, config);
+ }
+
+ // Calculate the appropriate URL
+ StringBuffer url = new StringBuffer();
+ HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
+
+ String mgnlaction = null;
+
+ if (destinationPage != null && href == null)
+ {
+ url.append(destinationPage);
+ }
+
+ if (forward != null)
+ {
+ ForwardConfig fc = config.findForwardConfig(forward);
+ if (fc == null)
+ {
+ throw new MalformedURLException(messages.getMessage("computeURL.forward", forward));
+ }
+ if (fc.getRedirect())
+ {
+ redirect = true;
+ }
+
+ mgnlaction = forward;
+
+ }
+ else if (href != null)
+ {
+ url.append(href);
+ }
+ else if (action != null)
+ {
+ mgnlaction = RequestUtils.getActionMappingURL(action, pageContext);
+ // url.append(RequestUtils.getActionMappingURL(action, pageContext));
+
+ }
+ else
+ /* if (page != null) */{
+
+ mgnlaction = RequestUtils.pageURL(request, page);
+ // url.append(request.getContextPath());
+ // url.append(RequestUtils.pageURL(request, page));
+ }
+
+ if (mgnlaction != null)
+ {
+ // remove parameters (how ugly is struts 1 :( )
+ if (mgnlaction.contains("?"))
+ {
+ String actionparams = StringUtils.substringAfter(mgnlaction, "?");
+
+ String[] paramz = StringUtils.split(actionparams, "&");
+ for (String string : paramz)
+ {
+ if (StringUtils.contains(string, "="))
+ {
+ params.put(StringUtils.substringBefore(string, "="), StringUtils.substringAfter(string, "="));
+ }
+
+ }
+ mgnlaction = StringUtils.substringBefore(mgnlaction, "?");
+ }
+
+ if (mgnlaction.endsWith(".do"))
+ {
+ mgnlaction = StringUtils.substringBeforeLast(mgnlaction, ".do");
+ }
+
+ params.put(PARAMETER_MGNLACTION, mgnlaction);
+ }
+
+ // Add anchor if requested (replacing any existing anchor)
+ if (anchor != null)
+ {
+ String temp = url.toString();
+ int hash = temp.indexOf('#');
+ if (hash >= 0)
+ {
+ url.setLength(hash);
+ }
+ url.append('#');
+ url.append(encode(anchor));
+ }
+
+ // Add dynamic parameters if requested
+ if ((params != null) && (params.size() > 0))
+ {
+
+ // Save any existing anchor
+ String temp = url.toString();
+ int hash = temp.indexOf('#');
+ if (hash >= 0)
+ {
+ anchor = temp.substring(hash + 1);
+ url.setLength(hash);
+ temp = url.toString();
+ }
+ else
+ {
+ anchor = null;
+ }
+
+ // Define the parameter separator
+ String separator = null;
+ if (redirect)
+ {
+ separator = "&";
+ }
+ else if (encodeSeparator)
+ {
+ separator = "&";
+ }
+ else
+ {
+ separator = "&";
+ }
+
+ // Add the required request parameters
+ boolean question = temp.indexOf('?') >= 0;
+ Iterator keys = params.keySet().iterator();
+ while (keys.hasNext())
+ {
+ String key = (String) keys.next();
+ Object value = params.get(key);
+ ...
[truncated message content] |