You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by "Myers, James D" <ji...@pnl.gov> on 2004/01/07 23:18:02 UTC

Handling XML-valued properties in the webdav client

The following change addresses an issue that was pointed out on the
slide users mailer - the command line client returns an empty string for
XML valued properties (getPropertyAsString for BaseProperty just calls
DOMUtils.getTextValue(element)).
Changing the getPropertyAsString method in
org.apache.webdav.lib.BaseProperty.java 

From: 

      return DOMUtils.getTextValue(element); 

To: 

       StringWriter sw = new StringWriter(); 
       PropertyWriter pw = new PropertyWriter( sw, false); 
       NodeList children = element.getChildNodes(); 
       if (children == null || children.getLength() == 0) { 
           return DOMUtils.getTextValue(element); 
       } else { 
         for (int i = 0; i < children.getLength(); i++) { 
           Node child = (Node) children.item(i); 
           pw.print(child); 
         }        
       } 
       return sw.toString(); 

will print text or XML values as text. This is primarily useful for the
command line client, but it doesn't seem like an unreasonable thing to
do within the library itself. 

(getPropertyAsString is really display oriented anyway since the
subclasses of BaseProperty override it to pretty print their XML -
changing BaseProperty just makes it possible to see XML values of non
DAV properties without having to add new classes. )

   Jim 


James D. Myers 
Chief Scientist, Scientific Computing Environments Group 
Computational Science and Mathematics Department 
Pacific Northwest National Laboratory 
Phone: 610-355-0994 
Fax:     208-474-4616 
Jim.Myers@pnl.gov 

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org


Re: Handling XML-valued properties in the webdav client

Posted by Jim Myers <ji...@verizon.net>.
And I agree with you :-) PropertyWriter appears to produce valid, but
verbose xml, e.g. every element /child node gets an "xmlns=<ns>" attribute -
no use of a default or named namespaces. We've been using this patch since
modifying Slide1.0.16 and haven't had any issues where we couldn't parse the
output back into a DOM tree, but I'm definitely offering it as an
improvement over returning "" rather than a good long-term solution.

BTW: We're definitely interested in keeping the client lib alive and having
the command line client as an example of how to use the lib as well as a
quick debug/admin tool. We may have resources to help migrate it towards the
JSR 170 spec over time. For 2.0, we just have a few bug fixes/additions.

  Jim


----- Original Message ----- 
From: "Ingo Brunberg" <ib...@fiz-chemie.de>
To: <sl...@jakarta.apache.org>
Sent: Thursday, January 08, 2004 10:35 AM
Subject: Re: Handling XML-valued properties in the webdav client


> I agree with you, that it would be much nicer if getPropertyAsString()
> returned a full textual representation of the property. That
> technically means to serialize the child nodes of the property
> element. I just hesitate because I am unsure about the quality of
> PropertyWriter. Usually you would do this with the help of JDOM, dom4j
> or something like that, but these libs are not used by the client. So
> I would prefer to utilize JAXP, but that's a bit ugly.
>
> Ingo
>
> > The following change addresses an issue that was pointed out on the
> > slide users mailer - the command line client returns an empty string for
> > XML valued properties (getPropertyAsString for BaseProperty just calls
> > DOMUtils.getTextValue(element)).
> > Changing the getPropertyAsString method in
> > org.apache.webdav.lib.BaseProperty.java=20
> >
> > From:=20
> >
> >       return DOMUtils.getTextValue(element);=20
> >
> > To:=20
> >
> >        StringWriter sw =3D new StringWriter();=20
> >        PropertyWriter pw =3D new PropertyWriter( sw, false);=20
> >        NodeList children =3D element.getChildNodes();=20
> >        if (children =3D=3D null || children.getLength() =3D=3D 0) {=20
> >            return DOMUtils.getTextValue(element);=20
> >        } else {=20
> >          for (int i =3D 0; i < children.getLength(); i++) {=20
> >            Node child =3D (Node) children.item(i);=20
> >            pw.print(child);=20
> >          }       =20
> >        }=20
> >        return sw.toString();=20
> >
> > will print text or XML values as text. This is primarily useful for the
> > command line client, but it doesn't seem like an unreasonable thing to
> > do within the library itself.=20
> >
> > (getPropertyAsString is really display oriented anyway since the
> > subclasses of BaseProperty override it to pretty print their XML -
> > changing BaseProperty just makes it possible to see XML values of non
> > DAV properties without having to add new classes. )
> >
> >    Jim=20
> >
> >
> > James D. Myers=20
> > Chief Scientist, Scientific Computing Environments Group=20
> > Computational Science and Mathematics Department=20
> > Pacific Northwest National Laboratory=20
> > Phone: 610-355-0994=20
> > Fax:     208-474-4616=20
> > Jim.Myers@pnl.gov=20
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: slide-dev-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org


Re: Handling XML-valued properties in the webdav client

Posted by Ingo Brunberg <ib...@fiz-chemie.de>.
I agree with you, that it would be much nicer if getPropertyAsString()
returned a full textual representation of the property. That
technically means to serialize the child nodes of the property
element. I just hesitate because I am unsure about the quality of
PropertyWriter. Usually you would do this with the help of JDOM, dom4j
or something like that, but these libs are not used by the client. So
I would prefer to utilize JAXP, but that's a bit ugly.

Ingo

> The following change addresses an issue that was pointed out on the
> slide users mailer - the command line client returns an empty string for
> XML valued properties (getPropertyAsString for BaseProperty just calls
> DOMUtils.getTextValue(element)).
> Changing the getPropertyAsString method in
> org.apache.webdav.lib.BaseProperty.java=20
> 
> From:=20
> 
>       return DOMUtils.getTextValue(element);=20
> 
> To:=20
> 
>        StringWriter sw =3D new StringWriter();=20
>        PropertyWriter pw =3D new PropertyWriter( sw, false);=20
>        NodeList children =3D element.getChildNodes();=20
>        if (children =3D=3D null || children.getLength() =3D=3D 0) {=20
>            return DOMUtils.getTextValue(element);=20
>        } else {=20
>          for (int i =3D 0; i < children.getLength(); i++) {=20
>            Node child =3D (Node) children.item(i);=20
>            pw.print(child);=20
>          }       =20
>        }=20
>        return sw.toString();=20
> 
> will print text or XML values as text. This is primarily useful for the
> command line client, but it doesn't seem like an unreasonable thing to
> do within the library itself.=20
> 
> (getPropertyAsString is really display oriented anyway since the
> subclasses of BaseProperty override it to pretty print their XML -
> changing BaseProperty just makes it possible to see XML values of non
> DAV properties without having to add new classes. )
> 
>    Jim=20
> 
> 
> James D. Myers=20
> Chief Scientist, Scientific Computing Environments Group=20
> Computational Science and Mathematics Department=20
> Pacific Northwest National Laboratory=20
> Phone: 610-355-0994=20
> Fax:     208-474-4616=20
> Jim.Myers@pnl.gov=20


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org