butlermh 2003/02/26 07:17:19
Modified: src/documentation/xdocs/developing deli.xml Log: Made some changes to reflect updates to DELI, added code examples Revision Changes Path 1.10 +133 -27 xml-cocoon2/src/documentation/xdocs/developing/deli.xml Index: deli.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/src/documentation/xdocs/developing/deli.xml,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- deli.xml 13 Feb 2003 19:08:36 -0000 1.9 +++ deli.xml 26 Feb 2003 15:17:18 -0000 1.10 @@ -228,19 +228,20 @@ <source><![CDATA[ <?xml version="1.0"?> <deli> - <legacyDeviceFile>resources/deli/config/legacyDevice.xml</legacyDeviceFile> - <debug>false</debug> - <printDefaults>false</printDefaults> - <printProfileBeforeMerge>false</printProfileBeforeMerge> - <schemaVocabularyFile namespace="http://www.wapforum.org/UAPROF/ccppschema-20000405#"> - resources/deli/config/vocab/ccppschema-20000405.rdfs - </schemaVocabularyFile> - <schemaVocabularyFile namespace="http://www.wapforum.org/profiles/UAPROF/ccppschema-20010330#"> - resources/deli/config/vocab/ccppschema-20010330.rdfs - </schemaVocabularyFile> - <vocabularyFile> - resources/deli/config/vocab/uaprof_vocab_30apr2001.xml - </vocabularyFile> + <localProfilesFile>WEB-INF/deli/config/localProfiles.xml</localProfilesFile> + <localProfilesPath>WEB-INF/deli/legacyProfiles</localProfilesPath> + <useLocalProfilesIfNoCCPP>true</useLocalProfilesIfNoCCPP> + <useLocalProfilesInAdditionToCCPP>false</useLocalProfilesInAdditionToCCPP> + <debug>false</debug> + <printDefaults>true</printDefaults> + <printProfileBeforeMerge>false</printProfileBeforeMerge> + <processUndefinedAttributes>true</processUndefinedAttributes> + <useCapabilityClasses>false</useCapabilityClasses> + <capabilityClassFile>WEB-INF/deli/config/capClass.xml</capabilityClassFile> + <namespaceConfigFile>WEB-INF/deli/config/namespaceConfig.xml</namespaceConfigFile> + <!-- note that the default uri is also hardcoded --> + <rdfsUri>http://www.w3.org/1999/PR-rdf-schema-19990303#</rdfsUri> + <rdfsUri>http://www.w3.org/TR/PR-rdf-schema#</rdfsUri> </deli> ]]></source> <p>This file can contain a number of configuration directives described in @@ -315,12 +316,12 @@ <th>Description</th> </tr> <tr> - <td>supportLegacyDevices</td> + <td>useLocalProfilesIfNoCCPP</td> <td>true</td> - <td>Is the legacy device database turned on?</td> + <td>Use the legacy device database if devices send no CC/PP information?</td> </tr> <tr> - <td>legacyDeviceFile</td> + <td>localProfilesFile</td> <td>legacyDevice.xml</td> <td>The file containing the legacy device database.</td> </tr> @@ -400,20 +401,19 @@ By default this is done in the <code>legacyDevice.xml</code> file which has the following format:</p> <source><![CDATA[ -<?xml version="1.0"?> +<?xml version="1.0" encoding="UTF-8"?> <devices> - <legacyDevice> - <useragentstring>MSIE</useragentstring> - <profileref>http://www.profiles.org/legacyProfiles/msie.rdf</profileref> - </legacyDevice> - <legacyDevice> - <useragentstring>mozilla</useragentstring> - <profileref>resources/deli/legacyProfiles/mozSample.rdf</profileref> - </legacyDevice> +<!-- Alcatel --> + <device> + <ua value="Alcatel-BF4/2.0" profile="Alcatel_OT512.rdf"/> + </device> + <device> + <ua value="Alcatel-BE4/1.0" profile="Alcatel_OT301.rdf"/> + </device> </devices> ]]></source> - <p>Where <code>useragentstring</code> is a device unique string found in -the user-agent string of the device and <code>profileref</code> is either a local file or a URL + <p>Where <code>vale</code> is a device unique string found in +the user-agent string of the device and <code>profile</code> is either a local file or a URL for the appropriate legacy profile. </p> </s2> </s1> @@ -483,6 +483,112 @@ </xsl:stylesheet> ]]></source> + </s1> + <s1 title="Incorporating DELI into other Cocoon components"> +<p>If you want to use DELI in other Cocoon components, DELI needs to go through an +initialization phase in order to read in configuration files. This occurs in +<code>initialization()</code> in DeliImpl.java in the Cocoon DELI component in this line:</p> +<source> +Workspace.getInstance().configure(this.servletContext, this.deliConfig); +</source> +<p>i.e. it constructs a DELI workspace object. In addition, DeliImpl.java has a number +of methods to get profile information, but the one which is of most use is <code>getProfile()</code>. +For examples of how to call DELI, see DeliTransformer.java - here are the relevant pieces.</p> + +<p>First import DELI:</p> +<source> +import org.apache.cocoon.components.deli.Deli; +</source> +<p>Then in compose(), initialize DELI:</p> +<source> +if (this.manager.hasComponent(Deli.ROLE)) { + if (this.getLogger().isDebugEnabled()) { + getLogger().debug("Looking up " + Deli.ROLE); +} +this.deli = (Deli) this.manager.lookup(Deli.ROLE); +} else { + if (this.getLogger().isDebugEnabled()) { + getLogger().debug("Deli is not available"); +} +} +</source> +<p> Then in getLogicSheetParameters, call DELI to get +a profile and convert it into a DOM tree to give to XSLT as a parameter:</p> +<source> +if (this.deli != null && this._useDeli) { + try { + Request request = ObjectModelHelper.getRequest(objectModel); + if (map == null) { + map = new HashMap(); + } + + org.w3c.dom.Document deliCapabilities = this.deli.getUACapabilities(request); + map.put("deli-capabilities", deliCapabilities); + } catch (Exception e) { + getLogger().error("Error setting DELI info", e); + } +} +</source> +<p> +However, you don't want to pipe DELI to XSLT so here is some more +example code showing how to use DELI in Cocoon if you want to use the +DELI API directly:</p> + +<p>Import the deli component and the DELI API:</p> +<source> +import org.apache.cocoon.components.deli.Deli; + +import com.hp.hpl.deli.Profile; +import com.hp.hpl.deli.ProfileAttribute; +</source> + +<p>Add code to initialize the compose method as before</p> +<source> + public void compose(ComponentManager manager) throws ComponentException + { + try + { + deli = (Deli)manager.lookup(Deli.ROLE); + } + catch(ComponentException ce) + { + logger.log(Level.ERROR, "Cannot get ref to Deli", ce); + ce.printStackTrace(); + } + } +</source> +<p>Some example code that shows how to extract WmlDeckSize from a +DELI profile</p> +<source> +try +{ + Profile theProfile = deli.getProfile(request); + if(theProfile != null) + { + ProfileAttribute attrib = theProfile.getAttribute("WmlDeckSize"); + if(attrib != null) + { + Vector temp = (Vector)attrib.get(); + if(temp != null) + { + deckSizeString = temp.get(0).toString(); + System.out.println("Determined WmlDeckSize from DELI: " + deckSizeString); + } + } + } + if(deckSizeString == null) + { + deckSizeString = "1100"; + System.out.println("Using fallback WmlDeckSize of " + deckSizeString); + } +} +catch(Exception ex) +{ + System.out.println(ex.toString()); + ex.printStackTrace(); +} +} +</source> </s1> <s1 title="More information ?"> <p>For more information on the DELI library please refer to the