TheProjecter / sardine

Automatically exported from code.google.com/p/sardine
0 stars 0 forks source link

[Patch] Sardine does not support custom namespaces for custom properties #91

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Sardine does create custom properties inside the "SAR:" namespace and doesn't 
expose it to user when re-reading properties. This mean that caller can not 

1) put properties in a specific namespace (troublesome when the backend WEBDAV 
server makes heavy use of metadatas)
2) distinguish between multiple properties with same name in different 
namespaces  namespace.
3) edit properties that have been set in a different namespace by another tool.

Also, properties value can not contains special caracters like "&" or "<", so a 
properties like authors="Benjamin <benjamin@company.com> & Frans 
<fra@othercompany.com>" will fail when set. It's also impossible to set a 
custom property that contains xml for same reasons.

It's to be expected that sardine can manipulate properties in any custom 
namespace containing arbitrary content.

This code is expected to work:
<code>
                sardine.put(url, "Hello".getBytes("UTF-8"), "text/plain");

        Map<String,String> newProps = new HashMap<String, String>();
        newProps.put("http://my.namespace.com:mykey", "myvalue");
        newProps.put("mykey", "my&value2");
        newProps.put("hello:mykey", "my<value3");
        sardine.setCustomProps(url, newProps, null);

        List<DavResource> resources = sardine.getResources(url);
        Map<String,String> props = resources.get(0).getCustomProps();
                assertEquals(props.get("http://my.namespace.com:mykey"),"myvalue");
        assertEquals(props.get("mykey"),"my&value2");
        assertEquals(props.get("hello:mykey"),"my<value3");
</code>

Attached is a patch that contains unit test and fixed code.

Original issue reported on code.google.com by tch...@gmail.com on 11 May 2011 at 2:24

Attachments:

GoogleCodeExporter commented 9 years ago
Note: 

This could be a more general solution to issue 90
 http://code.google.com/p/sardine/issues/detail?id=90

Original comment by tch...@gmail.com on 11 May 2011 at 2:27

GoogleCodeExporter commented 9 years ago
See also issue 90.

Original comment by dkocher@sudo.ch on 12 May 2011 at 8:48

GoogleCodeExporter commented 9 years ago
With MS Exchange server throght OWA I can´t achieve result writing:

Map<String,String> updateProps = new HashMap<String,String>();
updateProps.put("urn:schemas:httpmail::read", "0");
List<String> removeProps = new ArrayList<String>(1);
removeProps.add("urn:schemas:httpmail::importance");

sardine.setCustomProps("https://correo.xxxx.es/Exchange/myuser/MyEmailFolder/New
Mail.EML", updateProps, removeProps);

I get Bad Request from Server:

[java] com.googlecode.sardine.util.SardineException: , response: Solicitud 
incorrecta
[java]     at 
com.googlecode.sardine.SardineImpl.setCustomProps(SardineImpl.java:309)
[java]     at emailbroker.DavManager.main(DavManager.java:236)

Original comment by hector...@gmail.com on 16 May 2011 at 10:29

GoogleCodeExporter commented 9 years ago
Can you check if r228 does indeed fix this issue.

Original comment by dkocher@sudo.ch on 24 May 2011 at 10:35

GoogleCodeExporter commented 9 years ago
Sorry for delay in responding. Because we were using our patched version 
inside, had no time ot test your current version.

Simple response: No, it does not solve the problem.

Your code is still ignoring the namespace of properties when querying the 
server (did not test the setting of property).

Here is an example of the DAV response of a test entry:

<D:response xmlns:ns0="DAV:" xmlns:ns1="intra:" xmlns:lp1="DAV:" 
xmlns:lp2="http://apache.org/dav/props/">
<D:href>/webdav/published/test-6734f3fc-ff1c-4236-b843-da6a2ca6863c.test</D:href
>
<D:propstat>
<D:prop>
<ns1:i_title_nl>Hello world</ns1:i_title_nl>
<ns1:i_title_fr>Hello</ns1:i_title_fr>
<lp1:resourcetype/>
<lp1:creationdate>2011-09-21T14:17:53Z</lp1:creationdate>
<lp1:getcontentlength>21327</lp1:getcontentlength>
<lp1:getlastmodified>Wed, 21 Sep 2011 14:17:53 GMT</lp1:getlastmodified>
<lp1:getetag>"25dac1-534f-4ad743de3e640"</lp1:getetag>
<lp2:executable>F</lp2:executable>
<D:supportedlock>
<D:lockentry>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
<D:lockentry>
<D:lockscope><D:shared/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
</D:supportedlock>
<D:lockdiscovery/>
<D:getcontenttype>text/plain</D:getcontenttype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>

i would expect this code

for (Map.Entry<String,String> e: getResource().getCustomProps().entrySet())
    System.out.println(e.getKey()+" --> "+e.getValue());

to output something like 
intra::i_title_fr --> Hello
http://apache.org/dav/props/:executable --> F
intra::i_title_nl --> Hello world

instead i get
i_title_fr --> Hello
executable --> F
i_title_nl --> Hello world

which mean namespace information is lost. If dav has key in the form 
namespace:property=value, it's for good reason and i would expect sardine to 
handle it properly. Without this i can not make a reliable tool for our user to 
edit document metadata (how can you edit metadata when you can't find out in 
which namespace they are defined?).
Moreover, keep in ming i can in webdav have several properties, with same name, 
different namespace and different value...

Could you reopen issue?

Original comment by tch...@gmail.com on 8 Nov 2011 at 4:34

GoogleCodeExporter commented 9 years ago
I did some checks.

The changes you made for insertion is ok for me (using QName lists). Qname is a 
good choice because it's standard, small and support equals / hashcode 
operation.

The only missing brick was something to get this information from webdav 
server. So i added (see patch) a getCustomPropsNs() method to DavResource that 
returns a Map<QName,String> instead of a Map<String,String>

With this you can keep namespace informations and, for example, show it to end 
user :)

Original comment by tch...@gmail.com on 8 Nov 2011 at 6:11

Attachments:

GoogleCodeExporter commented 9 years ago
In r307.

Original comment by dkocher@sudo.ch on 9 Nov 2011 at 10:25

GoogleCodeExporter commented 9 years ago
Good job, thank you :)

Original comment by tch...@gmail.com on 9 Nov 2011 at 3:25