Milyn-Smooks Version 0.4

org.milyn.cdr
Class CDRDef

java.lang.Object
  extended byorg.milyn.cdr.CDRDef

public class CDRDef
extends java.lang.Object

Content Delivery Resource Definition.

Represents an instance of the <cdres> element within a .cdrl file (Content Delivery Resource List file). The .cdrl DTD can be seen at http://www.milyn.org/dtd/cdres-list-1.0.dtd

An instance of this class defines the following attributes of a Content Delivery Resource from a .cdrl file:

The following is a sample showing the basic structure of the .cdrl file.
 <?xml version='1.0'?>
 <!DOCTYPE cdres-list PUBLIC '-//MILYN//DTD SMOOKS 1.0//EN' 'http://www.milyn.org/dtd/cdres-cdres-list-1.0.dtd 
 <cdres-list>
 	<cdres uatarget="value" selector="value" path="value"/>
 </cdres-list>

All of the <cdres> attributes can be defaulted on the enclosing <cdres-list> element. Just prefix the attribute name with "default-". Example:

 <?xml version='1.0'?>
 <!DOCTYPE cdres-list PUBLIC '-//MILYN//DTD SMOOKS 1.0//EN' 'http://www.milyn.org/dtd/cdres-liscdres-list-1.0.dtd * <cdres-list default-uatarget="value" default-selector="value" >
 	<cdres path="value"/>
 </cdres-list>

Resource Targeting

Content Delivery Resources are targeted using a combination of the uatarget and selector attributes (see above).

Smooks does this at runtime by building (and caching) a table of resources per requesting device/browser type. When Smooks receives a request it uses the device recognition and profiling information provided by Tinak to iterate over the .cdrl configurations and select the definitions that apply to that browser type. It evaluates this based on the uatarget attribute value. Once the table is built it is cached so it doesn't need to be rebuilt for future requests from this browser type.

Once the resource table is built Smooks can "lookup" resources (during the content delivery process) based on the selector attribute value. As you'll probably notice, the types of configurations that the .cdrl file permits can/will result in multiple resources being mapped to a browser under the same "selector" value i.e. if you request the resource by selector "x", there may be 1+ matches. Because of this Smooks sorts these matches based on what we call the definitions "specificity" (a term stollen from the CSS spec :-). See CDRDefSortComparator.

<param> Elements

As can be seen from the DTD, the <cdres> element can also define zero or more <param> elements. These elements allow runtime parameters to be passed to content delivery units. This element defines a single mandatory attribute called "name". The parameter value is inclosed in the param element e.g.
 <?xml version='1.0'?>
 <!DOCTYPE cdres-list PUBLIC '-//MILYN//DTD SMOOKS 1.0//EN' 'http://www.milyn.org/dtd/cdres-list-1.0.cdres-list-1.0.dtd;cdres-list default-uatarget="value" default-selector="value" >
 	<cdres path="value">
 		<param name="paramname">paramval</param>
 	</cdres>
 </cdres-list>

Content Delivery Resources

<cdres>s can also be used to define Content Delivery Resources other than ContentDeliveryUnits (AssemblyUnits, TransUnits and SerializationUnits). In this case the type attribute is not required. This "feature" is used by Smooks to target specific DTD and DOCTYPE header files at specific browsers e.g.
 <?xml version='1.0'?>
 <!DOCTYPE cdres-list PUBLIC '-//MILYN//DTD SMOOKS 1.0//EN' 'http://www.milyn.org/dtd/cdres-list-1.0.dtdcdres-list-1.0.dtdres-list>
 	<!--	
 		Note: 
 		1. 	"wml11" is a browser profile.
 	-->
 	<cdres uatarget="wml11" selector="doctype" path="www.wapforum.org/DTD/wml_1_1.doctype" />
 	<cdres uatarget="wml11" selector="dtd" path="www.wapforum.org/DTD/wml_1_1.dtd"" />
 </cdres-list>
This feature could be used by AssemblyUnits, TransUnits and SerializationUnits to load other resources. See ContentDeliveryConfig.getObjects(String) and ContentDeliveryConfig.getCDRDefs(String).

Author:
tfennelly
See Also:
CDRDefSortComparator

Nested Class Summary
static class CDRDef.Parameter
          CDRDef Parameter.
 
Field Summary
static java.lang.String XML_DEF_PREFIX
          XML selector type definition prefix
 
Constructor Summary
CDRDef(java.lang.String selector, java.lang.String uatargets, java.lang.String path)
          Public constructor.
 
Method Summary
 boolean getBoolParameter(java.lang.String name, boolean defaultVal)
          Get the named CDRDef parameter as a boolean.
 CDRDef.Parameter getParameter(java.lang.String name)
          Get the named CDRDef parameter.
 int getParameterCount()
          Get the CDRDef parameter count.
 java.lang.String getPath()
          Get the cdrar path of the Content Delivery Resource for this CDRDef.
 java.lang.String getSelector()
          Get the selector definition for this CDRDef.
 java.lang.String getStringParameter(java.lang.String name)
          Get the named CDRDef parameter.
 java.lang.String getStringParameter(java.lang.String name, java.lang.String defaultVal)
          Get the named CDRDef parameter.
 java.lang.String[] getUaTargets()
          Get the device/profile uaTargets for this CDRDef.
 boolean isXmlDef()
          Is this selector defininition an XML based definition.
 void setParameter(java.lang.String name, java.lang.String value)
          Set the named CDRDef parameter value (default type - String).
 void setParameter(java.lang.String name, java.lang.String type, java.lang.String value)
          Set the named CDRDef parameter value (with type).
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

XML_DEF_PREFIX

public static final java.lang.String XML_DEF_PREFIX
XML selector type definition prefix

Constructor Detail

CDRDef

public CDRDef(java.lang.String selector,
              java.lang.String uatargets,
              java.lang.String path)
Public constructor.

Parameters:
selector - The selector definition.
uatargets - The device/profile uaTargets - comma separated uaTargets.
path - The cdrar path of the Content Delivery Resource.
Method Detail

getSelector

public java.lang.String getSelector()
Get the selector definition for this CDRDef.

Returns:
The selector definition.

getUaTargets

public java.lang.String[] getUaTargets()
Get the device/profile uaTargets for this CDRDef.

Returns:
The device/profile uaTargets.

getPath

public java.lang.String getPath()
Get the cdrar path of the Content Delivery Resource for this CDRDef.

Returns:
The cdrar path.

setParameter

public void setParameter(java.lang.String name,
                         java.lang.String value)
Set the named CDRDef parameter value (default type - String).

Overwrites previous value of the same name.

Parameters:
name - Parameter name.
value - Parameter value.

setParameter

public void setParameter(java.lang.String name,
                         java.lang.String type,
                         java.lang.String value)
Set the named CDRDef parameter value (with type).

Overwrites previous value of the same name.

Parameters:
name - Parameter name.
type - Parameter type.
value - Parameter value.

getParameter

public CDRDef.Parameter getParameter(java.lang.String name)
Get the named CDRDef parameter.

Parameters:
name - Name of parameter to get.
Returns:
Parameter value, or null if not set.

getStringParameter

public java.lang.String getStringParameter(java.lang.String name)
Get the named CDRDef parameter.

Parameters:
name - Name of parameter to get.
Returns:
Parameter value, or null if not set.

getStringParameter

public java.lang.String getStringParameter(java.lang.String name,
                                           java.lang.String defaultVal)
Get the named CDRDef parameter.

Parameters:
name - Name of parameter to get.
defaultVal - The default value to be returned if there are no parameters on the this CDRDef instance, or the parameter is not defined.
Returns:
Parameter value, or defaultVal if not defined.

getBoolParameter

public boolean getBoolParameter(java.lang.String name,
                                boolean defaultVal)
Get the named CDRDef parameter as a boolean.

Parameters:
name - Name of parameter to get.
defaultVal - The default value to be returned if there are no parameters on the this CDRDef instance, or the parameter is not defined.
Returns:
true if the parameter is set to true, defaultVal if not defined, otherwise false.

getParameterCount

public int getParameterCount()
Get the CDRDef parameter count.

Returns:
Number of parameters defined on this CDRDef.

isXmlDef

public boolean isXmlDef()
Is this selector defininition an XML based definition.

I.e. is the selector attribute value prefixed with "xmldef:".

Returns:
True if this selector defininition is an XML based definition, otherwise false.

toString

public java.lang.String toString()

Milyn-Smooks Version 0.4