Example Plugin: User Stats

    UserStats Sample

    This widget displays the names of recently registered users. Through

    one of its properties, you can specify the number of users that should

    be listed.

     

    NOTE: this plugin / widget is designed to be example code and ONLY works if you're using a MySQL database.

     

    Technologies

    The example code here illustrates how to:

     

    • Expose custom widget properties.

    • Retrieve user information from the Clearspace database.

    • Display data using a FreeMarker template.

     

    What's Included

    • build.xml -- Ant build file.

    • plugin.xml -- Plugin descriptor required by Clearspace.

    • resources/userstats.ftl -- FreeMarker template for displaying user data.

    • src/com.jivesoftware.clearspace.plugin.widget.UserStatsWidget.java -- Main widget class.

    • src/com.jivesoftware.community.impl.UserStatsManager.java
      -- Class with logic for connecting to the database and retrieving user
      information.

    • src/com.jivesoftware.community.impl.UserDTO.java -- Class representing user information in the widget.

     

    Building and Deploying the Code

    The Ant build.xml file at the root of the plugin includes a

    build.plugins target you can use to compile the code and package it

    into a JAR file. There's also a deploy.plugins target that copies the

    JAR into the <jiveHome>/plugins directory that accompanies your

    Clearspace distribution.

     

     

    Be sure to read the notes below about dependencies. The JAR files you'll need are included as part of Clearspace.

     

    Running the Samples

    1. Build and deploy the code.

    2. Open Clearspace
      and begin customizing a space overview. To do this, navigate to a space
      for which you are a space administrator (note: you can't customize the
      root space).

    3. Drag the User Statistics widget onto the layout, edit its properties, then publish the layout to see the statistics.

    Dependencies

     

    In addition to requiring Java 1.5, this code requires a few of the

    libraries you'll find in the WEB-INF/lib directory of your Clearspace

    installation, listed below.

     

    • clearspace-<version>.jar

    • freemarker.jar

     

    If you'd rather deploy the plugin manually, you can do that in one of two ways:

     

    • Just copy the plugin JAR file into the
      <jiveHome>/plugins directory. Your running Clearspace instance
      will deploy it automatically.

    • Open the admin console and navigate to System > Settings > Plugins, then browse for your plugin JAR file.

     

    Download or View Source

     

    The attached file contains the jar file or you can get all of the source files from svn.

     

    Clearspace 1.X Plugin Files

     

    Clearspace 2 Plugin Files