    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.api.plugin;
    020
    021import java.util.Locale;
    022import org.apache.wiki.api.core.Context;
    023import org.apache.wiki.api.exceptions.PluginException;
    024
    025import java.util.Map;
    026
    027
    028/**
    029 *  Defines an interface for plugins.  Any instance of a wiki plugin should implement this interface.
    030 */
    031public interface Plugin {
    032
    033    /** Name of the default plugin resource bundle. */
    034    String CORE_PLUGINS_RESOURCEBUNDLE = "plugin.PluginResources";
    035
    036    /**
    037     *  This is the main entry point for any plugin.  The parameters are parsed, and a special parameter called "_body" signifies the name
    038     *  of the plugin body, i.e. the part of the plugin that is not a parameter of the form "key=value".  This has been separated using an
    039     *  empty line.
    040     *  <P>
    041     *  Note that it is preferred that the plugin returns XHTML-compliant HTML (i.e. close all tags, use &lt;br /&gt; instead of
    042     *  &lt;br&gt;, etc.
    043     *
    044     *  @param context The current WikiContext.
    045     *  @param params  A Map which contains key-value pairs.  Any parameter that the user has specified on the
    046     *                 wiki page will contain String-String parameters, but it is possible that at some future date,
    047     *                 JSPWiki will give you other things that are not Strings.
    048     *  @return HTML, ready to be included into the rendered page.
    049     *  @throws PluginException In case anything goes wrong.
    050     */
    051    String execute( Context context, Map< String, String > params ) throws PluginException;
    052
    053    /**
    054     * Provides the ability for a plugin to provide a suggestion or template
    055     * for execution within a wiki page. Default returns just the FQCN of the
    056     * plugin, which should enable it to fire off, however no parameters are
    057     * provided in this case. Override it to provide example inputs to aid users
    058     * with configuring your plugin.
    059     *
    060     * Example: com.company.Plugin inputParamter='test'
    061     *
    062     * @since 3.0.0
    063     * @return String
    064     */
    065    default String getSnipExample() {
    066        return this.getClass().getCanonicalName();
    067    }
    068    /**
    069     * Provides the ability for a plugin to provide it's display name that
    070     * is visible via the [{}] autocomplete/suggestion mechanism within the
    071     * editor.Example: Calls My Custom plugin
    072     *
    073     *
    074     * @param locale
    075     * @since 3.0.0
    076     * @return String
    077     */
    078    default String getDisplayName(Locale locale) {
    079        return this.getClass().getSimpleName();
    080    }
    081
    082}