1 /** 2 * Copyright (C) 2012-2013 KO GmbH <copyright@kogmbh.com> 3 * 4 * @licstart 5 * This file is part of WebODF. 6 * 7 * WebODF is free software: you can redistribute it and/or modify it 8 * under the terms of the GNU Affero General Public License (GNU AGPL) 9 * as published by the Free Software Foundation, either version 3 of 10 * the License, or (at your option) any later version. 11 * 12 * WebODF is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU Affero General Public License for more details. 16 * 17 * You should have received a copy of the GNU Affero General Public License 18 * along with WebODF. If not, see <http://www.gnu.org/licenses/>. 19 * @licend 20 * 21 * @source: http://www.webodf.org/ 22 * @source: https://github.com/kogmbh/WebODF/ 23 */ 24 25 /*global odf*/ 26 27 /** 28 * Singleton object which provides namespace ids and 29 * some utility methods related to prefixes and namespaces 30 * @const 31 */ 32 odf.Namespaces = { 33 namespaceMap: { 34 config: "urn:oasis:names:tc:opendocument:xmlns:config:1.0", 35 db: "urn:oasis:names:tc:opendocument:xmlns:database:1.0", 36 dc: "http://purl.org/dc/elements/1.1/", 37 dr3d: "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0", 38 draw: "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0", 39 chart: "urn:oasis:names:tc:opendocument:xmlns:chart:1.0", 40 fo: "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0", 41 form: "urn:oasis:names:tc:opendocument:xmlns:form:1.0", 42 math: "http://www.w3.org/1998/Math/MathML", 43 meta: "urn:oasis:names:tc:opendocument:xmlns:meta:1.0", 44 number: "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0", 45 office: "urn:oasis:names:tc:opendocument:xmlns:office:1.0", 46 presentation: "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0", 47 style: "urn:oasis:names:tc:opendocument:xmlns:style:1.0", 48 svg: "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0", 49 table: "urn:oasis:names:tc:opendocument:xmlns:table:1.0", 50 text: "urn:oasis:names:tc:opendocument:xmlns:text:1.0", 51 xforms: "http://www.w3.org/2002/xforms", 52 xlink: 'http://www.w3.org/1999/xlink', 53 xml: "http://www.w3.org/XML/1998/namespace" 54 }, 55 /**@type{!Object.<string,string>}*/ 56 prefixMap: {}, 57 configns: "urn:oasis:names:tc:opendocument:xmlns:config:1.0", 58 dbns: "urn:oasis:names:tc:opendocument:xmlns:database:1.0", 59 dcns: "http://purl.org/dc/elements/1.1/", 60 dr3dns: "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0", 61 drawns: "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0", 62 chartns: "urn:oasis:names:tc:opendocument:xmlns:chart:1.0", 63 fons: "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0", 64 formns: "urn:oasis:names:tc:opendocument:xmlns:form:1.0", 65 mathns: "http://www.w3.org/1998/Math/MathML", 66 metans: "urn:oasis:names:tc:opendocument:xmlns:meta:1.0", 67 numberns: "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0", 68 /** 69 * @const 70 * @type{string} 71 */ 72 officens: "urn:oasis:names:tc:opendocument:xmlns:office:1.0", 73 presentationns: "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0", 74 stylens: "urn:oasis:names:tc:opendocument:xmlns:style:1.0", 75 svgns: "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0", 76 tablens: "urn:oasis:names:tc:opendocument:xmlns:table:1.0", 77 textns: "urn:oasis:names:tc:opendocument:xmlns:text:1.0", 78 xformsns: "http://www.w3.org/2002/xforms", 79 xlinkns: 'http://www.w3.org/1999/xlink', 80 xmlns: "http://www.w3.org/XML/1998/namespace" 81 }; 82 83 (function () { 84 "use strict"; 85 // map namespacemap to prefix map on startup 86 var map = odf.Namespaces.namespaceMap, 87 /**@type{!Object.<string,string>}*/ 88 pmap = odf.Namespaces.prefixMap, 89 /**@type{string}*/ 90 prefix; 91 92 for (prefix in map) { 93 if (map.hasOwnProperty(prefix)) { 94 pmap[map[prefix]] = prefix; 95 } 96 } 97 }()); 98 99 /** 100 * Calls the passed callback for all pairs of prefix and namespace 101 * which are in the namespaceMap property 102 * @param {function(string,string):undefined} cb 103 * @return {undefined} 104 */ 105 odf.Namespaces.forEachPrefix = function forEachPrefix(cb) { 106 "use strict"; 107 var /**@type{!Object.<string,string>}*/ 108 ns = odf.Namespaces.namespaceMap, 109 /**@type{string}*/ 110 prefix; 111 112 for (prefix in ns) { 113 if (ns.hasOwnProperty(prefix)) { 114 cb(prefix, ns[prefix]); 115 } 116 } 117 }; 118 119 /** 120 * Returns the namespace belonging to the prefix or null. 121 * @param {string} prefix 122 * @return {?string} 123 */ 124 odf.Namespaces.lookupNamespaceURI = function lookupNamespaceURI(prefix) { 125 "use strict"; 126 var /**@type{?string}*/ 127 r = null; 128 if (odf.Namespaces.namespaceMap.hasOwnProperty(prefix)) { 129 r = /**@type{string}*/(odf.Namespaces.namespaceMap[prefix]); 130 } 131 return r; 132 }; 133 134 /** 135 * Returns the prefix belonging to the NamespaceURI or null. 136 * @param {string} namespaceURI 137 * @return {?string} 138 */ 139 odf.Namespaces.lookupPrefix = function lookupPrefix(namespaceURI) { 140 "use strict"; 141 var /**@type{!Object.<string,string>}*/ 142 map = odf.Namespaces.prefixMap; 143 return map.hasOwnProperty(namespaceURI) ? map[namespaceURI] : null; 144 }; 145 146 // TODO: document where and why this is needed 147 odf.Namespaces.lookupNamespaceURI.lookupNamespaceURI = odf.Namespaces.lookupNamespaceURI; 148 149