TILESSB-24
Moved code form tiles-template to tiles-autotag-core-runtime.
git-svn-id: https://svn.apache.org/repos/asf/tiles/sandbox/trunk/tiles-autotag@912392 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tiles-autotag-core-runtime/pom.xml b/tiles-autotag-core-runtime/pom.xml
index 52fdf32..e55ed13 100644
--- a/tiles-autotag-core-runtime/pom.xml
+++ b/tiles-autotag-core-runtime/pom.xml
@@ -10,4 +10,12 @@
<version>1.0-SNAPSHOT</version>
<name>Autotag - Core runtime</name>
<description>Autotag: runtime core classes.</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tiles</groupId>
+ <artifactId>tiles-request</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
diff --git a/tiles-autotag-core-runtime/src/main/java/org/apache/tiles/autotag/core/runtime/AbstractModelBody.java b/tiles-autotag-core-runtime/src/main/java/org/apache/tiles/autotag/core/runtime/AbstractModelBody.java
new file mode 100644
index 0000000..6feb2d9
--- /dev/null
+++ b/tiles-autotag-core-runtime/src/main/java/org/apache/tiles/autotag/core/runtime/AbstractModelBody.java
@@ -0,0 +1,50 @@
+package org.apache.tiles.autotag.core.runtime;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.util.NullWriter;
+
+public abstract class AbstractModelBody implements ModelBody {
+
+ private Writer defaultWriter;
+
+ public AbstractModelBody(Writer defaultWriter) {
+ this.defaultWriter = defaultWriter;
+ }
+
+ @Override
+ public void evaluate() throws IOException {
+ evaluate(defaultWriter);
+ }
+
+ @Override
+ public String evaluateAsString() throws IOException {
+ StringWriter writer = new StringWriter();
+ try {
+ evaluate(writer);
+ } finally {
+ writer.close();
+ }
+ String body = writer.toString();
+ if (body != null) {
+ body = body.replaceAll("^\\s*|\\s*$", "");
+ if (body.length() <= 0) {
+ body = null;
+ }
+ }
+ return body;
+ }
+
+ @Override
+ public void evaluateWithoutWriting() throws IOException {
+ NullWriter writer = new NullWriter();
+ try {
+ evaluate(writer);
+ } finally {
+ writer.close();
+ }
+ }
+
+}
diff --git a/tiles-autotag-core-runtime/src/main/java/org/apache/tiles/autotag/core/runtime/ModelBody.java b/tiles-autotag-core-runtime/src/main/java/org/apache/tiles/autotag/core/runtime/ModelBody.java
new file mode 100644
index 0000000..6b5f465
--- /dev/null
+++ b/tiles-autotag-core-runtime/src/main/java/org/apache/tiles/autotag/core/runtime/ModelBody.java
@@ -0,0 +1,15 @@
+package org.apache.tiles.autotag.core.runtime;
+
+import java.io.IOException;
+import java.io.Writer;
+
+public interface ModelBody {
+
+ String evaluateAsString() throws IOException;
+
+ void evaluateWithoutWriting() throws IOException;
+
+ void evaluate() throws IOException;
+
+ void evaluate(Writer writer) throws IOException;
+}
diff --git a/tiles-autotag-core-runtime/src/main/java/org/apache/tiles/autotag/core/runtime/util/NullWriter.java b/tiles-autotag-core-runtime/src/main/java/org/apache/tiles/autotag/core/runtime/util/NullWriter.java
new file mode 100644
index 0000000..508651f
--- /dev/null
+++ b/tiles-autotag-core-runtime/src/main/java/org/apache/tiles/autotag/core/runtime/util/NullWriter.java
@@ -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.tiles.autotag.core.runtime.util;
+
+import java.io.Writer;
+
+/**
+ * A writer that does not write anything.
+ *
+ * @version $Rev$ $Date$
+ * @since 2.2.0
+ */
+public class NullWriter extends Writer {
+
+ /** {@inheritDoc} */
+ @Override
+ public void close() {
+ // Does nothing
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void flush() {
+ // Does nothing
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void write(char[] cbuf, int off, int len) {
+ // Does nothing
+ }
+}
diff --git a/tiles-autotag-core/pom.xml b/tiles-autotag-core/pom.xml
index 5b2b033..a83c864 100644
--- a/tiles-autotag-core/pom.xml
+++ b/tiles-autotag-core/pom.xml
@@ -46,5 +46,10 @@
<version>2.5.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.tiles</groupId>
+ <artifactId>tiles-autotag-core-runtime</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>