Changes for page Creating Plugins

Last modified by Simon Urli on 2023/10/10

From version 1.30
edited by Sergiu Dumitriu
on 2007/10/25
Change comment: Fixed the LOG initialization code, removed the manual call to init from the constructor
To version 1.31
edited by Sergiu Dumitriu
on 2007/10/25
Change comment: Rewrite the plugin api code

Summary

Details

Page properties
Content
... ... @@ -35,12 +35,8 @@
35 35  {code}
36 36  The <code>myPluginApi</code> variable will point to the same object as long as the variable exists. You can declare fields in your plugin class instead, since there is only one instance of this class, whose lifecycle spans over the entire servlet's lifecycle.
37 37  
38 +1.1 Write the plugin
38 38  
39 -
40 -
41 -
42 -1.1 Build the plugin
43 -
44 44  First of all let's *declare our plugin class*:
45 45  
46 46  {code:java}
... ... @@ -143,7 +143,7 @@
143 143  {code}
144 144  
145 145  
146 -1.1 Build the API
142 +1.1 Write the API
147 147  
148 148  Let's write the API class which will contain the methods that can be called from Velocity.
149 149  
... ... @@ -153,30 +153,32 @@
153 153  public class HelloWorldPluginApi extends Api {...}
154 154  {code}
155 155  
156 -Then, *plugin field declaration*. It will let our api to call backend methods.
152 +Then, *plugin field declaration*. It will let our API to call backend methods.
157 157  
158 158  {code:java}
159 159  private HelloWorldPlugin plugin;
160 160  {code}
161 161  
162 -*Constructor overloading*
158 +*Required constructor*
163 163  
164 164  {code:java}
165 165  public HelloWorldPluginApi(HelloWorldPlugin plugin, XWikiContext context) {
166 - super(context);
167 - setPlugin(plugin);
162 + super(context);
163 + setPlugin(plugin);
168 168  }
169 169  {code}
170 170  
171 -Classic *plugin getter and setter*
167 +Classic *plugin getter and setter*. These methods are not required at all, on the contrary, they should not be defined, unless they are really needed.
172 172  
173 173  {code:java}
174 174  public HelloWorldPlugin getPlugin(){
175 - return plugin;
171 + return (hasProgrammingRights() ? plugin : null);
172 + // Uncomment for allowing unrestricted access to the plugin
173 + // return plugin;
176 176  }
177 177  
178 178  public void setPlugin(HelloWorldPlugin plugin) {
179 - this.plugin = plugin;
177 + this.plugin = plugin;
180 180  }
181 181  {code}
182 182  
... ... @@ -204,26 +204,27 @@
204 204  public class HelloWorldPluginApi extends Api {
205 205   private HelloWorldPlugin plugin;
206 206  
207 - public HelloWorldPluginApi(HelloWorldPlugin plugin, XWikiContext context) {
208 - super(context);
209 - setPlugin(plugin);
210 - }
205 + public HelloWorldPluginApi(HelloWorldPlugin plugin, XWikiContext context) {
206 + super(context);
207 + setPlugin(plugin);
208 + }
211 211  
212 - public HelloWorldPlugin getPlugin(){
213 - return plugin;
214 - }
215 -
216 - public void setPlugin(HelloWorldPlugin plugin) {
217 - this.plugin = plugin;
218 - }
219 -
220 - public String hello() {
221 - return "Hello World!";
222 - }
210 + return (hasProgrammingRights() ? plugin : null);
211 + // Uncomment for allowing unrestricted access to the plugin
212 + // return plugin;
223 223  
224 - public void updatePage() {
225 - //...
226 - }
214 +
215 + public void setPlugin(HelloWorldPlugin plugin) {
216 + this.plugin = plugin;
217 + }
218 +
219 + public String hello() {
220 + return "Hello World!";
221 + }
222 +
223 + public void updatePage() {
224 + //...
225 + }
227 227  }
228 228  {code}
229 229  

Get Connected