|
|
|
|
|
| |
|
View
|
|
Discussion
|
|
Edit
|
|
Attachments
|
|
|
How do plugins work in SamePage
Plugin is a construct that allows the ability to add certain custom functionality into the Page. Essentially all plugins in SamePage work on the concept of invoking a plugin class for that plugin and replacing the contents of the plugin itself with the output of the class. All the plugin classes have to be specified in the wiki.plugins file and have to be added to the CLASSPATH.
For example, the plugin class net.etouch.contmgmt.wiki.WikiTOCTagResolver provides the functionality for creating a Table of Contents. At runtime, SamePage finds the $TOC{} in the Page and invokes the net.etouch.contmgmt.wiki.WikiTOCTagResolver class that returns the actual table of contents. The $TOC{} text gets replaced with this output. Additional parameters can be specified to the TOC plugin as name-value pairs separated by spaces within the curled braces. Eg. $TOC{show_div="yes" show_header="no"}. These parameters get passed as variables to the plugin class.
Custom plugins will also work in a similar fashion except that they need to be pre-pended with a # sign instead of a $ sign. The custom plugin class functionality could be completely independent of Samepage, for example it could in turn invoke a shell-script, make a DB call or invoke a web-service. It only needs to return either a text or HTML that will replace the plugin content in the Page. Say, you create a plugin that returns the temperature of a place based on city name or zip code. You will create a new plugin class, say common.template.sample.SampleTagResolver which will have to registered in the wiki.plugins file. This class will have the code to resolve a new custom tag say #TEMP{zip="94555"}, use the zipcode input to get the temperature and return a string "Your current local temperature is 32 degrees Fahrenheit". At run-time, SamePage will invoke your custom plugin class and replace the custom tag #TEMP{zip="94555"} with the output string "Your current local temperature is 32 degrees Fahrenheit".
Here are some Samples of how custom plugins would look in the Edit and View Tabs of the Page.
As seen on Edit Tab
#TEMP{zip"94555" city=""}
As seen on View Tab
Your current local temperature is 32 degrees Fahrenheit
|
As seen on Edit Tab
#CUST_DATA{id="543"}
As seen on View Tab
Customer name: William Thornton
Address : 4568 Maurice Avenue
Dublin CA 94568
Phone No : 925-889-7689
|
As seen on Edit Tab
#PRODUCT_INFO{sku="7676876"}
As seen on View Tab
Size and weight (30GB)
* Height: 4.1 inches
* Width: 2.4 inches
* Depth: 0.43 inch
* Weight: 4.8 ounces
Capacity
* 30GB or 80GB hard drive
* Holds up to 7,500 (30GB) or 20,000 songs (80GB) in 128-Kbps AAC format
|
|
|
Instructions to create your custom plugin
- Using the sample implementation below as a template, create your custom plugin class. The translate() method of your custom plugin class will be invoked by SamePage at run-time. It can have any number of internal methods for the actual custom functionality.
- You can refer to the javadocs for the SampleTagResolver or check out the source attached below.
- Create a jar , say custom_plugin.jar that contains your custom plugin class. You can wrap multiple plugin classes into this jar.
- Look for the wiki.plugins file under $INSTALL_DIR/cm/WEB-INF/lib/conf and add the name of your custom plugin class at the end. Make sure the plugin classes are delimited with commas. E.g net.etouch.contmgmt..........contmgmt.wiki.WikiChildrenResolver, common.template.sample.SampleTagResolver
- Add the custom_plugin.jar to $INSTALL_DIR/tomcat/common/lib folder.
- Restart SamePage server.
- Now on any Page, type your custom tag within the plugin and save. The View tab of the Page should show the resolved output of the custom plugin.
Sample Implementation
As a first step before creating your own custom plugin class, we would advise that you deploy this sample custom plugin class in your instance of SamePage.
- Look for the wiki.plugins file under $INSTALL_DIR/cm/WEB-INF/lib/conf and add the entry ""common.template.sample.SampleTagResolver" at the end of the file . Make sure the plugin classes are delimited with commas.
- Add the attached custom_plugin.jar to $INSTALL_DIR/tomcat/common/lib folder.
- Restart SamePage server.
- Now on any Page, add a plugin and type the text #TEMP{zip="94555"} inside the plugin. Save the Page. The View tab of the Page should show the resolved output of the custom plugin "Your current local temperature is 32 degrees Fahrenheit". This is just a dummy class.
|
|
|
|
|
|
|