Re: Service Provider mechanism and javax.imageio.spi.ServiceRegistry

Szegedi Attila <[email protected]>
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
I see your point.

That's indeed a valid concern -- a convenient representation for
programmatically modifying property files without damaging their
formatting and/or comments.

Actually, while it's not downright a full solution to this is that
starting from Java 5, you can use an XML representation for property
files -- you can use loadFromXML() and storeToXML() to load/save them,
and can manipulate them using SAX/DOM if you wish. Of course, this
doesn't help you with existing properties files...

Attila.

On 2007.11.07., at 23:31, Dilum Ranatunga wrote:

> When programmatically writing properties files out, you also have to
> worry about character encodings. The full 'contract' seems to be
> defined here:
>
> http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#load(java.io.InputStream)
>
> On that SAX/DOM front, without a complete representation, programmatic
> changes to properties files drop comments and shuffle the keys, making
> diffs very ugly... You are absolutely right about a full SAX
> implementation being an overkill, but similar behavior -- e.g
>
> protected handleCommentLine ( String comment ) { }
>
> protected handleBlankLine ( ) { }
>
> protected handlePair( String key, String value ) {
>  setProperty ( key, value );
> }
>
> on Properties that got invoked by the parser logic in load ( ... )
> would have prevented a lot of heartburn for many a developer.
>
>
> On 11/7/07, Szegedi Attila <[email protected]> wrote:
>> Dunno, having a SAX/DOM for .properties files strikes me as being a
>> bit heavyweight approach...
>>
>> Anyway, the service implementation files aren't required to conform
>> to
>> the full .properties file format IIRC (there are provisions for
>> multiline values and escaping in the properties file format that a
>> parser for service files shouldn't care about). It'd be quite trivial
>> to write a loop around BufferedReader.readLine() and ignore empty
>> lines and those starting with # character if you really cared about
>> ordering.
>>
>> Attila.
>>
>> On 2007.11.07., at 18:54, Dilum Ranatunga wrote:
>>
>>> Speaking of properties files, ordering and comments, does anyone
>>> know
>>> of a readily available SAX handler-like or DOM-like parser for
>>> properties files? (Seems like the right way to have written that
>>> code
>>> in the first place...)
>>>
>>>

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.