/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for * full list of contributors). Published under the 2-clause BSD license. * See license.txt in the OpenLayers distribution or repository for the * full text of the license. */ /** * @requires OpenLayers/Format/XML.js * @requires OpenLayers/Format/GML/v3.js * @requires OpenLayers/Feature/Vector.js */ /** * Class: OpenLayers.Format.Atom * Read/write Atom feeds. Create a new instance with the * constructor. * * Inherits from: * - */ OpenLayers.Format.Atom = OpenLayers.Class(OpenLayers.Format.XML, { /** * Property: namespaces * {Object} Mapping of namespace aliases to namespace URIs. Properties * of this object should not be set individually. Read-only. All * XML subclasses should have their own namespaces object. Use * to add or set a namespace alias after construction. */ namespaces: { atom: "http://www.w3.org/2005/Atom", georss: "http://www.georss.org/georss" }, /** * APIProperty: feedTitle * {String} Atom feed elements require a title. Default is "untitled". */ feedTitle: "untitled", /** * APIProperty: defaultEntryTitle * {String} Atom entry elements require a title. In cases where one is * not provided in the feature attributes, this will be used. Default * is "untitled". */ defaultEntryTitle: "untitled", /** * Property: gmlParse * {Object} GML Format object for parsing features * Non-API and only created if necessary */ gmlParser: null, /** * APIProperty: xy * {Boolean} Order of the GML coordinate: true:(x,y) or false:(y,x) * For GeoRSS the default is (y,x), therefore: false */ xy: false, /** * Constructor: OpenLayers.Format.AtomEntry * Create a new parser for Atom. * * Parameters: * options - {Object} An optional object whose properties will be set on * this instance. */ /** * APIMethod: read * Return a list of features from an Atom feed or entry document. * Parameters: * doc - {Element} or {String} * * Returns: * Array({}) */ read: function(doc) { if (typeof doc == "string") { doc = OpenLayers.Format.XML.prototype.read.apply(this, [doc]); } return this.parseFeatures(doc); }, /** * APIMethod: write * Serialize or more feature nodes to Atom documents. * * Parameters: * features - {} or Array({}) * * Returns: * {String} an Atom entry document if passed one feature node, or a feed * document if passed an array of feature nodes. */ write: function(features) { var doc; if (OpenLayers.Util.isArray(features)) { doc = this.createElementNSPlus("atom:feed"); doc.appendChild( this.createElementNSPlus("atom:title", { value: this.feedTitle }) ); for (var i=0, ii=features.length; i} * * Returns: * {DOMElement} an Atom entry node. * * These entries are geared for publication using AtomPub. * * TODO: support extension elements */ buildEntryNode: function(feature) { var attrib = feature.attributes; var atomAttrib = attrib.atom || {}; var entryNode = this.createElementNSPlus("atom:entry"); // atom:author if (atomAttrib.authors) { var authors = OpenLayers.Util.isArray(atomAttrib.authors) ? atomAttrib.authors : [atomAttrib.authors]; for (var i=0, ii=authors.length; i} * * Returns: * {DOMElement} A gml node. */ buildGeometryNode: function(geometry) { if (!this.gmlParser) { this.initGmlParser(); } var node = this.gmlParser.writeNode("feature:_geometry", geometry); return node.firstChild; }, /** * Method: buildPersonConstructNode * * Parameters: * name - {String} * value - {Object} * * Returns: * {DOMElement} an Atom person construct node. * * Example: * >>> buildPersonConstructNode("author", {name: "John Smith"}) * {John Smith} * * TODO: how to specify extension elements? Add to the oNames array? */ buildPersonConstructNode: function(name, value) { var oNames = ["uri", "email"]; var personNode = this.createElementNSPlus("atom:" + name); personNode.appendChild( this.createElementNSPlus("atom:name", { value: value.name }) ); for (var i=0, ii=oNames.length; i 0) { value = this.getChildValue(nodes[0], def); } else { value = def; } return value; }, /** * Method: parseFeature * Parse feature from an Atom entry node.. * * Parameters: * node - {DOMElement} An Atom entry or feed node. * * Returns: * {} */ parseFeature: function(node) { var atomAttrib = {}; var value = null; var nodes = null; var attval = null; var atomns = this.namespaces.atom; // atomAuthor* this.parsePersonConstructs(node, "author", atomAttrib); // atomCategory* nodes = this.getElementsByTagNameNS(node, atomns, "category"); if (nodes.length > 0) { atomAttrib.categories = []; } for (var i=0, ii=nodes.length; i 0) { value = {}; attval = nodes[0].getAttribute("type"); if (attval) { value.type = attval; } attval = nodes[0].getAttribute("src"); if (attval) { value.src = attval; } else { if (value.type == "text" || value.type == "html" || value.type == null ) { value.value = this.getFirstChildValue( node, atomns, "content", null ); } else if (value.type == "xhtml" || value.type.match(/(\+|\/)xml$/)) { value.value = this.getChildEl(nodes[0]); } else { // MUST be base64 encoded value.value = this.getFirstChildValue( node, atomns, "content", null ); } atomAttrib.content = value; } } // atomContributor* this.parsePersonConstructs(node, "contributor", atomAttrib); // atomId atomAttrib.id = this.getFirstChildValue(node, atomns, "id", null); // atomLink* nodes = this.getElementsByTagNameNS(node, atomns, "link"); if (nodes.length > 0) { atomAttrib.links = new Array(nodes.length); } var oAtts = ["rel", "type", "hreflang", "title", "length"]; for (var i=0, ii=nodes.length; i}) */ parseFeatures: function(node) { var features = []; var entries = this.getElementsByTagNameNS( node, this.namespaces.atom, "entry" ); if (entries.length == 0) { entries = [node]; } for (var i=0, ii=entries.length; i}) */ parseLocations: function(node) { var georssns = this.namespaces.georss; var locations = {components: []}; var where = this.getElementsByTagNameNS(node, georssns, "where"); if (where && where.length > 0) { if (!this.gmlParser) { this.initGmlParser(); } for (var i=0, ii=where.length; i 0) { for (var i=0, ii=point.length; i 0) { var coords; var p; var points; for (var i=0, ii=line.length; i 0) { var coords; var p; var points; for (var i=0, ii=polygon.length; i 0) { data[name + "s"] = persons; } }, CLASS_NAME: "OpenLayers.Format.Atom" });