Author: musachy
Date: Mon Dec 15 14:48:10 2008
New Revision: 726866
URL: http://svn.apache.org/viewvc?rev=726866&view=rev
Log:
Add label, hidden and password handlers
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/HiddenHandler.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/LabelHandler.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/PasswordHandler.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/HiddenTest.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/LabelTest.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/PasswordTest.java
Modified:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/HiddenHandler.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/HiddenHandler.java?rev=726866&view=auto
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/HiddenHandler.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/HiddenHandler.java
Mon Dec 15 14:48:10 2008
@@ -0,0 +1,45 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.struts2.views.java.simple;
+
+import org.apache.struts2.views.java.Attributes;
+import org.apache.struts2.views.java.TagGenerator;
+
+import java.io.IOException;
+import java.util.Map;
+
+public class HiddenHandler extends AbstractTagHandler implements TagGenerator {
+
+ public void generate() throws IOException {
+ Map<String, Object> params = context.getParameters();
+ Attributes a = new Attributes();
+
+ a.addDefaultToEmpty("name", params.get("name"))
+ .add("type", "hidden")
+ .addIfExists("value", params.get("nameValue"), false)
+ .addIfTrue("disabled", params.get("disabled"))
+ .addIfExists("id", params.get("id"))
+ .addIfExists("class", params.get("cssClass"))
+ .addIfExists("style", params.get("cssStyle"));
+ super.start("input", a);
+ super.end("input");
+ }
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/LabelHandler.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/LabelHandler.java?rev=726866&view=auto
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/LabelHandler.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/LabelHandler.java
Mon Dec 15 14:48:10 2008
@@ -0,0 +1,44 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.struts2.views.java.simple;
+
+import org.apache.struts2.views.java.TagGenerator;
+import org.apache.struts2.views.java.Attributes;
+
+import java.io.IOException;
+import java.util.Map;
+
+public class LabelHandler extends AbstractTagHandler implements TagGenerator {
+
+ public void generate() throws IOException {
+ Map<String, Object> params = context.getParameters();
+ Attributes a = new Attributes();
+
+ a.addDefaultToEmpty("name", params.get("name"))
+ .addIfExists("for", "for")
+ .addIfExists("id", params.get("id"))
+ .addIfExists("class", params.get("cssClass"))
+ .addIfExists("style", params.get("cssStyle"))
+ .addIfExists("title", params.get("title"));
+ super.start("label", a);
+ super.end("label");
+ }
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/PasswordHandler.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/PasswordHandler.java?rev=726866&view=auto
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/PasswordHandler.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/PasswordHandler.java
Mon Dec 15 14:48:10 2008
@@ -0,0 +1,54 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.struts2.views.java.simple;
+
+import org.apache.struts2.views.java.TagGenerator;
+import org.apache.struts2.views.java.Attributes;
+
+import java.io.IOException;
+import java.util.Map;
+
+public class PasswordHandler extends AbstractTagHandler implements
TagGenerator {
+
+ public void generate() throws IOException {
+ Map<String, Object> params = context.getParameters();
+ Attributes attrs = new Attributes();
+
+ Boolean showPassword = (Boolean) params.get("showPassword");
+ if (showPassword != null && showPassword)
+ attrs.addIfExists("value", params.get("nameValue"), false);
+
+ attrs.addDefaultToEmpty("name", params.get("name"))
+ .add("type", "password")
+ .addIfExists("size", params.get("size"))
+ .addIfExists("maxlength", params.get("maxlength"))
+ .addIfTrue("disabled", params.get("disabled"))
+ .addIfTrue("readonly", params.get("readonly"))
+ .addIfExists("tabindex", params.get("tabindex"))
+ .addIfExists("id", params.get("id"))
+ .addIfExists("class", params.get("cssClass"))
+ .addIfExists("style", params.get("cssStyle"))
+ .addIfExists("title", params.get("title"));
+ super.start("input", attrs);
+ super.end("input");
+ }
+}
+
Modified:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java?rev=726866&r1=726865&r2=726866&view=diff
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
(original)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
Mon Dec 15 14:48:10 2008
@@ -40,9 +40,12 @@
put("a", new FactoryList(AnchorHandler.class,
ScriptingEventsHandler.class, CommonAttributesHandler.class));
put("checkbox", new FactoryList(CheckboxHandler.class,
ScriptingEventsHandler.class, CommonAttributesHandler.class));
put("file", new FactoryList(FileHandler.class,
ScriptingEventsHandler.class, CommonAttributesHandler.class));
+ put("password", new FactoryList(PasswordHandler.class,
ScriptingEventsHandler.class, CommonAttributesHandler.class));
+ put("label", new FactoryList(LabelHandler.class,
ScriptingEventsHandler.class, CommonAttributesHandler.class));
put("actionerror", new FactoryList(ActionErrorHandler.class));
put("actionmessage", new FactoryList(ActionMessageHandler.class));
put("head", new FactoryList(HeadHandler.class));
+ put("hidden", new FactoryList(HiddenHandler.class));
put("fielderror", new FactoryList(FieldErrorHandler.class));
put("div", new FactoryList(DivHandler.class,
ScriptingEventsHandler.class, CommonAttributesHandler.class));
put("empty", new FactoryList(EmptyHandler.class));
Modified:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java?rev=726866&r1=726865&r2=726866&view=diff
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java
(original)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java
Mon Dec 15 14:48:10 2008
@@ -41,7 +41,7 @@
@Override
protected void setUp() throws Exception {
- super.setUp(); //To change body of overridden methods use File |
Settings | File Templates.
+ super.setUp();
scriptingAttrs.put("onclick", "onclick_");
scriptingAttrs.put("ondblclick", "ondblclick_");
scriptingAttrs.put("onmousedown", "onmousedown_");
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/HiddenTest.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/HiddenTest.java?rev=726866&view=auto
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/HiddenTest.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/HiddenTest.java
Mon Dec 15 14:48:10 2008
@@ -0,0 +1,65 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.struts2.views.java.simple;
+
+import org.apache.struts2.components.Hidden;
+import org.apache.struts2.components.UIBean;
+
+public class HiddenTest extends AbstractTest {
+ private Hidden tag;
+
+ public void testRenderHidden() {
+ tag.setName("name");
+ tag.setValue("val1");
+ tag.setDisabled("true");
+ tag.setTabindex("1");
+ tag.setId("id1");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<input name='name' type='hidden' value='val1'
id='id1' class='class1' style='style1'></input>");
+ assertEquals(expected, output);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.tag = new Hidden(stack, request, response);
+ }
+
+ @Override
+ protected UIBean getUIBean() {
+ return tag;
+ }
+
+ @Override
+ protected String getTagName() {
+ return "hidden";
+ }
+}
+
+
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/LabelTest.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/LabelTest.java?rev=726866&view=auto
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/LabelTest.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/LabelTest.java
Mon Dec 15 14:48:10 2008
@@ -0,0 +1,66 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.struts2.views.java.simple;
+
+import org.apache.struts2.components.Hidden;
+import org.apache.struts2.components.UIBean;
+import org.apache.struts2.components.Label;
+
+public class LabelTest extends AbstractCommonAttributesTest {
+ private Label tag;
+
+ public void testRenderLabel() {
+ tag.setName("name");
+ tag.setValue("val1");
+ tag.setId("id1");
+ tag.setFor("for_");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<label name='name' for='for' id='id1'
class='class1' style='style1' title='title'></label>");
+ assertEquals(expected, output);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.tag = new Label(stack, request, response);
+ }
+
+ @Override
+ protected UIBean getUIBean() {
+ return tag;
+ }
+
+ @Override
+ protected String getTagName() {
+ return "label";
+ }
+}
+
+
+
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/PasswordTest.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/PasswordTest.java?rev=726866&view=auto
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/PasswordTest.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/PasswordTest.java
Mon Dec 15 14:48:10 2008
@@ -0,0 +1,101 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.struts2.views.java.simple;
+
+import org.apache.struts2.components.File;
+import org.apache.struts2.components.UIBean;
+import org.apache.struts2.components.Password;
+import org.easymock.EasyMock;
+
+public class PasswordTest extends AbstractCommonAttributesTest {
+ private Password tag;
+ private boolean showPassword;
+
+ public void testRenderPassword() throws Exception {
+ this.showPassword = false;
+ super.setUp();
+ this.tag = new Password(stack, request, response);
+
+ tag.setName("name");
+ tag.setValue("val1");
+ tag.setSize("10");
+ tag.setDisabled("true");
+ tag.setTabindex("1");
+ tag.setId("id1");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<input name='name' type='password' size='10'
tabindex='1' id='id1' class='class1' style='style1' title='title'></input>");
+ assertEquals(expected, output);
+ }
+
+ public void testRenderPasswordShowIt() throws Exception {
+ this.showPassword = true;
+ super.setUp();
+ this.tag = new Password(stack, request, response);
+
+ tag.setName("name");
+ tag.setValue("val1");
+ tag.setSize("10");
+ tag.setDisabled("true");
+ tag.setTabindex("1");
+ tag.setId("id1");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+ tag.setShowPassword("%{'true'}");
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<input value='val1' name='name' type='password'
size='10' tabindex='1' id='id1' class='class1' style='style1'
title='title'></input>");
+ assertEquals(expected, output);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ //dont call base setup
+ }
+
+ @Override
+ protected void setUpStack() {
+ expectFind("'true'", Boolean.class, true);
+ }
+
+ @Override
+ protected UIBean getUIBean() {
+ return tag;
+ }
+
+ @Override
+ protected String getTagName() {
+ return "password";
+ }
+}
+
+