This is an automated email from the ASF dual-hosted git repository.
git-site-role pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/struts-site.git
The following commit(s) were added to refs/heads/asf-site by this push:
new 9f30af49e Automatic Site Publish by Buildbot
9f30af49e is described below
commit 9f30af49ed63599f316bec7095f44aeeefe76719
Author: buildbot <[email protected]>
AuthorDate: Tue Apr 5 06:27:01 2022 +0000
Automatic Site Publish by Buildbot
---
output/plugins/index.html | 4 +-
.../{plugins.html => plugins-architecture.html} | 161 +++++++++++++++++++--
2 files changed, 148 insertions(+), 17 deletions(-)
diff --git a/output/plugins/index.html b/output/plugins/index.html
index 4ee850aeb..0471b5fa9 100644
--- a/output/plugins/index.html
+++ b/output/plugins/index.html
@@ -130,12 +130,12 @@
<h1 id="plugin-developers-guide">Plugin Developers Guide</h1>
-<p>Apache Struts 2 provides a simple <a href="plugins">plugin architecture</a>
so that developers can extend the framework just by
+<p>Apache Struts 2 provides a simple <a href="plugins-architecture">plugin
architecture</a> so that developers can extend the framework just by
adding a JAR to the application’s classpath. Since plugins are contained in a
JAR, they are easy to share with others.
Several plugins are bundled with the framework, and others are available from
third-party sources.</p>
<ul>
- <li><a href="plugins">Plugins</a></li>
+ <li><a href="plugins-architecture">Plugins</a></li>
<li><a href="extending-an-application-with-custom-plugins">Extending an
Application with Custom Plugins</a></li>
</ul>
diff --git a/output/plugins/plugins.html
b/output/plugins/plugins-architecture.html
similarity index 67%
rename from output/plugins/plugins.html
rename to output/plugins/plugins-architecture.html
index 54e541737..8e307c320 100644
--- a/output/plugins/plugins.html
+++ b/output/plugins/plugins-architecture.html
@@ -126,7 +126,7 @@
<article class="container">
<section class="col-md-12">
- <a class="edit-on-gh"
href="https://github.com/apache/struts-site/edit/master/source/plugins/plugins.md"
title="Edit this page on GitHub">Edit on GitHub</a>
+ <a class="edit-on-gh"
href="https://github.com/apache/struts-site/edit/master/source/plugins/plugins-architecture.md"
title="Edit this page on GitHub">Edit on GitHub</a>
<a href="index.html" title="back to Plugins"><< back to Plugins</a>
@@ -140,6 +140,11 @@
<li><a href="#tiles-plugin" id="markdown-toc-tiles-plugin">Tiles
plugin</a></li>
</ul>
</li>
+ <li><a href="#developing-new-extension-point"
id="markdown-toc-developing-new-extension-point">Developing new extension
point</a> <ul>
+ <li><a href="#extension-point-provided-by-the-core"
id="markdown-toc-extension-point-provided-by-the-core">Extension point provided
by the Core</a></li>
+ <li><a href="#extension-point-provided-by-a-plugin"
id="markdown-toc-extension-point-provided-by-a-plugin">Extension point provided
by a plugin</a></li>
+ </ul>
+ </li>
<li><a href="#plugin-registry" id="markdown-toc-plugin-registry">Plugin
Registry</a></li>
</ul>
@@ -149,17 +154,10 @@ whatever dependencies the plugin itself may have. To
configure the plugin, the J
file, which follows the same format as an ordinary <code
class="highlighter-rouge">struts.xml</code> file.</p>
<p>Since a plugin can contain the <code
class="highlighter-rouge">struts-plugin.xml</code> file, it has the ability
to:</p>
-
<ul>
- <li>
- <p>Define new packages with results, interceptors, and/or actions</p>
- </li>
- <li>
- <p>Override framework constants</p>
- </li>
- <li>
- <p>Introduce new extension point implementation classes</p>
- </li>
+ <li>Define new packages with results, interceptors, and/or actions</li>
+ <li>Override framework constants</li>
+ <li>Introduce new extension point implementation classes</li>
</ul>
<p>Many popular but optional features of the framework are distributed as
plugins. An application can retain all the plugins
@@ -185,7 +183,7 @@ with the distribution, or any other plugins available to an
application.</p>
<h2 id="static-resources">Static resources</h2>
<p>To include static resources in your plugins add them under “/static” in
your jar. And include them in your page using
-“/struts” as the path, like in the following example:</p>
+“/static” as the path, like in the following example:</p>
<pre><code class="language-ftl"><!-- Assuming /static/main.css is inside a
plugin jar, to add it to the page: -->
@@ -193,7 +191,7 @@ with the distribution, or any other plugins available to an
application.</p>
<link rel="stylesheet" type="text/css" href="%{#css}" />
</code></pre>
-<p>Read also <a
href="https://struts.apache.org/maven/struts2-core/apidocs/org/apache/struts2/dispatcher/StaticContentLoader">StaticContentLoader
JavaDoc</a>.</p>
+<p>Read also <a href="../core-developers/static-content">Static Content</a>
and JavaDoc of <a
href="https://struts.apache.org/maven/struts2-core/apidocs/org/apache/struts2/dispatcher/StaticContentLoader">StaticContentLoader</a>.</p>
<h2 id="extension-points">Extension Points</h2>
@@ -452,6 +450,12 @@ For example, a plugin could provide a new class to create
Action classes or map
<td>singleton</td>
<td>com.opensymphony.xwork2.LocalizedTextProvider</td>
</tr>
+ <tr>
+ <td>struts.date.formatter</td>
+ <td>Allow define a date formatter used by <code
class="highlighter-rouge"><s:date/></code> tag (since 6.0.0)</td>
+ <td>singleton</td>
+ <td>org.apache.struts2.components.date.DateFromatter</td>
+ </tr>
</tbody>
</table>
@@ -484,8 +488,6 @@ points, it does need to know what settings have been
enabled in the Struts frame
<div class="language-xml highlighter-rouge"><div class="highlight"><pre
class="highlight"><code><span class="cp"><?xml version="1.0"
encoding="UTF-8" ?></span>
<span class="c"><!--
/*
- * $Id$
- *
* 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
@@ -542,6 +544,135 @@ a common look-and-feel to an application’s pages by
breaking the page down int
<p>Since the Tiles Plugin does need to register configuration elements, a
result class, it provides a <code
class="highlighter-rouge">struts-plugin.xml</code> file.</p>
+<h2 id="developing-new-extension-point">Developing new extension point</h2>
+
+<p>An extension point it’s a name which will be used to locate other beans by
the name and inject them into a given place.
+Extension point isn’t a bean, you cannot inject it. It’s a bridge between your
interface/class and the final implementation,
+provided either by a plugin or by a user.</p>
+
+<p>If needed you can define your own extension point. This can happen in two
ways: either define it in the Struts Core,
+or define the extension in the plugin you are developing.</p>
+
+<h3 id="extension-point-provided-by-the-core">Extension point provided by the
Core</h3>
+
+<p>First step is to name your extension point, basically we are using a
pattern like follow:</p>
+<div class="highlighter-rouge"><div class="highlight"><pre
class="highlight"><code>struts.<component | functionallity>.<name of
the extebsion point>
+</code></pre></div></div>
+
+<p>e.g.: <code class="highlighter-rouge">struts.date.formatter</code>.</p>
+
+<p>Now you must provide an interface or a class as the extension point, it
will be used by others to implement they own behaviour
+of the extension point, e.g.: <code
class="highlighter-rouge">org.apache.struts2.components.date.DateFormatter</code>.</p>
+
+<p>The next step is to tie the name of the extension point with the
interface/class. It happens in <code
class="highlighter-rouge">StrutsBeanSelectionProvider</code></p>
+
+<p>by using <code class="highlighter-rouge">alias()</code> method as below:</p>
+<div class="language-java highlighter-rouge"><div class="highlight"><pre
class="highlight"><code><span class="n">alias</span><span
class="o">(</span><span class="n">DateFormatter</span><span
class="o">.</span><span class="na">class</span><span class="o">,</span> <span
class="n">StrutsConstants</span><span class="o">.</span><span
class="na">STRUTS_DATE_FORMATTER</span><span class="o">,</span> <span
class="n">builder</span><span class="o">,</span> <span
class="n">props</span><span class="o [...]
+</code></pre></div></div>
+
+<p>as you can see you must provide:</p>
+<ul>
+ <li><code class="highlighter-rouge">Class<?></code> class behind the
extension point, which is used by users to implement the extension point</li>
+ <li><code class="highlighter-rouge">String</code> a key, the name of the
extension point</li>
+ <li><code class="highlighter-rouge">ContainerBuilder</code> builder used to
setup the Container</li>
+ <li><code class="highlighter-rouge">Properties</code> additional properties
when needed</li>
+ <li><code class="highlighter-rouge">Scope</code> scope of the extension
point, all the beans extneding the extension point must have the same scope</li>
+</ul>
+
+<p>Having all that set, you can define where to use the extension point by
injecting beans implementing it by using <code
class="highlighter-rouge">@Inject</code></p>
+
+<div class="language-java highlighter-rouge"><div class="highlight"><pre
class="highlight"><code><span class="nd">@Inject</span>
+<span class="kd">public</span> <span class="kt">void</span> <span
class="nf">setDateFormatter</span><span class="o">(</span><span
class="n">DateFormatter</span> <span class="n">dateFormatter</span><span
class="o">)</span> <span class="o">{</span>
+ <span class="k">this</span><span class="o">.</span><span
class="na">dateFormatter</span> <span class="o">=</span> <span
class="n">dateFormatter</span><span class="o">;</span>
+<span class="o">}</span>
+</code></pre></div></div>
+
+<p>you can use <code class="highlighter-rouge">optional = true</code> if the
implementation is not required, yet please remember to handle <code
class="highlighter-rouge">null</code> in such case.</p>
+
+<p>All the above steps have defined a new extension point, now you can
implement a bean which will be <em>bridged</em> throughout
+the extension point with the <code class="highlighter-rouge">@Inject</code>.
Just implement the interface/class used to define the extension point and define
+the bean in <code class="highlighter-rouge">struts-default.xml</code>:</p>
+
+<div class="language-java highlighter-rouge"><div class="highlight"><pre
class="highlight"><code><span class="kd">public</span> <span
class="kd">class</span> <span class="nc">DateTimeFormatterAdapter</span> <span
class="kd">implements</span> <span class="n">DateFormatter</span> <span
class="o">{</span>
+
+ <span class="nd">@Override</span>
+ <span class="kd">public</span> <span class="n">String</span> <span
class="nf">format</span><span class="o">(</span><span
class="n">TemporalAccessor</span> <span class="n">temporal</span><span
class="o">,</span> <span class="n">String</span> <span
class="n">format</span><span class="o">)</span> <span class="o">{</span>
+ <span class="n">DateTimeFormatter</span> <span
class="n">dtf</span><span class="o">;</span>
+ <span class="n">Locale</span> <span class="n">locale</span> <span
class="o">=</span> <span class="n">ActionContext</span><span
class="o">.</span><span class="na">getContext</span><span
class="o">().</span><span class="na">getLocale</span><span class="o">();</span>
+ <span class="k">if</span> <span class="o">(</span><span
class="n">format</span> <span class="o">==</span> <span
class="kc">null</span><span class="o">)</span> <span class="o">{</span>
+ <span class="n">dtf</span> <span class="o">=</span> <span
class="n">DateTimeFormatter</span><span class="o">.</span><span
class="na">ofLocalizedDateTime</span><span class="o">(</span><span
class="n">FormatStyle</span><span class="o">.</span><span
class="na">MEDIUM</span><span class="o">)</span>
+ <span class="o">.</span><span
class="na">withLocale</span><span class="o">(</span><span
class="n">locale</span><span class="o">);</span>
+ <span class="o">}</span> <span class="k">else</span> <span
class="o">{</span>
+ <span class="n">dtf</span> <span class="o">=</span> <span
class="n">DateTimeFormatter</span><span class="o">.</span><span
class="na">ofPattern</span><span class="o">(</span><span
class="n">format</span><span class="o">,</span> <span
class="n">locale</span><span class="o">);</span>
+ <span class="o">}</span>
+ <span class="k">return</span> <span class="n">dtf</span><span
class="o">.</span><span class="na">format</span><span class="o">(</span><span
class="n">temporal</span><span class="o">);</span>
+ <span class="o">}</span>
+
+<span class="o">}</span>
+</code></pre></div></div>
+
+<div class="language-xml highlighter-rouge"><div class="highlight"><pre
class="highlight"><code><span class="nt"><bean</span> <span
class="na">type=</span><span
class="s">"org.apache.struts2.components.date.DateFormatter"</span>
+ <span class="na">name=</span><span class="s">"dateTimeFormatter"</span>
+ <span class="na">class=</span><span
class="s">"org.apache.struts2.components.date.DateTimeFormatterAdapter"</span>
+ <span class="na">scope=</span><span class="s">"singleton"</span><span
class="nt">/></span>
+</code></pre></div></div>
+
+<p>The <code class="highlighter-rouge">name</code> attribute it’s of your
choice, it just needs to be unique.</p>
+
+<p>And the final step is to use the new bean with the extension point, this
will happen in <code class="highlighter-rouge">default.properties</code>:</p>
+
+<div class="highlighter-rouge"><div class="highlight"><pre
class="highlight"><code>struts.date.formatter=dateTimeFormatter
+</code></pre></div></div>
+
+<p>and done!</p>
+
+<p>If a user would like to provide its own implementation they just needs to
implement the interface, define a bean
+in <code class="highlighter-rouge">struts.xml</code> with a name and then tie
it to the extension point overriding the one provided by the framework:</p>
+
+<div class="language-xml highlighter-rouge"><div class="highlight"><pre
class="highlight"><code><span class="nt"><bean</span> <span
class="na">type=</span><span
class="s">"org.apache.struts2.components.date.DateFormatter"</span>
+ <span class="na">name=</span><span
class="s">"myDateTimeFormatter"</span>
+ <span class="na">class=</span><span
class="s">"com.company.date.MyDateTimeFormatterAdapter"</span>
+ <span class="na">scope=</span><span class="s">"singleton"</span><span
class="nt">/></span>
+</code></pre></div></div>
+
+<div class="highlighter-rouge"><div class="highlight"><pre
class="highlight"><code>struts.date.formatter=myDateTimeFormatter
+</code></pre></div></div>
+
+<h3 id="extension-point-provided-by-a-plugin">Extension point provided by a
plugin</h3>
+
+<p>It’s very the like as above except that the plugin must provide a <code
class="highlighter-rouge">bean-selection</code> configuration option in <code
class="highlighter-rouge">struts-plugin.xml</code>.
+The <code class="highlighter-rouge">bean-selection</code> option represents an
implementation of a class <code
class="highlighter-rouge">org.apache.struts2.config.AbstractBeanSelectionProvider</code>
+with <em>no-arguments</em> constructor:</p>
+
+<div class="language-java highlighter-rouge"><div class="highlight"><pre
class="highlight"><code><span class="kd">public</span> <span
class="kd">class</span> <span class="nc">VelocityBeanSelectionProvider</span>
<span class="kd">extends</span> <span
class="n">AbstractBeanSelectionProvider</span> <span class="o">{</span>
+
+ <span class="nd">@Override</span>
+ <span class="kd">public</span> <span class="kt">void</span> <span
class="nf">register</span><span class="o">(</span><span
class="n">ContainerBuilder</span> <span class="n">builder</span><span
class="o">,</span> <span class="n">LocatableProperties</span> <span
class="n">props</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">ConfigurationException</span> <span class="o">{</span>
+ <span class="n">alias</span><span class="o">(</span><span
class="n">VelocityManager</span><span class="o">.</span><span
class="na">class</span><span class="o">,</span> <span
class="n">VelocityConstants</span><span class="o">.</span><span
class="na">STRUTS_VELOCITY_MANAGER_CLASSNAME</span><span class="o">,</span>
<span class="n">builder</span><span class="o">,</span> <span
class="n">props</span><span class="o">);</span>
+ <span class="o">}</span>
+
+<span class="o">}</span>
+</code></pre></div></div>
+
+<p>The class defines extension points by implementing <code
class="highlighter-rouge">register()</code> method and using <code
class="highlighter-rouge">alias()</code> method to register them.</p>
+
+<p>And finally it must be added to the <code
class="highlighter-rouge">struts-plugin.xml</code>:</p>
+
+<div class="language-xml highlighter-rouge"><div class="highlight"><pre
class="highlight"><code><span class="cp"><?xml version="1.0"
encoding="UTF-8" ?></span>
+<span class="cp"><!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.6//EN"
+ "http://struts.apache.org/dtds/struts-2.6.dtd"></span>
+
+<span class="nt"><struts></span>
+ ...
+
+ <span class="nt"><bean-selection</span> <span
class="na">name=</span><span class="s">"velocityBeans"</span> <span
class="na">class=</span><span
class="s">"org.apache.struts2.views.velocity.VelocityBeanSelectionProvider"</span><span
class="nt">/></span>
+
+<span class="nt"></struts></span>
+</code></pre></div></div>
+
+<p>And now other plugins or user application can use the new extension point
represented by <code
class="highlighter-rouge">VelocityConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME</code>.</p>
+
<h2 id="plugin-registry">Plugin Registry</h2>
<blockquote>