Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 894F3200C2C for ; Fri, 17 Feb 2017 00:08:52 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 87B17160B61; Thu, 16 Feb 2017 23:08:52 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 60FFC160B72 for ; Fri, 17 Feb 2017 00:08:50 +0100 (CET) Received: (qmail 56469 invoked by uid 500); 16 Feb 2017 23:08:49 -0000 Mailing-List: contact notifications-help@freemarker.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@freemarker.incubator.apache.org Delivered-To: mailing list notifications@freemarker.incubator.apache.org Received: (qmail 56460 invoked by uid 99); 16 Feb 2017 23:08:49 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Feb 2017 23:08:49 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 0C36EC0444 for ; Thu, 16 Feb 2017 23:08:49 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.218 X-Spam-Level: X-Spam-Status: No, score=-6.218 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id B6q_YXCorMlm for ; Thu, 16 Feb 2017 23:08:44 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id E556860D38 for ; Thu, 16 Feb 2017 23:08:27 +0000 (UTC) Received: (qmail 55556 invoked by uid 99); 16 Feb 2017 23:08:26 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Feb 2017 23:08:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DB52FE006B; Thu, 16 Feb 2017 23:08:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ddekany@apache.org To: notifications@freemarker.incubator.apache.org Date: Thu, 16 Feb 2017 23:09:08 -0000 Message-Id: <79caa5e4680344baad553a4edd899e1c@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [43/54] [partial] incubator-freemarker git commit: Top level package name change to org.apache.freemarker, and some of of the internal package structure changes. Other smaller cleanup. To be continued... archived-at: Thu, 16 Feb 2017 23:08:52 -0000 http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/BuiltInsForStringsRegexp.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/BuiltInsForStringsRegexp.java b/src/main/java/freemarker/core/BuiltInsForStringsRegexp.java deleted file mode 100644 index 9cb2010..0000000 --- a/src/main/java/freemarker/core/BuiltInsForStringsRegexp.java +++ /dev/null @@ -1,305 +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 freemarker.core; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import freemarker.template.SimpleScalar; -import freemarker.template.SimpleSequence; -import freemarker.template.TemplateBooleanModel; -import freemarker.template.TemplateCollectionModel; -import freemarker.template.TemplateException; -import freemarker.template.TemplateMethodModel; -import freemarker.template.TemplateModel; -import freemarker.template.TemplateModelException; -import freemarker.template.TemplateModelIterator; -import freemarker.template.TemplateScalarModel; -import freemarker.template.TemplateSequenceModel; -import freemarker.template.utility.StringUtil; - - -/** - * Contains the string built-ins that correspond to basic regular expressions operations. - */ -class BuiltInsForStringsRegexp { - - static class groupsBI extends BuiltIn { - @Override - TemplateModel _eval(Environment env) throws TemplateException { - TemplateModel targetModel = target.eval(env); - assertNonNull(targetModel, env); - if (targetModel instanceof RegexMatchModel) { - return ((RegexMatchModel) targetModel).getGroups(); - } else if (targetModel instanceof RegexMatchModel.MatchWithGroups) { - return ((RegexMatchModel.MatchWithGroups) targetModel).groupsSeq; - } else { - throw new UnexpectedTypeException(target, targetModel, - "regular expression matcher", - new Class[] { RegexMatchModel.class, RegexMatchModel.MatchWithGroups.class }, - env); - } - } - } - - static class matchesBI extends BuiltInForString { - class MatcherBuilder implements TemplateMethodModel { - - String matchString; - - MatcherBuilder(String matchString) throws TemplateModelException { - this.matchString = matchString; - } - - public Object exec(List args) throws TemplateModelException { - int argCnt = args.size(); - checkMethodArgCount(argCnt, 1, 2); - - String patternString = (String) args.get(0); - long flags = argCnt > 1 ? RegexpHelper.parseFlagString((String) args.get(1)) : 0; - if ((flags & RegexpHelper.RE_FLAG_FIRST_ONLY) != 0) { - RegexpHelper.logFlagWarning("?" + key + " doesn't support the \"f\" flag."); - } - Pattern pattern = RegexpHelper.getPattern(patternString, (int) flags); - return new RegexMatchModel(pattern, matchString); - } - } - - @Override - TemplateModel calculateResult(String s, Environment env) throws TemplateModelException { - return new MatcherBuilder(s); - } - - } - - static class replace_reBI extends BuiltInForString { - - class ReplaceMethod implements TemplateMethodModel { - private String s; - - ReplaceMethod(String s) { - this.s = s; - } - - public Object exec(List args) throws TemplateModelException { - int argCnt = args.size(); - checkMethodArgCount(argCnt, 2, 3); - String arg1 = (String) args.get(0); - String arg2 = (String) args.get(1); - long flags = argCnt > 2 ? RegexpHelper.parseFlagString((String) args.get(2)) : 0; - String result; - if ((flags & RegexpHelper.RE_FLAG_REGEXP) == 0) { - RegexpHelper.checkNonRegexpFlags("replace", flags); - result = StringUtil.replace(s, arg1, arg2, - (flags & RegexpHelper.RE_FLAG_CASE_INSENSITIVE) != 0, - (flags & RegexpHelper.RE_FLAG_FIRST_ONLY) != 0); - } else { - Pattern pattern = RegexpHelper.getPattern(arg1, (int) flags); - Matcher matcher = pattern.matcher(s); - result = (flags & RegexpHelper.RE_FLAG_FIRST_ONLY) != 0 - ? matcher.replaceFirst(arg2) - : matcher.replaceAll(arg2); - } - return new SimpleScalar(result); - } - - } - - @Override - TemplateModel calculateResult(String s, Environment env) throws TemplateModelException { - return new ReplaceMethod(s); - } - - } - - // Represents the match - - static class RegexMatchModel - implements TemplateBooleanModel, TemplateCollectionModel, TemplateSequenceModel { - static class MatchWithGroups implements TemplateScalarModel { - final String matchedInputPart; - final SimpleSequence groupsSeq; - - MatchWithGroups(String input, Matcher matcher) { - matchedInputPart = input.substring(matcher.start(), matcher.end()); - final int grpCount = matcher.groupCount() + 1; - groupsSeq = new SimpleSequence(grpCount); - for (int i = 0; i < grpCount; i++) { - groupsSeq.add(matcher.group(i)); - } - } - - public String getAsString() { - return matchedInputPart; - } - } - final Pattern pattern; - - final String input; - private Matcher firedEntireInputMatcher; - private Boolean entireInputMatched; - - private TemplateSequenceModel entireInputMatchGroups; - - private ArrayList matchingInputParts; - - RegexMatchModel(Pattern pattern, String input) { - this.pattern = pattern; - this.input = input; - } - - public TemplateModel get(int i) throws TemplateModelException { - ArrayList matchingInputParts = this.matchingInputParts; - if (matchingInputParts == null) { - matchingInputParts = getMatchingInputPartsAndStoreResults(); - } - return (TemplateModel) matchingInputParts.get(i); - } - - public boolean getAsBoolean() { - Boolean result = entireInputMatched; - return result != null ? result.booleanValue() : isEntrieInputMatchesAndStoreResults(); - } - - TemplateModel getGroups() { - TemplateSequenceModel entireInputMatchGroups = this.entireInputMatchGroups; - if (entireInputMatchGroups == null) { - Matcher t = this.firedEntireInputMatcher; - if (t == null) { - isEntrieInputMatchesAndStoreResults(); - t = this.firedEntireInputMatcher; - } - final Matcher firedEntireInputMatcher = t; - - entireInputMatchGroups = new TemplateSequenceModel() { - - public TemplateModel get(int i) throws TemplateModelException { - try { - return new SimpleScalar(firedEntireInputMatcher.group(i)); - } catch (Exception e) { - throw new _TemplateModelException(e, "Failed to read match group"); - } - } - - public int size() throws TemplateModelException { - try { - return firedEntireInputMatcher.groupCount() + 1; - } catch (Exception e) { - throw new _TemplateModelException(e, "Failed to get match group count"); - } - } - - }; - this.entireInputMatchGroups = entireInputMatchGroups; - } - return entireInputMatchGroups; - } - - private ArrayList getMatchingInputPartsAndStoreResults() throws TemplateModelException { - ArrayList matchingInputParts = new ArrayList(); - - Matcher matcher = pattern.matcher(input); - while (matcher.find()) { - matchingInputParts.add(new MatchWithGroups(input, matcher)); - } - - this.matchingInputParts = matchingInputParts; - return matchingInputParts; - } - - private boolean isEntrieInputMatchesAndStoreResults() { - Matcher matcher = pattern.matcher(input); - boolean matches = matcher.matches(); - firedEntireInputMatcher = matcher; - entireInputMatched = Boolean.valueOf(matches); - return matches; - } - - public TemplateModelIterator iterator() { - final ArrayList matchingInputParts = this.matchingInputParts; - if (matchingInputParts == null) { - final Matcher matcher = pattern.matcher(input); - return new TemplateModelIterator() { - - private int nextIdx = 0; - boolean hasFindInfo = matcher.find(); - - public boolean hasNext() { - final ArrayList matchingInputParts = RegexMatchModel.this.matchingInputParts; - if (matchingInputParts == null) { - return hasFindInfo; - } else { - return nextIdx < matchingInputParts.size(); - } - } - - public TemplateModel next() throws TemplateModelException { - final ArrayList matchingInputParts = RegexMatchModel.this.matchingInputParts; - if (matchingInputParts == null) { - if (!hasFindInfo) throw new _TemplateModelException("There were no more matches"); - MatchWithGroups result = new MatchWithGroups(input, matcher); - nextIdx++; - hasFindInfo = matcher.find(); - return result; - } else { - try { - return (TemplateModel) matchingInputParts.get(nextIdx++); - } catch (IndexOutOfBoundsException e) { - throw new _TemplateModelException(e, "There were no more matches"); - } - } - } - - }; - } else { - return new TemplateModelIterator() { - - private int nextIdx = 0; - - public boolean hasNext() { - return nextIdx < matchingInputParts.size(); - } - - public TemplateModel next() throws TemplateModelException { - try { - return (TemplateModel) matchingInputParts.get(nextIdx++); - } catch (IndexOutOfBoundsException e) { - throw new _TemplateModelException(e, "There were no more matches"); - } - } - }; - } - } - - public int size() throws TemplateModelException { - ArrayList matchingInputParts = this.matchingInputParts; - if (matchingInputParts == null) { - matchingInputParts = getMatchingInputPartsAndStoreResults(); - } - return matchingInputParts.size(); - } - } - - // Can't be instantiated - private BuiltInsForStringsRegexp() { } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/BuiltInsWithParseTimeParameters.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/BuiltInsWithParseTimeParameters.java b/src/main/java/freemarker/core/BuiltInsWithParseTimeParameters.java deleted file mode 100644 index 5901c28..0000000 --- a/src/main/java/freemarker/core/BuiltInsWithParseTimeParameters.java +++ /dev/null @@ -1,158 +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 freemarker.core; - -import java.util.ArrayList; -import java.util.List; - -import freemarker.template.TemplateException; -import freemarker.template.TemplateModel; - - -final class BuiltInsWithParseTimeParameters { - - /** - * Behaves similarly to the ternary operator of Java. - */ - static class then_BI extends BuiltInWithParseTimeParameters { - - private Expression whenTrueExp; - private Expression whenFalseExp; - - @Override - TemplateModel _eval(Environment env) throws TemplateException { - boolean lho = target.evalToBoolean(env); - return (lho ? whenTrueExp : whenFalseExp).evalToNonMissing(env); - } - - @Override - void bindToParameters(List parameters, Token openParen, Token closeParen) throws ParseException { - if (parameters.size() != 2) { - throw newArgumentCountException("requires exactly 2", openParen, closeParen); - } - whenTrueExp = (Expression) parameters.get(0); - whenFalseExp = (Expression) parameters.get(1); - } - - @Override - protected Expression getArgumentParameterValue(final int argIdx) { - switch (argIdx) { - case 0: return whenTrueExp; - case 1: return whenFalseExp; - default: throw new IndexOutOfBoundsException(); - } - } - - @Override - protected int getArgumentsCount() { - return 2; - } - - @Override - protected List getArgumentsAsList() { - ArrayList args = new ArrayList(2); - args.add(whenTrueExp); - args.add(whenFalseExp); - return args; - } - - @Override - protected void cloneArguments(Expression cloneExp, String replacedIdentifier, - Expression replacement, ReplacemenetState replacementState) { - then_BI clone = (then_BI) cloneExp; - clone.whenTrueExp = whenTrueExp.deepCloneWithIdentifierReplaced(replacedIdentifier, replacement, replacementState); - clone.whenFalseExp = whenFalseExp.deepCloneWithIdentifierReplaced(replacedIdentifier, replacement, replacementState); - } - - } - - private BuiltInsWithParseTimeParameters() { - // Not to be instantiated - } - - static class switch_BI extends BuiltInWithParseTimeParameters { - - private List/**/ parameters; - - @Override - void bindToParameters(List parameters, Token openParen, Token closeParen) throws ParseException { - if (parameters.size() < 2) { - throw newArgumentCountException("must have at least 2", openParen, closeParen); - } - this.parameters = parameters; - } - - @Override - protected List getArgumentsAsList() { - return parameters; - } - - @Override - protected int getArgumentsCount() { - return parameters.size(); - } - - @Override - protected Expression getArgumentParameterValue(int argIdx) { - return (Expression) parameters.get(argIdx); - } - - @Override - protected void cloneArguments(Expression clone, String replacedIdentifier, Expression replacement, - ReplacemenetState replacementState) { - ArrayList parametersClone = new ArrayList(parameters.size()); - for (int i = 0; i < parameters.size(); i++) { - parametersClone.add(((Expression) parameters.get(i)) - .deepCloneWithIdentifierReplaced(replacedIdentifier, replacement, replacementState)); - } - ((switch_BI) clone).parameters = parametersClone; - } - - @Override - TemplateModel _eval(Environment env) throws TemplateException { - TemplateModel targetValue = target.evalToNonMissing(env); - - List parameters = this.parameters; - int paramCnt = parameters.size(); - for (int i = 0; i + 1 < paramCnt; i += 2) { - Expression caseExp = (Expression) parameters.get(i); - TemplateModel caseValue = caseExp.evalToNonMissing(env); - if (EvalUtil.compare( - targetValue, target, - EvalUtil.CMP_OP_EQUALS, "==", - caseValue, caseExp, - this, true, - false, false, false, - env)) { - return ((Expression) parameters.get(i + 1)).evalToNonMissing(env); - } - } - - if (paramCnt % 2 == 0) { - throw new _MiscTemplateException(target, - "The value before ?", key, "(case1, value1, case2, value2, ...) didn't match any of the " - + "case parameters, and there was no default value parameter (an additional last parameter) " - + "eithter. "); - } - return ((Expression) parameters.get(paramCnt - 1)).evalToNonMissing(env); - } - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/BuiltinVariable.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/BuiltinVariable.java b/src/main/java/freemarker/core/BuiltinVariable.java deleted file mode 100644 index 5b0f4d2..0000000 --- a/src/main/java/freemarker/core/BuiltinVariable.java +++ /dev/null @@ -1,305 +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 freemarker.core; - -import java.util.Arrays; -import java.util.Date; - -import freemarker.template.Configuration; -import freemarker.template.SimpleDate; -import freemarker.template.SimpleScalar; -import freemarker.template.TemplateDateModel; -import freemarker.template.TemplateException; -import freemarker.template.TemplateHashModel; -import freemarker.template.TemplateModel; -import freemarker.template.TemplateModelException; -import freemarker.template._TemplateAPI; -import freemarker.template.utility.StringUtil; - -/** - * A reference to a built-in identifier, such as .root - */ -final class BuiltinVariable extends Expression { - - static final String TEMPLATE_NAME_CC = "templateName"; - static final String TEMPLATE_NAME = "template_name"; - static final String MAIN_TEMPLATE_NAME_CC = "mainTemplateName"; - static final String MAIN_TEMPLATE_NAME = "main_template_name"; - static final String CURRENT_TEMPLATE_NAME_CC = "currentTemplateName"; - static final String CURRENT_TEMPLATE_NAME = "current_template_name"; - static final String NAMESPACE = "namespace"; - static final String MAIN = "main"; - static final String GLOBALS = "globals"; - static final String LOCALS = "locals"; - static final String DATA_MODEL_CC = "dataModel"; - static final String DATA_MODEL = "data_model"; - static final String LANG = "lang"; - static final String LOCALE = "locale"; - static final String LOCALE_OBJECT_CC = "localeObject"; - static final String LOCALE_OBJECT = "locale_object"; - static final String CURRENT_NODE_CC = "currentNode"; - static final String CURRENT_NODE = "current_node"; - static final String NODE = "node"; - static final String PASS = "pass"; - static final String VARS = "vars"; - static final String VERSION = "version"; - static final String INCOMPATIBLE_IMPROVEMENTS_CC = "incompatibleImprovements"; - static final String INCOMPATIBLE_IMPROVEMENTS = "incompatible_improvements"; - static final String ERROR = "error"; - static final String OUTPUT_ENCODING_CC = "outputEncoding"; - static final String OUTPUT_ENCODING = "output_encoding"; - static final String OUTPUT_FORMAT_CC = "outputFormat"; - static final String OUTPUT_FORMAT = "output_format"; - static final String AUTO_ESC_CC = "autoEsc"; - static final String AUTO_ESC = "auto_esc"; - static final String URL_ESCAPING_CHARSET_CC = "urlEscapingCharset"; - static final String URL_ESCAPING_CHARSET = "url_escaping_charset"; - static final String NOW = "now"; - - static final String[] SPEC_VAR_NAMES = new String[] { - AUTO_ESC_CC, - AUTO_ESC, - CURRENT_NODE_CC, - CURRENT_TEMPLATE_NAME_CC, - CURRENT_NODE, - CURRENT_TEMPLATE_NAME, - DATA_MODEL_CC, - DATA_MODEL, - ERROR, - GLOBALS, - INCOMPATIBLE_IMPROVEMENTS_CC, - INCOMPATIBLE_IMPROVEMENTS, - LANG, - LOCALE, - LOCALE_OBJECT_CC, - LOCALE_OBJECT, - LOCALS, - MAIN, - MAIN_TEMPLATE_NAME_CC, - MAIN_TEMPLATE_NAME, - NAMESPACE, - NODE, - NOW, - OUTPUT_ENCODING_CC, - OUTPUT_FORMAT_CC, - OUTPUT_ENCODING, - OUTPUT_FORMAT, - PASS, - TEMPLATE_NAME_CC, - TEMPLATE_NAME, - URL_ESCAPING_CHARSET_CC, - URL_ESCAPING_CHARSET, - VARS, - VERSION - }; - - private final String name; - private final TemplateModel parseTimeValue; - - BuiltinVariable(Token nameTk, FMParserTokenManager tokenManager, TemplateModel parseTimeValue) - throws ParseException { - String name = nameTk.image; - this.parseTimeValue = parseTimeValue; - if (Arrays.binarySearch(SPEC_VAR_NAMES, name) < 0) { - StringBuilder sb = new StringBuilder(); - sb.append("Unknown special variable name: "); - sb.append(StringUtil.jQuote(name)).append("."); - - int shownNamingConvention; - { - int namingConvention = tokenManager.namingConvention; - shownNamingConvention = namingConvention != Configuration.AUTO_DETECT_NAMING_CONVENTION - ? namingConvention : Configuration.LEGACY_NAMING_CONVENTION /* [2.4] CAMEL_CASE */; - } - - { - String correctName; - if (name.equals("auto_escape") || name.equals("auto_escaping") || name.equals("autoesc")) { - correctName = "auto_esc"; - } else if (name.equals("autoEscape") || name.equals("autoEscaping")) { - correctName = "autoEsc"; - } else { - correctName = null; - } - if (correctName != null) { - sb.append(" You may meant: "); - sb.append(StringUtil.jQuote(correctName)).append("."); - } - } - - sb.append("\nThe allowed special variable names are: "); - boolean first = true; - for (int i = 0; i < SPEC_VAR_NAMES.length; i++) { - final String correctName = SPEC_VAR_NAMES[i]; - int correctNameNamingConvetion = _CoreStringUtils.getIdentifierNamingConvention(correctName); - if (shownNamingConvention == Configuration.CAMEL_CASE_NAMING_CONVENTION - ? correctNameNamingConvetion != Configuration.LEGACY_NAMING_CONVENTION - : correctNameNamingConvetion != Configuration.CAMEL_CASE_NAMING_CONVENTION) { - if (first) { - first = false; - } else { - sb.append(", "); - } - sb.append(correctName); - } - } - throw new ParseException(sb.toString(), null, nameTk); - } - - this.name = name.intern(); - } - - @Override - TemplateModel _eval(Environment env) throws TemplateException { - if (parseTimeValue != null) { - return parseTimeValue; - } - if (name == NAMESPACE) { - return env.getCurrentNamespace(); - } - if (name == MAIN) { - return env.getMainNamespace(); - } - if (name == GLOBALS) { - return env.getGlobalVariables(); - } - if (name == LOCALS) { - Macro.Context ctx = env.getCurrentMacroContext(); - return ctx == null ? null : ctx.getLocals(); - } - if (name == DATA_MODEL || name == DATA_MODEL_CC) { - return env.getDataModel(); - } - if (name == VARS) { - return new VarsHash(env); - } - if (name == LOCALE) { - return new SimpleScalar(env.getLocale().toString()); - } - if (name == LOCALE_OBJECT || name == LOCALE_OBJECT_CC) { - return env.getObjectWrapper().wrap(env.getLocale()); - } - if (name == LANG) { - return new SimpleScalar(env.getLocale().getLanguage()); - } - if (name == CURRENT_NODE || name == NODE || name == CURRENT_NODE_CC) { - return env.getCurrentVisitorNode(); - } - if (name == TEMPLATE_NAME || name == TEMPLATE_NAME_CC) { - // The behavior of env.getTemplate() was changed with IcI 2.3.22, but there was an unintended side effect - // of changing the behavior of .template_name, which was fixed with IcI 2.3.23. IcI 2.3.22 deliberately - // remains broken. - return (env.getConfiguration().getIncompatibleImprovements().intValue() >= _TemplateAPI.VERSION_INT_2_3_23) - ? new SimpleScalar(env.getTemplate230().getName()) - : new SimpleScalar(env.getTemplate().getName()); - } - if (name == MAIN_TEMPLATE_NAME || name == MAIN_TEMPLATE_NAME_CC) { - return SimpleScalar.newInstanceOrNull(env.getMainTemplate().getName()); - } - if (name == CURRENT_TEMPLATE_NAME || name == CURRENT_TEMPLATE_NAME_CC) { - return SimpleScalar.newInstanceOrNull(env.getCurrentTemplate().getName()); - } - if (name == PASS) { - return Macro.DO_NOTHING_MACRO; - } - if (name == OUTPUT_ENCODING || name == OUTPUT_ENCODING_CC) { - String s = env.getOutputEncoding(); - return SimpleScalar.newInstanceOrNull(s); - } - if (name == URL_ESCAPING_CHARSET || name == URL_ESCAPING_CHARSET_CC) { - String s = env.getURLEscapingCharset(); - return SimpleScalar.newInstanceOrNull(s); - } - if (name == ERROR) { - return new SimpleScalar(env.getCurrentRecoveredErrorMessage()); - } - if (name == NOW) { - return new SimpleDate(new Date(), TemplateDateModel.DATETIME); - } - if (name == VERSION) { - return new SimpleScalar(Configuration.getVersionNumber()); - } - if (name == INCOMPATIBLE_IMPROVEMENTS || name == INCOMPATIBLE_IMPROVEMENTS_CC) { - return new SimpleScalar(env.getConfiguration().getIncompatibleImprovements().toString()); - } - - throw new _MiscTemplateException(this, - "Invalid special variable: ", name); - } - - @Override - public String toString() { - return "." + name; - } - - @Override - public String getCanonicalForm() { - return "." + name; - } - - @Override - String getNodeTypeSymbol() { - return getCanonicalForm(); - } - - @Override - boolean isLiteral() { - return false; - } - - @Override - protected Expression deepCloneWithIdentifierReplaced_inner( - String replacedIdentifier, Expression replacement, ReplacemenetState replacementState) { - return this; - } - - static class VarsHash implements TemplateHashModel { - - Environment env; - - VarsHash(Environment env) { - this.env = env; - } - - public TemplateModel get(String key) throws TemplateModelException { - return env.getVariable(key); - } - - public boolean isEmpty() { - return false; - } - } - - @Override - int getParameterCount() { - return 0; - } - - @Override - Object getParameterValue(int idx) { - throw new IndexOutOfBoundsException(); - } - - @Override - ParameterRole getParameterRole(int idx) { - throw new IndexOutOfBoundsException(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/CSSOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/CSSOutputFormat.java b/src/main/java/freemarker/core/CSSOutputFormat.java deleted file mode 100644 index 6b2cf3c..0000000 --- a/src/main/java/freemarker/core/CSSOutputFormat.java +++ /dev/null @@ -1,52 +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 freemarker.core; - -/** - * Represents the CSS output format (MIME type "text/css", name "CSS"). This format doesn't support escaping. - * - * @since 2.3.24 - */ -public class CSSOutputFormat extends OutputFormat { - - /** - * The only instance (singleton) of this {@link OutputFormat}. - */ - public static final CSSOutputFormat INSTANCE = new CSSOutputFormat(); - - private CSSOutputFormat() { - // Only to decrease visibility - } - - @Override - public String getName() { - return "CSS"; - } - - @Override - public String getMimeType() { - return "text/css"; - } - - @Override - public boolean isOutputFormatMixingAllowed() { - return false; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/CallPlaceCustomDataInitializationException.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/CallPlaceCustomDataInitializationException.java b/src/main/java/freemarker/core/CallPlaceCustomDataInitializationException.java deleted file mode 100644 index 7fce97c..0000000 --- a/src/main/java/freemarker/core/CallPlaceCustomDataInitializationException.java +++ /dev/null @@ -1,33 +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 freemarker.core; - -/** - * Thrown by {@link DirectiveCallPlace#getOrCreateCustomData(Object, freemarker.template.utility.ObjectFactory)} - * - * @since 2.3.22 - */ -public class CallPlaceCustomDataInitializationException extends Exception { - - public CallPlaceCustomDataInitializationException(String message, Throwable cause) { - super(message, cause); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/Case.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/Case.java b/src/main/java/freemarker/core/Case.java deleted file mode 100644 index 4f9c5c8..0000000 --- a/src/main/java/freemarker/core/Case.java +++ /dev/null @@ -1,91 +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 freemarker.core; - -/** - * Represents a case in a switch statement. - */ -final class Case extends TemplateElement { - - final int TYPE_CASE = 0; - final int TYPE_DEFAULT = 1; - - Expression condition; - - Case(Expression matchingValue, TemplateElements children) { - this.condition = matchingValue; - setChildren(children); - } - - @Override - TemplateElement[] accept(Environment env) { - return getChildBuffer(); - } - - @Override - protected String dump(boolean canonical) { - StringBuilder sb = new StringBuilder(); - if (canonical) sb.append('<'); - sb.append(getNodeTypeSymbol()); - if (condition != null) { - sb.append(' '); - sb.append(condition.getCanonicalForm()); - } - if (canonical) { - sb.append('>'); - sb.append(getChildrenCanonicalForm()); - } - return sb.toString(); - } - - @Override - String getNodeTypeSymbol() { - return condition != null ? "#case" : "#default"; - } - - @Override - int getParameterCount() { - return 2; - } - - @Override - Object getParameterValue(int idx) { - switch (idx) { - case 0: return condition; - case 1: return Integer.valueOf(condition != null ? TYPE_CASE : TYPE_DEFAULT); - default: throw new IndexOutOfBoundsException(); - } - } - - @Override - ParameterRole getParameterRole(int idx) { - switch (idx) { - case 0: return ParameterRole.CONDITION; - case 1: return ParameterRole.AST_NODE_SUBTYPE; - default: throw new IndexOutOfBoundsException(); - } - } - - @Override - boolean isNestedBlockRepeater() { - return false; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/CollectionAndSequence.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/CollectionAndSequence.java b/src/main/java/freemarker/core/CollectionAndSequence.java deleted file mode 100644 index 01524c2..0000000 --- a/src/main/java/freemarker/core/CollectionAndSequence.java +++ /dev/null @@ -1,104 +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 freemarker.core; - -import java.io.Serializable; -import java.util.ArrayList; - -import freemarker.template.TemplateCollectionModel; -import freemarker.template.TemplateModel; -import freemarker.template.TemplateModelException; -import freemarker.template.TemplateModelIterator; -import freemarker.template.TemplateSequenceModel; - -/** - * Add sequence capabilities to an existing collection, or - * vice versa. Used by ?keys and ?values built-ins. - */ -final public class CollectionAndSequence -implements TemplateCollectionModel, TemplateSequenceModel, Serializable { - private TemplateCollectionModel collection; - private TemplateSequenceModel sequence; - private ArrayList data; - - public CollectionAndSequence(TemplateCollectionModel collection) { - this.collection = collection; - } - - public CollectionAndSequence(TemplateSequenceModel sequence) { - this.sequence = sequence; - } - - public TemplateModelIterator iterator() throws TemplateModelException { - if (collection != null) { - return collection.iterator(); - } else { - return new SequenceIterator(sequence); - } - } - - public TemplateModel get(int i) throws TemplateModelException { - if (sequence != null) { - return sequence.get(i); - } else { - initSequence(); - return (TemplateModel) data.get(i); - } - } - - public int size() throws TemplateModelException { - if (sequence != null) { - return sequence.size(); - } else { - initSequence(); - return data.size(); - } - } - - private void initSequence() throws TemplateModelException { - if (data == null) { - data = new ArrayList(); - TemplateModelIterator it = collection.iterator(); - while (it.hasNext()) { - data.add(it.next()); - } - } - } - - private static class SequenceIterator - implements TemplateModelIterator { - private final TemplateSequenceModel sequence; - private final int size; - private int index = 0; - - SequenceIterator(TemplateSequenceModel sequence) throws TemplateModelException { - this.sequence = sequence; - this.size = sequence.size(); - - } - public TemplateModel next() throws TemplateModelException { - return sequence.get(index++); - } - - public boolean hasNext() { - return index < size; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/CombinedMarkupOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/CombinedMarkupOutputFormat.java b/src/main/java/freemarker/core/CombinedMarkupOutputFormat.java deleted file mode 100644 index 53827ef..0000000 --- a/src/main/java/freemarker/core/CombinedMarkupOutputFormat.java +++ /dev/null @@ -1,106 +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 freemarker.core; - -import java.io.IOException; -import java.io.Writer; - -import freemarker.template.TemplateModelException; - -/** - * Represents two markup formats nested into each other. For example, markdown nested into HTML. - * - * @since 2.3.24 - */ -public final class CombinedMarkupOutputFormat extends CommonMarkupOutputFormat { - - private final String name; - - private final MarkupOutputFormat outer; - private final MarkupOutputFormat inner; - - /** - * Same as {@link #CombinedMarkupOutputFormat(String, MarkupOutputFormat, MarkupOutputFormat)} with {@code null} as - * the {@code name} parameter. - */ - public CombinedMarkupOutputFormat(MarkupOutputFormat outer, MarkupOutputFormat inner) { - this(null, outer, inner); - } - - /** - * @param name - * Maybe {@code null}, in which case it defaults to - * outer.getName() + "{" + inner.getName() + "}". - */ - public CombinedMarkupOutputFormat(String name, MarkupOutputFormat outer, MarkupOutputFormat inner) { - this.name = name != null ? null : outer.getName() + "{" + inner.getName() + "}"; - this.outer = outer; - this.inner = inner; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getMimeType() { - return outer.getMimeType(); - } - - @Override - public void output(String textToEsc, Writer out) throws IOException, TemplateModelException { - outer.output(inner.escapePlainText(textToEsc), out); - } - - @Override - public String escapePlainText(String plainTextContent) throws TemplateModelException { - return outer.escapePlainText(inner.escapePlainText(plainTextContent)); - } - - @Override - public boolean isLegacyBuiltInBypassed(String builtInName) throws TemplateModelException { - return outer.isLegacyBuiltInBypassed(builtInName); - } - - @Override - public boolean isAutoEscapedByDefault() { - return outer.isAutoEscapedByDefault(); - } - - @Override - public boolean isOutputFormatMixingAllowed() { - return outer.isOutputFormatMixingAllowed(); - } - - public MarkupOutputFormat getOuterOutputFormat() { - return outer; - } - - public MarkupOutputFormat getInnerOutputFormat() { - return inner; - } - - @Override - protected TemplateCombinedMarkupOutputModel newTemplateMarkupOutputModel( - String plainTextContent, String markupContent) { - return new TemplateCombinedMarkupOutputModel(plainTextContent, markupContent, this); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/Comment.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/Comment.java b/src/main/java/freemarker/core/Comment.java deleted file mode 100644 index 89ac087..0000000 --- a/src/main/java/freemarker/core/Comment.java +++ /dev/null @@ -1,91 +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 freemarker.core; - -import freemarker.template.utility.StringUtil; - -/** - * Internal API - subject to change: A template element where the content is ignored, a Comment. - * - * @deprecated This is an internal FreeMarker API with no backward compatibility guarantees, so you shouldn't depend on - * it. - */ -@Deprecated -public final class Comment extends TemplateElement { - - private final String text; - - Comment(String text) { - this.text = text; - } - - @Override - TemplateElement[] accept(Environment env) { - // do nothing, skip the body - return null; - } - - @Override - protected String dump(boolean canonical) { - if (canonical) { - return "<#--" + text + "-->"; - } else { - return "comment " + StringUtil.jQuote(text.trim()); - } - } - - @Override - String getNodeTypeSymbol() { - return "#--...--"; - } - - - @Override - int getParameterCount() { - return 1; - } - - @Override - Object getParameterValue(int idx) { - if (idx != 0) throw new IndexOutOfBoundsException(); - return text; - } - - @Override - ParameterRole getParameterRole(int idx) { - if (idx != 0) throw new IndexOutOfBoundsException(); - return ParameterRole.CONTENT; - } - - public String getText() { - return text; - } - - @Override - boolean isOutputCacheable() { - return true; - } - - @Override - boolean isNestedBlockRepeater() { - return false; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/CommonMarkupOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/CommonMarkupOutputFormat.java b/src/main/java/freemarker/core/CommonMarkupOutputFormat.java deleted file mode 100644 index ed9a3c6..0000000 --- a/src/main/java/freemarker/core/CommonMarkupOutputFormat.java +++ /dev/null @@ -1,124 +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 freemarker.core; - -import java.io.IOException; -import java.io.Writer; - -import freemarker.template.TemplateModelException; - -/** - * Common superclass for implementing {@link MarkupOutputFormat}-s that use a {@link CommonTemplateMarkupOutputModel} - * subclass. - * - * @since 2.3.24 - */ -public abstract class CommonMarkupOutputFormat - extends MarkupOutputFormat { - - protected CommonMarkupOutputFormat() { - // Only to decrease visibility - } - - @Override - public final MO fromPlainTextByEscaping(String textToEsc) throws TemplateModelException { - return newTemplateMarkupOutputModel(textToEsc, null); - } - - @Override - public final MO fromMarkup(String markupText) throws TemplateModelException { - return newTemplateMarkupOutputModel(null, markupText); - } - - @Override - public final void output(MO mo, Writer out) throws IOException, TemplateModelException { - String mc = mo.getMarkupContent(); - if (mc != null) { - out.write(mc); - } else { - output(mo.getPlainTextContent(), out); - } - } - - @Override - public abstract void output(String textToEsc, Writer out) throws IOException, TemplateModelException; - - @Override - public final String getSourcePlainText(MO mo) throws TemplateModelException { - return mo.getPlainTextContent(); - } - - @Override - public final String getMarkupString(MO mo) throws TemplateModelException { - String mc = mo.getMarkupContent(); - if (mc != null) { - return mc; - } - - mc = escapePlainText(mo.getPlainTextContent()); - mo.setMarkupContet(mc); - return mc; - } - - @Override - public final MO concat(MO mo1, MO mo2) throws TemplateModelException { - String pc1 = mo1.getPlainTextContent(); - String mc1 = mo1.getMarkupContent(); - String pc2 = mo2.getPlainTextContent(); - String mc2 = mo2.getMarkupContent(); - - String pc3 = pc1 != null && pc2 != null ? pc1 + pc2 : null; - String mc3 = mc1 != null && mc2 != null ? mc1 + mc2 : null; - if (pc3 != null || mc3 != null) { - return newTemplateMarkupOutputModel(pc3, mc3); - } - - if (pc1 != null) { - return newTemplateMarkupOutputModel(null, getMarkupString(mo1) + mc2); - } else { - return newTemplateMarkupOutputModel(null, mc1 + getMarkupString(mo2)); - } - } - - @Override - public boolean isEmpty(MO mo) throws TemplateModelException { - String s = mo.getPlainTextContent(); - if (s != null) { - return s.length() == 0; - } - return mo.getMarkupContent().length() == 0; - } - - @Override - public boolean isOutputFormatMixingAllowed() { - return false; - } - - @Override - public boolean isAutoEscapedByDefault() { - return true; - } - - /** - * Creates a new {@link CommonTemplateMarkupOutputModel} that's bound to this {@link OutputFormat} instance. - */ - protected abstract MO newTemplateMarkupOutputModel(String plainTextContent, String markupContent) - throws TemplateModelException; - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/CommonTemplateMarkupOutputModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/CommonTemplateMarkupOutputModel.java b/src/main/java/freemarker/core/CommonTemplateMarkupOutputModel.java deleted file mode 100644 index 3f1a43e..0000000 --- a/src/main/java/freemarker/core/CommonTemplateMarkupOutputModel.java +++ /dev/null @@ -1,66 +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 freemarker.core; - -/** - * Common superclass for implementing {@link TemplateMarkupOutputModel}-s that belong to a - * {@link CommonMarkupOutputFormat} subclass format. - * - *

- * Thread-safe after proper publishing. Calculated fields (typically, the markup calculated from plain text) might will - * be re-calculated for multiple times if accessed from multiple threads (this only affects performance, not - * functionality). - * - * @since 2.3.24 - */ -public abstract class CommonTemplateMarkupOutputModel> - implements TemplateMarkupOutputModel { - - private final String plainTextContent; - private String markupContet; - - /** - * A least one of the parameters must be non-{@code null}! - */ - protected CommonTemplateMarkupOutputModel(String plainTextContent, String markupContent) { - this.plainTextContent = plainTextContent; - this.markupContet = markupContent; - } - - public abstract CommonMarkupOutputFormat getOutputFormat(); - - /** Maybe {@code null}, but then {@link #getMarkupContent()} isn't {@code null}. */ - final String getPlainTextContent() { - return plainTextContent; - } - - /** Maybe {@code null}, but then {@link #getPlainTextContent()} isn't {@code null}. */ - final String getMarkupContent() { - return markupContet; - } - - /** - * Use only to set the value calculated from {@link #getPlainTextContent()}, when {@link #getMarkupContent()} was - * still {@code null}! - */ - final void setMarkupContet(String markupContet) { - this.markupContet = markupContet; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/ComparisonExpression.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/ComparisonExpression.java b/src/main/java/freemarker/core/ComparisonExpression.java deleted file mode 100644 index d2536a1..0000000 --- a/src/main/java/freemarker/core/ComparisonExpression.java +++ /dev/null @@ -1,104 +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 freemarker.core; - -import freemarker.template.TemplateException; - -/** - * A class that handles comparisons. - */ -final class ComparisonExpression extends BooleanExpression { - - private final Expression left; - private final Expression right; - private final int operation; - private final String opString; - - ComparisonExpression(Expression left, Expression right, String opString) { - this.left = left; - this.right = right; - opString = opString.intern(); - this.opString = opString; - if (opString == "==" || opString == "=") { - operation = EvalUtil.CMP_OP_EQUALS; - } else if (opString == "!=") { - operation = EvalUtil.CMP_OP_NOT_EQUALS; - } else if (opString == "gt" || opString == "\\gt" || opString == ">" || opString == ">") { - operation = EvalUtil.CMP_OP_GREATER_THAN; - } else if (opString == "gte" || opString == "\\gte" || opString == ">=" || opString == ">=") { - operation = EvalUtil.CMP_OP_GREATER_THAN_EQUALS; - } else if (opString == "lt" || opString == "\\lt" || opString == "<" || opString == "<") { - operation = EvalUtil.CMP_OP_LESS_THAN; - } else if (opString == "lte" || opString == "\\lte" || opString == "<=" || opString == "<=") { - operation = EvalUtil.CMP_OP_LESS_THAN_EQUALS; - } else { - throw new BugException("Unknown comparison operator " + opString); - } - } - - /* - * WARNING! This algorithm is duplicated in SequenceBuiltins.modelsEqual. - * Thus, if you update this method, then you have to update that too! - */ - @Override - boolean evalToBoolean(Environment env) throws TemplateException { - return EvalUtil.compare(left, operation, opString, right, this, env); - } - - @Override - public String getCanonicalForm() { - return left.getCanonicalForm() + ' ' + opString + ' ' + right.getCanonicalForm(); - } - - @Override - String getNodeTypeSymbol() { - return opString; - } - - @Override - boolean isLiteral() { - return constantValue != null || (left.isLiteral() && right.isLiteral()); - } - - @Override - protected Expression deepCloneWithIdentifierReplaced_inner( - String replacedIdentifier, Expression replacement, ReplacemenetState replacementState) { - return new ComparisonExpression( - left.deepCloneWithIdentifierReplaced(replacedIdentifier, replacement, replacementState), - right.deepCloneWithIdentifierReplaced(replacedIdentifier, replacement, replacementState), - opString); - } - - @Override - int getParameterCount() { - return 2; - } - - @Override - Object getParameterValue(int idx) { - return idx == 0 ? left : right; - } - - @Override - ParameterRole getParameterRole(int idx) { - return ParameterRole.forBinaryOperatorOperand(idx); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/CompressedBlock.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/CompressedBlock.java b/src/main/java/freemarker/core/CompressedBlock.java deleted file mode 100644 index 9a497e3..0000000 --- a/src/main/java/freemarker/core/CompressedBlock.java +++ /dev/null @@ -1,86 +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 freemarker.core; - -import java.io.IOException; - -import freemarker.template.TemplateException; -import freemarker.template.utility.StandardCompress; - -/** - * An instruction that reduces all sequences of whitespace to a single - * space or newline. In addition, leading and trailing whitespace is removed. - * @see freemarker.template.utility.StandardCompress - */ -final class CompressedBlock extends TemplateElement { - - CompressedBlock(TemplateElements children) { - setChildren(children); - } - - @Override - TemplateElement[] accept(Environment env) throws TemplateException, IOException { - TemplateElement[] childBuffer = getChildBuffer(); - if (childBuffer != null) { - env.visitAndTransform(childBuffer, StandardCompress.INSTANCE, null); - } - return null; - } - - @Override - protected String dump(boolean canonical) { - if (canonical) { - return "<" + getNodeTypeSymbol() + ">" + getChildrenCanonicalForm() + ""; - } else { - return getNodeTypeSymbol(); - } - } - - @Override - String getNodeTypeSymbol() { - return "#compress"; - } - - @Override - int getParameterCount() { - return 0; - } - - @Override - Object getParameterValue(int idx) { - throw new IndexOutOfBoundsException(); - } - - @Override - ParameterRole getParameterRole(int idx) { - throw new IndexOutOfBoundsException(); - } - - @Override - boolean isIgnorable(boolean stripWhitespace) { - return getChildCount() == 0 && getParameterCount() == 0; - } - - @Override - boolean isNestedBlockRepeater() { - return false; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/core/ConditionalBlock.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/ConditionalBlock.java b/src/main/java/freemarker/core/ConditionalBlock.java deleted file mode 100644 index 3b94001..0000000 --- a/src/main/java/freemarker/core/ConditionalBlock.java +++ /dev/null @@ -1,114 +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 freemarker.core; - -import java.io.IOException; - -import freemarker.template.TemplateException; - -/** - * An element that represents a conditionally executed block: #if, #elseif or #elseif. Note that when an #if has - * related #elseif-s or #else, an {@link IfBlock} parent must be used. For a lonely #if, no such parent is needed. - */ - -final class ConditionalBlock extends TemplateElement { - - static final int TYPE_IF = 0; - static final int TYPE_ELSE = 1; - static final int TYPE_ELSE_IF = 2; - - final Expression condition; - private final int type; - - ConditionalBlock(Expression condition, TemplateElements children, int type) { - this.condition = condition; - setChildren(children); - this.type = type; - } - - @Override - TemplateElement[] accept(Environment env) throws TemplateException, IOException { - if (condition == null || condition.evalToBoolean(env)) { - return getChildBuffer(); - } - return null; - } - - @Override - protected String dump(boolean canonical) { - StringBuilder buf = new StringBuilder(); - if (canonical) buf.append('<'); - buf.append(getNodeTypeSymbol()); - if (condition != null) { - buf.append(' '); - buf.append(condition.getCanonicalForm()); - } - if (canonical) { - buf.append(">"); - buf.append(getChildrenCanonicalForm()); - if (!(getParentElement() instanceof IfBlock)) { - buf.append(""); - } - } - return buf.toString(); - } - - @Override - String getNodeTypeSymbol() { - if (type == TYPE_ELSE) { - return "#else"; - } else if (type == TYPE_IF) { - return "#if"; - } else if (type == TYPE_ELSE_IF) { - return "#elseif"; - } else { - throw new BugException("Unknown type"); - } - } - - @Override - int getParameterCount() { - return 2; - } - - @Override - Object getParameterValue(int idx) { - switch (idx) { - case 0: return condition; - case 1: return Integer.valueOf(type); - default: throw new IndexOutOfBoundsException(); - } - } - - @Override - ParameterRole getParameterRole(int idx) { - switch (idx) { - case 0: return ParameterRole.CONDITION; - case 1: return ParameterRole.AST_NODE_SUBTYPE; - default: throw new IndexOutOfBoundsException(); - } - } - - @Override - boolean isNestedBlockRepeater() { - return false; - } - -}