mirror of
https://github.com/apache/struts.git
synced 2026-08-05 22:56:59 +00:00
WW-2933 Move Java Templates plugin out of the sandbox
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@728738 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.1.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-javatemplates-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Struts 2 Java Templates Plugin</name>
|
||||
|
||||
<scm>
|
||||
<connection>scm:svn:http://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-javatemplates-plugin/</connection>
|
||||
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-javatemplates-plugin/</developerConnection>
|
||||
<url>http://svn.apache.org/viewcvs.cgi/struts/sandbox/trunk/struts2-javatemplates-plugin/</url>
|
||||
</scm>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymockclassextension</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<inherited>true</inherited>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* $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;
|
||||
|
||||
import com.opensymphony.xwork2.util.TextUtils;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* Map of tag attributes, used for rendering the tags
|
||||
*/
|
||||
public class Attributes extends LinkedHashMap<String, String> {
|
||||
|
||||
public Attributes add(String key, String value) {
|
||||
return add(key, value, true);
|
||||
}
|
||||
|
||||
public Attributes add(String key, String value, boolean encode) {
|
||||
put(key, (encode ? TextUtils.htmlEncode(value) : value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a key/value pair to the attributes only if the value is not null. Value
|
||||
* is html encoded
|
||||
* @param attrName attribute name
|
||||
* @param paramValue value of attribute
|
||||
* @return this
|
||||
*/
|
||||
public Attributes addIfExists(String attrName, Object paramValue) {
|
||||
return addIfExists(attrName, paramValue, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a key/value pair to the attributes only if the value is not null.
|
||||
* @param attrName attribute name
|
||||
* @param paramValue value of attribute
|
||||
* @param encode html encode the value
|
||||
* @return this
|
||||
*/
|
||||
public Attributes addIfExists(String attrName, Object paramValue, boolean encode) {
|
||||
if (paramValue != null) {
|
||||
String val = paramValue.toString();
|
||||
if (val.trim().length() > 0)
|
||||
put(attrName, (encode ? TextUtils.htmlEncode(val) : val));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a key/value pair to the attributes only if the value is not null and is a boolean with a
|
||||
* value of 'true'. Value is html encoded
|
||||
* @param attrName attribute name
|
||||
* @param paramValue value of attribute
|
||||
* @return this
|
||||
*/
|
||||
public Attributes addIfTrue(String attrName, Object paramValue) {
|
||||
if (paramValue != null) {
|
||||
if ((paramValue instanceof Boolean && ((Boolean) paramValue).booleanValue()) ||
|
||||
(Boolean.valueOf(paramValue.toString()).booleanValue())) {
|
||||
put(attrName, attrName);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a key/value pair to the attributes, if the value is null, it will be set as an empty string.
|
||||
* Value is html encoded.
|
||||
* @param attrName attribute name
|
||||
* @param paramValue value of attribute
|
||||
* @return this
|
||||
*/
|
||||
public Attributes addDefaultToEmpty(String attrName, Object paramValue) {
|
||||
return addDefaultToEmpty(attrName, paramValue, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a key/value pair to the attributes, if the value is null, it will be set as an empty string.
|
||||
* @param attrName attribute name
|
||||
* @param paramValue value of attribute
|
||||
* @param encode html encode the value
|
||||
* @return this
|
||||
*/
|
||||
public Attributes addDefaultToEmpty(String attrName, Object paramValue, boolean encode) {
|
||||
if (paramValue != null) {
|
||||
String val = paramValue.toString();
|
||||
put(attrName, (encode ? TextUtils.htmlEncode(val) : val));
|
||||
} else {
|
||||
put(attrName, "");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* $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;
|
||||
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Default implementation of TagHandlerFactory
|
||||
*/
|
||||
public class DefaultTagHandlerFactory implements TagHandlerFactory {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DefaultTagHandlerFactory.class);
|
||||
|
||||
private Class tagHandlerClass;
|
||||
|
||||
public DefaultTagHandlerFactory(Class tagHandlerClass) {
|
||||
this.tagHandlerClass = tagHandlerClass;
|
||||
}
|
||||
|
||||
public TagHandler create(TagHandler next) {
|
||||
try {
|
||||
TagHandler th = (TagHandler) tagHandlerClass.newInstance();
|
||||
th.setNext(next);
|
||||
return th;
|
||||
} catch (Exception e) {
|
||||
if (LOG.isErrorEnabled())
|
||||
LOG.error("Failed to instantiate tag handler class [#0]", e, tagHandlerClass.getName());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* $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;
|
||||
|
||||
import org.apache.struts2.StrutsException;
|
||||
import org.apache.struts2.components.template.TemplateRenderingContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Default implementation of the theme
|
||||
*/
|
||||
public class DefaultTheme implements Theme {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DefaultTheme.class);
|
||||
|
||||
private String name;
|
||||
private Map<String, List<TagHandlerFactory>> handlerFactories;
|
||||
|
||||
protected void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected void setHandlerFactories(Map<String, List<TagHandlerFactory>> handlers) {
|
||||
this.handlerFactories = handlers;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void renderTag(String tagName, TemplateRenderingContext context) {
|
||||
if (tagName.endsWith(".java")) {
|
||||
tagName = tagName.substring(0, tagName.length() - ".java".length());
|
||||
}
|
||||
|
||||
List<TagHandler> handlers = new ArrayList<TagHandler>();
|
||||
List<TagHandlerFactory> factories = handlerFactories.get(tagName);
|
||||
if (factories == null) {
|
||||
throw new StrutsException("Unable to find handlers for tag " + tagName);
|
||||
}
|
||||
|
||||
TagHandler prev = null;
|
||||
for (int x = factories.size() - 1; x >= 0; x--) {
|
||||
prev = factories.get(x).create(prev);
|
||||
prev.setup(context);
|
||||
handlers.add(0, prev);
|
||||
}
|
||||
|
||||
TagSerializer ser = (TagSerializer) handlers.get(handlers.size() - 1);
|
||||
|
||||
TagGenerator gen = (TagGenerator) handlers.get(0);
|
||||
try {
|
||||
if (LOG.isTraceEnabled())
|
||||
LOG.trace("Rendering tag [#0]", tagName);
|
||||
gen.generate();
|
||||
} catch (IOException ex) {
|
||||
throw new StrutsException("Unable to write tag: " + tagName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* $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;
|
||||
|
||||
import org.apache.struts2.StrutsException;
|
||||
import org.apache.struts2.components.template.BaseTemplateEngine;
|
||||
import org.apache.struts2.components.template.Template;
|
||||
import org.apache.struts2.components.template.TemplateRenderingContext;
|
||||
import org.apache.struts2.views.java.simple.SimpleTheme;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Template engine that renders tags using java implementations
|
||||
*/
|
||||
public class JavaTemplateEngine extends BaseTemplateEngine {
|
||||
|
||||
private Themes themes = new Themes() {{
|
||||
add(new SimpleTheme());
|
||||
}};
|
||||
|
||||
@Override
|
||||
protected String getSuffix() {
|
||||
return "java";
|
||||
}
|
||||
|
||||
public void renderTemplate(TemplateRenderingContext templateContext)
|
||||
throws Exception {
|
||||
Template t = templateContext.getTemplate();
|
||||
Theme theme = themes.get(t.getTheme());
|
||||
if (theme == null) {
|
||||
throw new StrutsException("Cannot render tag [" + t.getName() + "] because theme [" + t.getTheme() + "] was not found.");
|
||||
}
|
||||
theme.renderTag(t.getName(), templateContext);
|
||||
}
|
||||
|
||||
private class Themes {
|
||||
private HashMap<String, Theme> themes = new HashMap<String, Theme>();
|
||||
|
||||
public void add(Theme theme) {
|
||||
themes.put(theme.getName(), theme);
|
||||
}
|
||||
|
||||
public Theme get(String name) {
|
||||
return themes.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* $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;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface TagGenerator extends TagHandler {
|
||||
|
||||
public void generate() throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* $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;
|
||||
|
||||
import org.apache.struts2.components.template.TemplateRenderingContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface TagHandler {
|
||||
|
||||
void setNext(TagHandler next);
|
||||
|
||||
void setup(TemplateRenderingContext context);
|
||||
|
||||
/**
|
||||
* Write a tag openening, with its attributes
|
||||
* @param name name of the tag
|
||||
* @param attributes attributes of the tag
|
||||
* @throws IOException
|
||||
*/
|
||||
void start(String name, Attributes attributes) throws IOException;
|
||||
|
||||
/**
|
||||
* Writes a tag close
|
||||
* @param name name of the tag
|
||||
* @throws IOException
|
||||
*/
|
||||
void end(String name) throws IOException;
|
||||
|
||||
/**
|
||||
* Writes to the inner text of a tag. By default the body is html encoded
|
||||
* @param text tag body.
|
||||
* @throws IOException
|
||||
*/
|
||||
void characters(String text) throws IOException;
|
||||
|
||||
/**
|
||||
* Writes to the inner text of a tag
|
||||
* @param text tag body
|
||||
* @param encode html encode the body
|
||||
* @throws IOException
|
||||
*/
|
||||
void characters(String text, boolean encode) throws IOException;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* $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;
|
||||
|
||||
public interface TagHandlerFactory {
|
||||
|
||||
public TagHandler create(TagHandler next);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* $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;
|
||||
|
||||
/**
|
||||
* Implementations of this class build the html representation of the tag
|
||||
*/
|
||||
public interface TagSerializer extends TagHandler {
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* $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;
|
||||
|
||||
import org.apache.struts2.components.template.TemplateRenderingContext;
|
||||
|
||||
public interface Theme {
|
||||
public String getName();
|
||||
|
||||
public void renderTag(String name, TemplateRenderingContext context);
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* $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;
|
||||
|
||||
import com.opensymphony.xwork2.util.TextUtils;
|
||||
import org.apache.struts2.components.template.TemplateRenderingContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Write tags as XHTML
|
||||
*/
|
||||
public class XHTMLTagSerializer implements TagSerializer {
|
||||
|
||||
private Writer writer;
|
||||
|
||||
public void characters(String text) throws IOException {
|
||||
characters(text, true);
|
||||
}
|
||||
|
||||
public void characters(String text, boolean encode) throws IOException {
|
||||
writer.write(encode ? TextUtils.htmlEncode(text) : text);
|
||||
}
|
||||
|
||||
public void end(String name) throws IOException {
|
||||
writer.write("</");
|
||||
writer.write(name);
|
||||
writer.write(">");
|
||||
}
|
||||
|
||||
public void setNext(TagHandler next) {
|
||||
}
|
||||
|
||||
public void start(String name, Attributes attrs) throws IOException {
|
||||
writer.write("<");
|
||||
writer.write(name);
|
||||
if (attrs != null) {
|
||||
for (String key : attrs.keySet()) {
|
||||
writer.write(" ");
|
||||
writer.write(key);
|
||||
writer.write("=\"");
|
||||
writer.write(attrs.get(key));
|
||||
writer.write("\"");
|
||||
}
|
||||
}
|
||||
|
||||
writer.write(">");
|
||||
}
|
||||
|
||||
public void setup(TemplateRenderingContext context) {
|
||||
this.writer = context.getWriter();
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* $Id: AbstractTagHandler.java 726340 2008-12-14 02:45:05Z musachy $
|
||||
*
|
||||
* 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.util.MakeIterator;
|
||||
import org.apache.struts2.views.java.Attributes;
|
||||
import org.apache.struts2.views.java.TagGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Base class for ActionError and ActionMessage
|
||||
*/
|
||||
public abstract class AbstractMessageListHandler extends AbstractTagHandler implements TagGenerator {
|
||||
@Override
|
||||
public void generate() throws IOException {
|
||||
Map<String, Object> params = context.getParameters();
|
||||
Object errorsObj = findValue(getListExpression());
|
||||
|
||||
if (errorsObj != null) {
|
||||
Iterator itt = MakeIterator.convert(errorsObj);
|
||||
if (itt.hasNext()) {
|
||||
Attributes attrs = new Attributes();
|
||||
attrs.addIfExists("style", params.get("cssStyle"))
|
||||
.add("class", params.containsKey("cssClass") ? (String) params.get("cssClass") : getDefaultClass());
|
||||
start("ul", attrs);
|
||||
while (itt.hasNext()) {
|
||||
String error = (String) itt.next();
|
||||
|
||||
//li for each error
|
||||
start("li", null);
|
||||
|
||||
//span for error
|
||||
start("span", null);
|
||||
characters(error);
|
||||
end("span");
|
||||
end("li");
|
||||
|
||||
}
|
||||
end("ul");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Expression used to get list from stack
|
||||
*/
|
||||
protected abstract String getListExpression();
|
||||
|
||||
/*
|
||||
* default class for UL element
|
||||
*/
|
||||
protected abstract String getDefaultClass();
|
||||
}
|
||||
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* $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 com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.components.template.TemplateRenderingContext;
|
||||
import org.apache.struts2.components.Component;
|
||||
import org.apache.struts2.views.java.Attributes;
|
||||
import org.apache.struts2.views.java.TagHandler;
|
||||
import org.apache.struts2.views.util.ContextUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class AbstractTagHandler implements TagHandler {
|
||||
|
||||
protected TagHandler nextTagHandler;
|
||||
protected TemplateRenderingContext context;
|
||||
protected boolean altSyntax;
|
||||
|
||||
public void characters(String text) throws IOException {
|
||||
characters(text, true);
|
||||
}
|
||||
|
||||
public void characters(String text, boolean encode) throws IOException {
|
||||
if (nextTagHandler != null) {
|
||||
nextTagHandler.characters(text, encode);
|
||||
}
|
||||
}
|
||||
|
||||
public void end(String name) throws IOException {
|
||||
if (nextTagHandler != null) {
|
||||
nextTagHandler.end(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setNext(TagHandler next) {
|
||||
this.nextTagHandler = next;
|
||||
}
|
||||
|
||||
public void start(String name, Attributes a) throws IOException {
|
||||
if (nextTagHandler != null) {
|
||||
nextTagHandler.start(name, a);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setup(TemplateRenderingContext context) {
|
||||
this.context = context;
|
||||
this.altSyntax = ContextUtil.isUseAltSyntax(context.getStack().getContext());
|
||||
processParams();
|
||||
}
|
||||
|
||||
protected void processParams() {
|
||||
}
|
||||
|
||||
protected String findString(String expr) {
|
||||
return (String) findValue(expr, String.class);
|
||||
}
|
||||
|
||||
protected Object findValue(String expr) {
|
||||
if (expr == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ValueStack stack = context.getStack();
|
||||
return stack.findValue(Component.stripExpressionIfAltSyntax(stack, expr));
|
||||
}
|
||||
|
||||
private Object findValue(String expr, Class toType) {
|
||||
ValueStack stack = context.getStack();
|
||||
|
||||
if (altSyntax && toType == String.class) {
|
||||
return TextParseUtil.translateVariables('%', expr, stack);
|
||||
} else {
|
||||
return stack.findValue(Component.stripExpressionIfAltSyntax(stack, expr), toType);
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* $Id: SelectHandler.java 726340 2008-12-14 02:45:05Z musachy $
|
||||
*
|
||||
* 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;
|
||||
|
||||
public class ActionErrorHandler extends AbstractMessageListHandler {
|
||||
protected String getListExpression() {
|
||||
return "actionErrors";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultClass() {
|
||||
return "errorMessage";
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package org.apache.struts2.views.java.simple;
|
||||
|
||||
public class ActionMessageHandler extends AbstractMessageListHandler {
|
||||
protected String getListExpression() {
|
||||
return "actionMessages";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultClass() {
|
||||
return "actionMessage";
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* $Id: SelectHandler.java 726340 2008-12-14 02:45:05Z musachy $
|
||||
*
|
||||
* 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 AnchorHandler extends AbstractTagHandler implements TagGenerator {
|
||||
@Override
|
||||
public void generate() throws IOException {
|
||||
Map<String, Object> params = context.getParameters();
|
||||
Attributes attrs = new Attributes();
|
||||
|
||||
attrs.addIfExists("name", params.get("name"))
|
||||
.addIfExists("id", params.get("id"))
|
||||
.addIfExists("class", params.get("cssClass"))
|
||||
.addIfExists("style", params.get("cssStyle"))
|
||||
.addIfExists("href", params.get("href"), false)
|
||||
.addIfExists("title", params.get("title"))
|
||||
.addIfExists("tabindex", params.get("tabindex"));
|
||||
start("a", attrs);
|
||||
}
|
||||
|
||||
public static class CloseHandler extends AbstractTagHandler implements TagGenerator {
|
||||
@Override
|
||||
public void generate() throws IOException {
|
||||
end("a");
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package org.apache.struts2.views.java.simple;
|
||||
|
||||
import com.opensymphony.xwork2.util.TextUtils;
|
||||
import org.apache.struts2.views.java.Attributes;
|
||||
import org.apache.struts2.views.java.TagGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class CheckboxHandler extends AbstractTagHandler implements TagGenerator {
|
||||
@Override
|
||||
public void generate() throws IOException {
|
||||
Map<String, Object> params = context.getParameters();
|
||||
Attributes attrs = new Attributes();
|
||||
|
||||
String fieldValue = (String) params.get("fieldValue");
|
||||
String id = (String) params.get("id");
|
||||
String name = (String) params.get("name");
|
||||
Object disabled = params.get("disabled");
|
||||
|
||||
attrs.add("type", "checkbox")
|
||||
.add("name", name)
|
||||
.add("value", fieldValue)
|
||||
.addIfTrue("checked", params.get("nameValue"))
|
||||
.addIfTrue("readonly", params.get("readonly"))
|
||||
.addIfTrue("disabled", disabled)
|
||||
.addIfExists("tabindex", params.get("tabindex"))
|
||||
.addIfExists("id", id)
|
||||
.addIfExists("class", params.get("cssClass"))
|
||||
.addIfExists("style", params.get("cssStyle"))
|
||||
.addIfExists("title", params.get("title"));
|
||||
start("input", attrs);
|
||||
end("input");
|
||||
|
||||
//hidden input
|
||||
attrs = new Attributes();
|
||||
attrs.add("type", "hidden")
|
||||
.add("id", "__checkbox_" + TextUtils.htmlEncode(id))
|
||||
.add("name", "__checkbox_" + TextUtils.htmlEncode(name))
|
||||
.add("value", "__checkbox_" + TextUtils.htmlEncode(fieldValue))
|
||||
.addIfTrue("disabled", disabled);
|
||||
start("input", attrs);
|
||||
end("input");
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* $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 java.io.IOException;
|
||||
|
||||
/**
|
||||
* Adds attributes from common-attributes.ftl
|
||||
*/
|
||||
public class CommonAttributesHandler extends AbstractTagHandler {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.struts2.views.java.simple.AbstractTagHandler#start(java.lang.String, org.apache.struts2.views.java.Attributes)
|
||||
*/
|
||||
@Override
|
||||
public void start(String name, Attributes a) throws IOException {
|
||||
a.addIfExists("accesskey", context.getParameters().get("accesskey"));
|
||||
super.start(name, a);
|
||||
}
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* $Id: CommonAttributesHandler.java 726340 2008-12-14 02:45:05Z musachy $
|
||||
*
|
||||
* 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 DivHandler extends AbstractTagHandler implements TagGenerator {
|
||||
@Override
|
||||
public void generate() throws IOException {
|
||||
Map<String, Object> params = context.getParameters();
|
||||
Attributes attrs = new Attributes();
|
||||
attrs.addIfExists("name", params.get("name"))
|
||||
.addIfExists("id", params.get("id"))
|
||||
.addIfExists("class", params.get("cssClass"))
|
||||
.addIfExists("style", params.get("cssStyle"))
|
||||
.addIfExists("title", params.get("title"));
|
||||
start("div", attrs);
|
||||
}
|
||||
|
||||
public static class CloseHandler extends AbstractTagHandler implements TagGenerator {
|
||||
@Override
|
||||
public void generate() throws IOException {
|
||||
end("div");
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* $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 java.io.IOException;
|
||||
|
||||
//does nothing
|
||||
public class EmptyHandler extends AbstractTagHandler implements TagGenerator {
|
||||
@Override
|
||||
public void generate() throws IOException {
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* $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.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FieldErrorHandler extends AbstractTagHandler implements TagGenerator {
|
||||
public void generate() throws IOException {
|
||||
Map<String, Object> params = context.getParameters();
|
||||
Map<String, List<String>> errors = (Map<String, List<String>>) findValue("fieldErrors");
|
||||
List<String> fieldErrorFieldNames = (List<String>) params.get("errorFieldNames");
|
||||
|
||||
if (fieldErrorFieldNames != null && !fieldErrorFieldNames.isEmpty()) {
|
||||
//wrapping ul
|
||||
Attributes attrs = new Attributes();
|
||||
attrs.addIfExists("style", params.get("cssStyle"))
|
||||
.add("class", params.containsKey("cssClass") ? (String) params.get("cssClass") : "errorMessage");
|
||||
start("ul", attrs);
|
||||
|
||||
//iterate over field error names
|
||||
for (String fieldErrorFieldName : fieldErrorFieldNames) {
|
||||
List<String> fieldErrors = errors.get(fieldErrorFieldName);
|
||||
if (fieldErrors != null) {
|
||||
for (String fieldError : fieldErrors) {
|
||||
start("li", null);
|
||||
start("span", null);
|
||||
characters(fieldError);
|
||||
end("span");
|
||||
end("li");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end("ul");
|
||||
} else if (errors != null && !errors.isEmpty()) {
|
||||
//wrapping ul
|
||||
Attributes attrs = new Attributes();
|
||||
attrs.addIfExists("style", params.get("cssStyle"))
|
||||
.add("class", params.containsKey("cssClass") ? (String) params.get("cssClass") : "errorMessage");
|
||||
start("ul", attrs);
|
||||
|
||||
for (Map.Entry<String, List<String>> errorEntry : errors.entrySet()) {
|
||||
for (String fieldError : errorEntry.getValue()) {
|
||||
start("li", null);
|
||||
start("span", null);
|
||||
characters(fieldError);
|
||||
end("span");
|
||||
end("li");
|
||||
}
|
||||
}
|
||||
|
||||
end("ul");
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* $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 FileHandler 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", "file")
|
||||
.addIfExists("size", params.get("size"))
|
||||
.addIfExists("value", params.get("nameValue"), false)
|
||||
.addIfTrue("disabled", params.get("disabled"))
|
||||
.addIfExists("accept", params.get("accept"))
|
||||
.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", a);
|
||||
super.end("input");
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* $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 FormHandler extends AbstractTagHandler implements TagGenerator {
|
||||
public void generate() throws IOException {
|
||||
Map<String, Object> params = context.getParameters();
|
||||
Attributes attrs = new Attributes();
|
||||
|
||||
attrs.addIfExists("name", params.get("name"))
|
||||
.addIfExists("id", params.get("id"))
|
||||
.addIfExists("onsubmit", params.get("onsubmit"))
|
||||
.addIfExists("onreset", params.get("onreset"))
|
||||
.addIfExists("action", params.get("action"))
|
||||
.addIfExists("target", params.get("target"))
|
||||
.addIfExists("enctype", params.get("enctype"))
|
||||
.addIfExists("class", params.get("cssClass"))
|
||||
.addIfExists("style", params.get("cssStyle"))
|
||||
.addIfExists("title", params.get("title"))
|
||||
.addIfExists("accept-charset", params.get("acceptcharset"));
|
||||
attrs.add("method", params.containsKey("method") ? (String) params.get("method") : "post");
|
||||
start("form", attrs);
|
||||
}
|
||||
|
||||
public static class CloseHandler extends AbstractTagHandler implements TagGenerator {
|
||||
@Override
|
||||
public void generate() throws IOException {
|
||||
end("form");
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* $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 org.apache.struts2.ServletActionContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
|
||||
public class HeadHandler extends AbstractTagHandler implements TagGenerator {
|
||||
|
||||
public void generate() throws IOException {
|
||||
Map<String, Object> params = context.getParameters();
|
||||
Attributes attrs = new Attributes();
|
||||
attrs.put("type", "text/javascript");
|
||||
|
||||
String base = ServletActionContext.getRequest().getContextPath();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (base != null)
|
||||
sb.append(base);
|
||||
sb.append("/struts/utils.js");
|
||||
attrs.put("src", sb.toString());
|
||||
|
||||
super.start("script", attrs);
|
||||
super.end("script");
|
||||
}
|
||||
}
|
||||
+45
@@ -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");
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* $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 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", params.get("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);
|
||||
String value = (String) params.get("nameValue");
|
||||
if (TextUtils.stringSet(value))
|
||||
characters(value);
|
||||
super.end("label");
|
||||
}
|
||||
}
|
||||
+54
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
+60
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* $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 java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Adds attributes from scripting-event.ftl
|
||||
*/
|
||||
public class ScriptingEventsHandler extends AbstractTagHandler {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.struts2.views.java.simple.AbstractTagHandler#start(java.lang.String, org.apache.struts2.views.java.Attributes)
|
||||
*/
|
||||
@Override
|
||||
public void start(String name, Attributes a) throws IOException {
|
||||
Map params = context.getParameters();
|
||||
a.addIfExists("onclick", params.get("onclick"));
|
||||
a.addIfExists("ondblclick", params.get("ondblclick"));
|
||||
a.addIfExists("onmousedown", params.get("onmousedown"));
|
||||
a.addIfExists("onmouseup", params.get("onmouseup"));
|
||||
a.addIfExists("onmouseover", params.get("onmouseover"));
|
||||
a.addIfExists("onmousemove", params.get("onmousemove"));
|
||||
a.addIfExists("onmouseout", params.get("onmouseout"));
|
||||
a.addIfExists("onfocus", params.get("onfocus"));
|
||||
a.addIfExists("onblur", params.get("onblur"));
|
||||
a.addIfExists("onkeypress", params.get("onkeypress"));
|
||||
a.addIfExists("onkeydown", params.get("onkeydown"));
|
||||
a.addIfExists("onkeyup", params.get("onkeyup"));
|
||||
a.addIfExists("onselect", params.get("onselect"));
|
||||
a.addIfExists("onchange", params.get("onchange"));
|
||||
|
||||
super.start(name, a);
|
||||
}
|
||||
|
||||
}
|
||||
+143
@@ -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 com.opensymphony.xwork2.util.TextUtils;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.components.ListUIBean;
|
||||
import org.apache.struts2.components.OptGroup;
|
||||
import org.apache.struts2.util.ContainUtil;
|
||||
import org.apache.struts2.util.MakeIterator;
|
||||
import org.apache.struts2.views.java.Attributes;
|
||||
import org.apache.struts2.views.java.TagGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SelectHandler extends AbstractTagHandler implements TagGenerator {
|
||||
public void generate() throws IOException {
|
||||
Map<String, Object> params = context.getParameters();
|
||||
Attributes a = new Attributes();
|
||||
|
||||
Object value = params.get("nameValue");
|
||||
|
||||
a.addDefaultToEmpty("name", params.get("name"))
|
||||
.addIfExists("size", params.get("size"))
|
||||
.addIfExists("value", value, false)
|
||||
.addIfTrue("disabled", params.get("disabled"))
|
||||
.addIfTrue("readonly", params.get("readonly"))
|
||||
.addIfTrue("multiple", params.get("multiple"))
|
||||
.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("select", a);
|
||||
|
||||
//options
|
||||
|
||||
//header
|
||||
String headerKey = (String) params.get("headerKey");
|
||||
String headerValue = (String) params.get("headerValue");
|
||||
if (headerKey != null && headerValue != null) {
|
||||
boolean selected = ContainUtil.contains(value, params.get("headerKey"));
|
||||
writeOption(headerKey, headerValue, selected);
|
||||
}
|
||||
|
||||
Object listObj = params.get("list");
|
||||
String listKey = (String) params.get("listKey");
|
||||
String listValue = (String) params.get("listValue");
|
||||
ValueStack stack = this.context.getStack();
|
||||
if (listObj != null) {
|
||||
Iterator itt = MakeIterator.convert(listObj);
|
||||
while (itt.hasNext()) {
|
||||
Object item = itt.next();
|
||||
stack.push(item);
|
||||
|
||||
//key
|
||||
Object itemKey = findValue(listKey != null ? listKey : "top");
|
||||
String itemKeyStr = TextUtils.noNull(itemKey.toString());
|
||||
//value
|
||||
Object itemValue = findValue(listValue != null ? listValue : "top");
|
||||
String itemValueStr = TextUtils.noNull(itemValue.toString());
|
||||
|
||||
boolean selected = ContainUtil.contains(value, itemKey);
|
||||
writeOption(itemKeyStr, itemValueStr, selected);
|
||||
|
||||
stack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//opt group
|
||||
List<ListUIBean> listUIBeans = (List<ListUIBean>) params.get(OptGroup.INTERNAL_LIST_UI_BEAN_LIST_PARAMETER_KEY);
|
||||
if (listUIBeans != null) {
|
||||
for (ListUIBean listUIBean : listUIBeans) {
|
||||
writeOptionGroup(listUIBean, value);
|
||||
}
|
||||
}
|
||||
|
||||
super.end("select");
|
||||
}
|
||||
|
||||
private void writeOption(String value, String text, boolean selected) throws IOException {
|
||||
Attributes attrs = new Attributes();
|
||||
attrs.addIfExists("value", value)
|
||||
.addIfTrue("selected", selected);
|
||||
|
||||
start("option", attrs);
|
||||
characters(text);
|
||||
end("option");
|
||||
}
|
||||
|
||||
private void writeOptionGroup(ListUIBean listUIBean, Object value) throws IOException {
|
||||
Map params = listUIBean.getParameters();
|
||||
Attributes attrs = new Attributes();
|
||||
attrs.addIfExists("label", params.get("label"))
|
||||
.addIfTrue("disabled", params.get("disabled"));
|
||||
start("optgroup", attrs);
|
||||
|
||||
//options
|
||||
ValueStack stack = context.getStack();
|
||||
Object listObj = params.get("list");
|
||||
if (listObj != null) {
|
||||
Iterator itt = MakeIterator.convert(listObj);
|
||||
String listKey = (String) params.get("listKey");
|
||||
String listValue = (String) params.get("listValue");
|
||||
while (itt.hasNext()) {
|
||||
Object optGroupBean = itt.next();
|
||||
stack.push(optGroupBean);
|
||||
|
||||
Object tmpKey = stack.findValue(listKey != null ? listKey : "top");
|
||||
String tmpKeyStr = TextUtils.noNull(tmpKey.toString());
|
||||
Object tmpValue = stack.findValue(listValue != null ? listValue : "top");
|
||||
String tmpValueStr = TextUtils.noNull(tmpValue.toString());
|
||||
boolean selected = ContainUtil.contains(value, tmpKeyStr);
|
||||
writeOption(tmpKeyStr, tmpValueStr, selected);
|
||||
|
||||
stack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
end("optgroup");
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* $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.DefaultTagHandlerFactory;
|
||||
import org.apache.struts2.views.java.DefaultTheme;
|
||||
import org.apache.struts2.views.java.TagHandlerFactory;
|
||||
import org.apache.struts2.views.java.XHTMLTagSerializer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleTheme extends DefaultTheme {
|
||||
|
||||
public SimpleTheme() {
|
||||
setHandlerFactories(new HashMap<String, List<TagHandlerFactory>>() {{
|
||||
put("text", new FactoryList(TextFieldHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
|
||||
put("textfield", new FactoryList(TextFieldHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
|
||||
put("select", new FactoryList(SelectHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
|
||||
put("form", new FactoryList(FormHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
|
||||
put("form-close", new FactoryList(FormHandler.CloseHandler.class));
|
||||
put("a", new FactoryList(AnchorHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
|
||||
put("a-close", new FactoryList(AnchorHandler.CloseHandler.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("reset", new FactoryList(ResetHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
|
||||
put("submit", new FactoryList(SubmitHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
|
||||
put("submit-close", new FactoryList(SubmitHandler.CloseHandler.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));
|
||||
put("fielderror", new FactoryList(FieldErrorHandler.class));
|
||||
put("div", new FactoryList(DivHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
|
||||
put("div-close", new FactoryList(DivHandler.CloseHandler.class));
|
||||
put("empty", new FactoryList(EmptyHandler.class));
|
||||
}});
|
||||
setName("simple");
|
||||
}
|
||||
|
||||
private class FactoryList extends ArrayList<TagHandlerFactory> {
|
||||
public FactoryList(Class... classes) {
|
||||
super();
|
||||
for (Class cls : classes) {
|
||||
add(new DefaultTagHandlerFactory(cls));
|
||||
}
|
||||
add(new DefaultTagHandlerFactory(XHTMLTagSerializer.class));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* $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");
|
||||
|
||||
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);
|
||||
} else if ("image".equals(type)) {
|
||||
attrs.addIfExists("src", params.get("src"), false)
|
||||
.add("type", "image")
|
||||
.addIfExists("alt", params.get("label"));
|
||||
|
||||
start("input", attrs);
|
||||
} else {
|
||||
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("input", attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CloseHandler extends AbstractTagHandler implements TagGenerator {
|
||||
@Override
|
||||
public void generate() throws IOException {
|
||||
Map<String, Object> params = context.getParameters();
|
||||
Attributes attrs = new Attributes();
|
||||
String body = (String) params.get("body");
|
||||
|
||||
String type = TextUtils.noNull((String) params.get("type"), "input");
|
||||
if ("button".equals(type)) {
|
||||
//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);
|
||||
end("input");
|
||||
} else
|
||||
end("input");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+54
@@ -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"));
|
||||
start("textarea", attrs);
|
||||
String value = (String) params.get("nameValue");
|
||||
if (TextUtils.stringSet(value))
|
||||
characters(value);
|
||||
end("textarea");
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* $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 TextFieldHandler extends AbstractTagHandler implements TagGenerator {
|
||||
|
||||
public void generate() throws IOException {
|
||||
Map<String, Object> params = context.getParameters();
|
||||
Attributes attr = new Attributes();
|
||||
|
||||
attr.add("type", "text")
|
||||
.addDefaultToEmpty("name", params.get("name"))
|
||||
.addIfExists("size", params.get("size"))
|
||||
.addIfExists("maxlength", params.get("maxlength"))
|
||||
.addIfExists("value", params.get("nameValue"), false)
|
||||
.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", attr);
|
||||
super.end("input");
|
||||
}
|
||||
}
|
||||
+53
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<!DOCTYPE struts PUBLIC
|
||||
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
|
||||
"http://struts.apache.org/dtds/struts-2.0.dtd">
|
||||
|
||||
<struts>
|
||||
|
||||
<bean type="org.apache.struts2.components.template.TemplateEngine" name="java" class="org.apache.struts2.views.java.JavaTemplateEngine" />
|
||||
<constant name="struts.templateEngines" value="ftl,jsp,vm,java" />
|
||||
</struts>
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package org.apache.struts2.views.java.simple;
|
||||
|
||||
import org.apache.struts2.components.UIBean;
|
||||
|
||||
public abstract class AbstractCommonAttributesTest extends AbstractTest {
|
||||
public void testRenderTextFieldScriptingAttrs() throws Exception {
|
||||
UIBean tag = getUIBean();
|
||||
|
||||
applyScriptingAttrs(tag);
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
|
||||
assertScriptingAttrs(output);
|
||||
}
|
||||
|
||||
public void testRenderTextFieldCommonAttrs() throws Exception {
|
||||
UIBean tag = getUIBean();
|
||||
|
||||
|
||||
applyCommonAttrs(tag);
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
|
||||
assertCommongAttrs(output);
|
||||
}
|
||||
|
||||
}
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
package org.apache.struts2.views.java.simple;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.components.Component;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
import org.apache.struts2.components.template.Template;
|
||||
import org.apache.struts2.components.template.TemplateRenderingContext;
|
||||
import org.easymock.EasyMock;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
public abstract class AbstractTest extends TestCase {
|
||||
private Map<String, String> scriptingAttrs = new HashMap<String, String>();
|
||||
private Map<String, String> commonAttrs = new HashMap<String, String>();
|
||||
|
||||
protected SimpleTheme theme;
|
||||
|
||||
protected StringWriter writer;
|
||||
protected Map map;
|
||||
|
||||
protected Template template;
|
||||
protected Map stackContext;
|
||||
protected ValueStack stack;
|
||||
protected TemplateRenderingContext context;
|
||||
protected HttpServletRequest request;
|
||||
protected HttpServletResponse response;
|
||||
|
||||
protected abstract UIBean getUIBean() throws Exception;
|
||||
|
||||
protected abstract String getTagName();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
scriptingAttrs.put("onclick", "onclick_");
|
||||
scriptingAttrs.put("ondblclick", "ondblclick_");
|
||||
scriptingAttrs.put("onmousedown", "onmousedown_");
|
||||
scriptingAttrs.put("onmouseup", "onmouseup_");
|
||||
scriptingAttrs.put("onmouseover", "onmouseover_");
|
||||
scriptingAttrs.put("onmousemove", "onmousemove_");
|
||||
scriptingAttrs.put("onmouseout", "onmouseout_");
|
||||
scriptingAttrs.put("onfocus", "onfocus_");
|
||||
scriptingAttrs.put("onblur", "onblur_");
|
||||
scriptingAttrs.put("onkeypress", "onkeypress_");
|
||||
scriptingAttrs.put("onkeydown", "onkeydown_");
|
||||
scriptingAttrs.put("onkeyup", "onkeyup_");
|
||||
scriptingAttrs.put("onselect", "onselect_");
|
||||
scriptingAttrs.put("onchange", "onchange_");
|
||||
|
||||
commonAttrs.put("accesskey", "accesskey_");
|
||||
|
||||
theme = new SimpleTheme();
|
||||
writer = new StringWriter();
|
||||
map = new HashMap();
|
||||
|
||||
template = org.easymock.classextension.EasyMock.createMock(Template.class);
|
||||
stack = EasyMock.createNiceMock(ValueStack.class);
|
||||
setUpStack();
|
||||
stackContext = new HashMap();
|
||||
|
||||
context = new TemplateRenderingContext(template, writer, stack, map, null);
|
||||
stackContext.put(Component.COMPONENT_STACK, new Stack());
|
||||
|
||||
request = EasyMock.createNiceMock(HttpServletRequest.class);
|
||||
EasyMock.expect(request.getContextPath()).andReturn("/some/path").anyTimes();
|
||||
response = EasyMock.createNiceMock(HttpServletResponse.class);
|
||||
|
||||
EasyMock.expect(stack.getContext()).andReturn(stackContext).anyTimes();
|
||||
|
||||
Container container = EasyMock.createNiceMock(Container.class);
|
||||
XWorkConverter converter = new ConverterEx();
|
||||
EasyMock.expect(container.getInstance(String.class, StrutsConstants.STRUTS_TAG_ALTSYNTAX)).andReturn("true").anyTimes();
|
||||
EasyMock.expect(container.getInstance(XWorkConverter.class)).andReturn(converter).anyTimes();
|
||||
stackContext.put(ActionContext.CONTAINER, container);
|
||||
|
||||
|
||||
EasyMock.replay(request);
|
||||
EasyMock.replay(stack);
|
||||
EasyMock.replay(container);
|
||||
|
||||
ActionContext.setContext(new ActionContext(stackContext));
|
||||
ServletActionContext.setRequest(request);
|
||||
}
|
||||
|
||||
protected static String s(String input) {
|
||||
return input.replaceAll("'", "\"");
|
||||
}
|
||||
|
||||
protected void expectFind(String expr, Class toClass, Object returnVal) {
|
||||
EasyMock.expect(stack.findValue(expr, toClass)).andReturn(returnVal);
|
||||
}
|
||||
|
||||
protected void expectFind(String expr, Object returnVal) {
|
||||
EasyMock.expect(stack.findValue(expr)).andReturn(returnVal);
|
||||
}
|
||||
|
||||
protected void setUpStack() {
|
||||
//TODO setup a config with stack and all..for real
|
||||
}
|
||||
|
||||
protected void applyScriptingAttrs(UIBean bean) {
|
||||
bean.setOnclick(scriptingAttrs.get("onclick"));
|
||||
bean.setOndblclick(scriptingAttrs.get("ondblclick"));
|
||||
bean.setOnmousedown(scriptingAttrs.get("onmousedown"));
|
||||
bean.setOnmouseup(scriptingAttrs.get("onmouseup"));
|
||||
bean.setOnmouseover(scriptingAttrs.get("onmouseover"));
|
||||
bean.setOnmousemove(scriptingAttrs.get("onmousemove"));
|
||||
bean.setOnmouseout(scriptingAttrs.get("onmouseout"));
|
||||
bean.setOnfocus(scriptingAttrs.get("onfocus"));
|
||||
bean.setOnblur(scriptingAttrs.get("onblur"));
|
||||
bean.setOnkeypress(scriptingAttrs.get("onkeypress"));
|
||||
bean.setOnkeydown(scriptingAttrs.get("onkeydown"));
|
||||
bean.setOnkeyup(scriptingAttrs.get("onkeyup"));
|
||||
bean.setOnselect(scriptingAttrs.get("onselect"));
|
||||
bean.setOnchange(scriptingAttrs.get("onchange"));
|
||||
}
|
||||
|
||||
protected void applyCommonAttrs(UIBean bean) {
|
||||
bean.setAccesskey("accesskey_");
|
||||
}
|
||||
|
||||
protected void assertScriptingAttrs(String str) {
|
||||
for (Map.Entry<String, String> entry : scriptingAttrs.entrySet()) {
|
||||
String substr = entry.getKey() + "=\"" + entry.getValue() + "\"";
|
||||
assertTrue("String [" + substr + "] was not found in [" + str + "]", str.indexOf(substr) >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertCommongAttrs(String str) {
|
||||
for (Map.Entry<String, String> entry : commonAttrs.entrySet()) {
|
||||
String substr = entry.getKey() + "=\"" + entry.getValue() + "\"";
|
||||
assertTrue("String [" + substr + "] was not found in [" + str + "]", str.indexOf(substr) >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object doFindValue(String expr, Class toType) {
|
||||
Object val = stack.findValue(expr);
|
||||
|
||||
if (toType == String.class)
|
||||
return val == null ? expr : val;
|
||||
else
|
||||
return val == null ? null : val;
|
||||
}
|
||||
|
||||
//XWorkConverter doesnt have a public onstructor (the one with parameters will require mor config)
|
||||
public class ConverterEx extends XWorkConverter {
|
||||
public ConverterEx() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* $Id: Bean.java 726216 2008-12-13 14:58:16Z musachy $
|
||||
*
|
||||
* 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.ActionError;
|
||||
import org.apache.struts2.components.Anchor;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ActionErrorTest extends AbstractTest {
|
||||
private ActionError tag;
|
||||
private List<String> errors;
|
||||
|
||||
public void testRenderActionError() {
|
||||
tag.setCssClass("class");
|
||||
tag.setCssStyle("style");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<ul style='style' class='class'><li><span>this clas is bad</span></li><li><span>baaaaad</span></li></ul>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderActionErrorWithoutCssClass() {
|
||||
tag.setCssStyle("style");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<ul style='style' class='errorMessage'><li><span>this clas is bad</span></li><li><span>baaaaad</span></li></ul>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderActionErrorNoErrors() {
|
||||
this.errors.clear();
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
assertEquals("", output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
this.errors = new ArrayList<String>();
|
||||
this.errors.add("this clas is bad");
|
||||
this.errors.add("baaaaad");
|
||||
|
||||
//errors are needed to setup stack
|
||||
super.setUp();
|
||||
this.tag = new ActionError(stack, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpStack() {
|
||||
super.setUpStack();
|
||||
expectFind("actionErrors", this.errors);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UIBean getUIBean() {
|
||||
return new Anchor(stack, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "actionerror";
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package org.apache.struts2.views.java.simple;
|
||||
|
||||
import org.apache.struts2.components.ActionError;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ActionMessageTest extends AbstractTest {
|
||||
private ActionError tag;
|
||||
private List<String> errors;
|
||||
|
||||
public void testRenderActionError() {
|
||||
tag.setCssClass("class");
|
||||
tag.setCssStyle("style");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<ul style='style' class='class'><li><span>this clas is bad</span></li><li><span>baaaaad</span></li></ul>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderActionErrorWithoutCssClass() {
|
||||
tag.setCssStyle("style");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<ul style='style' class='actionMessage'><li><span>this clas is bad</span></li><li><span>baaaaad</span></li></ul>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderActionErrorNoErrors() {
|
||||
this.errors.clear();
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
assertEquals("", output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
this.errors = new ArrayList<String>();
|
||||
this.errors.add("this clas is bad");
|
||||
this.errors.add("baaaaad");
|
||||
|
||||
//errors are needed to setup stack
|
||||
super.setUp();
|
||||
this.tag = new ActionError(stack, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpStack() {
|
||||
super.setUpStack();
|
||||
expectFind("actionMessages", this.errors);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UIBean getUIBean() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "actionmessage";
|
||||
}
|
||||
}
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* $Id: Bean.java 726216 2008-12-13 14:58:16Z musachy $
|
||||
*
|
||||
* 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.Anchor;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
|
||||
public class AnchorTest extends AbstractCommonAttributesTest {
|
||||
private Anchor tag;
|
||||
|
||||
public void testRenderAnchor() {
|
||||
tag.setName("name_");
|
||||
tag.setDisabled("true");
|
||||
tag.setTabindex("1");
|
||||
tag.setId("id_");
|
||||
tag.setCssClass("class");
|
||||
tag.setCssStyle("style");
|
||||
tag.setTitle("title");
|
||||
tag.setHref("http://sometest.com?ab=10");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
theme.renderTag(getTagName() + "-close", context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<a name='name_' id='id_' class='class' style='style' href='http://sometest.com?ab=10' title='title' tabindex='1'></a>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
this.tag = new Anchor(stack, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UIBean getUIBean() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "a";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* $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;
|
||||
|
||||
public class Bean {
|
||||
private int intField;
|
||||
private String stringField;
|
||||
|
||||
public int getIntField() {
|
||||
return intField;
|
||||
}
|
||||
|
||||
public void setIntField(int intField) {
|
||||
this.intField = intField;
|
||||
}
|
||||
|
||||
public String getStringField() {
|
||||
return stringField;
|
||||
}
|
||||
|
||||
public void setStringField(String stringField) {
|
||||
this.stringField = stringField;
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* $Id: Bean.java 726216 2008-12-13 14:58:16Z musachy $
|
||||
*
|
||||
* 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.Checkbox;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
|
||||
public class CheckboxTest extends AbstractCommonAttributesTest {
|
||||
private Checkbox tag;
|
||||
|
||||
public void testRenderCheckbox() {
|
||||
tag.setName("name_");
|
||||
tag.setDisabled("true");
|
||||
tag.setTabindex("1");
|
||||
tag.setId("id_");
|
||||
tag.setCssClass("class");
|
||||
tag.setCssStyle("style");
|
||||
tag.setTitle("title");
|
||||
tag.setFieldValue("xyz");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<input type='checkbox' name='name_' value='xyz' tabindex='1' id='id_' class='class' style='style' title='title'></input><input type='hidden' id='__checkbox_id_' name='__checkbox_name_' value='__checkbox_xyz'></input>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderCheckboxWithNameValue() {
|
||||
tag.setName("name_");
|
||||
tag.setValue("%{someValue}");
|
||||
tag.setDisabled("true");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<input type='checkbox' name='name_' value='true' checked='checked' id='name_'></input><input type='hidden' id='__checkbox_name_' name='__checkbox_name_' value='__checkbox_true'></input>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpStack() {
|
||||
super.setUpStack();
|
||||
|
||||
expectFind("someValue", Boolean.class, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
tag = new Checkbox(stack, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UIBean getUIBean() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "checkbox";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* $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.Div;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
|
||||
public class DivTest extends AbstractCommonAttributesTest {
|
||||
private Div tag;
|
||||
|
||||
public void testRenderAnchor() {
|
||||
tag.setName("name_");
|
||||
tag.setDisabled("true");
|
||||
tag.setId("id_");
|
||||
tag.setCssClass("class");
|
||||
tag.setCssStyle("style");
|
||||
tag.setTitle("title");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
theme.renderTag(getTagName() + "-close", context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<div name='name_' id='id_' class='class' style='style' title='title'></div>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
this.tag = new Div(stack, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UIBean getUIBean() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "div";
|
||||
}
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* $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.FieldError;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class FieldErrorTest extends AbstractTest {
|
||||
private FieldError tag;
|
||||
private Map<String, List<String>> errors;
|
||||
private List<String> fieldNames;
|
||||
|
||||
public void testRenderFieldError() {
|
||||
tag.setCssClass("class");
|
||||
tag.setCssStyle("style");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<ul style='style' class='class'><li><span>not good</span></li><li><span>bad</span></li><li><span>bad to the bone</span></li></ul>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderFieldErrorWithoutCssClass() {
|
||||
tag.setCssStyle("style");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<ul style='style' class='errorMessage'><li><span>not good</span></li><li><span>bad</span></li><li><span>bad to the bone</span></li></ul>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderFieldErrorWithoutFieldName() {
|
||||
this.fieldNames.clear();
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<ul class='errorMessage'><li><span>not good</span></li><li><span>bad</span></li><li><span>bad to the bone</span></li></ul>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderFieldErrorWithoutOneFieldName() {
|
||||
tag.setFieldName("field1");
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<ul class='errorMessage'><li><span>not good</span></li><li><span>bad</span></li></ul>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderActionErrorNoErrors() {
|
||||
this.errors.clear();
|
||||
this.fieldNames.clear();
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
assertEquals("", output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
this.errors = new LinkedHashMap<String, List<String>>() {
|
||||
{
|
||||
put("field1", Arrays.asList("not good", "bad"));
|
||||
put("field2", Arrays.asList("bad to the bone"));
|
||||
}
|
||||
};
|
||||
this.fieldNames = new ArrayList<String>();
|
||||
this.fieldNames.add("field1");
|
||||
this.fieldNames.add("field2");
|
||||
|
||||
//errors are needed to setup stack
|
||||
super.setUp();
|
||||
this.tag = new FieldError(stack, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpStack() {
|
||||
super.setUpStack();
|
||||
expectFind("fieldErrorFieldNames", this.fieldNames);
|
||||
expectFind("fieldErrors", this.errors);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UIBean getUIBean() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "fielderror";
|
||||
}
|
||||
}
|
||||
+66
@@ -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.File;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
|
||||
public class FileTest extends AbstractCommonAttributesTest {
|
||||
private File tag;
|
||||
|
||||
public void testRenderTextField() {
|
||||
tag.setName("name");
|
||||
tag.setValue("val1");
|
||||
tag.setSize("10");
|
||||
tag.setDisabled("true");
|
||||
tag.setAccept("accept_");
|
||||
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='file' size='10' value='val1' accept='accept_' 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 File(stack, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UIBean getUIBean() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "file";
|
||||
}
|
||||
}
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* $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.Form;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
import org.apache.struts2.components.UrlRenderer;
|
||||
import org.easymock.EasyMock;
|
||||
|
||||
public class FormTest extends AbstractCommonAttributesTest {
|
||||
private Form tag;
|
||||
|
||||
public void testRenderForm() {
|
||||
tag.setName("name_");
|
||||
tag.setDisabled("true");
|
||||
tag.setTabindex("1");
|
||||
tag.setId("id_");
|
||||
tag.setCssClass("class_");
|
||||
tag.setCssStyle("style_");
|
||||
tag.setTitle("title");
|
||||
tag.setAcceptcharset("charset_");
|
||||
tag.setAction("action_");
|
||||
tag.setOnsubmit("submit");
|
||||
tag.setOnreset("reset");
|
||||
tag.setTarget("target_");
|
||||
tag.setEnctype("enc");
|
||||
tag.setMethod("post");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
theme.renderTag(getTagName() + "-close", context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<form name='name_' id='id_' onsubmit='submit' onreset='reset' target='target_' enctype='enc' class='class_' style='style_' title='title' accept-charset='charset_' method='post'></form>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testDefaultMethod() {
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
theme.renderTag(getTagName() + "-close", context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<form method='post'></form>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UIBean getUIBean() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "form";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
tag = new Form(stack, request, response);
|
||||
UrlRenderer renderer = EasyMock.createNiceMock(UrlRenderer.class);
|
||||
EasyMock.replay(renderer);
|
||||
tag.setUrlRenderer(renderer);
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* $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.Head;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
|
||||
public class HeadTest extends AbstractTest {
|
||||
private Head tag;
|
||||
|
||||
public void testRenderTextField() {
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<script type='text/javascript' src='/some/path/struts/utils.js'></script>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
this.tag = new Head(stack, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UIBean getUIBean() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "head";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+65
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+66
@@ -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'>val1</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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* $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() throws Exception {
|
||||
super.setUp();
|
||||
this.tag = new Password(stack, request, response);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "password";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+86
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* $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.Select;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SelectTest extends AbstractCommonAttributesTest {
|
||||
private Bean bean1;
|
||||
private Select tag;
|
||||
|
||||
public void testRenderSelect() {
|
||||
tag.setName("name_");
|
||||
tag.setSize("10");
|
||||
tag.setDisabled("true");
|
||||
tag.setMultiple("true");
|
||||
tag.setTabindex("1");
|
||||
tag.setId("id_");
|
||||
tag.setCssClass("class");
|
||||
tag.setCssStyle("style");
|
||||
tag.setTitle("title");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<select name='name_' size='10' tabindex='1' id='id_' class='class' style='style' title='title'></select>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderSelectWithHeader() {
|
||||
tag.setList("%{{'key0', 'key1'}}");
|
||||
tag.setHeaderKey("%{'key0'}");
|
||||
tag.setHeaderValue("%{'val'}");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<select name=''><option value='key0'>val</option></select>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderSelectWithOptions() {
|
||||
tag.setList("%{list}");
|
||||
tag.setListKey("intField");
|
||||
tag.setListValue("stringField");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<select name=''><option value='1'>val</option></select>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderSelectWithMapOptions() {
|
||||
tag.setList("%{#{'key0' : 'val'}}");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<select name=''><option value='key0'>val</option></select>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderSelectWithOptionSelected() {
|
||||
tag.setList("%{list}");
|
||||
tag.setListKey("intField");
|
||||
tag.setListValue("stringField");
|
||||
tag.setValue("%{'1'}");
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<select name='' value='1'><option value='1' selected='selected'>val</option></select>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UIBean getUIBean() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "select";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
this.tag = new Select(stack, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpStack() {
|
||||
super.setUpStack();
|
||||
bean1 = new Bean();
|
||||
bean1.setIntField(1);
|
||||
bean1.setStringField("val");
|
||||
|
||||
|
||||
expectFind("'key0'", String.class, "key0");
|
||||
expectFind("'key1'", String.class, "key1");
|
||||
expectFind("'val'", String.class, "val");
|
||||
expectFind("'val1'", String.class, "val1");
|
||||
expectFind("'1'", "1");
|
||||
expectFind("list", Arrays.asList(bean1));
|
||||
expectFind("key", "key0");
|
||||
expectFind("value", "val");
|
||||
expectFind("#{'key0' : 'val'}", new HashMap() {
|
||||
{
|
||||
put("key0", "val");
|
||||
}
|
||||
});
|
||||
|
||||
expectFind("intField", 1);
|
||||
expectFind("stringField", "val");
|
||||
}
|
||||
}
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* $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.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
|
||||
tag.addParameter("body", "<span>hey hey hey, here I go now</span>");
|
||||
map.clear();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName() + "-close", 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 its time I disappear");
|
||||
tag.setType("button");
|
||||
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
theme.renderTag(getTagName() + "-close", 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 its 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);
|
||||
theme.renderTag(getTagName() + "-close", context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<input name='name' type='submit' value='val1' tabindex='1' id='id1' class='class1' style='style1'></input>");
|
||||
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);
|
||||
theme.renderTag(getTagName() + "-close", context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<input name='name' type='submit' value='val1' tabindex='1' id='id1' class='class1' style='style1'></input>");
|
||||
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);
|
||||
theme.renderTag(getTagName() + "-close", context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<input src='http://somesource/image.gif' type='image' alt='alt text'></input>");
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testRenderButtonImageWithBody() {
|
||||
tag.setSrc("http://somesource/image.gif");
|
||||
tag.setLabel("alt text");
|
||||
tag.setType("image");
|
||||
|
||||
|
||||
tag.evaluateParams();
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName(), context);
|
||||
map.clear();
|
||||
tag.setType("image");
|
||||
tag.addParameter("body", "<span>hey hey hey, here I go now</span>");
|
||||
map.putAll(tag.getParameters());
|
||||
theme.renderTag(getTagName() + "-close", context);
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<input src='http://somesource/image.gif' type='image' alt='alt text'><span>hey hey hey, here I go now</span></input>");
|
||||
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";
|
||||
}
|
||||
}
|
||||
+86
@@ -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";
|
||||
}
|
||||
}
|
||||
+66
@@ -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.TextField;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
|
||||
public class TextFieldTest extends AbstractCommonAttributesTest {
|
||||
private TextField tag;
|
||||
|
||||
public void testRenderTextField() {
|
||||
tag.setName("name");
|
||||
tag.setValue("val1");
|
||||
tag.setSize("10");
|
||||
tag.setMaxlength("11");
|
||||
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("<input type='text' name='name' size='10' maxlength='11' 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 TextField(stack, request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UIBean getUIBean() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagName() {
|
||||
return "textfield";
|
||||
}
|
||||
}
|
||||
+69
@@ -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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user