Repository: incubator-freemarker Updated Branches: refs/heads/3 be5568979 -> 99ac69739
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/99ac6973/freemarker-core/src/main/java/org/apache/freemarker/core/ParsingConfiguration.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/ParsingConfiguration.java b/freemarker-core/src/main/java/org/apache/freemarker/core/ParsingConfiguration.java index 0eb9569..6b40359 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/ParsingConfiguration.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/ParsingConfiguration.java @@ -21,7 +21,6 @@ package org.apache.freemarker.core; import java.nio.charset.Charset; import org.apache.freemarker.core.arithmetic.ArithmeticEngine; -import org.apache.freemarker.core.outputformat.MarkupOutputFormat; import org.apache.freemarker.core.outputformat.OutputFormat; import org.apache.freemarker.core.outputformat.impl.HTMLOutputFormat; import org.apache.freemarker.core.outputformat.impl.UndefinedOutputFormat; @@ -37,27 +36,6 @@ import org.apache.freemarker.core.outputformat.impl.XMLOutputFormat; */ public interface ParsingConfiguration { - int AUTO_DETECT_NAMING_CONVENTION = 10; - int LEGACY_NAMING_CONVENTION = 11; - int CAMEL_CASE_NAMING_CONVENTION = 12; - - int AUTO_DETECT_TAG_SYNTAX = 0; - int ANGLE_BRACKET_TAG_SYNTAX = 1; - int SQUARE_BRACKET_TAG_SYNTAX = 2; - - /** - * Don't enable auto-escaping, regardless of what the {@link OutputFormat} is. Note that a {@code - * <#ftl auto_esc=true>} in the template will override this. - */ - int DISABLE_AUTO_ESCAPING_POLICY = 20; - /** - * Enable auto-escaping if the output format supports it and {@link MarkupOutputFormat#isAutoEscapedByDefault()} is - * {@code true}. - */ - int ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY = 21; - /** Enable auto-escaping if the {@link OutputFormat} supports it. */ - int ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY = 22; - /** * The template language used; this is often overridden for certain file extension with the * {@link Configuration#getTemplateConfigurations() templateConfigurations} setting of the {@link Configuration}. @@ -71,25 +49,25 @@ public interface ParsingConfiguration { * that has no {@code #ftl} in it. The {@code tagSyntax} * parameter must be one of: * <ul> - * <li>{@link #AUTO_DETECT_TAG_SYNTAX}: + * <li>{@link TagSyntax#AUTO_DETECT}: * use the syntax of the first FreeMarker tag (can be anything, like <tt>#list</tt>, * <tt>#include</tt>, user defined, etc.) - * <li>{@link #ANGLE_BRACKET_TAG_SYNTAX}: + * <li>{@link TagSyntax#ANGLE_BRACKET}: * use the angle bracket syntax (the normal syntax) - * <li>{@link #SQUARE_BRACKET_TAG_SYNTAX}: + * <li>{@link TagSyntax#SQUARE_BRACKET}: * use the square bracket syntax * </ul> * - * <p>In FreeMarker 2.3.x {@link #ANGLE_BRACKET_TAG_SYNTAX} is the + * <p>In FreeMarker 2.3.x {@link TagSyntax#ANGLE_BRACKET} is the * default for better backward compatibility. Starting from 2.4.x {@link - * ParsingConfiguration#AUTO_DETECT_TAG_SYNTAX} is the default, so it's recommended to use + * TagSyntax#AUTO_DETECT} is the default, so it's recommended to use * that even for 2.3.x. * * <p>This setting is ignored for the templates that have {@code ftl} directive in * it. For those templates the syntax used for the {@code ftl} directive determines * the syntax. */ - int getTagSyntax(); + TagSyntax getTagSyntax(); /** * Tells if this setting is set directly in this object. If not, then depending on the implementing class, reading @@ -113,14 +91,15 @@ public interface ParsingConfiguration { * * <p> * Which convention to use: FreeMarker prior to 2.3.23 has only supported - * {@link #LEGACY_NAMING_CONVENTION}, so that's how most templates and examples out there are written + * {@link NamingConvention#LEGACY}, so that's how most templates and examples out there are + * written * as of 2015. But as templates today are mostly written by programmers and often access Java API-s which already - * use camel case, {@link #CAMEL_CASE_NAMING_CONVENTION} is the recommended option for most projects. + * use camel case, {@link NamingConvention#CAMEL_CASE} is the recommended option for most projects. * However, it's no necessary to make a application-wide decision; see auto-detection below. * * <p> * FreeMarker will decide the naming convention automatically for each template individually when this setting is - * set to {@link #AUTO_DETECT_NAMING_CONVENTION} (which is the default). The naming convention of a template is + * set to {@link NamingConvention#AUTO_DETECT} (which is the default). The naming convention of a template is * decided when the first core (non-user-defined) identifier is met during parsing (not during processing) where the * naming convention is relevant (like for {@code s?upperCase} or {@code s?upper_case} it's relevant, but for * {@code s?length} it isn't). At that point, the naming convention of the template is decided, and any later core @@ -130,15 +109,15 @@ public interface ParsingConfiguration { * * <p> * FreeMarker always enforces the same naming convention to be used consistently within the same template "file". - * Additionally, when this setting is set to non-{@link #AUTO_DETECT_NAMING_CONVENTION}, the selected naming + * Additionally, when this setting is set to non-{@link NamingConvention#AUTO_DETECT}, the selected naming * convention is enforced on all templates. Thus such a setup can be used to enforce an application-wide naming * convention. * * @return - * One of the {@link #AUTO_DETECT_NAMING_CONVENTION} or - * {@link #LEGACY_NAMING_CONVENTION} or {@link #CAMEL_CASE_NAMING_CONVENTION}. + * One of the {@link NamingConvention#AUTO_DETECT} or + * {@link NamingConvention#LEGACY} or {@link NamingConvention#CAMEL_CASE}. */ - int getNamingConvention(); + NamingConvention getNamingConvention(); /** * Tells if this setting is set directly in this object. If not, then depending on the implementing class, reading @@ -175,7 +154,7 @@ public interface ParsingConfiguration { /** * See {@link Configuration#getAutoEscapingPolicy()}. */ - int getAutoEscapingPolicy(); + AutoEscapingPolicy getAutoEscapingPolicy(); /** * Tells if this setting is set directly in this object. If not, then depending on the implementing class, reading @@ -225,12 +204,12 @@ public interface ParsingConfiguration { * (i.e., {@link HTMLOutputFormat#INSTANCE}, unless the {@code "HTML"} name is overridden by * the {@link Configuration#getRegisteredCustomOutputFormats registeredOutputFormats} setting) and * the {@link #getAutoEscapingPolicy() autoEscapingPolicy} setting to - * {@link #ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY}. + * {@link AutoEscapingPolicy#ENABLE_IF_DEFAULT}. * <li>{@code ftlx}: Sets the {@link #getOutputFormat() outputFormat} setting to * {@code "XML"} (i.e., {@link XMLOutputFormat#INSTANCE}, unless the {@code "XML"} name is overridden by * the {@link Configuration#getRegisteredCustomOutputFormats registeredOutputFormats} setting) and * the {@link #getAutoEscapingPolicy() autoEscapingPolicy} setting to - * {@link #ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY}. + * {@link AutoEscapingPolicy#ENABLE_IF_DEFAULT}. * </ul> * * <p>These file extensions are not case sensitive. The file extension is the part after the last dot in the source http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/99ac6973/freemarker-core/src/main/java/org/apache/freemarker/core/TagSyntax.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/TagSyntax.java b/freemarker-core/src/main/java/org/apache/freemarker/core/TagSyntax.java new file mode 100644 index 0000000..423ab9c --- /dev/null +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/TagSyntax.java @@ -0,0 +1,29 @@ +/* + * 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; + +/** + * Used as the value of the {@link ParsingConfiguration#getTagSyntax()} tagSyntax} setting. + */ +public enum TagSyntax { + AUTO_DETECT, + ANGLE_BRACKET, + SQUARE_BRACKET +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/99ac6973/freemarker-core/src/main/java/org/apache/freemarker/core/Template.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/Template.java b/freemarker-core/src/main/java/org/apache/freemarker/core/Template.java index c4787e4..7562b85 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/Template.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/Template.java @@ -115,12 +115,12 @@ public class Template implements ProcessingConfiguration, CustomStateScope { private Map<String, Serializable> customAttributes; private transient Map<Object, Object> mergedCustomAttributes; - private Integer autoEscapingPolicy; + private AutoEscapingPolicy autoEscapingPolicy; // Values from template content that are detected automatically: private Charset actualSourceEncoding; - private int actualTagSyntax; + private TagSyntax actualTagSyntax; - private int actualNamingConvention; + private NamingConvention actualNamingConvention; // Custom state: private final Object customStateMapLock = new Object(); private final ConcurrentHashMap<CustomStateKey, Object> customStateMap = new ConcurrentHashMap<>(0); @@ -283,7 +283,7 @@ public class Template implements ProcessingConfiguration, CustomStateScope { Template( String lookupName, String sourceName, Reader reader, Configuration configuration, TemplateConfiguration templateConfiguration, - OutputFormat contextOutputFormat, Integer contextAutoEscapingPolicy, + OutputFormat contextOutputFormat, AutoEscapingPolicy contextAutoEscapingPolicy, Charset actualSourceEncoding, InputStream streamToUnmarkWhenEncEstabd) throws IOException, ParseException { _NullArgumentException.check("configuration", configuration); this.cfg = configuration; @@ -659,27 +659,27 @@ public class Template implements ProcessingConfiguration, CustomStateScope { /** * Returns the tag syntax the parser has chosen for this template. If the syntax could be determined, it's - * {@link ParsingConfiguration#SQUARE_BRACKET_TAG_SYNTAX} or {@link ParsingConfiguration#ANGLE_BRACKET_TAG_SYNTAX}. If the syntax + * {@link TagSyntax#SQUARE_BRACKET} or {@link TagSyntax#ANGLE_BRACKET}. If the syntax * couldn't be determined (like because there was no tags in the template, or it was a plain text template), this * returns whatever the default is in the current configuration, so it's maybe - * {@link ParsingConfiguration#AUTO_DETECT_TAG_SYNTAX}. + * {@link TagSyntax#AUTO_DETECT}. * * @since 2.3.20 */ - public int getActualTagSyntax() { + public TagSyntax getActualTagSyntax() { return actualTagSyntax; } /** * Returns the naming convention the parser has chosen for this template. If it could be determined, it's - * {@link ParsingConfiguration#LEGACY_NAMING_CONVENTION} or {@link ParsingConfiguration#CAMEL_CASE_NAMING_CONVENTION}. If it + * {@link NamingConvention#LEGACY} or {@link NamingConvention#CAMEL_CASE}. If it * couldn't be determined (like because there no identifier that's part of the template language was used where * the naming convention matters), this returns whatever the default is in the current configuration, so it's maybe - * {@link ParsingConfiguration#AUTO_DETECT_TAG_SYNTAX}. + * {@link TagSyntax#AUTO_DETECT}. * * @since 2.3.23 */ - public int getActualNamingConvention() { + public NamingConvention getActualNamingConvention() { return actualNamingConvention; } @@ -709,7 +709,7 @@ public class Template implements ProcessingConfiguration, CustomStateScope { * {@link Configuration#getAutoEscapingPolicy()}, {@link ParsingConfiguration#getAutoEscapingPolicy()}, * {@code #ftl} header's {@code auto_esc} option in the template. */ - public int getAutoEscapingPolicy() { + public AutoEscapingPolicy getAutoEscapingPolicy() { return autoEscapingPolicy != null ? autoEscapingPolicy : tCfg != null && tCfg.isAutoEscapingPolicySet() ? tCfg.getAutoEscapingPolicy() : cfg.getAutoEscapingPolicy(); @@ -718,7 +718,7 @@ public class Template implements ProcessingConfiguration, CustomStateScope { /** * Should be called by the parser, for example to apply the auto escaping policy specified in the #ftl header. */ - void setAutoEscapingPolicy(int autoEscapingPolicy) { + void setAutoEscapingPolicy(AutoEscapingPolicy autoEscapingPolicy) { this.autoEscapingPolicy = autoEscapingPolicy; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/99ac6973/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java b/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java index a8fc5ae..77a40bb 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java @@ -84,10 +84,10 @@ public final class TemplateConfiguration implements ParsingAndProcessingConfigur private final Map<Object, Object> customAttributes; private final TemplateLanguage templateLanguage; - private final Integer tagSyntax; - private final Integer namingConvention; + private final TagSyntax tagSyntax; + private final NamingConvention namingConvention; private final Boolean whitespaceStripping; - private final Integer autoEscapingPolicy; + private final AutoEscapingPolicy autoEscapingPolicy; private final Boolean recognizeStandardFileExtensions; private final OutputFormat outputFormat; private final Charset sourceEncoding; @@ -185,7 +185,7 @@ public final class TemplateConfiguration implements ParsingAndProcessingConfigur } @Override - public int getTagSyntax() { + public TagSyntax getTagSyntax() { if (!isTagSyntaxSet()) { throw new SettingValueNotSetException("tagSyntax"); } @@ -211,7 +211,7 @@ public final class TemplateConfiguration implements ParsingAndProcessingConfigur } @Override - public int getNamingConvention() { + public NamingConvention getNamingConvention() { if (!isNamingConventionSet()) { throw new SettingValueNotSetException("namingConvention"); } @@ -237,7 +237,7 @@ public final class TemplateConfiguration implements ParsingAndProcessingConfigur } @Override - public int getAutoEscapingPolicy() { + public AutoEscapingPolicy getAutoEscapingPolicy() { if (!isAutoEscapingPolicySet()) { throw new SettingValueNotSetException("autoEscapingPolicy"); } @@ -942,7 +942,7 @@ public final class TemplateConfiguration implements ParsingAndProcessingConfigur } @Override - protected int getDefaultTagSyntax() { + protected TagSyntax getDefaultTagSyntax() { throw new SettingValueNotSetException("tagSyntax"); } @@ -952,7 +952,7 @@ public final class TemplateConfiguration implements ParsingAndProcessingConfigur } @Override - protected int getDefaultNamingConvention() { + protected NamingConvention getDefaultNamingConvention() { throw new SettingValueNotSetException("namingConvention"); } @@ -962,7 +962,7 @@ public final class TemplateConfiguration implements ParsingAndProcessingConfigur } @Override - protected int getDefaultAutoEscapingPolicy() { + protected AutoEscapingPolicy getDefaultAutoEscapingPolicy() { throw new SettingValueNotSetException("autoEscapingPolicy"); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/99ac6973/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateParsingConfigurationWithFallback.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateParsingConfigurationWithFallback.java b/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateParsingConfigurationWithFallback.java index 93a5840..30414a7 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateParsingConfigurationWithFallback.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateParsingConfigurationWithFallback.java @@ -48,7 +48,7 @@ final class TemplateParsingConfigurationWithFallback implements ParsingConfigura } @Override - public int getTagSyntax() { + public TagSyntax getTagSyntax() { return tCfg.isTagSyntaxSet() ? tCfg.getTagSyntax() : cfg.getTagSyntax(); } @@ -58,7 +58,7 @@ final class TemplateParsingConfigurationWithFallback implements ParsingConfigura } @Override - public int getNamingConvention() { + public NamingConvention getNamingConvention() { return tCfg.isNamingConventionSet() ? tCfg.getNamingConvention() : cfg.getNamingConvention(); } @@ -88,7 +88,7 @@ final class TemplateParsingConfigurationWithFallback implements ParsingConfigura } @Override - public int getAutoEscapingPolicy() { + public AutoEscapingPolicy getAutoEscapingPolicy() { return tCfg.isAutoEscapingPolicySet() ? tCfg.getAutoEscapingPolicy() : cfg.getAutoEscapingPolicy(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/99ac6973/freemarker-core/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java b/freemarker-core/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java index 2d09062..5dfa623 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java @@ -225,7 +225,7 @@ public class _ErrorDescriptionBuilder { || (partStr.charAt(1) == '/') && (partStr.charAt(2) == '#' || partStr.charAt(2) == '@') ) && partStr.charAt(partStr.length() - 1) == '>') { - if (template.getActualTagSyntax() == ParsingConfiguration.SQUARE_BRACKET_TAG_SYNTAX) { + if (template.getActualTagSyntax() == TagSyntax.SQUARE_BRACKET) { sb.append('['); sb.append(partStr.substring(1, partStr.length() - 1)); sb.append(']'); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/99ac6973/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java b/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java index cc96d81..6a51764 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java @@ -697,7 +697,10 @@ public class _ObjectBuilderSettingEvaluator { } // For accessing static fields: - addWithSimpleName(SHORTHANDS, Configuration.class); + addWithSimpleName(SHORTHANDS, Configuration.class); // [FM3] Won't be needed + addWithSimpleName(SHORTHANDS, TagSyntax.class); + addWithSimpleName(SHORTHANDS, NamingConvention.class); + } String fullClassName = SHORTHANDS.get(className); return fullClassName == null ? className : fullClassName; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/99ac6973/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtil.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtil.java b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtil.java index b53aae8..4035a1f 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtil.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtil.java @@ -30,7 +30,7 @@ import java.util.StringTokenizer; import java.util.regex.Pattern; import org.apache.freemarker.core.Environment; -import org.apache.freemarker.core.ParsingConfiguration; +import org.apache.freemarker.core.NamingConvention; import org.apache.freemarker.core.Template; import org.apache.freemarker.core.Version; @@ -1604,21 +1604,21 @@ public class _StringUtil { } /** - * @return {@link ParsingConfiguration#CAMEL_CASE_NAMING_CONVENTION}, or {@link ParsingConfiguration#LEGACY_NAMING_CONVENTION} - * or, {@link ParsingConfiguration#AUTO_DETECT_NAMING_CONVENTION} when undecidable. + * @return {@link NamingConvention#CAMEL_CASE}, or {@link NamingConvention#LEGACY} + * or, {@link NamingConvention#AUTO_DETECT} when undecidable. */ - public static int getIdentifierNamingConvention(String name) { + public static NamingConvention getIdentifierNamingConvention(String name) { final int ln = name.length(); for (int i = 0; i < ln; i++) { final char c = name.charAt(i); if (c == '_') { - return ParsingConfiguration.LEGACY_NAMING_CONVENTION; + return NamingConvention.LEGACY; } if (_StringUtil.isUpperUSASCII(c)) { - return ParsingConfiguration.CAMEL_CASE_NAMING_CONVENTION; + return NamingConvention.CAMEL_CASE; } } - return ParsingConfiguration.AUTO_DETECT_NAMING_CONVENTION; + return NamingConvention.AUTO_DETECT; } // [2.4] Won't be needed anymore http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/99ac6973/freemarker-core/src/main/javacc/FTL.jj ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/javacc/FTL.jj b/freemarker-core/src/main/javacc/FTL.jj index dc6079f..0df4035 100644 --- a/freemarker-core/src/main/javacc/FTL.jj +++ b/freemarker-core/src/main/javacc/FTL.jj @@ -78,7 +78,7 @@ public class FMParser { private boolean stripWhitespace, stripText; private int incompatibleImprovements; private OutputFormat outputFormat; - private int autoEscapingPolicy; + private AutoEscapingPolicy autoEscapingPolicy; private boolean autoEscaping; private ParsingConfiguration pCfg; private InputStream streamToUnmarkWhenEncEstabd; @@ -96,7 +96,7 @@ public class FMParser { private int mixedContentNesting; // for stripText FMParser(Template template, Reader reader, - ParsingConfiguration pCfg, OutputFormat outputFormat, Integer autoEscapingPolicy, + ParsingConfiguration pCfg, OutputFormat outputFormat, AutoEscapingPolicy autoEscapingPolicy, InputStream streamToUnmarkWhenEncEstabd) { this(template, true, readerToTokenManager(reader, pCfg), pCfg, outputFormat, autoEscapingPolicy, @@ -110,7 +110,7 @@ public class FMParser { } FMParser(Template template, boolean newTemplate, FMParserTokenManager tkMan, - ParsingConfiguration pCfg, OutputFormat contextOutputFormat, Integer contextAutoEscapingPolicy, + ParsingConfiguration pCfg, OutputFormat contextOutputFormat, AutoEscapingPolicy contextAutoEscapingPolicy, InputStream streamToUnmarkWhenEncEstabd) { this(tkMan); @@ -133,39 +133,30 @@ public class FMParser { : outputFormatFromExt != null ? outputFormatFromExt : pCfg.getOutputFormat(); autoEscapingPolicy = contextAutoEscapingPolicy != null ? contextAutoEscapingPolicy - : outputFormatFromExt != null ? Configuration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY + : outputFormatFromExt != null ? AutoEscapingPolicy.ENABLE_IF_DEFAULT : pCfg.getAutoEscapingPolicy(); } recalculateAutoEscapingField(); token_source.setParser(this); - int tagSyntax = pCfg.getTagSyntax(); + TagSyntax tagSyntax = pCfg.getTagSyntax(); switch (tagSyntax) { - case Configuration.AUTO_DETECT_TAG_SYNTAX: + case AUTO_DETECT: token_source.autodetectTagSyntax = true; break; - case Configuration.ANGLE_BRACKET_TAG_SYNTAX: + case ANGLE_BRACKET: token_source.squBracTagSyntax = false; break; - case Configuration.SQUARE_BRACKET_TAG_SYNTAX: + case SQUARE_BRACKET: token_source.squBracTagSyntax = true; break; default: - throw new IllegalArgumentException("Illegal argument for tagSyntax: " + tagSyntax); + throw new BugException("Unsupported tagSyntax: " + tagSyntax); } - int namingConvention = pCfg.getNamingConvention(); - switch (namingConvention) { - case Configuration.AUTO_DETECT_NAMING_CONVENTION: - case Configuration.CAMEL_CASE_NAMING_CONVENTION: - case Configuration.LEGACY_NAMING_CONVENTION: - token_source.initialNamingConvention = namingConvention; - token_source.namingConvention = namingConvention; - break; - default: - throw new IllegalArgumentException("Illegal argument for namingConvention: " + namingConvention); - } + token_source.initialNamingConvention = pCfg.getNamingConvention(); + token_source.namingConvention = token_source.initialNamingConvention; this.stripWhitespace = pCfg.getWhitespaceStripping(); @@ -233,14 +224,14 @@ public class FMParser { */ private void recalculateAutoEscapingField() { if (outputFormat instanceof MarkupOutputFormat) { - if (autoEscapingPolicy == Configuration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY) { + if (autoEscapingPolicy == AutoEscapingPolicy.ENABLE_IF_DEFAULT) { autoEscaping = ((MarkupOutputFormat) outputFormat).isAutoEscapedByDefault(); - } else if (autoEscapingPolicy == Configuration.ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY) { + } else if (autoEscapingPolicy == AutoEscapingPolicy.ENABLE_IF_SUPPORTED) { autoEscaping = true; - } else if (autoEscapingPolicy == Configuration.DISABLE_AUTO_ESCAPING_POLICY) { + } else if (autoEscapingPolicy == AutoEscapingPolicy.DISABLE) { autoEscaping = false; } else { - throw new IllegalStateException("Unhandled autoEscaping enum: " + autoEscapingPolicy); + throw new BugException("Unhandled autoEscaping enum: " + autoEscapingPolicy); } } else { autoEscaping = false; @@ -254,10 +245,8 @@ public class FMParser { /** * Don't use it, unless you are developing FreeMarker itself. */ - public int _getLastTagSyntax() { - return token_source.squBracTagSyntax - ? Configuration.SQUARE_BRACKET_TAG_SYNTAX - : Configuration.ANGLE_BRACKET_TAG_SYNTAX; + public TagSyntax _getLastTagSyntax() { + return token_source.squBracTagSyntax ? TagSyntax.SQUARE_BRACKET : TagSyntax.ANGLE_BRACKET; } /** @@ -265,7 +254,7 @@ public class FMParser { * The naming convention used by this template; if it couldn't be detected so far, it will be the most probable one. * This could be used for formatting error messages, but not for anything serious. */ - public int _getLastNamingConvention() { + public NamingConvention _getLastNamingConvention() { return token_source.namingConvention; } @@ -501,8 +490,8 @@ TOKEN_MGR_DECLS: autodetectTagSyntax, directiveSyntaxEstablished, inInvocation; - int initialNamingConvention; - int namingConvention; + NamingConvention initialNamingConvention; + NamingConvention namingConvention; Token namingConventionEstabilisher; int incompatibleImprovements; @@ -514,7 +503,7 @@ TOKEN_MGR_DECLS: * This method handles tag syntax ('<' VS '['), and also participates in naming convention detection. * If you update this logic, take a look at the UNKNOWN_DIRECTIVE token too. */ - private void handleTagSyntaxAndSwitch(Token tok, int tokenNamingConvention, int newLexState) { + private void handleTagSyntaxAndSwitch(Token tok, NamingConvention tokenNamingConvention, int newLexState) { final String image = tok.image; char firstChar = image.charAt(0); @@ -537,16 +526,16 @@ TOKEN_MGR_DECLS: * Used for tags whose name isn't affected by naming convention. */ private void handleTagSyntaxAndSwitch(Token tok, int newLexState) { - handleTagSyntaxAndSwitch(tok, Configuration.AUTO_DETECT_NAMING_CONVENTION, newLexState); + handleTagSyntaxAndSwitch(tok, NamingConvention.AUTO_DETECT, newLexState); } void checkNamingConvention(Token tok) { checkNamingConvention(tok, _StringUtil.getIdentifierNamingConvention(tok.image)); } - void checkNamingConvention(Token tok, int tokenNamingConvention) { - if (tokenNamingConvention != Configuration.AUTO_DETECT_NAMING_CONVENTION) { - if (namingConvention == Configuration.AUTO_DETECT_NAMING_CONVENTION) { + void checkNamingConvention(Token tok, NamingConvention tokenNamingConvention) { + if (tokenNamingConvention != NamingConvention.AUTO_DETECT) { + if (namingConvention == NamingConvention.AUTO_DETECT) { namingConvention = tokenNamingConvention; namingConventionEstabilisher = tok; } else if (namingConvention != tokenNamingConvention) { @@ -559,12 +548,12 @@ TOKEN_MGR_DECLS: return new TokenMgrError( "Naming convention mismatch. " + "Identifiers that are part of the template language (not the user specified ones) " - + (initialNamingConvention == Configuration.AUTO_DETECT_NAMING_CONVENTION + + (initialNamingConvention == NamingConvention.AUTO_DETECT ? "must consistently use the same naming convention within the same template. This template uses " : "must use the configured naming convention, which is the ") - + (namingConvention == Configuration.CAMEL_CASE_NAMING_CONVENTION + + (namingConvention == NamingConvention.CAMEL_CASE ? "camel case naming convention (like: exampleName) " - : (namingConvention == Configuration.LEGACY_NAMING_CONVENTION + : (namingConvention == NamingConvention.LEGACY ? "legacy naming convention (directive (tag) names are like examplename, " + "everything else is like example_name) " : "??? (internal error)" @@ -587,9 +576,9 @@ TOKEN_MGR_DECLS: * @param charIdxInName * The index of the deciding character relatively to the first letter of the name. */ - private static int getTagNamingConvention(Token tok, int charIdxInName) { + private static NamingConvention getTagNamingConvention(Token tok, int charIdxInName) { return _StringUtil.isUpperUSASCII(getTagNameCharAt(tok, charIdxInName)) - ? Configuration.CAMEL_CASE_NAMING_CONVENTION : Configuration.LEGACY_NAMING_CONVENTION; + ? NamingConvention.CAMEL_CASE : NamingConvention.LEGACY; } static char getTagNameCharAt(Token tok, int charIdxInName) { @@ -803,9 +792,9 @@ TOKEN: <TERSE_COMMENT : ("<" | "[") "#--" > { noparseTag = "-->"; handleTagSyntaxAndSwitch(matchedToken, NO_PARSE); } | <NOPARSE: <START_TAG> "no" ("p" | "P") "arse" <CLOSE_TAG1>> { - int tagNamingConvention = getTagNamingConvention(matchedToken, 2); + NamingConvention tagNamingConvention = getTagNamingConvention(matchedToken, 2); handleTagSyntaxAndSwitch(matchedToken, tagNamingConvention, NO_PARSE); - noparseTag = tagNamingConvention == Configuration.CAMEL_CASE_NAMING_CONVENTION ? "noParse" : "noparse"; + noparseTag = tagNamingConvention == NamingConvention.CAMEL_CASE ? "noParse" : "noparse"; } | <END_IF : <END_TAG> "if" <CLOSE_TAG1>> { handleTagSyntaxAndSwitch(matchedToken, DEFAULT); } @@ -3503,14 +3492,14 @@ ASTDirAutoEsc AutoEsc() : { Token start, end; TemplateElements children; - int lastAutoEscapingPolicy; + AutoEscapingPolicy lastAutoEscapingPolicy; } { start = <AUTOESC> { checkCurrentOutputFormatCanEscape(start); lastAutoEscapingPolicy = autoEscapingPolicy; - autoEscapingPolicy = Configuration.ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY; + autoEscapingPolicy = AutoEscapingPolicy.ENABLE_IF_SUPPORTED; recalculateAutoEscapingField(); } children = MixedContentElements() @@ -3529,13 +3518,13 @@ ASTDirNoAutoEsc NoAutoEsc() : { Token start, end; TemplateElements children; - int lastAutoEscapingPolicy; + AutoEscapingPolicy lastAutoEscapingPolicy; } { start = <NOAUTOESC> { lastAutoEscapingPolicy = autoEscapingPolicy; - autoEscapingPolicy = Configuration.DISABLE_AUTO_ESCAPING_POLICY; + autoEscapingPolicy = AutoEscapingPolicy.DISABLE; recalculateAutoEscapingField(); } children = MixedContentElements() @@ -3923,9 +3912,9 @@ void HeaderElement() : } else if (ks.equalsIgnoreCase("auto_esc") || ks.equals("autoEsc")) { if (getBoolean(exp, false)) { autoEscRequester = key; - autoEscapingPolicy = Configuration.ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY; + autoEscapingPolicy = AutoEscapingPolicy.ENABLE_IF_SUPPORTED; } else { - autoEscapingPolicy = Configuration.DISABLE_AUTO_ESCAPING_POLICY; + autoEscapingPolicy = AutoEscapingPolicy.DISABLE; } recalculateAutoEscapingField(); @@ -3993,7 +3982,7 @@ void HeaderElement() : } else if (ks.equals("xmlns")) { // [2.4] If camel case will be the default, update this correctName - = token_source.namingConvention == Configuration.CAMEL_CASE_NAMING_CONVENTION + = token_source.namingConvention == NamingConvention.CAMEL_CASE ? "nsPrefixes" : "ns_prefixes"; } else if (ks.equals("auto_escape") || ks.equals("auto_escaping") || ks.equals("autoesc")) { correctName = "auto_esc";
