http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/ThreadInterruptionSupportTemplatePostProcessor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/ThreadInterruptionSupportTemplatePostProcessor.java b/src/main/java/org/apache/freemarker/core/ast/ThreadInterruptionSupportTemplatePostProcessor.java deleted file mode 100644 index eeb209b..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/ThreadInterruptionSupportTemplatePostProcessor.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -import java.io.IOException; - -import org.apache.freemarker.core.Template; -import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.model.TemplateDateModel; -import org.apache.freemarker.core.model.TemplateDirectiveBody; - -/** - * Not yet public; subject to change. - * - * <p> - * Known compatibility risks when using this post-processor: - * <ul> - * <li>{@link TemplateDateModel}-s that care to explicitly check if their nested content is {@code null} might start to - * complain that you have specified a body despite that the directive doesn't support that. Directives should use - * {@link NestedContentNotSupportedException#check(TemplateDirectiveBody)} instead of a simple - * {@code null}-check to avoid this problem.</li> - * <li> - * Software that uses {@link DirectiveCallPlace#isNestedOutputCacheable()} will always get {@code false}, because - * interruption checks ({@link ThreadInterruptionCheck} elements) are, obviously, not cacheable. This should only - * impact the performance. - * <li> - * Software that investigates the AST will see the injected {@link ThreadInterruptionCheck} elements. As of this - * writing the AST API-s aren't published, also such software need to be able to deal with new kind of elements - * anyway, so this shouldn't be a problem. - * </ul> - */ -class ThreadInterruptionSupportTemplatePostProcessor extends TemplatePostProcessor { - - @Override - public void postProcess(Template t) throws TemplatePostProcessorException { - final TemplateElement te = t.getRootTreeNode(); - addInterruptionChecks(te); - } - - private void addInterruptionChecks(final TemplateElement te) throws TemplatePostProcessorException { - if (te == null) { - return; - } - - final int regulatedChildrenCount = te.getChildCount(); - for (int i = 0; i < regulatedChildrenCount; i++) { - addInterruptionChecks(te.getChild(i)); - } - - if (te.isNestedBlockRepeater()) { - try { - te.addChild(0, new ThreadInterruptionCheck(te)); - } catch (ParseException e) { - throw new TemplatePostProcessorException("Unexpected error; see cause", e); - } - } - } - - /** - * Check if the current thread's "interrupted" flag is set, and throws - * {@link TemplateProcessingThreadInterruptedException} if it is. We inject this to some points in the AST. - */ - static class ThreadInterruptionCheck extends TemplateElement { - - private ThreadInterruptionCheck(TemplateElement te) throws ParseException { - setLocation(te.getTemplate(), te.beginColumn, te.beginLine, te.beginColumn, te.beginLine); - } - - @Override - TemplateElement[] accept(Environment env) throws TemplateException, IOException { - // As the API doesn't allow throwing InterruptedException here (nor anywhere else, most importantly, - // Template.process can't throw it), we must not clear the "interrupted" flag of the thread. - if (Thread.currentThread().isInterrupted()) { - throw new TemplateProcessingThreadInterruptedException(); - } - return null; - } - - @Override - protected String dump(boolean canonical) { - return canonical ? "" : "<#--" + getNodeTypeSymbol() + "--#>"; - } - - @Override - String getNodeTypeSymbol() { - return "##threadInterruptionCheck"; - } - - @Override - int getParameterCount() { - return 0; - } - - @Override - Object getParameterValue(int idx) { - throw new IndexOutOfBoundsException(); - } - - @Override - ParameterRole getParameterRole(int idx) { - throw new IndexOutOfBoundsException(); - } - - @Override - boolean isNestedBlockRepeater() { - return false; - } - - } - - /** - * Indicates that the template processing thread's "interrupted" flag was found to be set. - * - * <p>ATTENTION: This is used by https://github.com/kenshoo/freemarker-online. Don't break backward - * compatibility without updating that project too! - */ - static class TemplateProcessingThreadInterruptedException extends RuntimeException { - - TemplateProcessingThreadInterruptedException() { - super("Template processing thread \"interrupted\" flag was set."); - } - - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/TokenMgrError.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/TokenMgrError.java b/src/main/java/org/apache/freemarker/core/ast/TokenMgrError.java deleted file mode 100644 index cdd1395..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/TokenMgrError.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -import org.apache.freemarker.core.Template; - -/** - * Exception thrown on lower (lexical) level parsing errors. Shouldn't reach normal FreeMarker users, as FreeMarker - * usually catches this and wraps it into a {@link ParseException}. - * - * This is a modified version of file generated by JavaCC from FTL.jj. - * You can modify this class to customize the error reporting mechanisms so long as the public interface - * remains compatible with the original. - * - * @see ParseException - */ -public class TokenMgrError extends Error { - /* - * Ordinals for various reasons why an Error of this type can be thrown. - */ - - /** - * Lexical error occurred. - */ - static final int LEXICAL_ERROR = 0; - - /** - * An attempt was made to create a second instance of a static token manager. - */ - static final int STATIC_LEXER_ERROR = 1; - - /** - * Tried to change to an invalid lexical state. - */ - static final int INVALID_LEXICAL_STATE = 2; - - /** - * Detected (and bailed out of) an infinite loop in the token manager. - */ - static final int LOOP_DETECTED = 3; - - /** - * Indicates the reason why the exception is thrown. It will have - * one of the above 4 values. - */ - int errorCode; - - private String detail; - private Integer lineNumber, columnNumber; - private Integer endLineNumber, endColumnNumber; - - /** - * Replaces unprintable characters by their espaced (or unicode escaped) - * equivalents in the given string - */ - protected static final String addEscapes(String str) { - StringBuilder retval = new StringBuilder(); - char ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - case 0 : - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - continue; - } - } - return retval.toString(); - } - - /** - * Returns a detailed message for the Error when it's thrown by the - * token manager to indicate a lexical error. - * Parameters : - * EOFSeen : indicates if EOF caused the lexicl error - * curLexState : lexical state in which this error occurred - * errorLine : line number when the error occurred - * errorColumn : column number when the error occurred - * errorAfter : prefix that was seen before this error occurred - * curchar : the offending character - * Note: You can customize the lexical error message by modifying this method. - */ - protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { - return("Lexical error: encountered " + - (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") + - "after \"" + addEscapes(errorAfter) + "\"."); - } - - /** - * You can also modify the body of this method to customize your error messages. - * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not - * of end-users concern, so you can return something like : - * - * "Internal Error : Please file a bug report .... " - * - * from this method for such cases in the release version of your parser. - */ - @Override -public String getMessage() { - return super.getMessage(); - } - - /* - * Constructors of various flavors follow. - */ - - public TokenMgrError() { - } - - public TokenMgrError(String detail, int reason) { - super(detail); // the "detail" must not contain location information, the "message" might does - this.detail = detail; - errorCode = reason; - } - - /** - * @since 2.3.21 - */ - public TokenMgrError(String detail, int reason, - int errorLine, int errorColumn, - int endLineNumber, int endColumnNumber) { - super(detail); // the "detail" must not contain location information, the "message" might does - this.detail = detail; - errorCode = reason; - - lineNumber = Integer.valueOf(errorLine); // In J2SE there was no Integer.valueOf(int) - columnNumber = Integer.valueOf(errorColumn); - this.endLineNumber = Integer.valueOf(endLineNumber); - this.endColumnNumber = Integer.valueOf(endColumnNumber); - } - - /** - * Overload for JavaCC 6 compatibility. - * - * @since 2.3.24 - */ - TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { - this(EOFSeen, lexState, errorLine, errorColumn, errorAfter, (char) curChar, reason); - } - - public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { - this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); - - lineNumber = Integer.valueOf(errorLine); // In J2SE there was no Integer.valueOf(int) - columnNumber = Integer.valueOf(errorColumn); - // We blame the single character that can't be the start of a legal token: - endLineNumber = lineNumber; - endColumnNumber = columnNumber; - } - - /** - * 1-based line number of the unexpected character(s). - * - * @since 2.3.20 - */ - public Integer getLineNumber() { - return lineNumber; - } - - /** - * 1-based column number of the unexpected character(s). - * - * @since 2.3.20 - */ - public Integer getColumnNumber() { - return columnNumber; - } - - /** - * Returns the 1-based line at which the last character of the wrong section is. This will be usually (but not - * always) the same as {@link #getLineNumber()} because the lexer can only point to the single character that - * doesn't match any patterns. - * - * @since 2.3.21 - */ - public Integer getEndLineNumber() { - return endLineNumber; - } - - /** - * Returns the 1-based column at which the last character of the wrong section is. This will be usually (but not - * always) the same as {@link #getColumnNumber()} because the lexer can only point to the single character that - * doesn't match any patterns. - * - * @since 2.3.21 - */ - public Integer getEndColumnNumber() { - return endColumnNumber; - } - - public String getDetail() { - return detail; - } - - public ParseException toParseException(Template template) { - return new ParseException(getDetail(), - template, - getLineNumber() != null ? getLineNumber().intValue() : 0, - getColumnNumber() != null ? getColumnNumber().intValue() : 0, - getEndLineNumber() != null ? getEndLineNumber().intValue() : 0, - getEndColumnNumber() != null ? getEndColumnNumber().intValue() : 0); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/TransformBlock.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/TransformBlock.java b/src/main/java/org/apache/freemarker/core/ast/TransformBlock.java deleted file mode 100644 index fc9ad67..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/TransformBlock.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -import java.io.IOException; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateTransformModel; - -/** - * A template element that contains a nested block - * that is transformed according to an instance of T - * TemplateTransformModel - */ -final class TransformBlock extends TemplateElement { - - private Expression transformExpression; - Map namedArgs; - private transient volatile SoftReference/*List<Map.Entry<String,Expression>>*/ sortedNamedArgsCache; - - /** - * Creates new TransformBlock, with a given transformation - */ - TransformBlock(Expression transformExpression, - Map namedArgs, - TemplateElements children) { - this.transformExpression = transformExpression; - this.namedArgs = namedArgs; - setChildren(children); - } - - @Override - TemplateElement[] accept(Environment env) - throws TemplateException, IOException { - TemplateTransformModel ttm = env.getTransform(transformExpression); - if (ttm != null) { - Map args; - if (namedArgs != null && !namedArgs.isEmpty()) { - args = new HashMap(); - for (Iterator it = namedArgs.entrySet().iterator(); it.hasNext(); ) { - Map.Entry entry = (Map.Entry) it.next(); - String key = (String) entry.getKey(); - Expression valueExp = (Expression) entry.getValue(); - TemplateModel value = valueExp.eval(env); - args.put(key, value); - } - } else { - args = Collections.emptyMap(); - } - env.visitAndTransform(getChildBuffer(), ttm, args); - } else { - TemplateModel tm = transformExpression.eval(env); - throw new UnexpectedTypeException( - transformExpression, tm, - "transform", new Class[] { TemplateTransformModel.class }, env); - } - return null; - } - - @Override - protected String dump(boolean canonical) { - StringBuilder sb = new StringBuilder(); - if (canonical) sb.append('<'); - sb.append(getNodeTypeSymbol()); - sb.append(' '); - sb.append(transformExpression); - if (namedArgs != null) { - for (Iterator it = getSortedNamedArgs().iterator(); it.hasNext(); ) { - Map.Entry entry = (Map.Entry) it.next(); - sb.append(' '); - sb.append(entry.getKey()); - sb.append('='); - MessageUtil.appendExpressionAsUntearable(sb, (Expression) entry.getValue()); - } - } - if (canonical) { - sb.append(">"); - sb.append(getChildrenCanonicalForm()); - sb.append("</").append(getNodeTypeSymbol()).append('>'); - } - return sb.toString(); - } - - @Override - String getNodeTypeSymbol() { - return "#transform"; - } - - @Override - int getParameterCount() { - return 1/*nameExp*/ + (namedArgs != null ? namedArgs.size() * 2 : 0); - } - - @Override - Object getParameterValue(int idx) { - if (idx == 0) { - return transformExpression; - } else if (namedArgs != null && idx - 1 < namedArgs.size() * 2) { - Map.Entry namedArg = (Map.Entry) getSortedNamedArgs().get((idx - 1) / 2); - return (idx - 1) % 2 == 0 ? namedArg.getKey() : namedArg.getValue(); - } else { - throw new IndexOutOfBoundsException(); - } - } - - @Override - ParameterRole getParameterRole(int idx) { - if (idx == 0) { - return ParameterRole.CALLEE; - } else if (idx - 1 < namedArgs.size() * 2) { - return (idx - 1) % 2 == 0 ? ParameterRole.ARGUMENT_NAME : ParameterRole.ARGUMENT_VALUE; - } else { - throw new IndexOutOfBoundsException(); - } - } - - /** - * Returns the named args by source-code order; it's not meant to be used during template execution, too slow for - * that! - */ - private List/*<Map.Entry<String, Expression>>*/ getSortedNamedArgs() { - Reference ref = sortedNamedArgsCache; - if (ref != null) { - List res = (List) ref.get(); - if (res != null) return res; - } - - List res = MiscUtil.sortMapOfExpressions(namedArgs); - sortedNamedArgsCache = new SoftReference(res); - return res; - } - - @Override - boolean isNestedBlockRepeater() { - return false; - } - - @Override - boolean isShownInStackTrace() { - return true; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/TrimInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/TrimInstruction.java b/src/main/java/org/apache/freemarker/core/ast/TrimInstruction.java deleted file mode 100644 index 367ce2b..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/TrimInstruction.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -/** - * An instruction that indicates that that opening - * and trailing whitespace on this line should be trimmed. - */ -final class TrimInstruction extends TemplateElement { - - private final int TYPE_T = 0; - private final int TYPE_LT = 1; - private final int TYPE_RT = 2; - private final int TYPE_NT = 3; - - final boolean left, right; - - TrimInstruction(boolean left, boolean right) { - this.left = left; - this.right = right; - } - - @Override - TemplateElement[] accept(Environment env) { - // This instruction does nothing at render-time, only parse-time. - return null; - } - - @Override - protected String dump(boolean canonical) { - StringBuilder sb = new StringBuilder(); - if (canonical) sb.append('<'); - sb.append(getNodeTypeSymbol()); - if (canonical) sb.append("/>"); - return sb.toString(); - } - - @Override - String getNodeTypeSymbol() { - if (left && right) { - return "#t"; - } else if (left) { - return "#lt"; - } else if (right) { - return "#rt"; - } else { - return "#nt"; - } - } - - @Override - boolean isIgnorable(boolean stripWhitespace) { - return true; - } - - @Override - int getParameterCount() { - return 1; - } - - @Override - Object getParameterValue(int idx) { - if (idx != 0) throw new IndexOutOfBoundsException(); - int type; - if (left && right) { - type = TYPE_T; - } else if (left) { - type = TYPE_LT; - } else if (right) { - type = TYPE_RT; - } else { - type = TYPE_NT; - } - return Integer.valueOf(type); - } - - @Override - ParameterRole getParameterRole(int idx) { - if (idx != 0) throw new IndexOutOfBoundsException(); - return ParameterRole.AST_NODE_SUBTYPE; - } - - @Override - boolean isOutputCacheable() { - return true; - } - - @Override - boolean isNestedBlockRepeater() { - return false; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/UnaryPlusMinusExpression.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/UnaryPlusMinusExpression.java b/src/main/java/org/apache/freemarker/core/ast/UnaryPlusMinusExpression.java deleted file mode 100644 index 057c2fd..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/UnaryPlusMinusExpression.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 org.apache.freemarker.core.ast; - -import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateNumberModel; -import org.apache.freemarker.core.model.impl.SimpleNumber; - -final class UnaryPlusMinusExpression extends Expression { - - private final int TYPE_MINUS = 0; - private final int TYPE_PLUS = 1; - - private final Expression target; - private final boolean isMinus; - private static final Integer MINUS_ONE = Integer.valueOf(-1); - - UnaryPlusMinusExpression(Expression target, boolean isMinus) { - this.target = target; - this.isMinus = isMinus; - } - - @Override - TemplateModel _eval(Environment env) throws TemplateException { - TemplateNumberModel targetModel = null; - TemplateModel tm = target.eval(env); - try { - targetModel = (TemplateNumberModel) tm; - } catch (ClassCastException cce) { - throw new NonNumericalException(target, tm, env); - } - if (!isMinus) { - return targetModel; - } - target.assertNonNull(targetModel, env); - Number n = targetModel.getAsNumber(); - n = ArithmeticEngine.CONSERVATIVE_ENGINE.multiply(MINUS_ONE, n); - return new SimpleNumber(n); - } - - @Override - public String getCanonicalForm() { - String op = isMinus ? "-" : "+"; - return op + target.getCanonicalForm(); - } - - @Override - String getNodeTypeSymbol() { - return isMinus ? "-..." : "+..."; - } - - @Override - boolean isLiteral() { - return target.isLiteral(); - } - - @Override - protected Expression deepCloneWithIdentifierReplaced_inner( - String replacedIdentifier, Expression replacement, ReplacemenetState replacementState) { - return new UnaryPlusMinusExpression( - target.deepCloneWithIdentifierReplaced(replacedIdentifier, replacement, replacementState), - isMinus); - } - - @Override - int getParameterCount() { - return 2; - } - - @Override - Object getParameterValue(int idx) { - switch (idx) { - case 0: return target; - case 1: return Integer.valueOf(isMinus ? TYPE_MINUS : TYPE_PLUS); - default: throw new IndexOutOfBoundsException(); - } - } - - @Override - ParameterRole getParameterRole(int idx) { - switch (idx) { - case 0: return ParameterRole.RIGHT_HAND_OPERAND; - case 1: return ParameterRole.AST_NODE_SUBTYPE; - default: throw new IndexOutOfBoundsException(); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/UndefinedCustomFormatException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/UndefinedCustomFormatException.java b/src/main/java/org/apache/freemarker/core/ast/UndefinedCustomFormatException.java deleted file mode 100644 index bb0606c..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/UndefinedCustomFormatException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.freemarker.core.ast; - -/** - * @since 2.3.24 - */ -public class UndefinedCustomFormatException extends InvalidFormatStringException { - - public UndefinedCustomFormatException(String message, Throwable cause) { - super(message, cause); - } - - public UndefinedCustomFormatException(String message) { - super(message); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/UndefinedOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/UndefinedOutputFormat.java b/src/main/java/org/apache/freemarker/core/ast/UndefinedOutputFormat.java deleted file mode 100644 index e58be32..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/UndefinedOutputFormat.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.freemarker.core.ast; - -import org.apache.freemarker.core.Configuration; - -/** - * Represents the output format used when the template output format is undecided. This is the default output format if - * FreeMarker can't select anything more specific (see - * {@link Configuration#setTemplateConfigurations(org.apache.freemarker.core.templateresolver.TemplateConfigurationFactory)}). This format doesn't - * support auto-escaping ({@link Configuration#setAutoEscapingPolicy(int)}). It will print - * {@link TemplateMarkupOutputModel}-s as is (doesn't try to convert them). - * - * @see PlainTextOutputFormat - * - * @since 2.3.24 - */ -public final class UndefinedOutputFormat extends OutputFormat { - - public static final UndefinedOutputFormat INSTANCE = new UndefinedOutputFormat(); - - private UndefinedOutputFormat() { - // Only to decrease visibility - } - - @Override - public boolean isOutputFormatMixingAllowed() { - return true; - } - - @Override - public String getName() { - return "undefined"; - } - - @Override - public String getMimeType() { - return null; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/UnexpectedTypeException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/UnexpectedTypeException.java b/src/main/java/org/apache/freemarker/core/ast/UnexpectedTypeException.java deleted file mode 100644 index 12f5e03..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/UnexpectedTypeException.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.model.TemplateModel; - -/** - * The type of a value differs from what was expected. - * - * @since 2.3.20 - */ -public class UnexpectedTypeException extends TemplateException { - - public UnexpectedTypeException(Environment env, String description) { - super(description, env); - } - - UnexpectedTypeException(Environment env, _ErrorDescriptionBuilder description) { - super(null, env, null, description); - } - - UnexpectedTypeException( - Expression blamed, TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, Environment env) - throws InvalidReferenceException { - super(null, env, blamed, newDesciptionBuilder(blamed, null, model, expectedTypesDesc, expectedTypes, env)); - } - - UnexpectedTypeException( - Expression blamed, TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, String tip, - Environment env) - throws InvalidReferenceException { - super(null, env, blamed, newDesciptionBuilder(blamed, null, model, expectedTypesDesc, expectedTypes, env) - .tip(tip)); - } - - UnexpectedTypeException( - Expression blamed, TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, Object[] tips, - Environment env) - throws InvalidReferenceException { - super(null, env, blamed, newDesciptionBuilder(blamed, null, model, expectedTypesDesc, expectedTypes, env) - .tips(tips)); - } - - UnexpectedTypeException( - String blamedAssignmentTargetVarName, TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, - Object[] tips, - Environment env) - throws InvalidReferenceException { - super(null, env, null, newDesciptionBuilder( - null, blamedAssignmentTargetVarName, model, expectedTypesDesc, expectedTypes, env).tips(tips)); - } - - /** - * @param blamedAssignmentTargetVarName - * Used for assignments that use {@code +=} and such, in which case the {@code blamed} expression - * parameter will be null {@code null} and this parameter will be non-{null}. - */ - private static _ErrorDescriptionBuilder newDesciptionBuilder( - Expression blamed, String blamedAssignmentTargetVarName, - TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, Environment env) - throws InvalidReferenceException { - if (model == null) throw InvalidReferenceException.getInstance(blamed, env); - - _ErrorDescriptionBuilder errorDescBuilder = new _ErrorDescriptionBuilder( - unexpectedTypeErrorDescription(expectedTypesDesc, blamed, blamedAssignmentTargetVarName, model)) - .blame(blamed).showBlamer(true); - if (model instanceof _UnexpectedTypeErrorExplainerTemplateModel) { - Object[] tip = ((_UnexpectedTypeErrorExplainerTemplateModel) model).explainTypeError(expectedTypes); - if (tip != null) { - errorDescBuilder.tip(tip); - } - } - return errorDescBuilder; - } - - private static Object[] unexpectedTypeErrorDescription( - String expectedTypesDesc, - Expression blamed, String blamedAssignmentTargetVarName, - TemplateModel model) { - return new Object[] { - "Expected ", new _DelayedAOrAn(expectedTypesDesc), ", but ", - (blamedAssignmentTargetVarName == null - ? blamed != null ? "this" : "the expression" - : new Object[] { - "assignment target variable ", - new _DelayedJQuote(blamedAssignmentTargetVarName) }), - " has evaluated to ", - new _DelayedAOrAn(new _DelayedFTLTypeDescription(model)), - (blamedAssignmentTargetVarName == null ? ":" : ".")}; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/UnformattableValueException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/UnformattableValueException.java b/src/main/java/org/apache/freemarker/core/ast/UnformattableValueException.java deleted file mode 100644 index 8bc89c1..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/UnformattableValueException.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -import org.apache.freemarker.core.model.TemplateModel; - -/** - * Thrown when a {@link TemplateModel} can't be formatted because of the value/properties of it are outside of that the - * {@link TemplateValueFormat} supports. For example, a formatter may not support dates before year 1, or can't format - * NaN. The most often used subclass is {@link UnknownDateTypeFormattingUnsupportedException}. - * - * @since 2.3.24 - */ -public class UnformattableValueException extends TemplateValueFormatException { - - public UnformattableValueException(String message, Throwable cause) { - super(message, cause); - } - - public UnformattableValueException(String message) { - super(message); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/UnifiedCall.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/UnifiedCall.java b/src/main/java/org/apache/freemarker/core/ast/UnifiedCall.java deleted file mode 100644 index da3d95f..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/UnifiedCall.java +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -import java.io.IOException; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.model.TemplateDirectiveModel; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateTransformModel; -import org.apache.freemarker.core.util.ObjectFactory; -import org.apache.freemarker.core.util._StringUtil; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -/** - * An element for the unified macro/transform syntax. - */ -final class UnifiedCall extends TemplateElement implements DirectiveCallPlace { - - private Expression nameExp; - private Map namedArgs; - private List positionalArgs, bodyParameterNames; - boolean legacySyntax; - private transient volatile SoftReference/*List<Map.Entry<String,Expression>>*/ sortedNamedArgsCache; - private CustomDataHolder customDataHolder; - - UnifiedCall(Expression nameExp, - Map namedArgs, - TemplateElements children, - List bodyParameterNames) { - this.nameExp = nameExp; - this.namedArgs = namedArgs; - setChildren(children); - this.bodyParameterNames = bodyParameterNames; - } - - UnifiedCall(Expression nameExp, - List positionalArgs, - TemplateElements children, - List bodyParameterNames) { - this.nameExp = nameExp; - this.positionalArgs = positionalArgs; - setChildren(children); - this.bodyParameterNames = bodyParameterNames; - } - - @Override - TemplateElement[] accept(Environment env) throws TemplateException, IOException { - TemplateModel tm = nameExp.eval(env); - if (tm == Macro.DO_NOTHING_MACRO) return null; // shortcut here. - if (tm instanceof Macro) { - Macro macro = (Macro) tm; - if (macro.isFunction() && !legacySyntax) { - throw new _MiscTemplateException(env, - "Routine ", new _DelayedJQuote(macro.getName()), " is a function, not a directive. " - + "Functions can only be called from expressions, like in ${f()}, ${x + f()} or ", - "<@someDirective someParam=f() />", "."); - } - env.invoke(macro, namedArgs, positionalArgs, bodyParameterNames, getChildBuffer()); - } else { - boolean isDirectiveModel = tm instanceof TemplateDirectiveModel; - if (isDirectiveModel || tm instanceof TemplateTransformModel) { - Map args; - if (namedArgs != null && !namedArgs.isEmpty()) { - args = new HashMap(); - for (Iterator it = namedArgs.entrySet().iterator(); it.hasNext(); ) { - Map.Entry entry = (Map.Entry) it.next(); - String key = (String) entry.getKey(); - Expression valueExp = (Expression) entry.getValue(); - TemplateModel value = valueExp.eval(env); - args.put(key, value); - } - } else { - args = Collections.emptyMap(); - } - if (isDirectiveModel) { - env.visit(getChildBuffer(), (TemplateDirectiveModel) tm, args, bodyParameterNames); - } else { - env.visitAndTransform(getChildBuffer(), (TemplateTransformModel) tm, args); - } - } else if (tm == null) { - throw InvalidReferenceException.getInstance(nameExp, env); - } else { - throw new NonUserDefinedDirectiveLikeException(nameExp, tm, env); - } - } - return null; - } - - @Override - protected String dump(boolean canonical) { - StringBuilder sb = new StringBuilder(); - if (canonical) sb.append('<'); - sb.append('@'); - MessageUtil.appendExpressionAsUntearable(sb, nameExp); - boolean nameIsInParen = sb.charAt(sb.length() - 1) == ')'; - if (positionalArgs != null) { - for (int i = 0; i < positionalArgs.size(); i++) { - Expression argExp = (Expression) positionalArgs.get(i); - if (i != 0) { - sb.append(','); - } - sb.append(' '); - sb.append(argExp.getCanonicalForm()); - } - } else { - List entries = getSortedNamedArgs(); - for (int i = 0; i < entries.size(); i++) { - Map.Entry entry = (Map.Entry) entries.get(i); - Expression argExp = (Expression) entry.getValue(); - sb.append(' '); - sb.append(_StringUtil.toFTLTopLevelIdentifierReference((String) entry.getKey())); - sb.append('='); - MessageUtil.appendExpressionAsUntearable(sb, argExp); - } - } - if (bodyParameterNames != null && !bodyParameterNames.isEmpty()) { - sb.append("; "); - for (int i = 0; i < bodyParameterNames.size(); i++) { - if (i != 0) { - sb.append(", "); - } - sb.append(_StringUtil.toFTLTopLevelIdentifierReference((String) bodyParameterNames.get(i))); - } - } - if (canonical) { - if (getChildCount() == 0) { - sb.append("/>"); - } else { - sb.append('>'); - sb.append(getChildrenCanonicalForm()); - sb.append("</@"); - if (!nameIsInParen - && (nameExp instanceof Identifier - || (nameExp instanceof Dot && ((Dot) nameExp).onlyHasIdentifiers()))) { - sb.append(nameExp.getCanonicalForm()); - } - sb.append('>'); - } - } - return sb.toString(); - } - - @Override - String getNodeTypeSymbol() { - return "@"; - } - - @Override - int getParameterCount() { - return 1/*nameExp*/ - + (positionalArgs != null ? positionalArgs.size() : 0) - + (namedArgs != null ? namedArgs.size() * 2 : 0) - + (bodyParameterNames != null ? bodyParameterNames.size() : 0); - } - - @Override - Object getParameterValue(int idx) { - if (idx == 0) { - return nameExp; - } else { - int base = 1; - final int positionalArgsSize = positionalArgs != null ? positionalArgs.size() : 0; - if (idx - base < positionalArgsSize) { - return positionalArgs.get(idx - base); - } else { - base += positionalArgsSize; - final int namedArgsSize = namedArgs != null ? namedArgs.size() : 0; - if (idx - base < namedArgsSize * 2) { - Map.Entry namedArg = (Map.Entry) getSortedNamedArgs().get((idx - base) / 2); - return (idx - base) % 2 == 0 ? namedArg.getKey() : namedArg.getValue(); - } else { - base += namedArgsSize * 2; - final int bodyParameterNamesSize = bodyParameterNames != null ? bodyParameterNames.size() : 0; - if (idx - base < bodyParameterNamesSize) { - return bodyParameterNames.get(idx - base); - } else { - throw new IndexOutOfBoundsException(); - } - } - } - } - } - - @Override - ParameterRole getParameterRole(int idx) { - if (idx == 0) { - return ParameterRole.CALLEE; - } else { - int base = 1; - final int positionalArgsSize = positionalArgs != null ? positionalArgs.size() : 0; - if (idx - base < positionalArgsSize) { - return ParameterRole.ARGUMENT_VALUE; - } else { - base += positionalArgsSize; - final int namedArgsSize = namedArgs != null ? namedArgs.size() : 0; - if (idx - base < namedArgsSize * 2) { - return (idx - base) % 2 == 0 ? ParameterRole.ARGUMENT_NAME : ParameterRole.ARGUMENT_VALUE; - } else { - base += namedArgsSize * 2; - final int bodyParameterNamesSize = bodyParameterNames != null ? bodyParameterNames.size() : 0; - if (idx - base < bodyParameterNamesSize) { - return ParameterRole.TARGET_LOOP_VARIABLE; - } else { - throw new IndexOutOfBoundsException(); - } - } - } - } - } - - /** - * Returns the named args by source-code order; it's not meant to be used during template execution, too slow for - * that! - */ - private List/*<Map.Entry<String, Expression>>*/ getSortedNamedArgs() { - Reference ref = sortedNamedArgsCache; - if (ref != null) { - List res = (List) ref.get(); - if (res != null) return res; - } - - List res = MiscUtil.sortMapOfExpressions(namedArgs); - sortedNamedArgsCache = new SoftReference(res); - return res; - } - - @Override - @SuppressFBWarnings(value={ "IS2_INCONSISTENT_SYNC", "DC_DOUBLECHECK" }, justification="Performance tricks") - public Object getOrCreateCustomData(Object providerIdentity, ObjectFactory objectFactory) - throws CallPlaceCustomDataInitializationException { - // We are using double-checked locking, utilizing Java memory model "final" trick. - // Note that this.customDataHolder is NOT volatile. - - CustomDataHolder customDataHolder = this.customDataHolder; // Findbugs false alarm - if (customDataHolder == null) { // Findbugs false alarm - synchronized (this) { - customDataHolder = this.customDataHolder; - if (customDataHolder == null || customDataHolder.providerIdentity != providerIdentity) { - customDataHolder = createNewCustomData(providerIdentity, objectFactory); - this.customDataHolder = customDataHolder; - } - } - } - - if (customDataHolder.providerIdentity != providerIdentity) { - synchronized (this) { - customDataHolder = this.customDataHolder; - if (customDataHolder == null || customDataHolder.providerIdentity != providerIdentity) { - customDataHolder = createNewCustomData(providerIdentity, objectFactory); - this.customDataHolder = customDataHolder; - } - } - } - - return customDataHolder.customData; - } - - private CustomDataHolder createNewCustomData(Object provierIdentity, ObjectFactory objectFactory) - throws CallPlaceCustomDataInitializationException { - CustomDataHolder customDataHolder; - Object customData; - try { - customData = objectFactory.createObject(); - } catch (Exception e) { - throw new CallPlaceCustomDataInitializationException( - "Failed to initialize custom data for provider identity " - + _StringUtil.tryToString(provierIdentity) + " via factory " - + _StringUtil.tryToString(objectFactory), e); - } - if (customData == null) { - throw new NullPointerException("ObjectFactory.createObject() has returned null"); - } - customDataHolder = new CustomDataHolder(provierIdentity, customData); - return customDataHolder; - } - - @Override - public boolean isNestedOutputCacheable() { - return isChildrenOutputCacheable(); - } - -/* - //REVISIT - boolean heedsOpeningWhitespace() { - return nestedBlock == null; - } - - //REVISIT - boolean heedsTrailingWhitespace() { - return nestedBlock == null; - }*/ - - /** - * Used for implementing double check locking in implementing the - * {@link DirectiveCallPlace#getOrCreateCustomData(Object, ObjectFactory)}. - */ - private static class CustomDataHolder { - - private final Object providerIdentity; - private final Object customData; - public CustomDataHolder(Object providerIdentity, Object customData) { - this.providerIdentity = providerIdentity; - this.customData = customData; - } - - } - - @Override - boolean isNestedBlockRepeater() { - return true; - } - - @Override - boolean isShownInStackTrace() { - return true; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/UnknownDateTypeFormattingUnsupportedException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/UnknownDateTypeFormattingUnsupportedException.java b/src/main/java/org/apache/freemarker/core/ast/UnknownDateTypeFormattingUnsupportedException.java deleted file mode 100644 index aa3947b..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/UnknownDateTypeFormattingUnsupportedException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -import org.apache.freemarker.core.model.TemplateDateModel; - -/** - * Thrown when a {@link TemplateDateModel} can't be formatted because its type is {@link TemplateDateModel#UNKNOWN}. - * - * @since 2.3.24 - */ -public final class UnknownDateTypeFormattingUnsupportedException extends UnformattableValueException { - - public UnknownDateTypeFormattingUnsupportedException() { - super(MessageUtil.UNKNOWN_DATE_TO_STRING_ERROR_MESSAGE); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/UnknownDateTypeParsingUnsupportedException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/UnknownDateTypeParsingUnsupportedException.java b/src/main/java/org/apache/freemarker/core/ast/UnknownDateTypeParsingUnsupportedException.java deleted file mode 100644 index 15c4f3a..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/UnknownDateTypeParsingUnsupportedException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -import org.apache.freemarker.core.model.TemplateDateModel; - -/** - * Thrown when a string can't be parsed to {@link TemplateDateModel}, because the provided target type is - * {@link TemplateDateModel#UNKNOWN}. - * - * @since 2.3.24 - */ -public final class UnknownDateTypeParsingUnsupportedException extends UnformattableValueException { - - public UnknownDateTypeParsingUnsupportedException() { - super(MessageUtil.UNKNOWN_DATE_PARSING_ERROR_MESSAGE); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/UnparsableValueException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/UnparsableValueException.java b/src/main/java/org/apache/freemarker/core/ast/UnparsableValueException.java deleted file mode 100644 index 44f14fc..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/UnparsableValueException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -/** - * Thrown when the content of the string that should be parsed by the {@link TemplateValueFormat} doesn't match what the - * format expects. - * - * @since 2.3.24 - */ -public class UnparsableValueException extends TemplateValueFormatException { - - public UnparsableValueException(String message, Throwable cause) { - super(message, cause); - } - - public UnparsableValueException(String message) { - this(message, null); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/UnregisteredOutputFormatException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/UnregisteredOutputFormatException.java b/src/main/java/org/apache/freemarker/core/ast/UnregisteredOutputFormatException.java deleted file mode 100644 index f3f1466..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/UnregisteredOutputFormatException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.freemarker.core.ast; - -/** - * @since 2.3.24 - */ -public class UnregisteredOutputFormatException extends Exception { - - public UnregisteredOutputFormatException(String message) { - this(message, null); - } - - public UnregisteredOutputFormatException(String message, Throwable cause) { - super(message, cause); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/VisitNode.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/VisitNode.java b/src/main/java/org/apache/freemarker/core/ast/VisitNode.java deleted file mode 100644 index aa6c652..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/VisitNode.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -import java.io.IOException; - -import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateNodeModel; -import org.apache.freemarker.core.model.TemplateScalarModel; -import org.apache.freemarker.core.model.TemplateSequenceModel; -import org.apache.freemarker.core.model.impl.SimpleSequence; - - -/** - * An instruction to visit an XML node. - */ -final class VisitNode extends TemplateElement { - - Expression targetNode, namespaces; - - VisitNode(Expression targetNode, Expression namespaces) { - this.targetNode = targetNode; - this.namespaces = namespaces; - } - - @Override - TemplateElement[] accept(Environment env) throws IOException, TemplateException { - TemplateModel node = targetNode.eval(env); - if (!(node instanceof TemplateNodeModel)) { - throw new NonNodeException(targetNode, node, env); - } - - TemplateModel nss = namespaces == null ? null : namespaces.eval(env); - if (namespaces instanceof StringLiteral) { - nss = env.importLib(((TemplateScalarModel) nss).getAsString(), null); - } else if (namespaces instanceof ListLiteral) { - nss = ((ListLiteral) namespaces).evaluateStringsToNamespaces(env); - } - if (nss != null) { - if (nss instanceof Environment.Namespace) { - SimpleSequence ss = new SimpleSequence(1); - ss.add(nss); - nss = ss; - } else if (!(nss instanceof TemplateSequenceModel)) { - if (namespaces != null) { - throw new NonSequenceException(namespaces, nss, env); - } else { - // Should not occur - throw new _MiscTemplateException(env, "Expecting a sequence of namespaces after \"using\""); - } - } - } - env.invokeNodeHandlerFor((TemplateNodeModel) node, (TemplateSequenceModel) nss); - return null; - } - - @Override - protected String dump(boolean canonical) { - StringBuilder sb = new StringBuilder(); - if (canonical) sb.append('<'); - sb.append(getNodeTypeSymbol()); - sb.append(' '); - sb.append(targetNode.getCanonicalForm()); - if (namespaces != null) { - sb.append(" using "); - sb.append(namespaces.getCanonicalForm()); - } - if (canonical) sb.append("/>"); - return sb.toString(); - } - - @Override - String getNodeTypeSymbol() { - return "#visit"; - } - - @Override - int getParameterCount() { - return 2; - } - - @Override - Object getParameterValue(int idx) { - switch (idx) { - case 0: return targetNode; - case 1: return namespaces; - default: throw new IndexOutOfBoundsException(); - } - } - - @Override - ParameterRole getParameterRole(int idx) { - switch (idx) { - case 0: return ParameterRole.NODE; - case 1: return ParameterRole.NAMESPACE; - default: throw new IndexOutOfBoundsException(); - } - } - - @Override - boolean isNestedBlockRepeater() { - return true; - } - - @Override - boolean isShownInStackTrace() { - return true; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/XHTMLOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/XHTMLOutputFormat.java b/src/main/java/org/apache/freemarker/core/ast/XHTMLOutputFormat.java deleted file mode 100644 index 73f9c81..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/XHTMLOutputFormat.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.freemarker.core.ast; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.freemarker.core.model.TemplateModelException; -import org.apache.freemarker.core.util._StringUtil; - -/** - * Represents the XML output format (MIME type "application/xhtml+xml", name "XHTML"). This format escapes by default - * (via {@link _StringUtil#XHTMLEnc(String)}). The {@code ?xml} built-in silently bypasses template output values of the - * type produced by this output format ({@link TemplateXHTMLOutputModel}). - * - * @since 2.3.24 - */ -public final class XHTMLOutputFormat extends CommonMarkupOutputFormat<TemplateXHTMLOutputModel> { - - /** - * The only instance (singleton) of this {@link OutputFormat}. - */ - public static final XHTMLOutputFormat INSTANCE = new XHTMLOutputFormat(); - - private XHTMLOutputFormat() { - // Only to decrease visibility - } - - @Override - public String getName() { - return "XHTML"; - } - - @Override - public String getMimeType() { - return "application/xhtml+xml"; - } - - @Override - public void output(String textToEsc, Writer out) throws IOException, TemplateModelException { - _StringUtil.XHTMLEnc(textToEsc, out); - } - - @Override - public String escapePlainText(String plainTextContent) { - return _StringUtil.XHTMLEnc(plainTextContent); - } - - @Override - public boolean isLegacyBuiltInBypassed(String builtInName) { - return builtInName.equals("html") || builtInName.equals("xml") || builtInName.equals("xhtml"); - } - - @Override - protected TemplateXHTMLOutputModel newTemplateMarkupOutputModel(String plainTextContent, String markupContent) { - return new TemplateXHTMLOutputModel(plainTextContent, markupContent); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/XMLOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/XMLOutputFormat.java b/src/main/java/org/apache/freemarker/core/ast/XMLOutputFormat.java deleted file mode 100644 index 59b1670..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/XMLOutputFormat.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.freemarker.core.ast; - -import java.io.IOException; -import java.io.Writer; - -import org.apache.freemarker.core.model.TemplateModelException; -import org.apache.freemarker.core.util._StringUtil; - -/** - * Represents the XML output format (MIME type "application/xml", name "XML"). This format escapes by default (via - * {@link _StringUtil#XMLEnc(String)}). The {@code ?html}, {@code ?xhtml} and {@code ?xml} built-ins silently bypass - * template output values of the type produced by this output format ({@link TemplateXHTMLOutputModel}). - * - * @since 2.3.24 - */ -public final class XMLOutputFormat extends CommonMarkupOutputFormat<TemplateXMLOutputModel> { - - /** - * The only instance (singleton) of this {@link OutputFormat}. - */ - public static final XMLOutputFormat INSTANCE = new XMLOutputFormat(); - - private XMLOutputFormat() { - // Only to decrease visibility - } - - @Override - public String getName() { - return "XML"; - } - - @Override - public String getMimeType() { - return "application/xml"; - } - - @Override - public void output(String textToEsc, Writer out) throws IOException, TemplateModelException { - _StringUtil.XMLEnc(textToEsc, out); - } - - @Override - public String escapePlainText(String plainTextContent) { - return _StringUtil.XMLEnc(plainTextContent); - } - - @Override - public boolean isLegacyBuiltInBypassed(String builtInName) { - return builtInName.equals("xml"); - } - - @Override - protected TemplateXMLOutputModel newTemplateMarkupOutputModel(String plainTextContent, String markupContent) { - return new TemplateXMLOutputModel(plainTextContent, markupContent); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/XSTemplateDateFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/XSTemplateDateFormat.java b/src/main/java/org/apache/freemarker/core/ast/XSTemplateDateFormat.java deleted file mode 100644 index 230557b..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/XSTemplateDateFormat.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 org.apache.freemarker.core.ast; - -import java.util.Date; -import java.util.TimeZone; - -import org.apache.freemarker.core.util._DateUtil; -import org.apache.freemarker.core.util._DateUtil.CalendarFieldsToDateConverter; -import org.apache.freemarker.core.util._DateUtil.DateParseException; -import org.apache.freemarker.core.util._DateUtil.DateToISO8601CalendarFactory; - -/** - * XML Schema format. - */ -final class XSTemplateDateFormat extends ISOLikeTemplateDateFormat { - - XSTemplateDateFormat( - String settingValue, int parsingStart, - int dateType, - boolean zonelessInput, - TimeZone timeZone, - ISOLikeTemplateDateFormatFactory factory, - Environment env) - throws UnknownDateTypeFormattingUnsupportedException, InvalidFormatParametersException { - super(settingValue, parsingStart, dateType, zonelessInput, timeZone, factory, env); - } - - @Override - protected String format(Date date, boolean datePart, boolean timePart, boolean offsetPart, int accuracy, - TimeZone timeZone, DateToISO8601CalendarFactory calendarFactory) { - return _DateUtil.dateToXSString( - date, datePart, timePart, offsetPart, accuracy, timeZone, calendarFactory); - } - - @Override - protected Date parseDate(String s, TimeZone tz, CalendarFieldsToDateConverter calToDateConverter) - throws DateParseException { - return _DateUtil.parseXSDate(s, tz, calToDateConverter); - } - - @Override - protected Date parseTime(String s, TimeZone tz, CalendarFieldsToDateConverter calToDateConverter) - throws DateParseException { - return _DateUtil.parseXSTime(s, tz, calToDateConverter); - } - - @Override - protected Date parseDateTime(String s, TimeZone tz, - CalendarFieldsToDateConverter calToDateConverter) throws DateParseException { - return _DateUtil.parseXSDateTime(s, tz, calToDateConverter); - } - - @Override - protected String getDateDescription() { - return "W3C XML Schema date"; - } - - @Override - protected String getTimeDescription() { - return "W3C XML Schema time"; - } - - @Override - protected String getDateTimeDescription() { - return "W3C XML Schema dateTime"; - } - - @Override - protected boolean isXSMode() { - return true; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d784b2b/src/main/java/org/apache/freemarker/core/ast/XSTemplateDateFormatFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/XSTemplateDateFormatFactory.java b/src/main/java/org/apache/freemarker/core/ast/XSTemplateDateFormatFactory.java deleted file mode 100644 index 6072ca1..0000000 --- a/src/main/java/org/apache/freemarker/core/ast/XSTemplateDateFormatFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core.ast; - -import java.util.Locale; -import java.util.TimeZone; - -class XSTemplateDateFormatFactory extends ISOLikeTemplateDateFormatFactory { - - static final XSTemplateDateFormatFactory INSTANCE = new XSTemplateDateFormatFactory(); - - private XSTemplateDateFormatFactory() { - // Not meant to be instantiated - } - - @Override - public TemplateDateFormat get(String params, int dateType, Locale locale, TimeZone timeZone, boolean zonelessInput, - Environment env) throws UnknownDateTypeFormattingUnsupportedException, InvalidFormatParametersException { - // We don't cache these as creating them is cheap (only 10% speedup of ${d?string.xs} with caching) - return new XSTemplateDateFormat( - params, 2, - dateType, zonelessInput, - timeZone, this, env); - } - -}