jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jukka Zitting ...@yukatan.fi>
Subject Re: getString for multi-valued properties
Date Mon, 28 Feb 2005 08:32:36 GMT
Hi,

Michael Wechner wrote:
> I took it from the first steps example, but I think I still used a 
> rather old version ;-) which used
> 
> System.out.println(p.getPath() + "=" + p.getString());
> 
> for all cases (multivalued and singlevalued)

The First Steps document was probably written when Jackrabbit wasn't
returning multi-values for the example cases. Nowadays at least the
jcr:mixinTypes property is multivalued and requires special handling.

Among other updates to the First Steps document, I recently changed
property display code to the following. The changes are already visible
on the web site.

    Property p=pit.nextProperty();
    System.out.print(p.getPath() + "=");
    if (p.getDefinition().isMultiple()) {
        Value[] values = p.getValues();
        for (int i = 0; i < values.length; i++) {
            if (i > 0) System.out.println(",");
            System.out.println(values[i].getString());
        }
    } else {
        System.out.print(p.getString());
    }
    System.out.println();

It's not as straightforward as one might wish, but this is what the spec
requires. Should we start a "JCR code idioms" document somewhere (the
dormant wiki perhaps)? The general-case property value access code would
be:

    Property property = ...;
    if (property.getDefinition().isMultiple()) {
        Value[] values = property.getValues();
        for (int i = 0; i < values.length; i++) {
            processValue(values[i]);
        }
    } else {
        processValue(property.getValue());
    }

BR,

Jukka Zitting



Mime
View raw message