No, it is not in the openmap package, but I use to use the same tree
structure for my openmap derived classes. In fact I have a
NodusWMSPlugIn in which I have introduced the getCapabilities() method
and even a gui that makes it possible to interactivaly choose one or
more layers (see attachment)
You can obviously use it for free... (so can Don if he wants to
introduce it in the baseline...)
See http://www.java-engineer.com/java/checktree.html for the copyright
of the checklist I used :
*"What You're Allowed to Use The Code For*
Anything you like; though I retain the copyright to the code
implementation. You're not required to pay anything for the code, and
you can modify it how you wish, but please retain my copyright comment
in the source."
b.
Jeremy.Zacker@ngc.com wrote:
> Thanks, extremely helpful information. The WmsXMLParser is in an
> openmap package, but doesn't seem to be part of the current baseline.
> Will you be contributing it to the OpenMap project? I just don't want
> to use any proprietary code in my application.
>
>
> --------------------------------------
> Jeremy Zacker
> IBCP - Northrop Grumman
> (732) 530 - 5063
> jeremy.zacker@ngc.com
>
> -----Original Message-----
> *From:* Bart Jourquin [mailto:bart.jourquin@fucam.ac.be]
> *Sent:* Thursday, September 18, 2003 11:17 AM
> *To:* Zacker, Jeremy
> *Cc:* openmap-users@bbn.com
> *Subject:* Re: [OpenMap Users] WMS, etc.
>
> Hi Jeremy,
>
> You can use a "capabilities" request, following the WMS specs.
> This is an example
>
> http://www.geographynetwork.com/servlet/com.esri.wms.Esrimap?&REQUEST=capabilities
>
> The WMS server will return an XML text that you can parse to
> retrieve the available layers.
>
>
> You can for instance add a kind of getCapabilities to YourWMSPlugIn:
>
> public void getCapabilities() {
>
> if (queryHeader == null) {
> return;
> }
>
> // Example :
> http://www.geographynetwork.com/servlet/com.esri.wms.Esrimap?&REQUEST=capabilities
> StringBuffer buf = new StringBuffer(queryHeader);
> buf.append("?" + "&REQUEST=capabilities");
>
> java.net.URL url = null;
>
> try {
> url = new java.net.URL(buf.toString());
> java.net.HttpURLConnection urlc =
> (java.net.HttpURLConnection)url.openConnection();
>
> if (Debug.debugging("plugin")) {
> Debug.output("url content type: "+ urlc.getContentType());
> }
>
> if (urlc == null || urlc.getContentType() == null) {
> if (layer != null) {
> layer.fireRequestMessage(getName() + ": unable to
> connect to " + getServerName());
> } else {
> Debug.error(getName() + ": unable to connect to " +
> getServerName());
> }
>
> }
>
> // WMS standard states that the return must be an XML file
> (test)
> if (urlc.getContentType().indexOf("xml") != -1) {
> try {
> InputStreamReader isr = new
> InputStreamReader(urlc.getInputStream());
> XMLReader parser =
> XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
> WmsXmlParser h = new WmsXmlParser(Prefix, Prop);
> parser.setContentHandler(h);
> parser.parse(new InputSource(isr));
> return;
> }
> catch(IOException ioe) {
> ioe.printStackTrace();
> }
> catch(SAXException saxe) {
> saxe.printStackTrace();
> }
> }
>
> } catch (java.net.MalformedURLException murle) {
> Debug.error("NodusWMSPlugin: URL \"" + buf.toString() +
> "\" is malformed.");
> } catch (java.io.IOException ioe) {
> messageWindow.showMessageDialog(null, getName() + ":\n\n
> Couldn't connect to " + getServerName(), "Connection Problem",
> JOptionPane.INFORMATION_MESSAGE);
> }
>
> // Not found...
> return;
> }
>
>
> And then use a parser such as the one attached to this mail (you
> need Xerces)... This parser could probably be much more
> developped, but it can be a good start...
>
>
> Jeremy.Zacker@ngc.com wrote:
>
>> Hey all,
>>
>> I was wondering if anyone could point me to
>> examples/documentation on how to build queries against a GIS
>> server using WMS interface. The WMSPlug-In for OpenMap assumes
>> that you know which layers are available on the map server. I am
>> trying to build queries against the server to determine which
>> layers are available before actually assigning those layers.
>>
>> --------------------------------------
>> Jeremy Zacker
>> IBCP - Northrop Grumman
>> (732) 530 - 5063
>> jeremy.zacker@ngc.com
>>
>
>--
>Prof Dr Bart Jourquin
>F.U.Ca.M. - G.T.M.
>Chaussee de Binche, 151a
>B7000 Mons
>Belgium
>Tel. : +32 65 323293
>Fax. : +32 65 315691
>http://message.fucam.ac.be/~jourquin
>
>
-- Prof Dr Bart Jourquin F.U.Ca.M. - G.T.M. Chaussee de Binche, 151a B7000 Mons Belgium Tel. : +32 65 323293 Fax. : +32 65 315691 http://message.fucam.ac.be/~jourquin
// ***********************************************************************************
// $Source: /home/cvsroot/nodus/src/com/bbn/openmap/plugin/wms/NodusWMSPlugIn.java,v $
// $RCSfile: NodusWMSPlugIn.java,v $
// $Revision: 1.2 $
// $Date: 2003/08/14 13:24:55 $
// $Author: jourquin $
// ***********************************************************************************
package com.bbn.openmap.plugin.wms;
import java.beans.beancontext.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import com.bbn.openmap.image.*;
import com.bbn.openmap.proj.*;
import com.bbn.openmap.util.*;
import org.fucam.gtm.nodus.*;
public class NodusWMSPlugIn extends WMSPlugIn implements ImageServerConstants, BeanContextMembershipListener, NodusConstants {
private Properties Prop;
private String Prefix;
public void setProperties(String prefix, Properties p) {
Prop = p;
Prefix = "";
if (prefix != null) {
Prefix = prefix; // + ".";
}
super.setProperties(prefix,p);
setAddToBeanContext(true);
}
public void getCapabilities() {
if (queryHeader == null) {
return;
}
// Example : http://www.geographynetwork.com/servlet/com.esri.wms.Esrimap?&REQUEST=capabilities
StringBuffer buf = new StringBuffer(queryHeader);
buf.append("?" + "&REQUEST=capabilities");
java.net.URL url = null;
try {
url = new java.net.URL(buf.toString());
java.net.HttpURLConnection urlc =
(java.net.HttpURLConnection)url.openConnection();
if (Debug.debugging("plugin")) {
Debug.output("url content type: "+ urlc.getContentType());
}
if (urlc == null || urlc.getContentType() == null) {
if (layer != null) {
layer.fireRequestMessage(getName() + ": unable to connect to " + getServerName());
} else {
Debug.error(getName() + ": unable to connect to " + getServerName());
}
}
// WMS standard states that the return must be an XML file (test)
if (urlc.getContentType().indexOf("xml") != -1) {
try {
InputStreamReader isr = new InputStreamReader(urlc.getInputStream());
XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
WmsXmlParser h = new WmsXmlParser(Prefix, Prop);
parser.setContentHandler(h);
parser.parse(new InputSource(isr));
return;
}
catch(IOException ioe) {
ioe.printStackTrace();
}
catch(SAXException saxe) {
saxe.printStackTrace();
}
}
} catch (java.net.MalformedURLException murle) {
Debug.error("NodusWMSPlugin: URL \"" + buf.toString() +
"\" is malformed.");
} catch (java.io.IOException ioe) {
messageWindow.showMessageDialog(null, getName() + ":\n\n Couldn't connect to " + getServerName(), "Connection Problem", JOptionPane.INFORMATION_MESSAGE);
}
// Not found...
return;
}
public java.awt.Component getGUI() {
final JPanel panel = (JPanel) super.getGUI();
Component p = getComponent().getParent();
// Add a new button to existant panel
JButton layersButton = new JButton("Choose layers");
if (layer != null) {
layersButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
// Fetch layers on server
Cursor oldCursor = panel.getCursor();
panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
getCapabilities();
panel.setCursor(oldCursor);
WMSLayersChooserDlg wmsLayersChooserDlg = new WMSLayersChooserDlg(null, Prefix, Prop);
wmsLayersChooserDlg.setVisible(true);
layers = Prop.getProperty(Prefix + Prop_Layers);
}
});
}
panel.add(layersButton);
return panel;
}
public String createQueryString(Projection p) {
if (p instanceof LLXY || p instanceof CADRG)
return super.createQueryString(p);
System.out.println("WMS queries are only supported for LLXY or CADRG projections");
return null;
}
/**
* BeanContextMembershipListener method. Called when a new object
* is added to the BeanContext of this object.
*/
public void childrenAdded(BeanContextMembershipEvent bcme) {
findAndInit(bcme.iterator());
}
/**
* BeanContextMembershipListener method. Called when a new object
* is removed from the BeanContext of this object. For the Layer,
* this method doesn't do anything. If your layer does something
* with the childrenAdded method, or findAndInit, you should take
* steps in this method to unhook the layer from the object used
* in those methods.
*/
public void childrenRemoved(BeanContextMembershipEvent bcme) {
Iterator it = bcme.iterator();
while (it.hasNext()) {
findAndUndo(it.next());
}
}
/**
* This is the method that your object can use to find other
* objects within the MapHandler (BeanContext). This method gets
* called when the object gets added to the MapHandler, or when
* another object gets added to the MapHandler after the object is
* a member.
*
* @param it Iterator to use to go through a list of objects.
* Find the ones you need, and hook yourself up.
*/
public void findAndInit(Iterator it) {
while (it.hasNext()) {
findAndInit(it.next());
}
}
/**
* The findAndInit method has been made non-abstract, because it
* now calls this method for every object that is in the iterator
* it receives. This lets subclasses call a method on super
* classes so they can handle their needs as well.
*/
public void findAndInit(Object obj) {}
/**
* The childrenRemoved has been changed to go through its iterator
* to call this method with every object. This lets subclasses
* call this method on their super class, so it can handle what it
* needs to with objects it may be interested in.
*/
public void findAndUndo(Object obj) {}
}
// ***********************************************************************************
// $Source: /home/cvsroot/nodus/src/com/bbn/openmap/plugin/wms/WMSLayersChooserDlg.java,v $
// $RCSfile: WMSLayersChooserDlg.java,v $
// $Revision: 1.10 $
// $Date: 2003/08/14 13:24:55 $
// $Author: jourquin $
// ***********************************************************************************
package com.bbn.openmap.plugin.wms;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.mattwelsh.framework.gui.*;
import org.fucam.gtm.nodus.*;
/**
*
* <p>Description : This dialog displays a "checkable" list of layer names fetched from a properties
* file. When closing it, the properties are updated with a string representing the layers to pass to
* a WMS server (a '+' separated list of layer names)
* </p>
* <p>Copyright (c) 2002</p>
* <p> B. Jourquin, FUCaM-GTM</p>
* <p> </p>
*
*
*/
public class WMSLayersChooserDlg extends JDialog implements NodusConstants {
private JPanel Panel = new JPanel();
private GridBagLayout GBLayout = new GridBagLayout();
private JScrollPane ScrollPane = new JScrollPane();
private CheckList LayerCheckList = new CheckList();
private JButton OkButton = new JButton();
private Properties Prop;
private String Prefix;
JButton SelectAllButton = new JButton();
JButton DeselectAllButton = new JButton();
JButton CancelButton = new JButton();
public WMSLayersChooserDlg(Frame frame, String prefix, Properties p) {
super(frame, "", true);
Prefix = prefix;
Prop = p;
setTitle("Available layers");
try {
jbInit();
pack();
setLocationRelativeTo(frame);
}
catch(Exception ex) {
ex.printStackTrace();
}
}
/**
* Called by the constructor. Fills the "checkable list" with the available layer names and their
* state (selected or not).
* @throws Exception
*/
void jbInit() throws Exception {
Panel.setLayout(GBLayout);
OkButton.setText("Ok");
OkButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
OkButton_actionPerformed(e);
}
});
LayerCheckList.setMaximumSize(new Dimension(200, 300));
SelectAllButton.setText("Select all");
SelectAllButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
SelectAllButton_actionPerformed(e);
}
});
DeselectAllButton.setText("Deselect all");
DeselectAllButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
DeselectAllButton_actionPerformed(e);
}
});
//ScrollPane.setPreferredSize(new Dimension(-1, -1));
CancelButton.setText("Cancel");
CancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
CancelButton_actionPerformed(e);
}
});
getContentPane().add(Panel);
Panel.add(ScrollPane, new GridBagConstraints(0, 0, 4, 1, 0.5, 0.5
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
Panel.add(OkButton, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
Panel.add(SelectAllButton, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
Panel.add(DeselectAllButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
Panel.add(CancelButton, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
ScrollPane.getViewport().add(LayerCheckList, null);
LayerCheckList.setModel(getDefaultListModel());
}
/**
* List model used by the dialog's checkable listbox.
* @return
*/
protected ListModel getDefaultListModel() {
DefaultListModel model = new DefaultListModel();
String availableLayers = Prop.getProperty(Prefix + Prop_AvailableLayers);
String layers = Prop.getProperty(Prefix + Prop_Layers);
if (availableLayers != null) {
// Build a list of current selected layers
LinkedList ll = new LinkedList();
if (layers != null) { // if layers are currently selected
StringTokenizer st = new StringTokenizer(layers, ",");
while (st.hasMoreTokens()) {
String currentName = st.nextToken();
currentName = currentName.replace('+', ' ');
ll.add(currentName);
}
}
// Fill listbox and check the currently selected layers
StringTokenizer st = new StringTokenizer(availableLayers, ",");
while (st.hasMoreTokens()) {
String currentName = st.nextToken();
model.addElement(new CheckableItem(currentName, ll.contains(currentName)));
}
}
return model;
}
/**
* Creates a WMS compliant string of layer names ('+' separated list of names) and
* put it in the <i>WMS.Layer</i> entry of the properties. Closes the dialog when done.
* @param e
*/
void OkButton_actionPerformed(ActionEvent e) {
// Create a string that represent the selected layers
StringBuffer layers = new StringBuffer("");
// Create a string to remember wich layers are selected
StringBuffer selectedLayers = new StringBuffer("");
int n = LayerCheckList.getModel().getSize();
for (int i = 0 ; i < n ; i++) {
CheckableItem sel = (CheckableItem) LayerCheckList.getModel().getElementAt(i);
if (selectedLayers.length() > 0) selectedLayers.append(',');
if (sel.isChecked()) {
if (layers.length() > 0) layers.append(',');
layers.append(sel.toString());
selectedLayers.append('1');
}
else selectedLayers.append('0');
}
// Replace spaces with + signs
for (int i = 0 ; i < layers.length() ; i++) {
if (layers.charAt(i) == ' ') layers.setCharAt(i,'+');
}
// Put the result in the properties
Prop.put(Prefix + Prop_Layers, layers.toString());
// Close dialog
setVisible(false);
}
void SelectAllButton_actionPerformed(ActionEvent e) {
SelectAll(true);
}
void DeselectAllButton_actionPerformed(ActionEvent e) {
SelectAll(false);
}
void SelectAll(boolean flag) {
int n = LayerCheckList.getModel().getSize();
for (int i = 0 ; i < n ; i++) {
CheckableItem sel = (CheckableItem) LayerCheckList.getModel().getElementAt(i);
sel.setChecked(flag);
}
LayerCheckList.repaint();
}
void CancelButton_actionPerformed(ActionEvent e) {
setVisible(false);
}
}
class CheckableItem implements Checkable {
private boolean sel;
private String name;
public CheckableItem(String s, boolean b) {
sel = b;
name = s;
}
public boolean isChecked() {
return sel;
}
public void setChecked(boolean v) {
sel = v;
}
public String toString() {
return name;
}
}
// ***********************************************************************************
// $Source: /home/cvsroot/nodus/src/com/bbn/openmap/plugin/wms/WmsXmlParser.java,v $
// $RCSfile: WmsXmlParser.java,v $
// $Revision: 1.6 $
// $Date: 2003/08/14 13:24:55 $
// $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.*;
/** Simple XML parser that tries to get a list of unique layer names
It could be extended to get more capabilities...*/
public class WmsXmlParser extends DefaultHandler implements NodusConstants {
private String XMLKey;
private Properties Capabilities;
private String Prefix;
public WmsXmlParser(String prefix, Properties prop) {
Prefix = prefix;
Capabilities = prop;
}
public void characters(char[] ch, int start, int length) throws SAXException {
String s = new String(ch, start, length);
if (ch[0] == '\n')
return;
if (XMLKey.indexOf("WMT_MS_Capabilities.Capability.Layer.") != -1 && XMLKey.endsWith(".Name") && XMLKey.indexOf("Style") == -1) {
String availableLayer = Capabilities.getProperty(Prefix + Prop_AvailableLayers, "");
if (availableLayer.lastIndexOf(s) == -1) { // Keep unique value
StringBuffer sb1 = new StringBuffer(availableLayer);
if (sb1.length() > 0) {
sb1.append(',');
}
sb1.append(s);
Capabilities.put(Prefix+Prop_AvailableLayers, sb1.toString());
}
}
}
public void endElement(String uri, String localName, String qName) throws SAXException {
int i = XMLKey.lastIndexOf('.');
if (i != -1) XMLKey = XMLKey.substring(0, i);
}
public void startDocument() throws SAXException {
XMLKey = new String("");
}
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (XMLKey.length() > 0) XMLKey += ".";
XMLKey += localName;
}
}
-- [To unsubscribe to this list send an email to "majdart@bbn.com" with the following text in the BODY of the message "unsubscribe openmap-users"]
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:36 EDT