/*
 * Copyright 2002-2004 the original author or authors.
 * 
 * Licensed 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.springframework.web.servlet.view.freemarker;

import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.support.RequestContext;
import org.springframework.web.servlet.tags.BindStatusHelper;


/**
 * VelocityFormView is a simple extension of <code>VelocityView</code> that 
 * enables the implicit use of Spring's form based Velocity macros.  Note 
 * that this class is <b>not</b> required for templates that use html forms 
 * <b>unless</b> you wish to take advantage of the Spring helper macros.
 * 
 * @author Darren Davison
 * @since 1.1
 * @version $Id: FreeMarkerFormView.java,v 1.1 2004-07-02 00:40:02 davison Exp $
 */
public class FreeMarkerFormView extends FreeMarkerView {

    public static final String HELPER_VARIABLE_NAME = "springBindStatusHelper";

	private String path;
	
	private BindStatusHelper helper;

    /**
     * This method will expose an object to the VelocityContext of type 
     * BindStatusHelper and be accessible in macros as $springBindStatusHelper.  
     * Principally this is used by the Spring Velocity form helper macros.
     * 
     * @see BindStatusHelper
     * @see org.springframework.web.servlet.view.freemarker.FreeMarkerView#exposeHelpers
     */
    protected void exposeHelpers(Map model, HttpServletRequest request)
            throws Exception {
        if (model.containsKey(HELPER_VARIABLE_NAME)) {            
            String msg = "Attempt to use [" + getClass().getName() + 
	                "] with a context object named [" + 
	                HELPER_VARIABLE_NAME + "].";
            logger.error(msg);
            
            // the error will cause any calls to spring macros to throw exceptions - we
            // may as well fail now.
            throw new ServletException(msg);
            
        } else if (getRequestContextAttribute() == null) {
            throw new ServletException("RequestContext must be exposed to use [" + getClass().getName() +
            		"].  Ensure you set the bean property [requestContextAttribute] on this view");
            		
        } else {
            helper = new BindStatusHelper(
                    (RequestContext) model.get(getRequestContextAttribute()));
            // expose status object for Spring macros
            model.put(HELPER_VARIABLE_NAME, helper);
        }
    }
}

@@ -920,24 +920,26 @@
 %0A/**%0A * 
-Velocity
+FreeMarker
 FormView
@@ -970,24 +970,26 @@
 f %3Ccode%3E
-Velocity
+FreeMarker
 View%3C/co
@@ -1049,24 +1049,26 @@
 m based 
-Velocity
+FreeMarker
  macros.
@@ -1314,17 +1314,17 @@
 ava,v 1.
-1
+2
  2004-07
@@ -1335,12 +1335,12 @@
 00:4
-0:02
+9:09
  dav
@@ -1612,23 +1612,24 @@
 the 
-VelocityContext
+FreeMarker model
  of 
@@ -1766,16 +1766,18 @@
 ing 
-Velocity
+FreeMarker
  for

fix copy/paste javadoc errors!