Chon CMS ALPHA
How to create your own plugin?
A plugin concept for choncms is based on OSGI. Each osgi plugin is valid plugin for chon. You may, for example, use dropins dir to auto install external OSGi plugins, eg. "Felix Web Console". You can also drop chon independent OSGi plugins that expose services that can be used by your application.
In chon there is maven helper plugin that can generate new chon based plugin. If you using default project structure created by mvn com.choncms:chon-generate:new-project, you can generate new plugin in your budnles folder:
my.test-chon/bundles> mvn com.choncms:chon-generate:new-plugin
The script will ask for plugin package, and will create default OSGi plugin for chon under bundles. To include in default build add plugin name in .product file and in bundles/pom.xml modules section.
Generated plugin will have defaul Activator.java class - a starting point of your new plugin where you can register chon based extenstions. To register chon based Extension you must have implementation of org.chon.cms.core.Extension, and call app.regExtension in your Activator specifying extenstion name.
Here is an example:
Your extenstion must implement org.chon.cms.core.Extension:
Finally in getTplObject you can return whatever you need to be accessible in velocity templates. For example returned object above can have method hello:
app.regExtension tells the application about your extenstion name and getTplObj will be called only once during page render, if your extension is used on that page. From velocity templates you can access your front page object by the name you specify for extenstion. For example above, in base.html you may have:
$ext.myext.hello()
that will print in HTML the string "Hello". You usually will use services from other plugins and your front page object will be simple middle tier to access services and transform data to HTML.
You can also extend admin functionality from the extenstion using getAdminActions and getAjaxActions.
Other way to extend the framework is to use your special NodeRenderers. If you have your own types you can register NodeRenderer as service into OSGI context and that will be asked to render all nodes from your type. Usefull for example if you have your business object entity, for example product, you can render it in your template with your back end logic specified in the renderer. Good example for this might be chon image handling that use ImageNodeRenderer. That enables image nodes to be resized at runtime (usefull in design) see the example.
Difficault?
Please contact us if you have troubles running your own plugin. With your questions you can help us improve this guide.