Extending : Channel policy management and extension : Extending the NavigationEngine class
  
Extending the NavigationEngine class
The updateLocale4Popup(page) and updateLocale4Page(page) functions are provided in the com.ibm.btt.event.NavigationEngine class for catching the application locale and parsing the local parameter in general pages and popup pages.
To extend the NavigationEngine class, complete the following steps:
1 Create the test.MyNavigationEngine.js class, and then overwrite the updateLocale4Popup and updateLocale4Page functions.
The following codes show an example.
dojo.provide("test.MyNavigationEngine");
dojo.require("com.ibm.btt.event.NavigationEngine");
dojo.declare("test.MyNavigationEngine", [ com.ibm.btt.event.NavigationEngine ], {

updateLocale4Popup: function(page){
console.log("==========enter MyNavigationEngine- updateLocale4Popup=========");
// Update locale for new page
var test = page.match(/locale:'(.*)'/);
if(test){
var newlocale = test[1];
if(newlocale.length >= 2){
if(djConfig.locale != newlocale || dojo.locale != newlocale){
var old1 = djConfig.locale;
var old2 = dojo.locale;
if(!this._loadedLocales){
this._loadedLocales = [];
}
if(old1 != old2){
this._loadedLocales.push(old1);
this._loadedLocales.push(old2);
}else{
this._loadedLocales.push(old1);
}
djConfig.locale = newlocale;
dojo.locale = newlocale;
console.debug("djConfig.locale : " + old1);
console.debug("dojo.locale : " + old2);
console.debug("new locale : " + newlocale);

for(var module in dojo._loadedModules){
var modulename = "" + module;
var ms = modulename.split(".nls.");
if(ms && ms.length >= 2){
if( !this._containsLocale(ms[1]) && newlocale != "ROOT"){
// console.debug("Loading new bundle : " + modulename + " " + newlocale);
try{
dojo.requireLocalization(ms[0], ms[1], newlocale, "", "");
}catch(e){
console.debug("Fail to load : " + modulename + " " + newlocale);
}
}
}
}
}
}
}
},

updateLocale4Page : function(page){
// Update locale for new page
var test = page.match(/locale:'(.*)'/);
console.log("==========enter MyNavigationEngine- updateLocale4Page=========");
if(test){
var newlocale = test[1];
if(newlocale && newlocale.length > 1){
if(djConfig.locale != newlocale || dojo.locale != newlocale){
var old1 = djConfig.locale;
var old2 = dojo.locale;
if(!this._loadedLocales){
this._loadedLocales = [];
}
if(old1 != old2){
this._loadedLocales.push(old1);
this._loadedLocales.push(old2);
}else{
this._loadedLocales.push(old1);
}
djConfig.locale = newlocale;
dojo.locale = newlocale;



console.debug("djConfig.locale : " + old1);
console.debug("dojo.locale : " + old2);
console.debug("new locale : " + newlocale);

for(var module in dojo._loadedModules){
var modulename = "" + module;
var ms = modulename.split(".nls.");
if(ms && ms.length >= 2){
if( !this._containsLocale(ms[1]) && newlocale != "ROOT"){
// console.debug("Loading new bundle : " + modulename + " " + newlocale);
try{
dojo.requireLocalization(ms[0], ms[1], newlocale, "", "");
}catch(e){
console.debug("Fail to load : " + modulename + " " + newlocale);
}
}
}
}
}

var localeValues = newlocale.split("-");
if(localeValues && localeValues[0]) {
var language = localeValues[0];
var htmlTag = document.getElementsByTagName('html')[0];
if(htmlTag.getAttribute('lang')) {
htmlTag.setAttribute('lang', language);
}

if(htmlTag.getAttribute('xml:lang')) {
htmlTag.setAttribute('xml:lang', language);
}
}
}
}
}

});
2 Update the template.ftl file or template_debug.ftl file:
Add MyNavigationEngine.js as the import js.
The following codes show an example.
<script type="text/javascript" src="js/dojo/dojo_BTT.js"></script>
<script type="text/javascript" src="js/com/ibm/btt/btt.js"></script><script type="text/javascript" src="js/test/MyNavigationEngine.js"></script>
Set MyNavigationEngine as the Engine instance.
The following codes show an example.
<script type="text/javascript">
if(!BTT.engine){
<%if(utb.ajaxNavigationEnabled()){%>
Engine.setInstance(new test.MyNavigationEngine()); BTT.engine = Engine.getInstance();
Engine.getInstance()._sessionId = "<%=request.getSession().getId()%>";
<%}else{%>
</script>
3 Rebuild and deploy the project.
For sample codes for extending the NavigationEngine class, see Reference.
See also
Channel policy management and extension