Author: nbelaevski
Date: 2010-12-09 20:00:49 -0500 (Thu, 09 Dec 2010)
New Revision: 20489
Added:
trunk/core/api/src/main/java/org/richfaces/resource/AbstractJSONResource.java
trunk/core/api/src/main/java/org/richfaces/resource/ContentProducerResource.java
trunk/core/impl/src/main/java/org/richfaces/context/SkinningExternalContextFactory.java
trunk/examples/output-demo/src/main/java/org/richfaces/ProgressBarResource.java
Removed:
trunk/core/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java
trunk/core/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java
trunk/core/impl/src/main/java/org/richfaces/application/SkinningExternalContextFactory.java
trunk/ui/core/ui/src/main/resources/META-INF/org.richfaces.resource.PushResource.resource.properties
Modified:
trunk/core/api/src/main/java/org/richfaces/resource/ResourceFactory.java
trunk/core/api/src/main/java/org/richfaces/resource/UserResource.java
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
trunk/core/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java
trunk/core/impl/src/main/java/org/richfaces/util/Util.java
trunk/core/impl/src/main/resources/META-INF/components.faces-config.xml
trunk/core/impl/src/main/resources/META-INF/resources/richfaces.js
trunk/core/impl/src/test/java/org/richfaces/resource/UserResourcesTestCase.java
trunk/examples/output-demo/src/main/webapp/examples/progressbar.xhtml
trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java
trunk/ui/core/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java
trunk/ui/core/ui/src/main/java/org/richfaces/resource/PushResource.java
trunk/ui/output/ui/src/main/java/org/richfaces/component/NumberUtils.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.js
trunk/ui/output/ui/src/main/templates/progressBar.template.xml
Log:
Resources refactoring:
- Added ContentProducerResource + handling
- Dynamic resources updated to use encode() instead of getInputStream()
- Removed wrapper interfaces & added factory methods for creation of wrappers for
dynamic resources
- Removed PushResource marker file (not necessary)
- Added JSONResource
SkinningExternalContextFactory:
- Moved to 'context' package
- Changed mime-type for *.ecss files to vendor-specific
richfaces.js
- Added richfaces.parseJSON method
progress bar component:
- Added handling for 'resource' attribute + demo
Added: trunk/core/api/src/main/java/org/richfaces/resource/AbstractJSONResource.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/resource/AbstractJSONResource.java
(rev 0)
+++
trunk/core/api/src/main/java/org/richfaces/resource/AbstractJSONResource.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+package org.richfaces.resource;
+
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.javascript.ScriptUtils;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@DynamicResource
+public abstract class AbstractJSONResource extends AbstractUserResource {
+
+ public String getContentType() {
+ return "text/javascript; charset=utf-8";
+ }
+
+ public void encode(FacesContext context) throws IOException {
+ ScriptUtils.appendScript(context.getExternalContext().getResponseOutputWriter(),
getData(context));
+ }
+
+ protected abstract Object getData(FacesContext context);
+
+}
Added: trunk/core/api/src/main/java/org/richfaces/resource/ContentProducerResource.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/resource/ContentProducerResource.java
(rev 0)
+++
trunk/core/api/src/main/java/org/richfaces/resource/ContentProducerResource.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+package org.richfaces.resource;
+
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ContentProducerResource {
+
+ public void encode(FacesContext context) throws IOException;
+
+}
Deleted:
trunk/core/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java
===================================================================
---
trunk/core/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/core/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -1,35 +0,0 @@
-/*
- * 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.
- */
-package org.richfaces.resource;
-
-import javax.faces.FacesWrapper;
-
-
-/**
- * @author Nick Belaevski
- *
- */
-public interface Java2DUserResourceWrapper extends FacesWrapper<Java2DUserResource>
{
-
- public Java2DUserResource getWrapped();
-
-}
Modified: trunk/core/api/src/main/java/org/richfaces/resource/ResourceFactory.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/resource/ResourceFactory.java 2010-12-09
20:26:00 UTC (rev 20488)
+++ trunk/core/api/src/main/java/org/richfaces/resource/ResourceFactory.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -44,4 +44,8 @@
public abstract Resource createResource(FacesContext context, ResourceRequestData
resourceData);
+ public abstract Resource createResource(UserResource resource);
+
+ public abstract Resource createResource(Java2DUserResource resource);
+
}
Modified: trunk/core/api/src/main/java/org/richfaces/resource/UserResource.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/resource/UserResource.java 2010-12-09
20:26:00 UTC (rev 20488)
+++ trunk/core/api/src/main/java/org/richfaces/resource/UserResource.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -21,8 +21,6 @@
*/
package org.richfaces.resource;
-import java.io.IOException;
-import java.io.InputStream;
import java.util.Date;
import java.util.Map;
@@ -30,15 +28,12 @@
* @author Nick Belaevski
*
*/
-//TODO nick - add abstract class
-public interface UserResource {
+public interface UserResource extends ContentProducerResource {
public Map<String, String> getResponseHeaders();
public Date getLastModified();
- public InputStream getInputStream() throws IOException;
-
public String getContentType();
public int getContentLength();
Deleted: trunk/core/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java
===================================================================
---
trunk/core/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/core/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -1,34 +0,0 @@
-/*
- * 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.
- */
-package org.richfaces.resource;
-
-import javax.faces.FacesWrapper;
-
-/**
- * @author Nick Belaevski
- *
- */
-public interface UserResourceWrapper extends FacesWrapper<UserResource> {
-
- public UserResource getWrapped();
-
-}
Deleted:
trunk/core/impl/src/main/java/org/richfaces/application/SkinningExternalContextFactory.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/application/SkinningExternalContextFactory.java 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/core/impl/src/main/java/org/richfaces/application/SkinningExternalContextFactory.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -1,88 +0,0 @@
-/*
- * 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.
- */
-package org.richfaces.application;
-
-import javax.faces.FacesException;
-import javax.faces.FacesWrapper;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.ExternalContextFactory;
-import javax.faces.context.ExternalContextWrapper;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class SkinningExternalContextFactory extends ExternalContextFactory implements
FacesWrapper<ExternalContextFactory> {
-
- private ExternalContextFactory factory;
-
- private static final class ExternalContextWrapperImpl extends ExternalContextWrapper
{
-
- private ExternalContext externalContext;
-
- public ExternalContextWrapperImpl(ExternalContext externalContext) {
- super();
- this.externalContext = externalContext;
- }
-
- @Override
- public String getMimeType(String file) {
- String mimeType;
-
- if (file != null && file.endsWith(".ecss")) {
- mimeType = "text/plain";
- } else {
- mimeType = super.getMimeType(file);
- }
-
- return mimeType;
- }
-
- @Override
- public ExternalContext getWrapped() {
- return externalContext;
- }
-
- }
-
- public SkinningExternalContextFactory(ExternalContextFactory factory) {
- super();
- this.factory = factory;
- }
-
- @Override
- public ExternalContextFactory getWrapped() {
- return factory;
- }
-
- @Override
- public ExternalContext getExternalContext(Object context, Object request, Object
response) throws FacesException {
- ExternalContext externalContext = factory.getExternalContext(context, request,
response);
-
- return wrap(externalContext);
- }
-
- private ExternalContext wrap(ExternalContext externalContext) {
- return new ExternalContextWrapperImpl(externalContext);
- }
-
-}
Copied:
trunk/core/impl/src/main/java/org/richfaces/context/SkinningExternalContextFactory.java
(from rev 20481,
trunk/core/impl/src/main/java/org/richfaces/application/SkinningExternalContextFactory.java)
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/context/SkinningExternalContextFactory.java
(rev 0)
+++
trunk/core/impl/src/main/java/org/richfaces/context/SkinningExternalContextFactory.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+package org.richfaces.context;
+
+import javax.faces.FacesException;
+import javax.faces.FacesWrapper;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.ExternalContextFactory;
+import javax.faces.context.ExternalContextWrapper;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SkinningExternalContextFactory extends ExternalContextFactory implements
FacesWrapper<ExternalContextFactory> {
+
+ private ExternalContextFactory factory;
+
+ private static final class ExternalContextWrapperImpl extends ExternalContextWrapper
{
+
+ private ExternalContext externalContext;
+
+ public ExternalContextWrapperImpl(ExternalContext externalContext) {
+ super();
+ this.externalContext = externalContext;
+ }
+
+ @Override
+ public String getMimeType(String file) {
+ String mimeType;
+
+ if (file != null && file.endsWith(".ecss")) {
+ mimeType = "text/vnd.richfaces.css";
+ } else {
+ mimeType = super.getMimeType(file);
+ }
+
+ return mimeType;
+ }
+
+ @Override
+ public ExternalContext getWrapped() {
+ return externalContext;
+ }
+
+ }
+
+ public SkinningExternalContextFactory(ExternalContextFactory factory) {
+ super();
+ this.factory = factory;
+ }
+
+ @Override
+ public ExternalContextFactory getWrapped() {
+ return factory;
+ }
+
+ @Override
+ public ExternalContext getExternalContext(Object context, Object request, Object
response) throws FacesException {
+ ExternalContext externalContext = factory.getExternalContext(context, request,
response);
+
+ return wrap(externalContext);
+ }
+
+ private ExternalContext wrap(ExternalContext externalContext) {
+ return new ExternalContextWrapperImpl(externalContext);
+ }
+
+}
Modified:
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -24,8 +24,6 @@
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
@@ -35,25 +33,34 @@
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageOutputStream;
+import org.ajax4jsf.io.ByteBuffer;
+import org.ajax4jsf.io.FastBufferInputStream;
+import org.ajax4jsf.io.FastBufferOutputStream;
import org.ajax4jsf.util.HtmlColor;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
import org.richfaces.renderkit.util.HtmlDimensions;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
+import com.google.common.io.Closeables;
+
/**
* @author Nick Belaevski
*
*/
-public class Java2DUserResourceWrapperImpl extends
BaseResourceWrapper<Java2DUserResource>
- implements Java2DUserResourceWrapper {
+public class Java2DUserResourceWrapperImpl extends
BaseResourceWrapper<Java2DUserResource> {
+ private static final Logger LOGGER = RichfacesLogger.RESOURCE.getLogger();
+
public Java2DUserResourceWrapperImpl(Java2DUserResource resourceObject, boolean
cacheable, boolean versioned) {
super(resourceObject, cacheable, versioned);
}
public InputStream getInputStream() throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(baos);
+ FastBufferOutputStream fbos = new FastBufferOutputStream();
+
+ ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(fbos);
try {
paintAndWrite(imageOutputStream);
} finally {
@@ -61,12 +68,16 @@
try {
imageOutputStream.close();
} catch (IOException e) {
- // TODO: handle exception
- e.printStackTrace();
+ LOGGER.debug(e.getMessage(), e);
}
+
+ Closeables.closeQuietly(fbos);
}
}
- return new ByteArrayInputStream(baos.toByteArray());
+ ByteBuffer buffer = fbos.getFirstBuffer();
+ buffer.compact();
+
+ return new FastBufferInputStream(buffer);
}
protected void write(BufferedImage image, String formatName, ImageOutputStream
imageOutputStream) throws IOException {
Modified: trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -207,18 +207,24 @@
}
}
+ private boolean isCacheableSet(Class<?> c) {
+ DynamicUserResource annotation = c.getAnnotation(DynamicUserResource.class);
+ return annotation != null && annotation.cacheable();
+ }
+
+ private boolean isVersionedSet(Class<?> c) {
+ DynamicUserResource annotation = c.getAnnotation(DynamicUserResource.class);
+ return annotation != null && annotation.versioned();
+ }
+
private Resource createDynamicUserResourceInstance(Class<?> loadedClass) throws
Exception, LinkageError {
String resourceName = loadedClass.getName();
boolean checkResult = false;
- boolean cacheable = false;
- boolean versioned = false;
DynamicUserResource dynamicUserResource =
loadedClass.getAnnotation(DynamicUserResource.class);
if (dynamicUserResource != null) {
- cacheable = dynamicUserResource.cacheable();
- versioned = dynamicUserResource.versioned();
checkResult = true;
LOGGER.debug(MessageFormat.format("Dynamic resource annotation is
present on resource class {0}",
@@ -246,17 +252,14 @@
return null;
}
- BaseResourceWrapper<?> result = null;
+ Resource result = null;
- if (Java2DAnimatedUserResource.class.isAssignableFrom(loadedClass)) {
- Java2DAnimatedUserResource java2DAnimatedUserResource =
(Java2DAnimatedUserResource) loadedClass.newInstance();
- result = new
Java2DAnimatedUserResourceWrapperImpl(java2DAnimatedUserResource, cacheable, versioned);
- } else if (Java2DUserResource.class.isAssignableFrom(loadedClass)) {
+ if (Java2DUserResource.class.isAssignableFrom(loadedClass)) {
Java2DUserResource java2DUserResource = (Java2DUserResource)
loadedClass.newInstance();
- result = new Java2DUserResourceWrapperImpl(java2DUserResource, cacheable,
versioned);
+ result = createResource(java2DUserResource);
} else if (UserResource.class.isAssignableFrom(loadedClass)) {
UserResource userResource = (UserResource) loadedClass.newInstance();
- result = new UserResourceWrapperImpl(userResource, cacheable, versioned);
+ result = createResource(userResource);
}
return result;
@@ -472,4 +475,23 @@
public Collection<ResourceKey> getMappedDynamicResourceKeys() {
return Collections.unmodifiableSet(mappedResourceDataMap.keySet());
}
+
+ public Resource createResource(Java2DUserResource resource) {
+ boolean cacheable = isCacheableSet(resource.getClass());
+ boolean versioned = isVersionedSet(resource.getClass());
+
+ if (resource instanceof Java2DAnimatedUserResource) {
+ Java2DAnimatedUserResource java2DAnimatedUserResource =
(Java2DAnimatedUserResource) resource;
+ return new Java2DAnimatedUserResourceWrapperImpl(java2DAnimatedUserResource,
cacheable, versioned);
+ } else {
+ return new Java2DUserResourceWrapperImpl(resource, cacheable, versioned);
+ }
+ }
+
+ public Resource createResource(UserResource resource) {
+ boolean cacheable = isCacheableSet(resource.getClass());
+ boolean versioned = isVersionedSet(resource.getClass());
+
+ return new UserResourceWrapperImpl(resource, cacheable, versioned);
+ }
}
Modified: trunk/core/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -35,7 +35,6 @@
import javax.faces.application.ResourceHandlerWrapper;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.richfaces.application.ServiceTracker;
@@ -222,16 +221,14 @@
externalContext.setResponseContentType(contentType);
}
- // TODO - portlets
- HttpServletRequest httpServletRequest = (HttpServletRequest)
externalContext.getRequest();
-
- if (!"HEAD".equals(httpServletRequest.getMethod())) {
-
- // TODO 'HEAD' HTTP method resources - ?
+ if (resource instanceof ContentProducerResource) {
+ ContentProducerResource contentProducerResource =
(ContentProducerResource) resource;
+ contentProducerResource.encode(context);
+ } else {
// TODO setup output buffer size according to configuration
parameter
InputStream is = resource.getInputStream();
OutputStream os = externalContext.getResponseOutputStream();
-
+
try {
Util.copyStreamContent(is, os);
} finally {
@@ -244,11 +241,12 @@
}
}
}
-
+
// TODO flush resource
// TODO dispose resource
}
}
+
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Resource succesfully encoded");
Modified:
trunk/core/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -21,26 +21,152 @@
*/
package org.richfaces.resource;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.Charset;
import java.util.Date;
import java.util.Map;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.ExternalContextWrapper;
import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextWrapper;
+import org.ajax4jsf.io.ByteBuffer;
+import org.ajax4jsf.io.FastBufferInputStream;
+import org.ajax4jsf.io.FastBufferOutputStream;
+import org.richfaces.util.Util;
+
/**
* @author Nick Belaevski
*
*/
-public class UserResourceWrapperImpl extends BaseResourceWrapper<UserResource>
implements UserResourceWrapper {
+public class UserResourceWrapperImpl extends BaseResourceWrapper<UserResource>
implements ContentProducerResource {
+ private static final InputStream EMPTY_STREAM = new ByteArrayInputStream(new
byte[0]);
+
+ private static final class FacesContextWrapperImpl extends FacesContextWrapper {
+
+ private FacesContext facesContext;
+
+ private ExternalContextWrapperImpl externalContext;
+
+ private FacesContextWrapperImpl(FacesContext facesContext,
ExternalContextWrapperImpl externalContextWrapper) {
+ super();
+
+ this.facesContext = facesContext;
+ this.externalContext = externalContextWrapper;
+ }
+
+ @Override
+ public FacesContext getWrapped() {
+ return facesContext;
+ }
+
+ @Override
+ public ExternalContextWrapperImpl getExternalContext() {
+ return externalContext;
+ }
+
+ public static FacesContextWrapperImpl wrap(Charset charset) {
+ FacesContext originalFacesContext = FacesContext.getCurrentInstance();
+
+ ExternalContextWrapperImpl externalContextWrapper = new
ExternalContextWrapperImpl(originalFacesContext.getExternalContext(), charset);
+ FacesContextWrapperImpl facesContextWrapper = new
FacesContextWrapperImpl(originalFacesContext, externalContextWrapper);
+
+ setCurrentInstance(facesContextWrapper);
+ return facesContextWrapper;
+ }
+
+ public static void unwrap() {
+ FacesContext originalContext = ((FacesContextWrapper)
FacesContext.getCurrentInstance()).getWrapped();
+ setCurrentInstance(originalContext);
+ }
+
+ public InputStream getWrittenDataAsStream() throws IOException {
+ return externalContext.getWrittenDataAsStream();
+ }
+ }
+
+ private static final class ExternalContextWrapperImpl extends ExternalContextWrapper
{
+
+ private FastBufferOutputStream stream = null;
+
+ private Writer writer = null;
+
+ private ExternalContext externalContext;
+
+ private Charset charset;
+
+ public ExternalContextWrapperImpl(ExternalContext externalContext, Charset
charset) {
+ super();
+
+ this.externalContext = externalContext;
+ this.charset = charset;
+ }
+
+ @Override
+ public ExternalContext getWrapped() {
+ return externalContext;
+ }
+
+ @Override
+ public FastBufferOutputStream getResponseOutputStream() {
+ if (stream == null) {
+ stream = new FastBufferOutputStream();
+ }
+
+ return stream;
+ }
+
+ @Override
+ public Writer getResponseOutputWriter() {
+ if (writer == null) {
+ writer = new OutputStreamWriter(getResponseOutputStream(), charset);
+ }
+
+ return writer;
+ }
+
+ public InputStream getWrittenDataAsStream() throws IOException {
+ flushBuffers();
+
+ if (stream != null) {
+ ByteBuffer firstBuffer = stream.getFirstBuffer();
+ firstBuffer.compact();
+ return new FastBufferInputStream(firstBuffer);
+ } else {
+ return EMPTY_STREAM;
+ }
+ }
+
+ private void flushBuffers() throws IOException {
+ if (writer != null) {
+ writer.flush();
+ } else if (stream != null) {
+ stream.flush();
+ }
+ }
+ }
+
public UserResourceWrapperImpl(UserResource resourceObject, boolean cacheable,
boolean versioned) {
super(resourceObject, cacheable, versioned);
}
@Override
public InputStream getInputStream() throws IOException {
- return getWrapped().getInputStream();
+ Charset charset = Util.getCharsetFromContentType(getContentType());
+ FacesContextWrapperImpl wrappedContext = FacesContextWrapperImpl.wrap(charset);
+ try {
+ encode(wrappedContext);
+
+ return wrappedContext.getWrittenDataAsStream();
+ } finally {
+ FacesContextWrapperImpl.unwrap();
+ }
}
@Override
@@ -62,5 +188,9 @@
protected Date getLastModified(FacesContext context) {
return getWrapped().getLastModified();
}
+
+ public void encode(FacesContext context) throws IOException {
+ getWrapped().encode(context);
+ }
}
Modified: trunk/core/impl/src/main/java/org/richfaces/util/Util.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/util/Util.java 2010-12-09 20:26:00 UTC
(rev 20488)
+++ trunk/core/impl/src/main/java/org/richfaces/util/Util.java 2010-12-10 01:00:49 UTC
(rev 20489)
@@ -85,6 +85,8 @@
import org.richfaces.log.RichfacesLogger;
import org.richfaces.resource.StateHolderResource;
+import com.google.common.base.Strings;
+
/**
* @author Nick Belaevski
* @since 4.0
@@ -115,6 +117,8 @@
private static final String QUESTION_SIGN = "?";
private static final String EQUALS_SIGN = "=";
+ private static final Pattern CHARSET_IN_CONTENT_TYPE_PATTERN =
Pattern.compile(";\\s*charset\\s*=\\s*([^\\s;]+)", Pattern.CASE_INSENSITIVE);
+
static {
SimpleDateFormat format = new SimpleDateFormat(RFC1123_DATE_PATTERN, Locale.US);
@@ -616,4 +620,16 @@
stateHolder.restoreState(context, state);
}
}
+
+ public static Charset getCharsetFromContentType(String contentType) {
+ String charsetName = null;
+
+ Matcher matcher = CHARSET_IN_CONTENT_TYPE_PATTERN.matcher(contentType);
+ if (matcher.find()) {
+ charsetName = matcher.group(1);
+ }
+
+ return Strings.isNullOrEmpty(charsetName) ? Charset.defaultCharset() :
Charset.forName(charsetName);
+ }
+
}
Modified: trunk/core/impl/src/main/resources/META-INF/components.faces-config.xml
===================================================================
--- trunk/core/impl/src/main/resources/META-INF/components.faces-config.xml 2010-12-09
20:26:00 UTC (rev 20488)
+++ trunk/core/impl/src/main/resources/META-INF/components.faces-config.xml 2010-12-10
01:00:49 UTC (rev 20489)
@@ -4,7 +4,7 @@
version="2.0">
<factory>
-
<external-context-factory>org.richfaces.application.SkinningExternalContextFactory</external-context-factory>
+
<external-context-factory>org.richfaces.context.SkinningExternalContextFactory</external-context-factory>
<partial-view-context-factory>org.richfaces.context.PartialViewContextFactoryImpl</partial-view-context-factory>
</factory>
Modified: trunk/core/impl/src/main/resources/META-INF/resources/richfaces.js
===================================================================
--- trunk/core/impl/src/main/resources/META-INF/resources/richfaces.js 2010-12-09 20:26:00
UTC (rev 20488)
+++ trunk/core/impl/src/main/resources/META-INF/resources/richfaces.js 2010-12-10 01:00:49
UTC (rev 20489)
@@ -331,9 +331,7 @@
var JSON_STRING_START = /^\s*(\[|\{)/;
- var getJSONData = function(extensionElement, elementName) {
- var dataString = jQuery.trim(extensionElement.children(elementName).text());
- extensionElement.end();
+ richfaces.parseJSON = function(dataString) {
try {
if (dataString) {
if (JSON_STRING_START.test(dataString)) {
@@ -346,7 +344,14 @@
} catch (e) {
richfaces.log.warn("Error evaluating JSON data from element <" +
elementName + ">: " + e.message);
}
+
return null;
+ }
+
+ var getJSONData = function(extensionElement, elementName) {
+ var dataString = jQuery.trim(extensionElement.children(elementName).text());
+ extensionElement.end();
+ return richfaces.parseJSON(dataString);
};
richfaces.createJSFEventsAdapter = function(handlers) {
Modified: trunk/core/impl/src/test/java/org/richfaces/resource/UserResourcesTestCase.java
===================================================================
---
trunk/core/impl/src/test/java/org/richfaces/resource/UserResourcesTestCase.java 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/core/impl/src/test/java/org/richfaces/resource/UserResourcesTestCase.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -27,7 +27,6 @@
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Date;
import java.util.Map;
@@ -41,9 +40,7 @@
import org.junit.Before;
import org.junit.Test;
-import com.google.common.io.ByteStreams;
-
/**
* @author Nick Belaevski
*
@@ -52,10 +49,10 @@
protected static class BaseUserResource extends AbstractUserResource {
- public InputStream getInputStream() throws IOException {
- return
ByteStreams.newInputStreamSupplier(getClass().getSimpleName().getBytes("US-ASCII")).getInput();
+ public void encode(FacesContext facesContext) throws IOException {
+ facesContext.getResponseWriter().write(getClass().getSimpleName());
}
-
+
public String getContentType() {
return "text/plain";
}
Added: trunk/examples/output-demo/src/main/java/org/richfaces/ProgressBarResource.java
===================================================================
--- trunk/examples/output-demo/src/main/java/org/richfaces/ProgressBarResource.java
(rev 0)
+++
trunk/examples/output-demo/src/main/java/org/richfaces/ProgressBarResource.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+package org.richfaces;
+
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+import org.richfaces.resource.AbstractJSONResource;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ProgressBarResource extends AbstractJSONResource {
+
+ private static final String ATTRIBUTE_NAME = ProgressBarResource.class.getName();
+
+ @Override
+ protected Object getData(FacesContext context) {
+ Map<String, Object> sessionMap =
context.getExternalContext().getSessionMap();
+
+ Integer value = (Integer) sessionMap.get(ATTRIBUTE_NAME);
+ if (value == null) {
+ value = Integer.valueOf(0);
+ } else {
+ value = Integer.valueOf(value.intValue() + 5);
+ }
+
+ sessionMap.put(ATTRIBUTE_NAME, value);
+
+ return value;
+ }
+
+}
Modified: trunk/examples/output-demo/src/main/webapp/examples/progressbar.xhtml
===================================================================
--- trunk/examples/output-demo/src/main/webapp/examples/progressbar.xhtml 2010-12-09
20:26:00 UTC (rev 20488)
+++ trunk/examples/output-demo/src/main/webapp/examples/progressbar.xhtml 2010-12-10
01:00:49 UTC (rev 20489)
@@ -114,6 +114,26 @@
<a4j:commandLink value="re-render progress bar"
render="progressBar" />
</h:form>
+
+ <h:form id="ajaxExtResourcePBForm">
+ Ajax mode with GET requests:
+ <rich:progressBar id="progressBar" mode="ajax"
interval="2000"
resource="#{resource['org.richfaces.ProgressBarResource']}"
+ maxValue="#{progressBarBean.maxValue}"
minValue="#{progressBarBean.minValue}"
+ enabled="#{progressBarBean.enabled}">
+
+ <f:facet name="initial">
+ <h:panelGroup rendered="#{progressBarBean.initialFacetRendered}">
+ <h:outputText value="initial" />
+ </h:panelGroup>
+ </f:facet>
+
+ <f:facet name="finish">
+ <h:panelGroup rendered="#{progressBarBean.finishFacetRendered}">
+ <h:outputText value="finish" />
+ </h:panelGroup>
+ </f:facet>
+ </rich:progressBar>
+ </h:form>
</ui:define>
</ui:composition>
Modified: trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java
===================================================================
---
trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -28,12 +28,11 @@
import javax.el.MethodExpression;
import javax.faces.application.Resource;
-import javax.faces.application.ResourceHandler;
import javax.faces.component.UIOutput;
-import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
import org.ajax4jsf.resource.ResourceComponent2;
+import org.richfaces.application.ServiceTracker;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.JsfComponent;
@@ -42,7 +41,7 @@
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
import org.richfaces.resource.MediaOutputResource;
-import org.richfaces.resource.UserResourceWrapper;
+import org.richfaces.resource.ResourceFactory;
/**
* @author shura
@@ -120,14 +119,12 @@
}
public Resource getResource() {
- FacesContext facesContext = getFacesContext();
- ResourceHandler resourceHandler =
facesContext.getApplication().getResourceHandler();
- Resource resource =
resourceHandler.createResource(MediaOutputResource.class.getName());
+ ResourceFactory factory = ServiceTracker.getService(ResourceFactory.class);
- MediaOutputResource mediaResource = (MediaOutputResource) ((UserResourceWrapper)
resource).getWrapped();
- mediaResource.initialize(this);
-
- return resource;
+ MediaOutputResource mediaOutputResource = new MediaOutputResource();
+ mediaOutputResource.initialize(this);
+
+ return factory.createResource(mediaOutputResource);
}
@Attribute
Modified: trunk/ui/core/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java
===================================================================
---
trunk/ui/core/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/ui/core/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -23,12 +23,9 @@
package org.richfaces.resource;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Date;
-import java.util.Map;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
@@ -43,7 +40,7 @@
* @since 4.0
*/
@DynamicResource
-public class MediaOutputResource implements StateHolder, UserResource, CacheableResource
{
+public class MediaOutputResource extends AbstractUserResource implements StateHolder,
CacheableResource {
private String contentType;
@@ -62,15 +59,11 @@
private ValueExpression timeToLiveExpression;
private Object userData;
- public InputStream getInputStream() throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- FacesContext facesContext = FacesContext.getCurrentInstance();
-
- contentProducer.invoke(facesContext.getELContext(), new Object[] {baos,
userData});
-
- return new ByteArrayInputStream(baos.toByteArray());
+ public void encode(FacesContext facesContext) throws IOException {
+ OutputStream outStream =
facesContext.getExternalContext().getResponseOutputStream();
+ contentProducer.invoke(facesContext.getELContext(), new Object[] {outStream,
userData});
}
-
+
public boolean isTransient() {
return false;
}
@@ -135,14 +128,6 @@
return null;
}
- public Map<String, String> getResponseHeaders() {
- return null;
- }
-
- public Date getLastModified() {
- return null;
- }
-
public String getContentType() {
return contentType;
}
@@ -151,7 +136,4 @@
this.contentType = contentType;
}
- public int getContentLength() {
- return -1;
- }
}
Modified: trunk/ui/core/ui/src/main/java/org/richfaces/resource/PushResource.java
===================================================================
--- trunk/ui/core/ui/src/main/java/org/richfaces/resource/PushResource.java 2010-12-09
20:26:00 UTC (rev 20488)
+++ trunk/ui/core/ui/src/main/java/org/richfaces/resource/PushResource.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -21,17 +21,13 @@
*/
package org.richfaces.resource;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Date;
+import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
-import javax.faces.FacesException;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
@@ -47,31 +43,12 @@
*
*/
@DynamicResource
-public class PushResource implements UserResource {
+public class PushResource extends AbstractUserResource {
private static final String PUSH_TOPIC_PARAM = "pushTopic";
private static final String FORGET_PUSH_SESSION_ID_PARAM =
"forgetPushSessionId";
- private static final InputStream EMPTY_INPUT_STREAM = new ByteArrayInputStream(new
byte[0]);
-
- public Map<String, String> getResponseHeaders() {
- return null;
- }
-
- public Date getLastModified() {
- return null;
- }
-
- private InputStream mapToScript(Map<String, Object> map) {
- try {
- byte[] bs = ScriptUtils.toScript(map).getBytes("UTF-8");
- return new ByteArrayInputStream(bs);
- } catch (UnsupportedEncodingException e) {
- throw new FacesException(e.getMessage(), e);
- }
- }
-
private Map<String, String> getFailuresMap(Map<TopicKey, String>
failedSubscriptions) {
Map<String,String> result = new HashMap<String, String>();
@@ -82,15 +59,14 @@
return result;
}
- public InputStream getInputStream() throws IOException {
- FacesContext facesContext = FacesContext.getCurrentInstance();
+ public void encode(FacesContext facesContext) throws IOException {
ExternalContext externalContext = facesContext.getExternalContext();
PushContextFactory pushContextFactory =
ServiceTracker.getService(PushContextFactory.class);
//resource plugin stub
if (pushContextFactory == null) {
- return EMPTY_INPUT_STREAM;
+ return;
}
PushContext pushContext = pushContextFactory.getPushContext();
@@ -119,15 +95,12 @@
Map<TopicKey, String> failedSubscriptions =
session.getFailedSubscriptions();
subscriptionData.put("failures", getFailuresMap(failedSubscriptions));
- return mapToScript(subscriptionData);
+ Writer outWriter = facesContext.getExternalContext().getResponseOutputWriter();
+ ScriptUtils.appendScript(outWriter, subscriptionData);
}
-
+
public String getContentType() {
- return "application/javascript; charset=utf-8";
+ return "text/javascript; charset=utf-8";
}
- public int getContentLength() {
- return -1;
- }
-
}
Deleted:
trunk/ui/core/ui/src/main/resources/META-INF/org.richfaces.resource.PushResource.resource.properties
===================================================================
Modified: trunk/ui/output/ui/src/main/java/org/richfaces/component/NumberUtils.java
===================================================================
--- trunk/ui/output/ui/src/main/java/org/richfaces/component/NumberUtils.java 2010-12-09
20:26:00 UTC (rev 20488)
+++ trunk/ui/output/ui/src/main/java/org/richfaces/component/NumberUtils.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -2,7 +2,13 @@
import java.math.BigDecimal;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+
public final class NumberUtils {
+
+ private static final Logger LOGGER = RichfacesLogger.COMPONENTS.getLogger();
+
private NumberUtils() {
}
@@ -31,7 +37,7 @@
}
}
} catch (Exception e) {
- e.getMessage();
+ LOGGER.error(e.getMessage(), e);
}
return result;
}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java 2010-12-10
01:00:49 UTC (rev 20489)
@@ -93,7 +93,11 @@
* @param component
* @return
*/
- public boolean isAjaxMode(UIComponent component) {
+ protected boolean isAjaxMode(UIComponent component) {
+ if (isResourceMode(component)) {
+ return false;
+ }
+
SwitchType mode = (SwitchType) component.getAttributes().get("mode");
if (mode == SwitchType.server) {
@@ -103,19 +107,27 @@
return SwitchType.ajax == mode;
}
+ protected boolean isResourceMode(UIComponent component) {
+ return component.getAttributes().get("resource") != null;
+ }
+
protected ProgressBarState getCurrentState(FacesContext context, UIComponent
component){
- Number minValue =
NumberUtils.getNumber(component.getAttributes().get("minValue"));
- Number maxValue =
NumberUtils.getNumber(component.getAttributes().get("maxValue"));
- Number value =
NumberUtils.getNumber(component.getAttributes().get("value"));
-
ProgressBarState result;
- if (value.doubleValue() < minValue.doubleValue()) {
+ if (isResourceMode(component)) {
result = ProgressBarState.initialState;
- } else if (value.doubleValue() >= maxValue.doubleValue()) {
- result = ProgressBarState.finishState;
} else {
- result = ProgressBarState.progressState;
+ Number minValue =
NumberUtils.getNumber(component.getAttributes().get("minValue"));
+ Number maxValue =
NumberUtils.getNumber(component.getAttributes().get("maxValue"));
+ Number value =
NumberUtils.getNumber(component.getAttributes().get("value"));
+
+ if (value.doubleValue() < minValue.doubleValue()) {
+ result = ProgressBarState.initialState;
+ } else if (value.doubleValue() >= maxValue.doubleValue()) {
+ result = ProgressBarState.finishState;
+ } else {
+ result = ProgressBarState.progressState;
+ }
}
if (result == ProgressBarState.initialState || result ==
ProgressBarState.finishState) {
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.js 2010-12-09
20:26:00 UTC (rev 20488)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.js 2010-12-10
01:00:49 UTC (rev 20489)
@@ -23,9 +23,12 @@
this.enabled = this.options.enabled;
this.minValue = this.options.minValue;
this.maxValue = this.options.maxValue;
- this.__setValue(this.options.value);
- if (this.options.submitFunction) {
+ this.__setValue(this.options.value || this.options.minValue /* TODO - check with Ilya
*/);
+
+ if (this.options.resource) {
+ this.__poll();
+ } else if (this.options.submitFunction) {
this.submitFunction = new Function("beforeUpdateHandler",
"afterUpdateHandler", "params", "event",
this.options.submitFunction);
this.__poll();
}
@@ -67,9 +70,22 @@
this.__poll();
},
+ __onResourceDataAvailable: function(data) {
+ var parsedData = rf.parseJSON(data);
+ if (parsedData instanceof Number || typeof parsedData == 'number') {
+ this.setValue(parsedData);
+ }
+
+ this.__poll();
+ },
+
__submit: function() {
- this.submitFunction.call(this, $.proxy(this.__beforeUpdate, this),
$.proxy(this.__afterUpdate, this),
- this.__params || {});
+ if (this.submitFunction) {
+ this.submitFunction.call(this, $.proxy(this.__beforeUpdate, this),
$.proxy(this.__afterUpdate, this),
+ this.__params || {});
+ } else {
+ $.get(this.options.resource, this.__params || {},
$.proxy(this.__onResourceDataAvailable, this), 'text');
+ }
},
__poll: function(immediate) {
@@ -158,7 +174,7 @@
},
isAjaxMode: function () {
- return !!this.submitFunction;
+ return !!this.submitFunction || !!this.options.resource;
},
disable: function () {
Modified: trunk/ui/output/ui/src/main/templates/progressBar.template.xml
===================================================================
--- trunk/ui/output/ui/src/main/templates/progressBar.template.xml 2010-12-09 20:26:00 UTC
(rev 20488)
+++ trunk/ui/output/ui/src/main/templates/progressBar.template.xml 2010-12-10 01:00:49 UTC
(rev 20489)
@@ -38,7 +38,7 @@
<cdk:scriptOption name="minValue"
value="#{component.attributes['minValue']}" defaultValue="0"
/>
<cdk:scriptOption name="maxValue"
value="#{component.attributes['maxValue']}" defaultValue="100"
/>
- <cdk:scriptOption attributes="interval enabled value
onfinish" />
+ <cdk:scriptOption attributes="interval enabled value onfinish
resource" />
</cdk:scriptObject>
new RichFaces.ui.ProgressBar(#{toScriptArgs(clientId, options)});