ImagoX Counter Extension 

The ImagoX Counter Extension is an implementation of a "hit counter". Counter can register hits, report hit totals, or both in a single request. Counter may be configured to use either a file-based or database-based datastore.

update element.
Update the counter for the requested URI.

Attributes:
format
Optional attribute specifying the format of display. Valid options are:
  • none - no display (default)
  • text - simple text element
  • counter - each digit is enclosed in a <NS:counter> element
read element.
Read the counter for the requested URI.

Attributes:
uri
Optional attribute specifying the URI containing the count to read. If not specified the current URI is used.

format
Optional attribute specifying the format of display. Valid options are:
  • text - simple text element (default)
  • counter - each digit is enclosed in a <NS:counter> element


The ImagoX Counter is a good candidate for the Launcher mechanism, otherwise it must create a new instance of the Counter class on each request. If a database-based approach is chosen any database supported by LDBC may be used. Additional ImagoX extension configuration information is available here. The following configuration lines go into the imago.properties file.

Launcher-style configuration
Other Launcher configuration examples are shown here.

File-based counter:
init.Launcher.class.Counter=org.xenei.imagoX.counter.ImagoCounter
init.Launcher.init.Counter.class=org.xenei.imagoX.counter.FileCounterData
init.Launcher.init.Counter.init.directory=/tmp


Database-based counter:
init.Launcher.class.Counter=org.xenei.imagoX.counter.ImagoCounter
init.Launcher.init.Counter.class=org.xenei.imagoX.counter.DBCounterData
init.Launcher.init.Counter.init.db.driver=com.mysql.jdbc.Driver
init.Launcher.init.Counter.init.db.host=jdbc:mysql://db.xenei.org/imago
init.Launcher.init.Counter.init.db.user=imago
init.Launcher.init.Counter.init.db.password=imago


imago.properties-style configuration

File-based counter:
org.xenei.imagoX.counter.ImagoCounter.class=org.xenei.imagoX.counter.FileCounterData
org.xenei.imagoX.counter.ImagoCounter.init.directory=/tmp


Database-based counter:
init.Launcher.class.Counter=org.xenei.imagoX.counter.ImagoCounter
org.xenei.imagoX.counter.ImagoCounter.class=org.xenei.imagoX.counter.DBCounterData
org.xenei.imagoX.counter.ImagoCounter.init.db.driver=com.mysql.jdbc.Driver
org.xenei.imagoX.counter.ImagoCounter.init.db.host=jdbc:mysql://db.xenei.org/imago
org.xenei.imagoX.counter.ImagoCounter.init.db.user=imago
org.xenei.imagoX.counter.ImagoCounter.init.db.password=imago



 Usage 

Assuming that the XML file is as follows:

<?xml version="1.0"?>
<document xmlns:imago="http://xenei.org/imago/2002" >
    <imago:counter/>
</document>


The method of counter usage depends upon the configuration style. If configured using the Launcher style the following XSL would list the count twice. The first one would update it and the second would simply display it.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0"
    xmlns:launcher="xalan://org.xenei.imago.extensions.Launcher"
    xmlns:imago="http://xenei.org/imago/2002"
    extension-element-prefixes="xcounter"
>
<xsl:template match="document">
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="imago:counter">
    <launcher:launch launcher:class="Counter" launcher:method="update" format="text" />
    <launcher:launch launcher:class="Counter" launcher:method="read" format="text"/>
</xsl:template>
</xsl:stylesheet>


An alternative to the XSLT above is the imago.properties style configuration. Using the same XML file this transform will produce the same results. However it will take longer to execute.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0"
    xmlns:xcounter="xalan://org.xenei.imagox.counter.ImagoCounter"
    xmlns:imago="http://xenei.org/imago/2002"
    extension-element-prefixes="xcounter"
>
<xsl:template match="document">
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="imago:counter">
    <xcounter:update format="text" /> <!-- update and display -->
    <xcounter:read format="text" /> <!-- display again -->
</xsl:template>
</xsl:stylesheet>


Go to ImagoX Extensions.