http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateException.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateException.java b/src/main/java/freemarker/template/TemplateException.java deleted file mode 100644 index 7845bf8..0000000 --- a/src/main/java/freemarker/template/TemplateException.java +++ /dev/null @@ -1,661 +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.template; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.Method; - -import freemarker.core.Environment; -import freemarker.core.Expression; -import freemarker.core.InvalidReferenceException; -import freemarker.core.ParseException; -import freemarker.core.TemplateElement; -import freemarker.core.TemplateObject; -import freemarker.core._CoreAPI; -import freemarker.core._ErrorDescriptionBuilder; -import freemarker.template.utility.CollectionUtils; - -/** - * Runtime exception in a template (as opposed to a parsing-time exception: {@link ParseException}). - * It prints a special stack trace that contains the template-language stack trace along the usual Java stack trace. - */ -public class TemplateException extends Exception { - - private static final String FTL_INSTRUCTION_STACK_TRACE_TITLE - = "FTL stack trace (\"~\" means nesting-related):"; - - // Set in constructor: - private transient _ErrorDescriptionBuilder descriptionBuilder; - private final transient Environment env; - private final transient Expression blamedExpression; - private transient TemplateElement[] ftlInstructionStackSnapshot; - - // Calculated on demand: - private String renderedFtlInstructionStackSnapshot; // clalc. from ftlInstructionStackSnapshot - private String renderedFtlInstructionStackSnapshotTop; // clalc. from ftlInstructionStackSnapshot - private String description; // calc. from descriptionBuilder, or set by the construcor - private transient String messageWithoutStackTop; - private transient String message; - private boolean blamedExpressionStringCalculated; - private String blamedExpressionString; - private boolean positionsCalculated; - private String templateName; - private String templateSourceName; - private Integer lineNumber; - private Integer columnNumber; - private Integer endLineNumber; - private Integer endColumnNumber; - - // Concurrency: - private transient Object lock = new Object(); - private transient ThreadLocal messageWasAlreadyPrintedForThisTrace; - - /** - * Constructs a TemplateException with no specified detail message - * or underlying cause. - */ - public TemplateException(Environment env) { - this((String) null, null, env); - } - - /** - * Constructs a TemplateException with the given detail message, - * but no underlying cause exception. - * - * @param description the description of the error that occurred - */ - public TemplateException(String description, Environment env) { - this(description, null, env); - } - - /** - * The same as {@link #TemplateException(Throwable, Environment)}; it's exists only for binary - * backward-compatibility. - */ - public TemplateException(Exception cause, Environment env) { - this((String) null, cause, env); - } - - /** - * Constructs a TemplateException with the given underlying Exception, - * but no detail message. - * - * @param cause the underlying {@link Exception} that caused this - * exception to be raised - * - * @since 2.3.20 - */ - public TemplateException(Throwable cause, Environment env) { - this((String) null, cause, env); - } - - /** - * The same as {@link #TemplateException(String, Throwable, Environment)}; it's exists only for binary - * backward-compatibility. - */ - public TemplateException(String description, Exception cause, Environment env) { - this(description, cause, env, null, null); - } - - /** - * Constructs a TemplateException with both a description of the error - * that occurred and the underlying Exception that caused this exception - * to be raised. - * - * @param description the description of the error that occurred - * @param cause the underlying {@link Exception} that caused this exception to be raised - * - * @since 2.3.20 - */ - public TemplateException(String description, Throwable cause, Environment env) { - this(description, cause, env, null, null); - } - - /** - * Don't use this; this is to be used internally by FreeMarker. No backward compatibility guarantees. - * - * @param blamedExpr Maybe {@code null}. The FTL stack in the {@link Environment} only specifies the error location - * with "template element" granularity, and this can be used to point to the expression inside the - * template element. - */ - protected TemplateException(Throwable cause, Environment env, Expression blamedExpr, - _ErrorDescriptionBuilder descriptionBuilder) { - this(null, cause, env, blamedExpr, descriptionBuilder); - } - - private TemplateException( - String renderedDescription, - Throwable cause, - Environment env, Expression blamedExpression, - _ErrorDescriptionBuilder descriptionBuilder) { - // Note: Keep this constructor lightweight. - - super(cause); // Message managed locally. - - if (env == null) env = Environment.getCurrentEnvironment(); - this.env = env; - - this.blamedExpression = blamedExpression; - - this.descriptionBuilder = descriptionBuilder; - description = renderedDescription; - - if (env != null) ftlInstructionStackSnapshot = _CoreAPI.getInstructionStackSnapshot(env); - } - - private void renderMessages() { - String description = getDescription(); - - if (description != null && description.length() != 0) { - messageWithoutStackTop = description; - } else if (getCause() != null) { - messageWithoutStackTop = "No error description was specified for this error; low-level message: " - + getCause().getClass().getName() + ": " + getCause().getMessage(); - } else { - messageWithoutStackTop = "[No error description was available.]"; - } - - String stackTopFew = getFTLInstructionStackTopFew(); - if (stackTopFew != null) { - message = messageWithoutStackTop + "\n\n" - + _CoreAPI.ERROR_MESSAGE_HR + "\n" - + FTL_INSTRUCTION_STACK_TRACE_TITLE + "\n" - + stackTopFew - + _CoreAPI.ERROR_MESSAGE_HR; - messageWithoutStackTop = message.substring(0, messageWithoutStackTop.length()); // to reuse backing char[] - } else { - message = messageWithoutStackTop; - } - } - - private void calculatePosition() { - synchronized (lock) { - if (!positionsCalculated) { - // The expressions is the argument of the template element, so we prefer it as it's more specific. - TemplateObject templateObject = blamedExpression != null - ? (TemplateObject) blamedExpression - : ( - ftlInstructionStackSnapshot != null && ftlInstructionStackSnapshot.length != 0 - ? ftlInstructionStackSnapshot[0] : null); - // Line number blow 0 means no info, negative means position in ?eval-ed value that we won't use here. - if (templateObject != null && templateObject.getBeginLine() > 0) { - final Template template = templateObject.getTemplate(); - templateName = template != null ? template.getName() : null; - templateSourceName = template != null ? template.getSourceName() : null; - lineNumber = Integer.valueOf(templateObject.getBeginLine()); - columnNumber = Integer.valueOf(templateObject.getBeginColumn()); - endLineNumber = Integer.valueOf(templateObject.getEndLine()); - endColumnNumber = Integer.valueOf(templateObject.getEndColumn()); - } - positionsCalculated = true; - deleteFTLInstructionStackSnapshotIfNotNeeded(); - } - } - } - - /** - * @deprecated Java 1.4 has introduced {@link #getCause()} - use that instead, especially as this can't return - * runtime exceptions and errors as is. - */ - @Deprecated - public Exception getCauseException() { - return getCause() instanceof Exception - ? (Exception) getCause() - : new Exception("Wrapped to Exception: " + getCause(), getCause()); - } - - /** - * Returns the snapshot of the FTL stack trace at the time this exception was created. - */ - public String getFTLInstructionStack() { - synchronized (lock) { - if (ftlInstructionStackSnapshot != null || renderedFtlInstructionStackSnapshot != null) { - if (renderedFtlInstructionStackSnapshot == null) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - _CoreAPI.outputInstructionStack(ftlInstructionStackSnapshot, false, pw); - pw.close(); - if (renderedFtlInstructionStackSnapshot == null) { - renderedFtlInstructionStackSnapshot = sw.toString(); - deleteFTLInstructionStackSnapshotIfNotNeeded(); - } - } - return renderedFtlInstructionStackSnapshot; - } else { - return null; - } - } - } - - private String getFTLInstructionStackTopFew() { - synchronized (lock) { - if (ftlInstructionStackSnapshot != null || renderedFtlInstructionStackSnapshotTop != null) { - if (renderedFtlInstructionStackSnapshotTop == null) { - int stackSize = ftlInstructionStackSnapshot.length; - String s; - if (stackSize == 0) { - s = ""; - } else { - StringWriter sw = new StringWriter(); - _CoreAPI.outputInstructionStack(ftlInstructionStackSnapshot, true, sw); - s = sw.toString(); - } - if (renderedFtlInstructionStackSnapshotTop == null) { - renderedFtlInstructionStackSnapshotTop = s; - deleteFTLInstructionStackSnapshotIfNotNeeded(); - } - } - return renderedFtlInstructionStackSnapshotTop.length() != 0 - ? renderedFtlInstructionStackSnapshotTop : null; - } else { - return null; - } - } - } - - private void deleteFTLInstructionStackSnapshotIfNotNeeded() { - if (renderedFtlInstructionStackSnapshot != null && renderedFtlInstructionStackSnapshotTop != null - && (positionsCalculated || blamedExpression != null)) { - ftlInstructionStackSnapshot = null; - } - - } - - private String getDescription() { - synchronized (lock) { - if (description == null && descriptionBuilder != null) { - description = descriptionBuilder.toString( - getFailingInstruction(), - env != null ? env.getShowErrorTips() : true); - descriptionBuilder = null; - } - return description; - } - } - - private TemplateElement getFailingInstruction() { - if (ftlInstructionStackSnapshot != null && ftlInstructionStackSnapshot.length > 0) { - return ftlInstructionStackSnapshot[0]; - } else { - return null; - } - } - - /** - * @return the execution environment in which the exception occurred. - * {@code null} if the exception was deserialized. - */ - public Environment getEnvironment() { - return env; - } - - /** - * Overrides {@link Throwable#printStackTrace(PrintStream)} so that it will include the FTL stack trace. - */ - @Override - public void printStackTrace(PrintStream out) { - printStackTrace(out, true, true, true); - } - - /** - * Overrides {@link Throwable#printStackTrace(PrintWriter)} so that it will include the FTL stack trace. - */ - @Override - public void printStackTrace(PrintWriter out) { - printStackTrace(out, true, true, true); - } - - /** - * @param heading should the heading at the top be printed - * @param ftlStackTrace should the FTL stack trace be printed - * @param javaStackTrace should the Java stack trace be printed - * - * @since 2.3.20 - */ - public void printStackTrace(PrintWriter out, boolean heading, boolean ftlStackTrace, boolean javaStackTrace) { - synchronized (out) { - printStackTrace(new PrintWriterStackTraceWriter(out), heading, ftlStackTrace, javaStackTrace); - } - } - - /** - * @param heading should the heading at the top be printed - * @param ftlStackTrace should the FTL stack trace be printed - * @param javaStackTrace should the Java stack trace be printed - * - * @since 2.3.20 - */ - public void printStackTrace(PrintStream out, boolean heading, boolean ftlStackTrace, boolean javaStackTrace) { - synchronized (out) { - printStackTrace(new PrintStreamStackTraceWriter(out), heading, ftlStackTrace, javaStackTrace); - } - } - - private void printStackTrace(StackTraceWriter out, boolean heading, boolean ftlStackTrace, boolean javaStackTrace) { - synchronized (out) { - if (heading) { - out.println("FreeMarker template error:"); - } - - if (ftlStackTrace) { - String stackTrace = getFTLInstructionStack(); - if (stackTrace != null) { - out.println(getMessageWithoutStackTop()); // Not getMessage()! - out.println(); - out.println(_CoreAPI.ERROR_MESSAGE_HR); - out.println(FTL_INSTRUCTION_STACK_TRACE_TITLE); - out.print(stackTrace); - out.println(_CoreAPI.ERROR_MESSAGE_HR); - } else { - ftlStackTrace = false; - javaStackTrace = true; - } - } - - if (javaStackTrace) { - if (ftlStackTrace) { // We are after an FTL stack trace - out.println(); - out.println("Java stack trace (for programmers):"); - out.println(_CoreAPI.ERROR_MESSAGE_HR); - synchronized (lock) { - if (messageWasAlreadyPrintedForThisTrace == null) { - messageWasAlreadyPrintedForThisTrace = new ThreadLocal(); - } - messageWasAlreadyPrintedForThisTrace.set(Boolean.TRUE); - } - - try { - out.printStandardStackTrace(this); - } finally { - messageWasAlreadyPrintedForThisTrace.set(Boolean.FALSE); - } - } else { // javaStackTrace only - out.printStandardStackTrace(this); - } - - if (getCause() != null) { - // Dirty hack to fight with ServletException class whose getCause() method doesn't work properly: - Throwable causeCause = getCause().getCause(); - if (causeCause == null) { - try { - // Reflection is used to prevent dependency on Servlet classes. - Method m = getCause().getClass().getMethod("getRootCause", CollectionUtils.EMPTY_CLASS_ARRAY); - Throwable rootCause = (Throwable) m.invoke(getCause(), CollectionUtils.EMPTY_OBJECT_ARRAY); - if (rootCause != null) { - out.println("ServletException root cause: "); - out.printStandardStackTrace(rootCause); - } - } catch (Throwable exc) { - ; // ignore - } - } - } - } // if (javaStackTrace) - } - } - - /** - * Prints the stack trace as if wasn't overridden by {@link TemplateException}. - * @since 2.3.20 - */ - public void printStandardStackTrace(PrintStream ps) { - super.printStackTrace(ps); - } - - /** - * Prints the stack trace as if wasn't overridden by {@link TemplateException}. - * @since 2.3.20 - */ - public void printStandardStackTrace(PrintWriter pw) { - super.printStackTrace(pw); - } - - @Override - public String getMessage() { - if (messageWasAlreadyPrintedForThisTrace != null - && messageWasAlreadyPrintedForThisTrace.get() == Boolean.TRUE) { - return "[... Exception message was already printed; see it above ...]"; - } else { - synchronized (lock) { - if (message == null) renderMessages(); - return message; - } - } - } - - /** - * Similar to {@link #getMessage()}, but it doesn't contain the position of the failing instruction at then end - * of the text. It might contains the position of the failing <em>expression</em> though as part of the expression - * quotation, as that's the part of the description. - */ - public String getMessageWithoutStackTop() { - synchronized (lock) { - if (messageWithoutStackTop == null) renderMessages(); - return messageWithoutStackTop; - } - } - - /** - * 1-based line number of the failing section, or {@code null} if the information is not available. - * - * @since 2.3.21 - */ - public Integer getLineNumber() { - synchronized (lock) { - if (!positionsCalculated) { - calculatePosition(); - } - return lineNumber; - } - } - - /** - * Returns the name ({@link Template#getName()}) of the template where the error has occurred, or {@code null} if - * the information isn't available. This shouldn't be used for showing the error position; use - * {@link #getTemplateSourceName()} instead. - * - * @deprecated Use {@link #getTemplateSourceName()} instead, unless you are really sure that this is what you want. - * This method isn't really deprecated, it's just marked so to warn users about this. - * - * @since 2.3.21 - */ - @Deprecated - public String getTemplateName() { - synchronized (lock) { - if (!positionsCalculated) { - calculatePosition(); - } - return templateName; - } - } - - /** - * Returns the source name ({@link Template#getSourceName()}) of the template where the error has occurred, or - * {@code null} if the information isn't available. This is what should be used for showing the error position. - * - * @since 2.3.22 - */ - public String getTemplateSourceName() { - synchronized (lock) { - if (!positionsCalculated) { - calculatePosition(); - } - return templateSourceName; - } - } - - /** - * 1-based column number of the failing section, or {@code null} if the information is not available. - * - * @since 2.3.21 - */ - public Integer getColumnNumber() { - synchronized (lock) { - if (!positionsCalculated) { - calculatePosition(); - } - return columnNumber; - } - } - - /** - * 1-based line number of the last line that contains the failing section, or {@code null} if the information is not - * available. - * - * @since 2.3.21 - */ - public Integer getEndLineNumber() { - synchronized (lock) { - if (!positionsCalculated) { - calculatePosition(); - } - return endLineNumber; - } - } - - /** - * 1-based column number of the last character of the failing template section, or {@code null} if the information - * is not available. Note that unlike with Java string API-s, this column number is inclusive. - * - * @since 2.3.21 - */ - public Integer getEndColumnNumber() { - synchronized (lock) { - if (!positionsCalculated) { - calculatePosition(); - } - return endColumnNumber; - } - } - - /** - * If there was a blamed expression attached to this exception, it returns its canonical form, otherwise it returns - * {@code null}. This expression should always be inside the failing FTL instruction. - * - * <p>The typical application of this is getting the undefined expression from {@link InvalidReferenceException}-s. - * - * @since 2.3.21 - */ - public String getBlamedExpressionString() { - synchronized (lock) { - if (!blamedExpressionStringCalculated) { - if (blamedExpression != null) { - blamedExpressionString = blamedExpression.getCanonicalForm(); - } - blamedExpressionStringCalculated = true; - } - return blamedExpressionString; - } - } - - Expression getBlamedExpression() { - return blamedExpression; - } - - private void writeObject(ObjectOutputStream out) throws IOException, ClassNotFoundException { - // These are calculated from transient fields, so this is the last chance to calculate them: - getFTLInstructionStack(); - getFTLInstructionStackTopFew(); - getDescription(); - calculatePosition(); - getBlamedExpressionString(); - - out.defaultWriteObject(); - } - - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { - lock = new Object(); - in.defaultReadObject(); - } - - /** Delegate to a {@link PrintWriter} or to a {@link PrintStream}. */ - private interface StackTraceWriter { - void print(Object obj); - void println(Object obj); - void println(); - void printStandardStackTrace(Throwable exception); - } - - private static class PrintStreamStackTraceWriter implements StackTraceWriter { - - private final PrintStream out; - - PrintStreamStackTraceWriter(PrintStream out) { - this.out = out; - } - - public void print(Object obj) { - out.print(obj); - } - - public void println(Object obj) { - out.println(obj); - } - - public void println() { - out.println(); - } - - public void printStandardStackTrace(Throwable exception) { - if (exception instanceof TemplateException) { - ((TemplateException) exception).printStandardStackTrace(out); - } else { - exception.printStackTrace(out); - } - } - - } - - private static class PrintWriterStackTraceWriter implements StackTraceWriter { - - private final PrintWriter out; - - PrintWriterStackTraceWriter(PrintWriter out) { - this.out = out; - } - - public void print(Object obj) { - out.print(obj); - } - - public void println(Object obj) { - out.println(obj); - } - - public void println() { - out.println(); - } - - public void printStandardStackTrace(Throwable exception) { - if (exception instanceof TemplateException) { - ((TemplateException) exception).printStandardStackTrace(out); - } else { - exception.printStackTrace(out); - } - } - - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateExceptionHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateExceptionHandler.java b/src/main/java/freemarker/template/TemplateExceptionHandler.java deleted file mode 100644 index 6fb113e..0000000 --- a/src/main/java/freemarker/template/TemplateExceptionHandler.java +++ /dev/null @@ -1,155 +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.template; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.Writer; - -import freemarker.core.Configurable; -import freemarker.core.Environment; -import freemarker.core.StopException; -import freemarker.template.utility.StringUtil; - -/** - * Used for the {@code template_exception_handler} configuration setting; - * see {@link Configurable#setTemplateExceptionHandler(TemplateExceptionHandler)} for more. - */ -public interface TemplateExceptionHandler { - - /** - * Method called after a {@link TemplateException} was raised inside a template. The exception should be re-thrown - * unless you want to suppress the exception. - * - * <p>Note that you can check with {@link Environment#isInAttemptBlock()} if you are inside a {@code #attempt} - * block, which then will handle handle this exception and roll back the output generated inside it. - * - * <p>Note that {@link StopException}-s (raised by {@code #stop}) won't be captured. - * - * <p>Note that you shouldn't log the exception in this method unless you suppress it. If there's a concern that the - * exception might won't be logged after it bubbles up from {@link Template#process(Object, Writer)}, simply - * ensure that {@link Configuration#getLogTemplateExceptions()} is {@code true}. - * - * @param te The exception that occurred; don't forget to re-throw it unless you want to suppress it - * @param env The runtime environment of the template - * @param out This is where the output of the template is written - */ - void handleTemplateException(TemplateException te, Environment env, Writer out) throws TemplateException; - - /** - * {@link TemplateExceptionHandler} that simply skips the failing instructions, letting the template continue - * executing. It does nothing to handle the event. Note that the exception is still logged, as with all - * other {@link TemplateExceptionHandler}-s. - */ - TemplateExceptionHandler IGNORE_HANDLER = new TemplateExceptionHandler() { - public void handleTemplateException(TemplateException te, Environment env, Writer out) { - // Do nothing - } - }; - - /** - * {@link TemplateExceptionHandler} that simply re-throws the exception; this should be used in most production - * systems. - */ - TemplateExceptionHandler RETHROW_HANDLER = new TemplateExceptionHandler() { - public void handleTemplateException(TemplateException te, Environment env, Writer out) - throws TemplateException { - throw te; - } - }; - - /** - * {@link TemplateExceptionHandler} useful when you developing non-HTML templates. This handler - * outputs the stack trace information to the client and then re-throws the exception. - */ - TemplateExceptionHandler DEBUG_HANDLER = new TemplateExceptionHandler() { - public void handleTemplateException(TemplateException te, Environment env, Writer out) - throws TemplateException { - if (!env.isInAttemptBlock()) { - PrintWriter pw = (out instanceof PrintWriter) ? (PrintWriter) out : new PrintWriter(out); - pw.print("FreeMarker template error (DEBUG mode; use RETHROW in production!):\n"); - te.printStackTrace(pw, false, true, true); - - pw.flush(); // To commit the HTTP response - } - throw te; - } - }; - - /** - * {@link TemplateExceptionHandler} useful when you developing HTML templates. This handler - * outputs the stack trace information to the client, formatting it so that it will be usually well readable - * in the browser, and then re-throws the exception. - */ - TemplateExceptionHandler HTML_DEBUG_HANDLER = new TemplateExceptionHandler() { - public void handleTemplateException(TemplateException te, Environment env, Writer out) - throws TemplateException { - if (!env.isInAttemptBlock()) { - boolean externalPw = out instanceof PrintWriter; - PrintWriter pw = externalPw ? (PrintWriter) out : new PrintWriter(out); - try { - pw.print("<!-- FREEMARKER ERROR MESSAGE STARTS HERE -->" - + "<!-- ]]> -->" - + "<script language=javascript>//\"></script>" - + "<script language=javascript>//'></script>" - + "<script language=javascript>//\"></script>" - + "<script language=javascript>//'></script>" - + "</title></xmp></script></noscript></style></object>" - + "</head></pre></table>" - + "</form></table></table></table></a></u></i></b>" - + "<div align='left' " - + "style='background-color:#FFFF7C; " - + "display:block; border-top:double; padding:4px; margin:0; " - + "font-family:Arial,sans-serif; "); - pw.print(FONT_RESET_CSS); - pw.print("'>" - + "<b style='font-size:12px; font-style:normal; font-weight:bold; " - + "text-decoration:none; text-transform: none;'>FreeMarker template error " - + " (HTML_DEBUG mode; use RETHROW in production!)</b>" - + "<pre style='display:block; background: none; border: 0; margin:0; padding: 0;" - + "font-family:monospace; "); - pw.print(FONT_RESET_CSS); - pw.println("; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; " - + "white-space: -o-pre-wrap; word-wrap: break-word;'>"); - - StringWriter stackTraceSW = new StringWriter(); - PrintWriter stackPW = new PrintWriter(stackTraceSW); - te.printStackTrace(stackPW, false, true, true); - stackPW.close(); - pw.println(); - pw.println(StringUtil.XMLEncNQG(stackTraceSW.toString())); - - pw.println("</pre></div></html>"); - pw.flush(); // To commit the HTTP response - } finally { - if (!externalPw) pw.close(); - } - } // if (!env.isInAttemptBlock()) - - throw te; - } - - private static final String FONT_RESET_CSS = - "color:#A80000; font-size:12px; font-style:normal; font-variant:normal; " - + "font-weight:normal; text-decoration:none; text-transform: none"; - - }; - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateHashModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateHashModel.java b/src/main/java/freemarker/template/TemplateHashModel.java deleted file mode 100644 index 4a2997d..0000000 --- a/src/main/java/freemarker/template/TemplateHashModel.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 freemarker.template; - -/** - * "hash" template language data type: an object that contains other objects accessible through string keys - * (sub-variable names). - * - * <p>In templates they are used like {@code myHash.myKey} or {@code myHash[myDynamicKey]}. - */ -public interface TemplateHashModel extends TemplateModel { - - /** - * Gets a <tt>TemplateModel</tt> from the hash. - * - * @param key the name by which the <tt>TemplateModel</tt> - * is identified in the template. - * @return the <tt>TemplateModel</tt> referred to by the key, - * or null if not found. - */ - TemplateModel get(String key) throws TemplateModelException; - - boolean isEmpty() throws TemplateModelException; -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateHashModelEx.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateHashModelEx.java b/src/main/java/freemarker/template/TemplateHashModelEx.java deleted file mode 100644 index 91bde39..0000000 --- a/src/main/java/freemarker/template/TemplateHashModelEx.java +++ /dev/null @@ -1,49 +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.template; - -/** - * "extended hash" template language data type; extends {@link TemplateHashModel} by allowing - * iterating through its keys and values. - * - * <p>In templates they are used like hashes, but these will also work (among others): - * {@code myExtHash?size}, {@code myExtHash?keys}, {@code myExtHash?values}. - * @see SimpleHash - */ -public interface TemplateHashModelEx extends TemplateHashModel { - - /** - * @return the number of key/value mappings in the hash. - */ - int size() throws TemplateModelException; - - /** - * @return a collection containing the keys in the hash. Every element of - * the returned collection must implement the {@link TemplateScalarModel} - * (as the keys of hashes are always strings). - */ - TemplateCollectionModel keys() throws TemplateModelException; - - /** - * @return a collection containing the values in the hash. The elements of the - * returned collection can be any kind of {@link TemplateModel}-s. - */ - TemplateCollectionModel values() throws TemplateModelException; -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateHashModelEx2.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateHashModelEx2.java b/src/main/java/freemarker/template/TemplateHashModelEx2.java deleted file mode 100644 index d5b83a7..0000000 --- a/src/main/java/freemarker/template/TemplateHashModelEx2.java +++ /dev/null @@ -1,80 +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.template; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -/** - * Adds key-value pair listing capability to {@link TemplateHashModelEx}. While in many cases that can also be achieved - * with {@link #keys()} and then {@link #get(String)}, that has some problems. One is that {@link #get(String)} only - * accepts string keys, while {@link #keys()} can return non-string keys too. The other is that calling {@link #keys()} - * and then {@link #get(String)} for each key can be slower than listing the key-value pairs in one go. - * - * @since 2.3.25 - */ -public interface TemplateHashModelEx2 extends TemplateHashModelEx { - - /** - * @return The iterator that walks through the key-value pairs in the hash. Not {@code null}. - */ - KeyValuePairIterator keyValuePairIterator() throws TemplateModelException; - - /** - * A key-value pair in a hash; used for {@link KeyValuePairIterator}. - * - * @since 2.3.25 - */ - interface KeyValuePair { - - /** - * @return Any type of {@link TemplateModel}, maybe {@code null} (if the hash entry key is {@code null}). - */ - TemplateModel getKey() throws TemplateModelException; - - /** - * @return Any type of {@link TemplateModel}, maybe {@code null} (if the hash entry value is {@code null}). - */ - TemplateModel getValue() throws TemplateModelException; - } - - /** - * Iterates over the key-value pairs in a hash. This is very similar to an {@link Iterator}, but has a fixed item - * type, can throw {@link TemplateModelException}-s, and has no {@code remove()} method. - * - * @since 2.3.25 - */ - interface KeyValuePairIterator { - - /** - * Similar to {@link Iterator#hasNext()}. - */ - boolean hasNext() throws TemplateModelException; - - /** - * Similar to {@link Iterator#next()}. - * - * @return Not {@code null} - * - * @throws NoSuchElementException - */ - KeyValuePair next() throws TemplateModelException; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateMethodModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateMethodModel.java b/src/main/java/freemarker/template/TemplateMethodModel.java deleted file mode 100644 index 951b7e9..0000000 --- a/src/main/java/freemarker/template/TemplateMethodModel.java +++ /dev/null @@ -1,60 +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. - */ - -/* - * 22 October 1999: This class added by Holger Arendt. - */ - -package freemarker.template; - -import java.util.List; - -import freemarker.core.Environment; - -/** - * "method" template language data type: Objects that act like functions. The name comes from that their original - * application was calling Java methods via {@link freemarker.ext.beans.BeansWrapper}. - * - * <p>In templates they are used like {@code myMethod("foo", "bar")} or {@code myJavaObject.myJavaMethod("foo", "bar")}. - * - * @deprecated Use {@link TemplateMethodModelEx} instead. This interface is from the old times when the only kind of - * value you could pass in was string. - */ -@Deprecated -public interface TemplateMethodModel extends TemplateModel { - - /** - * Executes the method call. All arguments passed to the method call are - * coerced to strings before being passed, if the FreeMarker rules allow - * the coercion. If some of the passed arguments can not be coerced to a - * string, an exception will be raised in the engine and the method will - * not be called. If your method would like to act on actual data model - * objects instead of on their string representations, implement the - * {@link TemplateMethodModelEx} instead. - * - * @param arguments a <tt>List</tt> of <tt>String</tt> objects - * containing the values of the arguments passed to the method. - * - * @return the return value of the method, or {@code null}. If the returned value - * does not implement {@link TemplateModel}, it will be automatically - * wrapped using the {@link Environment#getObjectWrapper() environment - * object wrapper}. - */ - public Object exec(List arguments) throws TemplateModelException; -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateMethodModelEx.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateMethodModelEx.java b/src/main/java/freemarker/template/TemplateMethodModelEx.java deleted file mode 100644 index 54e2d45..0000000 --- a/src/main/java/freemarker/template/TemplateMethodModelEx.java +++ /dev/null @@ -1,53 +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.template; - -import java.util.List; - -import freemarker.core.Environment; -import freemarker.template.utility.DeepUnwrap; - -/** - * "extended method" template language data type: Objects that act like functions. Their main application is calling - * Java methods via {@link freemarker.ext.beans.BeansWrapper}, but you can implement this interface to create - * top-level functions too. They are "extended" compared to the deprecated {@link TemplateMethodModel}, which could only - * accept string parameters. - * - * <p>In templates they are used like {@code myMethod(1, "foo")} or {@code myJavaObject.myJavaMethod(1, "foo")}. - */ -public interface TemplateMethodModelEx extends TemplateMethodModel { - - /** - * Executes the method call. - * - * @param arguments a {@link List} of {@link TemplateModel}-s, - * containing the arguments passed to the method. If the implementation absolutely wants - * to operate on POJOs, it can use the static utility methods in the {@link DeepUnwrap} - * class to easily obtain them. However, unwrapping is not always possible (or not perfectly), and isn't always - * efficient, so it's recommended to use the original {@link TemplateModel} value as much as possible. - * - * @return the return value of the method, or {@code null}. If the returned value - * does not implement {@link TemplateModel}, it will be automatically - * wrapped using the {@link Environment#getObjectWrapper() environment's - * object wrapper}. - */ - public Object exec(List arguments) throws TemplateModelException; - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateModel.java b/src/main/java/freemarker/template/TemplateModel.java deleted file mode 100644 index 453d97e..0000000 --- a/src/main/java/freemarker/template/TemplateModel.java +++ /dev/null @@ -1,54 +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.template; - -import freemarker.template.utility.ClassUtil; - -/** - * The common super-interface of the interfaces that stand for the FreeMarker Template Language (FTL) data types. - * The template language only deals with {@link TemplateModel}-s, not directly with plain Java objects. (For example, - * it doesn't understand {@link java.lang.Number}, but {@link TemplateNumberModel}.) This is why the - * data-model (aka. the "template context" in other languages) is (automatically) mapped to a tree of - * {@link TemplateModel}-s. - * - * <p>Mapping the plain Java objects to {@link TemplateModel}-s (or the other way around sometimes) is the - * responsibility of the {@link ObjectWrapper} (can be set via {@link Configuration#setObjectWrapper(ObjectWrapper)}). - * But not all {@link TemplateModel}-s are for wrapping a plain object. For example, a value created within a template - * is not made to wrap an earlier existing object; it's a value that has always existed in the template language's - * domain. Users can also write {@link TemplateModel} implementations and put them directly into the data-model for - * full control over how that object is seen from the template. Certain {@link TemplateModel} interfaces doesn't - * even have equivalent in Java. For example the directive type ({@link TemplateDirectiveModel}) is like that. - * - * <p>Because {@link TemplateModel} "subclasses" are all interfaces, a value in the template language can have multiple - * types. However, to prevent ambiguous situations, it's not recommended to make values that implement more than one of - * these types: string, number, boolean, date. The intended applications are like string+hash, string+method, - * hash+sequence, etc. - * - * @see ClassUtil#getFTLTypeDescription(TemplateModel) - */ -public interface TemplateModel { - - /** - * A general-purpose object to represent nothing. It acts as - * an empty string, false, empty sequence, empty hash, and - * null-returning method model. - */ - TemplateModel NOTHING = GeneralPurposeNothing.getInstance(); -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateModelAdapter.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateModelAdapter.java b/src/main/java/freemarker/template/TemplateModelAdapter.java deleted file mode 100644 index 67adfeb..0000000 --- a/src/main/java/freemarker/template/TemplateModelAdapter.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 freemarker.template; - -/** - * Implemented by classes that serve as adapters for template model objects in - * some other object model. Actually a functional inverse of - * {@link AdapterTemplateModel}. You will rarely implement this interface - * directly. It is usually implemented by unwrapping adapter classes of various - * object wrapper implementations. - */ -public interface TemplateModelAdapter { - /** - * @return the template model this object is wrapping. - */ - public TemplateModel getTemplateModel(); -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateModelException.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateModelException.java b/src/main/java/freemarker/template/TemplateModelException.java deleted file mode 100644 index cac23be..0000000 --- a/src/main/java/freemarker/template/TemplateModelException.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 freemarker.template; - -import freemarker.core.Environment; -import freemarker.core._ErrorDescriptionBuilder; - -/** - * {@link TemplateModel} methods throw this exception if the requested data can't be retrieved. - */ -public class TemplateModelException extends TemplateException { - - /** - * Constructs a <tt>TemplateModelException</tt> with no - * specified detail message. - */ - public TemplateModelException() { - this((String) null, null); - } - - /** - * Constructs a <tt>TemplateModelException</tt> with the - * specified detail message. - * - * @param description the detail message. - */ - public TemplateModelException(String description) { - this(description, null); - } - - /** - * The same as {@link #TemplateModelException(Throwable)}; it's exists only for binary - * backward-compatibility. - */ - public TemplateModelException(Exception cause) { - this((String) null, cause); - } - - /** - * Constructs a <tt>TemplateModelException</tt> with the given underlying - * Exception, but no detail message. - * - * @param cause the underlying {@link Exception} that caused this - * exception to be raised - */ - public TemplateModelException(Throwable cause) { - this((String) null, cause); - } - - - /** - * The same as {@link #TemplateModelException(String, Throwable)}; it's exists only for binary - * backward-compatibility. - */ - public TemplateModelException(String description, Exception cause) { - super(description, cause, null); - } - - /** - * Constructs a TemplateModelException with both a description of the error - * that occurred and the underlying Exception that caused this exception - * to be raised. - * - * @param description the description of the error that occurred - * @param cause the underlying {@link Exception} that caused this - * exception to be raised - */ - public TemplateModelException(String description, Throwable cause) { - super(description, cause, null); - } - - /** - * Don't use this; this is to be used internally by FreeMarker. - * @param preventAmbiguity its value is ignored; it's only to prevent constructor selection ambiguities for - * backward-compatibility - */ - protected TemplateModelException(Throwable cause, Environment env, String description, - boolean preventAmbiguity) { - super(description, cause, env); - } - - /** - * Don't use this; this is to be used internally by FreeMarker. - * @param preventAmbiguity its value is ignored; it's only to prevent constructor selection ambiguities for - * backward-compatibility - */ - protected TemplateModelException( - Throwable cause, Environment env, _ErrorDescriptionBuilder descriptionBuilder, - boolean preventAmbiguity) { - super(cause, env, null, descriptionBuilder); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateModelIterator.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateModelIterator.java b/src/main/java/freemarker/template/TemplateModelIterator.java deleted file mode 100644 index c5965a7..0000000 --- a/src/main/java/freemarker/template/TemplateModelIterator.java +++ /dev/null @@ -1,39 +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.template; - -/** - * Used to iterate over a set of template models <em>once</em>; usually returned from - * {@link TemplateCollectionModel#iterator()}. Note that it's not a {@link TemplateModel}. - */ -public interface TemplateModelIterator { - - /** - * Returns the next model. - * @throws TemplateModelException if the next model can not be retrieved - * (i.e. because the iterator is exhausted). - */ - TemplateModel next() throws TemplateModelException; - - /** - * @return whether there are any more items to iterate over. - */ - boolean hasNext() throws TemplateModelException; -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateModelListSequence.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateModelListSequence.java b/src/main/java/freemarker/template/TemplateModelListSequence.java deleted file mode 100644 index d3bb7ca..0000000 --- a/src/main/java/freemarker/template/TemplateModelListSequence.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.template; - -import java.util.List; - -/** - * A sequence that wraps a {@link List} of {@link TemplateModel}-s. It does not copy the original - * list. It's mostly useful when implementing {@link TemplateMethodModelEx}-es that collect items from other - * {@link TemplateModel}-s. - */ -public class TemplateModelListSequence implements TemplateSequenceModel { - - private List/*<TemplateModel>*/ list; - - public TemplateModelListSequence(List list) { - this.list = list; - } - - public TemplateModel get(int index) { - return (TemplateModel) list.get(index); - } - - public int size() { - return list.size(); - } - - /** - * Returns the original {@link List} of {@link TemplateModel}-s, so it's not a fully unwrapped value. - */ - public Object getWrappedObject() { - return list; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateModelWithAPISupport.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateModelWithAPISupport.java b/src/main/java/freemarker/template/TemplateModelWithAPISupport.java deleted file mode 100644 index 00a4e6f..0000000 --- a/src/main/java/freemarker/template/TemplateModelWithAPISupport.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 freemarker.template; - -import freemarker.template.utility.ObjectWrapperWithAPISupport; - -/** - * <b>Experimental - subject to change:</b> A {@link TemplateModel} on which the {@code ?api} operation can be applied. - * - * <p> - * <b>Experimental status warning:</b> This interface is subject to change on non-backward compatible ways, hence, it - * shouldn't be implemented outside FreeMarker yet. - * - * @since 2.3.22 - */ -public interface TemplateModelWithAPISupport extends TemplateModel { - - /** - * Returns the model that exposes the (Java) API of the value. This is usually implemented by delegating to - * {@link ObjectWrapperWithAPISupport#wrapAsAPI(Object)}. - */ - TemplateModel getAPI() throws TemplateModelException; - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateNodeModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateNodeModel.java b/src/main/java/freemarker/template/TemplateNodeModel.java deleted file mode 100644 index c54b42c..0000000 --- a/src/main/java/freemarker/template/TemplateNodeModel.java +++ /dev/null @@ -1,78 +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.template; - -/** - * "node" template language data type: an object that is a node in a tree. - * A tree of nodes can be recursively <em>visited</em> using the <#visit...> and <#recurse...> - * directives. This API is largely based on the W3C Document Object Model - * (DOM) API. However, it's meant to be generally useful for describing - * any tree of objects that you wish to navigate using a recursive visitor - * design pattern (or simply through being able to get the parent - * and child nodes). - * - * <p>See the <a href="http://freemarker.org/docs/xgui.html" target="_blank">XML - * Processing Guide</a> for a concrete application. - * - * @since FreeMarker 2.3 - */ -public interface TemplateNodeModel extends TemplateModel { - - /** - * @return the parent of this node or null, in which case - * this node is the root of the tree. - */ - TemplateNodeModel getParentNode() throws TemplateModelException; - - /** - * @return a sequence containing this node's children. - * If the returned value is null or empty, this is essentially - * a leaf node. - */ - TemplateSequenceModel getChildNodes() throws TemplateModelException; - - /** - * @return a String that is used to determine the processing - * routine to use. In the XML implementation, if the node - * is an element, it returns the element's tag name. If it - * is an attribute, it returns the attribute's name. It - * returns "@text" for text nodes, "@pi" for processing instructions, - * and so on. - */ - String getNodeName() throws TemplateModelException; - - /** - * @return a String describing the <em>type</em> of node this is. - * In the W3C DOM, this should be "element", "text", "attribute", etc. - * A TemplateNodeModel implementation that models other kinds of - * trees could return whatever it appropriate for that application. It - * can be null, if you don't want to use node-types. - */ - String getNodeType() throws TemplateModelException; - - - /** - * @return the XML namespace URI with which this node is - * associated. If this TemplateNodeModel implementation is - * not XML-related, it will almost certainly be null. Even - * for XML nodes, this will often be null. - */ - String getNodeNamespace() throws TemplateModelException; -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateNodeModelEx.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateNodeModelEx.java b/src/main/java/freemarker/template/TemplateNodeModelEx.java deleted file mode 100644 index ca7d21d..0000000 --- a/src/main/java/freemarker/template/TemplateNodeModelEx.java +++ /dev/null @@ -1,40 +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.template; - -import freemarker.ext.dom.NodeModel; - -/** - * A {@link NodeModel} that supports navigating to the previous and next sibling nodes. - * - * @since 2.3.26 - */ -public interface TemplateNodeModelEx extends TemplateNodeModel { - - /** - * @return The immediate previous sibling of this node, or {@code null} if there's no such node. - */ - TemplateNodeModelEx getPreviousSibling() throws TemplateModelException; - - /** - * @return The immediate next sibling of this node, or {@code null} if there's no such node. - */ - TemplateNodeModelEx getNextSibling() throws TemplateModelException; -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateNotFoundException.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateNotFoundException.java b/src/main/java/freemarker/template/TemplateNotFoundException.java deleted file mode 100644 index 0a8b878..0000000 --- a/src/main/java/freemarker/template/TemplateNotFoundException.java +++ /dev/null @@ -1,61 +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.template; - -import java.io.FileNotFoundException; - -/** - * Thrown when {@link Configuration#getTemplate(String)} (or similar) doesn't find a template. - * This extends {@link FileNotFoundException} for backward compatibility, but in fact has nothing to do with files, as - * FreeMarker can load templates from many other sources. - * - * @since 2.3.22 - * - * @see MalformedTemplateNameException - * @see Configuration#getTemplate(String) - */ -public final class TemplateNotFoundException extends FileNotFoundException { - - private final String templateName; - private final Object customLookupCondition; - - public TemplateNotFoundException(String templateName, Object customLookupCondition, String message) { - super(message); - this.templateName = templateName; - this.customLookupCondition = customLookupCondition; - } - - /** - * The name (path) of the template that wasn't found. - */ - public String getTemplateName() { - return templateName; - } - - /** - * The custom lookup condition with which the template was requested, or {@code null} if there's no such condition. - * See the {@code customLookupCondition} parameter of - * {@link Configuration#getTemplate(String, java.util.Locale, Object, String, boolean, boolean)}. - */ - public Object getCustomLookupCondition() { - return customLookupCondition; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateNumberModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateNumberModel.java b/src/main/java/freemarker/template/TemplateNumberModel.java deleted file mode 100644 index 9b1b401..0000000 --- a/src/main/java/freemarker/template/TemplateNumberModel.java +++ /dev/null @@ -1,42 +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.template; - -import freemarker.core.ArithmeticEngine; - -/** - * "number" template language data type; an object that stores a number. There's only one numerical type as far as the - * template language is concerned, but it can store its value using whatever Java number type. Making operations between - * numbers (and so the coercion rules) is up to the {@link ArithmeticEngine}. - * - * <p> - * Objects of this type should be immutable, that is, calling {@link #getAsNumber()} should always return the same value - * as for the first time. - */ -public interface TemplateNumberModel extends TemplateModel { - - /** - * Returns the numeric value. The return value must not be {@code null}. - * - * @return the {@link Number} instance associated with this number model. - */ - public Number getAsNumber() throws TemplateModelException; - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateScalarModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateScalarModel.java b/src/main/java/freemarker/template/TemplateScalarModel.java deleted file mode 100644 index 3496f89..0000000 --- a/src/main/java/freemarker/template/TemplateScalarModel.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 freemarker.template; - -/** - * "string" template language data-type; like in Java, an unmodifiable UNICODE character sequence. - * (The name of this interface should be {@code TemplateStringModel}. The misnomer is inherited from the - * old times, when this was the only single-value type in FreeMarker.) - */ -public interface TemplateScalarModel extends TemplateModel { - - /** - * A constant value to use as the empty string. - */ - public TemplateModel EMPTY_STRING = new SimpleScalar(""); - - /** - * Returns the string representation of this model. Don't return {@code null}, as that will cause exception. - * - * <p> - * Objects of this type should be immutable, that is, calling {@link #getAsString()} should always return the same - * value as for the first time. - */ - public String getAsString() throws TemplateModelException; - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateSequenceModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateSequenceModel.java b/src/main/java/freemarker/template/TemplateSequenceModel.java deleted file mode 100644 index 12d4acb..0000000 --- a/src/main/java/freemarker/template/TemplateSequenceModel.java +++ /dev/null @@ -1,48 +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.template; - -/** - * "sequence" template language data type; an object that contains other objects accessible through an integer 0-based - * index. - * - * <p> - * Used in templates like: {@code mySeq[index]}, {@code <#list mySeq as i>...</#list>}, {@code mySeq?size}, etc. - * - * @see TemplateCollectionModel - */ -public interface TemplateSequenceModel extends TemplateModel { - - /** - * Retrieves the i-th template model in this sequence. - * - * @return the item at the specified index, or <code>null</code> if the index is out of bounds. Note that a - * <code>null</code> value is interpreted by FreeMarker as "variable does not exist", and accessing a - * missing variables is usually considered as an error in the FreeMarker Template Language, so the usage of - * a bad index will not remain hidden, unless the default value for that case was also specified in the - * template. - */ - TemplateModel get(int index) throws TemplateModelException; - - /** - * @return the number of items in the list. - */ - int size() throws TemplateModelException; -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TemplateTransformModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TemplateTransformModel.java b/src/main/java/freemarker/template/TemplateTransformModel.java deleted file mode 100644 index 636fd1e..0000000 --- a/src/main/java/freemarker/template/TemplateTransformModel.java +++ /dev/null @@ -1,54 +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.template; - -import java.io.IOException; -import java.io.Writer; -import java.util.Map; - -import freemarker.template.utility.DeepUnwrap; - -/** - * "transform" template language data type: user-defined directives - * (much like macros) specialized on filtering output; you should rather use the newer {@link TemplateDirectiveModel} - * instead. This certainly will be deprecated in FreeMarker 2.4. - */ -public interface TemplateTransformModel extends TemplateModel { - - /** - * Returns a writer that will be used by the engine to feed the - * transformation input to the transform. Each call to this method - * must return a new instance of the writer so that the transformation - * is thread-safe. - * @param out the character stream to which to write the transformed output - * @param args the arguments (if any) passed to the transformation as a - * map of key/value pairs where the keys are strings and the arguments are - * TemplateModel instances. This is never null. If you need to convert the - * template models to POJOs, you can use the utility methods in the - * {@link DeepUnwrap} class. - * @return a writer to which the engine will feed the transformation - * input, or null if the transform does not support nested content (body). - * The returned writer can implement the {@link TransformControl} - * interface if it needs advanced control over the evaluation of the - * transformation body. - */ - Writer getWriter(Writer out, Map args) - throws TemplateModelException, IOException; -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TransformControl.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TransformControl.java b/src/main/java/freemarker/template/TransformControl.java deleted file mode 100644 index eedbd2b..0000000 --- a/src/main/java/freemarker/template/TransformControl.java +++ /dev/null @@ -1,99 +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.template; - -import java.io.IOException; - -/** - * An interface that can be implemented by writers returned from - * {@link TemplateTransformModel#getWriter(java.io.Writer, java.util.Map)}. The - * methods on this - * interfaces are callbacks that will be called by the template engine and that - * give the writer a chance to better control the evaluation of the transform - * body. The writer can instruct the engine to skip or to repeat body - * evaluation, and gets notified about exceptions that are thrown during the - * body evaluation. - */ -public interface TransformControl { - /** - * Constant returned from {@link #afterBody()} that tells the - * template engine to repeat transform body evaluation and feed - * it again to the transform. - */ - public static final int REPEAT_EVALUATION = 0; - - /** - * Constant returned from {@link #afterBody()} that tells the - * template engine to end the transform and close the writer. - */ - public static final int END_EVALUATION = 1; - - /** - * Constant returned from {@link #onStart()} that tells the - * template engine to skip evaluation of the body. - */ - public static final int SKIP_BODY = 0; - - /** - * Constant returned from {@link #onStart()} that tells the - * template engine to evaluate the body. - */ - public static final int EVALUATE_BODY = 1; - - /** - * Called before the body is evaluated for the first time. - * @return - * <ul> - * <li><tt>SKIP_BODY</tt> if the transform wants to ignore the body. In this - * case, only {@link java.io.Writer#close()} is called next and processing ends.</li> - * <li><tt>EVALUATE_BODY</tt> to normally evaluate the body of the transform - * and feed it to the writer</li> - * </ul> - */ - public int onStart() throws TemplateModelException, IOException; - - /** - * Called after the body has been evaluated. - * @return - * <ul> - * <li><tt>END_EVALUATION</tt> if the transformation should be ended.</li> - * <li><tt>REPEAT_EVALUATION</tt> to have the engine re-evaluate the - * transform body and feed it again to the writer.</li> - * </ul> - */ - public int afterBody() throws TemplateModelException, IOException; - - /** - * Called if any exception occurs during the transform between the - * {@link TemplateTransformModel#getWriter(java.io.Writer, java.util.Map)} call - * and the {@link java.io.Writer#close()} call. - * @param t the throwable that represents the exception. It can be any - * non-checked throwable, as well as {@link TemplateException} and - * {@link java.io.IOException}. - * - * @throws Throwable is recommended that the methods rethrow the received - * throwable. If the method wants to throw another throwable, it should - * either throw a non-checked throwable, or an instance of - * {@link TemplateException} and {@link java.io.IOException}. Throwing any - * other checked exception will cause the engine to rethrow it as - * a {@link java.lang.reflect.UndeclaredThrowableException}. - */ - public void onError(Throwable t) throws Throwable; -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/template/TrueTemplateBooleanModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/TrueTemplateBooleanModel.java b/src/main/java/freemarker/template/TrueTemplateBooleanModel.java deleted file mode 100644 index 0d97dc6..0000000 --- a/src/main/java/freemarker/template/TrueTemplateBooleanModel.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 freemarker.template; - -/** - * Used for the {@link TemplateBooleanModel#FALSE} singleton. - */ -final class TrueTemplateBooleanModel implements SerializableTemplateBooleanModel { - - public boolean getAsBoolean() { - return true; - } - - private Object readResolve() { - return TRUE; - } - -} \ No newline at end of file
