Search in sources :

Example 1 with NullArgumentException

use of freemarker.template.utility.NullArgumentException in project freemarker by apache.

the class TemplateConfigurationTest method testSetParentConfiguration.

@Test
public void testSetParentConfiguration() throws IOException {
    TemplateConfiguration tc = new TemplateConfiguration();
    Template t = new Template(null, "", DEFAULT_CFG);
    try {
        tc.apply(t);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e.getMessage(), containsString("Configuration"));
    }
    tc.setParent(DEFAULT_CFG);
    try {
        tc.setParentConfiguration(new Configuration());
        fail();
    } catch (IllegalStateException e) {
        assertThat(e.getMessage(), containsString("Configuration"));
    }
    try {
        // Same as setParentConfiguration
        tc.setParent(new Configuration());
        fail();
    } catch (IllegalStateException e) {
        assertThat(e.getMessage(), containsString("Configuration"));
    }
    try {
        tc.setParentConfiguration(null);
        fail();
    } catch (NullArgumentException e) {
    // exected
    }
    tc.setParent(DEFAULT_CFG);
    tc.apply(t);
}
Also used : Configuration(freemarker.template.Configuration) NullArgumentException(freemarker.template.utility.NullArgumentException) Template(freemarker.template.Template) Test(org.junit.Test)

Example 2 with NullArgumentException

use of freemarker.template.utility.NullArgumentException in project freemarker by apache.

the class Configuration method setOutputFormat.

/**
 * Sets the default output format. Usually, you should leave this on its default, which is
 * {@link UndefinedOutputFormat#INSTANCE}, and then use standard file extensions like "ftlh" (for HTML) or "ftlx"
 * (for XML) and ensure that {@link #setRecognizeStandardFileExtensions(boolean)} is {@code true} (see more there).
 * Where you can't use the standard extensions, templates still can be associated to output formats with
 * patterns matching their name (their path) using {@link #setTemplateConfigurations(TemplateConfigurationFactory)}.
 * But if all templates will have the same output format, you may use {@link #setOutputFormat(OutputFormat)} after
 * all, to a value like {@link HTMLOutputFormat#INSTANCE}, {@link XMLOutputFormat#INSTANCE}, etc. Also note
 * that templates can specify their own output format like {@code
 * <#ftl output_format="HTML">}, which overrides any configuration settings.
 *
 * <p>
 * The output format is mostly important because of auto-escaping (see {@link #setAutoEscapingPolicy(int)}), but
 * maybe also used by the embedding application to set the HTTP response MIME type, etc.
 *
 * @see #setRegisteredCustomOutputFormats(Collection)
 * @see #setTemplateConfigurations(TemplateConfigurationFactory)
 * @see #setRecognizeStandardFileExtensions(boolean)
 * @see #setAutoEscapingPolicy(int)
 *
 * @since 2.3.24
 */
public void setOutputFormat(OutputFormat outputFormat) {
    if (outputFormat == null) {
        throw new NullArgumentException("outputFormat", "You may meant: " + UndefinedOutputFormat.class.getSimpleName() + ".INSTANCE");
    }
    OutputFormat prevOutputFormat = getOutputFormat();
    this.outputFormat = outputFormat;
    outputFormatExplicitlySet = true;
    if (prevOutputFormat != outputFormat) {
        clearTemplateCache();
    }
}
Also used : UndefinedOutputFormat(freemarker.core.UndefinedOutputFormat) UndefinedOutputFormat(freemarker.core.UndefinedOutputFormat) CSSOutputFormat(freemarker.core.CSSOutputFormat) HTMLOutputFormat(freemarker.core.HTMLOutputFormat) CombinedMarkupOutputFormat(freemarker.core.CombinedMarkupOutputFormat) JavaScriptOutputFormat(freemarker.core.JavaScriptOutputFormat) OutputFormat(freemarker.core.OutputFormat) XMLOutputFormat(freemarker.core.XMLOutputFormat) MarkupOutputFormat(freemarker.core.MarkupOutputFormat) PlainTextOutputFormat(freemarker.core.PlainTextOutputFormat) XHTMLOutputFormat(freemarker.core.XHTMLOutputFormat) RTFOutputFormat(freemarker.core.RTFOutputFormat) JSONOutputFormat(freemarker.core.JSONOutputFormat) NullArgumentException(freemarker.template.utility.NullArgumentException)

Aggregations

NullArgumentException (freemarker.template.utility.NullArgumentException)2 CSSOutputFormat (freemarker.core.CSSOutputFormat)1 CombinedMarkupOutputFormat (freemarker.core.CombinedMarkupOutputFormat)1 HTMLOutputFormat (freemarker.core.HTMLOutputFormat)1 JSONOutputFormat (freemarker.core.JSONOutputFormat)1 JavaScriptOutputFormat (freemarker.core.JavaScriptOutputFormat)1 MarkupOutputFormat (freemarker.core.MarkupOutputFormat)1 OutputFormat (freemarker.core.OutputFormat)1 PlainTextOutputFormat (freemarker.core.PlainTextOutputFormat)1 RTFOutputFormat (freemarker.core.RTFOutputFormat)1 UndefinedOutputFormat (freemarker.core.UndefinedOutputFormat)1 XHTMLOutputFormat (freemarker.core.XHTMLOutputFormat)1 XMLOutputFormat (freemarker.core.XMLOutputFormat)1 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 Test (org.junit.Test)1