You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2020/02/17 18:13:53 UTC
[jspwiki] 04/11: extract new PluginElement interface from
PluginContent in order to break a package/class cycle between PluginContent
and ParserStagePlugin
This is an automated email from the ASF dual-hosted git repository.
juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 6985a5913f2816dee3442d8903ec637b8ebafb7a
Author: juanpablo <ju...@apache.org>
AuthorDate: Sun Feb 2 21:34:16 2020 +0100
extract new PluginElement interface from PluginContent in order to break a package/class cycle between PluginContent and ParserStagePlugin
---
.../apache/wiki/api/plugin/ParserStagePlugin.java | 12 ++-
.../org/apache/wiki/api/plugin/PluginElement.java | 86 ++++++++++++++++++++++
.../java/org/apache/wiki/parser/PluginContent.java | 69 ++++++-----------
3 files changed, 112 insertions(+), 55 deletions(-)
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/api/plugin/ParserStagePlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/api/plugin/ParserStagePlugin.java
index 666b1b1..1e38c5c 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/api/plugin/ParserStagePlugin.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/api/plugin/ParserStagePlugin.java
@@ -18,17 +18,15 @@
*/
package org.apache.wiki.api.plugin;
-import java.util.Map;
-
import org.apache.wiki.WikiContext;
-import org.apache.wiki.parser.PluginContent;
+
+import java.util.Map;
/**
- * Implements a Plugin interface for the parser stage. Please see org.apache.wiki.api.PluginManager
+ * Implements a Plugin interface for the parser stage. Please see {@link org.apache.wiki.api.engine.PluginManager}
* for further documentation.
*/
-public interface ParserStagePlugin
-{
+public interface ParserStagePlugin {
/**
* Method which is executed during parsing.
@@ -37,6 +35,6 @@ public interface ParserStagePlugin
* @param context WikiContext, as usual.
* @param params Parsed parameters for the plugin.
*/
- void executeParser( PluginContent element, WikiContext context, Map< String, String > params );
+ void executeParser( PluginElement element, WikiContext context, Map< String, String > params );
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/api/plugin/PluginElement.java b/jspwiki-main/src/main/java/org/apache/wiki/api/plugin/PluginElement.java
new file mode 100644
index 0000000..ee7e33b
--- /dev/null
+++ b/jspwiki-main/src/main/java/org/apache/wiki/api/plugin/PluginElement.java
@@ -0,0 +1,86 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.apache.wiki.api.plugin;
+
+import org.apache.wiki.WikiContext;
+import org.apache.wiki.api.exceptions.PluginException;
+
+import java.util.Map;
+
+
+/**
+ * Exposes the contents of a plugin in a WikiDocument DOM tree.
+ */
+public interface PluginElement {
+
+ /**
+ * Returns the name of the plugin invoked by the DOM element.
+ *
+ * @return Name of the plugin
+ * @since 2.5.7
+ */
+ String getPluginName();
+
+ /**
+ * Returns a parameter value from the parameter map.
+ *
+ * @param name the name of the parameter.
+ * @return The value from the map, or null, if no such parameter exists.
+ */
+ String getParameter( String name);
+
+ /**
+ * Returns the parameter map given in the constructor.
+ *
+ * @return The parameter map.
+ */
+ Map< String, String > getParameters();
+
+ /**
+ * Returns the rendered plugin. Only calls getText().
+ *
+ * @return HTML
+ */
+ String getValue();
+
+ /**
+ * The main invocation for the plugin. When the getText() is called, it invokes the plugin and returns its contents. If there is
+ * no Document yet, only returns the plugin name itself.
+ *
+ * @return The plugin rendered according to the options set in the WikiContext.
+ */
+ String getText();
+
+ /**
+ * Performs plugin invocation and return its contents.
+ *
+ * @param context WikiContext in which the plugin is executed. Must NOT be null.
+ * @return plugin contents.
+ */
+ String invoke( WikiContext context );
+
+ /**
+ * Executes the executeParse() method.
+ *
+ * @param context The WikiContext
+ * @throws PluginException If something goes wrong.
+ */
+ void executeParse( WikiContext context ) throws PluginException;
+
+}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/parser/PluginContent.java b/jspwiki-main/src/main/java/org/apache/wiki/parser/PluginContent.java
index 1fa4947..a7f6f1c 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/parser/PluginContent.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/parser/PluginContent.java
@@ -27,6 +27,7 @@ import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
import org.apache.wiki.api.engine.PluginManager;
import org.apache.wiki.api.exceptions.PluginException;
+import org.apache.wiki.api.plugin.PluginElement;
import org.apache.wiki.api.plugin.ParserStagePlugin;
import org.apache.wiki.api.plugin.WikiPlugin;
import org.apache.wiki.preferences.Preferences;
@@ -50,7 +51,7 @@ import java.util.ResourceBundle;
*
* @since 2.4
*/
-public class PluginContent extends Text {
+public class PluginContent extends Text implements PluginElement {
private static final String BLANK = "";
private static final String CMDLINE = "_cmdline";
@@ -62,11 +63,10 @@ public class PluginContent extends Text {
private static final String SPACE = " ";
private static final long serialVersionUID = 1L;
-
- private static Logger log = Logger.getLogger(PluginContent.class);
+ private static final Logger log = Logger.getLogger(PluginContent.class);
private String m_pluginName;
- private Map<String, String> m_params;
+ private Map< String, String > m_params;
/**
* Creates a new DOM element with the given plugin name and a map of parameters.
@@ -79,51 +79,32 @@ public class PluginContent extends Text {
m_params = parameters;
}
- /**
- * Returns the name of the plugin invoked by the DOM element.
- *
- * @return Name of the plugin
- * @since 2.5.7
- */
+ /**{@inheritDoc}*/
+ @Override
public String getPluginName() {
return m_pluginName;
}
- /**
- * Returns a parameter value from the parameter map.
- *
- * @param name the name of the parameter.
- * @return The value from the map, or null, if no such parameter exists.
- */
+ /**{@inheritDoc}*/
+ @Override
public String getParameter( final String name) {
- return m_params.get(name);
+ return m_params.get( name );
}
- /**
- * Returns the parameter map given in the constructor.
- *
- * @return The parameter map.
- */
+ /**{@inheritDoc}*/
+ @Override
public Map< String, String > getParameters() {
return m_params;
}
- /**
- * Returns the rendered plugin. Only calls getText().
- *
- * @return HTML
- */
+ /**{@inheritDoc}*/
+ @Override
public String getValue() {
return getText();
}
- /**
- * The main invocation for the plugin. When the getText() is called, it
- * invokes the plugin and returns its contents. If there is no Document
- * yet, only returns the plugin name itself.
- *
- * @return The plugin rendered according to the options set in the WikiContext.
- */
+ /**{@inheritDoc}*/
+ @Override
public String getText() {
final WikiDocument doc = ( WikiDocument )getDocument();
if( doc == null ) {
@@ -144,13 +125,9 @@ public class PluginContent extends Text {
return invoke( context );
}
- /**
- * Performs plugin invocation and return its contents.
- *
- * @param context WikiContext in which the plugin is executed. Must NOT be null.
- * @return plugin contents.
- */
- public String invoke( final WikiContext context ) {
+ /**{@inheritDoc}*/
+ @Override
+ public String invoke( final WikiContext context ) {
String result;
final Boolean wysiwygVariable = ( Boolean )context.getVariable( WikiContext.VAR_WYSIWYG_EDITOR_MODE );
boolean wysiwygEditorMode = false;
@@ -165,7 +142,7 @@ public class PluginContent extends Text {
// since they can be edited visually.
//
// FIXME: The plugin name matching should not be done here, but in a per-editor resource
- if (wysiwygEditorMode && !m_pluginName.matches(EMITTABLE_PLUGINS)) {
+ if( wysiwygEditorMode && !m_pluginName.matches( EMITTABLE_PLUGINS ) ) {
result = PLUGIN_START + m_pluginName + SPACE;
// convert newlines to <br> in case the plugin has a body.
@@ -205,12 +182,8 @@ public class PluginContent extends Text {
return result;
}
- /**
- * Executes the executeParse() method.
- *
- * @param context The WikiContext
- * @throws PluginException If something goes wrong.
- */
+ /**{@inheritDoc}*/
+ @Override
public void executeParse( final WikiContext context ) throws PluginException {
final PluginManager pm = context.getEngine().getPluginManager();
if( pm.pluginsEnabled() ) {