    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 */
    019package org.apache.wiki.forms;
    020
    021import org.apache.wiki.api.core.Context;
    022import org.apache.wiki.api.exceptions.PluginException;
    023import org.apache.wiki.api.plugin.Plugin;
    024import org.apache.wiki.preferences.Preferences;
    025
    026import java.util.Map;
    027import java.util.ResourceBundle;
    028
    029/**
    030 *  Closes a WikiForm.
    031 *
    032 */
    033public class FormClose extends FormElement {
    034
    035    /**
    036     * Builds a Form close tag. Removes any information on the form from
    037     * the WikiContext.
    038     *
    039     * {@inheritDoc}
    040     */
    041    @Override
    042    public String execute( final Context ctx, final Map< String, String > params ) throws PluginException {
    043        // Don't render if no error and error-only-rendering is on.
    044        final FormInfo info = getFormInfo( ctx );
    045        if( info != null && info.hide() ) {
    046            final ResourceBundle rb = Preferences.getBundle( ctx, Plugin.CORE_PLUGINS_RESOURCEBUNDLE );
    047            return "<p>" + rb.getString( "formclose.noneedtoshow" ) + "</p>";
    048        }
    049
    050        // Get rid of remaining form data, so it doesn't mess up other forms. After this, it is safe to add other Forms.
    051        storeFormInfo( ctx, null );
    052
    053        return "  </form>\n" +
    054               "</div>";
    055    }
    056
    057}