Java Code Examples for org.apache.velocity.exception.MethodInvocationException#getReferenceName()

The following examples show how to use org.apache.velocity.exception.MethodInvocationException#getReferenceName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VelocityView.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Merge the template with the context.
 * Can be overridden to customize the behavior.
 * @param template the template to merge
 * @param context the Velocity context to use for rendering
 * @param response servlet response (use this to get the OutputStream or Writer)
 * @throws Exception if thrown by Velocity
 * @see org.apache.velocity.Template#merge
 */
protected void mergeTemplate(
		Template template, Context context, HttpServletResponse response) throws Exception {

	try {
		template.merge(context, response.getWriter());
	}
	catch (MethodInvocationException ex) {
		Throwable cause = ex.getWrappedThrowable();
		throw new NestedServletException(
				"Method invocation failed during rendering of Velocity view with name '" +
				getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName() +
				"], method '" + ex.getMethodName() + "'",
				cause==null ? ex : cause);
	}
}
 
Example 2
Source File: VelocityView.java    From scoold with Apache License 2.0 6 votes vote down vote up
/**
 * Merge the template with the context. Can be overridden to customize the behavior.
 *
 * @param template the template to merge
 * @param context the Velocity context to use for rendering
 * @param response servlet response (use this to get the OutputStream or Writer)
 * @throws Exception if thrown by Velocity
 * @see org.apache.velocity.Template#merge
 */
protected void mergeTemplate(
		Template template, Context context, HttpServletResponse response) throws Exception {

	try {
		response.setCharacterEncoding(Config.DEFAULT_ENCODING);
		template.merge(context, response.getWriter());
	} catch (MethodInvocationException ex) {
		Throwable cause = ex.getCause();
		throw new NestedServletException(
				"Method invocation failed during rendering of Velocity view with name '"
				+ getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName()
				+ "], method '" + ex.getMethodName() + "'",
				cause == null ? ex : cause);
	}
}
 
Example 3
Source File: VelocityView.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Merge the template with the context.
 * Can be overridden to customize the behavior.
 * @param template the template to merge
 * @param context the Velocity context to use for rendering
 * @param response servlet response (use this to get the OutputStream or Writer)
 * @throws Exception if thrown by Velocity
 * @see org.apache.velocity.Template#merge
 */
protected void mergeTemplate(
		Template template, Context context, HttpServletResponse response) throws Exception {

	try {
		template.merge(context, response.getWriter());
	}
	catch (MethodInvocationException ex) {
		Throwable cause = ex.getWrappedThrowable();
		throw new NestedServletException(
				"Method invocation failed during rendering of Velocity view with name '" +
				getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName() +
				"], method '" + ex.getMethodName() + "'",
				cause==null ? ex : cause);
	}
}
 
Example 4
Source File: VelocityHelper.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * @param vtlInput
 * @param c
 * @return String
 */
public String evaluateVTL(String vtlInput, Context c) {
    StringWriter wOut = new StringWriter(10000);

    try {
        ve.evaluate(c, wOut, "internalEvaluator", vtlInput);
    } catch (MethodInvocationException me) {
        throw new OLATRuntimeException(VelocityHelper.class, "MethodInvocationException occured while merging template: methName:" + me.getMethodName()
                + ", refName:" + me.getReferenceName(), me);
    } catch (Exception e) {
        throw new OLATRuntimeException(VelocityHelper.class, "exception occured while merging template: " + e.getMessage(), e);
    }
    return wOut.toString();
}
 
Example 5
Source File: VelocityHelper.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * @param vtlInput
 * @param c
 * @return String
 */
public String evaluateVTL(String vtlInput, Context c) {
    StringWriter wOut = new StringWriter(10000);

    try {
        ve.evaluate(c, wOut, "internalEvaluator", vtlInput);
    } catch (MethodInvocationException me) {
        throw new OLATRuntimeException(VelocityHelper.class, "MethodInvocationException occured while merging template: methName:" + me.getMethodName()
                + ", refName:" + me.getReferenceName(), me);
    } catch (Exception e) {
        throw new OLATRuntimeException(VelocityHelper.class, "exception occured while merging template: " + e.getMessage(), e);
    }
    return wOut.toString();
}
 
Example 6
Source File: VelocityHelper.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * @param template
 *            e.g. org/olat/demo/_content/index.html
 * @param c
 *            the context
 * @param theme
 *            the theme e.g. "accessibility" or "printing". may be null if the default theme ("") should be taken
 * @return String the rendered template
 */
private String merge(String template, Context c, String theme) {
    StringWriter wOut = new StringWriter(10000);

    try {
        Template vtemplate = null;
        if (log.isDebugEnabled())
            log.debug("Merging template::" + template + " for theme::" + theme, null);

        if (theme != null) {
            // try the theme first, if resource not found exception, fallback to normal resource.
            // e.g. try /_accessibility/index.html first, if not found, try /index.html.
            // this allows for themes to only provide the delta to the default templates

            // todo we could avoid those string operations, if the performance gain is measureable
            int latestSlash = template.lastIndexOf('/');
            StringBuilder sb = new StringBuilder(template.substring(0, latestSlash));
            sb.append("/_").append(theme).append("/").append(template.substring(latestSlash + 1));
            String themedTemplatePath = sb.toString();

            // check cache
            boolean notFound;
            synchronized (resourcesNotFound) { // o_clusterOK by:fj
                notFound = resourcesNotFound.contains(themedTemplatePath);
            }

            if (!notFound) {
                // never tried before -> try to load it
                if (!ve.templateExists(themedTemplatePath)) {
                    // remember not found (since velocity doesn't) then try fallback.
                    // this will happen once for each theme when a resource does not exist in its themed variant but only in the default theme.
                    if (!isDebugging) {
                        synchronized (resourcesNotFound) { // o_clusterOK by:fj
                            resourcesNotFound.add(themedTemplatePath);
                        }
                    } // for debugging, allow introduction of themed files without restarting the application
                } else {
                    // template exists -> load it
                    vtemplate = ve.getTemplate(themedTemplatePath, getInputEncoding());
                }
            }
            // if not found, fallback to standard
            if (vtemplate == null) {
                vtemplate = ve.getTemplate(template, getInputEncoding());
            }
        } else {
            // no theme, load the standard template
            vtemplate = ve.getTemplate(template, getInputEncoding());
        }

        vtemplate.merge(c, wOut);
    } catch (MethodInvocationException me) {
        throw new OLATRuntimeException(VelocityHelper.class, "MethodInvocationException occured while merging template: methName:" + me.getMethodName()
                + ", refName:" + me.getReferenceName(), me.getWrappedThrowable());
    } catch (Exception e) {
        throw new OLATRuntimeException(VelocityHelper.class, "exception occured while merging template: " + e.getMessage(), e);
    }
    return wOut.toString();
}
 
Example 7
Source File: VelocityHelper.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * @param template
 *            e.g. org/olat/demo/_content/index.html
 * @param c
 *            the context
 * @param theme
 *            the theme e.g. "accessibility" or "printing". may be null if the default theme ("") should be taken
 * @return String the rendered template
 */
private String merge(String template, Context c, String theme) {
    StringWriter wOut = new StringWriter(10000);

    try {
        Template vtemplate = null;
        if (log.isDebugEnabled())
            log.debug("Merging template::" + template + " for theme::" + theme, null);

        if (theme != null) {
            // try the theme first, if resource not found exception, fallback to normal resource.
            // e.g. try /_accessibility/index.html first, if not found, try /index.html.
            // this allows for themes to only provide the delta to the default templates

            // todo we could avoid those string operations, if the performance gain is measureable
            int latestSlash = template.lastIndexOf('/');
            StringBuilder sb = new StringBuilder(template.substring(0, latestSlash));
            sb.append("/_").append(theme).append("/").append(template.substring(latestSlash + 1));
            String themedTemplatePath = sb.toString();

            // check cache
            boolean notFound;
            synchronized (resourcesNotFound) { // o_clusterOK by:fj
                notFound = resourcesNotFound.contains(themedTemplatePath);
            }

            if (!notFound) {
                // never tried before -> try to load it
                if (!ve.templateExists(themedTemplatePath)) {
                    // remember not found (since velocity doesn't) then try fallback.
                    // this will happen once for each theme when a resource does not exist in its themed variant but only in the default theme.
                    if (!isDebugging) {
                        synchronized (resourcesNotFound) { // o_clusterOK by:fj
                            resourcesNotFound.add(themedTemplatePath);
                        }
                    } // for debugging, allow introduction of themed files without restarting the application
                } else {
                    // template exists -> load it
                    vtemplate = ve.getTemplate(themedTemplatePath, getInputEncoding());
                }
            }
            // if not found, fallback to standard
            if (vtemplate == null) {
                vtemplate = ve.getTemplate(template, getInputEncoding());
            }
        } else {
            // no theme, load the standard template
            vtemplate = ve.getTemplate(template, getInputEncoding());
        }

        vtemplate.merge(c, wOut);
    } catch (MethodInvocationException me) {
        throw new OLATRuntimeException(VelocityHelper.class, "MethodInvocationException occured while merging template: methName:" + me.getMethodName()
                + ", refName:" + me.getReferenceName(), me.getWrappedThrowable());
    } catch (Exception e) {
        throw new OLATRuntimeException(VelocityHelper.class, "exception occured while merging template: " + e.getMessage(), e);
    }
    return wOut.toString();
}