Seam SVN: r8291 - trunk/src/main/org/jboss/seam/navigation.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-05-28 07:57:16 -0400 (Wed, 28 May 2008)
New Revision: 8291
Modified:
trunk/src/main/org/jboss/seam/navigation/Pages.java
Log:
JBSEAM-2352 - don't actually set a value expression if the expression string isn't specified
Modified: trunk/src/main/org/jboss/seam/navigation/Pages.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-05-27 17:50:04 UTC (rev 8290)
+++ trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-05-28 11:57:16 UTC (rev 8291)
@@ -881,7 +881,7 @@
for (int i=stack.size()-1; i>=0; i--)
{
Page page = stack.get(i);
- if (page.getNoConversationViewId() != null && page.getNoConversationViewId().getExpressionString() != null)
+ if (page.getNoConversationViewId() != null)
{
String noConversationViewId = page.getNoConversationViewId().getValue();
if (noConversationViewId!=null)
@@ -890,9 +890,7 @@
}
}
}
- return this.noConversationViewId != null && this.noConversationViewId.getExpressionString() != null
- ? this.noConversationViewId.getValue()
- : null;
+ return this.noConversationViewId != null ? this.noConversationViewId.getValue() : null;
}
/**
@@ -930,7 +928,11 @@
Element root = getDocumentRoot(stream);
if (noConversationViewId==null) //let the setting in components.xml override the pages.xml
{
- noConversationViewId = Expressions.instance().createValueExpression(root.attributeValue("no-conversation-view-id"), String.class);
+ String noConversationViewIdString = root.attributeValue("no-conversation-view-id");
+ if (noConversationViewIdString != null)
+ {
+ noConversationViewId = Expressions.instance().createValueExpression(noConversationViewIdString, String.class);
+ }
}
if (loginViewId==null) //let the setting in components.xml override the pages.xml
{
@@ -1066,7 +1068,11 @@
page.setTimeout(Integer.parseInt(timeoutString));
}
- page.setNoConversationViewId(Expressions.instance().createValueExpression(element.attributeValue("no-conversation-view-id"), String.class));
+ String noConversationViewIdString = element.attributeValue("no-conversation-view-id");
+ if (noConversationViewIdString != null)
+ {
+ page.setNoConversationViewId(Expressions.instance().createValueExpression(noConversationViewIdString, String.class));
+ }
page.setConversationRequired("true".equals(element.attributeValue("conversation-required")));
page.setLoginRequired("true".equals(element.attributeValue("login-required")));
page.setScheme(element.attributeValue("scheme"));
16 years, 7 months
Seam SVN: r8290 - in tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam: init and 1 other directory.
by seam-commits@lists.jboss.org
Author: jbalunas(a)redhat.com
Date: 2008-05-27 13:50:04 -0400 (Tue, 27 May 2008)
New Revision: 8290
Modified:
tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/Seam.java
tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/init/DeploymentDescriptor.java
Log:
Port of JBSEAM-2917 to 2.0.2.SP1
Modified: tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/Seam.java
===================================================================
--- tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/Seam.java 2008-05-27 17:11:11 UTC (rev 8289)
+++ tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/Seam.java 2008-05-27 17:50:04 UTC (rev 8290)
@@ -11,7 +11,9 @@
import static org.jboss.seam.util.EJB.STATELESS;
import static org.jboss.seam.util.EJB.name;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.persistence.Entity;
@@ -35,30 +37,35 @@
*/
public class Seam
{
-
private static final Map<Class, String> COMPONENT_NAME_CACHE = new ConcurrentHashMap<Class, String>();
- private static final Map<String, EjbDescriptor> EJB_DESCRIPTOR_CACHE = new ConcurrentHashMap<String, EjbDescriptor>();
+ private static final Map<Class, EjbDescriptor> EJB_DESCRIPTOR_CACHE = new ConcurrentHashMap<Class, EjbDescriptor>();
+ private static final Set<ClassLoader> CLASSLOADERS_LOADED = new HashSet<ClassLoader>();
- public static EjbDescriptor getEjbDescriptor(String className)
+ public static EjbDescriptor getEjbDescriptor(Class clazz)
{
- EjbDescriptor info = EJB_DESCRIPTOR_CACHE.get(className);
+ EjbDescriptor info = EJB_DESCRIPTOR_CACHE.get(clazz);
if (info != null)
{
return info;
}
- else
+ else if (!CLASSLOADERS_LOADED.contains(clazz.getClassLoader()))
{
- Map<String, EjbDescriptor> ejbDescriptors = new DeploymentDescriptor().getEjbDescriptors();
- EJB_DESCRIPTOR_CACHE.putAll(ejbDescriptors);
- return ejbDescriptors.get(className);
+ cacheEjbDescriptors(clazz);
+ return EJB_DESCRIPTOR_CACHE.get(clazz);
}
+
+ return null;
}
- // TODO Better impl
- static EjbDescriptor getEjbDescriptor(Class clazz)
+ private synchronized static void cacheEjbDescriptors(Class clazz)
{
- return getEjbDescriptor(clazz.getName());
- }
+ if (!CLASSLOADERS_LOADED.contains(clazz.getClassLoader()))
+ {
+ Map<Class, EjbDescriptor> ejbDescriptors = new DeploymentDescriptor(clazz).getEjbDescriptors();
+ EJB_DESCRIPTOR_CACHE.putAll(ejbDescriptors);
+ CLASSLOADERS_LOADED.add(clazz.getClassLoader());
+ }
+ }
/**
* Get the default scope
@@ -161,7 +168,7 @@
}
else
{
- EjbDescriptor ejbDescriptor = Seam.getEjbDescriptor(clazz.getName());
+ EjbDescriptor ejbDescriptor = Seam.getEjbDescriptor(clazz);
if (ejbDescriptor != null)
{
return ejbDescriptor.getBeanType() == ComponentType.ENTITY_BEAN ? clazz : null;
Modified: tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/init/DeploymentDescriptor.java
===================================================================
--- tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/init/DeploymentDescriptor.java 2008-05-27 17:11:11 UTC (rev 8289)
+++ tags/JBoss_Seam_2_0_2_SP1/src/main/org/jboss/seam/init/DeploymentDescriptor.java 2008-05-27 17:50:04 UTC (rev 8290)
@@ -23,10 +23,16 @@
{
private static final LogProvider log = Logging.getLogProvider(Initialization.class);
- private Map<String, EjbDescriptor> ejbDescriptors = new HashMap<String, EjbDescriptor>();
+ private Map<Class, EjbDescriptor> ejbDescriptors = new HashMap<Class, EjbDescriptor>();
+ private Class componentClass;
- public DeploymentDescriptor()
+ public DeploymentDescriptor(Class clazz)
{
+ componentClass = clazz;
+ if (clazz.getClassLoader() == null) {
+ return;
+ }
+
try
{
InputStream ejbJarXml = Resources.getResourceAsStream("META-INF/ejb-jar.xml", null);
@@ -54,7 +60,7 @@
}
}
- public Map<String, EjbDescriptor> getEjbDescriptors()
+ public Map<Class, EjbDescriptor> getEjbDescriptors()
{
return ejbDescriptors;
}
@@ -197,6 +203,14 @@
protected void add(EjbDescriptor descriptor)
{
- ejbDescriptors.put(descriptor.getEjbClassName(), descriptor);
+ try
+ {
+ Class ejbClass = componentClass.getClassLoader().loadClass( descriptor.getEjbClassName() );
+ ejbDescriptors.put(ejbClass, descriptor);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ log.warn("Could not load EJB class: " + descriptor.getEjbClassName());
+ }
}
}
16 years, 7 months
Seam SVN: r8289 - in tags/JBoss_Seam_2_0_2_SP1: seam-gen and 1 other directory.
by seam-commits@lists.jboss.org
Author: jbalunas(a)redhat.com
Date: 2008-05-27 13:11:11 -0400 (Tue, 27 May 2008)
New Revision: 8289
Modified:
tags/JBoss_Seam_2_0_2_SP1/build/common.build.xml
tags/JBoss_Seam_2_0_2_SP1/seam-gen/build.xml
Log:
Port of JBSEAM-3017 to 2.0.2.SP1
Modified: tags/JBoss_Seam_2_0_2_SP1/build/common.build.xml
===================================================================
--- tags/JBoss_Seam_2_0_2_SP1/build/common.build.xml 2008-05-27 16:41:08 UTC (rev 8288)
+++ tags/JBoss_Seam_2_0_2_SP1/build/common.build.xml 2008-05-27 17:11:11 UTC (rev 8289)
@@ -118,6 +118,7 @@
<copyDependencies id="pdf" pom="${pdf.pom}" todir="${lib.dir}" scope="runtime" />
<copyDependencies id="remoting" pom="${remoting.pom}" todir="${lib.dir}" scope="runtime" />
<copyDependencies id="ui" pom="${ui.pom}" todir="${lib.dir}" scope="runtime" />
+ <copyDependencies id="gen" pom="${gen.pom}" todir="${lib.dir}" scope="runtime" />
<copyDependencies id="core" pom="${core.pom}" todir="${lib.dir}" scope="compile" />
<copyDependencies id="debug" pom="${debug.pom}" todir="${lib.dir}" scope="compile" />
<copyDependencies id="ioc" pom="${ioc.pom}" todir="${lib.dir}" scope="compile" />
@@ -125,6 +126,7 @@
<copyDependencies id="pdf" pom="${pdf.pom}" todir="${lib.dir}" scope="compile" />
<copyDependencies id="remoting" pom="${remoting.pom}" todir="${lib.dir}" scope="compile" />
<copyDependencies id="ui" pom="${ui.pom}" todir="${lib.dir}" scope="compile" />
+ <copyDependencies id="gen" pom="${gen.pom}" todir="${lib.dir}" scope="compile" />
<property name="copyseamdependenciesdone" value="true" />
</target>
@@ -334,4 +336,4 @@
<artifact:install-provider artifactId="wagon-webdav" version="1.0-beta-2"/>
</target>
-</project>
\ No newline at end of file
+</project>
Modified: tags/JBoss_Seam_2_0_2_SP1/seam-gen/build.xml
===================================================================
--- tags/JBoss_Seam_2_0_2_SP1/seam-gen/build.xml 2008-05-27 16:41:08 UTC (rev 8288)
+++ tags/JBoss_Seam_2_0_2_SP1/seam-gen/build.xml 2008-05-27 17:11:11 UTC (rev 8289)
@@ -8,7 +8,7 @@
<property file="./build.properties" />
<import file="${seam.dir}/build/common.build.xml" />
- <target name="init" depends="initpoms">
+ <target name="init">
<path id="seam-gen.path" path="${seam.dir}/lib/jboss-seam-gen.jar" />
<!-- taskdefs -->
@@ -39,8 +39,6 @@
<taskdef name="pathFixer"
classname="org.jboss.seam.tool.FixPathTask"
classpathref="seam-gen.path"/>
-
- <copyDependencies pom="${gen.pom}" id="gen" scope="runtime" todir="${lib.dir}/gen" />
</target>
<target name="init-properties" depends="init">
@@ -1060,9 +1058,13 @@
<target name="init-generate">
<path id="htools.classpath">
- <fileset dir="${lib.dir}/gen">
- <include name="*.jar"/>
- </fileset>
+ <pathelement path="../lib/ant.jar"/>
+ <pathelement path="../lib/hibernate-tools.jar"/>
+ <pathelement path="../lib/freemarker.jar"/>
+ <pathelement path="../lib/jboss-seam.jar"/>
+ <pathelement path="../lib/runtime.jar"/>
+ <pathelement path="../lib/common.jar"/>
+ <pathelement path="../lib/text.jar"/>
<pathelement path="../lib/dom4j.jar" />
<pathelement path="../lib/persistence-api.jar" />
<pathelement path="../lib/hibernate.jar" />
16 years, 7 months
Seam SVN: r8288 - trunk.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2008-05-27 12:41:08 -0400 (Tue, 27 May 2008)
New Revision: 8288
Modified:
trunk/seam21migration.txt
Log:
note about change to default name of Seam-managed Hibernate session
Modified: trunk/seam21migration.txt
===================================================================
--- trunk/seam21migration.txt 2008-05-27 16:35:44 UTC (rev 8287)
+++ trunk/seam21migration.txt 2008-05-27 16:41:08 UTC (rev 8288)
@@ -26,9 +26,44 @@
EntityConverter configuration
-----------------------------
-If you need to configure which entity manager to use, this is now done on the
+If you need to configure which entity manager to use, this is now done on the
entity-loader component. See the documentation for details.
+Assumed name for managed Hibernate session
+------------------------------------------
+
+Several areas of Seam, including the Seam Application Framework, rely on a
+naming convention for the Seam-managed persistence context (JPA) and Hibernate
+session. Prior to Seam 2.1, the assumed name of the managed Hibernate session
+was "session". However, session is a very overloaded name in Seam and the Java
+Servlet API. To make it less ambigous, the default was changed to
+"hibernateSession".
+
+The benefit now is that when you inject or resolve the Hibernate session, you
+know that is the refernece you are getting (rather than the HTTP session, mail
+session, or some other "session").
+
+You would inject it as follows:
+
+@In private Session hibernateSession;
+
+or
+
+@In(name = "hibernateSession") private Session session;
+
+If the name of your Seam-managed Hibernate session is "session", you can still
+inject this reference explictly using the session property:
+
+<framework:hibernate-entity-home session="#{session}".../>
+<transaction:entity-transaction session="#{session}".../>
+
+The alternative is to override the getPersistenceContextName() method on any
+persistence controller in the Seam Application Framework:
+
+public String getPersistenceContextName() {
+ "session";
+}
+
Security
--------
@@ -41,4 +76,4 @@
In Seam 2.1, rule-based permission checks are now carried out by the RuleBasedPermissionResolver,
requiring that it is configured with the security rules instead of Identity:
- <security:rule-based-permission-resolver security-rules="#{securityRules}"/>
\ No newline at end of file
+ <security:rule-based-permission-resolver security-rules="#{securityRules}"/>
16 years, 7 months
Seam SVN: r8287 - in tags/JBoss_Seam_2_0_2_SP1: build and 1 other directory.
by seam-commits@lists.jboss.org
Author: jbalunas(a)redhat.com
Date: 2008-05-27 12:35:44 -0400 (Tue, 27 May 2008)
New Revision: 8287
Modified:
tags/JBoss_Seam_2_0_2_SP1/build/default.build.properties
tags/JBoss_Seam_2_0_2_SP1/changelog.txt
tags/JBoss_Seam_2_0_2_SP1/readme.txt
Log:
Updated version information for 2.0.2.SP1
Modified: tags/JBoss_Seam_2_0_2_SP1/build/default.build.properties
===================================================================
--- tags/JBoss_Seam_2_0_2_SP1/build/default.build.properties 2008-05-27 16:23:10 UTC (rev 8286)
+++ tags/JBoss_Seam_2_0_2_SP1/build/default.build.properties 2008-05-27 16:35:44 UTC (rev 8287)
@@ -8,7 +8,7 @@
major.version 2
minor.version .0
patchlevel .2
-qualifier .GA
+qualifier .SP1
#
# Other program locations
# -----------------------
Modified: tags/JBoss_Seam_2_0_2_SP1/changelog.txt
===================================================================
--- tags/JBoss_Seam_2_0_2_SP1/changelog.txt 2008-05-27 16:23:10 UTC (rev 8286)
+++ tags/JBoss_Seam_2_0_2_SP1/changelog.txt 2008-05-27 16:35:44 UTC (rev 8287)
@@ -1,6 +1,13 @@
JBoss Seam Changelog
====================
+Release Notes - JBoss Seam - Version 2.0.2.SP1
+
+** Bug
+ * [ JBSEAM-2917 ] Bad cache in getEjbDescriptor
+ * [ JBSEAM-3017 ] Seam-gen downloading from maven
+ * [ JBSEAM-3024 ] Performance issues in 2.0.2 release
+
Release Notes - JBoss Seam - Version 2.0.2.GA
** Bug
Modified: tags/JBoss_Seam_2_0_2_SP1/readme.txt
===================================================================
--- tags/JBoss_Seam_2_0_2_SP1/readme.txt 2008-05-27 16:23:10 UTC (rev 8286)
+++ tags/JBoss_Seam_2_0_2_SP1/readme.txt 2008-05-27 16:35:44 UTC (rev 8287)
@@ -1,6 +1,6 @@
JBoss Seam - Contextual Component framework for Java EE 5
=========================================================
-version 2.0.2.GA, May 2008
+version 2.0.2.SP1, May 2008
This software is distributed under the terms of the FSF Lesser Gnu
Public License (see lgpl.txt).
16 years, 7 months
Seam SVN: r8286 - tags.
by seam-commits@lists.jboss.org
Author: jbalunas(a)redhat.com
Date: 2008-05-27 12:23:10 -0400 (Tue, 27 May 2008)
New Revision: 8286
Added:
tags/JBoss_Seam_2_0_2_SP1/
Log:
create JBoss_Seam_2_0_2_SP1 tag from JBoss_Seam_2_0_2_GA tag
Copied: tags/JBoss_Seam_2_0_2_SP1 (from rev 8285, tags/JBoss_Seam_2_0_2_GA)
16 years, 7 months
Seam SVN: r8285 - trunk/src/main/org/jboss/seam/navigation.
by seam-commits@lists.jboss.org
Author: christian.bauer(a)jboss.com
Date: 2008-05-27 08:46:07 -0400 (Tue, 27 May 2008)
New Revision: 8285
Modified:
trunk/src/main/org/jboss/seam/navigation/Pages.java
Log:
JBSEAM-2352, more attempts fixing the NPE
Modified: trunk/src/main/org/jboss/seam/navigation/Pages.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-05-26 14:27:44 UTC (rev 8284)
+++ trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-05-27 12:46:07 UTC (rev 8285)
@@ -881,7 +881,7 @@
for (int i=stack.size()-1; i>=0; i--)
{
Page page = stack.get(i);
- if (page.getNoConversationViewId() != null)
+ if (page.getNoConversationViewId() != null && page.getNoConversationViewId().getExpressionString() != null)
{
String noConversationViewId = page.getNoConversationViewId().getValue();
if (noConversationViewId!=null)
@@ -890,7 +890,9 @@
}
}
}
- return this.noConversationViewId != null ? this.noConversationViewId.getValue() : null;
+ return this.noConversationViewId != null && this.noConversationViewId.getExpressionString() != null
+ ? this.noConversationViewId.getValue()
+ : null;
}
/**
16 years, 7 months
Seam SVN: r8284 - trunk/src/main/org/jboss/seam/navigation.
by seam-commits@lists.jboss.org
Author: christian.bauer(a)jboss.com
Date: 2008-05-26 10:27:44 -0400 (Mon, 26 May 2008)
New Revision: 8284
Modified:
trunk/src/main/org/jboss/seam/navigation/Pages.java
Log:
JBSEAM-2352, Fix NPE
Modified: trunk/src/main/org/jboss/seam/navigation/Pages.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-05-26 11:03:31 UTC (rev 8283)
+++ trunk/src/main/org/jboss/seam/navigation/Pages.java 2008-05-26 14:27:44 UTC (rev 8284)
@@ -881,13 +881,16 @@
for (int i=stack.size()-1; i>=0; i--)
{
Page page = stack.get(i);
- String noConversationViewId = page.getNoConversationViewId().getValue();
- if (noConversationViewId!=null)
+ if (page.getNoConversationViewId() != null)
{
- return noConversationViewId;
+ String noConversationViewId = page.getNoConversationViewId().getValue();
+ if (noConversationViewId!=null)
+ {
+ return noConversationViewId;
+ }
}
}
- return this.noConversationViewId.getValue();
+ return this.noConversationViewId != null ? this.noConversationViewId.getValue() : null;
}
/**
16 years, 7 months
Seam SVN: r8283 - trunk/src/main/org/jboss/seam/web.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2008-05-26 07:03:31 -0400 (Mon, 26 May 2008)
New Revision: 8283
Added:
trunk/src/main/org/jboss/seam/web/MultipartRequestImpl.java
Modified:
trunk/src/main/org/jboss/seam/web/MultipartFilter.java
trunk/src/main/org/jboss/seam/web/MultipartRequest.java
Log:
JBSEAM-2982
Modified: trunk/src/main/org/jboss/seam/web/MultipartFilter.java
===================================================================
--- trunk/src/main/org/jboss/seam/web/MultipartFilter.java 2008-05-25 12:55:39 UTC (rev 8282)
+++ trunk/src/main/org/jboss/seam/web/MultipartFilter.java 2008-05-26 11:03:31 UTC (rev 8283)
@@ -77,7 +77,7 @@
if (isMultipartRequest(httpRequest))
{
- chain.doFilter(new MultipartRequest(httpRequest, createTempFiles,
+ chain.doFilter(new MultipartRequestImpl(httpRequest, createTempFiles,
maxRequestSize), response);
}
else
Modified: trunk/src/main/org/jboss/seam/web/MultipartRequest.java
===================================================================
--- trunk/src/main/org/jboss/seam/web/MultipartRequest.java 2008-05-25 12:55:39 UTC (rev 8282)
+++ trunk/src/main/org/jboss/seam/web/MultipartRequest.java 2008-05-26 11:03:31 UTC (rev 8283)
@@ -1,633 +1,20 @@
package org.jboss.seam.web;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.rmi.server.UID;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
/**
- * Request wrapper for supporting multipart requests, used for file uploading.
- *
+ * Interface that declares multipart-specific API methods, to enable easier mocking of multipart
+ * requests.
+ *
* @author Shane Bryzak
*/
-public class MultipartRequest extends HttpServletRequestWrapper
-{
- private static final String PARAM_NAME = "name";
- private static final String PARAM_FILENAME = "filename";
- private static final String PARAM_CONTENT_TYPE = "Content-Type";
-
- private static final int BUFFER_SIZE = 2048;
- private static final int CHUNK_SIZE = 512;
-
- private boolean createTempFiles;
-
- private String encoding = null;
-
- private Map<String,Param> parameters = null;
-
- private enum ReadState { BOUNDARY, HEADERS, DATA }
-
- private static final byte CR = 0x0d;
- private static final byte LF = 0x0a;
- private static final byte[] CR_LF = {CR,LF};
-
- private abstract class Param
- {
- private String name;
-
- public Param(String name)
- {
- this.name = name;
- }
-
- public String getName()
- {
- return name;
- }
-
- public abstract void appendData(byte[] data, int start, int length)
- throws IOException;
- }
-
- private class ValueParam extends Param
- {
- private Object value = null;
- private ByteArrayOutputStream buf = new ByteArrayOutputStream();
-
- public ValueParam(String name)
- {
- super(name);
- }
-
- @Override
- public void appendData(byte[] data, int start, int length)
- throws IOException
- {
- buf.write(data, start, length);
- }
-
- public void complete()
- throws UnsupportedEncodingException
- {
- String val = encoding == null ? new String(buf.toByteArray()) :
- new String(buf.toByteArray(), encoding);
- if (value == null)
- {
- value = val;
- }
- else
- {
- if (!(value instanceof List))
- {
- List<String> v = new ArrayList<String>();
- v.add((String) value);
- value = v;
- }
-
- ((List) value).add(val);
- }
- buf.reset();
- }
-
- public Object getValue()
- {
- return value;
- }
- }
-
- private class FileParam extends Param
- {
- private String filename;
- private String contentType;
- private int fileSize;
-
- private ByteArrayOutputStream bOut = null;
- private FileOutputStream fOut = null;
- private File tempFile = null;
-
- public FileParam(String name)
- {
- super(name);
- }
-
- public String getFilename()
- {
- return filename;
- }
-
- public void setFilename(String filename)
- {
- this.filename = filename;
- }
-
- public String getContentType()
- {
- return contentType;
- }
-
- public void setContentType(String contentType)
- {
- this.contentType = contentType;
- }
-
- public int getFileSize()
- {
- return fileSize;
- }
-
- public void createTempFile()
- {
- try
- {
- tempFile = File.createTempFile(new UID().toString().replace(":", "-"), ".upload");
- tempFile.deleteOnExit();
- fOut = new FileOutputStream(tempFile);
- }
- catch (IOException ex)
- {
- throw new FileUploadException("Could not create temporary file");
- }
- }
-
- @Override
- public void appendData(byte[] data, int start, int length)
- throws IOException
- {
- if (fOut != null)
- {
- fOut.write(data, start, length);
- fOut.flush();
- }
- else
- {
- if (bOut == null) bOut = new ByteArrayOutputStream();
- bOut.write(data, start, length);
- }
-
- fileSize += length;
- }
-
- public byte[] getData()
- {
- if (fOut != null)
- {
- try
- {
- fOut.close();
- }
- catch (IOException ex) {}
- fOut = null;
- }
-
- if (bOut != null)
- {
- return bOut.toByteArray();
- }
- else if (tempFile != null)
- {
- if (tempFile.exists())
- {
- try
- {
- FileInputStream fIn = new FileInputStream(tempFile);
- ByteArrayOutputStream bOut = new ByteArrayOutputStream();
- byte[] buf = new byte[512];
- int read = fIn.read(buf);
- while (read != -1)
- {
- bOut.write(buf, 0, read);
- read = fIn.read(buf);
- }
- bOut.flush();
-
- fIn.close();
- tempFile.delete();
- return bOut.toByteArray();
- }
- catch (IOException ex) { /* too bad? */}
- }
- }
-
- return null;
- }
-
- public InputStream getInputStream()
- {
- if (fOut != null)
- {
- try
- {
- fOut.close();
- }
- catch (IOException ex) {}
- fOut = null;
- }
-
- if (bOut!=null)
- {
- return new ByteArrayInputStream(bOut.toByteArray());
- }
- else if (tempFile!=null)
- {
- try
- {
- return new FileInputStream(tempFile) {
- @Override
- public void close() throws IOException
- {
- super.close();
- tempFile.delete();
- }
- };
- }
- catch (FileNotFoundException ex) { }
- }
-
- return null;
- }
- }
-
- private HttpServletRequest request;
-
- public MultipartRequest(HttpServletRequest request, boolean createTempFiles,
- int maxRequestSize)
- {
- super(request);
- this.request = request;
- this.createTempFiles = createTempFiles;
-
- String contentLength = request.getHeader("Content-Length");
- if (contentLength != null && maxRequestSize > 0 &&
- Integer.parseInt(contentLength) > maxRequestSize)
- {
- throw new FileUploadException("Multipart request is larger than allowed size");
- }
- }
-
- private void parseRequest()
- {
- byte[] boundaryMarker = getBoundaryMarker(request.getContentType());
- if (boundaryMarker == null)
- {
- throw new FileUploadException("The request was rejected because "
- + "no multipart boundary was found");
- }
-
- encoding = request.getCharacterEncoding();
-
- parameters = new HashMap<String,Param>();
-
- try
- {
- byte[] buffer = new byte[BUFFER_SIZE];
- Map<String,String> headers = new HashMap<String,String>();
-
- ReadState readState = ReadState.BOUNDARY;
-
- InputStream input = request.getInputStream();
- int read = input.read(buffer);
- int pos = 0;
-
- Param p = null;
-
- while (read != -1)
- {
- for (int i = 0; i < read; i++)
- {
- switch (readState)
- {
- case BOUNDARY:
- {
- if (checkSequence(buffer, i, boundaryMarker) && checkSequence(buffer, i + 2, CR_LF))
- {
- readState = ReadState.HEADERS;
- i += 2;
- pos = i + 1;
- }
- break;
- }
- case HEADERS:
- {
- if (checkSequence(buffer, i, CR_LF))
- {
- String param = (encoding == null) ?
- new String(buffer, pos, i - pos - 1) :
- new String(buffer, pos, i - pos - 1, encoding);
- parseParams(param, ";", headers);
-
- if (checkSequence(buffer, i + CR_LF.length, CR_LF))
- {
- readState = ReadState.DATA;
- i += CR_LF.length;
- pos = i + 1;
-
- String paramName = headers.get(PARAM_NAME);
- if (paramName != null)
- {
- if (headers.containsKey(PARAM_FILENAME))
- {
- FileParam fp = new FileParam(paramName);
- if (createTempFiles) fp.createTempFile();
- fp.setContentType(headers.get(PARAM_CONTENT_TYPE));
- fp.setFilename(headers.get(PARAM_FILENAME));
- p = fp;
- }
- else
- {
- if (parameters.containsKey(paramName))
- {
- p = parameters.get(paramName);
- }
- else
- {
- p = new ValueParam(paramName);
- }
- }
-
- if (!parameters.containsKey(paramName))
- {
- parameters.put(paramName, p);
- }
- }
-
- headers.clear();
- }
- else
- {
- pos = i + 1;
- }
- }
- break;
- }
- case DATA:
- {
- // If we've encountered another boundary...
- if (checkSequence(buffer, i - boundaryMarker.length - CR_LF.length, CR_LF) &&
- checkSequence(buffer, i, boundaryMarker))
- {
- // Write any data before the boundary (that hasn't already been written) to the param
- if (pos < i - boundaryMarker.length - CR_LF.length - 1)
- {
- p.appendData(buffer, pos, i - pos - boundaryMarker.length - CR_LF.length - 1);
- }
-
- if (p instanceof ValueParam) ((ValueParam) p).complete();
-
- if (checkSequence(buffer, i + CR_LF.length, CR_LF))
- {
- i += CR_LF.length;
- pos = i + 1;
- }
- else
- {
- pos = i;
- }
-
- readState = ReadState.HEADERS;
- }
- // Otherwise write whatever data we have to the param
- else if (i > (pos + boundaryMarker.length + CHUNK_SIZE + CR_LF.length))
- {
- p.appendData(buffer, pos, CHUNK_SIZE);
- pos += CHUNK_SIZE;
- }
- break;
- }
- }
- }
-
- if (pos < read)
- {
- // move the bytes that weren't read to the start of the buffer
- int bytesNotRead = read - pos;
- System.arraycopy(buffer, pos, buffer, 0, bytesNotRead);
- read = input.read(buffer, bytesNotRead, buffer.length - bytesNotRead);
- read += bytesNotRead;
- }
- else
- {
- read = input.read(buffer);
- }
-
- pos = 0;
- }
- }
- catch (IOException ex)
- {
- throw new FileUploadException("IO Error parsing multipart request", ex);
- }
- }
-
- private byte[] getBoundaryMarker(String contentType)
- {
- Map<String, Object> params = parseParams(contentType, ";");
- String boundaryStr = (String) params.get("boundary");
-
- if (boundaryStr == null) return null;
-
- try
- {
- return boundaryStr.getBytes("ISO-8859-1");
- }
- catch (UnsupportedEncodingException e)
- {
- return boundaryStr.getBytes();
- }
- }
-
- /**
- * Checks if a specified sequence of bytes ends at a specific position
- * within a byte array.
- *
- * @param data
- * @param pos
- * @param seq
- * @return boolean indicating if the sequence was found at the specified position
- */
- private boolean checkSequence(byte[] data, int pos, byte[] seq)
- {
- if (pos - seq.length < -1 || pos >= data.length)
- return false;
-
- for (int i = 0; i < seq.length; i++)
- {
- if (data[(pos - seq.length) + i + 1] != seq[i])
- return false;
- }
-
- return true;
- }
-
- private static final Pattern PARAM_VALUE_PATTERN = Pattern
- .compile("^\\s*([^\\s=]+)\\s*[=:]\\s*(.+)\\s*$");
-
- private Map parseParams(String paramStr, String separator)
- {
- Map<String,String> paramMap = new HashMap<String, String>();
- parseParams(paramStr, separator, paramMap);
- return paramMap;
- }
-
- private void parseParams(String paramStr, String separator, Map paramMap)
- {
- String[] parts = paramStr.split("[" + separator + "]");
-
- for (String part : parts)
- {
- Matcher m = PARAM_VALUE_PATTERN.matcher(part);
- if (m.matches())
- {
- String key = m.group(1);
- String value = m.group(2);
-
- // Strip double quotes
- if (value.startsWith("\"") && value.endsWith("\""))
- value = value.substring(1, value.length() - 1);
-
- paramMap.put(key, value);
- }
- }
- }
-
- private Param getParam(String name)
- {
- if (parameters == null)
- parseRequest();
- return parameters.get(name);
- }
-
- @Override
- public Enumeration getParameterNames()
- {
- if (parameters == null)
- parseRequest();
-
- return Collections.enumeration(parameters.keySet());
- }
-
- public byte[] getFileBytes(String name)
- {
- Param p = getParam(name);
- return (p != null && p instanceof FileParam) ?
- ((FileParam) p).getData() : null;
- }
-
- public InputStream getFileInputStream(String name)
- {
- Param p = getParam(name);
- return (p != null && p instanceof FileParam) ?
- ((FileParam) p).getInputStream() : null;
- }
-
- public String getFileContentType(String name)
- {
- Param p = getParam(name);
- return (p != null && p instanceof FileParam) ?
- ((FileParam) p).getContentType() : null;
- }
-
- public String getFileName(String name)
- {
- Param p = getParam(name);
- return (p != null && p instanceof FileParam) ?
- ((FileParam) p).getFilename() : null;
- }
-
- public int getFileSize(String name)
- {
- Param p = getParam(name);
- return (p != null && p instanceof FileParam) ?
- ((FileParam) p).getFileSize() : -1;
- }
-
- @Override
- public String getParameter(String name)
- {
- Param p = getParam(name);
- if (p != null && p instanceof ValueParam)
- {
- ValueParam vp = (ValueParam) p;
- if (vp.getValue() instanceof String) return (String) vp.getValue();
- }
- else if (p != null && p instanceof FileParam)
- {
- return "---BINARY DATA---";
- }
- else
- {
- return super.getParameter(name);
- }
-
- return null;
- }
-
- @Override
- public String[] getParameterValues(String name)
- {
- Param p = getParam(name);
- if (p != null && p instanceof ValueParam)
- {
- ValueParam vp = (ValueParam) p;
- if (vp.getValue() instanceof List)
- {
- List vals = (List) vp.getValue();
- String[] values = new String[vals.size()];
- vals.toArray(values);
- return values;
- }
- else
- {
- return new String[] {(String) vp.getValue()};
- }
- }
- else
- {
- return super.getParameterValues(name);
- }
- }
-
- @Override
- public Map getParameterMap()
- {
- if (parameters == null)
- parseRequest();
-
- Map<String,Object> params = new HashMap<String,Object>(super.getParameterMap());
-
- for (String name : parameters.keySet())
- {
- Param p = parameters.get(name);
- if (p instanceof ValueParam)
- {
- ValueParam vp = (ValueParam) p;
- if (vp.getValue() instanceof String)
- {
- params.put(name, vp.getValue());
- }
- else if (vp.getValue() instanceof List)
- {
- params.put(name, getParameterValues(name));
- }
- }
- }
-
- return params;
- }
+public interface MultipartRequest extends HttpServletRequest
+{
+ byte[] getFileBytes(String name);
+ InputStream getFileInputStream(String name);
+ String getFileContentType(String name);
+ String getFileName(String name);
+ int getFileSize(String name);
}
Added: trunk/src/main/org/jboss/seam/web/MultipartRequestImpl.java
===================================================================
--- trunk/src/main/org/jboss/seam/web/MultipartRequestImpl.java (rev 0)
+++ trunk/src/main/org/jboss/seam/web/MultipartRequestImpl.java 2008-05-26 11:03:31 UTC (rev 8283)
@@ -0,0 +1,633 @@
+package org.jboss.seam.web;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.rmi.server.UID;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+/**
+ * Request wrapper for supporting multipart requests, used for file uploading.
+ *
+ * @author Shane Bryzak
+ */
+public class MultipartRequestImpl extends HttpServletRequestWrapper implements MultipartRequest
+{
+ private static final String PARAM_NAME = "name";
+ private static final String PARAM_FILENAME = "filename";
+ private static final String PARAM_CONTENT_TYPE = "Content-Type";
+
+ private static final int BUFFER_SIZE = 2048;
+ private static final int CHUNK_SIZE = 512;
+
+ private boolean createTempFiles;
+
+ private String encoding = null;
+
+ private Map<String,Param> parameters = null;
+
+ private enum ReadState { BOUNDARY, HEADERS, DATA }
+
+ private static final byte CR = 0x0d;
+ private static final byte LF = 0x0a;
+ private static final byte[] CR_LF = {CR,LF};
+
+ private abstract class Param
+ {
+ private String name;
+
+ public Param(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public abstract void appendData(byte[] data, int start, int length)
+ throws IOException;
+ }
+
+ private class ValueParam extends Param
+ {
+ private Object value = null;
+ private ByteArrayOutputStream buf = new ByteArrayOutputStream();
+
+ public ValueParam(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ public void appendData(byte[] data, int start, int length)
+ throws IOException
+ {
+ buf.write(data, start, length);
+ }
+
+ public void complete()
+ throws UnsupportedEncodingException
+ {
+ String val = encoding == null ? new String(buf.toByteArray()) :
+ new String(buf.toByteArray(), encoding);
+ if (value == null)
+ {
+ value = val;
+ }
+ else
+ {
+ if (!(value instanceof List))
+ {
+ List<String> v = new ArrayList<String>();
+ v.add((String) value);
+ value = v;
+ }
+
+ ((List) value).add(val);
+ }
+ buf.reset();
+ }
+
+ public Object getValue()
+ {
+ return value;
+ }
+ }
+
+ private class FileParam extends Param
+ {
+ private String filename;
+ private String contentType;
+ private int fileSize;
+
+ private ByteArrayOutputStream bOut = null;
+ private FileOutputStream fOut = null;
+ private File tempFile = null;
+
+ public FileParam(String name)
+ {
+ super(name);
+ }
+
+ public String getFilename()
+ {
+ return filename;
+ }
+
+ public void setFilename(String filename)
+ {
+ this.filename = filename;
+ }
+
+ public String getContentType()
+ {
+ return contentType;
+ }
+
+ public void setContentType(String contentType)
+ {
+ this.contentType = contentType;
+ }
+
+ public int getFileSize()
+ {
+ return fileSize;
+ }
+
+ public void createTempFile()
+ {
+ try
+ {
+ tempFile = File.createTempFile(new UID().toString().replace(":", "-"), ".upload");
+ tempFile.deleteOnExit();
+ fOut = new FileOutputStream(tempFile);
+ }
+ catch (IOException ex)
+ {
+ throw new FileUploadException("Could not create temporary file");
+ }
+ }
+
+ @Override
+ public void appendData(byte[] data, int start, int length)
+ throws IOException
+ {
+ if (fOut != null)
+ {
+ fOut.write(data, start, length);
+ fOut.flush();
+ }
+ else
+ {
+ if (bOut == null) bOut = new ByteArrayOutputStream();
+ bOut.write(data, start, length);
+ }
+
+ fileSize += length;
+ }
+
+ public byte[] getData()
+ {
+ if (fOut != null)
+ {
+ try
+ {
+ fOut.close();
+ }
+ catch (IOException ex) {}
+ fOut = null;
+ }
+
+ if (bOut != null)
+ {
+ return bOut.toByteArray();
+ }
+ else if (tempFile != null)
+ {
+ if (tempFile.exists())
+ {
+ try
+ {
+ FileInputStream fIn = new FileInputStream(tempFile);
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ byte[] buf = new byte[512];
+ int read = fIn.read(buf);
+ while (read != -1)
+ {
+ bOut.write(buf, 0, read);
+ read = fIn.read(buf);
+ }
+ bOut.flush();
+
+ fIn.close();
+ tempFile.delete();
+ return bOut.toByteArray();
+ }
+ catch (IOException ex) { /* too bad? */}
+ }
+ }
+
+ return null;
+ }
+
+ public InputStream getInputStream()
+ {
+ if (fOut != null)
+ {
+ try
+ {
+ fOut.close();
+ }
+ catch (IOException ex) {}
+ fOut = null;
+ }
+
+ if (bOut!=null)
+ {
+ return new ByteArrayInputStream(bOut.toByteArray());
+ }
+ else if (tempFile!=null)
+ {
+ try
+ {
+ return new FileInputStream(tempFile) {
+ @Override
+ public void close() throws IOException
+ {
+ super.close();
+ tempFile.delete();
+ }
+ };
+ }
+ catch (FileNotFoundException ex) { }
+ }
+
+ return null;
+ }
+ }
+
+ private HttpServletRequest request;
+
+ public MultipartRequestImpl(HttpServletRequest request, boolean createTempFiles,
+ int maxRequestSize)
+ {
+ super(request);
+ this.request = request;
+ this.createTempFiles = createTempFiles;
+
+ String contentLength = request.getHeader("Content-Length");
+ if (contentLength != null && maxRequestSize > 0 &&
+ Integer.parseInt(contentLength) > maxRequestSize)
+ {
+ throw new FileUploadException("Multipart request is larger than allowed size");
+ }
+ }
+
+ private void parseRequest()
+ {
+ byte[] boundaryMarker = getBoundaryMarker(request.getContentType());
+ if (boundaryMarker == null)
+ {
+ throw new FileUploadException("The request was rejected because "
+ + "no multipart boundary was found");
+ }
+
+ encoding = request.getCharacterEncoding();
+
+ parameters = new HashMap<String,Param>();
+
+ try
+ {
+ byte[] buffer = new byte[BUFFER_SIZE];
+ Map<String,String> headers = new HashMap<String,String>();
+
+ ReadState readState = ReadState.BOUNDARY;
+
+ InputStream input = request.getInputStream();
+ int read = input.read(buffer);
+ int pos = 0;
+
+ Param p = null;
+
+ while (read != -1)
+ {
+ for (int i = 0; i < read; i++)
+ {
+ switch (readState)
+ {
+ case BOUNDARY:
+ {
+ if (checkSequence(buffer, i, boundaryMarker) && checkSequence(buffer, i + 2, CR_LF))
+ {
+ readState = ReadState.HEADERS;
+ i += 2;
+ pos = i + 1;
+ }
+ break;
+ }
+ case HEADERS:
+ {
+ if (checkSequence(buffer, i, CR_LF))
+ {
+ String param = (encoding == null) ?
+ new String(buffer, pos, i - pos - 1) :
+ new String(buffer, pos, i - pos - 1, encoding);
+ parseParams(param, ";", headers);
+
+ if (checkSequence(buffer, i + CR_LF.length, CR_LF))
+ {
+ readState = ReadState.DATA;
+ i += CR_LF.length;
+ pos = i + 1;
+
+ String paramName = headers.get(PARAM_NAME);
+ if (paramName != null)
+ {
+ if (headers.containsKey(PARAM_FILENAME))
+ {
+ FileParam fp = new FileParam(paramName);
+ if (createTempFiles) fp.createTempFile();
+ fp.setContentType(headers.get(PARAM_CONTENT_TYPE));
+ fp.setFilename(headers.get(PARAM_FILENAME));
+ p = fp;
+ }
+ else
+ {
+ if (parameters.containsKey(paramName))
+ {
+ p = parameters.get(paramName);
+ }
+ else
+ {
+ p = new ValueParam(paramName);
+ }
+ }
+
+ if (!parameters.containsKey(paramName))
+ {
+ parameters.put(paramName, p);
+ }
+ }
+
+ headers.clear();
+ }
+ else
+ {
+ pos = i + 1;
+ }
+ }
+ break;
+ }
+ case DATA:
+ {
+ // If we've encountered another boundary...
+ if (checkSequence(buffer, i - boundaryMarker.length - CR_LF.length, CR_LF) &&
+ checkSequence(buffer, i, boundaryMarker))
+ {
+ // Write any data before the boundary (that hasn't already been written) to the param
+ if (pos < i - boundaryMarker.length - CR_LF.length - 1)
+ {
+ p.appendData(buffer, pos, i - pos - boundaryMarker.length - CR_LF.length - 1);
+ }
+
+ if (p instanceof ValueParam) ((ValueParam) p).complete();
+
+ if (checkSequence(buffer, i + CR_LF.length, CR_LF))
+ {
+ i += CR_LF.length;
+ pos = i + 1;
+ }
+ else
+ {
+ pos = i;
+ }
+
+ readState = ReadState.HEADERS;
+ }
+ // Otherwise write whatever data we have to the param
+ else if (i > (pos + boundaryMarker.length + CHUNK_SIZE + CR_LF.length))
+ {
+ p.appendData(buffer, pos, CHUNK_SIZE);
+ pos += CHUNK_SIZE;
+ }
+ break;
+ }
+ }
+ }
+
+ if (pos < read)
+ {
+ // move the bytes that weren't read to the start of the buffer
+ int bytesNotRead = read - pos;
+ System.arraycopy(buffer, pos, buffer, 0, bytesNotRead);
+ read = input.read(buffer, bytesNotRead, buffer.length - bytesNotRead);
+ read += bytesNotRead;
+ }
+ else
+ {
+ read = input.read(buffer);
+ }
+
+ pos = 0;
+ }
+ }
+ catch (IOException ex)
+ {
+ throw new FileUploadException("IO Error parsing multipart request", ex);
+ }
+ }
+
+ private byte[] getBoundaryMarker(String contentType)
+ {
+ Map<String, Object> params = parseParams(contentType, ";");
+ String boundaryStr = (String) params.get("boundary");
+
+ if (boundaryStr == null) return null;
+
+ try
+ {
+ return boundaryStr.getBytes("ISO-8859-1");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ return boundaryStr.getBytes();
+ }
+ }
+
+ /**
+ * Checks if a specified sequence of bytes ends at a specific position
+ * within a byte array.
+ *
+ * @param data
+ * @param pos
+ * @param seq
+ * @return boolean indicating if the sequence was found at the specified position
+ */
+ private boolean checkSequence(byte[] data, int pos, byte[] seq)
+ {
+ if (pos - seq.length < -1 || pos >= data.length)
+ return false;
+
+ for (int i = 0; i < seq.length; i++)
+ {
+ if (data[(pos - seq.length) + i + 1] != seq[i])
+ return false;
+ }
+
+ return true;
+ }
+
+ private static final Pattern PARAM_VALUE_PATTERN = Pattern
+ .compile("^\\s*([^\\s=]+)\\s*[=:]\\s*(.+)\\s*$");
+
+ private Map parseParams(String paramStr, String separator)
+ {
+ Map<String,String> paramMap = new HashMap<String, String>();
+ parseParams(paramStr, separator, paramMap);
+ return paramMap;
+ }
+
+ private void parseParams(String paramStr, String separator, Map paramMap)
+ {
+ String[] parts = paramStr.split("[" + separator + "]");
+
+ for (String part : parts)
+ {
+ Matcher m = PARAM_VALUE_PATTERN.matcher(part);
+ if (m.matches())
+ {
+ String key = m.group(1);
+ String value = m.group(2);
+
+ // Strip double quotes
+ if (value.startsWith("\"") && value.endsWith("\""))
+ value = value.substring(1, value.length() - 1);
+
+ paramMap.put(key, value);
+ }
+ }
+ }
+
+ private Param getParam(String name)
+ {
+ if (parameters == null)
+ parseRequest();
+ return parameters.get(name);
+ }
+
+ @Override
+ public Enumeration getParameterNames()
+ {
+ if (parameters == null)
+ parseRequest();
+
+ return Collections.enumeration(parameters.keySet());
+ }
+
+ public byte[] getFileBytes(String name)
+ {
+ Param p = getParam(name);
+ return (p != null && p instanceof FileParam) ?
+ ((FileParam) p).getData() : null;
+ }
+
+ public InputStream getFileInputStream(String name)
+ {
+ Param p = getParam(name);
+ return (p != null && p instanceof FileParam) ?
+ ((FileParam) p).getInputStream() : null;
+ }
+
+ public String getFileContentType(String name)
+ {
+ Param p = getParam(name);
+ return (p != null && p instanceof FileParam) ?
+ ((FileParam) p).getContentType() : null;
+ }
+
+ public String getFileName(String name)
+ {
+ Param p = getParam(name);
+ return (p != null && p instanceof FileParam) ?
+ ((FileParam) p).getFilename() : null;
+ }
+
+ public int getFileSize(String name)
+ {
+ Param p = getParam(name);
+ return (p != null && p instanceof FileParam) ?
+ ((FileParam) p).getFileSize() : -1;
+ }
+
+ @Override
+ public String getParameter(String name)
+ {
+ Param p = getParam(name);
+ if (p != null && p instanceof ValueParam)
+ {
+ ValueParam vp = (ValueParam) p;
+ if (vp.getValue() instanceof String) return (String) vp.getValue();
+ }
+ else if (p != null && p instanceof FileParam)
+ {
+ return "---BINARY DATA---";
+ }
+ else
+ {
+ return super.getParameter(name);
+ }
+
+ return null;
+ }
+
+ @Override
+ public String[] getParameterValues(String name)
+ {
+ Param p = getParam(name);
+ if (p != null && p instanceof ValueParam)
+ {
+ ValueParam vp = (ValueParam) p;
+ if (vp.getValue() instanceof List)
+ {
+ List vals = (List) vp.getValue();
+ String[] values = new String[vals.size()];
+ vals.toArray(values);
+ return values;
+ }
+ else
+ {
+ return new String[] {(String) vp.getValue()};
+ }
+ }
+ else
+ {
+ return super.getParameterValues(name);
+ }
+ }
+
+ @Override
+ public Map getParameterMap()
+ {
+ if (parameters == null)
+ parseRequest();
+
+ Map<String,Object> params = new HashMap<String,Object>(super.getParameterMap());
+
+ for (String name : parameters.keySet())
+ {
+ Param p = parameters.get(name);
+ if (p instanceof ValueParam)
+ {
+ ValueParam vp = (ValueParam) p;
+ if (vp.getValue() instanceof String)
+ {
+ params.put(name, vp.getValue());
+ }
+ else if (vp.getValue() instanceof List)
+ {
+ params.put(name, getParameterValues(name));
+ }
+ }
+ }
+
+ return params;
+ }
+}
16 years, 7 months
Seam SVN: r8282 - trunk/src/main/org/jboss/seam.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2008-05-25 08:55:39 -0400 (Sun, 25 May 2008)
New Revision: 8282
Modified:
trunk/src/main/org/jboss/seam/Seam.java
Log:
removed unnecessary null check
Modified: trunk/src/main/org/jboss/seam/Seam.java
===================================================================
--- trunk/src/main/org/jboss/seam/Seam.java 2008-05-25 12:55:06 UTC (rev 8281)
+++ trunk/src/main/org/jboss/seam/Seam.java 2008-05-25 12:55:39 UTC (rev 8282)
@@ -51,8 +51,7 @@
{
return info;
}
- else if (clazz.getClassLoader() == null ||
- (clazz.getClassLoader() != null && !CLASSLOADERS_LOADED.contains(clazz.getClassLoader())))
+ else if (!CLASSLOADERS_LOADED.contains(clazz.getClassLoader()))
{
cacheEjbDescriptors(clazz);
return EJB_DESCRIPTOR_CACHE.get(clazz);
16 years, 7 months