Public API

Java Content Repository API (JSR 283)

The SiteVision model can be accessed using the JSR 283 (Java Content Repository) standard. SiteVision currently supports level 1 of JCR, which means that it is a read-only interface where you can read but not alter data. Currently there are some restrictions to the present level 1 implementation (for more information about what is implemented and what is not see the javax.jcr classes in the SiteVision public API javadocopens in new window. Features that are not implemented are denoted 'Unsupported operation')

For fast and effective access SiteVision data you must have knowledge of the data model tree.

To access the data in the model just define your point of origin and extract the corresponding node from the Session or use the SiteVision specific utilities. With this node as base it is possible to traverse the model tree and retrieve information about nodes and their properties using node and property iterators.

The Java Content Repository specification (JSR 283) can be downloaded from here.

SiteVision Utility API

SiteVision also exposes a supporting API for the JCR implementation in SiteVision that can make your life easier - especially if you use the JCR programming model from Velocity.

The SiteVision Public API can be found hereopens in new window.

Please note that since the API is continuously updated, some methods and JCR properties are only available in the latest version of SiteVision. A tip if you need to do backward compatibility workarounds: you can get the SiteVision version via the system property "sitevision.version" (i.e. System.getProperty("sitevision.version")).

Always check the change log of the SiteVision Public API whenever you upgrade or a new SiteVision version is released.

The SiteVision Public API change log contains information about new fields/methods/interfaces/enums in the API and what's been fixed or deprecated.

Accessing the API

SiteVision makes sure that the JCR session and the utilities are available as attributes in the portlet request at all times.

Example: retrieve the API in a struts-2 portlet

import com.opensymphony.xwork2.ActionContext;
import javax.portlet.PortletRequest;

import javax.jcr.Session;

import org.apache.struts2.dispatcher.DefaultActionSupport;

import senselogic.sitevision.api.Utils;


public class IndexAction extends DefaultActionSupport
{
  public String execute()
  {
    ActionContext ctx = ActionContext.getContext();
    PortletRequest req = (PortletRequest) ctx.get(
       "struts.portlet.request"
    );


    // Retrieve the JCR session
    Session s = (Session) req.getAttribute(
"sitevision.jcr.session"
);

    // Retrieve the SiteVision utils
    Utils u = (Utils) req.getAttribute(
"sitevision.utils"
);

    ...

    return SUCCESS;
  }
}

The JCR session and the utilities are also available in all JCR capable SiteVision portlets that exposes a custom template (e.g. the Menu portlet).

Example: use the API in a JCR capable custom Velocity template

## use the JCR session
$jcrSession.xxxx

## use the SiteVision utils
$sitevisionUtils.xxx

...

Get access to the Public API from a custom portlet

To be able to develop your own portlet that uses the public API, you will need access to the Public API jar-file. It is available in the maven repository (more information about the maven repository is available here).

The class loader hierarchy makes the jar-file available to your portlet when it is deployed in SiteVision. This means that your war-file must never contain this file!

In versions prior to SiteVision 2.6_02 the public api jar was split in two jars (jcr-2.0-public-review.jar and sitevision-api-<version>.jar)!

Denna sida publicerades: 2016-10-03

Skriv ut PDF-avsnitt

Hjälpte informationen på den här sidan dig?

Missa inga nya rön, tips och tricks! Prenumerera på insite!

Find us!

SiteVision AB (Headquarter)
Vasagatan 10
702 10 Orebro
Sweden

Info: +46 19-17 30 30
Support: +46 19-17 30 39

Latest Tweets