Ross Laidlaw commented on Improvement OODT-458

(I transferred this comment over from OODT-449):

I've been experimenting with some ideas to implement Paul's suggestion for namespaces. I have a solution that appears to be working. Here are the steps I took:

1) Added Paul's namespace tags to the georss-config.xml file, as follows:

<namespace prefix="geo" uri="http://www.w3.org/2003/01/geo/wgs84_pos#" />
<namespace prefix="georss" uri="http://www.georss.org/georss" />
<namespace prefix="gml" uri="http://www.opengis.net/gml" />


2) Created a new RSSNamespace class, which is very similar to the RSSTag class:

package org.apache.oodt.cas.product.rss;

public class RSSNamespace 
{
  private String prefix;
  private String uri;

  public RSSNamespace() { }

  public String getPrefix() { return prefix; }
  public void setPrefix(String prefix) { this.prefix = prefix;}

  public String getUri() { return uri; }
  public void setUri(String uri) { this.uri = uri; }
}

3) Modified the RSSConfig class to add a list to store namespaces:

  • added new instance variable namespaces:
private List<RSSNamespace> namespaces;
  • added assignment to the constructor:
this.namespaces = new Vector<RSSNamespace>();
  • added getter and setter methods for the namespaces instance variable:
public List<RSSNamespace> getNamespaces() { return namespaces; }
public void setNamespaces(List<RSSNamespace> namespaces) { this.namespaces = namespaces; }

4) Added new constants to the RSSConfigReaderMetKeys interface:

public static final String NAMESPACE_TAG = "namespace";
public static final String NAMESPACE_ATTR_PREFIX = "prefix";
public static final String NAMESPACE_ATTR_URI = "uri";

5) Updated the RSSConfigReader class to read in the namespace tags:

  • added readNamespaces() method to RSSConfigReader
protected static void readNamespaces(Element root, RSSConfig conf) {
  NodeList namespaceList = root.getElementsByTagName(NAMESPACE_TAG);
  if (namespaceList != null && namespaceList.getLength() > 0) {
    for (int i = 0; i < namespaceList.getLength(); i++) {
      Element namespaceElem = (Element) namespaceList.item(i);
      RSSNamespace namespace = new RSSNamespace();
      namespace.setPrefix(namespaceElem.getAttribute(NAMESPACE_ATTR_PREFIX));
      namespace.setUri(namespaceElem.getAttribute(NAMESPACE_ATTR_URI));
      conf.getNamespaces().add(namespace);
    }
  }
}
  • added call to readNamespaces before the call to readTags in the readConfig method
public static RSSConfig readConfig(File file) throws FileNotFoundException {
  ...
  readNamespaces(rootElem, conf);
  readTags(rootElem, conf);
  ...
}

6) Updated the doIt() method in the RSSProductServlet class to process the list of namespace tags and add any namespaces to the rss tag of the output:

public void doIt(HttpServletRequest req, HttpServletResponse resp) 
  throws ServletException, java.io.IOException 
{
  ...

  if (products != null && products.size() > 0) 
  {
    ...
    try 
    {
      ...
      Element rss = XMLUtils.addNode(doc, doc, "rss");
      XMLUtils.addAttribute(doc, rss, "version", "2.0");
      XMLUtils.addAttribute(doc, rss, "xmlns:cas", (String) NS_MAP.get("cas"));
        
      for (RSSNamespace namespace : this.conf.getNamespaces()) 
      {
        XMLUtils.addAttribute(doc, rss, "xmlns:" + namespace.getPrefix(), namespace.getUri());
      }
      ...
    }
  }
}

7) Tested the output:

The results showed that the namespaces defined in georss-config.xml are now being added to the 'rss' tag of the output, as follows:

<rss xmlns:cas="http://oodt.jpl.nasa.gov/1.0/cas" 
     xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" 
     xmlns:georss="http://www.georss.org/georss" 
     xmlns:gml="http://www.opengis.net/gml" version="2.0">
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to