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 /** 64 * @const 65 * @type{string} 66 */ 67 fons: "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0", 68 formns: "urn:oasis:names:tc:opendocument:xmlns:form:1.0", 69 mathns: "http://www.w3.org/1998/Math/MathML", 70 metans: "urn:oasis:names:tc:opendocument:xmlns:meta:1.0", 71 /** 72 * @const 73 * @type{string} 74 */ 75 numberns: "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0", 76 /** 77 * @const 78 * @type{string} 79 */ 80 officens: "urn:oasis:names:tc:opendocument:xmlns:office:1.0", 81 presentationns: "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0", 82 /** 83 * @const 84 * @type{string} 85 */ 86 stylens: "urn:oasis:names:tc:opendocument:xmlns:style:1.0", 87 /** 88 * @const 89 * @type{string} 90 */ 91 svgns: "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0", 92 tablens: "urn:oasis:names:tc:opendocument:xmlns:table:1.0", 93 /** 94 * @const 95 * @type{string} 96 */ 97 textns: "urn:oasis:names:tc:opendocument:xmlns:text:1.0", 98 xformsns: "http://www.w3.org/2002/xforms", 99 xlinkns: 'http://www.w3.org/1999/xlink', 100 xmlns: "http://www.w3.org/XML/1998/namespace" 101 }; 102 103 (function () { 104 "use strict"; 105 // map namespacemap to prefix map on startup 106 var map = odf.Namespaces.namespaceMap, 107 /**@type{!Object.<string,string>}*/ 108 pmap = odf.Namespaces.prefixMap, 109 /**@type{string}*/ 110 prefix; 111 112 for (prefix in map) { 113 if (map.hasOwnProperty(prefix)) { 114 pmap[map[prefix]] = prefix; 115 } 116 } 117 }()); 118 119 /** 120 * Calls the passed callback for all pairs of prefix and namespace 121 * which are in the namespaceMap property 122 * @param {function(string,string):undefined} cb 123 * @return {undefined} 124 */ 125 odf.Namespaces.forEachPrefix = function forEachPrefix(cb) { 126 "use strict"; 127 var /**@type{!Object.<string,string>}*/ 128 ns = odf.Namespaces.namespaceMap, 129 /**@type{string}*/ 130 prefix; 131 132 for (prefix in ns) { 133 if (ns.hasOwnProperty(prefix)) { 134 cb(prefix, ns[prefix]); 135 } 136 } 137 }; 138 139 /** 140 * Returns the namespace belonging to the prefix or null. 141 * @param {string} prefix 142 * @return {?string} 143 */ 144 odf.Namespaces.lookupNamespaceURI = function lookupNamespaceURI(prefix) { 145 "use strict"; 146 var /**@type{?string}*/ 147 r = null; 148 if (odf.Namespaces.namespaceMap.hasOwnProperty(prefix)) { 149 r = /**@type{string}*/(odf.Namespaces.namespaceMap[prefix]); 150 } 151 return r; 152 }; 153 154 /** 155 * Returns the prefix belonging to the NamespaceURI or null. 156 * @param {string} namespaceURI 157 * @return {?string} 158 */ 159 odf.Namespaces.lookupPrefix = function lookupPrefix(namespaceURI) { 160 "use strict"; 161 var /**@type{!Object.<string,string>}*/ 162 map = odf.Namespaces.prefixMap; 163 return map.hasOwnProperty(namespaceURI) ? map[namespaceURI] : null; 164 }; 165 166 // TODO: document where and why this is needed 167 odf.Namespaces.lookupNamespaceURI.lookupNamespaceURI = odf.Namespaces.lookupNamespaceURI; 168 169