// *********************************************************************************** // $Source: /home/cvsroot/nodus/src/com/bbn/openmap/plugin/wms/WmsXmlParser.java,v $ // $RCSfile: WmsXmlParser.java,v $ // $Revision: 1.11 $ // $Date: 2004/10/25 15:47:30 $ // $Author: jourquin $ // *********************************************************************************** package com.bbn.openmap.plugin.wms; import org.xml.sax.*; import org.xml.sax.helpers.*; import java.util.Properties; import org.fucam.gtm.nodus.*; /** * *

Title: Nodus 5.0

*

Description: Simple XML parser that tries to get a list of unique layer names It could be extended to get more capabilities...

*

Copyright : Copyright (c) 2004

*

Société : FUCaM-GTM

* @author Bart Jourquin * @version 1.0 */ public class WmsXmlParser extends DefaultHandler implements INodusConstants { private String xmlKey; private Properties capabilities; private String pathPrefix; /** * The parsed data will be stored in the properties, with a given prefix * @param prefix String * @param prop Properties */ public WmsXmlParser(String prefix, Properties prop) { pathPrefix = prefix; capabilities = prop; } /** * Stores a new unique layer name in the properties. See Xerces's documentation for more details on how the * parsing of an XML formatted stream works. * @param ch char[] * @param start int * @param length int * @throws SAXException */ public void characters(char[] ch, int start, int length) throws SAXException { String s = new String(ch, start, length); if (ch[0] == '\n') { return; } //System.out.println(XMLKey + " " +s); if (xmlKey.indexOf("WMT_MS_Capabilities.Capability.Layer.") != -1 && xmlKey.endsWith(".Name") && xmlKey.indexOf("Style") == -1) { String availableLayer = capabilities.getProperty(pathPrefix + PROP_AVAILABLE_LAYERS, ""); if (availableLayer.lastIndexOf(s) == -1) { // Keep unique value StringBuffer sb1 = new StringBuffer(availableLayer); if (sb1.length() > 0) { sb1.append(','); } sb1.append(s); capabilities.put(pathPrefix + PROP_AVAILABLE_LAYERS, sb1.toString()); } } } /** * Tells to the XML parser that the keys are separated with a dot. See Xerce's documentation * for more details on how the parsing of an XML stream works * @param uri String * @param localName String * @param qName String * @throws SAXException */ public void endElement(String uri, String localName, String qName) throws SAXException { int i = xmlKey.lastIndexOf('.'); if (i != -1) { xmlKey = xmlKey.substring(0, i); } } /** * See Xerce's documentation * for more details on how the parsing of an XML stream works * @throws SAXException */ public void startDocument() throws SAXException { xmlKey = new String(""); } /** * Tells to the XML parser that the keys are separated with a dot. See Xerce's documentation * for more details on how the parsing of an XML stream works * @param uri String * @param localName String * @param qName String * @param attributes Attributes * @throws SAXException */ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (xmlKey.length() > 0) { xmlKey += "."; } xmlKey += localName; } }