001    /* 
002        Licensed to the Apache Software Foundation (ASF) under one
003        or more contributor license agreements.  See the NOTICE file
004        distributed with this work for additional information
005        regarding copyright ownership.  The ASF licenses this file
006        to you under the Apache License, Version 2.0 (the
007        "License"); you may not use this file except in compliance
008        with the License.  You may obtain a copy of the License at
009    
010           http://www.apache.org/licenses/LICENSE-2.0
011    
012        Unless required by applicable law or agreed to in writing,
013        software distributed under the License is distributed on an
014        "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015        KIND, either express or implied.  See the License for the
016        specific language governing permissions and limitations
017        under the License.  
018     */
019    package org.apache.wiki.forms;
020    
021    import java.util.Map;
022    import java.util.ResourceBundle;
023    
024    import org.apache.wiki.WikiContext;
025    import org.apache.wiki.api.exceptions.PluginException;
026    import org.apache.wiki.api.plugin.WikiPlugin;
027    import org.apache.wiki.preferences.Preferences;
028    
029    /**
030     *  Closes a WikiForm.
031     *
032     */
033    public class FormClose
034        extends FormElement
035    {
036        /**
037         * Builds a Form close tag. Removes any information on the form from
038         * the WikiContext.
039         * 
040         * {@inheritDoc}
041         */
042        public String execute( WikiContext ctx, Map< String, String > params )
043            throws PluginException
044        {
045            StringBuffer tags = new StringBuffer();
046            tags.append( "</form>\n" );
047            tags.append( "</div>" );
048    
049            // Don't render if no error and error-only-rendering is on.
050            FormInfo info = getFormInfo( ctx );
051            if( info != null && info.hide() )
052            {
053                ResourceBundle rb = Preferences.getBundle( ctx, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE );
054                return "<p>" + rb.getString( "formclose.noneedtoshow" ) + "</p>";
055            }
056    
057            // Get rid of remaining form data, so it doesn't mess up other forms.
058            // After this, it is safe to add other Forms.
059            storeFormInfo( ctx, null );
060    
061            return tags.toString();
062    
063        }
064    }