From richfaces-svn-commits at lists.jboss.org Mon Oct 25 12:29:11 2010 Content-Type: multipart/mixed; boundary="===============3936976810093127230==" MIME-Version: 1.0 From: richfaces-svn-commits at lists.jboss.org To: richfaces-svn-commits at lists.jboss.org Subject: [richfaces-svn-commits] JBoss Rich Faces SVN: r19667 - in sandbox/trunk/ui/fileupload/ui/src/main: java/org/richfaces/application and 5 other directories. Date: Mon, 25 Oct 2010 12:29:10 -0400 Message-ID: <201010251629.o9PGTALD000554@svn01.web.mwc.hst.phx2.redhat.com> --===============3936976810093127230== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/Abs= tractFileUpload.java sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/pac= kage-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.fa= ces-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/F= ileUploadPhaselistener.java Log: RF-9497 Modified: sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/applic= ation/FileUploadPhaselistener.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 queryParamMap =3D parseQueryString(request.get= QueryString()); String uid =3D queryParamMap.get(MultipartRequest.UPLOAD_FILES_ID); if (uid !=3D null && isMultipartRequest(request)) { - if (maxRequestSize !=3D 0 && request.getContentLength() > maxR= equestSize) { + if (maxRequestSize !=3D 0 && externalContext.getRequestContent= Length() > maxRequestSize) { boolean sendError =3D Boolean.parseBoolean(queryParamMap.g= et(MultipartRequest.SEND_HTTP_ERROR)); if (sendError) { printResponse(facesContext, HttpServletResponse.SC_REQ= UEST_ENTITY_TOO_LARGE, null); @@ -111,7 +111,7 @@ printResponse(facesContext, HttpServletResponse.SC_OK, ""); } - } else if (!checkFileCount(request, queryParamMap.get("id"))) { + } else if (!checkFileCount(externalContext, queryParamMap.get(= "id"))) { printResponse(facesContext, HttpServletResponse.SC_OK, ""); } else { @@ -122,6 +122,9 @@ if (!multipartRequest.isDone()) { printResponse(facesContext, HttpServletResponse.SC= _OK, ""); + } else { + externalContext.getRequestMap().put(MultipartReque= st.UPLOAD_FILES_ID, multipartRequest); + externalContext.setRequest(multipartRequest); } } catch (FileUploadException e) { printResponse(facesContext, HttpServletResponse.SC_INT= ERNAL_SERVER_ERROR, null); @@ -133,9 +136,9 @@ } } = - private boolean checkFileCount(HttpServletRequest request, String idPa= rameter) { + private boolean checkFileCount(ExternalContext externalContext, String= idParameter) { //TODO implement this method -// HttpSession session =3D request.getSession(false); +// HttpSession session =3D externalContext.getSession(false); // = // if (session !=3D null) { // Map map =3D (Map) session Added: sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component= /AbstractFileUpload.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/Ab= stractFileUpload.java (rev 0) +++ sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/Ab= stractFileUpload.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 + * = + */ +(a)JsfComponent(tag =3D @Tag(handler =3D "org.richfaces.view.facelets.File= UploadHandler"), + renderer =3D @JsfRenderer(type =3D "org.richfaces.FileUploadRenderer")) +public abstract class AbstractFileUpload extends UIComponentBase { + = + @Override + public void decode(FacesContext context) { + super.decode(context); + MultipartRequest request =3D (MultipartRequest) context.getExterna= lContext().getRequestMap() + .get(MultipartRequest.UPLOAD_FILES_ID); + if (request !=3D null) { + queueEvent(new UploadEvent(this, request.getUploadItems())); + } + } + = + /** + *

Add a new {@link FileUploadListener} to the set of listeners + * interested in being notified when {@link UploadEvent}s occur.

+ * + * @param listener The {@link FileUploadListener} to be added + * @throws NullPointerException if listener + * is null + */ + public void addFileUploadListener(FileUploadListener listener) { + addFacesListener(listener); + } + + + /** + *

Return the set of registered {@link FileUploadListener}s for this + * {@link AbstractFileUpload} instance. If there are no registered li= steners, + * a zero-length array is returned.

+ */ + public FileUploadListener[] getFileUploadListeners() { + return (FileUploadListener[]) getFacesListeners(FileUploadListener= .class); + } + + + /** + *

Remove an existing {@link FileUploadListener} (if any) from the + * set of listeners interested in being notified when + * {@link FileUploadListener}s occur.

+ * + * @param listener The {@link FileUploadListener} to be removed + * @throws NullPointerException if listener + * is null + */ + 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/pa= ckage-info.java (rev 0) +++ sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/pa= ckage-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 =3D "http://richfaces.org/= fileUpload", shortName =3D "fu") +package org.richfaces.component; Added: sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/view/face= lets/FileUploadHandler.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/view/facelet= s/FileUploadHandler.java (rev 0) +++ sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/view/facelet= s/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 =3D 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.c= lass) { + @Override + public void applyMetadata(final FaceletContext= ctx, Object instance) { + final MethodExpression expression =3D getM= ethodExpression(ctx); + ((AbstractFileUpload) instance).addFileUpl= oadListener(new FileUploadListener(){ + public void processUpload(UploadEvent = event) { + expression.invoke(ctx.getFacesCont= ext().getELContext(), new Object[] {event}); + } + }); + } + }; + } + } + return null; + } + }); + return metaRuleset; + } +} Added: sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/fileuploa= d.faces-config.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/fileupload.f= aces-config.xml (rev 0) +++ sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/fileupload.f= aces-config.xml 2010-10-25 16:29:09 UTC (rev 19667) @@ -0,0 +1,33 @@ + + + + + org.richfaces.application.FileUploadPhaselistener + + Added: sandbox/trunk/ui/fileupload/ui/src/main/templates/fileupload.templat= e.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/ui/fileupload/ui/src/main/templates/fileupload.template.x= ml (rev 0) +++ sandbox/trunk/ui/fileupload/ui/src/main/templates/fileupload.template.x= ml 2010-10-25 16:29:09 UTC (rev 19667) @@ -0,0 +1,39 @@ + + + + + org.richfaces.renderkit.html.FileUploadRenderer + org.richfaces.renderkit.RendererBase + org.richfaces.FileUpload + org.richfaces.FileUploadRenderer + + + + + + --===============3936976810093127230==--