--- /dev/null
+/* ***** BEGIN LICENSE BLOCK *****\r
+ * Copyright (c) 2008-2009 EADS DEFENCE AND SECURITY - All rights reserved.\r
+ * ximfmail is under the triple license MPL 1.1/GPL 2.0/LGPL 2.1.\r
+ *\r
+ *\r
+ * Redistribution and use, in source and binary forms, with or without modification,\r
+ * are permitted provided that the following conditons are met :\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright notice,\r
+ * 2. MPL 1.1/GPL 2.0/LGPL 2.1. license agreements must be attached\r
+ * in the redistribution of the source code.\r
+ * 3. Neither the names of the copyright holders nor the names of any contributors\r
+ * may be used to endorse or promote products derived from this software without specific\r
+ * prior written permission from EADS Defence and Security.\r
+ *\r
+ * Alternatively, the contents of this file may be used under the terms of\r
+ * either of the GNU General Public License Version 2 or later (the "GPL"),\r
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),\r
+ * in which case the provisions of the GPL or the LGPL are applicable instead\r
+ * of those above. If you wish to allow use of your version of this file only\r
+ * under the terms of either the GPL or the LGPL, and not to allow others to\r
+ * use your version of this file under the terms of the MPL, indicate your\r
+ * decision by deleting the provisions above and replace them with the notice\r
+ * and other provisions required by the GPL or the LGPL. If you do not delete\r
+ * the provisions above, a recipient may use your version of this file under\r
+ * the terms of any one of the MPL, the GPL or the LGPL.\r
+ *\r
+ * REMINDER :\r
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\r
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\r
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * EADS Defence and Security - 1 Boulevard Jean Moulin -\r
+ * ZAC de la Clef Saint Pierre - 78990 Elancourt - FRANCE (IDDN.FR.001.480012.002.S.P.2008.000.10000)\r
+ *\r
+ * Contributor(s):\r
+ * Copyright(c) Airbus Defence and Space 2014 - All rights reserved\r
+ * ***** END LICENSE BLOCK ***** */\r
+var gConsole = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);\r
+var CHROME_XIMFMAIL_TREEDATA = "chrome://theme_ximfmail/content/ximfTreeData.rdf";\r
+var gRelativeXimfTreePath = "extensions/{A627B834-BD9F-4b3f-9AF5-347B5A570402}/chrome/content/theme/ximfTreeDataBck.rdf";\r
+/*\r
+ *\r
+ */\r
+function XimfTreeData(){\r
+ // private:\r
+ var _rdfService = null;\r
+ var _rdfCUtils = null;\r
+ var _dsCatalog = null;\r
+ var _rootNode = null;\r
+ var _urlCatalog = CHROME_XIMFMAIL_TREEDATA;\r
+ // instance counter for index RDF file\r
+ var _instanceCounter = 0;\r
+ function init(){\r
+ try{\r
+ if (!_rdfService) {\r
+ _rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);\r
+ }\r
+ if(!_dsCatalog){\r
+ _dsCatalog = Components.classes["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"].createInstance(Components.interfaces.nsIRDFDataSource);\r
+\r
+ }\r
+ if (!_rdfCUtils) {\r
+ _rdfCUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].getService(Components.interfaces.nsIRDFContainerUtils);\r
+ }\r
+ }catch(e){\r
+ gConsole.logStringMessage("[ximfmail - XimfTreeData.init ] \n " + e + "\nfile : " + e.fileName+"\nline : "+e.lineNumber);\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+ // public:\r
+ if (typeof XimfTreeData.initialized === "undefined") {\r
+ /*\r
+ * read infomations from catalog\r
+ */\r
+ XimfTreeData.prototype.getTarget = function(instance,predicate){\r
+ try {\r
+ init();\r
+ var resource = _rdfService.GetResource(instance);\r
+ var targets = _dsCatalog.ArcLabelsOut(resource);\r
+ while (targets.hasMoreElements()) {\r
+ var newpredicate = targets.getNext();\r
+ if (newpredicate instanceof Components.interfaces.nsIRDFResource) {\r
+ var target = _dsCatalog.GetTarget(resource, newpredicate, true);\r
+ if (target instanceof Components.interfaces.nsIRDFLiteral && newpredicate.Value === predicate) {\r
+ return target.Value;\r
+ }\r
+ }\r
+ }\r
+ } catch(e) {\r
+ gConsole.logStringMessage("[ximfmail - XimfTreeData.getTarget ] \n " + e + "\nfile : " + e.fileName+"\nline : "+e.lineNumber);\r
+ }\r
+ };\r
+ /*\r
+ * create catalog with profile xml informations\r
+ */\r
+ XimfTreeData.prototype.registerXimfmailProfileNode = function(domProfile){\r
+ try{\r
+ // create Seq container\r
+ init();\r
+ // create our root nodes\r
+ var seqCatalog = _rdfService.GetResource("http://www.ximfmail.com/catalog");\r
+ var RDFC_Cat = null;\r
+ try{\r
+ RDFC_Cat = _rdfCUtils.MakeSeq(_dsCatalog, seqCatalog);\r
+ }catch(e){\r
+ gConsole.logStringMessage("[ximfmail - XimfTreeData.registerXimfmailProfileNode ] \n " + e + "\nfile : " + Error().fileName+"\nline : "+Error().lineNumber);\r
+ }\r
+ var baseTag = domProfile.getElementsByTagName("base");\r
+ if (baseTag.length <= 0) {\r
+ return;\r
+ }\r
+ var tname = baseTag[0].getAttribute("name");\r
+ var baseURI = "http://www.ximfmail.com/catalog/" + tname;\r
+ try{\r
+ RDFC_Cat.AppendElement(_rdfService.GetResource(baseURI));\r
+ }catch(e){\r
+ gConsole.logStringMessage("[ximfmail - XimfTreeData.registerXimfmailProfileNode ] \n " + e + "\nfile : " + Error().fileName+"\nline : "+Error().lineNumber);\r
+ }\r
+ _dsCatalog.Assert(_rdfService.GetResource(baseURI),\r
+ _rdfService.GetResource("http://www.ximfmail.com/RDF#name"),\r
+ _rdfService.GetLiteral(tname), true);\r
+ _dsCatalog.Assert(_rdfService.GetResource(baseURI),\r
+ _rdfService.GetResource("http://www.ximfmail.com/RDF#dialogheader"),\r
+ _rdfService.GetLiteral(baseURI+"/dialogheader"), true);\r
+ _dsCatalog.Assert(_rdfService.GetResource(baseURI),\r
+ _rdfService.GetResource("http://www.ximfmail.com/RDF#datas"),\r
+ _rdfService.GetLiteral(baseURI+"/datas"), true);\r
+ // Create dialogheader description\r
+ var dlgUri = baseURI + "/dialogheader";\r
+ var seqNode = _rdfService.GetResource(dlgUri);\r
+ var RDFC_Dgh = null;\r
+ RDFC_Dgh = _rdfCUtils.MakeSeq(_dsCatalog, seqNode);\r
+ RDFC_Dgh.AppendElement(_rdfService.GetResource(dlgUri));\r
+ var headerTag = baseTag[0].getElementsByTagName("header");\r
+ // append tiltle element <ximf:title>MCA</ximf:title>\r
+ var title = headerTag[0].getElementsByTagName("title");\r
+ _dsCatalog.Assert(_rdfService.GetResource(dlgUri),\r
+ _rdfService.GetResource("http://www.ximfmail.com/RDF#title"),\r
+ _rdfService.GetLiteral(title[0].textContent), true);\r
+ // append description element <ximf:descritpion>Mentions et clés d'attribution</ximf:descritpion>\r
+ var descritpion = headerTag[0].getElementsByTagName("description");\r
+ _dsCatalog.Assert(_rdfService.GetResource(dlgUri),\r
+ _rdfService.GetResource("http://www.ximfmail.com/RDF#description"),\r
+ _rdfService.GetLiteral(descritpion[0].textContent), true);\r
+ // append title colonne <ximf:column>clé</ximf:column>\r
+ var columnTag = headerTag[0].getElementsByTagName("column");\r
+ for(var x = 0; x < columnTag.length; ++x){\r
+ // append description element\r
+ _dsCatalog.Assert(_rdfService.GetResource(dlgUri),\r
+ _rdfService.GetResource("http://www.ximfmail.com/RDF#column"+x),\r
+ _rdfService.GetLiteral(columnTag[x].textContent), true);\r
+ }\r
+ // Create datas descritpion\r
+ var datasUri = baseURI + "/datas";\r
+ var seqNode = _rdfService.GetResource(datasUri);\r
+ var RDFC_data = null;\r
+ try{\r
+ RDFC_data = _rdfCUtils.MakeSeq(_dsCatalog, seqNode);\r
+ }catch(e){\r
+ gConsole.logStringMessage("[ximfmail - XimfTreeData.registerXimfmailProfileNode ] \n " + e + "\nfile : " + Error().fileName+"\nline : "+Error().lineNumber);\r
+ }\r
+ // add datas from xml profile to RDF file\r
+ var treeTag = baseTag[0].getElementsByTagName("tree");\r
+ var instanceTag = treeTag[0].getElementsByTagName("description");\r
+ for(var i = 0; i < instanceTag.length; ++i){\r
+ // append resource element to sequence\r
+ var newURI = datasUri + "/data" + i;\r
+ RDFC_data.AppendElement(_rdfService.GetResource(newURI));\r
+ var instanceTagData = instanceTag[i].getElementsByTagName("data");\r
+ for(var j = 0; j < instanceTagData.length; ++j){\r
+ // append description element\r
+ _dsCatalog.Assert(_rdfService.GetResource(newURI),\r
+ _rdfService.GetResource("http://www.ximfmail.com/RDF#column"+j),\r
+ _rdfService.GetLiteral(instanceTagData[j].textContent), true);\r
+ }\r
+ }\r
+ }catch(e){\r
+ gConsole.logStringMessage("[ximfmail - XimfTreeData.registerXimfmailProfileNode ] \n " + e + "\nfile : " + Error().fileName+"\nline : "+Error().lineNumber);\r
+ }\r
+ };\r
+ XimfTreeData.prototype.getTitleHeader = function(key){\r
+ var uri = "http://www.ximfmail.com/catalog/"+ key + "/dialogheader";\r
+ return this.getTarget(uri,"http://www.ximfmail.com/RDF#title");\r
+ };\r
+ XimfTreeData.prototype.getDescriptionHeader = function(key){\r
+ var uri = "http://www.ximfmail.com/catalog/"+ key + "/dialogheader";\r
+ return this.getTarget(uri,"http://www.ximfmail.com/RDF#description");\r
+ };\r
+ XimfTreeData.prototype.getTitleColumn = function(key,idx){\r
+ var uri = "http://www.ximfmail.com/catalog/"+ key + "/dialogheader";\r
+ return this.getTarget(uri,"http://www.ximfmail.com/RDF#column"+idx);\r
+ };\r
+ XimfTreeData.initialized = true;\r
+ }\r
+}
\ No newline at end of file