JBoss Rich Faces SVN: r22438 - in trunk/ui/input/ui/src: test/java/org/richfaces/request and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2011-04-21 11:55:38 -0400 (Thu, 21 Apr 2011)
New Revision: 22438
Added:
trunk/ui/input/ui/src/test/java/org/richfaces/request/FileUploadResourcesTest.java
trunk/ui/input/ui/src/test/java/org/richfaces/request/FileUploadValueParamTest.java
trunk/ui/input/ui/src/test/java/org/richfaces/request/ProgressControlTest.java
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressServletInputStream.java
trunk/ui/input/ui/src/test/java/org/richfaces/request/MockUploadResource.java
Log:
RF-10128
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java 2011-04-21 13:15:55 UTC (rev 22437)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java 2011-04-21 15:55:38 UTC (rev 22438)
@@ -34,12 +34,12 @@
private static final String UPLOAD_PROGRESS_PREFIX = "_richfaces_upload_percents";
+ long totalBytesRead = 0;
+
private Map<String, Object> contextMap;
private String attributeName;
- private long totalBytesRead = 0;
-
private long length;
private byte lastUpdatedPercentValue;
@@ -60,7 +60,7 @@
return 0;
}
- private static String getContextAttributeName(String uploadId) {
+ static String getContextAttributeName(String uploadId) {
return UPLOAD_PROGRESS_PREFIX + uploadId;
}
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressServletInputStream.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressServletInputStream.java 2011-04-21 13:15:55 UTC (rev 22437)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressServletInputStream.java 2011-04-21 15:55:38 UTC (rev 22438)
@@ -72,5 +72,29 @@
}
return read;
}
+
+ public long skip(long n) throws IOException {
+ return wrappedStream.skip(n);
+ }
+
+ public int available() throws IOException {
+ return wrappedStream.available();
+ }
+
+ public void close() throws IOException {
+ wrappedStream.close();
+ }
+
+ public void mark(int readlimit) {
+ wrappedStream.mark(readlimit);
+ }
+
+ public void reset() throws IOException {
+ wrappedStream.reset();
+ }
+
+ public boolean markSupported() {
+ return wrappedStream.markSupported();
+ }
}
\ No newline at end of file
Added: trunk/ui/input/ui/src/test/java/org/richfaces/request/FileUploadResourcesTest.java
===================================================================
--- trunk/ui/input/ui/src/test/java/org/richfaces/request/FileUploadResourcesTest.java (rev 0)
+++ trunk/ui/input/ui/src/test/java/org/richfaces/request/FileUploadResourcesTest.java 2011-04-21 15:55:38 UTC (rev 22438)
@@ -0,0 +1,259 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Random;
+import java.util.UUID;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.io.ByteStreams;
+import com.google.common.io.Closeables;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FileUploadResourcesTest {
+
+ private FileUploadMemoryResource memoryResource;
+
+ private FileUploadDiscResource discResource;
+
+ private String memoryTempDirectory;
+
+ private String discTempDirectory;
+
+ private String createTempDirectory() {
+ File tmpDir = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
+ if (!tmpDir.mkdirs()) {
+ fail();
+ }
+
+ return tmpDir.getAbsolutePath();
+ }
+
+ private void eraseDirectory(String location) {
+ File file = new File(location);
+
+ for (File f: file.listFiles()) {
+ f.delete();
+ }
+
+ file.delete();
+ }
+
+ private byte[] getRandomBytes(int size) {
+ byte[] bs = new byte[size];
+ new Random().nextBytes(bs);
+ return bs;
+ }
+
+ private byte[] readFully(InputStream is) throws IOException {
+ try {
+ return ByteStreams.toByteArray(is);
+ } finally {
+ Closeables.closeQuietly(is);
+ }
+ }
+
+ private byte[] readFully(File file) throws IOException {
+ assertNotNull(file);
+ return readFully(new FileInputStream(file));
+ }
+
+ private File getSingleFile(String location) {
+ File root = new File(location);
+
+ File[] files = root.listFiles();
+ switch (files.length) {
+ case 0:
+ return null;
+ case 1:
+ return files[0];
+ default:
+ throw new IllegalStateException("File is not single");
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ memoryTempDirectory = createTempDirectory();
+ discTempDirectory = createTempDirectory();
+
+ memoryResource = new FileUploadMemoryResource("form:memoryUpload", memoryTempDirectory);
+ memoryResource.create();
+ discResource = new FileUploadDiscResource("form:discUpload", discTempDirectory);
+ discResource.create();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ eraseDirectory(memoryTempDirectory);
+ eraseDirectory(discTempDirectory);
+
+ memoryTempDirectory = null;
+ discTempDirectory = null;
+
+ memoryResource = null;
+ discResource = null;
+ }
+
+ @Test
+ public void testBasics() throws Exception {
+ int length = 5;
+ byte[] bytes = getRandomBytes(length);
+
+ memoryResource.handle(bytes, bytes.length);
+ discResource.handle(bytes, bytes.length);
+
+ memoryResource.complete();
+ discResource.complete();
+
+ assertTrue(memoryResource.isFileParam());
+ assertTrue(discResource.isFileParam());
+
+ InputStream is = null;
+
+ try {
+ is = memoryResource.getInputStream();
+ assertNotNull(is);
+ } finally {
+ Closeables.closeQuietly(is);
+ }
+ try {
+ is = discResource.getInputStream();
+ assertNotNull(is);
+ } finally {
+ Closeables.closeQuietly(is);
+ }
+
+ assertSame(memoryResource, memoryResource.getResource());
+ assertSame(discResource, discResource.getResource());
+
+ assertNull(memoryResource.getValue());
+ assertNull(discResource.getValue());
+
+ assertEquals("form:memoryUpload", memoryResource.getName());
+ assertEquals("form:discUpload", discResource.getName());
+ }
+
+ @Test
+ public void testSmallData() throws Exception {
+ //should be less than 128 - initial buffer size
+ int length = 68;
+ byte[] bytes = getRandomBytes(length);
+
+ memoryResource.handle(bytes, bytes.length);
+ discResource.handle(bytes, bytes.length);
+
+ memoryResource.complete();
+ discResource.complete();
+
+ checkResourcesContent(bytes);
+ }
+
+ @Test
+ public void testLargeData() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ int count = new Random().nextInt(256) + 256;
+ for (int i = 0; i < count; i++) {
+ int size = new Random().nextInt(512) + 512;
+ byte[] bytes = getRandomBytes(size);
+
+ memoryResource.handle(bytes, bytes.length);
+ discResource.handle(bytes, bytes.length);
+
+ baos.write(bytes);
+ }
+
+ memoryResource.complete();
+ discResource.complete();
+
+ checkResourcesContent(baos.toByteArray());
+ }
+
+ private void checkResourcesContent(byte[] expected) throws IOException {
+ int length = expected.length;
+
+ assertEquals(length, memoryResource.getSize());
+ assertEquals(length, discResource.getSize());
+
+ assertArrayEquals(expected, readFully(memoryResource.getInputStream()));
+ assertArrayEquals(expected, readFully(discResource.getInputStream()));
+
+ assertNull(getSingleFile(memoryTempDirectory));
+ assertArrayEquals(expected, readFully(getSingleFile(discTempDirectory)));
+
+ memoryResource.write("out");
+ discResource.write("out");
+
+ File memoryOutFile = getSingleFile(memoryTempDirectory);
+ File discOutFile = getSingleFile(discTempDirectory);
+
+ assertEquals("out", memoryOutFile.getName());
+ assertEquals("out", discOutFile.getName());
+
+ assertTrue(memoryOutFile.getAbsolutePath().startsWith(memoryTempDirectory));
+ assertTrue(discOutFile.getAbsolutePath().startsWith(discTempDirectory));
+
+ assertArrayEquals(expected, readFully(memoryOutFile));
+ assertArrayEquals(expected, readFully(discOutFile));
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ int length = 5;
+ byte[] bytes = getRandomBytes(length);
+
+ memoryResource.handle(bytes, bytes.length);
+ discResource.handle(bytes, bytes.length);
+
+ memoryResource.complete();
+ discResource.complete();
+
+ assertNull(getSingleFile(memoryTempDirectory));
+ assertNotNull(getSingleFile(discTempDirectory));
+
+ memoryResource.delete();
+ discResource.delete();
+
+ assertNull(getSingleFile(memoryTempDirectory));
+ assertNull(getSingleFile(discTempDirectory));
+ }
+}
Added: trunk/ui/input/ui/src/test/java/org/richfaces/request/FileUploadValueParamTest.java
===================================================================
--- trunk/ui/input/ui/src/test/java/org/richfaces/request/FileUploadValueParamTest.java (rev 0)
+++ trunk/ui/input/ui/src/test/java/org/richfaces/request/FileUploadValueParamTest.java 2011-04-21 15:55:38 UTC (rev 22438)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+import java.util.Random;
+
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FileUploadValueParamTest {
+
+ private FileUploadValueParam param;
+
+ @Before
+ public void setUp() throws Exception {
+ param = new FileUploadValueParam("form:upload", "UTF-8");
+ param.create();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ param = null;
+ }
+
+ @Test
+ public void testBasics() throws Exception {
+ param.handle("test".getBytes(), 4);
+ param.complete();
+
+ assertEquals("form:upload", param.getName());
+ assertFalse(param.isFileParam());
+ assertNull(param.getResource());
+ }
+
+ @Test
+ public void testShortParam() throws Exception {
+ byte[] bytes = "test".getBytes();
+ param.handle(bytes, bytes.length);
+ param.complete();
+
+ assertEquals("test", param.getValue());
+ }
+
+ @Test
+ public void testLongParam() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ CharsetEncoder charsetEncoder = Charset.forName("UTF-8").newEncoder();
+
+ for (int i = 0; i < 256; i++) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ int count = new Random().nextInt(128) + 128;
+ while (count != 0) {
+ char c = (char) new Random().nextInt(Character.MAX_VALUE);
+
+ if (charsetEncoder.canEncode(c)) {
+ baos.write(charsetEncoder.encode(CharBuffer.wrap(new char[]{c})).array());
+ count--;
+ }
+ }
+
+ byte[] bs = baos.toByteArray();
+ param.handle(bs, bs.length);
+ sb.append(new String(bs, "UTF-8"));
+ }
+
+ param.complete();
+ assertEquals(sb.toString(), param.getValue());
+ }
+
+ @Test
+ public void testNullencoding() throws Exception {
+ param = new FileUploadValueParam("form:upload", null);
+ param.create();
+
+ byte[] bytes = "testing...".getBytes();
+ param.handle(bytes, bytes.length - 3);
+
+ param.complete();
+
+ assertEquals("testing", param.getValue());
+ }
+}
Modified: trunk/ui/input/ui/src/test/java/org/richfaces/request/MockUploadResource.java
===================================================================
--- trunk/ui/input/ui/src/test/java/org/richfaces/request/MockUploadResource.java 2011-04-21 13:15:55 UTC (rev 22437)
+++ trunk/ui/input/ui/src/test/java/org/richfaces/request/MockUploadResource.java 2011-04-21 15:55:38 UTC (rev 22438)
@@ -101,7 +101,7 @@
@Override
public long getSize() {
- return invokeMethod(this.control, this, getSizeMethod0);
+ return (Long) invokeMethod(this.control, this, getSizeMethod0);
}
private static final Method writeMethod0 = findMethod(FileUploadResource.class, "write", String.class);
Added: trunk/ui/input/ui/src/test/java/org/richfaces/request/ProgressControlTest.java
===================================================================
--- trunk/ui/input/ui/src/test/java/org/richfaces/request/ProgressControlTest.java (rev 0)
+++ trunk/ui/input/ui/src/test/java/org/richfaces/request/ProgressControlTest.java 2011-04-21 15:55:38 UTC (rev 22438)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.Map;
+
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ProgressControlTest {
+
+ private static final String UPLOAD_ID = "testId";
+
+ private static final String ATTRIBUTE_NAME = ProgressControl.getContextAttributeName(UPLOAD_ID);
+
+ @Test
+ public void testAdvance() throws Exception {
+ Map<String, Object> contextMap = Maps.newHashMap();
+ ProgressControl control = new ProgressControl(contextMap, UPLOAD_ID, 400);
+
+ assertNull(contextMap.get(ATTRIBUTE_NAME));
+ control.advance(1);
+ assertNull(contextMap.get(ATTRIBUTE_NAME));
+
+ control.advance(3);
+ assertEquals((byte) 1, contextMap.get(ATTRIBUTE_NAME));
+
+ control.advance(196);
+ assertEquals((byte) 50, contextMap.get(ATTRIBUTE_NAME));
+
+ control.advance(200);
+ assertEquals((byte) 100, contextMap.get(ATTRIBUTE_NAME));
+ }
+
+ @Test
+ public void testClearProgress() throws Exception {
+ Map<String, Object> contextMap = Maps.newHashMap();
+ ProgressControl control = new ProgressControl(contextMap, UPLOAD_ID, 100);
+
+ assertNull(contextMap.get(ATTRIBUTE_NAME));
+ control.advance(50);
+ assertNotNull(contextMap.get(ATTRIBUTE_NAME));
+ control.clearProgress();
+ assertNull(contextMap.get(ATTRIBUTE_NAME));
+ }
+}
13 years, 8 months
JBoss Rich Faces SVN: r22437 - in trunk/ui/input/ui/src/test/java/org/richfaces: request and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2011-04-21 09:15:55 -0400 (Thu, 21 Apr 2011)
New Revision: 22437
Added:
trunk/ui/input/ui/src/test/java/org/richfaces/request/
trunk/ui/input/ui/src/test/java/org/richfaces/request/MockUploadResource.java
trunk/ui/input/ui/src/test/java/org/richfaces/request/UploadedFile25Test.java
Log:
RF-10128
Added: trunk/ui/input/ui/src/test/java/org/richfaces/request/MockUploadResource.java
===================================================================
--- trunk/ui/input/ui/src/test/java/org/richfaces/request/MockUploadResource.java (rev 0)
+++ trunk/ui/input/ui/src/test/java/org/richfaces/request/MockUploadResource.java 2011-04-21 13:15:55 UTC (rev 22437)
@@ -0,0 +1,121 @@
+/*
+ * GENERATED FILE - DO NOT EDIT
+ */
+
+package org.richfaces.request;
+
+import static org.easymock.EasyMock.createControl;
+import static org.jboss.test.faces.mock.FacesMockController.findMethod;
+import static org.jboss.test.faces.mock.FacesMockController.invokeMethod;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+
+import org.easymock.IMocksControl;
+import org.easymock.internal.ThrowableWrapper;
+import org.jboss.test.faces.mock.FacesMockController.MockObject;
+
+public class MockUploadResource extends FileUploadResource implements MockObject {
+
+ private final IMocksControl control;
+
+ private final String name;
+
+ /**
+ * Default constructor
+ */
+ public MockUploadResource() {
+ super(null, null);
+ this.control = createControl();
+ this.name = null;
+ }
+
+ /**
+ * @param control
+ */
+ public MockUploadResource(IMocksControl control, String name) {
+ super(null, null);
+ this.control = control;
+ this.name = name;
+ }
+
+ public IMocksControl getControl() {
+ return control;
+ }
+
+ public String toString() {
+ return getClass().getSimpleName() + (name != null ? name : "");
+ }
+
+ public boolean equals(Object obj) {
+ return this == obj;
+ }
+
+ public int hashCode() {
+ if (name != null) {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + name.hashCode();
+ result = prime * result + getClass().getName().hashCode();
+ return result;
+ } else {
+ return System.identityHashCode(this);
+ }
+ }
+
+ private static final Method createMethod0 = findMethod(FileUploadResource.class, "create");
+
+ public void create() throws IOException {
+ invokeMethod(this.control, this, createMethod0);
+ }
+
+ private static final Method completeMethod0 = findMethod(FileUploadResource.class, "complete");
+
+ public void complete() {
+ invokeMethod(this.control, this, completeMethod0);
+ }
+
+ private static final Method handleMethod0 = findMethod(FileUploadResource.class, "handle", byte[].class, Integer.TYPE);
+
+ public void handle(byte[] bytes, int length) throws IOException {
+ invokeMethod(this.control, this, handleMethod0, bytes, length);
+ }
+
+ private static final Method getInputStreamMethod0 = findMethod(FileUploadResource.class, "getInputStream");
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ try {
+ return invokeMethod(this.control, this, getInputStreamMethod0);
+ } catch (RuntimeException e) {
+ if (e.getCause() instanceof ThrowableWrapper && ((ThrowableWrapper) e.getCause()).getThrowable() instanceof IOException) {
+ throw (IOException) ((ThrowableWrapper) e.getCause()).getThrowable();
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ private static final Method getSizeMethod0 = findMethod(FileUploadResource.class, "getSize");
+
+ @Override
+ public long getSize() {
+ return invokeMethod(this.control, this, getSizeMethod0);
+ }
+
+ private static final Method writeMethod0 = findMethod(FileUploadResource.class, "write", String.class);
+
+ @Override
+ public void write(String fileName) throws IOException {
+ invokeMethod(this.control, this, writeMethod0, fileName);
+ }
+
+ private static final Method deleteMethod0 = findMethod(FileUploadResource.class, "delete");
+
+ @Override
+ public void delete() throws IOException {
+ invokeMethod(this.control, this, deleteMethod0);
+ }
+
+}
Added: trunk/ui/input/ui/src/test/java/org/richfaces/request/UploadedFile25Test.java
===================================================================
--- trunk/ui/input/ui/src/test/java/org/richfaces/request/UploadedFile25Test.java (rev 0)
+++ trunk/ui/input/ui/src/test/java/org/richfaces/request/UploadedFile25Test.java 2011-04-21 13:15:55 UTC (rev 22437)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+import org.jboss.test.faces.mock.MockTestRunner;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.exception.FileUploadException;
+
+import com.google.common.collect.LinkedListMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Sets;
+import com.google.common.io.ByteStreams;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+(a)RunWith(MockTestRunner.class)
+public class UploadedFile25Test {
+
+ private static final String TEST_DATA = "test data";
+
+ private static final IAnswer<InputStream> INPUT_STREAM_SUPPLIER = new IAnswer<InputStream>() {
+
+ public InputStream answer() throws Throwable {
+ return new ByteArrayInputStream(TEST_DATA.getBytes());
+ }
+ };
+
+ private UploadedFile25 uploadedFile;
+
+ private MockUploadResource uploadResource;
+
+ @Before
+ public void setUp() throws Exception {
+ Multimap<String,String> headers = LinkedListMultimap.<String, String>create();
+
+ headers.put("content-type", "image/png");
+ headers.put("filename", "x.png");
+ headers.put("x-rftest", "set");
+ headers.put("x-rftest", "of");
+ headers.put("x-rftest", "values");
+
+ uploadResource = new MockUploadResource();
+ uploadedFile = new UploadedFile25("form:fileUpload", uploadResource, headers);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ uploadResource = null;
+ uploadedFile = null;
+ }
+
+ @Test
+ public void testAttributes() throws Exception {
+ assertEquals("form:fileUpload", uploadedFile.getParameterName());
+ assertEquals("image/png", uploadedFile.getContentType());
+ assertEquals("x.png", uploadedFile.getName());
+ }
+
+ @Test
+ public void testHeaders() throws Exception {
+ assertEquals("image/png", uploadedFile.getHeader("Content-Type"));
+ assertEquals("set", uploadedFile.getHeader("X-RFTest"));
+ assertNull(uploadedFile.getHeader("X-RFUnknown"));
+
+ assertEquals(Arrays.asList("image/png"), Lists.newArrayList(uploadedFile.getHeaders("Content-Type")));
+ assertEquals(Arrays.asList("set", "of", "values"), Lists.newArrayList(uploadedFile.getHeaders("X-RFTest")));
+ assertEquals(Arrays.asList(), Lists.newArrayList(uploadedFile.getHeaders("X-RFUnknown")));
+
+ Collection<String> sortedHeaderNames = Sets.newTreeSet(uploadedFile.getHeaderNames());
+ assertEquals(Sets.newLinkedHashSet(Arrays.asList("content-type", "filename", "x-rftest")), sortedHeaderNames);
+ }
+
+ @Test
+ public void testResource() throws Exception {
+ EasyMock.expect(uploadResource.getSize()).andStubReturn((long) TEST_DATA.length());
+ EasyMock.expect(uploadResource.getInputStream()).andStubAnswer(INPUT_STREAM_SUPPLIER);
+
+ uploadResource.write(EasyMock.eq("output.png"));
+ EasyMock.expectLastCall();
+
+ uploadResource.delete();
+ EasyMock.expectLastCall();
+
+ uploadResource.getControl().replay();
+
+ assertEquals(TEST_DATA.length(), uploadedFile.getSize());
+ assertNotNull(uploadedFile.getInputStream());
+
+ assertEquals(TEST_DATA, new String(ByteStreams.toByteArray(uploadedFile.getInputStream()), "US-ASCII"));
+ assertEquals(TEST_DATA, new String(uploadedFile.getData(), "US-ASCII"));
+
+ uploadedFile.write("output.png");
+ uploadedFile.delete();
+ }
+
+ @Test
+ public void testGetDataExceptions() throws Exception {
+ EasyMock.expect(uploadResource.getSize()).andStubReturn((long) Long.MAX_VALUE);
+ EasyMock.expect(uploadResource.getInputStream()).andStubAnswer(INPUT_STREAM_SUPPLIER);
+
+ uploadResource.getControl().replay();
+
+ try {
+ uploadedFile.getData();
+
+ fail();
+ } catch (FileUploadException e) {
+ //expected - ignore
+ }
+
+ uploadResource.getControl().reset();
+
+ EasyMock.expect(uploadResource.getSize()).andStubReturn(1l);
+ EasyMock.expect(uploadResource.getInputStream()).andStubThrow(new IOException("No stream available"));
+
+ uploadResource.getControl().replay();
+
+ try {
+ uploadedFile.getData();
+
+ fail();
+ } catch (FileUploadException e) {
+ //expected - ignore
+ assertTrue(e.getCause() instanceof IOException);
+ }
+ }
+}
13 years, 8 months
JBoss Rich Faces SVN: r22436 - in trunk/ui/input: api/src/main/java/org/richfaces/exception and 8 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2011-04-21 08:19:14 -0400 (Thu, 21 Apr 2011)
New Revision: 22436
Added:
trunk/ui/input/api/src/main/java/org/richfaces/exception/
trunk/ui/input/api/src/main/java/org/richfaces/exception/FileUploadException.java
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadExternalContextFactory.java
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadFacesContextFactory.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/BaseMultipartRequest.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/BaseUploadedFile.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadDiscResource.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadMemoryResource.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadParam.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadResource.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadValueParam.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest25.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequestParser.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressServletInputStream.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/UploadedFile25.java
Removed:
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java
trunk/ui/input/ui/src/main/java/org/richfaces/exception/FileUploadException.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/FileParam.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/Param.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/ValueParam.java
Modified:
trunk/ui/input/api/src/main/java/org/richfaces/model/UploadedFile.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest.java
trunk/ui/input/ui/src/main/java/org/richfaces/resource/FileUploadProgressResource.java
trunk/ui/input/ui/src/main/resources/META-INF/fileupload.faces-config.xml
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js
Log:
Copied: trunk/ui/input/api/src/main/java/org/richfaces/exception/FileUploadException.java (from rev 22426, trunk/ui/input/ui/src/main/java/org/richfaces/exception/FileUploadException.java)
===================================================================
--- trunk/ui/input/api/src/main/java/org/richfaces/exception/FileUploadException.java (rev 0)
+++ trunk/ui/input/api/src/main/java/org/richfaces/exception/FileUploadException.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,46 @@
+/*
+ * 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.exception;
+
+import javax.faces.FacesException;
+
+
+/**
+ * Thrown when an exception occurs while uploading a file.
+ *
+ */
+public class FileUploadException extends FacesException {
+
+ private static final long serialVersionUID = -3579917878909990838L;
+
+ public FileUploadException() {
+ this(null, null);
+ }
+
+ public FileUploadException(String message) {
+ this(message, null);
+ }
+
+ public FileUploadException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Modified: trunk/ui/input/api/src/main/java/org/richfaces/model/UploadedFile.java
===================================================================
--- trunk/ui/input/api/src/main/java/org/richfaces/model/UploadedFile.java 2011-04-21 12:16:50 UTC (rev 22435)
+++ trunk/ui/input/api/src/main/java/org/richfaces/model/UploadedFile.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -21,16 +21,36 @@
*/
package org.richfaces.model;
+import java.io.IOException;
import java.io.InputStream;
+import java.util.Collection;
+import org.richfaces.exception.FileUploadException;
+
/**
* @author Konstantin Mishin
*
*/
public interface UploadedFile {
String getContentType();
- byte[] getData();
- InputStream getInputStream();
+
+ byte[] getData() throws FileUploadException;
+
+ InputStream getInputStream() throws IOException;
+
String getName();
+
long getSize();
+
+ void delete() throws IOException;
+
+ void write(String fileName) throws IOException;
+
+ String getHeader(String headerName);
+
+ Collection<String> getHeaderNames();
+
+ Collection<String> getHeaders(String headerName);
+
+ String getParameterName();
}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadExternalContextFactory.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadExternalContextFactory.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadExternalContextFactory.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,228 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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 java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.AbstractMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import javax.faces.FacesException;
+import javax.faces.FacesWrapper;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.ExternalContextFactory;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.richfaces.exception.FileUploadException;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.model.UploadedFile;
+import org.richfaces.request.MultipartRequest;
+import org.richfaces.request.MultipartRequest.ResponseState;
+import org.richfaces.request.MultipartRequest25;
+import org.richfaces.request.MultipartRequestParser;
+import org.richfaces.request.ProgressControl;
+
+import com.google.common.collect.LinkedListMultimap;
+import com.google.common.collect.Lists;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FileUploadExternalContextFactory extends ExternalContextFactory implements FacesWrapper<ExternalContextFactory> {
+
+ private static class HttpSessionMap extends AbstractMap<String, Object> {
+
+ private HttpSession session;
+
+ public HttpSessionMap(HttpSession session) {
+ super();
+ this.session = session;
+ }
+
+ @Override
+ public Object get(Object key) {
+ return session.getAttribute((String) key);
+ }
+
+ @Override
+ public Object put(String key, Object value) {
+ session.setAttribute(key, value);
+ return null;
+ }
+
+ @Override
+ public Object remove(Object key) {
+ session.removeAttribute((String) key);
+ return null;
+ }
+
+ @Override
+ public Set<java.util.Map.Entry<String, Object>> entrySet() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public static final String UID_KEY = "rf_fu_uid";
+
+ private static final Logger LOGGER = RichfacesLogger.CONTEXT.getLogger();
+
+ private static final Pattern AMPERSAND = Pattern.compile("&+");
+
+ private ExternalContextFactory wrappedFactory;
+
+ public FileUploadExternalContextFactory(ExternalContextFactory wrappedFactory) {
+ super();
+
+ //TODO Use ConfigurationServiceHelper to initialize InitParameters.
+ this.wrappedFactory = wrappedFactory;
+ }
+
+ @Override
+ public ExternalContextFactory getWrapped() {
+ return wrappedFactory;
+ }
+
+ private String getParameterValueFromQueryString(String queryString, String paramName) {
+ if (queryString != null) {
+ String[] nvPairs = AMPERSAND.split(queryString);
+ for (String nvPair : nvPairs) {
+ if (nvPair.length() == 0) {
+ continue;
+ }
+
+ int eqIdx = nvPair.indexOf('=');
+ if (eqIdx >= 0) {
+ try {
+ String name = URLDecoder.decode(nvPair.substring(0, eqIdx), "UTF-8");
+
+ if (paramName.equals(name)) {
+ return URLDecoder.decode(nvPair.substring(eqIdx + 1), "UTF-8");
+ }
+ } catch (UnsupportedEncodingException e) {
+ // log warning and skip this parameter
+ LOGGER.debug(e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private boolean isCreateTempFiles(ServletContext servletContext) {
+ String param = servletContext.getInitParameter("org.richfaces.fileUpload.createTempFiles");
+ if (param != null) {
+ return Boolean.parseBoolean(param);
+ }
+
+ return true;
+ }
+
+ private String getTempFilesDirectory(ServletContext servletContext) {
+ String result = servletContext.getInitParameter("org.richfaces.fileUpload.tempFilesDirectory");
+ if (result == null) {
+ File servletTempDir = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
+ if (servletTempDir != null) {
+ result = servletTempDir.getAbsolutePath();
+ }
+ }
+ if (result == null) {
+ result = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
+ }
+
+ return result;
+ }
+
+ private long getMaxRequestSize(ServletContext servletContext) {
+ String param = servletContext.getInitParameter("org.richfaces.fileUpload.maxRequestSize");
+ if (param != null) {
+ return Long.parseLong(param);
+ }
+
+ return 0;
+ }
+
+ @Override
+ public ExternalContext getExternalContext(Object context, Object request, Object response) throws FacesException {
+ Object wrappedRequest = request;
+
+ if (wrappedRequest instanceof HttpServletRequest) {
+ HttpServletRequest httpRequest = (HttpServletRequest) wrappedRequest;
+
+ if (httpRequest.getContentType() != null && httpRequest.getContentType().startsWith("multipart/")) {
+ String uid = getParameterValueFromQueryString(httpRequest.getQueryString(), UID_KEY);
+
+ if (uid != null) {
+ long contentLength = Long.parseLong(httpRequest.getHeader("Content-Length"));
+
+ Map<String,Object> contextMap = new HttpSessionMap(httpRequest.getSession());
+
+ ProgressControl progressControl = new ProgressControl(contextMap, uid, contentLength);
+
+ wrappedRequest = wrapMultipartRequestServlet25((ServletContext) context, httpRequest, uid,
+ contentLength, progressControl);
+ }
+ }
+ }
+
+ return getWrapped().getExternalContext(context, wrappedRequest, response);
+ }
+
+ private MultipartRequest wrapMultipartRequestServlet25(ServletContext servletContext, HttpServletRequest request,
+ String uploadId, long contentLength, ProgressControl progressControl) {
+
+ MultipartRequest multipartRequest;
+
+ long maxRequestSize = getMaxRequestSize(servletContext);
+ if (maxRequestSize == 0 || contentLength <= maxRequestSize) {
+ MultipartRequestParser requestParser = new MultipartRequestParser(request, isCreateTempFiles(servletContext),
+ getTempFilesDirectory(servletContext), progressControl);
+
+ ResponseState result = ResponseState.ok;
+
+ try {
+ requestParser.parse();
+ } catch (FileUploadException e) {
+ result = ResponseState.serverError;
+ }
+
+ multipartRequest = new MultipartRequest25(request, uploadId, progressControl, requestParser.getParameters(),
+ requestParser.getUploadedFiles(), result);
+ } else {
+ multipartRequest = new MultipartRequest25(request, uploadId, progressControl, LinkedListMultimap.<String, String>create(),
+ Lists.<UploadedFile>newArrayList(), ResponseState.sizeExceeded);
+ }
+
+ request.setAttribute(MultipartRequest.REQUEST_ATTRIBUTE_NAME, multipartRequest);
+
+ return multipartRequest;
+ }
+
+}
\ No newline at end of file
Added: trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadFacesContextFactory.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadFacesContextFactory.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadFacesContextFactory.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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 java.io.IOException;
+import java.io.Writer;
+
+import javax.faces.FacesException;
+import javax.faces.FacesWrapper;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.context.FacesContextWrapper;
+import javax.faces.lifecycle.Lifecycle;
+import javax.servlet.http.HttpServletResponse;
+
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.request.MultipartRequest;
+import org.richfaces.request.MultipartRequest.ResponseState;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FileUploadFacesContextFactory extends FacesContextFactory implements FacesWrapper<FacesContextFactory> {
+
+ private static final Logger LOGGER = RichfacesLogger.CONTEXT.getLogger();
+
+ private static final class FileUploadFacesContext extends FacesContextWrapper {
+
+ private FacesContext facesContext;
+
+ public FileUploadFacesContext(FacesContext facesContext) {
+ super();
+ this.facesContext = facesContext;
+ }
+
+ @Override
+ public FacesContext getWrapped() {
+ return facesContext;
+ }
+
+ @Override
+ public void release() {
+ MultipartRequest multipartRequest = (MultipartRequest) getExternalContext().getRequestMap().get(MultipartRequest.REQUEST_ATTRIBUTE_NAME);
+
+ if (multipartRequest != null) {
+ multipartRequest.release();
+ }
+
+ super.release();
+ }
+ }
+
+ private FacesContextFactory wrappedFactory;
+
+ public FileUploadFacesContextFactory(FacesContextFactory wrappedFactory) {
+ super();
+ this.wrappedFactory = wrappedFactory;
+ }
+
+ @Override
+ public FacesContextFactory getWrapped() {
+ return wrappedFactory;
+ }
+
+ @Override
+ public FacesContext getFacesContext(Object context, Object request, Object response, Lifecycle lifecycle)
+ throws FacesException {
+
+ FacesContext facesContext = wrappedFactory.getFacesContext(context, request, response, lifecycle);
+
+ MultipartRequest multipartRequest = (MultipartRequest) facesContext.getExternalContext().getRequestMap().get(MultipartRequest.REQUEST_ATTRIBUTE_NAME);
+ if (multipartRequest != null) {
+ facesContext = new FileUploadFacesContext(facesContext);
+
+ if (multipartRequest.getResponseState() != ResponseState.ok) {
+ printResponse(facesContext, multipartRequest);
+ }
+ }
+
+ return facesContext;
+ }
+
+
+ private void printResponse(FacesContext facesContext, MultipartRequest multipartRequest) {
+ facesContext.responseComplete();
+ ExternalContext externalContext = facesContext.getExternalContext();
+ externalContext.setResponseStatus(HttpServletResponse.SC_OK);
+ externalContext.setResponseContentType("text/html");
+ try {
+ Writer writer = externalContext.getResponseOutputWriter();
+ writer.write("<html id=\"" + FileUploadExternalContextFactory.UID_KEY + multipartRequest.getUploadId() + ":" + multipartRequest.getResponseState() + "\"/>");
+ writer.close();
+ } catch (IOException e) {
+ LOGGER.error(e.getMessage(), e);
+ }
+ }
+}
Deleted: trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java 2011-04-21 12:16:50 UTC (rev 22435)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -1,194 +0,0 @@
-/*
- * 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.context;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.net.URLDecoder;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.PartialViewContext;
-import javax.faces.context.PartialViewContextFactory;
-import javax.faces.context.PartialViewContextWrapper;
-import javax.faces.event.PhaseId;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.richfaces.exception.FileUploadException;
-import org.richfaces.log.Logger;
-import org.richfaces.log.RichfacesLogger;
-import org.richfaces.request.MultipartRequest;
-
-/**
- * @author Konstantin Mishin
- *
- */
-public class FileUploadPartialViewContextFactory extends PartialViewContextFactory {
-
- public static final String UID_KEY = "rf_fu_uid";
-
- public static final String UID_ALT_KEY = "rf_fu_uid_alt";
-
- private static enum ResponseState {
- sizeExceeded, stopped, serverError
- };
-
- private static final Logger LOGGER = RichfacesLogger.CONTEXT.getLogger();
-
- private static final Pattern AMPERSAND = Pattern.compile("&+");
-
- private PartialViewContextFactory parentFactory;
-
- /** Flag indicating whether a temporary file should be used to cache the uploaded file */
- private boolean createTempFiles = true;
-
- private String tempFilesDirectory;
-
- /** The maximum size of a file upload request. 0 means no limit. */
- private long maxRequestSize = 0;
-
- public FileUploadPartialViewContextFactory(PartialViewContextFactory parentFactory) {
- this.parentFactory = parentFactory;
- ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
- //TODO Use ConfigurationServiceHelper to initialize InitParameters.
- String param = context.getInitParameter("org.richfaces.fileUpload.createTempFiles");
- if (param != null) {
- this.createTempFiles = Boolean.parseBoolean(param);
- }
- this.tempFilesDirectory = context.getInitParameter("org.richfaces.fileUpload.tempFilesDirectory");
- param = context.getInitParameter("org.richfaces.fileUpload.maxRequestSize");
- if (param != null) {
- this.maxRequestSize = Long.parseLong(param);
- }
- }
-
- @Override
- public PartialViewContext getPartialViewContext(FacesContext facesContext) {
- PartialViewContext partialViewContext = parentFactory.getPartialViewContext(facesContext);
- ExternalContext externalContext = facesContext.getExternalContext();
- Object request = externalContext.getRequest();
- if (request instanceof HttpServletRequest) {
- HttpServletRequest httpRequest = (HttpServletRequest) request;
- Map<String, String> queryParamMap = parseQueryString(httpRequest.getQueryString());
- String uid = queryParamMap.get(UID_KEY);
- if (uid != null) {
- long contentLength = Long.parseLong(externalContext.getRequestHeaderMap().get("Content-Length"));
- if (maxRequestSize != 0 && contentLength > maxRequestSize) {
- printResponse(facesContext, uid, ResponseState.sizeExceeded);
- } else {
- final MultipartRequest multipartRequest =
- new MultipartRequest(httpRequest, createTempFiles, tempFilesDirectory, uid);
- try {
- final PartialViewContext viewContext = partialViewContext;
- partialViewContext = new PartialViewContextWrapper() {
- @Override
- public void processPartial(PhaseId phaseId) {
- try {
- super.processPartial(phaseId);
- } finally {
- if (PhaseId.RENDER_RESPONSE.equals(phaseId)) {
- multipartRequest.cancel();
- // TODO PartialViewContext.release isn't invoked by JSF. Maybe it's a bug.
- // So we should use PartialViewContext.processPartial instead of.
- }
- }
- }
-
- // TODO This method can be removed from here when PartialViewContextWrapper will implement
- // it.
- @Override
- public void setPartialRequest(boolean isPartialRequest) {
- viewContext.setPartialRequest(isPartialRequest);
- }
-
- @Override
- public PartialViewContext getWrapped() {
- return viewContext;
- }
- };
- multipartRequest.parseRequest();
- if (!multipartRequest.isDone()) {
- printResponse(facesContext, uid, ResponseState.stopped);
- } else {
- externalContext.setRequest(multipartRequest);
- }
- } catch (FileUploadException e) {
- printResponse(facesContext, uid, ResponseState.serverError);
- } finally {
- multipartRequest.clearRequestData();
- }
- }
- }
- }
- return partialViewContext;
- }
-
- private Map<String, String> parseQueryString(String queryString) {
- if (queryString != null) {
- Map<String, String> parameters = new HashMap<String, String>();
- String[] nvPairs = AMPERSAND.split(queryString);
- for (String nvPair : nvPairs) {
- if (nvPair.length() == 0) {
- continue;
- }
-
- int eqIdx = nvPair.indexOf('=');
- if (eqIdx >= 0) {
- try {
- String name = URLDecoder.decode(nvPair.substring(0, eqIdx), "UTF-8");
- if (!parameters.containsKey(name)) {
- String value = URLDecoder.decode(nvPair.substring(eqIdx + 1), "UTF-8");
-
- parameters.put(name, value);
- }
- } catch (UnsupportedEncodingException e) {
- // log warning and skip this parameter
- LOGGER.warn(e.getLocalizedMessage(), e);
- }
- }
- }
- return parameters;
- } else {
- return Collections.emptyMap();
- }
- }
-
- private void printResponse(FacesContext facesContext, String uid, ResponseState state) {
- facesContext.responseComplete();
- ExternalContext externalContext = facesContext.getExternalContext();
- externalContext.setResponseStatus(HttpServletResponse.SC_OK);
- externalContext.setResponseContentType(MultipartRequest.TEXT_HTML);
- try {
- Writer writer = externalContext.getResponseOutputWriter();
- writer.write("<html id=\"" + UID_KEY + uid + ":" + state + "\"/>");
- writer.close();
- } catch (IOException e) {
- LOGGER.error(e);
- }
- }
-}
Deleted: trunk/ui/input/ui/src/main/java/org/richfaces/exception/FileUploadException.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/exception/FileUploadException.java 2011-04-21 12:16:50 UTC (rev 22435)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/exception/FileUploadException.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -1,43 +0,0 @@
-/*
- * 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.exception;
-
-/**
- * Thrown when an exception occurs while uploading a file.
- *
- */
-public class FileUploadException extends RuntimeException {
-
- private static final long serialVersionUID = -3579917878909990838L;
-
- public FileUploadException() {
- this(null, null);
- }
-
- public FileUploadException(String message) {
- this(message, null);
- }
-
- public FileUploadException(String message, Throwable cause) {
- super(message, cause);
- }
-}
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java 2011-04-21 12:16:50 UTC (rev 22435)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -31,18 +31,22 @@
/**
* @author Konstantin Mishin
- *
+ * @author Nick Belaevski
*/
public class FileUploadRendererBase extends RendererBase {
@Override
protected void doDecode(FacesContext context, UIComponent component) {
ExternalContext externalContext = context.getExternalContext();
- Object request = externalContext.getRequest();
- if (request instanceof MultipartRequest) {
- UploadedFile file = ((MultipartRequest) request).getUploadedFile(component.getClientId(context));
- if (file != null) {
- component.queueEvent(new FileUploadEvent(component, file));
+ MultipartRequest multipartRequest = (MultipartRequest) externalContext.getRequestMap().get(MultipartRequest.REQUEST_ATTRIBUTE_NAME);
+ if (multipartRequest != null) {
+ String clientId = component.getClientId(context);
+
+ for (UploadedFile file : multipartRequest.getUploadedFiles()) {
+ if (clientId.equals(file.getParameterName())) {
+ component.queueEvent(new FileUploadEvent(component, file));
+ break;
+ }
}
}
}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/BaseMultipartRequest.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/BaseMultipartRequest.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/BaseMultipartRequest.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Maps;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+abstract class BaseMultipartRequest extends HttpServletRequestWrapper implements MultipartRequest {
+
+ static final String CONTENT_TYPE = "application/x-www-form-urlencoded";
+
+ static final Map<String, String> HEADERS_MAP;
+
+ static {
+ HEADERS_MAP = Maps.newHashMap();
+
+ HEADERS_MAP.put("accept", "text/html");
+ HEADERS_MAP.put("faces-request", "partial/ajax");
+ HEADERS_MAP.put("content-type", CONTENT_TYPE);
+ }
+
+ private String uploadId;
+
+ private ProgressControl progressControl;
+
+ /**
+ * @param request
+ */
+ public BaseMultipartRequest(HttpServletRequest request, String uploadId, ProgressControl progressControl) {
+ super(request);
+ this.uploadId = uploadId;
+ this.progressControl = progressControl;
+ }
+
+ public String getUploadId() {
+ return uploadId;
+ }
+
+ public void release() {
+ progressControl.clearProgress();
+ }
+
+ @Override
+ public String getHeader(String name) {
+ String headerValue = HEADERS_MAP.get(name.toLowerCase(Locale.US));
+
+ if (!Strings.isNullOrEmpty(headerValue)) {
+ return headerValue;
+ }
+
+ return super.getHeader(name);
+ }
+
+ @Override
+ public String getContentType() {
+ return getHeader("Content-Type");
+ }
+
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/BaseUploadedFile.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/BaseUploadedFile.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/BaseUploadedFile.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.richfaces.exception.FileUploadException;
+import org.richfaces.model.UploadedFile;
+
+import com.google.common.io.ByteStreams;
+import com.google.common.io.Closeables;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class BaseUploadedFile implements UploadedFile {
+
+ private String parameterName;
+
+ public BaseUploadedFile(String parameterName) {
+ super();
+ this.parameterName = parameterName;
+ }
+
+ public String getParameterName() {
+ return parameterName;
+ }
+
+ public String getName() {
+ return getHeader(MultipartRequestParser.PARAM_FILENAME);
+ }
+
+ public String getContentType() {
+ return getHeader(MultipartRequestParser.PARAM_CONTENT_TYPE);
+ }
+
+ public byte[] getData() {
+ long size = getSize();
+
+ if (size > Integer.MAX_VALUE) {
+ throw new FileUploadException("Resource content is too long to be allocated as byte[]");
+ }
+
+ InputStream is = null;
+ try {
+ is = getInputStream();
+ byte[] result = new byte[(int) size];
+ ByteStreams.readFully(is, result);
+ return result;
+ } catch (IOException e) {
+ throw new FileUploadException(e.getMessage(), e);
+ } finally {
+ Closeables.closeQuietly(is);
+ }
+ }
+
+}
Deleted: trunk/ui/input/ui/src/main/java/org/richfaces/request/FileParam.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/FileParam.java 2011-04-21 12:16:50 UTC (rev 22435)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/FileParam.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -1,173 +0,0 @@
-/*
- * 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.request;
-
-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.OutputStream;
-
-import org.richfaces.exception.FileUploadException;
-import org.richfaces.log.Logger;
-import org.richfaces.log.RichfacesLogger;
-import org.richfaces.model.UploadedFile;
-
-/**
- * @author Konstantin Mishin
- *
- */
-class FileParam implements Param, UploadedFile {
-
- private static final Logger LOGGER = RichfacesLogger.APPLICATION.getLogger();
-
- private String name;
- private String contentType;
- private OutputStream outputStream;
- private File file;
- private byte[] data;
-
- public FileParam(String name, String contentType, boolean createTempFiles, String tempFilesDirectory) {
- if (createTempFiles) {
- try {
- File dir = null;
- if (tempFilesDirectory != null) {
- dir = new File(tempFilesDirectory);
- }
- file = File.createTempFile("richfaces_uploaded_file_", null, dir);
- file.deleteOnExit();
- outputStream = new FileOutputStream(file);
- } catch (IOException ex) {
- if (outputStream != null) {
- try {
- outputStream.close();
- } catch (IOException e) {
- LOGGER.error(e.getMessage(), e);
- }
- }
- throw new FileUploadException("Could not create temporary file");
- }
- } else {
- outputStream = new ByteArrayOutputStream();
- }
- this.name = name;
- this.contentType = contentType;
- }
-
- public String getName() {
- return name;
- }
-
- public String getContentType() {
- return contentType;
- }
-
- public long getSize() {
- long size = -1;
- if (data != null) {
- size = data.length;
- } else {
- size = file.length();
- }
- return size;
- }
-
- public byte[] getData() {
- byte[] result = null;
- if (data != null) {
- result = data;
- } else {
- long fileLength = file.length();
- if (fileLength > Integer.MAX_VALUE) {
- throw new IllegalArgumentException("File content is too long to be allocated as byte[]");
- } else {
- FileInputStream inputStream = null;
- try {
- inputStream = new FileInputStream(file);
- byte[] fileData = new byte[(int) fileLength];
- int totalRead = 0;
- int read;
- do {
- read = inputStream.read(fileData, totalRead, fileData.length - totalRead);
- totalRead += read;
- } while (read > 0);
- result = fileData;
- } catch (IOException ex) {
- LOGGER.error(ex.getMessage(), ex);
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- LOGGER.error(e.getMessage(), e);
- }
- }
- }
- }
- }
- return result;
- }
-
- public InputStream getInputStream() {
- InputStream stream = null;
- if (data != null) {
- stream = new ByteArrayInputStream(data);
- } else {
- try {
- stream = new FileInputStream(file);
- } catch (FileNotFoundException ex) {
- LOGGER.error(ex.getMessage(), ex);
- }
- }
- return stream;
- }
-
- public void complete() throws IOException {
- if (outputStream instanceof ByteArrayOutputStream) {
- data = ((ByteArrayOutputStream) outputStream).toByteArray();
- } else {
- try {
- outputStream.close();
- } catch (IOException ex) {
- LOGGER.error(ex.getMessage(), ex);
- }
- }
- outputStream = null;
- }
-
- public void clear() {
- if (data != null) {
- data = null;
- } else {
- file.delete();
- }
- }
-
- public void handle(byte[] bytes, int length) throws IOException {
- outputStream.write(bytes, 0, length);
- outputStream.flush();
- }
-}
\ No newline at end of file
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadDiscResource.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadDiscResource.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadDiscResource.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.MessageFormat;
+
+import com.google.common.io.Closeables;
+
+/**
+ * @author Nick Belaevski
+ */
+final class FileUploadDiscResource extends FileUploadResource {
+
+ private File file;
+
+ private FileOutputStream fos;
+
+ public FileUploadDiscResource(String name, String uploadLocation) {
+ super(name, uploadLocation);
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return new FileInputStream(file);
+ }
+
+ @Override
+ public long getSize() {
+ return file.length();
+ }
+
+ @Override
+ public void write(String fileName) throws IOException {
+ boolean writeResult = file.renameTo(getOutputFile(fileName));
+
+ if (!writeResult) {
+ throw new IOException(MessageFormat.format("Write to disc resource {0} failed", fileName));
+ }
+ }
+
+ @Override
+ public void delete() throws IOException {
+ complete();
+
+ if (file == null || !file.exists()) {
+ return;
+ }
+
+ boolean deleteResult = file.delete();
+
+ if (!deleteResult) {
+ throw new IOException("File delete failed");
+ }
+ }
+
+ public void create() throws IOException {
+ file = File.createTempFile("richfaces_uploaded_file_", null, getOutputFile(null));
+ file.deleteOnExit();
+ fos = new FileOutputStream(file);
+ }
+
+ public void handle(byte[] bytes, int length) throws IOException {
+ fos.write(bytes, 0, length);
+ }
+
+ public void complete() {
+ Closeables.closeQuietly(fos);
+ fos = null;
+ }
+
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadMemoryResource.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadMemoryResource.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadMemoryResource.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.ajax4jsf.io.ByteBuffer;
+import org.ajax4jsf.io.FastBufferInputStream;
+
+import com.google.common.io.Files;
+import com.google.common.io.InputSupplier;
+
+/**
+ * @author Nick Belaevski
+ */
+class FileUploadMemoryResource extends FileUploadResource {
+
+ private ByteBuffer buffer;
+
+ public FileUploadMemoryResource(String name, String uploadLocation) {
+ super(name, uploadLocation);
+ }
+
+ private void checkNotDeleted() throws IOException {
+ if (buffer == null) {
+ throw new IOException("Resource has been deleted");
+ }
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ checkNotDeleted();
+
+ return new FastBufferInputStream(buffer);
+ }
+
+ @Override
+ public long getSize() {
+ return buffer.getLast().getTotalSize();
+ }
+
+ @Override
+ public void write(String fileName) throws IOException {
+ checkNotDeleted();
+
+ InputSupplier<InputStream> inputSupplier = new InputSupplier<InputStream>() {
+ public InputStream getInput() throws IOException {
+ return getInputStream();
+ }
+ };
+
+ Files.copy(inputSupplier, getOutputFile(fileName));
+ }
+
+ @Override
+ public void delete() throws IOException {
+ buffer = null;
+ }
+
+ public void handle(byte[] bytes, int length) throws IOException {
+ buffer.append(bytes, 0, length);
+ }
+
+ public void create() {
+ buffer = new ByteBuffer(128);
+ }
+
+ public void complete() {
+ buffer.compact();
+ }
+
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadParam.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadParam.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadParam.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.io.IOException;
+
+import org.richfaces.request.ByteSequenceMatcher.BytesHandler;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+interface FileUploadParam extends BytesHandler {
+
+ public void create() throws IOException;
+
+ public void complete();
+
+ public String getName();
+
+ public boolean isFileParam();
+
+ public String getValue();
+
+ public FileUploadResource getResource();
+
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadResource.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadResource.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadResource.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import com.google.common.base.Strings;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+abstract class FileUploadResource implements FileUploadParam {
+
+ private String name;
+
+ private String uploadLocation;
+
+ public FileUploadResource(String name, String uploadLocation) {
+ super();
+
+ this.name = name;
+ this.uploadLocation = uploadLocation;
+ }
+
+ protected String getUploadLocation() {
+ return uploadLocation;
+ }
+
+ protected File getOutputFile(String name) {
+ if (Strings.isNullOrEmpty(name)) {
+ return new File(uploadLocation);
+ }
+
+ return new File(uploadLocation, name);
+ }
+
+ public abstract InputStream getInputStream() throws IOException;
+
+ public abstract long getSize();
+
+ public abstract void write(String fileName) throws IOException;
+
+ public abstract void delete() throws IOException;
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isFileParam() {
+ return true;
+ }
+
+ public String getValue() {
+ return null;
+ }
+
+ public FileUploadResource getResource() {
+ return this;
+ }
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadValueParam.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadValueParam.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/FileUploadValueParam.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import javax.faces.FacesException;
+
+import org.ajax4jsf.io.ByteBuffer;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+final class FileUploadValueParam implements FileUploadParam {
+
+ private ByteBuffer buffer;
+
+ private String name;
+
+ private String encoding;
+
+ private String value;
+
+ public FileUploadValueParam(String name, String encoding) {
+ super();
+
+ this.name = name;
+ this.encoding = encoding;
+ }
+
+ private byte[] getBufferBytes() {
+ byte[] bs = new byte[buffer.getLast().getTotalSize()];
+
+ int pos = 0;
+ ByteBuffer currentBuffer = buffer;
+ while (currentBuffer != null) {
+ System.arraycopy(currentBuffer.getBytes(), 0, bs, pos, currentBuffer.getUsedSize());
+ pos += currentBuffer.getUsedSize();
+ currentBuffer = currentBuffer.getNext();
+ }
+
+ return bs;
+ }
+
+ public void handle(byte[] bytes, int length) throws IOException {
+ buffer.append(bytes, 0, length);
+ }
+
+ public void create() throws IOException {
+ buffer = new ByteBuffer(256);
+ }
+
+ public void complete() {
+ byte[] bytes = getBufferBytes();
+ buffer = null;
+
+ try {
+ value = (encoding != null) ? new String(bytes, encoding) : new String(bytes);
+ } catch (UnsupportedEncodingException e) {
+ throw new FacesException(e.getMessage(), e);
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isFileParam() {
+ return false;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public FileUploadResource getResource() {
+ return null;
+ }
+}
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest.java 2011-04-21 12:16:50 UTC (rev 22435)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -1,641 +1,46 @@
-/*
- * 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.request;
-
-import java.io.ByteArrayOutputStream;
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-
-import org.richfaces.exception.FileUploadException;
-import org.richfaces.log.Logger;
-import org.richfaces.log.RichfacesLogger;
-import org.richfaces.model.UploadedFile;
-import org.richfaces.request.ByteSequenceMatcher.BytesHandler;
-
-public class MultipartRequest extends HttpServletRequestWrapper {
-
- public static final String TEXT_HTML = "text/html";
-
- /** Session bean name where progress bar's percent map will be stored */
- public static final String PERCENT_BEAN_NAME = "_richfaces_upload_percents";
-
- private static final BytesHandler NOOP_HANDLER = new BytesHandler() {
- public void handle(byte[] bytes, int length) {
- // do nothing
- }
- };
-
- /** Session bean name where request size will be stored */
- private static final String REQUEST_SIZE_BEAN_NAME = "_richfaces_request_size";
-
- 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 = 1024;
- private static final int MAX_HEADER_SIZE = 32768;
-
- private static final Logger LOGGER = RichfacesLogger.APPLICATION.getLogger();
-
- private static final byte CR = 0x0d;
- private static final byte LF = 0x0a;
- private static final byte[] CR_LF = {CR, LF};
- private static final byte[] HYPHENS = {0x2d, 0x2d}; // '--'
-
- private static final Pattern PARAM_VALUE_PATTERN = Pattern.compile("^\\s*([^\\s=]+)\\s*[=:]\\s*(.+)\\s*$");
-
- private static final Pattern FILE_NAME_PATTERN = Pattern.compile(".*filename=\"(.*)\"");
-
- private boolean createTempFiles;
-
- private String tempFilesDirectory;
-
- private String uid;
-
- private String encoding = null;
-
- private long contentLength = 0;
-
- private long bytesRead = 0;
-
- // we shouldn't allow to stop until request reaches PhaseListener because of portlets
- private volatile boolean canStop = false;
-
- private Map<String, Param> parameters = null;
-
- private Map<String, Object> percentMap = null;
-
- private Map<String, Long> requestSizeMap = null;
-
- private List<String> keys = new ArrayList<String>();
-
- private byte[] boundaryMarker;
-
- private ByteSequenceMatcher sequenceMatcher;
-
- private boolean shouldStop = false;
- private boolean canceled;
-
- private boolean initialized = false;
-
- private HeadersHandler headersHandler = null;
-
- public MultipartRequest(HttpServletRequest request, boolean createTempFiles, String tempFilesDirectory,
- String uid) {
- super(request);
- this.createTempFiles = createTempFiles;
- this.tempFilesDirectory = tempFilesDirectory;
- this.uid = uid;
- this.contentLength = Long.parseLong(request.getHeader("Content-Length"));
- }
-
- private class ControlledProgressInputStream extends FilterInputStream {
-
- protected ControlledProgressInputStream(InputStream in) {
- super(in);
- }
-
- @Override
- public int read() throws IOException {
- int read = super.read();
- if (read >= 0) {
- bytesRead++;
- fillProgressInfo();
- }
- return read;
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- int read = super.read(b);
- if (read > 0) {
- bytesRead += read;
- fillProgressInfo();
- }
- return read;
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- int read = super.read(b, off, len);
- if (read > 0) {
- bytesRead += read;
- fillProgressInfo();
- }
- return read;
- }
- }
-
- private String decodeFileName(String name) {
- String fileName = null;
- try {
- StringBuffer buffer = new StringBuffer();
- String[] codes = name.split(";");
- if (codes != null) {
- for (String code : codes) {
- if (code.startsWith("&")) {
- String sCode = code.replaceAll("[&#]*", "");
- Integer iCode = Integer.parseInt(sCode);
- buffer.append(Character.toChars(iCode));
- } else {
- buffer.append(code);
- }
- }
- fileName = buffer.toString();
- }
- } catch (Exception e) {
- fileName = name;
- }
-
- return fileName;
- }
-
- public void cancel() {
- this.canceled = true;
-
- if (parameters != null) {
- Iterator<Param> it = parameters.values().iterator();
- while (it.hasNext()) {
- Param p = it.next();
- if (p instanceof FileParam) {
- ((FileParam) p).clear();
- }
- }
- }
- }
-
- private void readNext() throws IOException {
- Param p = readHeader();
- if (p != null) {
- try {
- readData(p);
- } finally {
- try {
- p.complete();
- } catch (IOException e) {
- LOGGER.error(e.getMessage(), e);
- }
- }
- }
- }
-
- private Param createParam(Map<String, String> headers) {
- Param param = null;
- String paramName = headers.get(PARAM_NAME);
- if (paramName != null) {
- if (headers.containsKey(PARAM_FILENAME)) {
- param = new FileParam(decodeFileName(headers.get(PARAM_FILENAME)), headers.get(PARAM_CONTENT_TYPE),
- createTempFiles, tempFilesDirectory);
- this.keys.add(paramName);
- } else {
- if (parameters.containsKey(paramName)) {
- param = parameters.get(paramName);
- } else {
- param = new ValueParam(encoding);
- }
- }
-
- if (!parameters.containsKey(paramName)) {
- parameters.put(paramName, param);
- }
- }
-
- return param;
- }
-
- private class HeadersHandler implements BytesHandler {
-
- private ByteArrayOutputStream baos = new ByteArrayOutputStream(BUFFER_SIZE);
-
- public void handle(byte[] bytes, int length) throws IOException {
- if (length != 0) {
- if (baos.size() + length > MAX_HEADER_SIZE) {
- throw new IOException("Header section is too big");
- }
-
- baos.write(bytes, 0, length);
- }
- }
-
- public boolean dataEquals(byte[] bytes) {
- return (baos.size() == bytes.length) && Arrays.equals(HYPHENS, baos.toByteArray());
- }
-
- public String asString() throws UnsupportedEncodingException {
- if (encoding != null) {
- return baos.toString(encoding);
- } else {
- return baos.toString();
- }
- }
-
- public void reset() {
- baos.reset();
- }
-
- }
-
- private Param readHeader() throws IOException {
- if (sequenceMatcher.isEOF()) {
- return null;
- }
-
- if (headersHandler == null) {
- headersHandler = new HeadersHandler();
- } else {
- headersHandler.reset();
- }
-
- sequenceMatcher.setBytesHandler(headersHandler);
- sequenceMatcher.findSequence(-1, CR_LF);
-
- if (sequenceMatcher.isMatchedAndNotEOF() && !headersHandler.dataEquals(HYPHENS)) {
- headersHandler.reset();
-
- sequenceMatcher.findSequence(-1, CR_LF, CR_LF);
-
- if (!sequenceMatcher.isMatchedAndNotEOF()) {
- throw new IOException("Request header cannot be read");
- }
-
- String headersString = headersHandler.asString();
- Map<String, String> headers = new HashMap<String, String>();
- String[] split = headersString.split("\r\n");
- for (String headerString : split) {
- parseParams(headerString, "; ", headers);
- }
-
- return createParam(headers);
- }
-
- return null;
- }
-
- private void readProlog() throws IOException {
- sequenceMatcher.setBytesHandler(NOOP_HANDLER);
- sequenceMatcher.findSequence(-1, HYPHENS, boundaryMarker);
- if (!sequenceMatcher.isMatchedAndNotEOF()) {
- throw new IOException("Request prolog cannot be read");
- }
- }
-
- private void readData(final Param param) throws IOException {
- sequenceMatcher.setBytesHandler(param);
- sequenceMatcher.findSequence(CHUNK_SIZE, CR_LF, HYPHENS, boundaryMarker);
- if (!this.sequenceMatcher.isMatchedAndNotEOF()) {
- throw new IOException("Request data cannot be read");
- }
- }
-
- private void initialize() throws IOException {
- if (!initialized) {
- initialized = true;
-
- this.boundaryMarker = getBoundaryMarker(super.getContentType());
- if (this.boundaryMarker == null) {
- throw new FileUploadException("The request was rejected because " + "no multipart boundary was found");
- }
-
- if (HYPHENS.length + boundaryMarker.length + CHUNK_SIZE + CR_LF.length > BUFFER_SIZE) {
- throw new FileUploadException("Boundary marker is too long");
- }
-
- this.encoding = getCharacterEncoding();
-
- this.parameters = new HashMap<String, Param>();
-
- InputStream input = new ControlledProgressInputStream(getInputStream());
-
- this.sequenceMatcher = new ByteSequenceMatcher(input, BUFFER_SIZE);
-
- setupProgressData();
-
- readProlog();
- }
- }
-
- public void parseRequest() {
- canStop = true;
-
- setupProgressData();
-
- try {
- initialize();
-
- while (!sequenceMatcher.isEOF()) {
- readNext();
- }
- } catch (IOException e) {
- this.cancel();
-
- if (!this.shouldStop) {
- throw new FileUploadException("IO Error parsing multipart request", e);
- }
- } finally {
- canStop = false;
- }
- }
-
- @SuppressWarnings("unchecked")
- private void setupProgressData() {
- if (percentMap == null || requestSizeMap == null) {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if (facesContext != null) {
- ExternalContext externalContext = facesContext.getExternalContext();
- if (externalContext != null) {
- Map<String, Object> sessionMap = externalContext.getSessionMap();
- if (sessionMap != null) {
- String uploadId = getUploadId();
-
- synchronized (sessionMap) {
- if (percentMap == null) {
- percentMap = (Map<String, Object>) sessionMap.get(PERCENT_BEAN_NAME);
- if (percentMap == null) {
- percentMap = new ConcurrentHashMap<String, Object>();
- sessionMap.put(PERCENT_BEAN_NAME, percentMap);
- }
- }
-
- if (requestSizeMap == null) {
- requestSizeMap = (Map<String, Long>) sessionMap.get(REQUEST_SIZE_BEAN_NAME);
- if (requestSizeMap == null) {
- requestSizeMap = new ConcurrentHashMap<String, Long>();
- sessionMap.put(REQUEST_SIZE_BEAN_NAME, requestSizeMap);
- }
- }
- }
-
- percentMap.put(uploadId, Double.valueOf(0));
-
- requestSizeMap.put(uploadId, contentLength);
- }
- }
- }
- }
- }
-
- private void fillProgressInfo() {
- setupProgressData();
-
- if (percentMap != null) {
- Double percent = (Double) (100.0 * this.bytesRead / this.contentLength);
- percentMap.put(uid, percent);
- // this.percent = percent;
- }
- }
-
- private byte[] getBoundaryMarker(String contentType) {
- Map<String, String> 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();
- }
- }
-
- private Map<String, String> 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<String, String> 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);
- }
- if (!"filename".equals(key)) {
- paramMap.put(key, value);
- } else {
- paramMap.put(key, parseFileName(paramStr));
- }
- }
- }
- }
-
- private String parseFileName(String parseStr) {
- Matcher m = FILE_NAME_PATTERN.matcher(parseStr);
- if (m.matches()) {
- String name = m.group(1);
- if (name.startsWith("&")) {
- return decodeFileName(name);
- } else {
- return name;
- }
- }
- return null;
- }
-
- private Param getParam(String name) {
- Param param = null;
- if (parameters != null) {
- param = parameters.get(name);
- }
-
- if (param == null) {
- if (!canceled) {
- try {
- initialize();
-
- while (param == null && !sequenceMatcher.isEOF()) {
- readNext();
- param = parameters.get(name);
- }
- } catch (IOException e) {
- this.cancel();
- throw new FileUploadException("IO Error parsing multipart request", e);
- }
- }
- }
-
- return param;
- }
-
- @SuppressWarnings("rawtypes")
- @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;
- }
-
- @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) {
- parseRequest();
-
- Param p = getParam(name);
- if (p != null && p instanceof ValueParam) {
- ValueParam vp = (ValueParam) p;
- if (vp.getValue() instanceof List<?>) {
- @SuppressWarnings("unchecked")
- List<String> vals = (List<String>) 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<String, Object> getParameterMap() {
- if (parameters == null) {
- parseRequest();
- }
-
- @SuppressWarnings("unchecked")
- 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 UploadedFile getUploadedFile(String name) {
- Param param = getParam(name);
- if (param instanceof UploadedFile) {
- return (UploadedFile) param;
- } else {
- return null;
- }
- }
-
- public boolean isFormUpload() {
- return "_richfaces_form_upload".equals(uid);
- }
-
- @Override
- public String getHeader(String name) {
- if ("Accept".equals(name)) {
- return TEXT_HTML;
- } else if ("Faces-Request".equals(name)) {
- return "partial/ajax";
- } else {
- return super.getHeader(name);
- }
- }
-
- public void stop() {
- if (canStop) {
- shouldStop = true;
- }
- }
-
- public boolean isStopped() {
- return this.shouldStop;
- }
-
- public boolean isDone() {
- return !(this.contentLength != this.bytesRead && this.shouldStop && this.canceled);
- }
-
- @Override
- public String getContentType() {
- return "application/x-www-form-urlencoded";
- }
-
- public String getUploadId() {
- return uid;
- }
-
- public void clearRequestData() {
- String uploadId = getUploadId();
-
- if (percentMap != null) {
- percentMap.remove(uploadId);
- }
-
- if (requestSizeMap != null) {
- requestSizeMap.remove(uploadId);
- }
- }
-}
\ No newline at end of file
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import org.richfaces.model.UploadedFile;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface MultipartRequest {
+
+ public static final String REQUEST_ATTRIBUTE_NAME = MultipartRequest.class.getName();
+
+ public enum ResponseState {
+ ok, sizeExceeded, serverError
+ }
+
+ public Iterable<UploadedFile> getUploadedFiles();
+
+ public ResponseState getResponseState();
+
+ public void release();
+
+ public String getUploadId();
+
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest25.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest25.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest25.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,153 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.model.UploadedFile;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Sets;
+
+public class MultipartRequest25 extends BaseMultipartRequest {
+
+ private static final Logger LOGGER = RichfacesLogger.APPLICATION.getLogger();
+
+ private static final Function<Collection<String>, Object> MULTIMAP_VALUE_TRANSFORMER = new Function<Collection<String>, Object>() {
+ public Object apply(Collection<String> input) {
+ if (input.isEmpty()) {
+ return null;
+ }
+
+ if (input.size() == 1) {
+ return Iterables.get(input, 0);
+ }
+
+ return input.toArray(new String[input.size()]);
+ }
+ };
+
+ private Multimap<String, String> params;
+
+ private Iterable<UploadedFile> uploadedFiles;
+
+ private ResponseState responseState;
+
+ public MultipartRequest25(HttpServletRequest request, String uploadId, ProgressControl progressControl,
+ Multimap<String, String> params, Iterable<UploadedFile> uploadedFiles, ResponseState responseState) {
+ super(request, uploadId, progressControl);
+
+ this.params = params;
+ this.uploadedFiles = uploadedFiles;
+ this.responseState = responseState;
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public Enumeration getParameterNames() {
+ Collection<Object> result = Sets.newHashSet();
+
+ Enumeration names = super.getParameterNames();
+ while (names.hasMoreElements()) {
+ String name = (String) names.nextElement();
+
+ result.add(name);
+ }
+
+ result.addAll(params.keySet());
+
+ return Iterators.asEnumeration(result.iterator());
+ }
+
+ @Override
+ public String getParameter(String name) {
+ String parameter = super.getParameter(name);
+ if (parameter != null) {
+ return parameter;
+ }
+
+ Collection<String> values = params.get(name);
+
+ if (values.isEmpty()) {
+ return null;
+ }
+
+ return Iterables.get(values, 0);
+ }
+
+ @Override
+ public String[] getParameterValues(String name) {
+ String[] parameterValues = super.getParameterValues(name);
+ if (parameterValues != null) {
+ return parameterValues;
+ }
+
+ Collection<String> values = params.get(name);
+
+ if (values.isEmpty()) {
+ return null;
+ }
+
+ return values.toArray(new String[values.size()]);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ public Map getParameterMap() {
+ Map parameterMap = Maps.newHashMap(super.getParameterMap());
+ parameterMap.putAll(Maps.transformValues(params.asMap(), MULTIMAP_VALUE_TRANSFORMER));
+
+ return parameterMap;
+ }
+
+ public Iterable<UploadedFile> getUploadedFiles() {
+ return uploadedFiles;
+ }
+
+ public void release() {
+ super.release();
+
+ for (UploadedFile uploadedFile : uploadedFiles) {
+ try {
+ uploadedFile.delete();
+ } catch (IOException e) {
+ LOGGER.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ public ResponseState getResponseState() {
+ return responseState;
+ }
+
+}
\ No newline at end of file
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequestParser.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequestParser.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequestParser.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,394 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.text.MessageFormat;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.richfaces.exception.FileUploadException;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.model.UploadedFile;
+import org.richfaces.request.ByteSequenceMatcher.BytesHandler;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.LinkedListMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class MultipartRequestParser {
+
+ static final String PARAM_NAME = "name";
+
+ static final String PARAM_FILENAME = "filename";
+
+ static final String PARAM_CONTENT_TYPE = "Content-Type";
+
+ private static final byte CR = 0x0d;
+
+ private static final byte LF = 0x0a;
+
+ private static final byte[] CR_LF = {CR, LF};
+
+ private static final byte[] HYPHENS = {0x2d, 0x2d}; // '--'
+
+ private static final int BUFFER_SIZE = 2048;
+
+ private static final int CHUNK_SIZE = 1024;
+
+ private static final int MAX_HEADER_SIZE = 32768;
+
+ private static final Logger LOGGER = RichfacesLogger.APPLICATION.getLogger();
+
+ private static final Pattern FILE_NAME_PATTERN = Pattern.compile(".*filename=\"(.*)\"");
+
+ private static final Pattern PARAM_VALUE_PATTERN = Pattern.compile("^\\s*([^\\s=]+)\\s*[=:]\\s*(.+)\\s*$");
+
+ private static final BytesHandler NOOP_HANDLER = new BytesHandler() {
+ public void handle(byte[] bytes, int length) {
+ // do nothing
+ }
+ };
+
+ private class HeadersHandler implements BytesHandler {
+
+ private ByteArrayOutputStream baos = new ByteArrayOutputStream(BUFFER_SIZE);
+
+ public void handle(byte[] bytes, int length) throws IOException {
+ if (length != 0) {
+ if (baos.size() + length > MAX_HEADER_SIZE) {
+ throw new IOException("Header section is too big");
+ }
+
+ baos.write(bytes, 0, length);
+ }
+ }
+
+ public boolean dataEquals(byte[] bytes) {
+ return (baos.size() == bytes.length) && Arrays.equals(HYPHENS, baos.toByteArray());
+ }
+
+ public String asString() throws UnsupportedEncodingException {
+ if (request.getCharacterEncoding() != null) {
+ return baos.toString(request.getCharacterEncoding());
+ } else {
+ return baos.toString();
+ }
+ }
+
+ public void reset() {
+ baos.reset();
+ }
+
+ }
+
+ private HttpServletRequest request;
+
+ private boolean createTempFiles;
+
+ private String tempFilesDirectory;
+
+ private Multimap<String, String> parametersMap = LinkedListMultimap.create();
+
+ private List<UploadedFile> uploadedFiles = Lists.newArrayList();
+
+ private byte[] boundaryMarker;
+
+ private ByteSequenceMatcher sequenceMatcher;
+
+ private HeadersHandler headersHandler;
+
+ private ProgressControl progressControl;
+
+ /**
+ * @param request
+ * @param createTempFiles
+ * @param tempFilesDirectory
+ * @param uploadId
+ */
+ public MultipartRequestParser(HttpServletRequest request, boolean createTempFiles, String tempFilesDirectory,
+ ProgressControl progressControl) {
+
+ this.request = request;
+ this.createTempFiles = createTempFiles;
+ this.tempFilesDirectory = tempFilesDirectory;
+ this.progressControl = progressControl;
+ }
+
+ private void cancel() {
+ for (UploadedFile uploadedFile : uploadedFiles) {
+ try {
+ uploadedFile.delete();
+ } catch (IOException e) {
+ LOGGER.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ public Multimap<String, String> getParameters() {
+ return parametersMap;
+ }
+
+ public Iterable<UploadedFile> getUploadedFiles() {
+ return uploadedFiles;
+ }
+
+ public void parse() throws FileUploadException {
+ try {
+ initialize();
+
+ while (!sequenceMatcher.isEOF()) {
+ readNext();
+ }
+ } catch (IOException e) {
+ this.cancel();
+
+ throw new FileUploadException(MessageFormat.format("Exception parsing multipart request: {0}", e.getMessage()), e);
+ }
+ }
+
+ private void initialize() throws IOException, FileUploadException {
+ this.boundaryMarker = getBoundaryMarker(request.getContentType());
+ if (this.boundaryMarker == null) {
+ throw new FileUploadException("The request was rejected because no multipart boundary was found");
+ }
+
+ if (HYPHENS.length + boundaryMarker.length + CHUNK_SIZE + CR_LF.length > BUFFER_SIZE) {
+ throw new FileUploadException("Boundary marker is too long");
+ }
+
+ this.sequenceMatcher = new ByteSequenceMatcher(progressControl.wrapStream(request.getInputStream()), BUFFER_SIZE);
+
+ readProlog();
+ }
+
+ private String getFirstParameterValue(Multimap<String, String> multimap, String key) {
+ Collection<String> values = multimap.get(key);
+
+ if (values.isEmpty()) {
+ return null;
+ }
+
+ return Iterables.get(values, 0);
+ }
+
+ private byte[] getBoundaryMarker(String contentType) {
+ Multimap<String, String> params = parseParams(contentType, ";");
+ String boundaryStr = getFirstParameterValue(params, "boundary");
+
+ if (boundaryStr == null) {
+ return null;
+ }
+
+ try {
+ return boundaryStr.getBytes("ISO-8859-1");
+ } catch (UnsupportedEncodingException e) {
+ return boundaryStr.getBytes();
+ }
+ }
+
+ private Multimap<String, String> parseParams(String paramStr, String separator) {
+ Multimap<String, String> paramMap = LinkedListMultimap.create();
+ parseParams(paramStr, separator, paramMap);
+ return paramMap;
+ }
+
+ private void parseParams(String paramStr, String separator, Multimap<String, String> 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).toLowerCase(Locale.US);
+ String value = m.group(2);
+
+ // Strip double quotes
+ if (value.startsWith("\"") && value.endsWith("\"")) {
+ value = value.substring(1, value.length() - 1);
+ }
+ if (!"filename".equals(key)) {
+ paramMap.put(key, value);
+ } else {
+ paramMap.put(key, parseFileName(paramStr));
+ }
+ }
+ }
+ }
+
+ //TODO - URI decoder?
+ private String decodeFileName(String name) {
+ String fileName = null;
+ try {
+ StringBuilder builder = new StringBuilder();
+ String[] codes = name.split(";");
+ if (codes != null) {
+ for (String code : codes) {
+ if (code.startsWith("&")) {
+ String sCode = code.replaceAll("[&#]*", "");
+ Integer iCode = Integer.parseInt(sCode);
+ builder.append(Character.toChars(iCode));
+ } else {
+ builder.append(code);
+ }
+ }
+ fileName = builder.toString();
+ }
+ } catch (Exception e) {
+ fileName = name;
+ }
+
+ return fileName;
+ }
+
+ private String parseFileName(String parseStr) {
+ Matcher m = FILE_NAME_PATTERN.matcher(parseStr);
+ if (m.matches()) {
+ String name = m.group(1);
+ if (name.startsWith("&")) {
+ return decodeFileName(name);
+ } else {
+ return name;
+ }
+ }
+ return null;
+ }
+
+ private void readProlog() throws IOException {
+ sequenceMatcher.setBytesHandler(NOOP_HANDLER);
+ sequenceMatcher.findSequence(-1, HYPHENS, boundaryMarker);
+ if (!sequenceMatcher.isMatchedAndNotEOF()) {
+ throw new IOException("Request prolog cannot be read");
+ }
+ }
+
+ private void readData(FileUploadParam uploadParam) throws IOException {
+ sequenceMatcher.setBytesHandler(uploadParam);
+ sequenceMatcher.findSequence(CHUNK_SIZE, CR_LF, HYPHENS, boundaryMarker);
+ sequenceMatcher.setBytesHandler(null);
+ if (!this.sequenceMatcher.isMatchedAndNotEOF()) {
+ throw new IOException("Request data cannot be read");
+ }
+ }
+
+ private void readNext() throws IOException {
+ Multimap<String, String> headers = readHeaders();
+ FileUploadParam param = createParam(headers);
+
+ if (param == null) {
+ return;
+ }
+
+ param.create();
+
+ try {
+ readData(param);
+ } finally {
+ param.complete();
+ }
+
+ if (param.isFileParam()) {
+ uploadedFiles.add(new UploadedFile25(param.getName(), param.getResource(), headers));
+ } else {
+ parametersMap.put(param.getName(), param.getValue());
+ }
+ }
+
+ private FileUploadParam createParam(Multimap<String, String> headers) {
+ if (headers == null) {
+ return null;
+ }
+
+ String parameterName = getFirstParameterValue(headers, PARAM_NAME);
+
+ if (Strings.isNullOrEmpty(parameterName)) {
+ return null;
+ }
+
+ boolean isFile = !Strings.isNullOrEmpty(getFirstParameterValue(headers, PARAM_FILENAME));
+
+ FileUploadParam param;
+
+ if (isFile) {
+ if (createTempFiles) {
+ param = new FileUploadDiscResource(parameterName, tempFilesDirectory);
+ } else {
+ param = new FileUploadMemoryResource(parameterName, tempFilesDirectory);
+ }
+ } else {
+ param = new FileUploadValueParam(parameterName, request.getCharacterEncoding());
+ }
+
+ return param;
+ }
+
+ private Multimap<String, String> readHeaders() throws IOException {
+ if (sequenceMatcher.isEOF()) {
+ return null;
+ }
+
+ if (headersHandler == null) {
+ headersHandler = new HeadersHandler();
+ } else {
+ headersHandler.reset();
+ }
+
+ sequenceMatcher.setBytesHandler(headersHandler);
+ sequenceMatcher.findSequence(-1, CR_LF);
+
+ if (sequenceMatcher.isMatchedAndNotEOF() && !headersHandler.dataEquals(HYPHENS)) {
+ headersHandler.reset();
+
+ sequenceMatcher.findSequence(-1, CR_LF, CR_LF);
+
+ if (!sequenceMatcher.isMatchedAndNotEOF()) {
+ throw new IOException("Request header cannot be read");
+ }
+
+ String headersString = headersHandler.asString();
+ Multimap<String, String> headers = LinkedListMultimap.create();
+ String[] split = headersString.split("\r\n");
+ for (String headerString : split) {
+ parseParams(headerString, "; ", headers);
+ }
+
+ return headers;
+ }
+
+ return null;
+ }
+
+}
Deleted: trunk/ui/input/ui/src/main/java/org/richfaces/request/Param.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/Param.java 2011-04-21 12:16:50 UTC (rev 22435)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/Param.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -1,34 +0,0 @@
-/*
- * 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.request;
-
-import java.io.IOException;
-
-import org.richfaces.request.ByteSequenceMatcher.BytesHandler;
-
-/**
- * @author Konstantin Mishin
- *
- */
-interface Param extends BytesHandler {
- void complete() throws IOException;
-}
\ No newline at end of file
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletInputStream;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class ProgressControl {
+
+ private static final String UPLOAD_PROGRESS_PREFIX = "_richfaces_upload_percents";
+
+ private Map<String, Object> contextMap;
+
+ private String attributeName;
+
+ private long totalBytesRead = 0;
+
+ private long length;
+
+ private byte lastUpdatedPercentValue;
+
+ public ProgressControl(Map<String, Object> contextMap, String uploadId, long length) {
+ this.contextMap = contextMap;
+ this.attributeName = getContextAttributeName(uploadId);
+ this.length = length;
+ }
+
+ public static byte getProgress(FacesContext context, String uploadId) {
+ Byte progress = (Byte) context.getExternalContext().getSessionMap().get(getContextAttributeName(uploadId));
+
+ if (progress != null) {
+ return progress.byteValue();
+ }
+
+ return 0;
+ }
+
+ private static String getContextAttributeName(String uploadId) {
+ return UPLOAD_PROGRESS_PREFIX + uploadId;
+ }
+
+ void clearProgress() {
+ contextMap.remove(attributeName);
+ }
+
+ public void advance(long bytesRead) {
+ totalBytesRead += bytesRead;
+
+ byte percent;
+ if (length != 0) {
+ percent = (byte) Math.floor( ((double)totalBytesRead) / length * 100);
+ } else {
+ percent = 100;
+ }
+
+ if (percent > lastUpdatedPercentValue) {
+ lastUpdatedPercentValue = percent;
+ contextMap.put(attributeName, lastUpdatedPercentValue);
+ }
+ }
+
+ public ServletInputStream wrapStream(ServletInputStream inputStream) {
+ return new ProgressServletInputStream(inputStream, this);
+ }
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressServletInputStream.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressServletInputStream.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressServletInputStream.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.io.IOException;
+
+import javax.servlet.ServletInputStream;
+
+
+class ProgressServletInputStream extends ServletInputStream {
+
+ private ServletInputStream wrappedStream;
+
+ private ProgressControl progressControl;
+
+ protected ProgressServletInputStream(ServletInputStream wrappedStream, ProgressControl progressControl) {
+ this.wrappedStream = wrappedStream;
+ this.progressControl = progressControl;
+ }
+
+ @Override
+ public int read() throws IOException {
+ int read = wrappedStream.read();
+ if (read >= 0) {
+ progressControl.advance(1);
+ }
+ return read;
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ int read = wrappedStream.read(b);
+ if (read > 0) {
+ progressControl.advance(read);
+ }
+ return read;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ int read = wrappedStream.read(b, off, len);
+ if (read > 0) {
+ progressControl.advance(read);
+ }
+ return read;
+ }
+
+ @Override
+ public int readLine(byte[] b, int off, int len) throws IOException {
+ int read = wrappedStream.readLine(b, off, len);
+ if (read > 0) {
+ progressControl.advance(read);
+ }
+ return read;
+ }
+
+}
\ No newline at end of file
Added: trunk/ui/input/ui/src/main/java/org/richfaces/request/UploadedFile25.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/UploadedFile25.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/UploadedFile25.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.request;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Locale;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Multimap;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class UploadedFile25 extends BaseUploadedFile {
+
+ private FileUploadResource uploadResource;
+
+ private Multimap<String, String> headersMap;
+
+ public UploadedFile25(String parameterName, FileUploadResource uploadResource,
+ Multimap<String, String> headersMap) {
+ super(parameterName);
+
+ this.uploadResource = uploadResource;
+ this.headersMap = headersMap;
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return uploadResource.getInputStream();
+ }
+
+ public void delete() throws IOException {
+ uploadResource.delete();
+ }
+
+ public void write(String fileName) throws IOException {
+ uploadResource.write(fileName);
+ }
+
+ public String getHeader(String headerName) {
+ String lcHeaderName = headerName.toLowerCase(Locale.US);
+ Collection<String> headers = headersMap.get(lcHeaderName);
+
+ if (headers.isEmpty()) {
+ return null;
+ }
+
+ return Iterables.get(headers, 0);
+ }
+
+ public Collection<String> getHeaderNames() {
+ return new HashSet<String>(headersMap.keySet());
+ }
+
+ public Collection<String> getHeaders(String headerName) {
+ String lcHeaderName = headerName.toLowerCase(Locale.US);
+ Collection<String> headers = headersMap.get(lcHeaderName);
+
+ return new ArrayList<String>(headers);
+ }
+
+ public long getSize() {
+ return uploadResource.getSize();
+ }
+
+}
Deleted: trunk/ui/input/ui/src/main/java/org/richfaces/request/ValueParam.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/ValueParam.java 2011-04-21 12:16:50 UTC (rev 22435)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/ValueParam.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -1,64 +0,0 @@
-/*
- * 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.request;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-class ValueParam implements Param {
-
- private Object value = null;
- private ByteArrayOutputStream buf = new ByteArrayOutputStream();
- private String encoding;
-
- public ValueParam(String encoding) {
- this.encoding = encoding;
- }
-
- @SuppressWarnings("unchecked")
- public void complete() throws IOException {
- String val = this.encoding == null ? new String(buf.toByteArray()) : new String(buf.toByteArray(),
- this.encoding);
- if (value == null) {
- value = val;
- } else {
- if (!(value instanceof List<?>)) {
- List<String> v = new ArrayList<String>();
- v.add((String) value);
- value = v;
- }
-
- ((List<String>) value).add(val);
- }
- buf.reset();
- }
-
- public Object getValue() {
- return value;
- }
-
- public void handle(byte[] bytes, int length) throws IOException {
- buf.write(bytes, 0, length);
- }
-}
\ No newline at end of file
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/resource/FileUploadProgressResource.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/resource/FileUploadProgressResource.java 2011-04-21 12:16:50 UTC (rev 22435)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/resource/FileUploadProgressResource.java 2011-04-21 12:19:14 UTC (rev 22436)
@@ -21,12 +21,9 @@
*/
package org.richfaces.resource;
-import java.util.Map;
-
import javax.faces.context.FacesContext;
-import org.richfaces.context.FileUploadPartialViewContextFactory;
-import org.richfaces.request.MultipartRequest;
+import org.richfaces.request.ProgressControl;
/**
* @author Nick Belaevski
@@ -34,19 +31,12 @@
*/
public class FileUploadProgressResource extends AbstractJSONResource {
+ private static final Object UID_ALT_KEY = "rf_fu_uid_alt";
+
@Override
protected Object getData(FacesContext context) {
- Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
- Map<String, Number> percentMap = (Map<String, Number>) sessionMap.get(MultipartRequest.PERCENT_BEAN_NAME);
-
- Number result = null;
-
- if (percentMap != null) {
- String uploadId = context.getExternalContext().getRequestParameterMap().get(FileUploadPartialViewContextFactory.UID_ALT_KEY);
- result = (Number) percentMap.get(uploadId);
- }
-
- return result != null ? result : 0;
+ String uploadId = context.getExternalContext().getRequestParameterMap().get(UID_ALT_KEY);
+ return ProgressControl.getProgress(context, uploadId);
}
}
Modified: trunk/ui/input/ui/src/main/resources/META-INF/fileupload.faces-config.xml
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/fileupload.faces-config.xml 2011-04-21 12:16:50 UTC (rev 22435)
+++ trunk/ui/input/ui/src/main/resources/META-INF/fileupload.faces-config.xml 2011-04-21 12:19:14 UTC (rev 22436)
@@ -28,6 +28,7 @@
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">
<factory>
- <partial-view-context-factory>org.richfaces.context.FileUploadPartialViewContextFactory</partial-view-context-factory>
+ <faces-context-factory>org.richfaces.context.FileUploadFacesContextFactory</faces-context-factory>
+ <external-context-factory>org.richfaces.context.FileUploadExternalContextFactory</external-context-factory>
</factory>
</faces-config>
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js 2011-04-21 12:16:50 UTC (rev 22435)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js 2011-04-21 12:19:14 UTC (rev 22436)
@@ -191,7 +191,15 @@
responseStatus = id.split(":")[1];
}
if (responseStatus) {
- responseStatus == ITEM_STATE.DONE && jsf.ajax.response({responseXML: contentDocument}, {});
+ var responseContext = {
+ source: this.element[0],
+ /* hack for MyFaces */
+ _mfInternal: {
+ _mfSourceControlId: this.element.attr('id')
+ }
+ };
+
+ responseStatus == ITEM_STATE.DONE && jsf.ajax.response({responseXML: contentDocument}, responseContext);
this.loadableItem.finishUploading(responseStatus);
this.submitedItems.push(this.loadableItem);
if (responseStatus == ITEM_STATE.DONE && this.items.length) {
13 years, 8 months
JBoss Rich Faces SVN: r22435 - in trunk/core: api/src/main/java/org/ajax4jsf/io and 8 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2011-04-21 08:16:50 -0400 (Thu, 21 Apr 2011)
New Revision: 22435
Added:
trunk/core/api/src/main/java/org/ajax4jsf/io/
trunk/core/api/src/main/java/org/ajax4jsf/io/ByteBuffer.java
trunk/core/api/src/main/java/org/ajax4jsf/io/CharBuffer.java
trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java
trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java
trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferReader.java
trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferWriter.java
trunk/core/api/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java
trunk/core/api/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java
trunk/core/api/src/main/java/org/ajax4jsf/io/package-info.java
trunk/core/api/src/test/java/org/ajax4jsf/io/
trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java
trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java
trunk/core/api/src/test/java/org/ajax4jsf/io/Test.java
Removed:
trunk/core/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferReader.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/package-info.java
trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java
trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java
trunk/core/impl/src/test/java/org/ajax4jsf/io/Test.java
Modified:
trunk/core/api/src/test/java/org/richfaces/log/JavaLoggerTest.java
trunk/core/api/src/test/java/org/richfaces/util/LRUMapTest.java
trunk/core/impl/src/test/java/org/richfaces/cache/JBossCacheTest.java
trunk/core/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java
Log:
RF-10128
Checkstyle fixes
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/ByteBuffer.java (from rev 22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/ByteBuffer.java (rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/ByteBuffer.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,276 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.io;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * A single link in chain of byte arrays.
+ *
+ * @author glory
+ */
+public class ByteBuffer {
+ private static final int MAX_WASTE = 16384;
+
+ /**
+ * Stored bytes
+ */
+ private byte[] bytes;
+
+ /**
+ * Length of byte array.
+ */
+ private int cacheSize;
+ private ByteBuffer next;
+ private ByteBuffer prev;
+
+ /**
+ * Number of bytes stored in the array.
+ */
+ private int usedSize;
+
+ /**
+ * Creates instance of ByteBuffer already filled by bytes.
+ *
+ * @param bytes
+ */
+ public ByteBuffer(byte[] bytes) {
+ this.bytes = bytes;
+ usedSize = bytes.length;
+ cacheSize = usedSize;
+ }
+
+ /**
+ * Creates instance of ByteBuffer with byte array of required length.
+ *
+ * @param cacheSize length of byte array
+ */
+ public ByteBuffer(int cacheSize) {
+ bytes = new byte[cacheSize];
+ this.cacheSize = cacheSize;
+ usedSize = 0;
+ }
+
+ /**
+ * Appends byte to array if there are unfilled positions in it.
+ * Otherwize creates next link in the chain, and appends the byte to it.
+ *
+ * @param c
+ * @return instance of ByteBuffer to which byte was appended.
+ */
+ public ByteBuffer append(byte c) {
+ if (next != null) {
+ return next.append(c);
+ }
+
+ if (usedSize < cacheSize) {
+ bytes[usedSize] = c;
+ usedSize++;
+
+ return this;
+ } else {
+ next = new ByteBuffer(cacheSize * 2);
+ next.prev = this;
+
+ return next.append(c);
+ }
+ }
+
+ /**
+ * Appends segment of a byte array to array if there are unfilled positions in it.
+ * Otherwize creates next link in the chain, and appends data to it.
+ *
+ * @param c
+ * @return instance of ByteBuffer to which byte array was appended.
+ */
+ public ByteBuffer append(byte[] bs, int off, int len) {
+ if (next != null) {
+ return next.append(bs, off, len);
+ }
+
+ if (len + usedSize <= cacheSize) {
+ System.arraycopy(bs, off, bytes, usedSize, len);
+ usedSize += len;
+
+ return this;
+ }
+
+ int av = cacheSize - usedSize;
+
+ if (av > 0) {
+ System.arraycopy(bs, off, bytes, usedSize, av);
+ usedSize += av;
+ off += av;
+ len -= av;
+ }
+
+ next = new ByteBuffer(cacheSize * 2);
+ next.prev = this;
+
+ return next.append(bs, off, len);
+ }
+
+ /**
+ * Returns stored byte array.
+ *
+ * @return stored byte array
+ */
+ public byte[] getBytes() {
+ return bytes;
+ }
+
+ /**
+ * Returns byte at index. No check is fulfilled to provide high speed.
+ *
+ * @param index
+ * @return
+ */
+ public byte getByteAt(int index) {
+ return bytes[index];
+ }
+
+ /**
+ * Returns actual number of byte stored in this link.
+ *
+ * @return
+ */
+ public int getUsedSize() {
+ return usedSize;
+ }
+
+ /**
+ * Returns capacity of this link.
+ *
+ * @return
+ */
+ public int getCacheSize() {
+ return cacheSize;
+ }
+
+ /**
+ * Returns total number of bytes stored in this link and all its predecessors.
+ *
+ * @return
+ */
+ public int getTotalSize() {
+ return (prev == null) ? usedSize : prev.getTotalSize() + usedSize;
+ }
+
+ /**
+ * Returns the previous link in the chain.
+ *
+ * @return
+ */
+ public ByteBuffer getPrevious() {
+ return prev;
+ }
+
+ /**
+ * Returns the next link in the chain.
+ *
+ * @return
+ */
+ public ByteBuffer getNext() {
+ return next;
+ }
+
+ /**
+ * Sets the next link in the chain.
+ *
+ * @param b
+ */
+ public void setNext(ByteBuffer b) {
+ next = b;
+
+ if (b != null) {
+ b.prev = this;
+ }
+ }
+
+ /**
+ * Transforms this instance to instance of CharBuffer (a link of chain of char arrays).
+ *
+ * @param encoding
+ * @return link of chain of char arrays
+ * @throws UnsupportedEncodingException
+ */
+ public CharBuffer toCharBuffer(String encoding) throws UnsupportedEncodingException {
+ String s;
+
+ if (null != encoding) {
+ s = new String(bytes, 0, usedSize, encoding);
+ } else {
+ s = new String(bytes, 0, usedSize);
+ }
+
+ return new CharBuffer(s.toCharArray());
+ }
+
+ /**
+ * Transforms this instance to instance of CharBuffer (a link of chain of char arrays).
+ *
+ * @return link of chain of char arrays
+ */
+ public CharBuffer toCharBuffer() {
+ String s = new String(bytes, 0, usedSize);
+
+ return new CharBuffer(s.toCharArray());
+ }
+
+ /**
+ * Resets this byte buffer to empty state
+ *
+ * @since 3.3.0
+ */
+ public void reset() {
+ usedSize = 0;
+ next = null;
+ prev = null;
+ }
+
+ /**
+ * @since 4.0
+ */
+ public void compact() {
+ if (bytes.length - usedSize > MAX_WASTE) {
+ byte[] bs = new byte[usedSize];
+
+ System.arraycopy(bytes, 0, bs, 0, usedSize);
+ this.bytes = bs;
+ this.cacheSize = bs.length;
+ }
+
+ if (next != null) {
+ next.compact();
+ }
+ }
+
+ public ByteBuffer getLast() {
+ ByteBuffer result = this;
+
+ while (result.next != null) {
+ result = result.next;
+ }
+
+ return result;
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/CharBuffer.java (from rev 22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/CharBuffer.java (rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/CharBuffer.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,266 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.io;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * A single link in chain of char arrays.
+ *
+ * @author glory
+ */
+public class CharBuffer {
+ private static final int MAX_WASTE = 16384;
+ private static final int MIN_CACHE_SIZE = 64;
+
+ /**
+ * Length of char array.
+ */
+ private int cacheSize;
+
+ /**
+ * Stored characters
+ */
+ private char[] chars;
+ private CharBuffer next;
+ private CharBuffer prev;
+
+ /**
+ * number of characters stored in the array.
+ */
+ private int usedSize;
+
+ /**
+ * Creates instance of CharBuffer already filled by chars.
+ *
+ * @param bytes
+ */
+ public CharBuffer(char[] chars) {
+ this.chars = chars;
+ usedSize = chars.length;
+ cacheSize = usedSize;
+ }
+
+ /**
+ * Creates instance of CharBuffer with char array of required length.
+ *
+ * @param cacheSize length of char array
+ */
+ public CharBuffer(int cacheSize) {
+ if (cacheSize < MIN_CACHE_SIZE) {
+ this.cacheSize = MIN_CACHE_SIZE;
+ } else {
+ this.cacheSize = cacheSize;
+ }
+
+ chars = new char[this.cacheSize];
+ usedSize = 0;
+ }
+
+ /**
+ * Appends character to array chars if there are unfilled positions in it.
+ * Otherwise creates next link in the chain, and appends the character to it.
+ *
+ * @param c
+ * @return instance of CharBuffer to which character was appended.
+ */
+ public CharBuffer append(char c) {
+ if (next != null) {
+ return next.append(c);
+ }
+
+ if (usedSize < cacheSize) {
+ chars[usedSize] = c;
+ usedSize++;
+
+ return this;
+ } else {
+ next = new CharBuffer(cacheSize * 2);
+ next.prev = this;
+
+ return next.append(c);
+ }
+ }
+
+ /**
+ * Appends segment of a char array to array if there are unfilled positions in it.
+ * Otherwise creates next link in the chain, and appends data to it.
+ *
+ * @param c
+ * @return instance of CharBuffer to which char array was appended.
+ */
+ public CharBuffer append(char[] cs, int off, int len) {
+ if (next != null) {
+ return next.append(cs, off, len);
+ }
+
+ if (len + usedSize <= cacheSize) {
+ System.arraycopy(cs, off, chars, usedSize, len);
+ usedSize += len;
+
+ return this;
+ }
+
+ int av = cacheSize - usedSize;
+
+ if (av > 0) {
+ System.arraycopy(cs, off, chars, usedSize, av);
+ usedSize += av;
+ off += av;
+ len -= av;
+ }
+
+ next = new CharBuffer(cacheSize * 2);
+ next.prev = this;
+
+ return next.append(cs, off, len);
+ }
+
+ /**
+ * Returns stored char array.
+ *
+ * @return stored char array
+ */
+ public char[] getChars() {
+ return chars;
+ }
+
+ /**
+ * Returns character at index. No check is fulfilled to provide high speed.
+ *
+ * @param index
+ * @return
+ */
+ public char getCharAt(int index) {
+ return chars[index];
+ }
+
+ /**
+ * Returns actual number of characters stored in this link.
+ *
+ * @return
+ */
+ public int getUsedSize() {
+ return usedSize;
+ }
+
+ /**
+ * Returns capacity of this link.
+ *
+ * @return
+ */
+ public int getCacheSize() {
+ return cacheSize;
+ }
+
+ /**
+ * Returns total number of characters stored in this link and all its predecessors.
+ *
+ * @return
+ */
+ public int getTotalSize() {
+ return (prev == null) ? usedSize : prev.getTotalSize() + usedSize;
+ }
+
+ /**
+ * Returns the previous link in the chain.
+ *
+ * @return
+ */
+ public CharBuffer getPrevious() {
+ return prev;
+ }
+
+ /**
+ * Returns the next link in the chain.
+ *
+ * @return
+ */
+ public CharBuffer getNext() {
+ return next;
+ }
+
+ /**
+ * Sets the next link in the chain.
+ *
+ * @param b
+ */
+ public void setNext(CharBuffer b) {
+ next = b;
+
+ if (b != null) {
+ b.prev = this;
+ }
+ }
+
+ /**
+ * Transforms this instance to instance of ByteBuffer (a link of chain of byte arrays).
+ *
+ * @param encoding
+ * @return link of chain of byte arrays
+ * @throws UnsupportedEncodingException
+ */
+ public ByteBuffer toByteBuffer(String encoding) throws UnsupportedEncodingException {
+ byte[] bs = new String(chars, 0, usedSize).getBytes(encoding);
+
+ return new ByteBuffer(bs);
+ }
+
+ /**
+ * Transforms this instance to instance of ByteBuffer (a link of chain of byte arrays).
+ *
+ * @return link of chain of byte arrays
+ */
+ public ByteBuffer toByteBuffer() {
+ byte[] bs = new String(chars, 0, usedSize).getBytes();
+
+ return new ByteBuffer(bs);
+ }
+
+ /**
+ * Resets this char buffer to empty state
+ *
+ * @since 3.3.0
+ */
+ public void reset() {
+ usedSize = 0;
+ next = null;
+ prev = null;
+ }
+
+ /**
+ * @since 4.0
+ */
+ public void compact() {
+ if (chars.length - usedSize > MAX_WASTE) {
+ char[] cs = new char[usedSize];
+
+ System.arraycopy(chars, 0, cs, 0, usedSize);
+ this.chars = cs;
+ this.cacheSize = cs.length;
+ }
+
+ if (next != null) {
+ next.compact();
+ }
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java (from rev 22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java (rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,260 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Class for reading from a byte array chain.
+ *
+ * @author glory
+ */
+public class FastBufferInputStream extends InputStream {
+
+ /**
+ * Currently read link.
+ */
+ ByteBuffer current;
+
+ /**
+ * The first link in the chain of char arrays.
+ */
+ ByteBuffer firstLink;
+
+ /**
+ * Position of next byte in current link.
+ */
+ int index;
+ int mark;
+
+ public FastBufferInputStream(ByteBuffer byteBuffer) {
+ this.firstLink = byteBuffer;
+ current = byteBuffer;
+ index = 0;
+ mark = 0;
+ }
+
+ /**
+ * Creates instance of FastBufferInputStream.
+ *
+ * @param stream
+ */
+ @Deprecated
+ public FastBufferInputStream(FastBufferOutputStream stream) {
+ this(stream.getFirstBuffer());
+ }
+
+ /**
+ * @see java.io.InputStream.read()
+ */
+ public int read() throws IOException {
+ if (current == null) {
+ return -1;
+ }
+
+ if (current.getUsedSize() <= index) {
+ current = current.getNext();
+
+ if (current == null) {
+ return -1;
+ }
+
+ index = 0;
+ }
+
+ byte c = current.getByteAt(index);
+
+ index++;
+
+ return c;
+ }
+
+ /**
+ * @see java.io.InputStream.read(byte b[])
+ */
+ @Override
+ public int read(byte[] b) throws IOException {
+ if (b == null) {
+ throw new NullPointerException();
+ }
+
+ if (current == null) {
+ return -1;
+ }
+
+ int off = 0;
+ int len = b.length;
+ int actuallyRead = 0;
+
+ while ((current != null) && (len > 0)) {
+ int av = current.getUsedSize() - index;
+
+ if (av <= 0) {
+ current = current.getNext();
+ index = 0;
+
+ continue;
+ }
+
+ if (av > len) {
+ av = len;
+ }
+
+ System.arraycopy(current.getBytes(), index, b, off, av);
+ index += av;
+ off += av;
+ actuallyRead += av;
+ len -= av;
+ }
+
+ return (actuallyRead == 0) ? -1 : actuallyRead;
+ }
+
+ /**
+ * @see java.io.InputStream.read(byte b[], int off, int len)
+ */
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ if (b == null) {
+ throw new NullPointerException();
+ } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return 0;
+ }
+
+ if (current == null) {
+ return -1;
+ }
+
+ int actuallyRead = 0;
+
+ while ((current != null) && (len > 0)) {
+ int av = current.getUsedSize() - index;
+
+ if (av <= 0) {
+ current = current.getNext();
+ index = 0;
+
+ continue;
+ }
+
+ if (av > len) {
+ av = len;
+ }
+
+ System.arraycopy(current.getBytes(), index, b, off, av);
+ index += av;
+ off += av;
+ actuallyRead += av;
+ len -= av;
+ }
+
+ return (actuallyRead == 0) ? -1 : actuallyRead;
+ }
+
+ /**
+ * @see java.io.InputStream.available()
+ */
+ public int available() throws IOException {
+ if (current == null) {
+ return 0;
+ }
+
+ ByteBuffer b = current;
+ int result = -index;
+
+ while (b != null) {
+ result += b.getUsedSize();
+ b = b.getNext();
+ }
+
+ return result;
+ }
+
+ /**
+ * @see java.io.InputStream.mark()
+ */
+ public void mark(int readAheadLimit) {
+ if (current == null) {
+ mark = 0;
+ } else {
+ mark = index;
+
+ ByteBuffer b = current.getPrevious();
+
+ if (b != null) {
+ mark += b.getTotalSize();
+ }
+ }
+ }
+
+ /**
+ * @see java.io.InputStream.reset()
+ */
+ public void reset() {
+ if (current == null) {
+ current = firstLink;
+ }
+
+ int m = 0;
+
+ while ((current != null) && (current.getUsedSize() + m <= mark)) {
+ m += current.getUsedSize();
+ current = current.getNext();
+ }
+
+ if (current != null) {
+ index = mark - m;
+ }
+ }
+
+ /**
+ * @see java.io.InputStream.skip()
+ */
+ public long skip(long n) throws IOException {
+ long skipped = 0;
+
+ while (n > 0) {
+ if (current == null) {
+ return 0;
+ }
+
+ if (current.getUsedSize() - index <= n) {
+ index += n;
+ skipped += n;
+
+ break;
+ } else {
+ int dn = current.getUsedSize() - index;
+
+ skipped += dn;
+ n -= dn;
+ current = current.getNext();
+ index = 0;
+ }
+ }
+
+ return skipped;
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java (from rev 22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java (rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,256 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+
+/**
+ * Class for writing to chain of byte arrays extending OutputStream.
+ *
+ * @author glory
+ */
+public class FastBufferOutputStream extends OutputStream {
+
+ /**
+ * The beginning of the chain of byte arrays.
+ */
+ ByteBuffer firstBuffer;
+
+ /**
+ * Currently filled link of the chain of byte arrays.
+ */
+ ByteBuffer lastBuffer;
+
+ /**
+ * Total number of written bytes.
+ */
+ int length;
+
+ /**
+ * Creates instance of default initial capacity.
+ */
+ public FastBufferOutputStream() {
+ this(256);
+ }
+
+ /**
+ * Creates instance for an already existing chain of byte arrays.
+ *
+ * @param firstBuffer
+ */
+ public FastBufferOutputStream(ByteBuffer firstBuffer) {
+ this.firstBuffer = firstBuffer;
+ this.lastBuffer = firstBuffer;
+ }
+
+ /**
+ * Creates instance with required initial capacity.
+ *
+ * @param initialSize
+ */
+ public FastBufferOutputStream(int initialSize) {
+ this(new ByteBuffer(initialSize));
+ }
+
+ /**
+ * @see java.io.OutputStream.write(int c)
+ */
+ public void write(int c) throws IOException {
+ lastBuffer = lastBuffer.append((byte) c);
+ length++;
+ }
+
+ /**
+ * @see java.io.OutputStream.write(byte b[])
+ */
+ public void write(byte[] b) throws IOException {
+ if (b == null) {
+ throw new NullPointerException();
+ }
+
+ int limit = b.length;
+
+ length += limit;
+ lastBuffer = lastBuffer.append(b, 0, limit);
+ }
+
+ /**
+ * @see java.io.OutputStream.write(byte[] b, int off, int len)
+ */
+ public void write(byte[] b, int off, int len) throws IOException {
+ if (b == null) {
+ throw new NullPointerException();
+ } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return;
+ }
+
+ lastBuffer = lastBuffer.append(b, off, len);
+ length += len;
+ }
+
+ /**
+ * Returns the total number of written bytes.
+ *
+ * @return
+ */
+ public int getLength() {
+ return length;
+ }
+
+ /**
+ * Returns the first link of the chain of byte arrays.
+ *
+ * @return
+ */
+ public ByteBuffer getFirstBuffer() {
+ return firstBuffer;
+ }
+
+ public byte[] toByteArray() {
+ ByteBuffer b = getFirstBuffer();
+
+ if (b == null) {
+ return new byte[0];
+ }
+
+ ByteBuffer l = b;
+
+ while (l.getNext() != null) {
+ l = l.getNext();
+ }
+
+ byte[] result = new byte[l.getTotalSize()];
+ int index = 0;
+
+ while (b != null) {
+ int s = b.getUsedSize();
+
+ System.arraycopy(b.getBytes(), 0, result, index, s);
+ index += s;
+ b = b.getNext();
+ }
+
+ return result;
+ }
+
+ /**
+ * Writes all data written up to the moment to out.
+ *
+ * @param out
+ * @throws IOException
+ */
+ public void writeTo(OutputStream out) throws IOException {
+ ByteBuffer b = getFirstBuffer();
+
+ while (b != null) {
+ out.write(b.getBytes(), 0, b.getUsedSize());
+ b = b.getNext();
+ }
+ }
+
+ /**
+ * Writes all data written up to the moment to out.
+ *
+ * @param out
+ * @throws IOException
+ */
+ public void writeTo(Writer out, String encoding) throws IOException {
+ ByteBuffer b = getFirstBuffer();
+
+ while (b != null) {
+ CharBuffer c = b.toCharBuffer(encoding);
+
+ out.write(c.getChars(), 0, c.getUsedSize());
+ b = b.getNext();
+ }
+ }
+
+ /**
+ * Returns instance of FastBufferWriter containing all data written to this output stream.
+ *
+ * @param encoding
+ * @return
+ * @throws UnsupportedEncodingException
+ */
+ public FastBufferWriter convertToWriter(String encoding) throws UnsupportedEncodingException {
+ ByteBuffer c = firstBuffer;
+ CharBuffer first = c.toCharBuffer(encoding);
+ CharBuffer b = first;
+
+ while (c != null) {
+ c = c.getNext();
+
+ if (c == null) {
+ break;
+ }
+
+ CharBuffer n = c.toCharBuffer(encoding);
+
+ b.setNext(n);
+ b = n;
+ }
+
+ return new FastBufferWriter(first);
+ }
+
+ /**
+ * Returns instance of FastBufferWriter containing all data written to this output stream.
+ *
+ * @return
+ */
+ public FastBufferWriter convertToWriter() {
+ ByteBuffer c = firstBuffer;
+ CharBuffer first = c.toCharBuffer();
+ CharBuffer b = first;
+
+ while (c != null) {
+ c = c.getNext();
+
+ if (c == null) {
+ break;
+ }
+
+ CharBuffer n = c.toCharBuffer();
+
+ b.setNext(n);
+ b = n;
+ }
+
+ return new FastBufferWriter(first);
+ }
+
+ /**
+ * Resets stream to empty state
+ *
+ * @since 3.3.0
+ */
+ public void reset() {
+ this.firstBuffer.reset();
+ this.lastBuffer = this.firstBuffer;
+ this.length = 0;
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferReader.java (from rev 22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferReader.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferReader.java (rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferReader.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,181 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.io;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * Class for reading from a char array chain.
+ *
+ * @author glory
+ */
+public class FastBufferReader extends Reader {
+
+ /**
+ * Currently read link.
+ */
+ CharBuffer current;
+
+ /**
+ * The first link in the chain of char arrays.
+ */
+ CharBuffer firstLink;
+
+ /**
+ * Position of next char in current link.
+ */
+ int index;
+
+ public FastBufferReader(CharBuffer buffer) {
+ firstLink = buffer;
+ current = firstLink;
+ index = 0;
+ }
+
+ /**
+ * Creates instance for given writer.
+ *
+ * @param writer
+ */
+ @Deprecated
+ public FastBufferReader(FastBufferWriter writer) {
+ firstLink = writer.getFirstBuffer();
+ current = firstLink;
+ index = 0;
+ }
+
+ public void close() throws IOException {
+ }
+
+ /**
+ * @see java.io.Reader.read()
+ */
+ public int read() throws IOException {
+ if (current == null) {
+ return -1;
+ }
+
+ if (current.getUsedSize() <= index) {
+ current = current.getNext();
+
+ if (current == null) {
+ return -1;
+ }
+
+ index = 0;
+ }
+
+ char c = current.getCharAt(index);
+
+ index++;
+
+ return c;
+ }
+
+ /**
+ * @see java.io.Reader.read(char[] cbuf, int off, int len)
+ */
+ public int read(char[] cbuf, int off, int len) throws IOException {
+ if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return 0;
+ }
+
+ if (current == null) {
+ return -1;
+ }
+
+ int actuallyRead = 0;
+
+ while ((current != null) && (len > 0)) {
+ int av = current.getUsedSize() - index;
+
+ if (av <= 0) {
+ current = current.getNext();
+ index = 0;
+
+ continue;
+ }
+
+ if (av > len) {
+ av = len;
+ }
+
+ System.arraycopy(current.getChars(), index, cbuf, off, av);
+ index += av;
+ off += av;
+ actuallyRead += av;
+ len -= av;
+ }
+
+ return (actuallyRead == 0) ? -1 : actuallyRead;
+ }
+
+ /**
+ * Returns the number of chars that may be read from this storage.
+ *
+ * @return
+ * @throws IOException
+ */
+ public int available() throws IOException {
+ if (current == null) {
+ return 0;
+ }
+
+ CharBuffer b = current;
+ int result = -index;
+
+ while (b != null) {
+ result += b.getUsedSize();
+ b = b.getNext();
+ }
+
+ return result;
+ }
+
+ /**
+ * Writes rest of data written up to the moment to out.
+ *
+ * @param out
+ * @throws IOException
+ */
+ public void writeTo(Writer writer) throws IOException {
+ if (current == null) {
+ return;
+ }
+
+ if (current.getUsedSize() > index) {
+ writer.write(current.getChars(), index, current.getUsedSize() - index);
+ current = current.getNext();
+ }
+
+ while (current != null) {
+ writer.write(current.getChars(), 0, current.getUsedSize());
+ current = current.getNext();
+ }
+
+ index = 0;
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferWriter.java (from rev 22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferWriter.java (rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferWriter.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,262 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.io;
+
+import javax.servlet.ServletOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+
+/**
+ * Class for writing to chain of char arrays extending Writer.
+ *
+ * @author glory
+ */
+public class FastBufferWriter extends Writer {
+
+ /**
+ * The beginning of the chain of char arrays.
+ */
+ CharBuffer firstBuffer;
+
+ /**
+ * Currently filled link of the chain of char arrays.
+ */
+ CharBuffer lastBuffer;
+
+ /**
+ * Total number of written chars.
+ */
+ int length;
+
+ /**
+ * Creates instance of default initial capacity.
+ */
+ public FastBufferWriter() {
+ this(256);
+ }
+
+ /**
+ * Creates instance for an already existing chain of char arrays.
+ *
+ * @param firstBuffer
+ */
+ public FastBufferWriter(CharBuffer firstBuffer) {
+ this.firstBuffer = firstBuffer;
+ lastBuffer = firstBuffer;
+ }
+
+ /**
+ * Creates instance with required initial capacity.
+ *
+ * @param initialSize
+ */
+ public FastBufferWriter(int initialSize) {
+ this(new CharBuffer(initialSize));
+ }
+
+ /**
+ * @see java.io.Writer.write(int c)
+ */
+ public void write(int c) throws IOException {
+ lastBuffer = lastBuffer.append((char) c);
+ length++;
+ }
+
+ /**
+ * @see java.io.Writer.write(char cbuf[])
+ */
+ public void write(char[] cbuf) throws IOException {
+ if (cbuf == null) {
+ throw new NullPointerException();
+ }
+
+ lastBuffer = lastBuffer.append(cbuf, 0, cbuf.length);
+ length += cbuf.length;
+ }
+
+ /**
+ * @see java.io.Writer.write(char cbuf[], int off, int len)
+ */
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ if (cbuf == null) {
+ throw new NullPointerException();
+ }
+
+ if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return;
+ }
+
+ lastBuffer = lastBuffer.append(cbuf, off, len);
+ length += len;
+ }
+
+ /**
+ * Returns the total number of written chars.
+ *
+ * @return
+ */
+ public int getLength() {
+ return length;
+ }
+
+ /**
+ * Returns the first link of the chain of char arrays.
+ *
+ * @return
+ */
+ public CharBuffer getFirstBuffer() {
+ return firstBuffer;
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
+
+ @Override
+ public void flush() throws IOException {
+ }
+
+ /**
+ * Writes all data written up to the moment to string buffer.
+ *
+ * @param out
+ * @throws IOException
+ */
+ public char[] toCharArray() {
+ CharBuffer b = firstBuffer;
+
+ if (b == null) {
+ return new char[0];
+ }
+
+ CharBuffer l = b;
+
+ while (l.getNext() != null) {
+ l = l.getNext();
+ }
+
+ char[] result = new char[l.getTotalSize()];
+ int index = 0;
+
+ while (b != null) {
+ int s = b.getUsedSize();
+
+ System.arraycopy(b.getChars(), 0, result, index, s);
+ index += s;
+ b = b.getNext();
+ }
+
+ return result;
+ }
+
+ /**
+ * Writes all data written up to the moment to out.
+ *
+ * @param out
+ * @throws IOException
+ */
+ public void writeTo(Writer writer) throws IOException {
+ CharBuffer b = firstBuffer;
+
+ while (b != null) {
+ writer.write(b.getChars(), 0, b.getUsedSize());
+ b = b.getNext();
+ }
+ }
+
+ public void printTo(ServletOutputStream outputStream) throws IOException {
+ CharBuffer b = firstBuffer;
+
+ while (b != null) {
+ outputStream.print(new String(b.getChars()));
+ b = b.getNext();
+ }
+ }
+
+ /**
+ * Returns instance of FastBufferOutputStream containing all data written to this writer.
+ *
+ * @param encoding
+ * @return
+ * @throws UnsupportedEncodingException
+ */
+ public FastBufferOutputStream convertToOutputStream(String encoding) throws UnsupportedEncodingException {
+ CharBuffer c = firstBuffer;
+ ByteBuffer first = c.toByteBuffer(encoding);
+ ByteBuffer b = first;
+
+ while (c != null) {
+ c = c.getNext();
+
+ if (c == null) {
+ break;
+ }
+
+ ByteBuffer n = c.toByteBuffer(encoding);
+
+ b.setNext(n);
+ b = n;
+ }
+
+ return new FastBufferOutputStream(first);
+ }
+
+ /**
+ * Returns instance of FastBufferOutputStream containing all data written to this writer.
+ *
+ * @return
+ */
+ public FastBufferOutputStream convertToOutputStream() {
+ CharBuffer c = firstBuffer;
+ ByteBuffer first = c.toByteBuffer();
+ ByteBuffer b = first;
+
+ while (c != null) {
+ c = c.getNext();
+
+ if (c == null) {
+ break;
+ }
+
+ ByteBuffer n = c.toByteBuffer();
+
+ b.setNext(n);
+ b = n;
+ }
+
+ return new FastBufferOutputStream(first);
+ }
+
+ /**
+ * Resets writer to empty state
+ *
+ * @since 3.3.0
+ */
+ public void reset() {
+ this.firstBuffer.reset();
+ this.lastBuffer = this.firstBuffer;
+ this.length = 0;
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java (from rev 22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java (rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,562 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.io;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.helpers.AttributesImpl;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * @author shura
+ * <p/>
+ * Realization of Faces <code>ResponseWriter</code> for Cocoon Environment.
+ * Use ONLY Markup-specific calls , send it as SAX events to
+ * <code>XMLConsumer</code> Use "State" pattern for control of events flow.
+ * TODO - implement namespace capabilites
+ */
+public class SAXResponseWriter extends ResponseWriter {
+
+ /**
+ * As we in XML framework, only UTF-8 supported for
+ * <code>CHARTER_ENCODING</code>
+ */
+ private static final String CHARTER_ENCODING = "UTF-8";
+
+ /**
+ * As we in XML framework, only xml supported for <code>CONTENT_TYPE</code>
+ */
+ private static final String CONTENT_TYPE = "text/xml";
+ private String namespaceURI = "http://www.w3.org/1999/xhtml";
+ private LexicalHandler xmlLexicalHandler = null;
+ private AttributesImpl attributes;
+ private XMLResponseWriterState cdataState;
+ private String element;
+
+ /**
+ * State after startElement. Collect Attributes for SAX startElement
+ * <code>elementState</code>
+ */
+ private XMLResponseWriterState elementState;
+
+ /**
+ * State in normal document <code>inDocumentState</code>
+ */
+ private XMLResponseWriterState inDocumentState;
+
+ /**
+ * Before StartDocument or after EndDocument <code>notDocumentState</code>
+ */
+ private XMLResponseWriterState notDocumentState;
+ private XMLResponseWriterState state;
+
+ /**
+ * Hold Cocoon Generator XML <code>consumer</code>
+ */
+ private ContentHandler xmlConsumer;
+
+ /**
+ * @param consumer -
+ * SAX events receiver for Cocoon pipeline.
+ */
+ public SAXResponseWriter(ContentHandler consumer) {
+ super();
+ this.xmlConsumer = consumer;
+
+ if (consumer instanceof LexicalHandler) {
+ xmlLexicalHandler = (LexicalHandler) consumer;
+ }
+
+ // Initialise states. May be must implemented in static block ?
+ this.notDocumentState = new NotDocumentState();
+
+ // inside document. allow any events exclude attributes and
+ // startDocument.
+ this.inDocumentState = new InDocumentState();
+ this.cdataState = new CDATAState();
+
+ // In element, collect attributes ...
+ this.elementState = new ElementState();
+ this.state = notDocumentState;
+ }
+
+ public ContentHandler getXmlConsumer() {
+ return xmlConsumer;
+ }
+
+ /**
+ * @return Returns the namespaceURI.
+ */
+ public String getNamespaceURI() {
+ return namespaceURI;
+ }
+
+ /**
+ * @param namespaceURI The namespaceURI to set.
+ */
+ public void setNamespaceURI(String namespaceURI) {
+ this.namespaceURI = namespaceURI;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#getContentType()
+ */
+ public String getContentType() {
+ return CONTENT_TYPE;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#getCharacterEncoding()
+ */
+ public String getCharacterEncoding() {
+ return CHARTER_ENCODING;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Flushable#flush()
+ */
+ public void flush() throws IOException {
+
+ // DO NOTHING...
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#startDocument()
+ */
+ public void startDocument() throws IOException {
+ state.startDocument();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#endDocument()
+ */
+ public void endDocument() throws IOException {
+ state.endDocument();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#startElement(java.lang.String,
+ * javax.faces.component.UIComponent)
+ */
+ public void startElement(String name, UIComponent component) throws IOException {
+ state.startElement(name, component);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#endElement(java.lang.String)
+ */
+ public void endElement(String name) throws IOException {
+ state.endElement(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#writeAttribute(java.lang.String,
+ * java.lang.Object, java.lang.String)
+ */
+ public void writeAttribute(String name, Object value, String property) throws IOException {
+ state.writeAttribute(name, value, property);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#writeURIAttribute(java.lang.String,
+ * java.lang.Object, java.lang.String)
+ */
+ public void writeURIAttribute(String name, Object value, String property) throws IOException {
+ state.writeURIAttribute(name, value, property);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#writeComment(java.lang.Object)
+ */
+ public void writeComment(Object comment) throws IOException {
+ state.writeComment(comment);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#writeText(java.lang.Object,
+ * java.lang.String)
+ */
+ public void writeText(Object text, String property) throws IOException {
+ state.writeText(text, property);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#writeText(char[], int, int)
+ */
+ public void writeText(char[] text, int off, int len) throws IOException {
+ state.writeText(text, off, len);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#cloneWithWriter(java.io.Writer)
+ */
+ public ResponseWriter cloneWithWriter(Writer writer) {
+
+ // TODO as used XML consumer to get sax Events, we simple return current
+ // instance.
+ // if will used wrapper to combine XML Consumer with plain Servlet
+ // responce writer, must
+ // perform real clone ...
+ // We can use org.apache.cocoon.xml.SaxBuffer;
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Writer#write(char[], int, int)
+ */
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ state.writeText(cbuf, off, len);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Closeable#close()
+ */
+ public void close() throws IOException {
+
+ // TODO Auto-generated method stub
+ }
+
+ /**
+ * @author shura
+ * <p/>
+ * CDATA section. allow regular write() functions, write any text.
+ */
+ private final class CDATAState extends XMLResponseWriterState {
+ void flushCDATA() throws IOException {
+
+ // try {
+ // xmlConsumer.endCDATA();
+ // } catch (SAXException e) {
+ // throw new IOException("Exception in endCDATA: "+ e.getMessage());
+ // }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#endDocument()
+ */
+ void endDocument() throws IOException {
+ flushCDATA();
+ state = inDocumentState;
+ state.endDocument();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#endElement(java.lang.String)
+ */
+ void endElement(String name) throws IOException {
+ flushCDATA();
+ state = inDocumentState;
+ state.endElement(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#startElement(java.lang.String,
+ * javax.faces.component.UIComponent)
+ */
+ void startElement(String name, UIComponent component) throws IOException {
+ flushCDATA();
+ element = name;
+ attributes = new AttributesImpl();
+ state = elementState;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeComment(java.lang.Object)
+ */
+ void writeComment(Object comment) throws IOException {
+ flushCDATA();
+ state = inDocumentState;
+ state.writeComment(comment);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(char[],
+ * int, int)
+ */
+ void writeText(char[] text, int off, int len) throws IOException {
+ try {
+ xmlConsumer.characters(text, off, len);
+ } catch (SAXException e) {
+ throw new IOException("Sax exceptions in writeText: " + e.getMessage());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(java.lang.Object,
+ * java.lang.String)
+ */
+ void writeText(Object text, String property) throws IOException {
+ writeText(text.toString().toCharArray(), 0, text.toString().length());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#write(char[],
+ * int, int)
+ */
+ void write(char[] cbuf, int off, int len) throws IOException {
+ writeText(cbuf, off, len);
+ }
+ }
+
+ /**
+ * @author shura State in element declsration. Collect attributes, on any
+ * other eventss - generate SAX startElement()
+ */
+ private final class ElementState extends XMLResponseWriterState {
+
+ /**
+ * Generate SAX StartElement event
+ *
+ * @throws IOException
+ */
+ void flushElement() throws IOException {
+ try {
+ xmlConsumer.startElement(getNamespaceURI(), element, element, attributes);
+ } catch (SAXException e) {
+ throw new IOException("Exception in startElement: " + e.getMessage());
+ } finally {
+ element = null;
+ attributes = null;
+ }
+ }
+
+ void writeAttribute(String name, Object value, String property) throws IOException {
+ attributes.addAttribute(getNamespaceURI(), name, name, "id".equalsIgnoreCase(name) ? "ID" : "CDATA",
+ value.toString());
+ }
+
+ void writeURIAttribute(String name, Object value, String property) throws IOException {
+ String uri = value.toString();
+
+ // TODO - perform encodeActionURL() or ???
+ attributes.addAttribute(getNamespaceURI(), name, name, "CDATA", uri);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#endElement(java.lang.String)
+ */
+ void endElement(String name) throws IOException {
+
+ //
+ flushElement();
+ state = inDocumentState;
+ state.endElement(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#startElement(java.lang.String,
+ * javax.faces.component.UIComponent)
+ */
+ void startElement(String name, UIComponent component) throws IOException {
+
+ //
+ flushElement();
+ element = name;
+ attributes = new AttributesImpl();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeComment(java.lang.Object)
+ */
+ void writeComment(Object comment) throws IOException {
+
+ // TODO Auto-generated method stub
+ flushElement();
+ state = inDocumentState;
+ state.writeComment(comment);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(char[],
+ * int, int)
+ */
+ void writeText(char[] text, int off, int len) throws IOException {
+
+ // TODO Auto-generated method stub
+ flushElement();
+ state = cdataState;
+ state.writeText(text, off, len);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(java.lang.Object,
+ * java.lang.String)
+ */
+ void writeText(Object text, String property) throws IOException {
+
+ // TODO Auto-generated method stub
+ flushElement();
+ state = cdataState;
+ state.writeText(text, property);
+ }
+ }
+
+ /**
+ * @author shura
+ * <p/>
+ * State in regular document. Disabled attributes & startDocument.
+ */
+ private final class InDocumentState extends XMLResponseWriterState {
+ void startElement(String name, UIComponent component) {
+ element = name;
+ attributes = new AttributesImpl();
+ state = elementState;
+ }
+
+ void writeComment(Object comment) throws IOException {
+ String remark = comment.toString();
+
+ try {
+ xmlLexicalHandler.comment(remark.toCharArray(), 0, remark.length());
+ } catch (SAXException e) {
+ throw new IOException("Comment SAX exception :" + e.getMessage());
+ }
+ }
+
+ void writeText(Object o, String property) throws IOException {
+ writeText(o.toString().toCharArray(), 0, o.toString().length());
+ }
+
+ void writeText(char[] text, int start, int lenght) throws IOException {
+
+ // try {
+ // xmlConsumer.startCDATA();
+ // } catch (SAXException e) {
+ // throw new IOException("Sax exceptions in writeText: "+
+ // e.getMessage());
+ // } finally {
+ state = cdataState;
+
+ // }
+ state.writeText(text, start, lenght);
+ }
+
+ void endElement(String name) throws IOException {
+ try {
+ xmlConsumer.endElement(getNamespaceURI(), name, name);
+ } catch (SAXException e) {
+ throw new IOException("Sax exceptions in endElement: " + e.getMessage());
+ }
+ }
+
+ void endDocument() throws IOException {
+ try {
+ xmlConsumer.endDocument();
+ } catch (SAXException e) {
+ throw new IOException("Sax exceptions in endDocument" + e.getMessage());
+ } finally {
+
+ // after endDocument all events disabled ...
+ state = new XMLResponseWriterState();
+ }
+ }
+ }
+
+
+ // Private classes
+
+ /**
+ * @author shura
+ * <p/>
+ * state before startDocument - only allow startDocument.
+ */
+ private final class NotDocumentState extends XMLResponseWriterState {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#startDocument()
+ */
+ void startDocument() throws IOException {
+ try {
+
+ //
+ xmlConsumer.startDocument();
+ } catch (SAXException e) {
+
+ //
+ throw new IOException("StartDocument SAX exception :" + e.getMessage());
+ } finally {
+ state = inDocumentState;
+ }
+ }
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java (from rev 22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java (rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,127 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.io;
+
+import javax.faces.component.UIComponent;
+import java.io.IOException;
+
+/**
+ * @author shura Class to implement state pattern for
+ * <code>ResponseWriter</code> Real states must extend this. By
+ * default, block any events, ignore output.
+ */
+class XMLResponseWriterState {
+
+ // private ResponseWriter writer;
+
+ /**
+ * @throws java.io.IOException
+ */
+ void endDocument() throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param name
+ * @throws java.io.IOException
+ */
+ void endElement(String name) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @throws java.io.IOException
+ */
+ void startDocument() throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param name
+ * @param component
+ * @throws java.io.IOException
+ */
+ void startElement(String name, UIComponent component) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param name
+ * @param value
+ * @param property
+ * @throws java.io.IOException
+ */
+ void writeAttribute(String name, Object value, String property) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param comment
+ * @throws java.io.IOException
+ */
+ void writeComment(Object comment) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param text
+ * @param off
+ * @param len
+ * @throws java.io.IOException
+ */
+ void writeText(char[] text, int off, int len) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param text
+ * @param property
+ * @throws java.io.IOException
+ */
+ void writeText(Object text, String property) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param name
+ * @param value
+ * @param property
+ * @throws java.io.IOException
+ */
+ void writeURIAttribute(String name, Object value, String property) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * Main hook for realise <code>Writer</code>. In document writed as
+ * comment, outside of document do nothing ....
+ *
+ * @param cbuf
+ * @param off
+ * @param len
+ * @throws IOException
+ */
+ void write(char[] cbuf, int off, int len) throws IOException {
+
+ // DO NOTHING
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/package-info.java (from rev 22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/package-info.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/package-info.java (rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/package-info.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,4 @@
+/**
+ * Implementation of I/O streams based on buffers
+ */
+package org.ajax4jsf.io;
Copied: trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java (from rev 22426, trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java)
===================================================================
--- trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java (rev 0)
+++ trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,81 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+
+package org.ajax4jsf.io;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+public class FastBufferOutputStreamTest extends TestCase {
+
+ /**
+ * Test method for {@link org.ajax4jsf.io.FastBufferOutputStream#reset()}.
+ */
+ public void testResetOneBuffer() throws Exception {
+ FastBufferOutputStream stream = new FastBufferOutputStream(256);
+
+ for (int i = 0; i < 255; i++) {
+ stream.write(i);
+ }
+
+ assertEquals(255, stream.getLength());
+
+ ByteBuffer firstBuffer = stream.getFirstBuffer();
+
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ stream.reset();
+ assertEquals(0, stream.getLength());
+ firstBuffer = stream.getFirstBuffer();
+ assertEquals(0, firstBuffer.getUsedSize());
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.io.FastBufferOutputStream#reset()}.
+ */
+ public void testResetTwoBuffers() throws Exception {
+ FastBufferOutputStream stream = new FastBufferOutputStream(256);
+
+ for (int i = 0; i < 257; i++) {
+ stream.write(i);
+ }
+
+ assertEquals(257, stream.getLength());
+
+ ByteBuffer firstBuffer = stream.getFirstBuffer();
+
+ assertNotNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ stream.reset();
+ assertEquals(0, stream.getLength());
+ firstBuffer = stream.getFirstBuffer();
+ assertEquals(0, firstBuffer.getUsedSize());
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ }
+}
Copied: trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java (from rev 22426, trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java)
===================================================================
--- trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java (rev 0)
+++ trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,114 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+
+package org.ajax4jsf.io;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+public class FastBufferWriterTest extends TestCase {
+
+ /**
+ * Test method for {@link org.ajax4jsf.io.FastBufferWriter#reset()}.
+ */
+ public void testResetOneBuffer() throws Exception {
+ FastBufferWriter stream = new FastBufferWriter(256);
+
+ for (int i = 0; i < 255; i++) {
+ stream.write(i);
+ }
+
+ assertEquals(255, stream.getLength());
+
+ CharBuffer firstBuffer = stream.getFirstBuffer();
+
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ stream.reset();
+ assertEquals(0, stream.getLength());
+ firstBuffer = stream.getFirstBuffer();
+ assertEquals(0, firstBuffer.getUsedSize());
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.io.FastBufferWriter#reset()}.
+ */
+ public void testResetTwoBuffers() throws Exception {
+ FastBufferWriter stream = new FastBufferWriter(256);
+
+ for (int i = 0; i < 257; i++) {
+ stream.write(i);
+ }
+
+ assertEquals(257, stream.getLength());
+
+ CharBuffer firstBuffer = stream.getFirstBuffer();
+
+ assertNotNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ stream.reset();
+ assertEquals(0, stream.getLength());
+ firstBuffer = stream.getFirstBuffer();
+ assertEquals(0, firstBuffer.getUsedSize());
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ }
+
+ public void testCompact() throws Exception {
+ int itemsTowWrite = 16384 + 16000;
+ FastBufferWriter writer = new FastBufferWriter(16384);
+
+ for (int i = 0; i < itemsTowWrite; i++) {
+ writer.write(i);
+ }
+
+ writer.close();
+
+ CharBuffer firstBuffer = writer.getFirstBuffer();
+
+ assertNotNull(firstBuffer);
+
+ CharBuffer nextBuffer = firstBuffer.getNext();
+
+ assertNotNull(nextBuffer);
+ assertNull(nextBuffer.getNext());
+ assertTrue(firstBuffer.getUsedSize() == firstBuffer.getCacheSize());
+ assertTrue(nextBuffer.getUsedSize() < nextBuffer.getCacheSize());
+ firstBuffer.compact();
+ assertTrue(firstBuffer.getUsedSize() == firstBuffer.getCacheSize());
+ assertTrue(nextBuffer.getUsedSize() == nextBuffer.getCacheSize());
+
+ FastBufferReader reader = new FastBufferReader(firstBuffer);
+
+ for (int i = 0; i < itemsTowWrite; i++) {
+ assertEquals(i, reader.read());
+ }
+
+ reader.close();
+ }
+}
Copied: trunk/core/api/src/test/java/org/ajax4jsf/io/Test.java (from rev 22426, trunk/core/impl/src/test/java/org/ajax4jsf/io/Test.java)
===================================================================
--- trunk/core/api/src/test/java/org/ajax4jsf/io/Test.java (rev 0)
+++ trunk/core/api/src/test/java/org/ajax4jsf/io/Test.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -0,0 +1,340 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+
+package org.ajax4jsf.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import org.junit.Ignore;
+
+@Ignore
+public final class Test {
+ private static final int ARRAY_LENGTH = 27;
+ private static final int READ_LENGTH = 22;
+ private static final int READ_OFF = 4;
+ private static final boolean OUT_STRING = true;
+ private static final boolean BUILD_STRING = false;
+
+ private Test() {}
+
+ static void testStreams() throws IOException {
+ String s = "This is a senseless text to test streams.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ byte[] bytes = s.getBytes();
+ FastBufferOutputStream output = new FastBufferOutputStream(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ FastBufferInputStream input = new FastBufferInputStream(output);
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ byte[] bs = new byte[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ System.out.println("Length=" + output.getLength());
+ }
+ }
+
+ static void testStandardStreams() throws IOException {
+ String s = "This is a senseless text to test streams.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ byte[] bytes = s.getBytes();
+ ByteArrayOutputStream output = new ByteArrayOutputStream(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ byte[] bs = new byte[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ static void testReaders() throws IOException {
+ String s = "This is a senseless text to test readers.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ char[] bytes = s.toCharArray();
+ FastBufferWriter output = new FastBufferWriter(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ FastBufferReader input = new FastBufferReader(output);
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ char[] bs = new char[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ static void testStandardReaders() throws IOException {
+ String s = "This is a senseless text to test readers.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ char[] bytes = s.toCharArray();
+ StringWriter output = new StringWriter(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ StringReader input = new StringReader(output.toString());
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ char[] bs = new char[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ static void testTransitionFromWriterToStream() throws IOException {
+ String s = "This is a senseless text to test transform from writer to stream.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ char[] bytes = s.toCharArray();
+ FastBufferWriter output = new FastBufferWriter(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ FastBufferOutputStream output2 = output.convertToOutputStream("UTF-8");
+ FastBufferInputStream input = new FastBufferInputStream(output2);
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ byte[] bs = new byte[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ static void testStandardTransitionFromWriterToStream() throws IOException {
+ String s = "This is a senseless text to test transform from writer to stream.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ char[] bytes = s.toCharArray();
+ StringWriter output = new StringWriter(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ String str = output.toString();
+ ByteArrayInputStream input = new ByteArrayInputStream(str.getBytes());
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ byte[] bs = new byte[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ static void testTransitionFromStreamToWriter() throws IOException {
+ String s = "This is a senseless text to test transform from stream to writer.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ byte[] bytes = s.getBytes();
+ FastBufferOutputStream output = new FastBufferOutputStream(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ FastBufferWriter output2 = output.convertToWriter("UTF-8");
+ FastBufferReader input = new FastBufferReader(output2);
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ char[] bs = new char[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ long t = System.currentTimeMillis();
+
+ try {
+ for (int i = 0; i < 10; i++) {
+
+// testStreams();
+// testStandardStreams();
+// testReaders();
+// testStandardReaders();
+// testTransitionFromWriterToStream();
+ testStandardTransitionFromWriterToStream();
+
+// testTransitionFromStreamToWriter();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ long dt = System.currentTimeMillis() - t;
+
+ System.out.println(dt);
+ }
+}
Modified: trunk/core/api/src/test/java/org/richfaces/log/JavaLoggerTest.java
===================================================================
--- trunk/core/api/src/test/java/org/richfaces/log/JavaLoggerTest.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/api/src/test/java/org/richfaces/log/JavaLoggerTest.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -158,7 +158,7 @@
Logger.class.getMethod(levelName, Throwable.class, Enum.class, Object[].class).invoke(logger,
new UnsupportedOperationException(levelName), LoggerTestMessages.TEST_MESSAGE, new Object[] {levelName,
- ANOTHER_DUMMY_MESSAGE});
+ ANOTHER_DUMMY_MESSAGE});
}
Iterator<LogRecord> iterator = publishedRecords.iterator();
Modified: trunk/core/api/src/test/java/org/richfaces/util/LRUMapTest.java
===================================================================
--- trunk/core/api/src/test/java/org/richfaces/util/LRUMapTest.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/api/src/test/java/org/richfaces/util/LRUMapTest.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -26,8 +26,6 @@
import java.util.Iterator;
import java.util.Map.Entry;
-import org.richfaces.util.LRUMap;
-
import junit.framework.TestCase;
/**
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,266 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.io;
-
-import java.io.UnsupportedEncodingException;
-
-/**
- * A single link in chain of byte arrays.
- *
- * @author glory
- */
-public class ByteBuffer {
- private static final int MAX_WASTE = 16384;
-
- /**
- * Stored bytes
- */
- private byte[] bytes;
-
- /**
- * Length of byte array.
- */
- private int cacheSize;
- private ByteBuffer next;
- private ByteBuffer prev;
-
- /**
- * Number of bytes stored in the array.
- */
- private int usedSize;
-
- /**
- * Creates instance of ByteBuffer already filled by bytes.
- *
- * @param bytes
- */
- public ByteBuffer(byte[] bytes) {
- this.bytes = bytes;
- usedSize = bytes.length;
- cacheSize = usedSize;
- }
-
- /**
- * Creates instance of ByteBuffer with byte array of required length.
- *
- * @param cacheSize length of byte array
- */
- public ByteBuffer(int cacheSize) {
- bytes = new byte[cacheSize];
- this.cacheSize = cacheSize;
- usedSize = 0;
- }
-
- /**
- * Appends byte to array if there are unfilled positions in it.
- * Otherwize creates next link in the chain, and appends the byte to it.
- *
- * @param c
- * @return instance of ByteBuffer to which byte was appended.
- */
- public ByteBuffer append(byte c) {
- if (next != null) {
- return next.append(c);
- }
-
- if (usedSize < cacheSize) {
- bytes[usedSize] = c;
- usedSize++;
-
- return this;
- } else {
- next = new ByteBuffer(cacheSize * 2);
- next.prev = this;
-
- return next.append(c);
- }
- }
-
- /**
- * Appends segment of a byte array to array if there are unfilled positions in it.
- * Otherwize creates next link in the chain, and appends data to it.
- *
- * @param c
- * @return instance of ByteBuffer to which byte array was appended.
- */
- public ByteBuffer append(byte[] bs, int off, int len) {
- if (next != null) {
- return next.append(bs, off, len);
- }
-
- if (len + usedSize <= cacheSize) {
- System.arraycopy(bs, off, bytes, usedSize, len);
- usedSize += len;
-
- return this;
- }
-
- int av = cacheSize - usedSize;
-
- if (av > 0) {
- System.arraycopy(bs, off, bytes, usedSize, av);
- usedSize += av;
- off += av;
- len -= av;
- }
-
- next = new ByteBuffer(cacheSize * 2);
- next.prev = this;
-
- return next.append(bs, off, len);
- }
-
- /**
- * Returns stored byte array.
- *
- * @return stored byte array
- */
- public byte[] getBytes() {
- return bytes;
- }
-
- /**
- * Returns byte at index. No check is fulfilled to provide high speed.
- *
- * @param index
- * @return
- */
- public byte getByteAt(int index) {
- return bytes[index];
- }
-
- /**
- * Returns actual number of byte stored in this link.
- *
- * @return
- */
- public int getUsedSize() {
- return usedSize;
- }
-
- /**
- * Returns capacity of this link.
- *
- * @return
- */
- public int getCacheSize() {
- return cacheSize;
- }
-
- /**
- * Returns total number of bytes stored in this link and all its predecessors.
- *
- * @return
- */
- public int getTotalSize() {
- return (prev == null) ? usedSize : prev.getTotalSize() + usedSize;
- }
-
- /**
- * Returns the previous link in the chain.
- *
- * @return
- */
- public ByteBuffer getPrevious() {
- return prev;
- }
-
- /**
- * Returns the next link in the chain.
- *
- * @return
- */
- public ByteBuffer getNext() {
- return next;
- }
-
- /**
- * Sets the next link in the chain.
- *
- * @param b
- */
- public void setNext(ByteBuffer b) {
- next = b;
-
- if (b != null) {
- b.prev = this;
- }
- }
-
- /**
- * Transforms this instance to instance of CharBuffer (a link of chain of char arrays).
- *
- * @param encoding
- * @return link of chain of char arrays
- * @throws UnsupportedEncodingException
- */
- public CharBuffer toCharBuffer(String encoding) throws UnsupportedEncodingException {
- String s;
-
- if (null != encoding) {
- s = new String(bytes, 0, usedSize, encoding);
- } else {
- s = new String(bytes, 0, usedSize);
- }
-
- return new CharBuffer(s.toCharArray());
- }
-
- /**
- * Transforms this instance to instance of CharBuffer (a link of chain of char arrays).
- *
- * @return link of chain of char arrays
- */
- public CharBuffer toCharBuffer() {
- String s = new String(bytes, 0, usedSize);
-
- return new CharBuffer(s.toCharArray());
- }
-
- /**
- * Resets this byte buffer to empty state
- *
- * @since 3.3.0
- */
- public void reset() {
- usedSize = 0;
- next = null;
- prev = null;
- }
-
- /**
- * @since 4.0
- */
- public void compact() {
- if (bytes.length - usedSize > MAX_WASTE) {
- byte[] bs = new byte[usedSize];
-
- System.arraycopy(bytes, 0, bs, 0, usedSize);
- this.bytes = bs;
- this.cacheSize = bs.length;
- }
-
- if (next != null) {
- next.compact();
- }
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,266 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.io;
-
-import java.io.UnsupportedEncodingException;
-
-/**
- * A single link in chain of char arrays.
- *
- * @author glory
- */
-public class CharBuffer {
- private static final int MAX_WASTE = 16384;
- private static final int MIN_CACHE_SIZE = 64;
-
- /**
- * Length of char array.
- */
- private int cacheSize;
-
- /**
- * Stored characters
- */
- private char[] chars;
- private CharBuffer next;
- private CharBuffer prev;
-
- /**
- * number of characters stored in the array.
- */
- private int usedSize;
-
- /**
- * Creates instance of CharBuffer already filled by chars.
- *
- * @param bytes
- */
- public CharBuffer(char[] chars) {
- this.chars = chars;
- usedSize = chars.length;
- cacheSize = usedSize;
- }
-
- /**
- * Creates instance of CharBuffer with char array of required length.
- *
- * @param cacheSize length of char array
- */
- public CharBuffer(int cacheSize) {
- if (cacheSize < MIN_CACHE_SIZE) {
- this.cacheSize = MIN_CACHE_SIZE;
- } else {
- this.cacheSize = cacheSize;
- }
-
- chars = new char[this.cacheSize];
- usedSize = 0;
- }
-
- /**
- * Appends character to array chars if there are unfilled positions in it.
- * Otherwise creates next link in the chain, and appends the character to it.
- *
- * @param c
- * @return instance of CharBuffer to which character was appended.
- */
- public CharBuffer append(char c) {
- if (next != null) {
- return next.append(c);
- }
-
- if (usedSize < cacheSize) {
- chars[usedSize] = c;
- usedSize++;
-
- return this;
- } else {
- next = new CharBuffer(cacheSize * 2);
- next.prev = this;
-
- return next.append(c);
- }
- }
-
- /**
- * Appends segment of a char array to array if there are unfilled positions in it.
- * Otherwise creates next link in the chain, and appends data to it.
- *
- * @param c
- * @return instance of CharBuffer to which char array was appended.
- */
- public CharBuffer append(char[] cs, int off, int len) {
- if (next != null) {
- return next.append(cs, off, len);
- }
-
- if (len + usedSize <= cacheSize) {
- System.arraycopy(cs, off, chars, usedSize, len);
- usedSize += len;
-
- return this;
- }
-
- int av = cacheSize - usedSize;
-
- if (av > 0) {
- System.arraycopy(cs, off, chars, usedSize, av);
- usedSize += av;
- off += av;
- len -= av;
- }
-
- next = new CharBuffer(cacheSize * 2);
- next.prev = this;
-
- return next.append(cs, off, len);
- }
-
- /**
- * Returns stored char array.
- *
- * @return stored char array
- */
- public char[] getChars() {
- return chars;
- }
-
- /**
- * Returns character at index. No check is fulfilled to provide high speed.
- *
- * @param index
- * @return
- */
- public char getCharAt(int index) {
- return chars[index];
- }
-
- /**
- * Returns actual number of characters stored in this link.
- *
- * @return
- */
- public int getUsedSize() {
- return usedSize;
- }
-
- /**
- * Returns capacity of this link.
- *
- * @return
- */
- public int getCacheSize() {
- return cacheSize;
- }
-
- /**
- * Returns total number of characters stored in this link and all its predecessors.
- *
- * @return
- */
- public int getTotalSize() {
- return (prev == null) ? usedSize : prev.getTotalSize() + usedSize;
- }
-
- /**
- * Returns the previous link in the chain.
- *
- * @return
- */
- public CharBuffer getPrevious() {
- return prev;
- }
-
- /**
- * Returns the next link in the chain.
- *
- * @return
- */
- public CharBuffer getNext() {
- return next;
- }
-
- /**
- * Sets the next link in the chain.
- *
- * @param b
- */
- public void setNext(CharBuffer b) {
- next = b;
-
- if (b != null) {
- b.prev = this;
- }
- }
-
- /**
- * Transforms this instance to instance of ByteBuffer (a link of chain of byte arrays).
- *
- * @param encoding
- * @return link of chain of byte arrays
- * @throws UnsupportedEncodingException
- */
- public ByteBuffer toByteBuffer(String encoding) throws UnsupportedEncodingException {
- byte[] bs = new String(chars, 0, usedSize).getBytes(encoding);
-
- return new ByteBuffer(bs);
- }
-
- /**
- * Transforms this instance to instance of ByteBuffer (a link of chain of byte arrays).
- *
- * @return link of chain of byte arrays
- */
- public ByteBuffer toByteBuffer() {
- byte[] bs = new String(chars, 0, usedSize).getBytes();
-
- return new ByteBuffer(bs);
- }
-
- /**
- * Resets this char buffer to empty state
- *
- * @since 3.3.0
- */
- public void reset() {
- usedSize = 0;
- next = null;
- prev = null;
- }
-
- /**
- * @since 4.0
- */
- public void compact() {
- if (chars.length - usedSize > MAX_WASTE) {
- char[] cs = new char[usedSize];
-
- System.arraycopy(chars, 0, cs, 0, usedSize);
- this.chars = cs;
- this.cacheSize = cs.length;
- }
-
- if (next != null) {
- next.compact();
- }
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,260 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.io;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Class for reading from a byte array chain.
- *
- * @author glory
- */
-public class FastBufferInputStream extends InputStream {
-
- /**
- * Currently read link.
- */
- ByteBuffer current;
-
- /**
- * The first link in the chain of char arrays.
- */
- ByteBuffer firstLink;
-
- /**
- * Position of next byte in current link.
- */
- int index;
- int mark;
-
- public FastBufferInputStream(ByteBuffer byteBuffer) {
- this.firstLink = byteBuffer;
- current = byteBuffer;
- index = 0;
- mark = 0;
- }
-
- /**
- * Creates instance of FastBufferInputStream.
- *
- * @param stream
- */
- @Deprecated
- public FastBufferInputStream(FastBufferOutputStream stream) {
- this(stream.getFirstBuffer());
- }
-
- /**
- * @see java.io.InputStream.read()
- */
- public int read() throws IOException {
- if (current == null) {
- return -1;
- }
-
- if (current.getUsedSize() <= index) {
- current = current.getNext();
-
- if (current == null) {
- return -1;
- }
-
- index = 0;
- }
-
- byte c = current.getByteAt(index);
-
- index++;
-
- return c;
- }
-
- /**
- * @see java.io.InputStream.read(byte b[])
- */
- @Override
- public int read(byte[] b) throws IOException {
- if (b == null) {
- throw new NullPointerException();
- }
-
- if (current == null) {
- return -1;
- }
-
- int off = 0;
- int len = b.length;
- int actuallyRead = 0;
-
- while ((current != null) && (len > 0)) {
- int av = current.getUsedSize() - index;
-
- if (av <= 0) {
- current = current.getNext();
- index = 0;
-
- continue;
- }
-
- if (av > len) {
- av = len;
- }
-
- System.arraycopy(current.getBytes(), index, b, off, av);
- index += av;
- off += av;
- actuallyRead += av;
- len -= av;
- }
-
- return (actuallyRead == 0) ? -1 : actuallyRead;
- }
-
- /**
- * @see java.io.InputStream.read(byte b[], int off, int len)
- */
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- if (b == null) {
- throw new NullPointerException();
- } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return 0;
- }
-
- if (current == null) {
- return -1;
- }
-
- int actuallyRead = 0;
-
- while ((current != null) && (len > 0)) {
- int av = current.getUsedSize() - index;
-
- if (av <= 0) {
- current = current.getNext();
- index = 0;
-
- continue;
- }
-
- if (av > len) {
- av = len;
- }
-
- System.arraycopy(current.getBytes(), index, b, off, av);
- index += av;
- off += av;
- actuallyRead += av;
- len -= av;
- }
-
- return (actuallyRead == 0) ? -1 : actuallyRead;
- }
-
- /**
- * @see java.io.InputStream.available()
- */
- public int available() throws IOException {
- if (current == null) {
- return 0;
- }
-
- ByteBuffer b = current;
- int result = -index;
-
- while (b != null) {
- result += b.getUsedSize();
- b = b.getNext();
- }
-
- return result;
- }
-
- /**
- * @see java.io.InputStream.mark()
- */
- public void mark(int readAheadLimit) {
- if (current == null) {
- mark = 0;
- } else {
- mark = index;
-
- ByteBuffer b = current.getPrevious();
-
- if (b != null) {
- mark += b.getTotalSize();
- }
- }
- }
-
- /**
- * @see java.io.InputStream.reset()
- */
- public void reset() {
- if (current == null) {
- current = firstLink;
- }
-
- int m = 0;
-
- while ((current != null) && (current.getUsedSize() + m <= mark)) {
- m += current.getUsedSize();
- current = current.getNext();
- }
-
- if (current != null) {
- index = mark - m;
- }
- }
-
- /**
- * @see java.io.InputStream.skip()
- */
- public long skip(long n) throws IOException {
- long skipped = 0;
-
- while (n > 0) {
- if (current == null) {
- return 0;
- }
-
- if (current.getUsedSize() - index <= n) {
- index += n;
- skipped += n;
-
- break;
- } else {
- int dn = current.getUsedSize() - index;
-
- skipped += dn;
- n -= dn;
- current = current.getNext();
- index = 0;
- }
- }
-
- return skipped;
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,256 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.io;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-
-/**
- * Class for writing to chain of byte arrays extending OutputStream.
- *
- * @author glory
- */
-public class FastBufferOutputStream extends OutputStream {
-
- /**
- * The beginning of the chain of byte arrays.
- */
- ByteBuffer firstBuffer;
-
- /**
- * Currently filled link of the chain of byte arrays.
- */
- ByteBuffer lastBuffer;
-
- /**
- * Total number of written bytes.
- */
- int length;
-
- /**
- * Creates instance of default initial capacity.
- */
- public FastBufferOutputStream() {
- this(256);
- }
-
- /**
- * Creates instance for an already existing chain of byte arrays.
- *
- * @param firstBuffer
- */
- public FastBufferOutputStream(ByteBuffer firstBuffer) {
- this.firstBuffer = firstBuffer;
- this.lastBuffer = firstBuffer;
- }
-
- /**
- * Creates instance with required initial capacity.
- *
- * @param initialSize
- */
- public FastBufferOutputStream(int initialSize) {
- this(new ByteBuffer(initialSize));
- }
-
- /**
- * @see java.io.OutputStream.write(int c)
- */
- public void write(int c) throws IOException {
- lastBuffer = lastBuffer.append((byte) c);
- length++;
- }
-
- /**
- * @see java.io.OutputStream.write(byte b[])
- */
- public void write(byte[] b) throws IOException {
- if (b == null) {
- throw new NullPointerException();
- }
-
- int limit = b.length;
-
- length += limit;
- lastBuffer = lastBuffer.append(b, 0, limit);
- }
-
- /**
- * @see java.io.OutputStream.write(byte[] b, int off, int len)
- */
- public void write(byte[] b, int off, int len) throws IOException {
- if (b == null) {
- throw new NullPointerException();
- } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return;
- }
-
- lastBuffer = lastBuffer.append(b, off, len);
- length += len;
- }
-
- /**
- * Returns the total number of written bytes.
- *
- * @return
- */
- public int getLength() {
- return length;
- }
-
- /**
- * Returns the first link of the chain of byte arrays.
- *
- * @return
- */
- public ByteBuffer getFirstBuffer() {
- return firstBuffer;
- }
-
- public byte[] toByteArray() {
- ByteBuffer b = getFirstBuffer();
-
- if (b == null) {
- return new byte[0];
- }
-
- ByteBuffer l = b;
-
- while (l.getNext() != null) {
- l = l.getNext();
- }
-
- byte[] result = new byte[l.getTotalSize()];
- int index = 0;
-
- while (b != null) {
- int s = b.getUsedSize();
-
- System.arraycopy(b.getBytes(), 0, result, index, s);
- index += s;
- b = b.getNext();
- }
-
- return result;
- }
-
- /**
- * Writes all data written up to the moment to out.
- *
- * @param out
- * @throws IOException
- */
- public void writeTo(OutputStream out) throws IOException {
- ByteBuffer b = getFirstBuffer();
-
- while (b != null) {
- out.write(b.getBytes(), 0, b.getUsedSize());
- b = b.getNext();
- }
- }
-
- /**
- * Writes all data written up to the moment to out.
- *
- * @param out
- * @throws IOException
- */
- public void writeTo(Writer out, String encoding) throws IOException {
- ByteBuffer b = getFirstBuffer();
-
- while (b != null) {
- CharBuffer c = b.toCharBuffer(encoding);
-
- out.write(c.getChars(), 0, c.getUsedSize());
- b = b.getNext();
- }
- }
-
- /**
- * Returns instance of FastBufferWriter containing all data written to this output stream.
- *
- * @param encoding
- * @return
- * @throws UnsupportedEncodingException
- */
- public FastBufferWriter convertToWriter(String encoding) throws UnsupportedEncodingException {
- ByteBuffer c = firstBuffer;
- CharBuffer first = c.toCharBuffer(encoding);
- CharBuffer b = first;
-
- while (c != null) {
- c = c.getNext();
-
- if (c == null) {
- break;
- }
-
- CharBuffer n = c.toCharBuffer(encoding);
-
- b.setNext(n);
- b = n;
- }
-
- return new FastBufferWriter(first);
- }
-
- /**
- * Returns instance of FastBufferWriter containing all data written to this output stream.
- *
- * @return
- */
- public FastBufferWriter convertToWriter() {
- ByteBuffer c = firstBuffer;
- CharBuffer first = c.toCharBuffer();
- CharBuffer b = first;
-
- while (c != null) {
- c = c.getNext();
-
- if (c == null) {
- break;
- }
-
- CharBuffer n = c.toCharBuffer();
-
- b.setNext(n);
- b = n;
- }
-
- return new FastBufferWriter(first);
- }
-
- /**
- * Resets stream to empty state
- *
- * @since 3.3.0
- */
- public void reset() {
- this.firstBuffer.reset();
- this.lastBuffer = this.firstBuffer;
- this.length = 0;
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferReader.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferReader.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferReader.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,181 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.io;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-
-/**
- * Class for reading from a char array chain.
- *
- * @author glory
- */
-public class FastBufferReader extends Reader {
-
- /**
- * Currently read link.
- */
- CharBuffer current;
-
- /**
- * The first link in the chain of char arrays.
- */
- CharBuffer firstLink;
-
- /**
- * Position of next char in current link.
- */
- int index;
-
- public FastBufferReader(CharBuffer buffer) {
- firstLink = buffer;
- current = firstLink;
- index = 0;
- }
-
- /**
- * Creates instance for given writer.
- *
- * @param writer
- */
- @Deprecated
- public FastBufferReader(FastBufferWriter writer) {
- firstLink = writer.getFirstBuffer();
- current = firstLink;
- index = 0;
- }
-
- public void close() throws IOException {
- }
-
- /**
- * @see java.io.Reader.read()
- */
- public int read() throws IOException {
- if (current == null) {
- return -1;
- }
-
- if (current.getUsedSize() <= index) {
- current = current.getNext();
-
- if (current == null) {
- return -1;
- }
-
- index = 0;
- }
-
- char c = current.getCharAt(index);
-
- index++;
-
- return c;
- }
-
- /**
- * @see java.io.Reader.read(char[] cbuf, int off, int len)
- */
- public int read(char[] cbuf, int off, int len) throws IOException {
- if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return 0;
- }
-
- if (current == null) {
- return -1;
- }
-
- int actuallyRead = 0;
-
- while ((current != null) && (len > 0)) {
- int av = current.getUsedSize() - index;
-
- if (av <= 0) {
- current = current.getNext();
- index = 0;
-
- continue;
- }
-
- if (av > len) {
- av = len;
- }
-
- System.arraycopy(current.getChars(), index, cbuf, off, av);
- index += av;
- off += av;
- actuallyRead += av;
- len -= av;
- }
-
- return (actuallyRead == 0) ? -1 : actuallyRead;
- }
-
- /**
- * Returns the number of chars that may be read from this storage.
- *
- * @return
- * @throws IOException
- */
- public int available() throws IOException {
- if (current == null) {
- return 0;
- }
-
- CharBuffer b = current;
- int result = -index;
-
- while (b != null) {
- result += b.getUsedSize();
- b = b.getNext();
- }
-
- return result;
- }
-
- /**
- * Writes rest of data written up to the moment to out.
- *
- * @param out
- * @throws IOException
- */
- public void writeTo(Writer writer) throws IOException {
- if (current == null) {
- return;
- }
-
- if (current.getUsedSize() > index) {
- writer.write(current.getChars(), index, current.getUsedSize() - index);
- current = current.getNext();
- }
-
- while (current != null) {
- writer.write(current.getChars(), 0, current.getUsedSize());
- current = current.getNext();
- }
-
- index = 0;
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,262 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.io;
-
-import javax.servlet.ServletOutputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-
-/**
- * Class for writing to chain of char arrays extending Writer.
- *
- * @author glory
- */
-public class FastBufferWriter extends Writer {
-
- /**
- * The beginning of the chain of char arrays.
- */
- CharBuffer firstBuffer;
-
- /**
- * Currently filled link of the chain of char arrays.
- */
- CharBuffer lastBuffer;
-
- /**
- * Total number of written chars.
- */
- int length;
-
- /**
- * Creates instance of default initial capacity.
- */
- public FastBufferWriter() {
- this(256);
- }
-
- /**
- * Creates instance for an already existing chain of char arrays.
- *
- * @param firstBuffer
- */
- public FastBufferWriter(CharBuffer firstBuffer) {
- this.firstBuffer = firstBuffer;
- lastBuffer = firstBuffer;
- }
-
- /**
- * Creates instance with required initial capacity.
- *
- * @param initialSize
- */
- public FastBufferWriter(int initialSize) {
- this(new CharBuffer(initialSize));
- }
-
- /**
- * @see java.io.Writer.write(int c)
- */
- public void write(int c) throws IOException {
- lastBuffer = lastBuffer.append((char) c);
- length++;
- }
-
- /**
- * @see java.io.Writer.write(char cbuf[])
- */
- public void write(char[] cbuf) throws IOException {
- if (cbuf == null) {
- throw new NullPointerException();
- }
-
- lastBuffer = lastBuffer.append(cbuf, 0, cbuf.length);
- length += cbuf.length;
- }
-
- /**
- * @see java.io.Writer.write(char cbuf[], int off, int len)
- */
- public void write(char[] cbuf, int off, int len) throws IOException {
- if (cbuf == null) {
- throw new NullPointerException();
- }
-
- if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return;
- }
-
- lastBuffer = lastBuffer.append(cbuf, off, len);
- length += len;
- }
-
- /**
- * Returns the total number of written chars.
- *
- * @return
- */
- public int getLength() {
- return length;
- }
-
- /**
- * Returns the first link of the chain of char arrays.
- *
- * @return
- */
- public CharBuffer getFirstBuffer() {
- return firstBuffer;
- }
-
- @Override
- public void close() throws IOException {
- }
-
- @Override
- public void flush() throws IOException {
- }
-
- /**
- * Writes all data written up to the moment to string buffer.
- *
- * @param out
- * @throws IOException
- */
- public char[] toCharArray() {
- CharBuffer b = firstBuffer;
-
- if (b == null) {
- return new char[0];
- }
-
- CharBuffer l = b;
-
- while (l.getNext() != null) {
- l = l.getNext();
- }
-
- char[] result = new char[l.getTotalSize()];
- int index = 0;
-
- while (b != null) {
- int s = b.getUsedSize();
-
- System.arraycopy(b.getChars(), 0, result, index, s);
- index += s;
- b = b.getNext();
- }
-
- return result;
- }
-
- /**
- * Writes all data written up to the moment to out.
- *
- * @param out
- * @throws IOException
- */
- public void writeTo(Writer writer) throws IOException {
- CharBuffer b = firstBuffer;
-
- while (b != null) {
- writer.write(b.getChars(), 0, b.getUsedSize());
- b = b.getNext();
- }
- }
-
- public void printTo(ServletOutputStream outputStream) throws IOException {
- CharBuffer b = firstBuffer;
-
- while (b != null) {
- outputStream.print(new String(b.getChars()));
- b = b.getNext();
- }
- }
-
- /**
- * Returns instance of FastBufferOutputStream containing all data written to this writer.
- *
- * @param encoding
- * @return
- * @throws UnsupportedEncodingException
- */
- public FastBufferOutputStream convertToOutputStream(String encoding) throws UnsupportedEncodingException {
- CharBuffer c = firstBuffer;
- ByteBuffer first = c.toByteBuffer(encoding);
- ByteBuffer b = first;
-
- while (c != null) {
- c = c.getNext();
-
- if (c == null) {
- break;
- }
-
- ByteBuffer n = c.toByteBuffer(encoding);
-
- b.setNext(n);
- b = n;
- }
-
- return new FastBufferOutputStream(first);
- }
-
- /**
- * Returns instance of FastBufferOutputStream containing all data written to this writer.
- *
- * @return
- */
- public FastBufferOutputStream convertToOutputStream() {
- CharBuffer c = firstBuffer;
- ByteBuffer first = c.toByteBuffer();
- ByteBuffer b = first;
-
- while (c != null) {
- c = c.getNext();
-
- if (c == null) {
- break;
- }
-
- ByteBuffer n = c.toByteBuffer();
-
- b.setNext(n);
- b = n;
- }
-
- return new FastBufferOutputStream(first);
- }
-
- /**
- * Resets writer to empty state
- *
- * @since 3.3.0
- */
- public void reset() {
- this.firstBuffer.reset();
- this.lastBuffer = this.firstBuffer;
- this.length = 0;
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,562 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.io;
-
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.ext.LexicalHandler;
-import org.xml.sax.helpers.AttributesImpl;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- * @author shura
- * <p/>
- * Realization of Faces <code>ResponseWriter</code> for Cocoon Environment.
- * Use ONLY Markup-specific calls , send it as SAX events to
- * <code>XMLConsumer</code> Use "State" pattern for control of events flow.
- * TODO - implement namespace capabilites
- */
-public class SAXResponseWriter extends ResponseWriter {
-
- /**
- * As we in XML framework, only UTF-8 supported for
- * <code>CHARTER_ENCODING</code>
- */
- private static final String CHARTER_ENCODING = "UTF-8";
-
- /**
- * As we in XML framework, only xml supported for <code>CONTENT_TYPE</code>
- */
- private static final String CONTENT_TYPE = "text/xml";
- private String namespaceURI = "http://www.w3.org/1999/xhtml";
- private LexicalHandler xmlLexicalHandler = null;
- private AttributesImpl attributes;
- private XMLResponseWriterState cdataState;
- private String element;
-
- /**
- * State after startElement. Collect Attributes for SAX startElement
- * <code>elementState</code>
- */
- private XMLResponseWriterState elementState;
-
- /**
- * State in normal document <code>inDocumentState</code>
- */
- private XMLResponseWriterState inDocumentState;
-
- /**
- * Before StartDocument or after EndDocument <code>notDocumentState</code>
- */
- private XMLResponseWriterState notDocumentState;
- private XMLResponseWriterState state;
-
- /**
- * Hold Cocoon Generator XML <code>consumer</code>
- */
- private ContentHandler xmlConsumer;
-
- /**
- * @param consumer -
- * SAX events receiver for Cocoon pipeline.
- */
- public SAXResponseWriter(ContentHandler consumer) {
- super();
- this.xmlConsumer = consumer;
-
- if (consumer instanceof LexicalHandler) {
- xmlLexicalHandler = (LexicalHandler) consumer;
- }
-
- // Initialise states. May be must implemented in static block ?
- this.notDocumentState = new NotDocumentState();
-
- // inside document. allow any events exclude attributes and
- // startDocument.
- this.inDocumentState = new InDocumentState();
- this.cdataState = new CDATAState();
-
- // In element, collect attributes ...
- this.elementState = new ElementState();
- this.state = notDocumentState;
- }
-
- public ContentHandler getXmlConsumer() {
- return xmlConsumer;
- }
-
- /**
- * @return Returns the namespaceURI.
- */
- public String getNamespaceURI() {
- return namespaceURI;
- }
-
- /**
- * @param namespaceURI The namespaceURI to set.
- */
- public void setNamespaceURI(String namespaceURI) {
- this.namespaceURI = namespaceURI;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#getContentType()
- */
- public String getContentType() {
- return CONTENT_TYPE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#getCharacterEncoding()
- */
- public String getCharacterEncoding() {
- return CHARTER_ENCODING;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.Flushable#flush()
- */
- public void flush() throws IOException {
-
- // DO NOTHING...
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#startDocument()
- */
- public void startDocument() throws IOException {
- state.startDocument();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#endDocument()
- */
- public void endDocument() throws IOException {
- state.endDocument();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#startElement(java.lang.String,
- * javax.faces.component.UIComponent)
- */
- public void startElement(String name, UIComponent component) throws IOException {
- state.startElement(name, component);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#endElement(java.lang.String)
- */
- public void endElement(String name) throws IOException {
- state.endElement(name);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#writeAttribute(java.lang.String,
- * java.lang.Object, java.lang.String)
- */
- public void writeAttribute(String name, Object value, String property) throws IOException {
- state.writeAttribute(name, value, property);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#writeURIAttribute(java.lang.String,
- * java.lang.Object, java.lang.String)
- */
- public void writeURIAttribute(String name, Object value, String property) throws IOException {
- state.writeURIAttribute(name, value, property);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#writeComment(java.lang.Object)
- */
- public void writeComment(Object comment) throws IOException {
- state.writeComment(comment);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#writeText(java.lang.Object,
- * java.lang.String)
- */
- public void writeText(Object text, String property) throws IOException {
- state.writeText(text, property);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#writeText(char[], int, int)
- */
- public void writeText(char[] text, int off, int len) throws IOException {
- state.writeText(text, off, len);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#cloneWithWriter(java.io.Writer)
- */
- public ResponseWriter cloneWithWriter(Writer writer) {
-
- // TODO as used XML consumer to get sax Events, we simple return current
- // instance.
- // if will used wrapper to combine XML Consumer with plain Servlet
- // responce writer, must
- // perform real clone ...
- // We can use org.apache.cocoon.xml.SaxBuffer;
- return this;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.Writer#write(char[], int, int)
- */
- public void write(char[] cbuf, int off, int len) throws IOException {
- state.writeText(cbuf, off, len);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.Closeable#close()
- */
- public void close() throws IOException {
-
- // TODO Auto-generated method stub
- }
-
- /**
- * @author shura
- * <p/>
- * CDATA section. allow regular write() functions, write any text.
- */
- private final class CDATAState extends XMLResponseWriterState {
- void flushCDATA() throws IOException {
-
- // try {
- // xmlConsumer.endCDATA();
- // } catch (SAXException e) {
- // throw new IOException("Exception in endCDATA: "+ e.getMessage());
- // }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#endDocument()
- */
- void endDocument() throws IOException {
- flushCDATA();
- state = inDocumentState;
- state.endDocument();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#endElement(java.lang.String)
- */
- void endElement(String name) throws IOException {
- flushCDATA();
- state = inDocumentState;
- state.endElement(name);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#startElement(java.lang.String,
- * javax.faces.component.UIComponent)
- */
- void startElement(String name, UIComponent component) throws IOException {
- flushCDATA();
- element = name;
- attributes = new AttributesImpl();
- state = elementState;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeComment(java.lang.Object)
- */
- void writeComment(Object comment) throws IOException {
- flushCDATA();
- state = inDocumentState;
- state.writeComment(comment);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(char[],
- * int, int)
- */
- void writeText(char[] text, int off, int len) throws IOException {
- try {
- xmlConsumer.characters(text, off, len);
- } catch (SAXException e) {
- throw new IOException("Sax exceptions in writeText: " + e.getMessage());
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(java.lang.Object,
- * java.lang.String)
- */
- void writeText(Object text, String property) throws IOException {
- writeText(text.toString().toCharArray(), 0, text.toString().length());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#write(char[],
- * int, int)
- */
- void write(char[] cbuf, int off, int len) throws IOException {
- writeText(cbuf, off, len);
- }
- }
-
- /**
- * @author shura State in element declsration. Collect attributes, on any
- * other eventss - generate SAX startElement()
- */
- private final class ElementState extends XMLResponseWriterState {
-
- /**
- * Generate SAX StartElement event
- *
- * @throws IOException
- */
- void flushElement() throws IOException {
- try {
- xmlConsumer.startElement(getNamespaceURI(), element, element, attributes);
- } catch (SAXException e) {
- throw new IOException("Exception in startElement: " + e.getMessage());
- } finally {
- element = null;
- attributes = null;
- }
- }
-
- void writeAttribute(String name, Object value, String property) throws IOException {
- attributes.addAttribute(getNamespaceURI(), name, name, "id".equalsIgnoreCase(name) ? "ID" : "CDATA",
- value.toString());
- }
-
- void writeURIAttribute(String name, Object value, String property) throws IOException {
- String uri = value.toString();
-
- // TODO - perform encodeActionURL() or ???
- attributes.addAttribute(getNamespaceURI(), name, name, "CDATA", uri);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#endElement(java.lang.String)
- */
- void endElement(String name) throws IOException {
-
- //
- flushElement();
- state = inDocumentState;
- state.endElement(name);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#startElement(java.lang.String,
- * javax.faces.component.UIComponent)
- */
- void startElement(String name, UIComponent component) throws IOException {
-
- //
- flushElement();
- element = name;
- attributes = new AttributesImpl();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeComment(java.lang.Object)
- */
- void writeComment(Object comment) throws IOException {
-
- // TODO Auto-generated method stub
- flushElement();
- state = inDocumentState;
- state.writeComment(comment);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(char[],
- * int, int)
- */
- void writeText(char[] text, int off, int len) throws IOException {
-
- // TODO Auto-generated method stub
- flushElement();
- state = cdataState;
- state.writeText(text, off, len);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(java.lang.Object,
- * java.lang.String)
- */
- void writeText(Object text, String property) throws IOException {
-
- // TODO Auto-generated method stub
- flushElement();
- state = cdataState;
- state.writeText(text, property);
- }
- }
-
- /**
- * @author shura
- * <p/>
- * State in regular document. Disabled attributes & startDocument.
- */
- private final class InDocumentState extends XMLResponseWriterState {
- void startElement(String name, UIComponent component) {
- element = name;
- attributes = new AttributesImpl();
- state = elementState;
- }
-
- void writeComment(Object comment) throws IOException {
- String remark = comment.toString();
-
- try {
- xmlLexicalHandler.comment(remark.toCharArray(), 0, remark.length());
- } catch (SAXException e) {
- throw new IOException("Comment SAX exception :" + e.getMessage());
- }
- }
-
- void writeText(Object o, String property) throws IOException {
- writeText(o.toString().toCharArray(), 0, o.toString().length());
- }
-
- void writeText(char[] text, int start, int lenght) throws IOException {
-
- // try {
- // xmlConsumer.startCDATA();
- // } catch (SAXException e) {
- // throw new IOException("Sax exceptions in writeText: "+
- // e.getMessage());
- // } finally {
- state = cdataState;
-
- // }
- state.writeText(text, start, lenght);
- }
-
- void endElement(String name) throws IOException {
- try {
- xmlConsumer.endElement(getNamespaceURI(), name, name);
- } catch (SAXException e) {
- throw new IOException("Sax exceptions in endElement: " + e.getMessage());
- }
- }
-
- void endDocument() throws IOException {
- try {
- xmlConsumer.endDocument();
- } catch (SAXException e) {
- throw new IOException("Sax exceptions in endDocument" + e.getMessage());
- } finally {
-
- // after endDocument all events disabled ...
- state = new XMLResponseWriterState();
- }
- }
- }
-
-
- // Private classes
-
- /**
- * @author shura
- * <p/>
- * state before startDocument - only allow startDocument.
- */
- private final class NotDocumentState extends XMLResponseWriterState {
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cocoon.components.faces.context.XMLResponseWriterState#startDocument()
- */
- void startDocument() throws IOException {
- try {
-
- //
- xmlConsumer.startDocument();
- } catch (SAXException e) {
-
- //
- throw new IOException("StartDocument SAX exception :" + e.getMessage());
- } finally {
- state = inDocumentState;
- }
- }
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,127 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.io;
-
-import javax.faces.component.UIComponent;
-import java.io.IOException;
-
-/**
- * @author shura Class to implement state pattern for
- * <code>ResponseWriter</code> Real states must extend this. By
- * default, block any events, ignore output.
- */
-class XMLResponseWriterState {
-
- // private ResponseWriter writer;
-
- /**
- * @throws java.io.IOException
- */
- void endDocument() throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param name
- * @throws java.io.IOException
- */
- void endElement(String name) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @throws java.io.IOException
- */
- void startDocument() throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param name
- * @param component
- * @throws java.io.IOException
- */
- void startElement(String name, UIComponent component) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param name
- * @param value
- * @param property
- * @throws java.io.IOException
- */
- void writeAttribute(String name, Object value, String property) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param comment
- * @throws java.io.IOException
- */
- void writeComment(Object comment) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param text
- * @param off
- * @param len
- * @throws java.io.IOException
- */
- void writeText(char[] text, int off, int len) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param text
- * @param property
- * @throws java.io.IOException
- */
- void writeText(Object text, String property) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param name
- * @param value
- * @param property
- * @throws java.io.IOException
- */
- void writeURIAttribute(String name, Object value, String property) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * Main hook for realise <code>Writer</code>. In document writed as
- * comment, outside of document do nothing ....
- *
- * @param cbuf
- * @param off
- * @param len
- * @throws IOException
- */
- void write(char[] cbuf, int off, int len) throws IOException {
-
- // DO NOTHING
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/package-info.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/package-info.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/package-info.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,4 +0,0 @@
-/**
- * Implementation of I/O streams based on buffers
- */
-package org.ajax4jsf.io;
Deleted: trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java
===================================================================
--- trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,84 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-
-package org.ajax4jsf.io;
-
-import junit.framework.TestCase;
-
-import org.ajax4jsf.io.ByteBuffer;
-import org.ajax4jsf.io.FastBufferOutputStream;
-
-/**
- * @author Nick Belaevski
- * @since 3.3.0
- */
-public class FastBufferOutputStreamTest extends TestCase {
-
- /**
- * Test method for {@link org.ajax4jsf.io.FastBufferOutputStream#reset()}.
- */
- public void testResetOneBuffer() throws Exception {
- FastBufferOutputStream stream = new FastBufferOutputStream(256);
-
- for (int i = 0; i < 255; i++) {
- stream.write(i);
- }
-
- assertEquals(255, stream.getLength());
-
- ByteBuffer firstBuffer = stream.getFirstBuffer();
-
- assertNull(firstBuffer.getNext());
- assertNull(firstBuffer.getPrevious());
- stream.reset();
- assertEquals(0, stream.getLength());
- firstBuffer = stream.getFirstBuffer();
- assertEquals(0, firstBuffer.getUsedSize());
- assertNull(firstBuffer.getNext());
- assertNull(firstBuffer.getPrevious());
- }
-
- /**
- * Test method for {@link org.ajax4jsf.io.FastBufferOutputStream#reset()}.
- */
- public void testResetTwoBuffers() throws Exception {
- FastBufferOutputStream stream = new FastBufferOutputStream(256);
-
- for (int i = 0; i < 257; i++) {
- stream.write(i);
- }
-
- assertEquals(257, stream.getLength());
-
- ByteBuffer firstBuffer = stream.getFirstBuffer();
-
- assertNotNull(firstBuffer.getNext());
- assertNull(firstBuffer.getPrevious());
- stream.reset();
- assertEquals(0, stream.getLength());
- firstBuffer = stream.getFirstBuffer();
- assertEquals(0, firstBuffer.getUsedSize());
- assertNull(firstBuffer.getNext());
- assertNull(firstBuffer.getPrevious());
- }
-}
Deleted: trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java
===================================================================
--- trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,118 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-
-package org.ajax4jsf.io;
-
-import junit.framework.TestCase;
-
-import org.ajax4jsf.io.CharBuffer;
-import org.ajax4jsf.io.FastBufferReader;
-import org.ajax4jsf.io.FastBufferWriter;
-
-/**
- * @author Nick Belaevski
- * @since 3.3.0
- */
-public class FastBufferWriterTest extends TestCase {
-
- /**
- * Test method for {@link org.ajax4jsf.io.FastBufferWriter#reset()}.
- */
- public void testResetOneBuffer() throws Exception {
- FastBufferWriter stream = new FastBufferWriter(256);
-
- for (int i = 0; i < 255; i++) {
- stream.write(i);
- }
-
- assertEquals(255, stream.getLength());
-
- CharBuffer firstBuffer = stream.getFirstBuffer();
-
- assertNull(firstBuffer.getNext());
- assertNull(firstBuffer.getPrevious());
- stream.reset();
- assertEquals(0, stream.getLength());
- firstBuffer = stream.getFirstBuffer();
- assertEquals(0, firstBuffer.getUsedSize());
- assertNull(firstBuffer.getNext());
- assertNull(firstBuffer.getPrevious());
- }
-
- /**
- * Test method for {@link org.ajax4jsf.io.FastBufferWriter#reset()}.
- */
- public void testResetTwoBuffers() throws Exception {
- FastBufferWriter stream = new FastBufferWriter(256);
-
- for (int i = 0; i < 257; i++) {
- stream.write(i);
- }
-
- assertEquals(257, stream.getLength());
-
- CharBuffer firstBuffer = stream.getFirstBuffer();
-
- assertNotNull(firstBuffer.getNext());
- assertNull(firstBuffer.getPrevious());
- stream.reset();
- assertEquals(0, stream.getLength());
- firstBuffer = stream.getFirstBuffer();
- assertEquals(0, firstBuffer.getUsedSize());
- assertNull(firstBuffer.getNext());
- assertNull(firstBuffer.getPrevious());
- }
-
- public void testCompact() throws Exception {
- int itemsTowWrite = 16384 + 16000;
- FastBufferWriter writer = new FastBufferWriter(16384);
-
- for (int i = 0; i < itemsTowWrite; i++) {
- writer.write(i);
- }
-
- writer.close();
-
- CharBuffer firstBuffer = writer.getFirstBuffer();
-
- assertNotNull(firstBuffer);
-
- CharBuffer nextBuffer = firstBuffer.getNext();
-
- assertNotNull(nextBuffer);
- assertNull(nextBuffer.getNext());
- assertTrue(firstBuffer.getUsedSize() == firstBuffer.getCacheSize());
- assertTrue(nextBuffer.getUsedSize() < nextBuffer.getCacheSize());
- firstBuffer.compact();
- assertTrue(firstBuffer.getUsedSize() == firstBuffer.getCacheSize());
- assertTrue(nextBuffer.getUsedSize() == nextBuffer.getCacheSize());
-
- FastBufferReader reader = new FastBufferReader(firstBuffer);
-
- for (int i = 0; i < itemsTowWrite; i++) {
- assertEquals(i, reader.read());
- }
-
- reader.close();
- }
-}
Deleted: trunk/core/impl/src/test/java/org/ajax4jsf/io/Test.java
===================================================================
--- trunk/core/impl/src/test/java/org/ajax4jsf/io/Test.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/test/java/org/ajax4jsf/io/Test.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -1,340 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-
-package org.ajax4jsf.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import org.junit.Ignore;
-
-@Ignore
-public final class Test {
- private static final int ARRAY_LENGTH = 27;
- private static final int READ_LENGTH = 22;
- private static final int READ_OFF = 4;
- private static final boolean OUT_STRING = true;
- private static final boolean BUILD_STRING = false;
-
- private Test() {}
-
- static void testStreams() throws IOException {
- String s = "This is a senseless text to test streams.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- byte[] bytes = s.getBytes();
- FastBufferOutputStream output = new FastBufferOutputStream(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- FastBufferInputStream input = new FastBufferInputStream(output);
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- byte[] bs = new byte[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- System.out.println("Length=" + output.getLength());
- }
- }
-
- static void testStandardStreams() throws IOException {
- String s = "This is a senseless text to test streams.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- byte[] bytes = s.getBytes();
- ByteArrayOutputStream output = new ByteArrayOutputStream(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- byte[] bs = new byte[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- static void testReaders() throws IOException {
- String s = "This is a senseless text to test readers.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- char[] bytes = s.toCharArray();
- FastBufferWriter output = new FastBufferWriter(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- FastBufferReader input = new FastBufferReader(output);
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- char[] bs = new char[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- static void testStandardReaders() throws IOException {
- String s = "This is a senseless text to test readers.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- char[] bytes = s.toCharArray();
- StringWriter output = new StringWriter(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- StringReader input = new StringReader(output.toString());
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- char[] bs = new char[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- static void testTransitionFromWriterToStream() throws IOException {
- String s = "This is a senseless text to test transform from writer to stream.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- char[] bytes = s.toCharArray();
- FastBufferWriter output = new FastBufferWriter(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- FastBufferOutputStream output2 = output.convertToOutputStream("UTF-8");
- FastBufferInputStream input = new FastBufferInputStream(output2);
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- byte[] bs = new byte[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- static void testStandardTransitionFromWriterToStream() throws IOException {
- String s = "This is a senseless text to test transform from writer to stream.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- char[] bytes = s.toCharArray();
- StringWriter output = new StringWriter(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- String str = output.toString();
- ByteArrayInputStream input = new ByteArrayInputStream(str.getBytes());
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- byte[] bs = new byte[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- static void testTransitionFromStreamToWriter() throws IOException {
- String s = "This is a senseless text to test transform from stream to writer.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- byte[] bytes = s.getBytes();
- FastBufferOutputStream output = new FastBufferOutputStream(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- FastBufferWriter output2 = output.convertToWriter("UTF-8");
- FastBufferReader input = new FastBufferReader(output2);
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- char[] bs = new char[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- long t = System.currentTimeMillis();
-
- try {
- for (int i = 0; i < 10; i++) {
-
-// testStreams();
-// testStandardStreams();
-// testReaders();
-// testStandardReaders();
-// testTransitionFromWriterToStream();
- testStandardTransitionFromWriterToStream();
-
-// testTransitionFromStreamToWriter();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- long dt = System.currentTimeMillis() - t;
-
- System.out.println(dt);
- }
-}
Modified: trunk/core/impl/src/test/java/org/richfaces/cache/JBossCacheTest.java
===================================================================
--- trunk/core/impl/src/test/java/org/richfaces/cache/JBossCacheTest.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/test/java/org/richfaces/cache/JBossCacheTest.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -23,7 +23,6 @@
package org.richfaces.cache;
-import org.richfaces.cache.JBossCacheCacheFactory;
/**
* @author Nick Belaevski
Modified: trunk/core/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java
===================================================================
--- trunk/core/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java 2011-04-21 10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java 2011-04-21 12:16:50 UTC (rev 22435)
@@ -226,7 +226,7 @@
assertTrue(resource.userAgentNeedsUpdate(facesContext));
}
- private static abstract class AbstractTestResource extends AbstractCacheableResource {
+ private abstract static class AbstractTestResource extends AbstractCacheableResource {
@Override
public String toString() {
return "mock";
13 years, 8 months
JBoss Rich Faces SVN: r22434 - in modules/tests/metamer/trunk/application/src/main: java/org/richfaces/tests/metamer/validation and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: jjamrich
Date: 2011-04-21 06:26:42 -0400 (Thu, 21 Apr 2011)
New Revision: 22434
Added:
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichMessagesBean.properties
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessageBean.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessagesBean.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/validation/MultipleValidationRulesBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/csv.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsfValidator.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsr303.xhtml
Log:
Add support to verify globalOnly attribute
There is related JIRA: https://issues.jboss.org/browse/RF-7351.
Problem with 'globalOnly' parameter is that it is incompatible with
'for', so there are 2 instances of rich:messsages components.
Add new button for generate FacesMessage without bind to any component
(global message)
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessageBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessageBean.java 2011-04-20 13:29:05 UTC (rev 22433)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessageBean.java 2011-04-21 10:26:42 UTC (rev 22434)
@@ -21,6 +21,8 @@
*******************************************************************************/
package org.richfaces.tests.metamer.bean;
+import java.io.Serializable;
+
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@@ -38,8 +40,10 @@
*/
@ManagedBean(name = "richMessageBean")
@ViewScoped
-public class RichMessageBean {
+public class RichMessageBean implements Serializable {
+ /** Generated UID */
+ private static final long serialVersionUID = -5058242586244822846L;
private static Logger logger;
private Attributes attributes;
private String simpleInput1;
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessagesBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessagesBean.java 2011-04-20 13:29:05 UTC (rev 22433)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessagesBean.java 2011-04-21 10:26:42 UTC (rev 22434)
@@ -21,9 +21,14 @@
*******************************************************************************/
package org.richfaces.tests.metamer.bean;
+import java.io.Serializable;
+
import javax.annotation.PostConstruct;
+import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
import org.richfaces.component.UIRichMessages;
import org.richfaces.tests.metamer.Attributes;
@@ -38,8 +43,10 @@
*/
@ManagedBean(name = "richMessagesBean")
@ViewScoped
-public class RichMessagesBean {
+public class RichMessagesBean implements Serializable {
+ /** Generated UID */
+ private static final long serialVersionUID = 4893769498631480379L;
private static Logger logger;
private Attributes attributes;
@@ -52,11 +59,25 @@
logger.info("initializing bean " + getClass().getName());
attributes = Attributes.getComponentAttributesFromFacesConfig(UIRichMessages.class, getClass());
+ simpleInput1 = "10";
+ simpleInput2 = "10";
+
attributes.setAttribute("ajaxRendered", true);
attributes.setAttribute("rendered", true);
attributes.setAttribute("for", "simpleInput1");
attributes.setAttribute("showSummary", true);
}
+
+ public void generateFacesError(ActionEvent event) {
+
+ logger.info(" ### Just called generateFacesError()");
+
+ FacesContext.getCurrentInstance().addMessage(null,
+ new FacesMessage(FacesMessage.SEVERITY_ERROR, "Generated error message", "Generated error message"));
+
+ FacesContext.getCurrentInstance().addMessage(null,
+ new FacesMessage(FacesMessage.SEVERITY_WARN, "Generated warning message", "Generated warning message"));
+ }
public Attributes getAttributes() {
return attributes;
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/validation/MultipleValidationRulesBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/validation/MultipleValidationRulesBean.java 2011-04-20 13:29:05 UTC (rev 22433)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/validation/MultipleValidationRulesBean.java 2011-04-21 10:26:42 UTC (rev 22434)
@@ -27,7 +27,9 @@
import javax.validation.constraints.Min;
/**
- * Simple bean with property with more than one validation
+ * Simple bean with property with more than one validation.
+ * This is not very logic validation, but its useful for testing
+ * rich:messages component - where need more validation messages per input
*
* @author <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
* @version $Revision$
@@ -54,7 +56,7 @@
@Override
public String getDescription() {
- return "Integer between 5 and 150, but at less than 3 digits";
+ return "Integer between 5 and 150, but less than 3 digits";
}
@Override
Added: modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichMessagesBean.properties
===================================================================
--- modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichMessagesBean.properties (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichMessagesBean.properties 2011-04-21 10:26:42 UTC (rev 22434)
@@ -0,0 +1,3 @@
+attr.for.simpleInput1=simpleInput1
+attr.for.simpleInput2=simpleInput2
+attr.for.null=
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/csv.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/csv.xhtml 2011-04-20 13:29:05 UTC (rev 22433)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/csv.xhtml 2011-04-21 10:26:42 UTC (rev 22434)
@@ -61,8 +61,26 @@
<input id="setCorrectValuesButton" type="button" value="set correct values" onclick="setCorrectValues()"/>
<input id="setWrongValuesButton" type="button" value="set wrong values" onclick="setWrongValues()"/>
- <rich:messages id="msgs"
+ <fieldset title="Msgs1 - with for attribute" >
+ <legend>Messages1 - with 'for' attribute</legend>
+ <rich:messages id="msgs1"
for="#{richMessagesBean.attributes['for'].value}"
+ ajaxRendered="#{richMessagesBean.attributes['ajaxRendered'].value}"
+ keepTransient="#{richMessagesBean.attributes['keepTransient'].value}"
+ rendered="#{richMessagesBean.attributes['rendered'].value}"
+ showDetail="#{richMessagesBean.attributes['showDetail'].value}"
+ showSummary="#{richMessagesBean.attributes['showSummary'].value}"
+ style="#{richMessagesBean.attributes['style'].value}"
+ styleClass="#{richMessagesBean.attributes['styleClass'].value}"
+ title="#{richMessagesBean.attributes['title'].value}"
+ />
+ </fieldset>
+
+ <br/>
+
+ <fieldset title="Msgs2 - with globalOnly attribute">
+ <legend>Messages2 - without 'for' but 'globalOnly' attribute instead</legend>
+ <rich:messages id="msgs2"
ajaxRendered="#{richMessagesBean.attributes['ajaxRendered'].value}"
globalOnly="#{richMessagesBean.attributes['globalOnly'].value}"
keepTransient="#{richMessagesBean.attributes['keepTransient'].value}"
@@ -72,7 +90,9 @@
style="#{richMessagesBean.attributes['style'].value}"
styleClass="#{richMessagesBean.attributes['styleClass'].value}"
title="#{richMessagesBean.attributes['title'].value}"
- />
+ />
+ </fieldset>
+
<h:panelGrid columns="3">
<h:outputLabel for="simpleInput1" value="#{multipleValidationRulesBean.description}" />
<h:inputText id="simpleInput1" value="#{multipleValidationRulesBean.value}" label="Input 1"
@@ -93,9 +113,11 @@
<h:commandButton id="hButton" value="h:commandButton" style="margin-right: 10px;"/>
<a4j:commandButton id="a4jButton" value="a4j:commandButton"/>
+ <a4j:commandButton id="generateMsgsBtn" value="Generate Msgs"
+ actionListener="#{richMessagesBean.generateFacesError}" />
<br/>
- <rich:messages id="msgs2" />
+ <rich:messages id="msgs" />
</ui:define>
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsfValidator.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsfValidator.xhtml 2011-04-20 13:29:05 UTC (rev 22433)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsfValidator.xhtml 2011-04-21 10:26:42 UTC (rev 22434)
@@ -56,8 +56,26 @@
<input id="setCorrectValuesButton" type="button" value="set correct values" onclick="setCorrectValues()"/>
<input id="setWrongValuesButton" type="button" value="set wrong values" onclick="setWrongValues()"/>
- <rich:messages id="msgs"
+ <fieldset title="Msgs1 - with for attribute" >
+ <legend>Messages1 - with 'for' attribute</legend>
+ <rich:messages id="msgs1"
for="#{richMessagesBean.attributes['for'].value}"
+ ajaxRendered="#{richMessagesBean.attributes['ajaxRendered'].value}"
+ keepTransient="#{richMessagesBean.attributes['keepTransient'].value}"
+ rendered="#{richMessagesBean.attributes['rendered'].value}"
+ showDetail="#{richMessagesBean.attributes['showDetail'].value}"
+ showSummary="#{richMessagesBean.attributes['showSummary'].value}"
+ style="#{richMessagesBean.attributes['style'].value}"
+ styleClass="#{richMessagesBean.attributes['styleClass'].value}"
+ title="#{richMessagesBean.attributes['title'].value}"
+ />
+ </fieldset>
+
+ <br/>
+
+ <fieldset title="Msgs2 - with globalOnly attribute">
+ <legend>Messages2 - without 'for' but 'globalOnly' attribute instead</legend>
+ <rich:messages id="msgs2"
ajaxRendered="#{richMessagesBean.attributes['ajaxRendered'].value}"
globalOnly="#{richMessagesBean.attributes['globalOnly'].value}"
keepTransient="#{richMessagesBean.attributes['keepTransient'].value}"
@@ -67,7 +85,9 @@
style="#{richMessagesBean.attributes['style'].value}"
styleClass="#{richMessagesBean.attributes['styleClass'].value}"
title="#{richMessagesBean.attributes['title'].value}"
- />
+ />
+ </fieldset>
+
<h:panelGrid columns="3">
<h:outputLabel for="simpleInput1" value="#{multipleValidationRulesBean.description}" />
<h:inputText id="simpleInput1" value="#{richMessagesBean.simpleInput1}" label="Input 1" >
@@ -88,9 +108,11 @@
<h:commandButton id="hButton" value="h:commandButton" style="margin-right: 10px;"/>
<a4j:commandButton id="a4jButton" value="a4j:commandButton"/>
+ <a4j:commandButton id="generateMsgsBtn" value="Generate Msgs"
+ actionListener="#{richMessagesBean.generateFacesError}" />
<br/>
- <rich:messages id="msgs2" />
+ <rich:messages id="msgs" />
</ui:define>
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsr303.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsr303.xhtml 2011-04-20 13:29:05 UTC (rev 22433)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsr303.xhtml 2011-04-21 10:26:42 UTC (rev 22434)
@@ -60,9 +60,29 @@
<input id="setCorrectValuesButton" type="button" value="set correct values" onclick="setCorrectValues()"/>
<input id="setWrongValuesButton" type="button" value="set wrong values" onclick="setWrongValues()"/>
+
+ <br/>
- <rich:messages id="msgs"
+ <fieldset title="Msgs1 - with for attribute" >
+ <legend>Messages1 - with 'for' attribute</legend>
+ <rich:messages id="msgs1"
for="#{richMessagesBean.attributes['for'].value}"
+ ajaxRendered="#{richMessagesBean.attributes['ajaxRendered'].value}"
+ keepTransient="#{richMessagesBean.attributes['keepTransient'].value}"
+ rendered="#{richMessagesBean.attributes['rendered'].value}"
+ showDetail="#{richMessagesBean.attributes['showDetail'].value}"
+ showSummary="#{richMessagesBean.attributes['showSummary'].value}"
+ style="#{richMessagesBean.attributes['style'].value}"
+ styleClass="#{richMessagesBean.attributes['styleClass'].value}"
+ title="#{richMessagesBean.attributes['title'].value}"
+ />
+ </fieldset>
+
+ <br/>
+
+ <fieldset title="Msgs2 - with globalOnly attribute">
+ <legend>Messages2 - without 'for' but 'globalOnly' attribute instead</legend>
+ <rich:messages id="msgs2"
ajaxRendered="#{richMessagesBean.attributes['ajaxRendered'].value}"
globalOnly="#{richMessagesBean.attributes['globalOnly'].value}"
keepTransient="#{richMessagesBean.attributes['keepTransient'].value}"
@@ -72,7 +92,9 @@
style="#{richMessagesBean.attributes['style'].value}"
styleClass="#{richMessagesBean.attributes['styleClass'].value}"
title="#{richMessagesBean.attributes['title'].value}"
- />
+ />
+ </fieldset>
+
<h:panelGrid columns="3">
<h:outputLabel for="simpleInput1" value="#{multipleValidationRulesBean.description}" />
<h:inputText id="simpleInput1" value="#{multipleValidationRulesBean.value}" label="Input 1"
@@ -89,9 +111,11 @@
<h:commandButton id="hButton" value="h:commandButton" style="margin-right: 10px;"/>
<a4j:commandButton id="a4jButton" value="a4j:commandButton"/>
+ <a4j:commandButton id="generateMsgsBtn" value="Generate Msgs"
+ actionListener="#{richMessagesBean.generateFacesError}" />
<br/>
- <rich:messages id="msgs2" />
+ <rich:messages id="msgs" />
</ui:define>
13 years, 8 months
JBoss Rich Faces SVN: r22433 - in sandbox/trunk/ui/notify: bom and 8 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: blabno
Date: 2011-04-20 09:29:05 -0400 (Wed, 20 Apr 2011)
New Revision: 22433
Added:
sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/package-info.java
sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/close.png
sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/notify.ecss
Removed:
sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/notify.taglib.xml
sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/notify.ecss
Modified:
sandbox/trunk/ui/notify/bom/pom.xml
sandbox/trunk/ui/notify/demo/pom.xml
sandbox/trunk/ui/notify/demo/src/main/webapp/notify.xhtml
sandbox/trunk/ui/notify/demo/src/main/webapp/notify_1.xhtml
sandbox/trunk/ui/notify/demo/src/main/webapp/notify_2.xhtml
sandbox/trunk/ui/notify/parent/pom.xml
sandbox/trunk/ui/notify/pom.xml
sandbox/trunk/ui/notify/ui/pom.xml
sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotify.java
sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotifyMessages.java
sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotifyStack.java
sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/NotifyAttributes.java
sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyMessagesRenderer.java
sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyRenderer.java
sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyStackRenderer.java
sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/jquery.pnotify.js
sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/richfaces.notify.js
Log:
Updated notify to 4.1-SNAPSHOT.
Modified: sandbox/trunk/ui/notify/bom/pom.xml
===================================================================
--- sandbox/trunk/ui/notify/bom/pom.xml 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/bom/pom.xml 2011-04-20 13:29:05 UTC (rev 22433)
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
JBoss, Home of Professional Open Source
Copyright , Red Hat, Inc. and individual contributors
by the @authors tag. See the copyright.txt in the distribution for a
@@ -26,39 +25,37 @@
<modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.richfaces</groupId>
- <artifactId>richfaces-parent</artifactId>
- <version>7</version>
- </parent>
-
- <groupId>org.richfaces.ui.notify</groupId>
- <artifactId>richfaces-ui-notify-bom</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <groupId>org.richfaces.sandbox.ui.notify</groupId>
+ <artifactId>notify-bom</artifactId>
+ <version>4.1.0-SNAPSHOT</version>
<name>Richfaces UI Components: notify bom</name>
<packaging>pom</packaging>
- <properties>
- <org.richfaces.version>4.0.0-SNAPSHOT</org.richfaces.version>
- </properties>
-
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-bom</artifactId>
- <version>${org.richfaces.version}</version>
+ <version>${project.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>richfaces-ui-notify-ui</artifactId>
+ <artifactId>notify-ui</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
+ <distributionManagement>
+ <snapshotRepository>
+ <id>bernard.labno.pl</id>
+ <name>MyCo Internal Repository</name>
+ <url>http://bernard.labno.pl/artifactory/libs-snapshot-local</url>
+ </snapshotRepository>
+ </distributionManagement>
+
</project>
Modified: sandbox/trunk/ui/notify/demo/pom.xml
===================================================================
--- sandbox/trunk/ui/notify/demo/pom.xml 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/demo/pom.xml 2011-04-20 13:29:05 UTC (rev 22433)
@@ -1,19 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
- xmlns="http://maven.apache.org/POM/4.0.0"
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.richfaces.ui.notify</groupId>
- <artifactId>richfaces-ui-notify-parent</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <groupId>org.richfaces.sandbox.ui.notify</groupId>
+ <artifactId>notify-parent</artifactId>
+ <version>4.1.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
- <groupId>org.richfaces.ui.notify</groupId>
<artifactId>notify-demo</artifactId>
- <version>4.0.0-SNAPSHOT</version>
<name>Richfaces UI Components: notify demo</name>
<packaging>war</packaging>
<build>
@@ -29,38 +26,36 @@
</plugins>
</build>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.richfaces.ui.notify</groupId>
- <artifactId>richfaces-ui-notify-bom</artifactId>
- <version>${version}</version>
- <scope>import</scope>
- <type>pom</type>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
<dependencies>
<dependency>
- <groupId>org.richfaces.ui.core</groupId>
- <artifactId>richfaces-ui-core-ui</artifactId>
+ <groupId>org.richfaces.ui</groupId>
+ <artifactId>richfaces-components-ui</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.richfaces.ui.notify</groupId>
- <artifactId>richfaces-ui-notify-ui</artifactId>
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-impl</artifactId>
+ <version>${project.version}</version>
</dependency>
-
<dependency>
- <groupId>${jsf2.api.groupid}</groupId>
- <artifactId>${jsf2.api.artifactid}</artifactId>
- <scope>provided</scope>
+ <groupId>org.richfaces.sandbox.ui.notify</groupId>
+ <artifactId>notify-ui</artifactId>
</dependency>
<dependency>
- <groupId>${jsf2.impl.groupid}</groupId>
- <artifactId>${jsf2.impl.artifactid}</artifactId>
- <scope>provided</scope>
+ <groupId>com.sun.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>com.sun.faces</groupId>
+ <artifactId>jsf-impl</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.el</groupId>
+ <artifactId>el-ri</artifactId>
+ <version>1.0</version>
+ </dependency>
</dependencies>
</project>
Modified: sandbox/trunk/ui/notify/demo/src/main/webapp/notify.xhtml
===================================================================
--- sandbox/trunk/ui/notify/demo/src/main/webapp/notify.xhtml 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/demo/src/main/webapp/notify.xhtml 2011-04-20 13:29:05 UTC (rev 22433)
@@ -22,13 +22,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:a4j="http://richfaces.org/a4j"
- xmlns:notify="http://richfaces.org/notify"
- >
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" xmlns:notify="http://richfaces.org/sandbox/notify">
<h:head>
<title>Notify sample</title>
</h:head>
@@ -52,77 +47,20 @@
<p>
Here we have notify displaying all messages (not only global).
- Severity is reflected in overriden style classes.
- </p>
+ Severity is reflected in overriden style classes. </p>
<h:form>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
- <notify:notify sticky="false" stayTime="5000"
- title="Default stack"
- text="Details of the message"
- nonblockingOpacity="0"/>
+ <notify:notify sticky="false" stayTime="5000" title="Default stack" text="Details of the message" nonblockingOpacity="0"/>
- <notify:notify title="Before stack definition"
- text="This message is defined in code before stack"
+ <notify:notify title="Before stack definition" text="This message is defined in code before stack" stack="bottomLeftStack"/>
+ <notify:notify title="Left bottom stack 2" text="This message alos should be displayed in the left bottom corner" showCloseButton="true"
stack="bottomLeftStack"/>
- <notify:notify title="Left bottom stack 2"
- text="This message alos should be displayed in the left bottom corner"
- showCloseButton="true" stack="bottomLeftStack"/>
- <notify:notifyStack id="bottomLeftStack" styleClass="bottomLeft" stackDir1="up"
- stackDir2="right" push="top">
- <notify:notify sticky="true"
- title="Left bottom stack"
- text="This message should be displayed in the left bottom corner
- and should stay until you close it"
- showCloseButton="true"/>
- <notify:notify title="Nonblocking"
- nonblocking="true"/>
+ <notify:notifyStack id="bottomLeftStack" styleClass="bottomLeft" stackDir1="up" stackDir2="right" push="top">
+ <notify:notify sticky="true" title="Left bottom stack" text="This message should be displayed in the left bottom corner
+ and should stay until you close it" showCloseButton="true"/>
+ <notify:notify title="Nonblocking" nonblocking="true"/>
</notify:notifyStack>
<notify:notifyMessages interval="1000" stack="bottomRightStack" ajaxRendered="true"/>
- <notify:notifyStack id="bottomRightStack" styleClass="bottomRight" stackDir1="up"
- stackDir2="left" push="bottom"/>
+ <notify:notifyStack id="bottomRightStack" styleClass="bottomRight" stackDir1="up" stackDir2="left" push="bottom"/>
Leave this blank for error:
<br/>
<h:outputLabel for="greeting" value="Greeting"/>
Modified: sandbox/trunk/ui/notify/demo/src/main/webapp/notify_1.xhtml
===================================================================
--- sandbox/trunk/ui/notify/demo/src/main/webapp/notify_1.xhtml 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/demo/src/main/webapp/notify_1.xhtml 2011-04-20 13:29:05 UTC (rev 22433)
@@ -22,12 +22,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:a4j="http://richfaces.org/a4j"
- xmlns:notify="http://richfaces.org/notify">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" xmlns:notify="http://richfaces.org/sandbox/notify">
<h:head>
<title>Notify sample</title>
<style type="text/css">
@@ -84,47 +80,19 @@
<ui:include src="menu.xhtml"/>
<h:form>
<a4j:outputPanel ajaxRendered="true">
- <notify:notifyStack id="customStack"
- stackDir1="#{greeter.stackDir1}"
- stackDir2="#{greeter.stackDir2}"
- push="#{greeter.stackPush}"
- styleClass="#{greeter.stackStyleClass}"
- />
- <notify:notify title="#{greeter.title}"
- text="#{greeter.text}"
- nonblocking="#{greeter.nonblocking}"
- showShadow="#{greeter.showShadow}"
- showHistory="#{greeter.showHistory}"
- showCloseButton="#{greeter.showCloseButton}"
- sticky="#{greeter.sticky}"
- stayTime="#{greeter.stayTime}"
- appearAnimation="#{greeter.appearAnimation}"
- hideAnimation="#{greeter.hideAnimation}"
- animationSpeed="#{greeter.animationSpeed}"
- nonblockingOpacity="#{greeter.nonblockingOpacity}"
- styleClass="#{greeter.styleClass}"
- stackDir1="#{greeter.stackDir1}"
- stackDir2="#{greeter.stackDir2}"
- stackPush="#{greeter.stackPush}"
- stack="customStack"
- />
+ <notify:notifyStack id="customStack" stackDir1="#{greeter.stackDir1}" stackDir2="#{greeter.stackDir2}" push="#{greeter.stackPush}"
+ styleClass="#{greeter.stackStyleClass}"/>
+ <notify:notify title="#{greeter.title}" text="#{greeter.text}" nonblocking="#{greeter.nonblocking}" showShadow="#{greeter.showShadow}"
+ showHistory="#{greeter.showHistory}" showCloseButton="#{greeter.showCloseButton}" sticky="#{greeter.sticky}"
+ stayTime="#{greeter.stayTime}" appearAnimation="#{greeter.appearAnimation}" hideAnimation="#{greeter.hideAnimation}"
+ animationSpeed="#{greeter.animationSpeed}" nonblockingOpacity="#{greeter.nonblockingOpacity}" styleClass="#{greeter.styleClass}"
+ stackDir1="#{greeter.stackDir1}" stackDir2="#{greeter.stackDir2}" stackPush="#{greeter.stackPush}" stack="customStack"/>
</a4j:outputPanel>
- <notify:notifyMessages interval="#{greeter.interval}"
- nonblocking="#{greeter.nonblocking}"
- showShadow="#{greeter.showShadow}"
- showHistory="#{greeter.showHistory}"
- showCloseButton="#{greeter.showCloseButton}"
- sticky="#{greeter.sticky}"
- stayTime="#{greeter.stayTime}"
- appearAnimation="#{greeter.appearAnimation}"
- hideAnimation="#{greeter.hideAnimation}"
- animationSpeed="#{greeter.animationSpeed}"
- nonblockingOpacity="#{greeter.nonblockingOpacity}"
- styleClass="#{greeter.styleClass}"
- stackDir1="#{greeter.stackDir1}"
- stackDir2="#{greeter.stackDir2}"
- stackPush="#{greeter.stackPush}"
- stack="customStack"/>
+ <notify:notifyMessages interval="#{greeter.interval}" nonblocking="#{greeter.nonblocking}" showShadow="#{greeter.showShadow}"
+ showHistory="#{greeter.showHistory}" showCloseButton="#{greeter.showCloseButton}" sticky="#{greeter.sticky}"
+ stayTime="#{greeter.stayTime}" appearAnimation="#{greeter.appearAnimation}" hideAnimation="#{greeter.hideAnimation}"
+ animationSpeed="#{greeter.animationSpeed}" nonblockingOpacity="#{greeter.nonblockingOpacity}" styleClass="#{greeter.styleClass}"
+ stackDir1="#{greeter.stackDir1}" stackDir2="#{greeter.stackDir2}" stackPush="#{greeter.stackPush}" stack="customStack"/>
<a4j:commandButton value="Say Hello" action="#{greeter.sayHello}" execute="@form"/>
<a4j:commandButton value="Warn me" action="#{greeter.warnMe}" execute="@form"/>
<a4j:commandButton value="Say error" action="#{greeter.sayError}" execute="@form"/>
Modified: sandbox/trunk/ui/notify/demo/src/main/webapp/notify_2.xhtml
===================================================================
--- sandbox/trunk/ui/notify/demo/src/main/webapp/notify_2.xhtml 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/demo/src/main/webapp/notify_2.xhtml 2011-04-20 13:29:05 UTC (rev 22433)
@@ -22,11 +22,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:notify="http://richfaces.org/notify">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:h="http://java.sun.com/jsf/html" xmlns:notify="http://richfaces.org/sandbox/notify">
<h:head>
<title>Notify sample</title>
<style type="text/css">
@@ -52,20 +49,9 @@
<ui:include src="menu.xhtml"/>
<p>
- Skinning. Icon, skining by message type.
- </p>
- <notify:notify title="You've got mail"
- nonblocking="#{greeter.nonblocking}"
- sticky="true"
- styleClass="mail"
- />
- <notify:notify title="You've got more mail (hides in 3sec)"
- nonblocking="true"
- sticky="false"
- styleClass="mail"
- delay="3000"
- stayTime="3000"
- />
+ Skinning. Icon, skining by message type. </p>
+ <notify:notify title="You've got mail" nonblocking="#{greeter.nonblocking}" sticky="true" styleClass="mail"/>
+ <notify:notify title="You've got more mail (hides in 3sec)" nonblocking="true" sticky="false" styleClass="mail" delay="3000" stayTime="3000"/>
<!--
TODO uncomment this once rich:insert is implemented
<rich:insert src="/notify_2.xhtml" highlight="xhtml" rendered="#{showSource!=false}"/>
Modified: sandbox/trunk/ui/notify/parent/pom.xml
===================================================================
--- sandbox/trunk/ui/notify/parent/pom.xml 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/parent/pom.xml 2011-04-20 13:29:05 UTC (rev 22433)
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
JBoss, Home of Professional Open Source
Copyright , Red Hat, Inc. and individual contributors
by the @authors tag. See the copyright.txt in the distribution for a
@@ -28,31 +27,29 @@
<parent>
<groupId>org.richfaces</groupId>
- <artifactId>richfaces-parent</artifactId>
- <version>7</version>
+ <artifactId>richfaces-root-parent</artifactId>
+ <version>4.1.0-SNAPSHOT</version>
</parent>
- <groupId>org.richfaces.ui.notify</groupId>
- <artifactId>richfaces-ui-notify-parent</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <groupId>org.richfaces.sandbox.ui.notify</groupId>
+ <artifactId>notify-parent</artifactId>
<name>Richfaces UI Components: notify parent</name>
<packaging>pom</packaging>
<properties>
<richfaces.checkstyle.version>1</richfaces.checkstyle.version>
- <org.richfaces.cdk.version>4.0.0-SNAPSHOT</org.richfaces.cdk.version>
+ <org.richfaces.cdk.version>4.1.0-SNAPSHOT</org.richfaces.cdk.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
- <groupId>org.richfaces.ui.notify</groupId>
- <artifactId>richfaces-ui-notify-bom</artifactId>
+ <groupId>org.richfaces.sandbox.ui.notify</groupId>
+ <artifactId>notify-bom</artifactId>
<version>${project.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
-
<dependency>
<groupId>org.richfaces.cdk</groupId>
<artifactId>annotations</artifactId>
@@ -86,98 +83,24 @@
<version>2.0-alpha-4</version>
<extensions>true</extensions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0-beta-1</version>
+ <configuration>
+ <fail>false</fail>
+ </configuration>
+ </plugin>
</plugins>
</pluginManagement>
-
- <plugins>
- <plugin>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <dependencies>
- <dependency>
- <groupId>org.richfaces</groupId>
- <artifactId>richfaces-build-checkstyle</artifactId>
- <version>${richfaces.checkstyle.version}</version>
- </dependency>
- </dependencies>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <version>1.0-beta-1</version>
- <configuration>
- <fail>false</fail>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.richfaces.cdk</groupId>
- <artifactId>maven-cdk-plugin</artifactId>
- <configuration>
- <library>
- <prefix>org.richfaces</prefix>
- <taglib>
- <uri>http://richfaces.org/notify</uri>
- <shortName>notify</shortName>
- <displayName>notify components tags</displayName>
- </taglib>
- </library>
- </configuration>
- <executions>
- <execution>
- <id>cdk-generate-sources</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>generate</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
</build>
- <profiles>
- <profile>
- <id>release</id>
+ <distributionManagement>
+ <snapshotRepository>
+ <id>bernard.labno.pl</id>
+ <name>MyCo Internal Repository</name>
+ <url>http://bernard.labno.pl/artifactory/libs-snapshot-local</url>
+ </snapshotRepository>
+ </distributionManagement>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <configuration>
- <javadocVersion>1.5</javadocVersion>
- <aggregate>true</aggregate>
- </configuration>
- <executions>
- <execution>
- <id>generate-javadoc</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <configuration>
- <aggregate>true</aggregate>
- </configuration>
- <executions>
- <execution>
- <id>generate-source</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
</project>
Modified: sandbox/trunk/ui/notify/pom.xml
===================================================================
--- sandbox/trunk/ui/notify/pom.xml 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/pom.xml 2011-04-20 13:29:05 UTC (rev 22433)
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
+<?xml version="1.0" encoding="UTF-8"?><!--
JBoss, Home of Professional Open Source
Copyright , Red Hat, Inc. and individual contributors
by the @authors tag. See the copyright.txt in the distribution for a
@@ -26,14 +25,13 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.richfaces</groupId>
- <artifactId>richfaces-parent</artifactId>
- <version>9</version>
+ <groupId>org.richfaces.sandbox.ui.notify</groupId>
+ <artifactId>notify-parent</artifactId>
+ <version>4.1.0-SNAPSHOT</version>
+ <relativePath>parent/pom.xml</relativePath>
</parent>
- <groupId>org.richfaces.ui.notify</groupId>
<artifactId>notify-aggregator</artifactId>
- <version>4.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Richfaces UI Components: notify Aggregator</name>
@@ -44,37 +42,39 @@
<module>demo</module>
</modules>
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-release-plugin</artifactId>
- <configuration>
- <!-- The dist requires clean install for prepare -->
- <preparationGoals>clean install</preparationGoals>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-release-plugin</artifactId>
- <configuration>
- <!-- The dist requires clean install for prepare -->
- <preparationGoals>clean install</preparationGoals>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <version>1.0-beta-1</version>
- <configuration>
- <fail>false</fail>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <profiles>
+ <profile>
+ <id>cli</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.twdata.maven</groupId>
+ <artifactId>maven-cli-plugin</artifactId>
+ <version>1.0.6-SNAPSHOT</version>
+ <configuration>
+ <userAliases>
+ <ui>notify-ui clean install</ui>
+ <demo>notify-demo clean package</demo>
+ </userAliases>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
-</project>
\ No newline at end of file
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/richfaces/sandbox/trunk/ui/notify</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/sandbox/trunk/ui/notify</developerConnection>
+ <url>http://fisheye.jboss.org/browse/richfaces/</url>
+ </scm>
+
+ <distributionManagement>
+ <snapshotRepository>
+ <id>bernard.labno.pl</id>
+ <name>MyCo Internal Repository</name>
+ <url>http://bernard.labno.pl/artifactory/libs-snapshot-local</url>
+ </snapshotRepository>
+ </distributionManagement>
+
+</project>
Modified: sandbox/trunk/ui/notify/ui/pom.xml
===================================================================
--- sandbox/trunk/ui/notify/ui/pom.xml 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/pom.xml 2011-04-20 13:29:05 UTC (rev 22433)
@@ -28,146 +28,44 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.richfaces.ui.notify</groupId>
- <artifactId>richfaces-ui-notify-parent</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <groupId>org.richfaces.sandbox.ui.notify</groupId>
+ <artifactId>notify-parent</artifactId>
+ <version>4.1.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
-
- <groupId>org.richfaces.ui.notify</groupId>
- <artifactId>richfaces-ui-notify-ui</artifactId>
+ <artifactId>notify-ui</artifactId>
<name>Richfaces UI Components: notify ui</name>
- <packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.richfaces.ui.core</groupId>
<artifactId>richfaces-ui-core-ui</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.richfaces.core</groupId>
- <artifactId>richfaces-core-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.richfaces.core</groupId>
- <artifactId>richfaces-core-impl</artifactId>
- </dependency>
- <dependency>
<groupId>org.richfaces.cdk</groupId>
<artifactId>annotations</artifactId>
- </dependency>
-
- <!-- JSF with dependencies -->
- <dependency>
- <groupId>${jsf2.api.groupid}</groupId>
- <artifactId>${jsf2.api.artifactid}</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet.jsp</groupId>
- <artifactId>jsp-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jstl</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <!-- tests -->
- <dependency>
<groupId>org.jboss.test-jsf</groupId>
<artifactId>jsf-test-stage</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.test-jsf</groupId>
- <artifactId>htmlunit-client</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.test-jsf</groupId>
- <artifactId>jsf-mock</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.richfaces.cdk</groupId>
- <artifactId>maven-cdk-plugin</artifactId>
- <version>${org.richfaces.cdk.version}</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.1</version>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>xml-maven-plugin</artifactId>
- <version>1.0-beta-2</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-archetype-plugin</artifactId>
- <version>2.0-alpha-4</version>
- <extensions>true</extensions>
- </plugin>
- </plugins>
- </pluginManagement>
-
<plugins>
<plugin>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <dependencies>
- <dependency>
- <groupId>org.richfaces</groupId>
- <artifactId>richfaces-build-checkstyle</artifactId>
- <version>${richfaces.checkstyle.version}</version>
- </dependency>
- </dependencies>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <version>1.0-beta-1</version>
- <configuration>
- <fail>false</fail>
- </configuration>
- </plugin>
-
- <plugin>
<groupId>org.richfaces.cdk</groupId>
<artifactId>maven-cdk-plugin</artifactId>
- <configuration>
- <library>
- <prefix>org.richfaces</prefix>
- <taglib>
- <uri>http://richfaces.org/notify</uri>
- <shortName>notify</shortName>
- <displayName>notify components tags</displayName>
- </taglib>
- </library>
- </configuration>
+ <version>${org.richfaces.cdk.version}</version>
<executions>
<execution>
<id>cdk-generate-sources</id>
@@ -181,48 +79,4 @@
</plugins>
</build>
- <profiles>
- <profile>
- <id>release</id>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <configuration>
- <javadocVersion>1.5</javadocVersion>
- <aggregate>true</aggregate>
- </configuration>
- <executions>
- <execution>
- <id>generate-javadoc</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <configuration>
- <aggregate>true</aggregate>
- </configuration>
- <executions>
- <execution>
- <id>generate-source</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
</project>
Modified: sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotify.java
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotify.java 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotify.java 2011-04-20 13:29:05 UTC (rev 22433)
@@ -24,26 +24,33 @@
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.renderkit.html.NotifyRenderer;
import javax.faces.component.UIComponentBase;
-@JsfComponent(tag = @Tag(name = "notify", type = TagType.Facelets))
+@JsfComponent(tag = @Tag(name = "notify", type = TagType.Facelets),
+ renderer = @JsfRenderer(family = AbstractNotify.COMPONENT_FAMILY, type = NotifyRenderer.RENDERER_TYPE))
public abstract class AbstractNotify extends UIComponentBase implements NotifyAttributes {
+// ------------------------------ FIELDS ------------------------------
- public static final String COMPONENT_TYPE = "org.richfaces.Notify";
public static final String COMPONENT_FAMILY = "org.richfaces.Notify";
+ public static final String COMPONENT_TYPE = "org.richfaces.Notify";
+
public static final double DEFAULT_NONBLOCKING_OPACITY = .2;
+// -------------------------- OTHER METHODS --------------------------
+
@Attribute
+ public abstract String getText();
+
+ @Attribute
public abstract String getTitle();
+ public abstract void setText(String text);
+
public abstract void setTitle(String summary);
-
- @Attribute
- public abstract String getText();
-
- public abstract void setText(String test);
}
Modified: sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotifyMessages.java
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotifyMessages.java 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotifyMessages.java 2011-04-20 13:29:05 UTC (rev 22433)
@@ -25,20 +25,36 @@
import org.ajax4jsf.component.AjaxOutput;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.renderkit.html.NotifyMessagesRenderer;
import javax.faces.component.UIMessages;
-@JsfComponent(tag = @Tag(name = "notifyMessages", type = TagType.Facelets))
+@JsfComponent(tag = @Tag(name = "notifyMessages", type = TagType.Facelets),
+ renderer = @JsfRenderer(family = AbstractNotifyMessages.COMPONENT_FAMILY, type = NotifyMessagesRenderer.RENDERER_TYPE),
+ attributes = {"ajax-props.xml"})
public abstract class AbstractNotifyMessages extends UIMessages implements AjaxOutput, NotifyAttributes {
+// ------------------------------ FIELDS ------------------------------
- public static final String COMPONENT_TYPE = "org.richfaces.NotifyMessages";
public static final String COMPONENT_FAMILY = "org.richfaces.Notify";
- @Attribute
- public abstract Integer getInterval();
+ public static final String COMPONENT_TYPE = "org.richfaces.NotifyMessages";
+// ------------------------ INTERFACE METHODS ------------------------
+
+
+// --------------------- Interface AjaxOutput ---------------------
+
@Attribute(defaultValue = "true")
public abstract boolean isAjaxRendered();
+
+ @Attribute
+ public abstract boolean isKeepTransient();
+
+// -------------------------- OTHER METHODS --------------------------
+
+ @Attribute
+ public abstract Integer getInterval();
}
Modified: sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotifyStack.java
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotifyStack.java 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/AbstractNotifyStack.java 2011-04-20 13:29:05 UTC (rev 22433)
@@ -24,25 +24,33 @@
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.renderkit.html.NotifyStackRenderer;
import javax.faces.component.UIComponentBase;
-@JsfComponent(tag = @Tag(name = "notifyStack", type = TagType.Facelets))
+@JsfComponent(tag = @Tag(name = "notifyStack", type = TagType.Facelets),
+ renderer = @JsfRenderer(family = AbstractNotifyStack.COMPONENT_FAMILY, type = NotifyStackRenderer.RENDERER_TYPE))
public abstract class AbstractNotifyStack extends UIComponentBase {
+// ------------------------------ FIELDS ------------------------------
- public static final String COMPONENT_TYPE = "org.richfaces.NotifyStack";
public static final String COMPONENT_FAMILY = "org.richfaces.Notify";
+ public static final String COMPONENT_TYPE = "org.richfaces.NotifyStack";
+
+// -------------------------- OTHER METHODS --------------------------
+
@Attribute
- public abstract String getStyleClass();
+ public abstract String getPush();
+ @Attribute
public abstract String getStackDir1();
@Attribute
public abstract String getStackDir2();
@Attribute
- public abstract String getPush();
+ public abstract String getStyleClass();
}
Modified: sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/NotifyAttributes.java
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/NotifyAttributes.java 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/NotifyAttributes.java 2011-04-20 13:29:05 UTC (rev 22433)
@@ -61,7 +61,7 @@
void setAnimationSpeed(Integer animationSpeed);
- @Attribute
+ @Attribute(defaultValue = "true")
boolean isShowHistory();
void setShowHistory(boolean showHistory);
@@ -76,7 +76,7 @@
void setShowShadow(boolean showShadow);
- @Attribute
+ @Attribute(defaultValue = "true")
boolean isShowCloseButton();
void setShowCloseButton(boolean showCloseButton);
Added: sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/package-info.java
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/package-info.java (rev 0)
+++ sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/component/package-info.java 2011-04-20 13:29:05 UTC (rev 22433)
@@ -0,0 +1,3 @@
+@TagLibrary(uri = "http://richfaces.org/sandbox/notify", shortName = "notify", prefix = "notify", displayName = "Notify component tags") package org.richfaces.component;
+
+import org.richfaces.cdk.annotations.TagLibrary;
\ No newline at end of file
Modified: sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyMessagesRenderer.java
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyMessagesRenderer.java 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyMessagesRenderer.java 2011-04-20 13:29:05 UTC (rev 22433)
@@ -22,20 +22,19 @@
package org.richfaces.renderkit.html;
-import java.io.IOException;
-import java.util.Iterator;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractNotify;
import org.richfaces.component.AbstractNotifyMessages;
import org.richfaces.renderkit.HtmlConstants;
import org.richfaces.renderkit.util.RendererUtils;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.Iterator;
+
@JsfRenderer(family = AbstractNotifyMessages.COMPONENT_FAMILY, type = NotifyMessagesRenderer.RENDERER_TYPE)
public class NotifyMessagesRenderer extends NotifyRenderer {
@@ -77,7 +76,7 @@
if (messagesComponent.isShowSummary()) {
notify.setTitle(msg.getSummary());
}
- if (messagesComponent.isShowDetail()) {
+ if (messagesComponent.isShowDetail() && msg.getDetail() != null && !msg.getDetail().equals(msg.getSummary())) {
notify.setText(msg.getDetail());
}
String styleClass = messagesComponent.getStyleClass();
Modified: sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyRenderer.java
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyRenderer.java 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyRenderer.java 2011-04-20 13:29:05 UTC (rev 22433)
@@ -22,25 +22,24 @@
package org.richfaces.renderkit.html;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import org.ajax4jsf.javascript.JSFunction;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.component.AbstractNotify;
+import org.richfaces.component.AbstractNotifyStack;
+import org.richfaces.renderkit.HtmlConstants;
+import org.richfaces.renderkit.RendererBase;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
-import org.ajax4jsf.javascript.JSFunction;
-import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.component.AbstractNotify;
-import org.richfaces.component.AbstractNotifyStack;
-import org.richfaces.renderkit.AjaxComponentRendererBase;
-import org.richfaces.renderkit.HtmlConstants;
-
@JsfRenderer(family = AbstractNotify.COMPONENT_FAMILY, type = NotifyRenderer.RENDERER_TYPE)
@ResourceDependencies({
@ResourceDependency(library = "javax.faces", name = "jsf.js"),
@@ -49,11 +48,15 @@
@ResourceDependency(name = "jquery.pnotify.js", target = "head"),
@ResourceDependency(name = "richfaces.notify.js", target = "head"),
@ResourceDependency(name = "notify.ecss", target = "head")})
-public class NotifyRenderer extends AjaxComponentRendererBase {
+public class NotifyRenderer extends RendererBase {
+// ------------------------------ FIELDS ------------------------------
public static final String RENDERER_TYPE = "org.richfaces.NotifyRenderer";
+
private static final Map<String, Object> DEFAULTS;
+// -------------------------- STATIC METHODS --------------------------
+
static {
Map<String, Object> defaults = new HashMap<String, Object>();
defaults.put("styleClass", "");
@@ -72,6 +75,8 @@
DEFAULTS = Collections.unmodifiableMap(defaults);
}
+// -------------------------- OTHER METHODS --------------------------
+
@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
if (!(component instanceof AbstractNotify)) {
@@ -82,12 +87,21 @@
writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, getUtils().clientId(context, component), "type");
writer.startElement(HtmlConstants.SCRIPT_ELEM, null);
writer.writeAttribute(HtmlConstants.TYPE_ATTR, "text/javascript", "type");
- writer.writeText(new JSFunction("RichFaces.Notify", getOptions(context, (AbstractNotify) component)), null);
+ writer.writeText(new JSFunction("RichFaces.ui.Notify", getOptions(context, (AbstractNotify) component)), null);
writer.writeText(";", null);
writer.endElement(HtmlConstants.SCRIPT_ELEM);
writer.endElement(HtmlConstants.DIV_ELEM);
}
+ protected void addOptionIfSetAndNotDefault(String optionName, Object value, Map<String, Object> options) {
+ if (value != null && !"".equals(value)
+ && !value.equals(DEFAULTS.get(optionName))
+ && !(value instanceof Collection && ((Collection) value).size() == 0)
+ && !(value instanceof Map && ((Map) value).size() == 0)) {
+ options.put(optionName, value);
+ }
+ }
+
protected Map<String, Object> getOptions(FacesContext context, AbstractNotify notify) throws IOException {
/**
* Include only attributes that are actually set.
@@ -120,20 +134,6 @@
return options;
}
- protected String getStackStyleClass(FacesContext context, AbstractNotify notify) {
- AbstractNotifyStack stack = getStackComponent(context, notify);
- return stack == null ? "" : stack.getStyleClass();
- }
-
- protected void addOptionIfSetAndNotDefault(String optionName, Object value, Map<String, Object> options) {
- if (value != null && !"".equals(value)
- && !value.equals(DEFAULTS.get(optionName))
- && !(value instanceof Collection && ((Collection) value).size() == 0)
- && !(value instanceof Map && ((Map) value).size() == 0)) {
- options.put(optionName, value);
- }
- }
-
protected AbstractNotifyStack getStackComponent(FacesContext context, AbstractNotify notify) {
String stackId = notify.getStack();
if (stackId == null) {
@@ -151,4 +151,9 @@
}
}
}
+
+ protected String getStackStyleClass(FacesContext context, AbstractNotify notify) {
+ AbstractNotifyStack stack = getStackComponent(context, notify);
+ return stack == null ? "" : stack.getStyleClass();
+ }
}
Modified: sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyStackRenderer.java
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyStackRenderer.java 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/src/main/java/org/richfaces/renderkit/html/NotifyStackRenderer.java 2011-04-20 13:29:05 UTC (rev 22433)
@@ -22,30 +22,29 @@
package org.richfaces.renderkit.html;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
+import org.ajax4jsf.javascript.JSFunction;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.component.AbstractNotifyStack;
+import org.richfaces.renderkit.HtmlConstants;
+import org.richfaces.renderkit.RendererBase;
+import org.richfaces.renderkit.util.RendererUtils;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
-import org.ajax4jsf.javascript.JSFunction;
-import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.component.AbstractNotifyStack;
-import org.richfaces.renderkit.AjaxComponentRendererBase;
-import org.richfaces.renderkit.HtmlConstants;
-import org.richfaces.renderkit.util.RendererUtils;
-
@JsfRenderer(family = AbstractNotifyStack.COMPONENT_FAMILY, type = NotifyStackRenderer.RENDERER_TYPE)
@ResourceDependencies({
@ResourceDependency(name = "jquery.js", target = "head"),
@ResourceDependency(name = "richfaces.js", target = "head"),
@ResourceDependency(name = "richfaces.notify.js", target = "head")
})
-public class NotifyStackRenderer extends AjaxComponentRendererBase {
+public class NotifyStackRenderer extends RendererBase {
public static final String RENDERER_TYPE = "org.richfaces.NotifyStackRenderer";
@@ -56,7 +55,7 @@
}
ResponseWriter writer = context.getResponseWriter();
writer.startElement(HtmlConstants.SCRIPT_ELEM, null);
- writer.writeText(new JSFunction("RichFaces.NotifyStack.register",
+ writer.writeText(new JSFunction("RichFaces.ui.NotifyStack.register",
RendererUtils.getInstance().clientId(context, component),
getOptions((AbstractNotifyStack) component)
), null);
Deleted: sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/notify.taglib.xml
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/notify.taglib.xml 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/notify.taglib.xml 2011-04-20 13:29:05 UTC (rev 22433)
@@ -1,247 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- JBoss, Home of Professional Open Source
- Copyright , 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.
- -->
-
-<facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
- version="2.0" id="a4j">
- <namespace>http://richfaces.org/notify</namespace>
- <tag>
- <tag-name>notify</tag-name>
- <component>
- <component-type>org.richfaces.Notify</component-type>
- <renderer-type>org.richfaces.NotifyRenderer</renderer-type>
- </component>
- <attribute>
- <name>animationSpeed</name>
- <type>java.lang.Integer</type>
- </attribute>
- <attribute>
- <name>appearAnimation</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <description>The value binding expression used to wire up this component to a component property of a JavaBean class</description>
- <name>binding</name>
- <type>javax.faces.component.UIComponent</type>
- </attribute>
- <attribute>
- <name>delay</name>
- <type>java.lang.Integer</type>
- </attribute>
- <attribute>
- <name>hideAnimation</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <description>The component identifier for this component. This value must be unique within the closest parent component that is a naming container.</description>
- <name>id</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <name>nonblocking</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>nonblockingOpacity</name>
- <type>java.lang.Double</type>
- </attribute>
- <attribute>
- <description>Flag indicating whether or not this component should be rendered (during Render Response Phase), or processed on any subsequent form submit. The default value for this property is true.</description>
- <name>rendered</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>showCloseButton</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>showHistory</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>showShadow</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>stack</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <name>stayTime</name>
- <type>java.lang.Integer</type>
- </attribute>
- <attribute>
- <name>sticky</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>styleClass</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <name>text</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <name>title</name>
- <type>java.lang.String</type>
- </attribute>
- </tag>
- <tag>
- <tag-name>notifyStack</tag-name>
- <component>
- <component-type>org.richfaces.NotifyStack</component-type>
- <renderer-type>org.richfaces.NotifyStackRenderer</renderer-type>
- </component>
- <attribute>
- <description>The value binding expression used to wire up this component to a component property of a JavaBean class</description>
- <name>binding</name>
- <type>javax.faces.component.UIComponent</type>
- </attribute>
- <attribute>
- <description>The component identifier for this component. This value must be unique within the closest parent component that is a naming container.</description>
- <name>id</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <name>push</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <description>Flag indicating whether or not this component should be rendered (during Render Response Phase), or processed on any subsequent form submit. The default value for this property is true.</description>
- <name>rendered</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>stackDir2</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <name>styleClass</name>
- <type>java.lang.String</type>
- </attribute>
- </tag>
- <tag>
- <tag-name>notifyMessages</tag-name>
- <component>
- <component-type>org.richfaces.NotifyMessages</component-type>
- <renderer-type>org.richfaces.NotifyMessagesRenderer</renderer-type>
- </component>
- <attribute>
- <name>ajaxRendered</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>animationSpeed</name>
- <type>java.lang.Integer</type>
- </attribute>
- <attribute>
- <name>appearAnimation</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <description>The value binding expression used to wire up this component to a component property of a JavaBean class</description>
- <name>binding</name>
- <type>javax.faces.component.UIComponent</type>
- </attribute>
- <attribute>
- <name>delay</name>
- <type>java.lang.Integer</type>
- </attribute>
- <attribute>
- <description>Client identifier of the component for which to display messages. This attribute is mutually exclusive with globalOnly and take precedence if used.</description>
- <name>for</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <description>Flag indicating that only global messages (that is, messages not associated with any client identifier) are to be displayed. Default value is "false".</description>
- <name>globalOnly</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>hideAnimation</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <description>The component identifier for this component. This value must be unique within the closest parent component that is a naming container.</description>
- <name>id</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <name>interval</name>
- <type>java.lang.Integer</type>
- </attribute>
- <attribute>
- <name>nonblocking</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>nonblockingOpacity</name>
- <type>java.lang.Double</type>
- </attribute>
- <attribute>
- <description>Flag indicating whether or not this component should be rendered (during Render Response Phase), or processed on any subsequent form submit. The default value for this property is true.</description>
- <name>rendered</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>showCloseButton</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <description>Flag indicating whether the detail portion of displayed messages should be included. Default value is "false".</description>
- <name>showDetail</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>showHistory</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>showShadow</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <description>Flag indicating whether the summary portion of displayed messages should be included. Default value is "true".</description>
- <name>showSummary</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>stack</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <name>stayTime</name>
- <type>java.lang.Integer</type>
- </attribute>
- <attribute>
- <name>sticky</name>
- <type>boolean</type>
- </attribute>
- <attribute>
- <name>styleClass</name>
- <type>java.lang.String</type>
- </attribute>
- </tag>
-</facelet-taglib>
Added: sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/close.png
===================================================================
(Binary files differ)
Property changes on: sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/close.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/jquery.pnotify.js
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/jquery.pnotify.js 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/jquery.pnotify.js 2011-04-20 13:29:05 UTC (rev 22433)
@@ -1,23 +1,10 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright , Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
+ * jQuery Pines Notify (pnotify) Plugin 1.0.1
*
- * 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.
+ * Copyright (c) 2009 Hunter Perrin
*
- * 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.
+ * Licensed (along with all of Pines) under the GNU Affero GPL:
+ * http://www.gnu.org/licenses/agpl.html
*/
(function($) {
@@ -253,13 +240,16 @@
if (opts.pnotify_mouse_reset && animating == "out") {
// If it's animating out, animate back in really quick.
pnotify.stop(true);
+ animating = "in";
pnotify.css("height", "auto").animate({"width": opts.pnotify_width, "opacity": opts.pnotify_nonblock ? opts.pnotify_nonblock_opacity : opts.pnotify_opacity}, "fast");
- } else if (opts.pnotify_nonblock && animating != "out") {
+ }
+ if (opts.pnotify_nonblock) {
// If it's non-blocking, animate to the other opacity.
pnotify.animate({"opacity": opts.pnotify_nonblock_opacity}, "fast");
}
if (opts.pnotify_hide && opts.pnotify_mouse_reset) pnotify.pnotify_cancel_remove();
- if (opts.pnotify_closer && !opts.pnotify_nonblock) pnotify.closer.show();
+ // Do not update
+ if (opts.pnotify_closer && !opts.pnotify_nonblock) pnotify.closer.css("visibility", "visible");
},
"mouseleave": function(e) {
if (opts.pnotify_nonblock) e.stopPropagation();
@@ -268,7 +258,8 @@
if (opts.pnotify_nonblock && animating != "out")
pnotify.animate({"opacity": opts.pnotify_opacity}, "fast");
if (opts.pnotify_hide && opts.pnotify_mouse_reset) pnotify.pnotify_queue_remove();
- pnotify.closer.hide();
+ // Do not update
+ pnotify.closer.css("visibility", "hidden");
$.pnotify_position_all();
},
"mouseover": function(e) {
@@ -318,7 +309,7 @@
pnotify.container = $("<div />", {"class": "rf-ny-co"})
.appendTo(pnotify);
- pnotify.pnotify_version = "1.0.0";
+ pnotify.pnotify_version = "1.0.1";
// This function is for updating the notice.
pnotify.pnotify = function(options) {
@@ -516,10 +507,11 @@
// Provide a button to close the notice.
pnotify.closer = $("<div />", {
"class": "rf-ny-cl",
- "css": {"cursor": "pointer", "display": "none"},
+ "css": {"cursor": "pointer", "visibility": "hidden"},
"click": function() {
pnotify.pnotify_remove();
- pnotify.closer.hide();
+ // Do not update
+ pnotify.closer.css("visibility", "hidden");
}
})
.append($("<span />", {"class": "rf-ny-cl-ic"}))
@@ -553,6 +545,9 @@
if (opts.pnotify_text === false)
pnotify.text_container.hide();
+ //Append div with clear:both class
+ $("<div />", {"class":"rf-ny-fcl"}).appendTo(pnotify.container);
+
// Set width and min height.
if (typeof opts.pnotify_width == "string")
pnotify.css("width", opts.pnotify_width);
@@ -599,6 +594,7 @@
// },
"click": function() {
// Display all notices. (Disregarding non-history notices.)
+ // Don't change it to pnotify's new version, cause using body_data here is a bug
$.each(body.data("pnotify"), function() {
if (this.pnotify_history && this.pnotify_display)
this.pnotify_display();
Deleted: sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/notify.ecss
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/notify.ecss 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/notify.ecss 2011-04-20 13:29:05 UTC (rev 22433)
@@ -1,162 +0,0 @@
-.rf-ny {
- bottom : auto;
- right : 10px;
- top: 10px;
- left: auto;
- z-index: 9999;
-}
-.rf-ny-info {
- color: '#{richSkin.generalTextColor}';
-}
-.rf-ny-warn {
- color:orange;
-}
-.rf-ny-error {
- color:red;
-}
-.rf-ny-fatal {
- color:red;
- font-weight:bold;
-}
-html > body .rf-ny {
- position: fixed;
-}
-.rf-ny .rf-ny-sh {
- margin:0;
- padding: 8px;
- opcity: .3;
- border-radius: 8px;
- position: absolute;
- z-index: -1;
- top: .1em;
- left: .1em;
- bottom: -.2em;
- right: -.2em;
- background-color: '#{richSkin.headerBackgroundColor}';
- color: '#{richSkin.headerTextColor}';
- '-moz-border-radius': 8px;
- '-webkit-border-radius': 8px;
-}
-.rf-ny-co {
- height: 100%;
- padding: .8em;
- border-width: 1px;
- border-style: solid;
- border-radius: 4px;
- border-color: '#{richSkin.panelBorderColor}';
- background-color: '#{richSkin.generalBackgroundColor}';
- color: '#{richSkin.panelTextColor}';
- '-moz-border-radius': 4px;
- '-webkit-border-radius': 4px;
-}
-
-.rf-ny-co-hover {
- background:red;
-}
-.rf-ny-cl {
- float: right;
- margin-left: .2em;
-}
-
-.rf-ny-cl-ic {
- display: block;
- width: 11px;
- height: 11px;
-/**
-TODO uncomment this
- background-image:"url(#{resource['org.richfaces.renderkit.html.images.CancelControlIcon']})";
-*/
-}
-
-.rf-ny-ti {
- display: block;
- font-size: 1.2em;
- font-weight: bold;
- margin-bottom: .4em;
-}
-.rf-ny-te {
- display: block;
-}
-.rf-ny-ic {
- display: none;
- float: left;
- margin-right: .2em;
- width:32px;
- height:32px;
-}
-
-.rf-ny-hc {
- background-color: '#{richSkin.headerBackgroundColor}';
- border-color: '#{richSkin.headerBackgroundColor}';
- font-size: '#{richSkin.headerSizeFont}';
- color: '#{richSkin.headerTextColor}';
- font-family: '#{richSkin.headerFamilyFont}';
-/**
-TODO uncomment this
- background-image:"url(#{resource['org.richfaces.renderkit.html.GradientA']})";
-*/
- font-weight: normal;
- border-bottom-left-radius: 4px;
- border-bottom-right-radius: 4px;
- position: absolute;
- top: 0;
- right: 18px;
- width: 70px;
- z-index: 10000;
- color: '#{richSkin.panelTextColor}';
- '-moz-border-radius-bottomleft': 4px;
- '-webkit-border-bottom-left-radius': 4px;
- '-moz-border-radius-bottomright': 4px;
- '-webkit-border-bottom-right-radius': 4px;
-}
-
-.rf-ny-hc .rf-ny-hh {
- padding: 2px;
-}
-.rf-ny-hc button {
- cursor: pointer;
- display: block;
- width: 100%;
-}
-.rc-ny-ha {
- border-radius: 4px;
- '-moz-border-radius': 4px;
- '-webkit-border-radius': 4px;
-}
-
-.rf-ny-hc .rf-ny-hp {
- display: block;
- margin: 0 auto;
- width: 16px;
- height: 16px;
- background-color: '#{richSkin.panelTextColor}';
-/**
-TODO check why nullpointer is thrown because of this
- background-image:"url(#{resource['org.richfaces.renderkit.html.images.TriangleIconDown']})";
-*/
-}
-.rc-ny-hl {
- font-weight: normal;
- color: '#{richSkin.panelTextColor}';
- border-radius: 4px;
- border-color: '#{richSkin.panelBorderColor}';
- background-color: '#{richSkin.generalBackgroundColor}';
- '-moz-border-radius': 4px;
- '-webkit-border-radius': 4px;
-}
-.rf-ny-info .rf-ny-ic {
- display: block;
- background-image:"url(#{resource['info.png']})";
-}
-.rf-ny-warn .rf-ny-ic {
- display: block;
- background-image:"url(#{resource['warn.png']})";
-}
-.rf-ny-error .rf-ny-ic {
- display: block;
- background-image:"url(#{resource['error.png']})";
-}
-.rf-ny-fatal .rf-ny-ic {
- display: block;
- background-image:"url(#{resource['fatal.png']})";
-}
\ No newline at end of file
Added: sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/notify.ecss
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/notify.ecss (rev 0)
+++ sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/notify.ecss 2011-04-20 13:29:05 UTC (rev 22433)
@@ -0,0 +1,177 @@
+.rf-ny {
+ bottom: auto;
+ right: 10px;
+ top: 10px;
+ left: auto;
+ z-index: 9999;
+}
+
+.rf-ny-info {
+ color: '#{richSkin.generalTextColor}';
+}
+
+.rf-ny-warn {
+ color: orange;
+}
+
+.rf-ny-error {
+ color: red;
+}
+
+.rf-ny-fatal {
+ color: red;
+ font-weight: bold;
+}
+
+html > body .rf-ny {
+ position: fixed;
+}
+
+.rf-ny .rf-ny-sh {
+ margin: 0;
+ padding: 8px;
+ opacity: .3;
+ border-radius: 8px;
+ position: absolute;
+ z-index: -1;
+ top: .1em;
+ left: .1em;
+ bottom: -.2em;
+ right: -.2em;
+ background-color: '#{richSkin.headerBackgroundColor}';
+ color: '#{richSkin.headerTextColor}';
+'-moz-border-radius' : 8 px;
+'-webkit-border-radius' : 8 px;
+}
+
+.rf-ny-co {
+ height: 100%;
+ padding: .8em;
+ border-width: 1px;
+ border-style: solid;
+ border-radius: 4px;
+ border-color: '#{richSkin.panelBorderColor}';
+ background-color: '#{richSkin.generalBackgroundColor}';
+ color: '#{richSkin.panelTextColor}';
+'-moz-border-radius' : 4 px;
+'-webkit-border-radius' : 4 px;
+}
+
+.rf-ny-co-hover {
+ background: red;
+}
+
+.rf-ny-cl {
+ float: right;
+ margin-left: .2em;
+}
+
+.rf-ny-cl-ic {
+ display: block;
+ width: 11px;
+ height: 11px;
+ background-image:"url(#{resource['close.png']})";
+}
+
+.rf-ny-ti {
+ display: block;
+ font-size: 1.2em;
+ font-weight: bold;
+ margin-bottom: .4em;
+}
+
+.rf-ny-te {
+ display: block;
+}
+
+.rf-ny-fcl{
+ clear:both;
+}
+
+.rf-ny-ic {
+ display: none;
+ float: left;
+ margin-right: .2em;
+ width: 32px;
+ height: 32px;
+}
+
+.rf-ny-hc {
+ background-color: '#{richSkin.headerBackgroundColor}';
+ border-color: '#{richSkin.headerBackgroundColor}';
+ font-size: '#{richSkin.headerSizeFont}';
+ color: '#{richSkin.headerTextColor}';
+ font-family: '#{richSkin.headerFamilyFont}';
+ /**
+ TODO uncomment this
+ background-image:"url(#{resource['org.richfaces.renderkit.html.GradientA']})";
+ */
+ font-weight: normal;
+ border-bottom-left-radius: 4px;
+ border-bottom-right-radius: 4px;
+ position: absolute;
+ top: 0;
+ right: 18px;
+ width: 70px;
+ z-index: 10000;
+ color: '#{richSkin.panelTextColor}';
+'-moz-border-radius-bottomleft' : 4 px;
+'-webkit-border-bottom-left-radius' : 4 px;
+'-moz-border-radius-bottomright' : 4 px;
+'-webkit-border-bottom-right-radius' : 4 px;
+}
+
+.rf-ny-hc .rf-ny-hh {
+ padding: 2px;
+}
+
+.rf-ny-hc button {
+ cursor: pointer;
+ display: block;
+ width: 100%;
+}
+
+.rc-ny-ha {
+ border-radius: 4px;
+'-moz-border-radius' : 4 px;
+'-webkit-border-radius' : 4 px;
+}
+
+.rf-ny-hc .rf-ny-hp {
+ display: block;
+ margin: 0 auto;
+ width: 16px;
+ height: 16px;
+ background-color: '#{richSkin.panelTextColor}';
+ background-image:"url(#{resource['org.richfaces.images:triangleDown.png']})";
+}
+
+.rc-ny-hl {
+ font-weight: normal;
+ color: '#{richSkin.panelTextColor}';
+ border-radius: 4px;
+ border-color: '#{richSkin.panelBorderColor}';
+ background-color: '#{richSkin.generalBackgroundColor}';
+'-moz-border-radius' : 4 px;
+'-webkit-border-radius' : 4 px;
+}
+
+.rf-ny-info .rf-ny-ic {
+ display: block;
+ background-image: "url(#{resource['info.png']})";
+}
+
+.rf-ny-warn .rf-ny-ic {
+ display: block;
+ background-image: "url(#{resource['warn.png']})";
+}
+
+.rf-ny-error .rf-ny-ic {
+ display: block;
+ background-image: "url(#{resource['error.png']})";
+}
+
+.rf-ny-fatal .rf-ny-ic {
+ display: block;
+ background-image: "url(#{resource['fatal.png']})";
+}
\ No newline at end of file
Modified: sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/richfaces.notify.js
===================================================================
--- sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/richfaces.notify.js 2011-04-19 10:33:53 UTC (rev 22432)
+++ sandbox/trunk/ui/notify/ui/src/main/resources/META-INF/resources/richfaces.notify.js 2011-04-20 13:29:05 UTC (rev 22433)
@@ -20,8 +20,8 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-window.RichFaces = window.RichFaces || {};
-RichFaces.NotifyStack = (function() {
+RichFaces.ui = RichFaces.ui || {};
+RichFaces.ui.NotifyStack = (function() {
var stacks = {};
return {
register: function(id, stack) {
@@ -50,7 +50,7 @@
}
})();
-RichFaces.Notify = function(options) {
+RichFaces.ui.Notify = function(options) {
/**
* Copies attributes from one objects to other object, but
* can change the name of target attributes.
@@ -68,7 +68,7 @@
options = jQuery.extend({stack:'default'}, options);
if (options != null && typeof options.stack == "string") {
- options.stack = RichFaces.NotifyStack.getStack(options.stack);
+ options.stack = RichFaces.ui.NotifyStack.getStack(options.stack);
}
var delegateOptions = extend({}, options, {
'title':'pnotify_title' ,
@@ -100,75 +100,4 @@
jQuery.pnotify(delegateOptions);
}
});
-};
-
-//TODO remove this fix when it gets in to jquery.js
-(function() {
- var safariCompatMode;
- var getCompatMode = function() {
- var compatMode = document.compatMode;
- if (!compatMode && jQuery.browser.safari) {
- if (!safariCompatMode) {
- //detect compatMode as described in http://code.google.com/p/doctype/wiki/ArticleCompatMode
- var width = jQuery(document.createElement("div")).attr('style', 'position:absolute;width:0;height:0;width:1')
- .css('width');
- safariCompatMode = compatMode = (width == '1px' ? 'BackCompat' : 'CSS1Compat');
- } else {
- compatMode = safariCompatMode;
- }
- }
-
- return compatMode;
- };
-
-
- // Create innerHeight, innerWidth, outerHeight and outerWidth methods
- jQuery.each([ "Height", "Width" ], function(i, name) {
-
- var tl = i ? "Left" : "Top", // top or left
- br = i ? "Right" : "Bottom", // bottom or right
- lower = name.toLowerCase();
-
- // innerHeight and innerWidth
- jQuery.fn["inner" + name] = function() {
- return this[0] ?
- jQuery.css(this[0], lower, false, "padding") :
- null;
- };
-
- // outerHeight and outerWidth
- jQuery.fn["outer" + name] = function(margin) {
- return this[0] ?
- jQuery.css(this[0], lower, false, margin ? "margin" : "border") :
- null;
- };
-
- var type = name.toLowerCase();
-
- jQuery.fn[ type ] = function(size) {
- // Get window width or height
- return this[0] == window ?
- // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
- getCompatMode() == "CSS1Compat" && document.documentElement[ "client" + name ] ||
- document.body[ "client" + name ] :
-
- // Get document width or height
- this[0] == document ?
- // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
- Math.max(
- document.documentElement["client" + name],
- document.body["scroll" + name], document.documentElement["scroll" + name],
- document.body["offset" + name], document.documentElement["offset" + name]
- ) :
-
- // Get or set width or height on the element
- size === undefined ?
- // Get width or height on the element
- (this.length ? jQuery.css(this[0], type) : null) :
-
- // Set the width or height on the element (default to pixels if value is unitless)
- this.css(type, typeof size === "string" ? size : size + "px");
- };
-
- });
-}());
\ No newline at end of file
+};
\ No newline at end of file
13 years, 8 months
JBoss Rich Faces SVN: r22432 - trunk/core/impl/src/main/resources/META-INF/resources.
by richfaces-svn-commits@lists.jboss.org
Author: pyaschenko
Date: 2011-04-19 06:33:53 -0400 (Tue, 19 Apr 2011)
New Revision: 22432
Modified:
trunk/core/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
Log:
https://jira.jboss.org/browse/RF-9645 - RichFaces.BaseComponent.invokeEvent() could not be moved, JS documentation is added.
Modified: trunk/core/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
===================================================================
--- trunk/core/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2011-04-18 21:42:06 UTC (rev 22431)
+++ trunk/core/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2011-04-19 10:33:53 UTC (rev 22432)
@@ -246,10 +246,15 @@
var element = richfaces.getDomElement(source);
element && element[richfaces.RICH_CONTAINER] && (element[richfaces.RICH_CONTAINER].component=null);
},
-
- /** TODO: add jsdocs and qunit tests
- *
- */
+
+ /**
+ * Invokes event on on the DOM element
+ * @param eventType event type, e.g. "click"
+ * @param element DOM element object
+ * @param event jQuery Event
+ * @param data additional data used for event handler
+ * @return true if an event is successfully invoked
+ */
invokeEvent: function(eventType, element, event, data) {
var handlerResult, result;
var eventObj = $.extend({}, event, {type: eventType});
13 years, 8 months
JBoss Rich Faces SVN: r22431 - in modules/tests/metamer/trunk: application/src/main/java/org/richfaces/tests/metamer/bean and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: jjamrich
Date: 2011-04-18 17:42:06 -0400 (Mon, 18 Apr 2011)
New Revision: 22431
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessagesBean.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/validation/MultipleValidationRulesBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/csv.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsfValidator.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsr303.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/list.xhtml
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java
modules/tests/metamer/trunk/build.sh
Log:
Add rich:messages support into metamer
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java 2011-04-18 15:24:27 UTC (rev 22430)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java 2011-04-18 21:42:06 UTC (rev 22431)
@@ -147,6 +147,7 @@
components.put("richMenuItem", "Rich Menu Item");
components.put("richMenuSeparator", "Rich Menu Separator");
components.put("richMessage", "Rich Message");
+ components.put("richMessages", "Rich Messages");
components.put("richPanel", "Rich Panel");
components.put("richPanelMenu", "Rich Panel Menu");
components.put("richPanelMenuGroup", "Rich Panel Menu Group");
Added: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessagesBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessagesBean.java (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessagesBean.java 2011-04-18 21:42:06 UTC (rev 22431)
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, 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.tests.metamer.bean;
+
+import javax.annotation.PostConstruct;
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.ViewScoped;
+
+import org.richfaces.component.UIRichMessages;
+import org.richfaces.tests.metamer.Attributes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Simple bean for rich:messages component example.
+ *
+ * @author <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
+ * @version $Revision$
+ */
+@ManagedBean(name = "richMessagesBean")
+@ViewScoped
+public class RichMessagesBean {
+
+ private static Logger logger;
+ private Attributes attributes;
+
+ private String simpleInput1;
+ private String simpleInput2;
+
+ @PostConstruct
+ public void init() {
+ logger = LoggerFactory.getLogger(getClass());
+ logger.info("initializing bean " + getClass().getName());
+ attributes = Attributes.getComponentAttributesFromFacesConfig(UIRichMessages.class, getClass());
+
+ attributes.setAttribute("ajaxRendered", true);
+ attributes.setAttribute("rendered", true);
+ attributes.setAttribute("for", "simpleInput1");
+ attributes.setAttribute("showSummary", true);
+ }
+
+ public Attributes getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(Attributes attributes) {
+ this.attributes = attributes;
+ }
+
+ public String getSimpleInput1() {
+ return simpleInput1;
+ }
+
+ public void setSimpleInput1(String simpleInput1) {
+ this.simpleInput1 = simpleInput1;
+ }
+
+ public String getSimpleInput2() {
+ return simpleInput2;
+ }
+
+ public void setSimpleInput2(String simpleInput2) {
+ this.simpleInput2 = simpleInput2;
+ }
+
+}
Added: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/validation/MultipleValidationRulesBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/validation/MultipleValidationRulesBean.java (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/validation/MultipleValidationRulesBean.java 2011-04-18 21:42:06 UTC (rev 22431)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, 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.tests.metamer.validation;
+
+import javax.faces.bean.ManagedBean;
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+
+/**
+ * Simple bean with property with more than one validation
+ *
+ * @author <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
+ * @version $Revision$
+ */
+@ManagedBean
+public class MultipleValidationRulesBean extends Validable<Integer> {
+
+ public MultipleValidationRulesBean(){
+ value = 10;
+ }
+
+ @Digits(integer=2, fraction=0)
+ @Min(5)
+ @Max(150)
+ @Override
+ public Integer getValue() {
+ return value;
+ }
+
+ @Override
+ public void setValue(Integer value) {
+ this.value = value;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Integer between 5 and 150, but at less than 3 digits";
+ }
+
+ @Override
+ public String getLabel() {
+ return "Number size and value";
+ }
+}
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/csv.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/csv.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/csv.xhtml 2011-04-18 21:42:06 UTC (rev 22431)
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"
+ xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010-2011, 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.
+ -->
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="view">
+ <f:metadata>
+ <f:viewParam name="templates" value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="head">
+ <style type="text/css">
+ .rf-msg-err {
+ display: block !important;
+ margin-bottom: 6px;
+ }
+ </style>
+ </ui:define>
+
+ <ui:define name="component">
+ <script type="text/javascript">
+ function setCorrectValues() {
+ $('input[id$=simpleInput1]').val('10');
+ $('input[id$=simpleInput2]').val('10');
+ }
+
+ function setWrongValues() {
+ $('input[id$=simpleInput1]').val('200');
+ $('input[id$=simpleInput2]').val('200');
+ }
+ </script>
+
+ <input id="setCorrectValuesButton" type="button" value="set correct values" onclick="setCorrectValues()"/>
+ <input id="setWrongValuesButton" type="button" value="set wrong values" onclick="setWrongValues()"/>
+
+ <rich:messages id="msgs"
+ for="#{richMessagesBean.attributes['for'].value}"
+ ajaxRendered="#{richMessagesBean.attributes['ajaxRendered'].value}"
+ globalOnly="#{richMessagesBean.attributes['globalOnly'].value}"
+ keepTransient="#{richMessagesBean.attributes['keepTransient'].value}"
+ rendered="#{richMessagesBean.attributes['rendered'].value}"
+ showDetail="#{richMessagesBean.attributes['showDetail'].value}"
+ showSummary="#{richMessagesBean.attributes['showSummary'].value}"
+ style="#{richMessagesBean.attributes['style'].value}"
+ styleClass="#{richMessagesBean.attributes['styleClass'].value}"
+ title="#{richMessagesBean.attributes['title'].value}"
+ />
+ <h:panelGrid columns="3">
+ <h:outputLabel for="simpleInput1" value="#{multipleValidationRulesBean.description}" />
+ <h:inputText id="simpleInput1" value="#{multipleValidationRulesBean.value}" label="Input 1"
+ converter="#{multipleValidationRulesBean.converter}">
+ <rich:validator />
+ </h:inputText>
+ <rich:message id="simpleInputMsg1" for="simpleInput1" ajaxRendered="true" />
+
+ <h:outputLabel for="simpleInput2" value="#{multipleValidationRulesBean.description}" />
+ <h:inputText id="simpleInput2" value="#{multipleValidationRulesBean.value}" label="Input 2"
+ converter="#{multipleValidationRulesBean.converter}">
+ <rich:validator />
+ </h:inputText>
+ <rich:message id="simpleInputMsg2" for="simpleInput2" ajaxRendered="true" />
+ </h:panelGrid>
+
+ <br/>
+
+ <h:commandButton id="hButton" value="h:commandButton" style="margin-right: 10px;"/>
+ <a4j:commandButton id="a4jButton" value="a4j:commandButton"/>
+
+ <br/>
+ <rich:messages id="msgs2" />
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <metamer:attributes value="#{richMessagesBean.attributes}" id="attributes"/>
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsfValidator.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsfValidator.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsfValidator.xhtml 2011-04-18 21:42:06 UTC (rev 22431)
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:a4j="http://richfaces.org/a4j"
+ xmlns:rich="http://richfaces.org/rich"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010-2011, 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.
+ -->
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="view">
+ <f:metadata>
+ <f:viewParam name="templates" value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="component">
+ <script type="text/javascript">
+ function setCorrectValues() {
+ $('input[id$=simpleInput1]').val('10');
+ $('input[id$=simpleInput2]').val('10');
+ }
+
+ function setWrongValues() {
+ $('input[id$=simpleInput1]').val('200');
+ $('input[id$=simpleInput2]').val('200');
+ }
+ </script>
+
+ <input id="setCorrectValuesButton" type="button" value="set correct values" onclick="setCorrectValues()"/>
+ <input id="setWrongValuesButton" type="button" value="set wrong values" onclick="setWrongValues()"/>
+
+ <rich:messages id="msgs"
+ for="#{richMessagesBean.attributes['for'].value}"
+ ajaxRendered="#{richMessagesBean.attributes['ajaxRendered'].value}"
+ globalOnly="#{richMessagesBean.attributes['globalOnly'].value}"
+ keepTransient="#{richMessagesBean.attributes['keepTransient'].value}"
+ rendered="#{richMessagesBean.attributes['rendered'].value}"
+ showDetail="#{richMessagesBean.attributes['showDetail'].value}"
+ showSummary="#{richMessagesBean.attributes['showSummary'].value}"
+ style="#{richMessagesBean.attributes['style'].value}"
+ styleClass="#{richMessagesBean.attributes['styleClass'].value}"
+ title="#{richMessagesBean.attributes['title'].value}"
+ />
+ <h:panelGrid columns="3">
+ <h:outputLabel for="simpleInput1" value="#{multipleValidationRulesBean.description}" />
+ <h:inputText id="simpleInput1" value="#{richMessagesBean.simpleInput1}" label="Input 1" >
+ <f:validateLongRange minimum="5" maximum="150" />
+ <f:validateLength maximum="2" />
+ </h:inputText>
+ <rich:message id="simpleInputMsg1" ajaxRendered="true" for="simpleInput1" />
+
+ <h:outputLabel for="simpleInput2" value="#{multipleValidationRulesBean.description}" />
+ <h:inputText id="simpleInput2" value="#{richMessagesBean.simpleInput2}" label="Input 2" >
+ <f:validateLongRange minimum="5" maximum="150" />
+ <f:validateLength maximum="2" />
+ </h:inputText>
+ <rich:message id="simpleInputMsg2" ajaxRendered="true" for="simpleInput2" />
+ </h:panelGrid>
+
+ <br/>
+
+ <h:commandButton id="hButton" value="h:commandButton" style="margin-right: 10px;"/>
+ <a4j:commandButton id="a4jButton" value="a4j:commandButton"/>
+
+ <br/>
+ <rich:messages id="msgs2" />
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <metamer:attributes value="#{richMessagesBean.attributes}" id="attributes"/>
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsr303.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsr303.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/jsr303.xhtml 2011-04-18 21:42:06 UTC (rev 22431)
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"
+ xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010-2011, 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.
+ -->
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="view">
+ <f:metadata>
+ <f:viewParam name="templates" value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="head">
+ <style type="text/css">
+ .rf-msg-err {
+ display: block !important;
+ margin-bottom: 6px;
+ }
+ </style>
+ </ui:define>
+
+ <ui:define name="component">
+ <script type="text/javascript">
+ function setCorrectValues() {
+ $('input[id$=simpleInput1]').val('10');
+ $('input[id$=simpleInput2]').val('10');
+ }
+
+ function setWrongValues() {
+ $('input[id$=simpleInput1]').val('200');
+ $('input[id$=simpleInput2]').val('200');
+ }
+ </script>
+
+ <input id="setCorrectValuesButton" type="button" value="set correct values" onclick="setCorrectValues()"/>
+ <input id="setWrongValuesButton" type="button" value="set wrong values" onclick="setWrongValues()"/>
+
+ <rich:messages id="msgs"
+ for="#{richMessagesBean.attributes['for'].value}"
+ ajaxRendered="#{richMessagesBean.attributes['ajaxRendered'].value}"
+ globalOnly="#{richMessagesBean.attributes['globalOnly'].value}"
+ keepTransient="#{richMessagesBean.attributes['keepTransient'].value}"
+ rendered="#{richMessagesBean.attributes['rendered'].value}"
+ showDetail="#{richMessagesBean.attributes['showDetail'].value}"
+ showSummary="#{richMessagesBean.attributes['showSummary'].value}"
+ style="#{richMessagesBean.attributes['style'].value}"
+ styleClass="#{richMessagesBean.attributes['styleClass'].value}"
+ title="#{richMessagesBean.attributes['title'].value}"
+ />
+ <h:panelGrid columns="3">
+ <h:outputLabel for="simpleInput1" value="#{multipleValidationRulesBean.description}" />
+ <h:inputText id="simpleInput1" value="#{multipleValidationRulesBean.value}" label="Input 1"
+ converter="#{multipleValidationRulesBean.converter}" />
+ <rich:message id="simpleInputMsg1" ajaxRendered="true" for="simpleInput1" />
+
+ <h:outputLabel for="simpleInput2" value="#{multipleValidationRulesBean.description}" />
+ <h:inputText id="simpleInput2" value="#{multipleValidationRulesBean.value}" label="Input 2"
+ converter="#{multipleValidationRulesBean.converter}" />
+ <rich:message id="simpleInputMsg2" ajaxRendered="true" for="simpleInput2" />
+ </h:panelGrid>
+
+ <br/>
+
+ <h:commandButton id="hButton" value="h:commandButton" style="margin-right: 10px;"/>
+ <a4j:commandButton id="a4jButton" value="a4j:commandButton"/>
+
+ <br/>
+ <rich:messages id="msgs2" />
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <metamer:attributes value="#{richMessagesBean.attributes}" id="attributes"/>
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/list.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/list.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richMessages/list.xhtml 2011-04-18 21:42:06 UTC (rev 22431)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010-2011, 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.
+ -->
+
+ <ui:composition template="/templates/list.xhtml">
+
+ <ui:define name="pageTitle">Rich Messages</ui:define>
+
+ <ui:define name="links">
+
+ <metamer:testPageLink id="csv" outcome="csv" value="Client Side Validation">
+ Simple page that contains <b>rich:validator</b> for input with JSR-303 validator.
+ </metamer:testPageLink>
+
+ <metamer:testPageLink id="jsr303" outcome="jsr303" value="JSR-303 Bean Validation">
+ Page containing input with JSR-303 validator.
+ </metamer:testPageLink>
+
+ <metamer:testPageLink id="jsfValidator" outcome="jsfValidator" value="Simple JSF Validation">
+ Page containing input with simple JSF validator.
+ </metamer:testPageLink>
+
+ </ui:define>
+
+ </ui:composition>
+
+</html>
Property changes on: modules/tests/metamer/trunk/build.sh
___________________________________________________________________
Added: svn:executable
+ *
13 years, 8 months
JBoss Rich Faces SVN: r22430 - in trunk/ui/iteration: ui/src/main/java/org/richfaces/component and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2011-04-18 11:24:27 -0400 (Mon, 18 Apr 2011)
New Revision: 22430
Modified:
trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/NodesTreeSequenceKeyModel.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
Log:
https://issues.jboss.org/browse/RF-10869
Modified: trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java 2011-04-18 12:09:35 UTC (rev 22429)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java 2011-04-18 15:24:27 UTC (rev 22430)
@@ -67,7 +67,11 @@
}
public TreeNode getChildAt(int childIndex) {
- return Iterables.get(children, childIndex);
+ if (childIndex < getChildCount()) {
+ return Iterables.get(children, childIndex);
+ }
+
+ return null;
}
public int getChildCount() {
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java 2011-04-18 12:09:35 UTC (rev 22429)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/component/DeclarativeTreeDataModelWalker.java 2011-04-18 15:24:27 UTC (rev 22430)
@@ -83,12 +83,23 @@
private void setupDataModelContext(Object key) {
if (modelData instanceof Iterable<?>) {
Iterable<?> iterable = (Iterable<?>) modelData;
- data = Iterables.get(iterable, (Integer) key);
+ Integer index = (Integer) key;
+
+ if (index < Iterables.size(iterable)) {
+ data = Iterables.get(iterable, index);
+ } else {
+ data = null;
+ }
} else {
data = ((Map<?, ?>) modelData).get(key);
}
}
+ private void resetForDataNotAvailable() {
+ data = null;
+ currentComponent = rootComponent;
+ }
+
protected FacesContext getFacesContext() {
return facesContext;
}
@@ -120,7 +131,18 @@
}
setupModelComponentContext(declarativeKey.getModelId());
+
+ if (modelData == null) {
+ resetForDataNotAvailable();
+ break;
+ }
+
setupDataModelContext(declarativeKey.getModelKey());
+
+ if (data == null) {
+ resetForDataNotAvailable();
+ break;
+ }
}
} finally {
if (var != null) {
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/NodesTreeSequenceKeyModel.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/NodesTreeSequenceKeyModel.java 2011-04-18 12:09:35 UTC (rev 22429)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/NodesTreeSequenceKeyModel.java 2011-04-18 15:24:27 UTC (rev 22430)
@@ -45,6 +45,11 @@
for (Object simpleKey: key.getSimpleKeys()) {
data = setupChildContext(simpleKey);
+
+ if (data == null) {
+ break;
+ }
+
setData(data);
}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2011-04-18 12:09:35 UTC (rev 22429)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2011-04-18 15:24:27 UTC (rev 22430)
@@ -74,7 +74,13 @@
}
protected TreeNode findChild(TreeNode parent, Integer simpleKey) {
- return parent.getChildAt(simpleKey.intValue());
+ int childIdx = simpleKey.intValue();
+
+ if (childIdx < parent.getChildCount()) {
+ return parent.getChildAt(childIdx);
+ }
+
+ return null;
}
public Iterator<TreeDataModelTuple> children() {
13 years, 8 months
JBoss Rich Faces SVN: r22429 - in modules/tests/metamer/trunk/application/src/main: webapp/components/richMessage and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: jjamrich
Date: 2011-04-18 08:09:35 -0400 (Mon, 18 Apr 2011)
New Revision: 22429
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/csv.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/jsr303.xhtml
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessageBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/jsfValidator.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/list.xhtml
Log:
Set the same interface for all type validators
Change all pages to use the same interface and differs only in
validators used.
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessageBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessageBean.java 2011-04-18 11:55:15 UTC (rev 22428)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichMessageBean.java 2011-04-18 12:09:35 UTC (rev 22429)
@@ -50,7 +50,11 @@
logger = LoggerFactory.getLogger(getClass());
logger.info("initializing bean " + getClass().getName());
attributes = Attributes.getComponentAttributesFromFacesConfig(UIRichMessage.class, getClass());
-
+
+ // setting up incorrect values to fire-up validator
+ simpleInput1 = "-5";
+ simpleInput2 = "-5";
+
// to get working this component example correctly is required that for
// property has been initialized
attributes.setAttribute("for", "simpleInput1");
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/csv.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/csv.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/csv.xhtml 2011-04-18 12:09:35 UTC (rev 22429)
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"
+ xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010-2011, 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.
+ -->
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="view">
+ <f:metadata>
+ <f:viewParam name="templates" value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="head">
+ <style type="text/css">
+ .rf-msg-err {
+ display: block !important;
+ margin-bottom: 6px;
+ }
+ </style>
+ </ui:define>
+
+ <ui:define name="component">
+ <script type="text/javascript">
+ function setCorrectValues() {
+ $('input[id$=simpleInput1]').val('4');
+ $('input[id$=simpleInput2]').val('4');
+ }
+
+ function setWrongValues() {
+ $('input[id$=simpleInput1]').val('-5');
+ $('input[id$=simpleInput2]').val('-5');
+ }
+ </script>
+
+ <input id="setCorrectValuesButton" type="button" value="set correct values" onclick="setCorrectValues()"/>
+ <input id="setWrongValuesButton" type="button" value="set wrong values" onclick="setWrongValues()"/>
+
+ <rich:message id="simpleInputMsg"
+ ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
+ for="#{richMessageBean.attributes['for'].value}"
+ keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
+ rendered="#{richMessageBean.attributes['rendered'].value}"
+ showDetail="#{richMessageBean.attributes['showDetail'].value}"
+ showSummary="#{richMessageBean.attributes['showSummary'].value}"
+ childCount="#{richMessageBean.attributes['childCount'].value}"
+ children="#{richMessageBean.attributes['children'].value}"
+ dir="#{richMessageBean.attributes['dir'].value}"
+ facets="#{richMessageBean.attributes['facets'].value}"
+ family="#{richMessageBean.attributes['family'].value}"
+ lang="#{richMessageBean.attributes['lang'].value}"
+ onclick="#{richMessageBean.attributes['onclick'].value}"
+ ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
+ onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
+ onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
+ onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
+ onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
+ onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
+ onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
+ onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
+ rendererType="#{richMessageBean.attributes['rendererType'].value}"
+ rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
+ style="#{richMessageBean.attributes['style'].value}"
+ styleClass="#{richMessageBean.attributes['styleClass'].value}"
+ title="#{richMessageBean.attributes['title'].value}"
+ />
+ <h:panelGrid columns="3">
+ <h:outputLabel for="simpleInput1" value="#{minMaxBean.description}" />
+ <h:inputText id="simpleInput1" value="#{minMaxBean.value}" label="Input 1" converter="#{minMaxBean.converter}">
+ <rich:validator />
+ </h:inputText>
+ <rich:message id="simpleInputMsg1"
+ ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
+ for="simpleInput1"
+ keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
+ rendered="#{richMessageBean.attributes['rendered'].value}"
+ showDetail="#{richMessageBean.attributes['showDetail'].value}"
+ showSummary="#{richMessageBean.attributes['showSummary'].value}"
+ childCount="#{richMessageBean.attributes['childCount'].value}"
+ children="#{richMessageBean.attributes['children'].value}"
+ dir="#{richMessageBean.attributes['dir'].value}"
+ facets="#{richMessageBean.attributes['facets'].value}"
+ family="#{richMessageBean.attributes['family'].value}"
+ lang="#{richMessageBean.attributes['lang'].value}"
+ onclick="#{richMessageBean.attributes['onclick'].value}"
+ ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
+ onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
+ onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
+ onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
+ onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
+ onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
+ onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
+ onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
+ rendererType="#{richMessageBean.attributes['rendererType'].value}"
+ rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
+ styleClass="#{richMessageBean.attributes['styleClass'].value}"
+ style="#{richMessageBean.attributes['style'].value}"
+ title="#{richMessageBean.attributes['title'].value}"
+ />
+
+ <h:outputLabel for="simpleInput2" value="#{minMaxBean.description}" />
+ <h:inputText id="simpleInput2" value="#{minMaxBean.value}" label="Input 2" converter="#{minMaxBean.converter}">
+ <rich:validator />
+ </h:inputText>
+ <rich:message id="simpleInputMsg2"
+ ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
+ for="simpleInput2"
+ keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
+ rendered="#{richMessageBean.attributes['rendered'].value}"
+ showDetail="#{richMessageBean.attributes['showDetail'].value}"
+ showSummary="#{richMessageBean.attributes['showSummary'].value}"
+ childCount="#{richMessageBean.attributes['childCount'].value}"
+ children="#{richMessageBean.attributes['children'].value}"
+ dir="#{richMessageBean.attributes['dir'].value}"
+ facets="#{richMessageBean.attributes['facets'].value}"
+ family="#{richMessageBean.attributes['family'].value}"
+ lang="#{richMessageBean.attributes['lang'].value}"
+ onclick="#{richMessageBean.attributes['onclick'].value}"
+ ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
+ onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
+ onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
+ onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
+ onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
+ onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
+ onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
+ onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
+ rendererType="#{richMessageBean.attributes['rendererType'].value}"
+ rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
+ styleClass="#{richMessageBean.attributes['styleClass'].value}"
+ style="#{richMessageBean.attributes['style'].value}"
+ title="#{richMessageBean.attributes['title'].value}"
+ />
+
+ </h:panelGrid>
+
+ <br/>
+
+ <h:commandButton id="hButton" value="h:commandButton" style="margin-right: 10px;"/>
+ <a4j:commandButton id="a4jButton" value="a4j:commandButton"/>
+
+ <br/>
+ <rich:messages id="msgs"/>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <metamer:attributes value="#{richMessageBean.attributes}" id="attributes"/>
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/jsfValidator.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/jsfValidator.xhtml 2011-04-18 11:55:15 UTC (rev 22428)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/jsfValidator.xhtml 2011-04-18 12:09:35 UTC (rev 22429)
@@ -39,115 +39,129 @@
</f:viewParam>
</f:metadata>
</ui:define>
-
+
<ui:define name="component">
+ <script type="text/javascript">
+ function setCorrectValues() {
+ $('input[id$=simpleInput1]').val('4');
+ $('input[id$=simpleInput2]').val('4');
+ }
+ function setWrongValues() {
+ $('input[id$=simpleInput1]').val('-5');
+ $('input[id$=simpleInput2]').val('-5');
+ }
+ </script>
+
+ <input id="setCorrectValuesButton" type="button" value="set correct values" onclick="setCorrectValues()"/>
+ <input id="setWrongValuesButton" type="button" value="set wrong values" onclick="setWrongValues()"/>
+
<rich:message id="simpleInputMsg"
- ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
- for="#{richMessageBean.attributes['for'].value}"
- keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
- rendered="#{richMessageBean.attributes['rendered'].value}"
- showDetail="#{richMessageBean.attributes['showDetail'].value}"
- showSummary="#{richMessageBean.attributes['showSummary'].value}"
- childCount="#{richMessageBean.attributes['childCount'].value}"
- children="#{richMessageBean.attributes['children'].value}"
- dir="#{richMessageBean.attributes['dir'].value}"
- facets="#{richMessageBean.attributes['facets'].value}"
- family="#{richMessageBean.attributes['family'].value}"
- lang="#{richMessageBean.attributes['lang'].value}"
- onclick="#{richMessageBean.attributes['onclick'].value}"
- ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
- onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
- onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
- onkeyup="#{richMessageBean.attributes['onkeyup'].value}"
- onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
- onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
- onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
- onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
- onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
- rendererType="#{richMessageBean.attributes['rendererType'].value}"
- rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
- style="#{richMessageBean.attributes['style'].value}"
- styleClass="#{richMessageBean.attributes['styleClass'].value}"
- title="#{richMessageBean.attributes['title'].value}"
- />
- <!-- ajax input, kombinacia a4j a input -->
+ ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
+ for="#{richMessageBean.attributes['for'].value}"
+ keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
+ rendered="#{richMessageBean.attributes['rendered'].value}"
+ showDetail="#{richMessageBean.attributes['showDetail'].value}"
+ showSummary="#{richMessageBean.attributes['showSummary'].value}"
+ childCount="#{richMessageBean.attributes['childCount'].value}"
+ children="#{richMessageBean.attributes['children'].value}"
+ dir="#{richMessageBean.attributes['dir'].value}"
+ facets="#{richMessageBean.attributes['facets'].value}"
+ family="#{richMessageBean.attributes['family'].value}"
+ lang="#{richMessageBean.attributes['lang'].value}"
+ onclick="#{richMessageBean.attributes['onclick'].value}"
+ ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
+ onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
+ onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
+ onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
+ onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
+ onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
+ onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
+ onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
+ rendererType="#{richMessageBean.attributes['rendererType'].value}"
+ rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
+ style="#{richMessageBean.attributes['style'].value}"
+ styleClass="#{richMessageBean.attributes['styleClass'].value}"
+ title="#{richMessageBean.attributes['title'].value}"
+ />
+
<h:panelGrid columns="3">
- <h:outputLabel for="simpleInput1" value="Simple Input 1" />
- <h:inputText id="simpleInput1" value="#{richMessageBean.simpleInput1}" label="Input 1" >
- <f:validateLength maximum="5" minimum="2" />
+ <h:outputLabel for="simpleInput1" value="#{minMaxBean.description}" />
+ <h:inputText id="simpleInput1" value="#{richMessageBean.simpleInput1}" label="Input 1" >
+ <f:validateLongRange minimum="2" maximum="10" />
</h:inputText>
<rich:message id="simpleInputMsg1"
- ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
- for="simpleInput1"
- keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
- rendered="#{richMessageBean.attributes['rendered'].value}"
- showDetail="#{richMessageBean.attributes['showDetail'].value}"
- showSummary="#{richMessageBean.attributes['showSummary'].value}"
- childCount="#{richMessageBean.attributes['childCount'].value}"
- children="#{richMessageBean.attributes['children'].value}"
- dir="#{richMessageBean.attributes['dir'].value}"
- facets="#{richMessageBean.attributes['facets'].value}"
- family="#{richMessageBean.attributes['family'].value}"
- lang="#{richMessageBean.attributes['lang'].value}"
- onclick="#{richMessageBean.attributes['onclick'].value}"
- ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
- onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
- onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
- onkeyup="#{richMessageBean.attributes['onkeyup'].value}"
- onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
- onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
- onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
- onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
- onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
- rendererType="#{richMessageBean.attributes['rendererType'].value}"
- rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
- styleClass="#{richMessageBean.attributes['styleClass'].value}"
- style="#{richMessageBean.attributes['style'].value}"
- title="#{richMessageBean.attributes['title'].value}"
- />
+ ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
+ for="simpleInput1"
+ keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
+ rendered="#{richMessageBean.attributes['rendered'].value}"
+ showDetail="#{richMessageBean.attributes['showDetail'].value}"
+ showSummary="#{richMessageBean.attributes['showSummary'].value}"
+ childCount="#{richMessageBean.attributes['childCount'].value}"
+ children="#{richMessageBean.attributes['children'].value}"
+ dir="#{richMessageBean.attributes['dir'].value}"
+ facets="#{richMessageBean.attributes['facets'].value}"
+ family="#{richMessageBean.attributes['family'].value}"
+ lang="#{richMessageBean.attributes['lang'].value}"
+ onclick="#{richMessageBean.attributes['onclick'].value}"
+ ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
+ onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
+ onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
+ onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
+ onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
+ onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
+ onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
+ onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
+ rendererType="#{richMessageBean.attributes['rendererType'].value}"
+ rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
+ styleClass="#{richMessageBean.attributes['styleClass'].value}"
+ style="#{richMessageBean.attributes['style'].value}"
+ title="#{richMessageBean.attributes['title'].value}"
+ />
</h:panelGrid>
-
+
<h:panelGrid columns="3">
- <h:outputLabel for="simpleInput2" value="Simple Input 2" />
+ <h:outputLabel for="simpleInput2" value="#{minMaxBean.description}" />
<h:inputText id="simpleInput2" value="#{richMessageBean.simpleInput2}" label="Input 2" >
- <f:validateLength maximum="5" minimum="2" />
+ <f:validateLongRange minimum="2" maximum="10" />
</h:inputText>
<rich:message id="simpleInputMsg2"
- ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
- for="simpleInput2"
- keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
- rendered="#{richMessageBean.attributes['rendered'].value}"
- showDetail="#{richMessageBean.attributes['showDetail'].value}"
- showSummary="#{richMessageBean.attributes['showSummary'].value}"
- childCount="#{richMessageBean.attributes['childCount'].value}"
- children="#{richMessageBean.attributes['children'].value}"
- dir="#{richMessageBean.attributes['dir'].value}"
- facets="#{richMessageBean.attributes['facets'].value}"
- family="#{richMessageBean.attributes['family'].value}"
- lang="#{richMessageBean.attributes['lang'].value}"
- onclick="#{richMessageBean.attributes['onclick'].value}"
- ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
- onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
- onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
- onkeyup="#{richMessageBean.attributes['onkeyup'].value}"
- onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
- onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
- onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
- onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
- onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
- rendererType="#{richMessageBean.attributes['rendererType'].value}"
- rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
- styleClass="#{richMessageBean.attributes['styleClass'].value}"
- style="#{richMessageBean.attributes['style'].value}"
- title="#{richMessageBean.attributes['title'].value}"
- />
+ ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
+ for="simpleInput2"
+ keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
+ rendered="#{richMessageBean.attributes['rendered'].value}"
+ showDetail="#{richMessageBean.attributes['showDetail'].value}"
+ showSummary="#{richMessageBean.attributes['showSummary'].value}"
+ childCount="#{richMessageBean.attributes['childCount'].value}"
+ children="#{richMessageBean.attributes['children'].value}"
+ dir="#{richMessageBean.attributes['dir'].value}"
+ facets="#{richMessageBean.attributes['facets'].value}"
+ family="#{richMessageBean.attributes['family'].value}"
+ lang="#{richMessageBean.attributes['lang'].value}"
+ onclick="#{richMessageBean.attributes['onclick'].value}"
+ ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
+ onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
+ onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
+ onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
+ onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
+ onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
+ onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
+ onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
+ rendererType="#{richMessageBean.attributes['rendererType'].value}"
+ rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
+ styleClass="#{richMessageBean.attributes['styleClass'].value}"
+ style="#{richMessageBean.attributes['style'].value}"
+ title="#{richMessageBean.attributes['title'].value}"
+ />
</h:panelGrid>
-
+
<br/>
-
+
<h:commandButton id="hButton" value="h:commandButton" style="margin-right: 10px;"/>
<a4j:commandButton id="a4jButton" value="a4j:commandButton"/>
+
+ <br/>
+ <rich:messages id="msgs"/>
</ui:define>
<ui:define name="outOfTemplateAfter">
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/jsr303.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/jsr303.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/jsr303.xhtml 2011-04-18 12:09:35 UTC (rev 22429)
@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"
+ xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010-2011, 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.
+ -->
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="view">
+ <f:metadata>
+ <f:viewParam name="templates" value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="head">
+ <style type="text/css">
+ .rf-msg-err {
+ display: block !important;
+ margin-bottom: 6px;
+ }
+ </style>
+ </ui:define>
+
+ <ui:define name="component">
+ <script type="text/javascript">
+ function setCorrectValues() {
+ $('input[id$=simpleInput1]').val('4');
+ $('input[id$=simpleInput2]').val('4');
+ }
+
+ function setWrongValues() {
+ $('input[id$=simpleInput1]').val('-5');
+ $('input[id$=simpleInput2]').val('-5');
+ }
+ </script>
+
+ <input id="setCorrectValuesButton" type="button" value="set correct values" onclick="setCorrectValues()"/>
+ <input id="setWrongValuesButton" type="button" value="set wrong values" onclick="setWrongValues()"/>
+
+ <rich:message id="simpleInputMsg"
+ ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
+ for="#{richMessageBean.attributes['for'].value}"
+ keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
+ rendered="#{richMessageBean.attributes['rendered'].value}"
+ showDetail="#{richMessageBean.attributes['showDetail'].value}"
+ showSummary="#{richMessageBean.attributes['showSummary'].value}"
+ childCount="#{richMessageBean.attributes['childCount'].value}"
+ children="#{richMessageBean.attributes['children'].value}"
+ dir="#{richMessageBean.attributes['dir'].value}"
+ facets="#{richMessageBean.attributes['facets'].value}"
+ family="#{richMessageBean.attributes['family'].value}"
+ lang="#{richMessageBean.attributes['lang'].value}"
+ onclick="#{richMessageBean.attributes['onclick'].value}"
+ ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
+ onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
+ onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
+ onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
+ onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
+ onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
+ onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
+ onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
+ rendererType="#{richMessageBean.attributes['rendererType'].value}"
+ rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
+ style="#{richMessageBean.attributes['style'].value}"
+ styleClass="#{richMessageBean.attributes['styleClass'].value}"
+ title="#{richMessageBean.attributes['title'].value}"
+ />
+ <h:panelGrid columns="3">
+ <h:outputLabel for="simpleInput1" value="#{minMaxBean.description}" />
+ <h:inputText id="simpleInput1" value="#{minMaxBean.value}" label="Input 1" converter="#{minMaxBean.converter}"/>
+ <rich:message id="simpleInputMsg1"
+ ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
+ for="simpleInput1"
+ keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
+ rendered="#{richMessageBean.attributes['rendered'].value}"
+ showDetail="#{richMessageBean.attributes['showDetail'].value}"
+ showSummary="#{richMessageBean.attributes['showSummary'].value}"
+ childCount="#{richMessageBean.attributes['childCount'].value}"
+ children="#{richMessageBean.attributes['children'].value}"
+ dir="#{richMessageBean.attributes['dir'].value}"
+ facets="#{richMessageBean.attributes['facets'].value}"
+ family="#{richMessageBean.attributes['family'].value}"
+ lang="#{richMessageBean.attributes['lang'].value}"
+ onclick="#{richMessageBean.attributes['onclick'].value}"
+ ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
+ onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
+ onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
+ onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
+ onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
+ onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
+ onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
+ onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
+ rendererType="#{richMessageBean.attributes['rendererType'].value}"
+ rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
+ styleClass="#{richMessageBean.attributes['styleClass'].value}"
+ style="#{richMessageBean.attributes['style'].value}"
+ title="#{richMessageBean.attributes['title'].value}"
+ />
+
+ <h:outputLabel for="simpleInput2" value="#{minMaxBean.description}" />
+ <h:inputText id="simpleInput2" value="#{minMaxBean.value}" label="Input 2" converter="#{minMaxBean.converter}"/>
+ <rich:message id="simpleInputMsg2"
+ ajaxRendered="#{richMessageBean.attributes['ajaxRendered'].value}"
+ for="simpleInput2"
+ keepTransient="#{richMessageBean.attributes['keepTransient'].value}"
+ rendered="#{richMessageBean.attributes['rendered'].value}"
+ showDetail="#{richMessageBean.attributes['showDetail'].value}"
+ showSummary="#{richMessageBean.attributes['showSummary'].value}"
+ childCount="#{richMessageBean.attributes['childCount'].value}"
+ children="#{richMessageBean.attributes['children'].value}"
+ dir="#{richMessageBean.attributes['dir'].value}"
+ facets="#{richMessageBean.attributes['facets'].value}"
+ family="#{richMessageBean.attributes['family'].value}"
+ lang="#{richMessageBean.attributes['lang'].value}"
+ onclick="#{richMessageBean.attributes['onclick'].value}"
+ ondblclick="#{richMessageBean.attributes['ondblclick'].value}"
+ onkeydown="#{richMessageBean.attributes['onkeydown'].value}"
+ onkeypress="#{richMessageBean.attributes['onkeypress'].value}"
+ onmousedown="#{richMessageBean.attributes['onmousedown'].value}"
+ onmousemove="#{richMessageBean.attributes['onmousemove'].value}"
+ onmouseout="#{richMessageBean.attributes['onmouseout'].value}"
+ onmouseover="#{richMessageBean.attributes['onmouseover'].value}"
+ onmouseup="#{richMessageBean.attributes['onmouseup'].value}"
+ rendererType="#{richMessageBean.attributes['rendererType'].value}"
+ rendersChildren="#{richMessageBean.attributes['rendersChildren'].value}"
+ styleClass="#{richMessageBean.attributes['styleClass'].value}"
+ style="#{richMessageBean.attributes['style'].value}"
+ title="#{richMessageBean.attributes['title'].value}"
+ />
+ </h:panelGrid>
+
+ <br/>
+
+ <h:commandButton id="hButton" value="h:commandButton" style="margin-right: 10px;"/>
+ <a4j:commandButton id="a4jButton" value="a4j:commandButton"/>
+
+ <br/>
+ <rich:messages id="msgs"/>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <metamer:attributes value="#{richMessageBean.attributes}" id="attributes"/>
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/list.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/list.xhtml 2011-04-18 11:55:15 UTC (rev 22428)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richMessage/list.xhtml 2011-04-18 12:09:35 UTC (rev 22429)
@@ -1,42 +1,50 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
-
- <!--
-JBoss, Home of Professional Open Source
-Copyright 2010-2011, 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.
- -->
-
- <ui:composition template="/templates/list.xhtml">
-
- <ui:define name="pageTitle">Rich Message</ui:define>
-
- <ui:define name="links">
-
- <metamer:testPageLink id="jsfValidator" outcome="jsfValidator" value="Simple JSF Validation">
- Page containing inputs with simple JSF validators and <b>rich:message</b>s.
- </metamer:testPageLink>
-
- </ui:define>
-
- </ui:composition>
-
-</html>
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010-2011, 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.
+ -->
+
+ <ui:composition template="/templates/list.xhtml">
+
+ <ui:define name="pageTitle">Rich Message</ui:define>
+
+ <ui:define name="links">
+
+ <metamer:testPageLink id="csv" outcome="csv" value="Client Side Validation">
+ Simple page that contains <b>rich:validator</b> for input with JSR-303 validator.
+ </metamer:testPageLink>
+
+ <metamer:testPageLink id="jsr303" outcome="jsr303" value="JSR-303 Bean Validation">
+ Page containing input with JSR-303 validator.
+ </metamer:testPageLink>
+
+ <metamer:testPageLink id="jsfValidator" outcome="jsfValidator" value="Simple JSF Validation">
+ Page containing input with simple JSF validator.
+ </metamer:testPageLink>
+
+ </ui:define>
+
+ </ui:composition>
+
+</html>
13 years, 8 months