RE: [OpenMap Users] Saving Layers in Properties file

From: Laura Paterson <laura.paterson@generaldynamics.uk.com>
Date: Mon Nov 03 2003 - 10:58:37 EST

<<
What happens if you specify the file names (originally) in the
openmap.properties as:

C:/openmap-4.5.4/share/data/shape/dcwpo-browse.shp

with forward slashes? I think the \ problem is a java problem.
>>

'\' is an escape character in Java, so to use a back slash you have to enter
two of them "\\". However one of these shall be stripped off every time the
String is created as a literal.

My code works fine if I manually change the file slashes in the property
file, but that still leaves the problem when I am updating the property file
programmatically.

To get around the problem, I added lines into the following File type
PropertyEditors:
FilePropertyEditor; FDUPropertyEditor; FUPropertyEditor;
MulitDirectoryPropertyEditor.
In their actionPerformed call I amend the path that is retreived from the
JFileChooser (e.g.):

    public void actionPerformed(ActionEvent e) {
       JFileChooser chooser = getFileChooser();
       int returnVal = chooser.showDialog((Component)null, "Select");
       if (returnVal==JFileChooser.APPROVE_OPTION) {
          String newFilename = chooser.getSelectedFile().getAbsolutePath();

           // replace all back slashes with forward slashes to permit safe
writing
           // and reading from PrintStreams
           newFilename = newFilename.replace('\\', '/');

           button.setText(newFilename);
           firePropertyChange();
       }
    }

Alternatively, to remove any possibility of back slashes being written to
the properties file where it is likely they shall cause confusion, the
PropertyHandler could be changed i.e.:

    protected static void printLayerProperties(LayerHandler layerHandler,
                           PrintStream ps) {
        .....
        .....
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
        // replace the slashes at this point
            String value =
layerProperties.getProperty(key).replace("\\","/");
            layerPropertiesString.append(key + "=" + value + "\n");
        }
        .....
        .....
    }

So far I have used the first method though, as I was unsure if there is a
possibility of back slashes being legitimately written.

Laura

General Dynamics United Kingdom Limited
Registered in England and Wales No. 1911653
Registered Office: 100 New Bridge Street, London, EC4V 6JA

--
[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"]
Received on Mon Nov 3 11:01:13 2003

This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:36 EDT