# com.bea.p13n.ad
AdHelper Class

public class AdHelper
extends `Object`
implements `AdConstants`

A set of static methods which perform provide utilities services to the ad package.

Hierarchy
  `Object`
  `AdHelper`

All Implemented Interfaces
  `AdConstants`

## Constructor Summary

AdHelper()

## Method Summary

`public static `String`` | `getAdContent`(`String` adQuery, long identifier, `String` containerUID, `String` contextUID, `String` placeholder, `String` userId, `String` servletBase, `Request` request, `AdService` as, int height, int width) Return the content for an ad Query as an XHTML string.
`public static `AdService`` | `getAdService`() return the currently active AdService EJB
`public static `AdService`` | `getAdService`(`String` name) Get an AdService instance from the specified JNDI name.
`public static `BinaryValue`` | `getBinaryValue`(`Property` p) Get the BinaryValue of the first non-null value of the property.
`public static `Node`` | `getContent`(`AdService` as, `String` path) return the content object for the passed content path.
`public static `Node`` | `getContent`(`AdService` as, `String` path, `Request` request) Return the content object for the passed content path.
`public static `String`` | `getDefaultAdBucketServiceName`() Get the default AdBucketService JNDI name for the current application.
`public static `String`` | `getDefaultAdServiceName`() Get the default AdService JNDI name for the current application.
`public static `AdEventTracker`` | `getEventTracker`() Return the ad event tracker to use.
`public static int` | `getNextRandom`(int max) Return a random number between [0,max)Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value max (exclusive).
`public static `BinaryValue`` | `getPrimaryContentBinaryValue`(`Node` c) Get the BinaryValue of the first non-null value of the node's primary content property.
`public static int` | `getPrimaryFileSize`(`Node` c, int def) Get the size of the primary content property.
`public static `String`` | `getPrimaryMimeType`(`Node` c) Get the mime type of the primary content property.
`public static `Property`` | `getPrimaryProperty`(`Node` c) Get the primary content property to use for rendering.
`public static int` | `getPropertyAsInt`(`Node` c, `String` propName, int def) Utility to retrieve the first value of a content property and convert it (if needed) into an int.
`public static `Object`` | `getPropertyValue`(`Node` c, `String` propName) Utility to retrieve the first non-null Object value of a content property.
`public static `String`` | `getPropertyValueString`(`Node` c, `String` propName) Utility to retrieve the first non-null Object value of a content property as a String.
`public static `AdContentProvider`` | `getRendering`() Return the global ad renderer to use.
`public static `String`` | `pathInfoEncode`(`String` pathInfo) Correctly URLEncode a path-info string.
`public static void` | `raiseClickThruEvent`(`String` userId, `HttpServletRequest` request, `String` containerUID, `String` contextUID, `String` placeholder, `String` contId) Raise a click thru event with the AdEventTracker
`public static void` | `raiseDisplayEvent`(`String` userId, `HttpServletRequest` request, `String` containerUID, `String` contextUID, `String` placeholder, `String` contId) Raise an display event with the AdEventTracker.
`public static `String`` | `toHTML`(`String` in) Convert an arbitrary string to HTML which will display as the original string intended.

Methods from class `java.lang.`Object``
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Detail

### AdHelper

    public AdHelper()

## Method Detail

### getAdContent(String, long, String, String, String, String, String, Request, AdService, int, int) Method

DEPRECATED This method moved to `com.bea.p13n.ad.AdService.getAdContent(com.bea.p13n.expression.Expression, long, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, com.bea.p13n.http.Request, int, int)```.

    public static String getAdContent(String adQuery,
                                      long identifier,
                                      String containerUID,
                                      String contextUID,
                                      String placeholder,
                                      String userId,
                                      String servletBase,
                                      Request request,
                                      AdService as,
                                      int height,
                                      int width)
         throws AdContentException, CreateException

Return the content for an ad Query as an XHTML string.

#### Parameters

adQuery
  the content management query

identifier
  a indentifier for the content bucket the query is from

containerUID
  the UID of the container

contextUID
  the UID of the context

placeholder
  the name of the placeholder

userId
  the user Id

servletBase
  the Web App root for the click thru servlet

request
  the HTTP request

as
  the AdService EJB

height
  the suggested content height

width
  the suggested content width

#### Returns

an XHMLT content descrption for the ad

#### Exceptions

``AdContentException``
  if there is a problem getting the content
``CreateException``

### getAdService() Method

DEPRECATED Use <ejb-ref> instead.

    public static AdService getAdService()
         throws NamingException, CreateException

return the currently active AdService EJB

#### Exceptions

``NamingException``
``CreateException``

### getAdService(String) Method

    public static AdService getAdService(String name)
         throws NamingException, CreateException

Get an AdService instance from the specified JNDI name.

#### Exceptions

``NamingException``
``CreateException``

### getBinaryValue(Property) Method

    public static BinaryValue getBinaryValue(Property p)

Get the BinaryValue of the first non-null value of the property.

#### Returns

null on no non-null binary value.

### getContent(AdService, String) Method

DEPRECATED Use getContent(AdService, String, Request) instead.

    public static Node getContent(AdService as,
                                  String path)

return the content object for the passed content path.

#### Parameters

as
  the AdService EJB

path
  the path of the content being requested

#### Returns

a Node object if the content is found, null otherwise.

Related Topics

``AdHelper.getContent(AdService, String, Request)``

### getContent(AdService, String, Request) Method

    public static Node getContent(AdService as,
                                  String path,
                                  Request request)

Return the content object for the passed content path.

#### Parameters

as
  the AdService EJB

path
  the path of the content being requested

#### Returns

a Node object if the content is found, null otherwise.

### getDefaultAdBucketServiceName() Method

    public static String getDefaultAdBucketServiceName()

Get the default AdBucketService JNDI name for the current application.

### getDefaultAdServiceName() Method

    public static String getDefaultAdServiceName()

Get the default AdService JNDI name for the current application.

### getEventTracker() Method

DEPRECATED No longer publically available.

    public static AdEventTracker getEventTracker()

Return the ad event tracker to use.

This will access the `AdServiceMBean``` for the class name of the AdEventTracker to use.

### getNextRandom(int) Method

DEPRECATED No longer used here (use java.util.Random)

    public static int getNextRandom(int max)

Return a random number between [0,max)Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value max (exclusive).

#### Parameters

max
  the max number to return

### getPrimaryContentBinaryValue(Node) Method

    public static BinaryValue getPrimaryContentBinaryValue(Node c)
         throws RepositoryException

Get the BinaryValue of the first non-null value of the node's primary content property.

#### Returns

null on no non-null binary value.

#### Exceptions

``RepositoryException``

Related Topics

``AdHelper.getPrimaryProperty(Node)``

### getPrimaryFileSize(Node, int) Method

    public static int getPrimaryFileSize(Node c,
                                         int def)
         throws RepositoryException

Get the size of the primary content property. If the primary property is not binary then return the number of `Value` objects contained in the primary `Property`. If the primary property is binary then return the file size of the first non-null `BinaryValue`. If the primary property is binary and a non-null `BinaryValue`s can not be found or no primary property can be found then the value of the parameter `def` is returned.

#### Parameters

c
  the content object.

def
  the value to return if the primary property is binary and a `BinaryValue` can't be found.

#### Returns

the size. If the primary property is not binary then return the number of `Value`s for the primary. If the primary property is binary then return the file size of the first non-null `BinaryValue`. If no primary property can be found or if the primary property is binary and no non-null `BinaryValue`s can be found, then `def` is returned.

#### Exceptions

``RepositoryException``

Related Topics

``AdHelper.getPrimaryProperty(Node)``
``AdHelper.getBinaryValue(Property)``

### getPrimaryMimeType(Node) Method

    public static String getPrimaryMimeType(Node c)
         throws RepositoryException

Get the mime type of the primary content property. If the primary property is not binary then `text/plain` will be returned. If the primary property is a binary property then the mime type of the first non-null `BinaryValue` will be returned. If the primary property is binary but does not contain a non-null `BinaryValue`, null will be returned.

#### Parameters

c
  the content object.

#### Returns

the mimeType. `text/plain` is returned if the primary property is not binary. If the primary property is binary then return the mime type of the first non-null binary or null if no non-null `BinaryValue` is found.

#### Exceptions

``RepositoryException``

Related Topics

``AdHelper.getPrimaryProperty(Node)``
``AdHelper.getBinaryValue(Property)``

### getPrimaryProperty(Node) Method

    public static Property getPrimaryProperty(Node c)
         throws RepositoryException

Get the primary content property to use for rendering. This will return the Node's primary property. If not set, it will find the first binary property. If no binary properties, it will find the first String property. Otherwise, it will return null.

#### Exceptions

``RepositoryException``

### getPropertyAsInt(Node, String, int) Method

    public static int getPropertyAsInt(Node c,
                                       String propName,
                                       int def)
         throws RepositoryException

Utility to retrieve the first value of a content property and convert it (if needed) into an int.

#### Parameters

c
  the content object

propName
  the name of the content propery.

def
  the default value to return if the property doesn't exist or doesn't have any values or isn't a number or can't be converted to a nubmer

#### Returns

the int value, or def.

#### Exceptions

``RepositoryException``

### getPropertyValue(Node, String) Method

    public static Object getPropertyValue(Node c,
                                          String propName)
         throws RepositoryException

Utility to retrieve the first non-null Object value of a content property.

#### Returns

the object value (e.g. Value.getValue()), or null if not Values for properties.

#### Exceptions

``RepositoryException``

### getPropertyValueString(Node, String) Method

    public static String getPropertyValueString(Node c,
                                                String propName)
         throws RepositoryException

Utility to retrieve the first non-null Object value of a content property as a String.

#### Returns

the object value (e.g. Value.getValue().toString()), or null if not Values for properties.

#### Exceptions

``RepositoryException``

### getRendering() Method

DEPRECATED No longer publically available.

    public static AdContentProvider getRendering()

Return the global ad renderer to use.

This will access the `AdServiceMBean``` for the class name of the AdContentProvider to use.

### pathInfoEncode(String) Method

    public static String pathInfoEncode(String pathInfo)

Correctly URLEncode a path-info string.

This can be used to pass a contentId as Path-Info to the ShowDocServlet.

This will url encode the pathInfo, but will leave "/"'s alone.

### raiseClickThruEvent(String, HttpServletRequest, String, String, String, String) Method

DEPRECATED No longer publically available.

    public static void raiseClickThruEvent(String userId,
                                           HttpServletRequest request,
                                           String containerUID,
                                           String contextUID,
                                           String placeholder,
                                           String contId)

Raise a click thru event with the AdEventTracker

#### Parameters

userId
  the user Id

request
  the HTTP request

containerUID
  the UID for the container

contextUID
  the UID for the context

placeholder
  the name of the placeholder

contId
  the content identifier

### raiseDisplayEvent(String, HttpServletRequest, String, String, String, String) Method

DEPRECATED No longer publically available.

    public static void raiseDisplayEvent(String userId,
                                         HttpServletRequest request,
                                         String containerUID,
                                         String contextUID,
                                         String placeholder,
                                         String contId)

Raise an display event with the AdEventTracker.

#### Parameters

userId
  the user Id

request
  the HTTP request

containerUID
  the UID for the container

contextUID
  the UID for the context

placeholder
  the name of the placeholder

contId
  the content identifier

### toHTML(String) Method

    public static String toHTML(String in)

Convert an arbitrary string to HTML which will display as the original string intended.

This will replace the characters '&', '"', '<', and '>' with '&amp;', &quot;', '&lt;', and '&gt;', respectively.