Author: mrdon
Date: Sun Dec 17 19:44:51 2006
New Revision: 488112
URL: http://svn.apache.org/viewvc?view=rev&rev=488112
Log:
Adding initial version of a Struts 2 template engine implemented in pure Java
using
a simplified SAX-style pipeline of tag handlers for construction and rendering
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/
struts/sandbox/trunk/struts2-javatemplates-plugin/pom.xml
struts/sandbox/trunk/struts2-javatemplates-plugin/src/
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/AbstractTagHandler.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/Attributes.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/CommonAttributesHandler.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTheme.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/JavaTemplateEngine.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/ScriptingEventsHandler.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/SimpleTheme.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagGenerator.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagHandler.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagHandlerFactory.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagSerializer.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TextFieldHandler.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/Theme.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/XHTMLTagSerializer.java
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/resources/
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/resources/struts-plugin.xml
Added: struts/sandbox/trunk/struts2-javatemplates-plugin/pom.xml
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/pom.xml?view=auto&rev=488112
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/pom.xml (added)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/pom.xml Sun Dec 17
19:44:51 2006
@@ -0,0 +1,29 @@
+<?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.0.2-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>
+ </dependencies>
+</project>
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/AbstractTagHandler.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/AbstractTagHandler.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/AbstractTagHandler.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/AbstractTagHandler.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,61 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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;
+
+import org.apache.struts2.components.template.TemplateRenderingContext;
+
+public class AbstractTagHandler implements TagHandler {
+
+ protected TagHandler nextTagHandler;
+ protected TemplateRenderingContext context;
+
+ public void characters(String text) throws IOException {
+ if (nextTagHandler != null) {
+ nextTagHandler.characters(text);
+ }
+
+ }
+
+ 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;
+ }
+
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/Attributes.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/Attributes.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/Attributes.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/Attributes.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,75 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import com.opensymphony.xwork2.util.TextUtils;
+
+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;
+ }
+
+ public Attributes addIfExists(String attrName, Object paramValue) {
+ return addIfExists(attrName, paramValue, true);
+ }
+
+ public Attributes addIfExists(String attrName, Object paramValue, boolean
encode) {
+ if (paramValue != null) {
+ String val = paramValue.toString();
+ put(attrName, (encode ? TextUtils.htmlEncode(val) : val));
+ }
+ 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;
+ }
+
+ public Attributes addDefaultToEmpty(String attrName, Object paramValue) {
+ return addDefaultToEmpty(attrName, paramValue, true);
+ }
+
+ 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;
+ }
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/CommonAttributesHandler.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/CommonAttributesHandler.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/CommonAttributesHandler.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/CommonAttributesHandler.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,36 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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 class CommonAttributesHandler extends AbstractTagHandler {
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts2.views.java.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);
+ }
+
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,49 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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 class DefaultTagHandlerFactory implements TagHandlerFactory {
+
+ 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 (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTheme.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTheme.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTheme.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTheme.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,76 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.struts2.StrutsException;
+import org.apache.struts2.components.template.TemplateRenderingContext;
+
+public class DefaultTheme implements Theme {
+
+ 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 {
+ gen.generate();
+ } catch (IOException ex) {
+ throw new StrutsException("Unable to write tag: "+tagName);
+ }
+ }
+
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/JavaTemplateEngine.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/JavaTemplateEngine.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/JavaTemplateEngine.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/JavaTemplateEngine.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,65 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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.util.HashMap;
+
+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.Theme;
+import org.apache.struts2.views.java.SimpleTheme;
+
+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()+" is 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);
+ }
+ }
+
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/ScriptingEventsHandler.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/ScriptingEventsHandler.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/ScriptingEventsHandler.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/ScriptingEventsHandler.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,52 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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;
+import java.util.Map;
+
+public class ScriptingEventsHandler extends AbstractTagHandler {
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts2.views.java.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);
+ }
+
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/SimpleTheme.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/SimpleTheme.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/SimpleTheme.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/SimpleTheme.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,47 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SimpleTheme extends DefaultTheme {
+
+ public SimpleTheme() {
+ setHandlerFactories(new HashMap<String,List<TagHandlerFactory>>() {{
+ put("text", new FactoryList(TextFieldHandler.class,
ScriptingEventsHandler.class, CommonAttributesHandler.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));
+ }
+ }
+
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagGenerator.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagGenerator.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagGenerator.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagGenerator.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,28 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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;
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagHandler.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagHandler.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagHandler.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagHandler.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,35 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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;
+
+import org.apache.struts2.components.template.TemplateRenderingContext;
+
+public interface TagHandler {
+
+ void setNext(TagHandler next);
+ void setup(TemplateRenderingContext context);
+
+ void start(String name, Attributes a) throws IOException;
+ void end(String name) throws IOException;
+ void characters(String text) throws IOException;
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagHandlerFactory.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagHandlerFactory.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagHandlerFactory.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagHandlerFactory.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,26 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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);
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagSerializer.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagSerializer.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagSerializer.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TagSerializer.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,26 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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.Writer;
+
+public interface TagSerializer extends TagHandler {
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TextFieldHandler.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TextFieldHandler.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TextFieldHandler.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/TextFieldHandler.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,61 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.struts2.components.Property;
+import org.apache.struts2.components.template.TemplateRenderingContext;
+
+public class TextFieldHandler extends AbstractTagHandler implements
TagGenerator {
+
+ public void generate() throws IOException {
+ Map<String,Object> params = context.getParameters();
+ Attributes a = new Attributes();
+ a.put("type", "text");
+
+ a.addDefaultToEmpty("name", params.get("name"))
+ .addIfExists("size", params.get("size"))
+ .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("tagindex"))
+ .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");
+ }
+
+ private String evalProperty(Object rawValue) {
+ Property prop = new Property(context.getStack());
+ prop.setValue(rawValue.toString());
+ StringWriter writer = new StringWriter();
+ prop.start(writer);
+ return writer.toString();
+ }
+
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/Theme.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/Theme.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/Theme.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/Theme.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,30 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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.Writer;
+
+import org.apache.struts2.components.template.TemplateRenderingContext;
+
+public interface Theme {
+ public String getName();
+ public void renderTag(String name, TemplateRenderingContext context);
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/XHTMLTagSerializer.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/XHTMLTagSerializer.java?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/XHTMLTagSerializer.java
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/XHTMLTagSerializer.java
Sun Dec 17 19:44:51 2006
@@ -0,0 +1,63 @@
+/*
+ * $Id: BaseTemplateEngine.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * 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;
+import java.io.Writer;
+
+import org.apache.struts2.components.template.TemplateRenderingContext;
+
+public class XHTMLTagSerializer implements TagSerializer {
+
+ private Writer writer;
+
+ public void characters(String text) throws IOException {
+ writer.write(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 a) throws IOException {
+ writer.write("<");
+ writer.write(name);
+ for (String key : a.keySet()) {
+ writer.write(" ");
+ writer.write(key);
+ writer.write("=\"");
+ writer.write(a.get(key));
+ writer.write("\"");
+ }
+ writer.write(">");
+ }
+
+ public void setup(TemplateRenderingContext context) {
+ this.writer = context.getWriter();
+
+ }
+
+}
Added:
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/resources/struts-plugin.xml
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/resources/struts-plugin.xml?view=auto&rev=488112
==============================================================================
---
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/resources/struts-plugin.xml
(added)
+++
struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/resources/struts-plugin.xml
Sun Dec 17 19:44:51 2006
@@ -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>