Author: konstantin.mishin
Date: 2010-10-25 12:29:09 -0400 (Mon, 25 Oct 2010)
New Revision: 19667
Added:
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/package-info.java
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/view/
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/view/facelets/
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/view/facelets/FileUploadHandler.java
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/fileupload.faces-config.xml
sandbox/trunk/ui/fileupload/ui/src/main/templates/fileupload.template.xml
Modified:
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/application/FileUploadPhaselistener.java
Log:
RF-9497
Modified:
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/application/FileUploadPhaselistener.java
===================================================================
---
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/application/FileUploadPhaselistener.java 2010-10-25
16:11:35 UTC (rev 19666)
+++
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/application/FileUploadPhaselistener.java 2010-10-25
16:29:09 UTC (rev 19667)
@@ -103,7 +103,7 @@
Map<String, String> queryParamMap =
parseQueryString(request.getQueryString());
String uid = queryParamMap.get(MultipartRequest.UPLOAD_FILES_ID);
if (uid != null && isMultipartRequest(request)) {
- if (maxRequestSize != 0 && request.getContentLength() >
maxRequestSize) {
+ if (maxRequestSize != 0 && externalContext.getRequestContentLength()
> maxRequestSize) {
boolean sendError =
Boolean.parseBoolean(queryParamMap.get(MultipartRequest.SEND_HTTP_ERROR));
if (sendError) {
printResponse(facesContext,
HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, null);
@@ -111,7 +111,7 @@
printResponse(facesContext, HttpServletResponse.SC_OK,
"<html
id=\"_richfaces_file_upload_size_restricted\"></html>");
}
- } else if (!checkFileCount(request, queryParamMap.get("id"))) {
+ } else if (!checkFileCount(externalContext,
queryParamMap.get("id"))) {
printResponse(facesContext, HttpServletResponse.SC_OK,
"<html
id=\"_richfaces_file_upload_forbidden\"></html>");
} else {
@@ -122,6 +122,9 @@
if (!multipartRequest.isDone()) {
printResponse(facesContext, HttpServletResponse.SC_OK,
"<html
id=\"_richfaces_file_upload_stopped\"></html>");
+ } else {
+
externalContext.getRequestMap().put(MultipartRequest.UPLOAD_FILES_ID, multipartRequest);
+ externalContext.setRequest(multipartRequest);
}
} catch (FileUploadException e) {
printResponse(facesContext,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null);
@@ -133,9 +136,9 @@
}
}
- private boolean checkFileCount(HttpServletRequest request, String idParameter) {
+ private boolean checkFileCount(ExternalContext externalContext, String idParameter)
{
//TODO implement this method
-// HttpSession session = request.getSession(false);
+// HttpSession session = externalContext.getSession(false);
//
// if (session != null) {
// Map<String, Integer> map = (Map<String, Integer>) session
Added:
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java
===================================================================
---
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java
(rev 0)
+++
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java 2010-10-25
16:29:09 UTC (rev 19667)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.event.FileUploadListener;
+import org.richfaces.event.UploadEvent;
+import org.richfaces.request.MultipartRequest;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+@JsfComponent(tag = @Tag(handler =
"org.richfaces.view.facelets.FileUploadHandler"),
+ renderer = @JsfRenderer(type = "org.richfaces.FileUploadRenderer"))
+public abstract class AbstractFileUpload extends UIComponentBase {
+
+ @Override
+ public void decode(FacesContext context) {
+ super.decode(context);
+ MultipartRequest request = (MultipartRequest)
context.getExternalContext().getRequestMap()
+ .get(MultipartRequest.UPLOAD_FILES_ID);
+ if (request != null) {
+ queueEvent(new UploadEvent(this, request.getUploadItems()));
+ }
+ }
+
+ /**
+ * <p>Add a new {@link FileUploadListener} to the set of listeners
+ * interested in being notified when {@link UploadEvent}s occur.</p>
+ *
+ * @param listener The {@link FileUploadListener} to be added
+ * @throws NullPointerException if <code>listener</code>
+ * is <code>null</code>
+ */
+ public void addFileUploadListener(FileUploadListener listener) {
+ addFacesListener(listener);
+ }
+
+
+ /**
+ * <p>Return the set of registered {@link FileUploadListener}s for this
+ * {@link AbstractFileUpload} instance. If there are no registered listeners,
+ * a zero-length array is returned.</p>
+ */
+ public FileUploadListener[] getFileUploadListeners() {
+ return (FileUploadListener[]) getFacesListeners(FileUploadListener.class);
+ }
+
+
+ /**
+ * <p>Remove an existing {@link FileUploadListener} (if any) from the
+ * set of listeners interested in being notified when
+ * {@link FileUploadListener}s occur.</p>
+ *
+ * @param listener The {@link FileUploadListener} to be removed
+ * @throws NullPointerException if <code>listener</code>
+ * is <code>null</code>
+ */
+ public void removeFileUploadListener(FileUploadListener listener) {
+ removeFacesListener(listener);
+ }
+}
\ No newline at end of file
Added:
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/package-info.java
===================================================================
---
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/package-info.java
(rev 0)
+++
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/package-info.java 2010-10-25
16:29:09 UTC (rev 19667)
@@ -0,0 +1,23 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+(a)org.richfaces.cdk.annotations.TagLibrary(uri =
"http://richfaces.org/fileUpload", shortName = "fu")
+package org.richfaces.component;
Added:
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/view/facelets/FileUploadHandler.java
===================================================================
---
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/view/facelets/FileUploadHandler.java
(rev 0)
+++
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/view/facelets/FileUploadHandler.java 2010-10-25
16:29:09 UTC (rev 19667)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.view.facelets;
+
+import javax.el.MethodExpression;
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.richfaces.component.AbstractFileUpload;
+import org.richfaces.event.FileUploadListener;
+import org.richfaces.event.UploadEvent;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class FileUploadHandler extends ComponentHandler {
+
+ public FileUploadHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset metaRuleset = super.createMetaRuleset(type);
+ metaRuleset.addRule(new MetaRule() {
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget
meta) {
+ if (meta.isTargetInstanceOf(AbstractFileUpload.class)) {
+ if ("fileUploadListener".equals(name)) {
+ return new MethodMetadata(attribute, UploadEvent.class) {
+ @Override
+ public void applyMetadata(final FaceletContext ctx, Object
instance) {
+ final MethodExpression expression =
getMethodExpression(ctx);
+ ((AbstractFileUpload) instance).addFileUploadListener(new
FileUploadListener(){
+ public void processUpload(UploadEvent event) {
+
expression.invoke(ctx.getFacesContext().getELContext(), new Object[] {event});
+ }
+ });
+ }
+ };
+ }
+ }
+ return null;
+ }
+ });
+ return metaRuleset;
+ }
+}
Added:
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/fileupload.faces-config.xml
===================================================================
---
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/fileupload.faces-config.xml
(rev 0)
+++
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/fileupload.faces-config.xml 2010-10-25
16:29:09 UTC (rev 19667)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+JBoss, Home of Professional Open Source
+Copyright ${year}, Red Hat, Inc. and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+
+This software 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
+Lesser General Public License for more details.
+
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+-->
+<faces-config version="2.0"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:cdk="http://jboss.org/schema/richfaces/cdk/extensions"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <lifecycle>
+ <phase-listener>org.richfaces.application.FileUploadPhaselistener</phase-listener>
+ </lifecycle>
+</faces-config>
Added: sandbox/trunk/ui/fileupload/ui/src/main/templates/fileupload.template.xml
===================================================================
--- sandbox/trunk/ui/fileupload/ui/src/main/templates/fileupload.template.xml
(rev 0)
+++ sandbox/trunk/ui/fileupload/ui/src/main/templates/fileupload.template.xml 2010-10-25
16:29:09 UTC (rev 19667)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+JBoss, Home of Professional Open Source
+Copyright ${year}, Red Hat, Inc. and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+
+This software 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
+Lesser General Public License for more details.
+
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+-->
+<cdk:root
xmlns="http://jboss.org/schema/richfaces/cdk/xhtml-el"
xmlns:cdk="http://jboss.org/schema/richfaces/cdk/core"
+
xmlns:cc="http://jboss.org/schema/richfaces/cdk/jsf/composite"
xmlns:c="http://jboss.org/schema/richfaces/cdk/jstl/core"
+
xmlns:xi="http://www.w3.org/2001/XInclude">
+ <cc:interface>
+ <cdk:class>org.richfaces.renderkit.html.FileUploadRenderer</cdk:class>
+ <cdk:superclass>org.richfaces.renderkit.RendererBase</cdk:superclass>
+ <cdk:component-family>org.richfaces.FileUpload</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.FileUploadRenderer</cdk:renderer-type>
+ <cdk:resource-dependency library="org.richfaces"
name="base-component.reslib" />
+ </cc:interface>
+ <cc:implementation>
+ <input name="#{clientId}" type="file" />
+ </cc:implementation>
+</cdk:root>