Author: musachy Date: Tue Dec 16 10:03:09 2008 New Revision: 727101 URL: http://svn.apache.org/viewvc?rev=727101&view=rev Log: Add a bunch of handlers (lazy to enumerate them)
Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.java struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextAreaHandler.java struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TokenHandler.java struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ResetTest.java struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TokenTest.java Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextFieldHandler.java Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java?rev=727101&r1=727100&r2=727101&view=diff ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java (original) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java Tue Dec 16 10:03:09 2008 @@ -20,8 +20,12 @@ */ package org.apache.struts2.views.java; -public class DefaultTagHandlerFactory implements TagHandlerFactory { +import com.opensymphony.xwork2.util.logging.Logger; +import com.opensymphony.xwork2.util.logging.LoggerFactory; +public class DefaultTagHandlerFactory implements TagHandlerFactory { + private static final Logger LOG = LoggerFactory.getLogger(DefaultTagHandlerFactory.class); + private Class tagHandlerClass; public DefaultTagHandlerFactory(Class tagHandlerClass) { @@ -34,14 +38,14 @@ th.setNext(next); return th; } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (LOG.isErrorEnabled()) + LOG.error("Failed to instantiate tag handler class [#0]", e, tagHandlerClass.getName()); } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (LOG.isErrorEnabled()) + LOG.error("Failed to instantiate tag handler class [#0]", e, tagHandlerClass.getName()); } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (LOG.isErrorEnabled()) + LOG.error("Failed to instantiate tag handler class [#0]", e, tagHandlerClass.getName()); } return null; } Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.java?rev=727101&view=auto ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.java (added) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.java Tue Dec 16 10:03:09 2008 @@ -0,0 +1,60 @@ +/* + * $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; + +import com.opensymphony.xwork2.util.TextUtils; + +public class ResetHandler extends AbstractTagHandler implements TagGenerator { + + public void generate() throws IOException { + Map<String, Object> params = context.getParameters(); + Attributes attrs = new Attributes(); + + boolean isButton = "button".equals(params.get("type")); + + attrs.addDefaultToEmpty("name", params.get("name")) + .add("type", "reset") + .addIfExists("value", params.get("nameValue"), false) + .addIfExists("tabindex", params.get("tabindex")) + .addIfExists("id", params.get("id")) + .addIfExists("class", params.get("cssClass")) + .addIfExists("style", params.get("cssStyle")); + + if (!isButton) + attrs.addIfExists("title", params.get("title")); + + super.start("input", attrs); + if (isButton) { + String label = (String) params.get("label"); + if (TextUtils.stringSet(label)) + characters(label); + } + + 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=727101&r1=727100&r2=727101&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 Tue Dec 16 10:03:09 2008 @@ -42,7 +42,11 @@ 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("reset", new FactoryList(ResetHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class)); + put("submit", new FactoryList(SubmitHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class)); + put("textarea", new FactoryList(TextAreaHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class)); put("actionerror", new FactoryList(ActionErrorHandler.class)); + put("token", new FactoryList(TokenHandler.class)); put("actionmessage", new FactoryList(ActionMessageHandler.class)); put("head", new FactoryList(HeadHandler.class)); put("hidden", new FactoryList(HiddenHandler.class)); Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java?rev=727101&view=auto ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java (added) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java Tue Dec 16 10:03:09 2008 @@ -0,0 +1,86 @@ +/* + * $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; + +import com.opensymphony.xwork2.util.TextUtils; + +public class SubmitHandler extends AbstractTagHandler implements TagGenerator { + + public void generate() throws IOException { + Map<String, Object> params = context.getParameters(); + Attributes attrs = new Attributes(); + + String type = TextUtils.noNull((String) params.get("type"), "input"); + String body = (String) params.get("body"); + + if ("button".equals(type)) { + attrs.addIfExists("name", params.get("name")) + .add("type", "submit") + .addIfExists("value", params.get("nameValue"), false) + .addIfTrue("disabled", params.get("disabled")) + .addIfExists("tabindex", params.get("tabindex")) + .addIfExists("id", params.get("id")) + .addIfExists("class", params.get("cssClass")) + .addIfExists("style", params.get("cssStyle")); + + start("button", attrs); + + //button body + if (TextUtils.stringSet(body)) + characters(body, false); + else if (params.containsKey("label")) { + String label = (String) params.get("label"); + if (TextUtils.stringSet(label)) + characters(label, false); + } + + end("button"); + } else if ("image".equals(type)) { + if (TextUtils.stringSet(body)) + characters(body, false); + attrs.addIfExists("src", params.get("src"), false) + .add("type", "image") + .addIfExists("alt", params.get("label")); + + start("input", attrs); + end("input"); + } else { + attrs.addIfExists("name", params.get("name")) + .addIfExists("value", params.get("nameValue"), false) + .addIfTrue("disabled", params.get("disabled")) + .addIfExists("tabindex", params.get("tabindex")) + .addIfExists("id", params.get("id")) + .addIfExists("class", params.get("cssClass")) + .addIfExists("style", params.get("cssStyle")); + + start("submit", attrs); + end("submit"); + } + } +} + + Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextAreaHandler.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextAreaHandler.java?rev=727101&view=auto ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextAreaHandler.java (added) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextAreaHandler.java Tue Dec 16 10:03:09 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; + +import com.opensymphony.xwork2.util.TextUtils; + +public class TextAreaHandler extends AbstractTagHandler implements TagGenerator { + + public void generate() throws IOException { + Map<String, Object> params = context.getParameters(); + Attributes attrs = new Attributes(); + + attrs.addDefaultToEmpty("name", params.get("name")) + .addDefaultToEmpty("cols", params.get("cols")) + .addDefaultToEmpty("rows", params.get("rows")) + .addIfExists("wrap", params.get("wrap")) + .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("textarea", attrs); + String value = (String) params.get("nameValue"); + if (TextUtils.stringSet(value)) + characters(value); + super.end("textarea"); + } +} \ No newline at end of file Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextFieldHandler.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextFieldHandler.java?rev=727101&r1=727100&r2=727101&view=diff ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextFieldHandler.java (original) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextFieldHandler.java Tue Dec 16 10:03:09 2008 @@ -31,7 +31,6 @@ public void generate() throws IOException { Map<String, Object> params = context.getParameters(); Attributes a = new Attributes(); - a.put("type", "text"); a.addDefaultToEmpty("name", params.get("name")) .addIfExists("size", params.get("size")) Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TokenHandler.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TokenHandler.java?rev=727101&view=auto ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TokenHandler.java (added) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TokenHandler.java Tue Dec 16 10:03:09 2008 @@ -0,0 +1,53 @@ +/* + * $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 TokenHandler extends AbstractTagHandler implements TagGenerator { + + public void generate() throws IOException { + Map<String, Object> params = context.getParameters(); + Attributes attrs = new Attributes(); + + //first input + attrs.add("type", "hidden") + .addDefaultToEmpty("name", params.get("tokenNameField"), false) + .addDefaultToEmpty("value", params.get("name")); + + start("input", attrs); + end("input"); + + //second input + attrs = new Attributes(); + attrs.add("type", "hidden") + .addDefaultToEmpty("name", params.get("name"), false) + .addDefaultToEmpty("value", params.get("token")); + + start("input", attrs); + end("input"); + } +} + Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ResetTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ResetTest.java?rev=727101&view=auto ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ResetTest.java (added) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ResetTest.java Tue Dec 16 10:03:09 2008 @@ -0,0 +1,86 @@ +/* + * $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.Reset; + +public class ResetTest extends AbstractCommonAttributesTest { + private Reset tag; + + public void testRenderResetButton() { + tag.setName("name"); + tag.setValue("val1"); + tag.setTabindex("1"); + tag.setId("id1"); + tag.setCssClass("class1"); + tag.setCssStyle("style1"); + tag.setTitle("title"); + tag.setType("button"); + tag.setLabel("some label"); + + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + String output = writer.getBuffer().toString(); + String expected = s("<input name='name' type='reset' value='val1' tabindex='1' id='id1' class='class1' style='style1'>some label</input>"); + assertEquals(expected, output); + } + + public void testRenderResetNoType() { + tag.setName("name"); + tag.setValue("val1"); + tag.setTabindex("1"); + tag.setId("id1"); + tag.setCssClass("class1"); + tag.setCssStyle("style1"); + tag.setTitle("title"); + tag.setLabel("some label"); + + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + String output = writer.getBuffer().toString(); + String expected = s("<input name='name' type='reset' value='val1' tabindex='1' id='id1' class='class1' style='style1' title='title'></input>"); + assertEquals(expected, output); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + this.tag = new Reset(stack, request, response); + } + + @Override + protected UIBean getUIBean() { + return tag; + } + + @Override + protected String getTagName() { + return "reset"; + } +} + + Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java?rev=727101&view=auto ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java (added) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java Tue Dec 16 10:03:09 2008 @@ -0,0 +1,143 @@ +/* + * $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.Submit; + +public class SubmitTest extends AbstractCommonAttributesTest { + private Submit tag; + + public void testRenderButtonWithBody() { + 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.setLabel("some label"); + tag.setType("button"); + tag.addParameter("body", "<span>hey hey hey, here I go now</span>"); + + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + String output = writer.getBuffer().toString(); + String expected = s("<button name='name' type='submit' value='val1' tabindex='1' id='id1' class='class1' style='style1'><span>hey hey hey, here I go now</span></button>"); + assertEquals(expected, output); + } + + public void testRenderButtonWithLabel() { + 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.setLabel("Just as soon as I belong, than it's time I disappear"); + tag.setType("button"); + + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + String output = writer.getBuffer().toString(); + String expected = s("<button name='name' type='submit' value='val1' tabindex='1' id='id1' class='class1' style='style1'>Just as soon as I belong, than it's time I disappear</button>"); + assertEquals(expected, output); + } + + public void testRenderButtonSubmit() { + 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.setLabel("label"); + tag.setType("input"); + + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + String output = writer.getBuffer().toString(); + String expected = s("<submit name='name' value='val1' tabindex='1' id='id1' class='class1' style='style1'></submit>"); + assertEquals(expected, output); + } + + public void testRenderButtonWithoutType() { + 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.setLabel("label"); + + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + String output = writer.getBuffer().toString(); + String expected = s("<submit name='name' value='val1' tabindex='1' id='id1' class='class1' style='style1'></submit>"); + assertEquals(expected, output); + } + + public void testRenderButtonImage() { + tag.setSrc("http://somesource/image.gif"); + tag.setLabel("alt text"); + tag.setType("image"); + + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + String output = writer.getBuffer().toString(); + String expected = s("<button name='name' type='submit' value='val1' tabindex='1' id='id1' class='class1' style='style1'><span>hey hey hey, here I go now</span></button>"); + assertEquals(expected, output); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + this.tag = new Submit(stack, request, response); + } + + @Override + protected UIBean getUIBean() { + return tag; + } + + @Override + protected String getTagName() { + return "submit"; + } +} Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java?rev=727101&view=auto ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java (added) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java Tue Dec 16 10:03:09 2008 @@ -0,0 +1,86 @@ +/* + * $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.TextField; +import org.apache.struts2.components.UIBean; +import org.apache.struts2.components.TextArea; + +public class TextAreaTest extends AbstractCommonAttributesTest { + private TextArea tag; + + public void testRenderTextArea() { + tag.setName("name"); + tag.setValue("val1"); + tag.setDisabled("true"); + tag.setReadonly("true"); + tag.setTabindex("1"); + tag.setId("id1"); + tag.setCssClass("class1"); + tag.setCssStyle("style1"); + tag.setTitle("title"); + tag.setRows("1"); + tag.setCols("2"); + + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + String output = writer.getBuffer().toString(); + String expected = s("<textarea name='name' cols='2' rows='1' tabindex='1' id='id1' class='class1' style='style1' title='title'>val1</textarea>"); + assertEquals(expected, output); + } + + public void testRenderTextAreaDefaults() { + tag.setValue("val1"); + tag.setDisabled("true"); + tag.setReadonly("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("<textarea name='' cols='' rows='' tabindex='1' id='id1' class='class1' style='style1' title='title'>val1</textarea>"); + assertEquals(expected, output); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + this.tag = new TextArea(stack, request, response); + } + + @Override + protected UIBean getUIBean() { + return tag; + } + + @Override + protected String getTagName() { + return "textarea"; + } +} Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TokenTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TokenTest.java?rev=727101&view=auto ============================================================================== --- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TokenTest.java (added) +++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TokenTest.java Tue Dec 16 10:03:09 2008 @@ -0,0 +1,69 @@ +/* + * $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.TextField; +import org.apache.struts2.components.UIBean; +import org.apache.struts2.components.Token; +import com.opensymphony.xwork2.ActionContext; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + +public class TokenTest extends AbstractTest { + private Token tag; + + public void testRenderTokenTag() { + tag.setName("name"); + tag.setValue("val1"); + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + String output = writer.getBuffer().toString(); + + + //token id is random + String pattern = s("<input type='hidden' name='struts.token.name' value='name'></input><input type='hidden' name='name' value='.*?'></input>"); + assertTrue(Pattern.matches(pattern, output)); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + this.tag = new Token(stack, request, response); + + Map map = new HashMap(); + map.put(ActionContext.SESSION, new HashMap()); + ActionContext.setContext(new ActionContext(map)); + } + + @Override + protected UIBean getUIBean() { + return tag; + } + + @Override + protected String getTagName() { + return "token"; + } +}