Author: hlship
Date: Fri Jun 15 19:59:51 2007
New Revision: 547850
URL: http://svn.apache.org/viewvc?view=rev&rev=547850
Log:
TAPESTRY-1354: Implement a file upload component
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/FormEncodingType.html
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormEncodingType.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/ComponentMessages.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Form.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/FormSupportImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FormSupport.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/ComponentStrings.properties
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/Start.html
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/components/FormSupportImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/ComponentMessages.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/ComponentMessages.java?view=diff&rev=547850&r1=547849&r2=547850
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/ComponentMessages.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/ComponentMessages.java
Fri Jun 15 19:59:51 2007
@@ -37,4 +37,9 @@
return MESSAGES.format("failure-instantitating-object", ClassFabUtils
.toJavaClassName(objectType), componentId, cause);
}
+
+ static String conflictingEncodingType(String existing, String conflicting)
+ {
+ return MESSAGES.format("conflicting-encoding-type", existing,
conflicting);
+ }
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Form.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Form.java?view=diff&rev=547850&r1=547849&r2=547850
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Form.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Form.java
Fri Jun 15 19:59:51 2007
@@ -161,6 +161,8 @@
private FormSupportImpl _formSupport;
+ private Element _form;
+
private Element _div;
@Inject
@@ -225,7 +227,11 @@
_resources.triggerEvent(PREPARE, contextArray, null);
Link link =
_resources.createActionLink(TapestryConstants.ACTION_EVENT, true, contextArray);
- writer.element("form", "name", _name, "id", _name, "method", "post",
"action", link);
+
+ // Save the form element for later, in case we want to write an
encoding type attribute.
+
+ _form = writer
+ .element("form", "name", _name, "id", _name, "method", "post",
"action", link);
_resources.renderInformalParameters(writer);
@@ -257,6 +263,10 @@
_environment.peek(Heartbeat.class).end();
_formSupport.executeDeferred();
+
+ String encodingType = _formSupport.getEncodingType();
+
+ if (encodingType != null) _form.forceAttributes("enctype",
encodingType);
writer.end(); // form
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/FormSupportImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/FormSupportImpl.java?view=diff&rev=547850&r1=547849&r2=547850
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/FormSupportImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/FormSupportImpl.java
Fri Jun 15 19:59:51 2007
@@ -16,6 +16,7 @@
import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
import static org.apache.tapestry.ioc.internal.util.Defense.cast;
+import static org.apache.tapestry.ioc.internal.util.Defense.notBlank;
import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
import java.io.IOException;
@@ -44,6 +45,8 @@
private List<Runnable> _commands;
+ private String _encodingType;
+
/** Constructor used when processing a form submission. */
public FormSupportImpl()
{
@@ -112,4 +115,22 @@
{
return _clientId;
}
+
+ String getEncodingType()
+ {
+ return _encodingType;
+ }
+
+ public void setEncodingType(String encodingType)
+ {
+ notBlank(encodingType, "encodingType");
+
+ if (_encodingType != null && !_encodingType.equals(encodingType))
+ throw new
IllegalStateException(ComponentMessages.conflictingEncodingType(
+ _encodingType,
+ encodingType));
+
+ _encodingType = encodingType;
+ }
+
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FormSupport.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FormSupport.java?view=diff&rev=547850&r1=547849&r2=547850
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FormSupport.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FormSupport.java
Fri Jun 15 19:59:51 2007
@@ -49,4 +49,14 @@
* @param command
*/
void defer(Runnable command);
+
+ /**
+ * Sets the encoding type for the Form. This should only be set once, and
if
+ *
+ * @param encodingType
+ * MIME type indicating type of encoding for the form
+ * @throws IllegalStateException
+ * if the encoding type has already been set to a value
different than the supplied
+ */
+ void setEncodingType(String encodingType);
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/ComponentStrings.properties
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/ComponentStrings.properties?view=diff&rev=547850&r1=547849&r2=547850
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/ComponentStrings.properties
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/ComponentStrings.properties
Fri Jun 15 19:59:51 2007
@@ -14,4 +14,5 @@
component-action-not-serializable=Error serializing component action for
component %s: %s
enclose-errors-in-form=The Errors component must be enclosed by a Form
component.
-failure-instantitating-object=Exception instantiating instance of %s (for
component '%s'): %s
\ No newline at end of file
+failure-instantitating-object=Exception instantiating instance of %s (for
component '%s'): %s
+conflicting-encoding-type=Encoding type of form has already been set to '%s'
and may not be changed to '%s'.
\ No newline at end of file
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/FormEncodingType.html
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/FormEncodingType.html?view=auto&rev=547850
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/FormEncodingType.html
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/FormEncodingType.html
Fri Jun 15 19:59:51 2007
@@ -0,0 +1,17 @@
+<html t:type="Border"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+ <h1>Form Encoding Type Demo</h1>
+
+
+ <t:form>
+
+ <p>
+ Not much to see here, unless you check the DOM.
+ </p>
+
+ <t:delegate to="forceEncodingType"/>
+
+ </t:form>
+
+
+</html>
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/Start.html
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/Start.html?view=diff&rev=547850&r1=547849&r2=547850
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/Start.html
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/Start.html Fri
Jun 15 19:59:51 2007
@@ -131,6 +131,9 @@
<t:pagelink page="ReturnTypes">Return Types</t:pagelink> -- Tests
various event handler
return types
</li>
+ <li>
+ <t:pagelink page="FormEncodingType">Form Encoding
Type</t:pagelink> --- Test ability to set an encoding type for a Form
+ </li>
</ul>
</td>
</tr>
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/components/FormSupportImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/components/FormSupportImplTest.java?view=diff&rev=547850&r1=547849&r2=547850
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/components/FormSupportImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/components/FormSupportImplTest.java
Fri Jun 15 19:59:51 2007
@@ -83,4 +83,50 @@
verify();
}
+
+ @Test
+ public void set_encoding_type()
+ {
+ FormSupportImpl support = new FormSupportImpl();
+
+ String encodingType = "foo/bar";
+
+ support.setEncodingType(encodingType);
+
+ assertSame(support.getEncodingType(), encodingType);
+ }
+
+ @Test
+ public void set_encoding_type_to_same_value_is_allowed()
+ {
+ FormSupportImpl support = new FormSupportImpl();
+
+ String encodingType = "foo/bar";
+
+ support.setEncodingType(encodingType);
+ support.setEncodingType(new String(encodingType));
+
+ assertEquals(support.getEncodingType(), encodingType);
+ }
+
+ @Test
+ public void set_encoding_type_conflict()
+ {
+
+ FormSupportImpl support = new FormSupportImpl();
+
+ support.setEncodingType("foo");
+ try
+ {
+ support.setEncodingType("bar");
+ unreachable();
+ }
+ catch (IllegalStateException ex)
+ {
+ assertEquals(
+ ex.getMessage(),
+ "Encoding type of form has already been set to \'foo\' and
may not be changed to \'bar\'.");
+ }
+
+ }
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?view=diff&rev=547850&r1=547849&r2=547850
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
Fri Jun 15 19:59:51 2007
@@ -1021,4 +1021,14 @@
assertTextPresent("Currently on page: GridDemo");
}
+ @Test
+ public void form_encoding_type()
+ {
+ open(BASE_URL);
+
+ clickAndWait("link=Form Encoding Type");
+
+ assertText("//form/@enctype", "x-override");
+ }
+
}
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormEncodingType.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormEncodingType.java?view=auto&rev=547850
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormEncodingType.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormEncodingType.java
Fri Jun 15 19:59:51 2007
@@ -0,0 +1,37 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.integration.app1.pages;
+
+import org.apache.tapestry.MarkupWriter;
+import org.apache.tapestry.Renderable;
+import org.apache.tapestry.annotations.Environmental;
+import org.apache.tapestry.services.FormSupport;
+
+public class FormEncodingType
+{
+ @Environmental
+ private FormSupport _support;
+
+ public Renderable getForceEncodingType()
+ {
+ return new Renderable()
+ {
+ public void render(MarkupWriter writer)
+ {
+ _support.setEncodingType("x-override");
+ }
+ };
+ }
+}