Currently, OpenLayers.Format.* classes do not read in all aspects of a provided document. Examples:
- GeoRSS feeds do not only have items (=features), but also global information at the channel level like title, creator or category.
- SLD documents have a hierarchy of entities, containing the style information at the bottom
All Format classes have only more or less static methods (except for some properties that control how documents should be read/written). Shouldn't those classes be able to store content, with the positive side effect of giving the user structured access to different entity types within the document instead of ignoring all but one of them? This would also be helpful for writing documents with a more complex structure, like GeoRSS or SLD.
My proposal would be to give all Format classes a content property. In the case of GeoRSS, this could look like that:
/**
* APIProperty: content
* {Object} containing
* - channel - {Hash of String} properties at the channel level, keyed by property name.
* Supported property names are title, category, creator [...]
* - items - {Array(<OpenLayers.Feature.Vector>)}
*/
content: {
channel: null,
items: null
}
For SLD, where the structure is more hierarchical, the content could provide a flat and a keyed storage for the userStyles. Helper methods can be created to get even more different views on the content conveniently:
/**
* APIProperty: content
* {Object} containing
* - namedLayer - {Object} hash of userStyles, keyed by sld:NamedLayer/Name,
* each again keyed by sld:UserStyle/Name. Each entry of namedLayer
* is a style map for a layer, with the userStyle names as style keys.
* - userStyles - {Array(<OpenLayers.Style>)}
*/
content: {
namedLayer: null,
userStyles: null
}
/**
* APIProperty: overrideDefaultStyleName
* {Boolean} if true, userStyles with sld:IsDefault==1 will be stored with name "default"
* instead of the sld:UserStyle/Name for this property.
*/
overrideDefaultStyleName: true
/**
* APIMethod: getStyleMap
* Fetches a StyleMap for a specific layer name
*
* Parameters:
* - layerName - {String} name of the layer for which we want a StyleMap
*
*/
getStyleMap: function(userStyles) {}
Generally, the read() method should maybe return the main entity type, as it does now (for compatibility reasons), but it should also fill the content object. The write() method can also maybe continue to take the main entity type as an argument, but for some formats this information will not be sufficient. A complete dump will only be possible when the content object is properly filled before writing.