--- /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
+\r
+ /*\r
+ *\r
+ */\r
+function XRDFDataSource(){\r
+ this._dataSource;\r
+ this._refDataSource;\r
+}\r
+/*\r
+ * create DataSource RDF with xml file of values\r
+ * xmlDataPath of xml format recognized :\r
+ <ximf:base name="MCA_List">\r
+ <ximf:header>\r
+ <ximf:title>Saaa</ximf:title>\r
+ <description>Subject ....</description>\r
+ <ximf:column>CODE</ximf:column>\r
+ <ximf:column>Description</ximf:column>\r
+ </ximf:header>\r
+ <ximf:tree>\r
+ <ximf:description>\r
+ <ximf:data>ZZZ</ximf:data>\r
+ <ximf:data>My description for this value</ximf:data>\r
+ </ximf:description>\r
+ </ximf:tree>\r
+ </ximf:base>\r
+ */\r
+function CreateRdfDatasSource(xmlDataPath){\r
+ try{\r
+ if (!xmlDataPath) {\r
+ return;\r
+ }\r
+ var domProfile = null;\r
+ var xDataSource = new XRDFDataSource();\r
+ var xmlDoc = GetXmlDocument(xmlDataPath);\r
+ if(xmlDoc){\r
+ domProfile = xmlDoc.documentElement;\r
+ }else{\r
+ gConsole.logStringMessage("[ximfmail - ximfTreeDialog ] \n " + Error.description + "\nfile : " + Error().fileName+"\nline : "+Error().lineNumber);\r
+ return;\r
+ }\r
+ // is valid xml document?\r
+ var baseTag = domProfile.getElementsByTagName("ximf:base");\r
+ if (baseTag.length <= 0) {\r
+ return;\r
+ }\r
+ // init RDF XPCOM Services\r
+ var _rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);\r
+ var _dsCatalog = Components.classes["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"].createInstance(Components.interfaces.nsIRDFDataSource);\r
+ var _rdfCUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].getService(Components.interfaces.nsIRDFContainerUtils);\r
+ // parse XML file and create RDF resources\r
+ var tname = baseTag[0].getAttribute("name");\r
+ var baseURI = "http://www.ximfmail.com/catalog/" + tname;\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 - CreateRdfDatasSource ] \n " + e + "\nfile : " + Error().fileName+"\nline : "+Error().lineNumber);\r
+ }\r
+ var treeTag = baseTag[0].getElementsByTagName("ximf:tree");\r
+ var instanceTag = treeTag[0].getElementsByTagName("ximf: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("ximf: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
+ //create objet result\r
+ xDataSource._dataSource = _dsCatalog;\r
+ xDataSource._refDataSource = datasUri;\r
+ return xDataSource;\r
+ }catch(e){\r
+ gConsole.logStringMessage("[ximfmail - CreateRdfDatasSource ] \n " + e + "\nfile : " + Error().fileName+"\nline : "+Error().lineNumber);\r
+ }\r
+}\r
+/*\r
+ * create DataSource RDF with array of values\r
+ * arrayDatas = [[col0][col1][coln], [col0][col1][coln], [col0][col1][coln], ...]\r
+ * nameSvc = title of box selection\r
+ */\r
+function CreateRdfDatasSource_array(arrayDatas, strTitle){\r
+ try{\r
+ // is valid array document?\r
+ if(arrayDatas.length <= 0){\r
+ return;\r
+ }\r
+ // init RDF XPCOM Services\r
+ var xDataSource = new XRDFDataSource();\r
+ var _rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);\r
+ var _dsCatalog = Components.classes["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"].createInstance(Components.interfaces.nsIRDFDataSource);\r
+ var _rdfCUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].getService(Components.interfaces.nsIRDFContainerUtils);\r
+ // parse XML file and create RDF resources\r
+ var baseURI = "http://www.ximfmail.com/catalog/" + strTitle;\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
+ for(var i = 0; i < arrayDatas.length; ++i){\r
+ // append resource element to sequence\r
+ var newURI = datasUri + "/data" + i;\r
+ RDFC_data.AppendElement(_rdfService.GetResource(newURI));\r
+\r
+ var arrayCols = arrayDatas[i];\r
+ for(var j = 0; j < arrayCols.length; ++j){\r
+ var valData = arrayCols[j];\r
+ if (valData === "") {\r
+ valData = " ";\r
+ }\r
+ // append description element\r
+ _dsCatalog.Assert(_rdfService.GetResource(newURI),\r
+ _rdfService.GetResource("http://www.ximfmail.com/RDF#column"+j),\r
+ _rdfService.GetLiteral(valData),\r
+ true\r
+ );\r
+ }\r
+ }\r
+ //create objet result\r
+ xDataSource._dataSource = _dsCatalog;\r
+ xDataSource._refDataSource = datasUri;\r
+ return xDataSource;\r
+ }catch(e){\r
+ gConsole.logStringMessage("[ximfmail - XimfTreeData.CreateRdfDatasSource ] \n " + e + "\nfile : " + Error().fileName+"\nline : "+Error().lineNumber);\r
+ }\r
+}
\ No newline at end of file