http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/CustomHTMLOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/CustomHTMLOutputFormat.java b/src/test/java/org/apache/freemarker/core/CustomHTMLOutputFormat.java deleted file mode 100644 index 86e69a4..0000000 --- a/src/test/java/org/apache/freemarker/core/CustomHTMLOutputFormat.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.freemarker.core; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.freemarker.core.CommonMarkupOutputFormat; -import org.apache.freemarker.core.model.TemplateModelException; -import org.apache.freemarker.core.util._StringUtil; - -/** - * Represents the HTML output format. - * - * @since 2.3.24 - */ -public final class CustomHTMLOutputFormat extends CommonMarkupOutputFormat<CustomTemplateHTMLModel> { - - public static final CustomHTMLOutputFormat INSTANCE = new CustomHTMLOutputFormat(); - - private CustomHTMLOutputFormat() { - // Only to decrease visibility - } - - @Override - public String getName() { - return "HTML"; - } - - @Override - public String getMimeType() { - return "text/html"; - } - - @Override - public void output(String textToEsc, Writer out) throws IOException, TemplateModelException { - // This is lazy - don't do it in reality. - out.write(escapePlainText(textToEsc)); - } - - @Override - public String escapePlainText(String plainTextContent) { - return _StringUtil.XHTMLEnc(plainTextContent.replace('x', 'X')); - } - - @Override - public boolean isLegacyBuiltInBypassed(String builtInName) { - return builtInName.equals("html") || builtInName.equals("xml") || builtInName.equals("xhtml"); - } - - @Override - protected CustomTemplateHTMLModel newTemplateMarkupOutputModel(String plainTextContent, String markupContent) { - return new CustomTemplateHTMLModel(plainTextContent, markupContent); - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/CustomTemplateHTMLModel.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/CustomTemplateHTMLModel.java b/src/test/java/org/apache/freemarker/core/CustomTemplateHTMLModel.java deleted file mode 100644 index 60a419a..0000000 --- a/src/test/java/org/apache/freemarker/core/CustomTemplateHTMLModel.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.freemarker.core; - -import org.apache.freemarker.core.CommonTemplateMarkupOutputModel; - -public final class CustomTemplateHTMLModel extends CommonTemplateMarkupOutputModel<CustomTemplateHTMLModel> { - - CustomTemplateHTMLModel(String plainTextContent, String markupContent) { - super(plainTextContent, markupContent); - } - - @Override - public CustomHTMLOutputFormat getOutputFormat() { - return CustomHTMLOutputFormat.INSTANCE; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/DummyOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/DummyOutputFormat.java b/src/test/java/org/apache/freemarker/core/DummyOutputFormat.java deleted file mode 100644 index 013b793..0000000 --- a/src/test/java/org/apache/freemarker/core/DummyOutputFormat.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.freemarker.core; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.freemarker.core.CommonMarkupOutputFormat; -import org.apache.freemarker.core.model.TemplateModelException; - -public class DummyOutputFormat extends CommonMarkupOutputFormat<TemplateDummyOutputModel> { - - public static final DummyOutputFormat INSTANCE = new DummyOutputFormat(); - - private DummyOutputFormat() { - // hide - } - - @Override - public String getName() { - return "dummy"; - } - - @Override - public String getMimeType() { - return "text/dummy"; - } - - @Override - public void output(String textToEsc, Writer out) throws IOException, TemplateModelException { - out.write(escapePlainText(textToEsc)); - } - - @Override - public String escapePlainText(String plainTextContent) { - return plainTextContent.replaceAll("(\\.|\\\\)", "\\\\$1"); - } - - @Override - public boolean isLegacyBuiltInBypassed(String builtInName) { - return false; - } - - @Override - protected TemplateDummyOutputModel newTemplateMarkupOutputModel(String plainTextContent, String markupContent) { - return new TemplateDummyOutputModel(plainTextContent, markupContent); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/HTMLISOTemplateDateFormatFactory.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/HTMLISOTemplateDateFormatFactory.java b/src/test/java/org/apache/freemarker/core/HTMLISOTemplateDateFormatFactory.java index 40305b8..0d8cad9 100644 --- a/src/test/java/org/apache/freemarker/core/HTMLISOTemplateDateFormatFactory.java +++ b/src/test/java/org/apache/freemarker/core/HTMLISOTemplateDateFormatFactory.java @@ -22,16 +22,7 @@ import java.util.Date; import java.util.Locale; import java.util.TimeZone; -import org.apache.freemarker.core.Environment; -import org.apache.freemarker.core.HTMLOutputFormat; -import org.apache.freemarker.core.InvalidFormatParametersException; -import org.apache.freemarker.core.TemplateDateFormat; -import org.apache.freemarker.core.TemplateDateFormatFactory; -import org.apache.freemarker.core.TemplateFormatUtil; -import org.apache.freemarker.core.TemplateValueFormatException; -import org.apache.freemarker.core.UnformattableValueException; -import org.apache.freemarker.core.UnknownDateTypeFormattingUnsupportedException; -import org.apache.freemarker.core.UnparsableValueException; +import org.apache.freemarker.core.outputformat.impl.HTMLOutputFormat; import org.apache.freemarker.core.model.TemplateDateModel; import org.apache.freemarker.core.model.TemplateModelException; import org.apache.freemarker.core.util._DateUtil; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/HTMLOutputFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/HTMLOutputFormatTest.java b/src/test/java/org/apache/freemarker/core/HTMLOutputFormatTest.java deleted file mode 100644 index cb02f88..0000000 --- a/src/test/java/org/apache/freemarker/core/HTMLOutputFormatTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * 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.freemarker.core; - -import static org.apache.freemarker.core.HTMLOutputFormat.*; -import static org.junit.Assert.*; - -import java.io.IOException; -import java.io.StringWriter; - -import org.apache.freemarker.core.CommonMarkupOutputFormat; -import org.apache.freemarker.core.TemplateHTMLOutputModel; -import org.apache.freemarker.core.model.TemplateModelException; -import org.junit.Test; - -/** - * This actually more a {@link CommonMarkupOutputFormat} test. - */ -public class HTMLOutputFormatTest { - - @Test - public void testOutputMO() throws TemplateModelException, IOException { - StringWriter out = new StringWriter(); - - INSTANCE.output(INSTANCE.fromMarkup("<p>Test "), out); - INSTANCE.output(INSTANCE.fromPlainTextByEscaping("foo & bar "), out); - INSTANCE.output(INSTANCE.fromPlainTextByEscaping("baaz "), out); - INSTANCE.output(INSTANCE.fromPlainTextByEscaping("<b>A</b> <b>B</b> <b>C</b>"), out); - INSTANCE.output(INSTANCE.fromPlainTextByEscaping(""), out); - INSTANCE.output(INSTANCE.fromPlainTextByEscaping("\"' x's \"y\" \""), out); - INSTANCE.output(INSTANCE.fromMarkup("</p>"), out); - - assertEquals( - "<p>Test " - + "foo & bar " - + "baaz " - + "<b>A</b> <b>B</b> <b>C</b>" - + ""' x's "y" "" - + "</p>", - out.toString()); - } - - @Test - public void testOutputString() throws TemplateModelException, IOException { - StringWriter out = new StringWriter(); - - INSTANCE.output("a", out); - INSTANCE.output("<", out); - INSTANCE.output("b'c", out); - - assertEquals("a<b'c", out.toString()); - } - - @Test - public void testFromPlainTextByEscaping() throws TemplateModelException { - String plainText = "a&b"; - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping(plainText); - assertSame(plainText, mo.getPlainTextContent()); - assertNull(mo.getMarkupContent()); // Not the MO's duty to calculate it! - } - - @Test - public void testFromMarkup() throws TemplateModelException { - String markup = "a&b"; - TemplateHTMLOutputModel mo = INSTANCE.fromMarkup(markup); - assertSame(markup, mo.getMarkupContent()); - assertNull(mo.getPlainTextContent()); // Not the MO's duty to calculate it! - } - - @Test - public void testGetMarkup() throws TemplateModelException { - { - String markup = "a&b"; - TemplateHTMLOutputModel mo = INSTANCE.fromMarkup(markup); - assertSame(markup, INSTANCE.getMarkupString(mo)); - } - - { - String safe = "abc"; - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping(safe); - assertSame(safe, INSTANCE.getMarkupString(mo)); - } - { - String safe = ""; - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping(safe); - assertSame(safe, INSTANCE.getMarkupString(mo)); - } - { - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("<abc"); - assertEquals("<abc", INSTANCE.getMarkupString(mo)); - } - { - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("abc>"); - assertEquals("abc>", INSTANCE.getMarkupString(mo)); - } - { - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("<abc>"); - assertEquals("<abc>", INSTANCE.getMarkupString(mo)); - } - { - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("a&bc"); - assertEquals("a&bc", INSTANCE.getMarkupString(mo)); - } - { - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("a&b&c"); - assertEquals("a&b&c", INSTANCE.getMarkupString(mo)); - } - { - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("a<&>b&c"); - assertEquals("a<&>b&c", INSTANCE.getMarkupString(mo)); - } - { - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("\"<a<&>b&c>\""); - assertEquals(""<a<&>b&c>"", INSTANCE.getMarkupString(mo)); - } - { - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("<"); - assertEquals("<", INSTANCE.getMarkupString(mo)); - } - { - TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("'"); - String mc = INSTANCE.getMarkupString(mo); - assertEquals("'", mc); - assertSame(mc, INSTANCE.getMarkupString(mo)); // cached - } - } - - @Test - public void testConcat() throws Exception { - assertMO( - "ab", null, - INSTANCE.concat(new TemplateHTMLOutputModel("a", null), new TemplateHTMLOutputModel("b", null))); - assertMO( - null, "ab", - INSTANCE.concat(new TemplateHTMLOutputModel(null, "a"), new TemplateHTMLOutputModel(null, "b"))); - assertMO( - null, "<a><b>", - INSTANCE.concat(new TemplateHTMLOutputModel(null, "<a>"), new TemplateHTMLOutputModel("<b>", null))); - assertMO( - null, "<a><b>", - INSTANCE.concat(new TemplateHTMLOutputModel("<a>", null), new TemplateHTMLOutputModel(null, "<b>"))); - } - - @Test - public void testEscaplePlainText() { - assertEquals("", INSTANCE.escapePlainText("")); - assertEquals("a", INSTANCE.escapePlainText("a")); - assertEquals("<a&b'c"d>", INSTANCE.escapePlainText("<a&b'c\"d>")); - assertEquals("a&b", INSTANCE.escapePlainText("a&b")); - assertEquals("<>", INSTANCE.escapePlainText("<>")); - } - - @Test - public void testIsEmpty() throws Exception { - assertTrue(INSTANCE.isEmpty(INSTANCE.fromMarkup(""))); - assertTrue(INSTANCE.isEmpty(INSTANCE.fromPlainTextByEscaping(""))); - assertFalse(INSTANCE.isEmpty(INSTANCE.fromMarkup(" "))); - assertFalse(INSTANCE.isEmpty(INSTANCE.fromPlainTextByEscaping(" "))); - } - - private void assertMO(String pc, String mc, TemplateHTMLOutputModel mo) { - assertEquals(pc, mo.getPlainTextContent()); - assertEquals(mc, mo.getMarkupContent()); - } - - @Test - public void testGetMimeType() { - assertEquals("text/html", INSTANCE.getMimeType()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/OutputFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/OutputFormatTest.java b/src/test/java/org/apache/freemarker/core/OutputFormatTest.java index 0918436..4ff47b6 100644 --- a/src/test/java/org/apache/freemarker/core/OutputFormatTest.java +++ b/src/test/java/org/apache/freemarker/core/OutputFormatTest.java @@ -28,22 +28,19 @@ import java.io.StringWriter; import java.io.Writer; import java.util.Collections; -import org.apache.freemarker.core.Configuration; -import org.apache.freemarker.core.HTMLOutputFormat; -import org.apache.freemarker.core.InvalidReferenceException; -import org.apache.freemarker.core.OutputFormat; -import org.apache.freemarker.core.ParseException; -import org.apache.freemarker.core.PlainTextOutputFormat; -import org.apache.freemarker.core.RTFOutputFormat; -import org.apache.freemarker.core.Template; -import org.apache.freemarker.core.TemplateConfiguration; -import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.UndefinedOutputFormat; -import org.apache.freemarker.core.XMLOutputFormat; +import org.apache.freemarker.core.outputformat.*; import org.apache.freemarker.core.model.TemplateModelException; +import org.apache.freemarker.core.outputformat.impl.HTMLOutputFormat; +import org.apache.freemarker.core.outputformat.impl.PlainTextOutputFormat; +import org.apache.freemarker.core.outputformat.impl.RTFOutputFormat; +import org.apache.freemarker.core.outputformat.impl.UndefinedOutputFormat; +import org.apache.freemarker.core.outputformat.impl.XMLOutputFormat; import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory; import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher; import org.apache.freemarker.core.templateresolver.OrMatcher; +import org.apache.freemarker.core.userpkg.CustomHTMLOutputFormat; +import org.apache.freemarker.core.userpkg.DummyOutputFormat; +import org.apache.freemarker.core.userpkg.SeldomEscapedOutputFormat; import org.apache.freemarker.test.TemplateTest; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/PrintfGTemplateNumberFormatFactory.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/PrintfGTemplateNumberFormatFactory.java b/src/test/java/org/apache/freemarker/core/PrintfGTemplateNumberFormatFactory.java index 0408b48..c24b2bb 100644 --- a/src/test/java/org/apache/freemarker/core/PrintfGTemplateNumberFormatFactory.java +++ b/src/test/java/org/apache/freemarker/core/PrintfGTemplateNumberFormatFactory.java @@ -22,13 +22,7 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Locale; -import org.apache.freemarker.core.Environment; -import org.apache.freemarker.core.HTMLOutputFormat; -import org.apache.freemarker.core.InvalidFormatParametersException; -import org.apache.freemarker.core.TemplateFormatUtil; -import org.apache.freemarker.core.TemplateNumberFormat; -import org.apache.freemarker.core.TemplateNumberFormatFactory; -import org.apache.freemarker.core.UnformattableValueException; +import org.apache.freemarker.core.outputformat.impl.HTMLOutputFormat; import org.apache.freemarker.core.model.TemplateModelException; import org.apache.freemarker.core.model.TemplateNumberModel; import org.apache.freemarker.core.util._StringUtil; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/RTFOutputFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/RTFOutputFormatTest.java b/src/test/java/org/apache/freemarker/core/RTFOutputFormatTest.java deleted file mode 100644 index 3b2c878..0000000 --- a/src/test/java/org/apache/freemarker/core/RTFOutputFormatTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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.freemarker.core; - -import static org.apache.freemarker.core.RTFOutputFormat.*; -import static org.junit.Assert.*; - -import java.io.IOException; -import java.io.StringWriter; - -import org.apache.freemarker.core.TemplateRTFOutputModel; -import org.apache.freemarker.core.model.TemplateModelException; -import org.junit.Test; - -public class RTFOutputFormatTest { - - @Test - public void testOutputMO() throws TemplateModelException, IOException { - StringWriter out = new StringWriter(); - - INSTANCE.output(INSTANCE.fromMarkup("\\par Test "), out); - INSTANCE.output(INSTANCE.fromPlainTextByEscaping("foo { bar } \\ "), out); - INSTANCE.output(INSTANCE.fromPlainTextByEscaping("baaz "), out); - INSTANCE.output(INSTANCE.fromPlainTextByEscaping("\\par qweqwe"), out); - INSTANCE.output(INSTANCE.fromMarkup("\\par{0} End"), out); - - assertEquals( - "\\par Test " - + "foo \\{ bar \\} \\\\ " - + "baaz " - + "\\\\par qweqwe" - + "\\par{0} End", - out.toString()); - } - - @Test - public void testOutputString() throws TemplateModelException, IOException { - StringWriter out = new StringWriter(); - - INSTANCE.output("a", out); - INSTANCE.output("{", out); - INSTANCE.output("b}c", out); - - assertEquals("a\\{b\\}c", out.toString()); - } - - @Test - public void testFromPlainTextByEscaping() throws TemplateModelException { - String plainText = "a\\b"; - TemplateRTFOutputModel mo = INSTANCE.fromPlainTextByEscaping(plainText); - assertSame(plainText, mo.getPlainTextContent()); - assertNull(mo.getMarkupContent()); // Not the MO's duty to calculate it! - } - - @Test - public void testFromMarkup() throws TemplateModelException { - String markup = "a \\par b"; - TemplateRTFOutputModel mo = INSTANCE.fromMarkup(markup); - assertSame(markup, mo.getMarkupContent()); - assertNull(mo.getPlainTextContent()); // Not the MO's duty to calculate it! - } - - @Test - public void testGetMarkup() throws TemplateModelException { - { - String markup = "a \\par b"; - TemplateRTFOutputModel mo = INSTANCE.fromMarkup(markup); - assertSame(markup, INSTANCE.getMarkupString(mo)); - } - - { - String safe = "abc"; - TemplateRTFOutputModel mo = INSTANCE.fromPlainTextByEscaping(safe); - assertSame(safe, INSTANCE.getMarkupString(mo)); - } - } - - @Test - public void testConcat() throws Exception { - assertMO( - "ab", null, - INSTANCE.concat(new TemplateRTFOutputModel("a", null), new TemplateRTFOutputModel("b", null))); - assertMO( - null, "ab", - INSTANCE.concat(new TemplateRTFOutputModel(null, "a"), new TemplateRTFOutputModel(null, "b"))); - assertMO( - null, "{a}\\{b\\}", - INSTANCE.concat(new TemplateRTFOutputModel(null, "{a}"), new TemplateRTFOutputModel("{b}", null))); - assertMO( - null, "\\{a\\}{b}", - INSTANCE.concat(new TemplateRTFOutputModel("{a}", null), new TemplateRTFOutputModel(null, "{b}"))); - } - - @Test - public void testEscaplePlainText() { - assertEquals("", INSTANCE.escapePlainText("")); - assertEquals("a", INSTANCE.escapePlainText("a")); - assertEquals("\\{a\\\\b\\}", INSTANCE.escapePlainText("{a\\b}")); - assertEquals("a\\\\b", INSTANCE.escapePlainText("a\\b")); - assertEquals("\\{\\}", INSTANCE.escapePlainText("{}")); - } - - private void assertMO(String pc, String mc, TemplateRTFOutputModel mo) { - assertEquals(pc, mo.getPlainTextContent()); - assertEquals(mc, mo.getMarkupContent()); - } - - @Test - public void testGetMimeType() { - assertEquals("application/rtf", INSTANCE.getMimeType()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/SeldomEscapedOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/SeldomEscapedOutputFormat.java b/src/test/java/org/apache/freemarker/core/SeldomEscapedOutputFormat.java deleted file mode 100644 index 1aa22cf..0000000 --- a/src/test/java/org/apache/freemarker/core/SeldomEscapedOutputFormat.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.freemarker.core; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.freemarker.core.CommonMarkupOutputFormat; -import org.apache.freemarker.core.model.TemplateModelException; - -public class SeldomEscapedOutputFormat extends CommonMarkupOutputFormat<TemplateSeldomEscapedOutputModel> { - - public static final SeldomEscapedOutputFormat INSTANCE = new SeldomEscapedOutputFormat(); - - private SeldomEscapedOutputFormat() { - // hide - } - - @Override - public String getName() { - return "seldomEscaped"; - } - - @Override - public String getMimeType() { - return "text/seldomEscaped"; - } - - @Override - public void output(String textToEsc, Writer out) throws IOException, TemplateModelException { - out.write(escapePlainText(textToEsc)); - } - - @Override - public String escapePlainText(String plainTextContent) { - return plainTextContent.replaceAll("(\\.|\\\\)", "\\\\$1"); - } - - @Override - public boolean isLegacyBuiltInBypassed(String builtInName) { - return false; - } - - @Override - public boolean isAutoEscapedByDefault() { - return false; - } - - @Override - protected TemplateSeldomEscapedOutputModel newTemplateMarkupOutputModel( - String plainTextContent, String markupContent) { - return new TemplateSeldomEscapedOutputModel(plainTextContent, markupContent); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/SpecialVariableTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/SpecialVariableTest.java b/src/test/java/org/apache/freemarker/core/SpecialVariableTest.java index b657164..7fcc8ae 100644 --- a/src/test/java/org/apache/freemarker/core/SpecialVariableTest.java +++ b/src/test/java/org/apache/freemarker/core/SpecialVariableTest.java @@ -22,12 +22,9 @@ package org.apache.freemarker.core; import static org.hamcrest.Matchers.greaterThan; import static org.junit.Assert.assertThat; -import org.apache.freemarker.core.ASTExpBuiltInVariable; -import org.apache.freemarker.core.Configuration; -import org.apache.freemarker.core.HTMLOutputFormat; -import org.apache.freemarker.core.PlainTextOutputFormat; -import org.apache.freemarker.core.UndefinedOutputFormat; -import org.apache.freemarker.core.Version; +import org.apache.freemarker.core.outputformat.impl.HTMLOutputFormat; +import org.apache.freemarker.core.outputformat.impl.PlainTextOutputFormat; +import org.apache.freemarker.core.outputformat.impl.UndefinedOutputFormat; import org.apache.freemarker.test.TemplateTest; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java b/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java index 561cc2f..29aa46e 100644 --- a/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java +++ b/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java @@ -21,10 +21,7 @@ package org.apache.freemarker.core; import java.io.IOException; import java.util.Collections; -import org.apache.freemarker.core.Configuration; -import org.apache.freemarker.core.InvalidReferenceException; -import org.apache.freemarker.core.RTFOutputFormat; -import org.apache.freemarker.core.TemplateException; +import org.apache.freemarker.core.outputformat.impl.RTFOutputFormat; import org.apache.freemarker.test.TemplateTest; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java b/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java index abf637c..07b815b 100644 --- a/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java +++ b/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java @@ -49,23 +49,9 @@ import java.util.Set; import java.util.TimeZone; import org.apache.commons.collections.ListUtils; -import org.apache.freemarker.core.ArithmeticEngine; -import org.apache.freemarker.core.Configurable; -import org.apache.freemarker.core.Configuration; -import org.apache.freemarker.core.CustomAttribute; -import org.apache.freemarker.core.HTMLOutputFormat; -import org.apache.freemarker.core.ParseException; -import org.apache.freemarker.core.ParserConfiguration; -import org.apache.freemarker.core.Template; -import org.apache.freemarker.core.TemplateClassResolver; -import org.apache.freemarker.core.TemplateConfiguration; -import org.apache.freemarker.core.TemplateDateFormatFactory; -import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.TemplateExceptionHandler; -import org.apache.freemarker.core.TemplateNumberFormatFactory; -import org.apache.freemarker.core.UndefinedOutputFormat; -import org.apache.freemarker.core.Version; -import org.apache.freemarker.core.XMLOutputFormat; +import org.apache.freemarker.core.outputformat.impl.HTMLOutputFormat; +import org.apache.freemarker.core.outputformat.impl.UndefinedOutputFormat; +import org.apache.freemarker.core.outputformat.impl.XMLOutputFormat; import org.apache.freemarker.core.model.impl.SimpleObjectWrapper; import org.apache.freemarker.core.templateresolver.impl.StringTemplateLoader; import org.apache.freemarker.core.util._NullArgumentException; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/TemplateDummyOutputModel.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/TemplateDummyOutputModel.java b/src/test/java/org/apache/freemarker/core/TemplateDummyOutputModel.java deleted file mode 100644 index a4b19d1..0000000 --- a/src/test/java/org/apache/freemarker/core/TemplateDummyOutputModel.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.freemarker.core; - -import org.apache.freemarker.core.CommonTemplateMarkupOutputModel; - -public class TemplateDummyOutputModel extends CommonTemplateMarkupOutputModel<TemplateDummyOutputModel> { - - TemplateDummyOutputModel(String plainTextContent, String markupContet) { - super(plainTextContent, markupContet); - } - - @Override - public DummyOutputFormat getOutputFormat() { - return DummyOutputFormat.INSTANCE; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/TemplateSeldomEscapedOutputModel.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/TemplateSeldomEscapedOutputModel.java b/src/test/java/org/apache/freemarker/core/TemplateSeldomEscapedOutputModel.java deleted file mode 100644 index 76afdd2..0000000 --- a/src/test/java/org/apache/freemarker/core/TemplateSeldomEscapedOutputModel.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.freemarker.core; - -import org.apache.freemarker.core.CommonTemplateMarkupOutputModel; - -public class TemplateSeldomEscapedOutputModel extends CommonTemplateMarkupOutputModel<TemplateSeldomEscapedOutputModel> { - - TemplateSeldomEscapedOutputModel(String plainTextContent, String markupContet) { - super(plainTextContent, markupContet); - } - - @Override - public SeldomEscapedOutputFormat getOutputFormat() { - return SeldomEscapedOutputFormat.INSTANCE; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/XHTMLOutputFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/XHTMLOutputFormatTest.java b/src/test/java/org/apache/freemarker/core/XHTMLOutputFormatTest.java index d4d9ca0..1bc49e2 100644 --- a/src/test/java/org/apache/freemarker/core/XHTMLOutputFormatTest.java +++ b/src/test/java/org/apache/freemarker/core/XHTMLOutputFormatTest.java @@ -18,7 +18,7 @@ */ package org.apache.freemarker.core; -import static org.apache.freemarker.core.XHTMLOutputFormat.*; +import static org.apache.freemarker.core.outputformat.impl.XHTMLOutputFormat.*; import static org.junit.Assert.*; import java.io.IOException; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/XMLOutputFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/XMLOutputFormatTest.java b/src/test/java/org/apache/freemarker/core/XMLOutputFormatTest.java index 09c075f..916193b 100644 --- a/src/test/java/org/apache/freemarker/core/XMLOutputFormatTest.java +++ b/src/test/java/org/apache/freemarker/core/XMLOutputFormatTest.java @@ -18,7 +18,7 @@ */ package org.apache.freemarker.core; -import static org.apache.freemarker.core.XMLOutputFormat.*; +import static org.apache.freemarker.core.outputformat.impl.XMLOutputFormat.*; import static org.junit.Assert.*; import java.io.IOException; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/model/impl/beans/ErrorMessagesTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/model/impl/beans/ErrorMessagesTest.java b/src/test/java/org/apache/freemarker/core/model/impl/beans/ErrorMessagesTest.java index b103e1f..3a030c3 100644 --- a/src/test/java/org/apache/freemarker/core/model/impl/beans/ErrorMessagesTest.java +++ b/src/test/java/org/apache/freemarker/core/model/impl/beans/ErrorMessagesTest.java @@ -30,8 +30,8 @@ import java.util.Collections; import java.util.Date; import org.apache.freemarker.core.Configuration; -import org.apache.freemarker.core.HTMLOutputFormat; -import org.apache.freemarker.core.TemplateHTMLOutputModel; +import org.apache.freemarker.core.outputformat.impl.HTMLOutputFormat; +import org.apache.freemarker.core.outputformat.impl.TemplateHTMLOutputModel; import org.apache.freemarker.core.model.TemplateHashModel; import org.apache.freemarker.core.model.TemplateMethodModelEx; import org.apache.freemarker.core.model.TemplateModelException; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/outputformat/_OutputFormatTestAPI.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/outputformat/_OutputFormatTestAPI.java b/src/test/java/org/apache/freemarker/core/outputformat/_OutputFormatTestAPI.java new file mode 100644 index 0000000..5cf183f --- /dev/null +++ b/src/test/java/org/apache/freemarker/core/outputformat/_OutputFormatTestAPI.java @@ -0,0 +1,35 @@ +/* + * 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.freemarker.core.outputformat; + +public final class _OutputFormatTestAPI { + + private _OutputFormatTestAPI() { + // + } + + public static String getMarkupContent(CommonTemplateMarkupOutputModel<?> tm) { + return tm.getMarkupContent(); + } + + public static String getPlainTextContent(CommonTemplateMarkupOutputModel<?> tm) { + return tm.getPlainTextContent(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/outputformat/impl/CombinedMarkupOutputFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/outputformat/impl/CombinedMarkupOutputFormatTest.java b/src/test/java/org/apache/freemarker/core/outputformat/impl/CombinedMarkupOutputFormatTest.java new file mode 100644 index 0000000..2f633c1 --- /dev/null +++ b/src/test/java/org/apache/freemarker/core/outputformat/impl/CombinedMarkupOutputFormatTest.java @@ -0,0 +1,196 @@ +/* + * 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.freemarker.core.outputformat.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + +import java.io.IOException; +import java.io.StringWriter; + +import org.apache.freemarker.core.model.TemplateModelException; +import org.apache.freemarker.core.outputformat.MarkupOutputFormat; +import org.apache.freemarker.core.outputformat._OutputFormatTestAPI; +import org.junit.Test; + +public class CombinedMarkupOutputFormatTest { + + private static final CombinedMarkupOutputFormat HTML_RTF = new CombinedMarkupOutputFormat( + HTMLOutputFormat.INSTANCE, RTFOutputFormat.INSTANCE); + private static final CombinedMarkupOutputFormat XML_XML = new CombinedMarkupOutputFormat( + XMLOutputFormat.INSTANCE, XMLOutputFormat.INSTANCE); + + @Test + public void testName() { + assertEquals("HTML{RTF}", HTML_RTF.getName()); + assertEquals("XML{XML}", XML_XML.getName()); + } + + @Test + public void testOutputMO() throws TemplateModelException, IOException { + StringWriter out = new StringWriter(); + + HTML_RTF.output(HTML_RTF.fromMarkup("<pre>\\par Test "), out); + HTML_RTF.output(HTML_RTF.fromPlainTextByEscaping("foo { bar } \\ "), out); + HTML_RTF.output(HTML_RTF.fromPlainTextByEscaping("& baaz "), out); + HTML_RTF.output(HTML_RTF.fromPlainTextByEscaping("\\par & qwe"), out); + HTML_RTF.output(HTML_RTF.fromMarkup("\\par{0} End</pre>"), out); + + assertEquals( + "<pre>\\par Test " + + "foo \\{ bar \\} \\\\ " + + "& baaz " + + "\\\\par & qwe" + + "\\par{0} End</pre>", + out.toString()); + } + + @Test + public void testOutputMO2() throws TemplateModelException, IOException { + StringWriter out = new StringWriter(); + + XML_XML.output(XML_XML.fromMarkup("<pre><p> Test "), out); + XML_XML.output(XML_XML.fromPlainTextByEscaping("a & b < c"), out); + XML_XML.output(XML_XML.fromMarkup(" End</pre>"), out); + + assertEquals( + "<pre><p> Test " + + "a &amp; b &lt; c" + + " End</pre>", + out.toString()); + } + + @Test + public void testOutputMO3() throws TemplateModelException, IOException { + MarkupOutputFormat outputFormat = new CombinedMarkupOutputFormat( + RTFOutputFormat.INSTANCE, + new CombinedMarkupOutputFormat(RTFOutputFormat.INSTANCE, RTFOutputFormat.INSTANCE)); + StringWriter out = new StringWriter(); + + outputFormat.output(outputFormat.fromPlainTextByEscaping("b{}"), out); + outputFormat.output(outputFormat.fromMarkup("a{}"), out); + + assertEquals( + "b\\\\\\\\\\\\\\{\\\\\\\\\\\\\\}" + + "a{}", + out.toString()); + } + + @Test + public void testOutputString() throws TemplateModelException, IOException { + StringWriter out = new StringWriter(); + + HTML_RTF.output("a", out); + HTML_RTF.output("{", out); + HTML_RTF.output("<b>}c", out); + + assertEquals("a\\{<b>\\}c", out.toString()); + } + + @Test + public void testOutputString2() throws TemplateModelException, IOException { + StringWriter out = new StringWriter(); + + XML_XML.output("a", out); + XML_XML.output("&", out); + XML_XML.output("<b>", out); + + assertEquals("a&amp;&lt;b&gt;", out.toString()); + } + + @Test + public void testFromPlainTextByEscaping() throws TemplateModelException { + String plainText = "a\\b&c"; + TemplateCombinedMarkupOutputModel mo = HTML_RTF.fromPlainTextByEscaping(plainText); + assertSame(plainText, _OutputFormatTestAPI.getPlainTextContent(mo)); + assertNull(_OutputFormatTestAPI.getMarkupContent(mo)); // Not the MO's duty to calculate it! + } + + @Test + public void testFromMarkup() throws TemplateModelException { + String markup = "a \\par <b>"; + TemplateCombinedMarkupOutputModel mo = HTML_RTF.fromMarkup(markup); + assertSame(markup, _OutputFormatTestAPI.getMarkupContent(mo)); + assertNull(_OutputFormatTestAPI.getPlainTextContent(mo)); // Not the MO's duty to calculate it! + } + + @Test + public void testGetMarkup() throws TemplateModelException { + { + String markup = "a \\par <b>"; + TemplateCombinedMarkupOutputModel mo = HTML_RTF.fromMarkup(markup); + assertSame(markup, HTML_RTF.getMarkupString(mo)); + } + + { + String safe = "abc"; + TemplateCombinedMarkupOutputModel mo = HTML_RTF.fromPlainTextByEscaping(safe); + assertSame(safe, HTML_RTF.getMarkupString(mo)); + } + } + + @Test + public void testConcat() throws Exception { + assertMO( + "ab", null, + HTML_RTF.concat( + new TemplateCombinedMarkupOutputModel("a", null, HTML_RTF), + new TemplateCombinedMarkupOutputModel("b", null, HTML_RTF))); + assertMO( + null, "ab", + HTML_RTF.concat( + new TemplateCombinedMarkupOutputModel(null, "a", HTML_RTF), + new TemplateCombinedMarkupOutputModel(null, "b", HTML_RTF))); + assertMO( + null, "{<a>}\\{<b>\\}", + HTML_RTF.concat( + new TemplateCombinedMarkupOutputModel(null, "{<a>}", HTML_RTF), + new TemplateCombinedMarkupOutputModel("{<b>}", null, HTML_RTF))); + assertMO( + null, "\\{<a>\\}{<b>}", + HTML_RTF.concat( + new TemplateCombinedMarkupOutputModel("{<a>}", null, HTML_RTF), + new TemplateCombinedMarkupOutputModel(null, "{<b>}", HTML_RTF))); + } + + @Test + public void testEscaplePlainText() throws TemplateModelException { + assertEquals("", HTML_RTF.escapePlainText("")); + assertEquals("a", HTML_RTF.escapePlainText("a")); + assertEquals("\\{a\\\\b&\\}", HTML_RTF.escapePlainText("{a\\b&}")); + assertEquals("a\\\\b&", HTML_RTF.escapePlainText("a\\b&")); + assertEquals("\\{\\}&", HTML_RTF.escapePlainText("{}&")); + + assertEquals("a", XML_XML.escapePlainText("a")); + assertEquals("a&apos;b", XML_XML.escapePlainText("a'b")); + } + + private void assertMO(String pc, String mc, TemplateCombinedMarkupOutputModel mo) { + assertEquals(pc, _OutputFormatTestAPI.getPlainTextContent(mo)); + assertEquals(mc, _OutputFormatTestAPI.getMarkupContent(mo)); + } + + @Test + public void testGetMimeType() { + assertEquals("text/html", HTML_RTF.getMimeType()); + assertEquals("application/xml", XML_XML.getMimeType()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/outputformat/impl/HTMLOutputFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/outputformat/impl/HTMLOutputFormatTest.java b/src/test/java/org/apache/freemarker/core/outputformat/impl/HTMLOutputFormatTest.java new file mode 100644 index 0000000..a06b11d --- /dev/null +++ b/src/test/java/org/apache/freemarker/core/outputformat/impl/HTMLOutputFormatTest.java @@ -0,0 +1,191 @@ +/* + * 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.freemarker.core.outputformat.impl; + +import static org.apache.freemarker.core.outputformat.impl.HTMLOutputFormat.INSTANCE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.io.StringWriter; + +import org.apache.freemarker.core.model.TemplateModelException; +import org.apache.freemarker.core.outputformat.CommonMarkupOutputFormat; +import org.apache.freemarker.core.outputformat._OutputFormatTestAPI; +import org.junit.Test; + +/** + * This actually more a {@link CommonMarkupOutputFormat} test. + */ +public class HTMLOutputFormatTest { + + @Test + public void testOutputMO() throws TemplateModelException, IOException { + StringWriter out = new StringWriter(); + + INSTANCE.output(INSTANCE.fromMarkup("<p>Test "), out); + INSTANCE.output(INSTANCE.fromPlainTextByEscaping("foo & bar "), out); + INSTANCE.output(INSTANCE.fromPlainTextByEscaping("baaz "), out); + INSTANCE.output(INSTANCE.fromPlainTextByEscaping("<b>A</b> <b>B</b> <b>C</b>"), out); + INSTANCE.output(INSTANCE.fromPlainTextByEscaping(""), out); + INSTANCE.output(INSTANCE.fromPlainTextByEscaping("\"' x's \"y\" \""), out); + INSTANCE.output(INSTANCE.fromMarkup("</p>"), out); + + assertEquals( + "<p>Test " + + "foo & bar " + + "baaz " + + "<b>A</b> <b>B</b> <b>C</b>" + + ""' x's "y" "" + + "</p>", + out.toString()); + } + + @Test + public void testOutputString() throws TemplateModelException, IOException { + StringWriter out = new StringWriter(); + + INSTANCE.output("a", out); + INSTANCE.output("<", out); + INSTANCE.output("b'c", out); + + assertEquals("a<b'c", out.toString()); + } + + @Test + public void testFromPlainTextByEscaping() throws TemplateModelException { + String plainText = "a&b"; + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping(plainText); + assertSame(plainText, _OutputFormatTestAPI.getPlainTextContent(mo)); + assertNull(_OutputFormatTestAPI.getMarkupContent(mo)); // Not the MO's duty to calculate it! + } + + @Test + public void testFromMarkup() throws TemplateModelException { + String markup = "a&b"; + TemplateHTMLOutputModel mo = INSTANCE.fromMarkup(markup); + assertSame(markup, _OutputFormatTestAPI.getMarkupContent(mo)); + assertNull(_OutputFormatTestAPI.getPlainTextContent(mo)); // Not the MO's duty to calculate it! + } + + @Test + public void testGetMarkup() throws TemplateModelException { + { + String markup = "a&b"; + TemplateHTMLOutputModel mo = INSTANCE.fromMarkup(markup); + assertSame(markup, INSTANCE.getMarkupString(mo)); + } + + { + String safe = "abc"; + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping(safe); + assertSame(safe, INSTANCE.getMarkupString(mo)); + } + { + String safe = ""; + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping(safe); + assertSame(safe, INSTANCE.getMarkupString(mo)); + } + { + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("<abc"); + assertEquals("<abc", INSTANCE.getMarkupString(mo)); + } + { + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("abc>"); + assertEquals("abc>", INSTANCE.getMarkupString(mo)); + } + { + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("<abc>"); + assertEquals("<abc>", INSTANCE.getMarkupString(mo)); + } + { + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("a&bc"); + assertEquals("a&bc", INSTANCE.getMarkupString(mo)); + } + { + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("a&b&c"); + assertEquals("a&b&c", INSTANCE.getMarkupString(mo)); + } + { + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("a<&>b&c"); + assertEquals("a<&>b&c", INSTANCE.getMarkupString(mo)); + } + { + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("\"<a<&>b&c>\""); + assertEquals(""<a<&>b&c>"", INSTANCE.getMarkupString(mo)); + } + { + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("<"); + assertEquals("<", INSTANCE.getMarkupString(mo)); + } + { + TemplateHTMLOutputModel mo = INSTANCE.fromPlainTextByEscaping("'"); + String mc = INSTANCE.getMarkupString(mo); + assertEquals("'", mc); + assertSame(mc, INSTANCE.getMarkupString(mo)); // cached + } + } + + @Test + public void testConcat() throws Exception { + assertMO( + "ab", null, + INSTANCE.concat(new TemplateHTMLOutputModel("a", null), new TemplateHTMLOutputModel("b", null))); + assertMO( + null, "ab", + INSTANCE.concat(new TemplateHTMLOutputModel(null, "a"), new TemplateHTMLOutputModel(null, "b"))); + assertMO( + null, "<a><b>", + INSTANCE.concat(new TemplateHTMLOutputModel(null, "<a>"), new TemplateHTMLOutputModel("<b>", null))); + assertMO( + null, "<a><b>", + INSTANCE.concat(new TemplateHTMLOutputModel("<a>", null), new TemplateHTMLOutputModel(null, "<b>"))); + } + + @Test + public void testEscaplePlainText() { + assertEquals("", INSTANCE.escapePlainText("")); + assertEquals("a", INSTANCE.escapePlainText("a")); + assertEquals("<a&b'c"d>", INSTANCE.escapePlainText("<a&b'c\"d>")); + assertEquals("a&b", INSTANCE.escapePlainText("a&b")); + assertEquals("<>", INSTANCE.escapePlainText("<>")); + } + + @Test + public void testIsEmpty() throws Exception { + assertTrue(INSTANCE.isEmpty(INSTANCE.fromMarkup(""))); + assertTrue(INSTANCE.isEmpty(INSTANCE.fromPlainTextByEscaping(""))); + assertFalse(INSTANCE.isEmpty(INSTANCE.fromMarkup(" "))); + assertFalse(INSTANCE.isEmpty(INSTANCE.fromPlainTextByEscaping(" "))); + } + + private void assertMO(String pc, String mc, TemplateHTMLOutputModel mo) { + assertEquals(pc, _OutputFormatTestAPI.getPlainTextContent(mo)); + assertEquals(mc, _OutputFormatTestAPI.getMarkupContent(mo)); + } + + @Test + public void testGetMimeType() { + assertEquals("text/html", INSTANCE.getMimeType()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/outputformat/impl/RTFOutputFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/outputformat/impl/RTFOutputFormatTest.java b/src/test/java/org/apache/freemarker/core/outputformat/impl/RTFOutputFormatTest.java new file mode 100644 index 0000000..3f3d626 --- /dev/null +++ b/src/test/java/org/apache/freemarker/core/outputformat/impl/RTFOutputFormatTest.java @@ -0,0 +1,131 @@ +/* + * 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.freemarker.core.outputformat.impl; + +import static org.apache.freemarker.core.outputformat.impl.RTFOutputFormat.INSTANCE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + +import java.io.IOException; +import java.io.StringWriter; + +import org.apache.freemarker.core.model.TemplateModelException; +import org.apache.freemarker.core.outputformat._OutputFormatTestAPI; +import org.junit.Test; + +public class RTFOutputFormatTest { + + @Test + public void testOutputMO() throws TemplateModelException, IOException { + StringWriter out = new StringWriter(); + + INSTANCE.output(INSTANCE.fromMarkup("\\par Test "), out); + INSTANCE.output(INSTANCE.fromPlainTextByEscaping("foo { bar } \\ "), out); + INSTANCE.output(INSTANCE.fromPlainTextByEscaping("baaz "), out); + INSTANCE.output(INSTANCE.fromPlainTextByEscaping("\\par qweqwe"), out); + INSTANCE.output(INSTANCE.fromMarkup("\\par{0} End"), out); + + assertEquals( + "\\par Test " + + "foo \\{ bar \\} \\\\ " + + "baaz " + + "\\\\par qweqwe" + + "\\par{0} End", + out.toString()); + } + + @Test + public void testOutputString() throws TemplateModelException, IOException { + StringWriter out = new StringWriter(); + + INSTANCE.output("a", out); + INSTANCE.output("{", out); + INSTANCE.output("b}c", out); + + assertEquals("a\\{b\\}c", out.toString()); + } + + @Test + public void testFromPlainTextByEscaping() throws TemplateModelException { + String plainText = "a\\b"; + TemplateRTFOutputModel mo = INSTANCE.fromPlainTextByEscaping(plainText); + assertSame(plainText, _OutputFormatTestAPI.getPlainTextContent(mo)); + assertNull(_OutputFormatTestAPI.getMarkupContent(mo)); // Not the MO's duty to calculate it! + } + + @Test + public void testFromMarkup() throws TemplateModelException { + String markup = "a \\par b"; + TemplateRTFOutputModel mo = INSTANCE.fromMarkup(markup); + assertSame(markup, _OutputFormatTestAPI.getMarkupContent(mo)); + assertNull(_OutputFormatTestAPI.getPlainTextContent(mo)); // Not the MO's duty to calculate it! + } + + @Test + public void testGetMarkup() throws TemplateModelException { + { + String markup = "a \\par b"; + TemplateRTFOutputModel mo = INSTANCE.fromMarkup(markup); + assertSame(markup, INSTANCE.getMarkupString(mo)); + } + + { + String safe = "abc"; + TemplateRTFOutputModel mo = INSTANCE.fromPlainTextByEscaping(safe); + assertSame(safe, INSTANCE.getMarkupString(mo)); + } + } + + @Test + public void testConcat() throws Exception { + assertMO( + "ab", null, + INSTANCE.concat(new TemplateRTFOutputModel("a", null), new TemplateRTFOutputModel("b", null))); + assertMO( + null, "ab", + INSTANCE.concat(new TemplateRTFOutputModel(null, "a"), new TemplateRTFOutputModel(null, "b"))); + assertMO( + null, "{a}\\{b\\}", + INSTANCE.concat(new TemplateRTFOutputModel(null, "{a}"), new TemplateRTFOutputModel("{b}", null))); + assertMO( + null, "\\{a\\}{b}", + INSTANCE.concat(new TemplateRTFOutputModel("{a}", null), new TemplateRTFOutputModel(null, "{b}"))); + } + + @Test + public void testEscaplePlainText() { + assertEquals("", INSTANCE.escapePlainText("")); + assertEquals("a", INSTANCE.escapePlainText("a")); + assertEquals("\\{a\\\\b\\}", INSTANCE.escapePlainText("{a\\b}")); + assertEquals("a\\\\b", INSTANCE.escapePlainText("a\\b")); + assertEquals("\\{\\}", INSTANCE.escapePlainText("{}")); + } + + private void assertMO(String pc, String mc, TemplateRTFOutputModel mo) { + assertEquals(pc, _OutputFormatTestAPI.getPlainTextContent(mo)); + assertEquals(mc, _OutputFormatTestAPI.getMarkupContent(mo)); + } + + @Test + public void testGetMimeType() { + assertEquals("application/rtf", INSTANCE.getMimeType()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/userpkg/CustomHTMLOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/userpkg/CustomHTMLOutputFormat.java b/src/test/java/org/apache/freemarker/core/userpkg/CustomHTMLOutputFormat.java new file mode 100644 index 0000000..7ccd186 --- /dev/null +++ b/src/test/java/org/apache/freemarker/core/userpkg/CustomHTMLOutputFormat.java @@ -0,0 +1,72 @@ +/* + * 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.freemarker.core.userpkg; + +import java.io.IOException; +import java.io.Writer; + +import org.apache.freemarker.core.model.TemplateModelException; +import org.apache.freemarker.core.outputformat.CommonMarkupOutputFormat; +import org.apache.freemarker.core.util._StringUtil; + +/** + * Represents the HTML output format. + * + * @since 2.3.24 + */ +public final class CustomHTMLOutputFormat extends CommonMarkupOutputFormat<CustomTemplateHTMLModel> { + + public static final CustomHTMLOutputFormat INSTANCE = new CustomHTMLOutputFormat(); + + private CustomHTMLOutputFormat() { + // Only to decrease visibility + } + + @Override + public String getName() { + return "HTML"; + } + + @Override + public String getMimeType() { + return "text/html"; + } + + @Override + public void output(String textToEsc, Writer out) throws IOException, TemplateModelException { + // This is lazy - don't do it in reality. + out.write(escapePlainText(textToEsc)); + } + + @Override + public String escapePlainText(String plainTextContent) { + return _StringUtil.XHTMLEnc(plainTextContent.replace('x', 'X')); + } + + @Override + public boolean isLegacyBuiltInBypassed(String builtInName) { + return builtInName.equals("html") || builtInName.equals("xml") || builtInName.equals("xhtml"); + } + + @Override + protected CustomTemplateHTMLModel newTemplateMarkupOutputModel(String plainTextContent, String markupContent) { + return new CustomTemplateHTMLModel(plainTextContent, markupContent); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/userpkg/CustomTemplateHTMLModel.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/userpkg/CustomTemplateHTMLModel.java b/src/test/java/org/apache/freemarker/core/userpkg/CustomTemplateHTMLModel.java new file mode 100644 index 0000000..7327a33 --- /dev/null +++ b/src/test/java/org/apache/freemarker/core/userpkg/CustomTemplateHTMLModel.java @@ -0,0 +1,34 @@ +/* + * 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.freemarker.core.userpkg; + +import org.apache.freemarker.core.outputformat.CommonTemplateMarkupOutputModel; + +public final class CustomTemplateHTMLModel extends CommonTemplateMarkupOutputModel<CustomTemplateHTMLModel> { + + CustomTemplateHTMLModel(String plainTextContent, String markupContent) { + super(plainTextContent, markupContent); + } + + @Override + public CustomHTMLOutputFormat getOutputFormat() { + return CustomHTMLOutputFormat.INSTANCE; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/userpkg/DummyOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/userpkg/DummyOutputFormat.java b/src/test/java/org/apache/freemarker/core/userpkg/DummyOutputFormat.java new file mode 100644 index 0000000..91c074e --- /dev/null +++ b/src/test/java/org/apache/freemarker/core/userpkg/DummyOutputFormat.java @@ -0,0 +1,65 @@ +/* + * 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.freemarker.core.userpkg; + +import java.io.IOException; +import java.io.Writer; + +import org.apache.freemarker.core.model.TemplateModelException; +import org.apache.freemarker.core.outputformat.CommonMarkupOutputFormat; + +public class DummyOutputFormat extends CommonMarkupOutputFormat<TemplateDummyOutputModel> { + + public static final DummyOutputFormat INSTANCE = new DummyOutputFormat(); + + private DummyOutputFormat() { + // hide + } + + @Override + public String getName() { + return "dummy"; + } + + @Override + public String getMimeType() { + return "text/dummy"; + } + + @Override + public void output(String textToEsc, Writer out) throws IOException, TemplateModelException { + out.write(escapePlainText(textToEsc)); + } + + @Override + public String escapePlainText(String plainTextContent) { + return plainTextContent.replaceAll("(\\.|\\\\)", "\\\\$1"); + } + + @Override + public boolean isLegacyBuiltInBypassed(String builtInName) { + return false; + } + + @Override + protected TemplateDummyOutputModel newTemplateMarkupOutputModel(String plainTextContent, String markupContent) { + return new TemplateDummyOutputModel(plainTextContent, markupContent); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/userpkg/SeldomEscapedOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/userpkg/SeldomEscapedOutputFormat.java b/src/test/java/org/apache/freemarker/core/userpkg/SeldomEscapedOutputFormat.java new file mode 100644 index 0000000..5ca8905 --- /dev/null +++ b/src/test/java/org/apache/freemarker/core/userpkg/SeldomEscapedOutputFormat.java @@ -0,0 +1,71 @@ +/* + * 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.freemarker.core.userpkg; + +import java.io.IOException; +import java.io.Writer; + +import org.apache.freemarker.core.model.TemplateModelException; +import org.apache.freemarker.core.outputformat.CommonMarkupOutputFormat; + +public class SeldomEscapedOutputFormat extends CommonMarkupOutputFormat<TemplateSeldomEscapedOutputModel> { + + public static final SeldomEscapedOutputFormat INSTANCE = new SeldomEscapedOutputFormat(); + + private SeldomEscapedOutputFormat() { + // hide + } + + @Override + public String getName() { + return "seldomEscaped"; + } + + @Override + public String getMimeType() { + return "text/seldomEscaped"; + } + + @Override + public void output(String textToEsc, Writer out) throws IOException, TemplateModelException { + out.write(escapePlainText(textToEsc)); + } + + @Override + public String escapePlainText(String plainTextContent) { + return plainTextContent.replaceAll("(\\.|\\\\)", "\\\\$1"); + } + + @Override + public boolean isLegacyBuiltInBypassed(String builtInName) { + return false; + } + + @Override + public boolean isAutoEscapedByDefault() { + return false; + } + + @Override + protected TemplateSeldomEscapedOutputModel newTemplateMarkupOutputModel( + String plainTextContent, String markupContent) { + return new TemplateSeldomEscapedOutputModel(plainTextContent, markupContent); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/userpkg/TemplateDummyOutputModel.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/userpkg/TemplateDummyOutputModel.java b/src/test/java/org/apache/freemarker/core/userpkg/TemplateDummyOutputModel.java new file mode 100644 index 0000000..6675f68 --- /dev/null +++ b/src/test/java/org/apache/freemarker/core/userpkg/TemplateDummyOutputModel.java @@ -0,0 +1,34 @@ +/* + * 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.freemarker.core.userpkg; + +import org.apache.freemarker.core.outputformat.CommonTemplateMarkupOutputModel; + +public class TemplateDummyOutputModel extends CommonTemplateMarkupOutputModel<TemplateDummyOutputModel> { + + TemplateDummyOutputModel(String plainTextContent, String markupContet) { + super(plainTextContent, markupContet); + } + + @Override + public DummyOutputFormat getOutputFormat() { + return DummyOutputFormat.INSTANCE; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/core/userpkg/TemplateSeldomEscapedOutputModel.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/userpkg/TemplateSeldomEscapedOutputModel.java b/src/test/java/org/apache/freemarker/core/userpkg/TemplateSeldomEscapedOutputModel.java new file mode 100644 index 0000000..b35bc09 --- /dev/null +++ b/src/test/java/org/apache/freemarker/core/userpkg/TemplateSeldomEscapedOutputModel.java @@ -0,0 +1,34 @@ +/* + * 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.freemarker.core.userpkg; + +import org.apache.freemarker.core.outputformat.CommonTemplateMarkupOutputModel; + +public class TemplateSeldomEscapedOutputModel extends CommonTemplateMarkupOutputModel<TemplateSeldomEscapedOutputModel> { + + TemplateSeldomEscapedOutputModel(String plainTextContent, String markupContet) { + super(plainTextContent, markupContet); + } + + @Override + public SeldomEscapedOutputFormat getOutputFormat() { + return SeldomEscapedOutputFormat.INSTANCE; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/manualtest/ConfigureOutputFormatExamples.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/manualtest/ConfigureOutputFormatExamples.java b/src/test/java/org/apache/freemarker/manualtest/ConfigureOutputFormatExamples.java index 83eb440..eba927d 100644 --- a/src/test/java/org/apache/freemarker/manualtest/ConfigureOutputFormatExamples.java +++ b/src/test/java/org/apache/freemarker/manualtest/ConfigureOutputFormatExamples.java @@ -21,10 +21,10 @@ package org.apache.freemarker.manualtest; import static org.junit.Assert.*; import org.apache.freemarker.core.Configuration; -import org.apache.freemarker.core.HTMLOutputFormat; -import org.apache.freemarker.core.RTFOutputFormat; +import org.apache.freemarker.core.outputformat.impl.HTMLOutputFormat; +import org.apache.freemarker.core.outputformat.impl.RTFOutputFormat; import org.apache.freemarker.core.TemplateConfiguration; -import org.apache.freemarker.core.XMLOutputFormat; +import org.apache.freemarker.core.outputformat.impl.XMLOutputFormat; import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory; import org.apache.freemarker.core.templateresolver.FileExtensionMatcher; import org.apache.freemarker.core.templateresolver.FirstMatchTemplateConfigurationFactory; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/db77001f/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java b/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java index a2facaf..af5ba00 100644 --- a/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java +++ b/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java @@ -23,12 +23,12 @@ import static org.junit.Assert.*; import java.util.Date; import org.apache.freemarker.core.Configuration; -import org.apache.freemarker.core.HTMLOutputFormat; -import org.apache.freemarker.core.PlainTextOutputFormat; +import org.apache.freemarker.core.outputformat.impl.HTMLOutputFormat; +import org.apache.freemarker.core.outputformat.impl.PlainTextOutputFormat; +import org.apache.freemarker.core.outputformat.impl.UndefinedOutputFormat; import org.apache.freemarker.core.Template; import org.apache.freemarker.core.TemplateConfiguration; -import org.apache.freemarker.core.UndefinedOutputFormat; -import org.apache.freemarker.core.XMLOutputFormat; +import org.apache.freemarker.core.outputformat.impl.XMLOutputFormat; import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory; import org.apache.freemarker.core.templateresolver.FileExtensionMatcher; import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher;
