Re: [OpenMap Users] Saving Layers in Properties file

From: Don Dietrick <dietrick@bbn.com>
Date: Wed Nov 05 2003 - 08:40:36 EST

Hi Laura,

On Nov 3, 2003, at 10:58 AM, Laura Paterson wrote:

> <<
> 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.

Do you still see a problem if you use forward-slashes programmatically?

- Don

> 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.
>

It feels a little odd creating a work-around for a specific Windows
situation in the code, but there might not be a more elegant solution.

I've been thinking more about the PropertyHandler problem where the
properties disappear on write-out, and there may be an easy solution.
It occurs to me that the PropertyHandler just collects properties and
writes them out, when it should start with the properties it has,
allowing other components to write over those properties, and then
write them out. That should fix your shrinking property file problem.
I'm going to look at that today.

- Don

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Don Dietrick, dietrick@bbn.com
BBN Technologies, Cambridge, MA
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
[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 Wed Nov 5 08:44:15 2003

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