Skip to content

Commit 9c066a3

Browse files
authored
Merge pull request #5381 from dizzzz/feature/makeWebdavMoreConfigurable
[Feature] Make WebDAV document size reporting more configurable
2 parents 2dbc643 + ea25170 commit 9c066a3

File tree

5 files changed

+176
-70
lines changed

5 files changed

+176
-70
lines changed

exist-distribution/src/main/config/webdav.properties

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,50 @@
2323
## XML Serialization options for the WevDAV
2424
## The file is read from EXIST_HOME/etc
2525
## Be careful changing the default values !
26-
#indent=yes
27-
#expand-xincludes=no
28-
#process-xsl-pi=no
2926
#encoding=UTF-8
27+
#expand-xincludes=no
28+
#indent=yes
29+
#omit-original-xml-declaration=no
3030
#omit-xml-declaration=no
3131
#output-doctype=yes
32-
#omit-xml-declaration=yes
33-
#omit-original-xml-declaration=no
32+
#process-xsl-pi=no
33+
34+
## Due to the way eXist-db stores XML, the exact size of an XML document when
35+
## it is serialized (e.g., sent to a WebDAV client) may vary depending upon
36+
## serialization parameters.
37+
##
38+
## For performance reasons, eXist by default only reports an approximate file size
39+
## for XML documents. (eXist reports accurate sizes for binary documents,
40+
## which aren't subject to serialization parameters.)
41+
##
42+
## The approximate size is a good indication of the size of document
43+
## but some WebDAV clients, in particular the macOS Finder version, can
44+
## not deal with this estimate, resulting in incomplete or overcomplete
45+
## documents.
46+
##
47+
## To address these various possibilities, two system variables can be set
48+
## to change the way the size is calculated.
49+
##
50+
## Supported values are APPROXIMATE, EXACT, NULL
51+
##
52+
## PROPFIND:
53+
## Unfortunately both NULL and APPROXIMATE do not work for
54+
## macOS Finder. The default behaviour for the Finder 'user-agent' is
55+
## exact, for the others it is approximate.
56+
##
57+
## GET:
58+
## The NULL value seems to be working well for macOS too.
59+
##
60+
## The system properties are:
61+
## -Dorg.exist.webdav.PROPFIND_METHOD_XML_SIZE=.. (used for listing documents in collection)
62+
## -Dorg.exist.webdav.GET_METHOD_XML_SIZE=... (used during download of one document)
63+
##
64+
## Supported values are:
65+
## NULL - document sizes are NOT reported
66+
## EXACT - document sizes are reported using document pre-serialization [Slow]
67+
## APPROXIMATE - document sizes are reported as (pagesize * number of pages)
68+
##
69+
## Depending on the WebDAV client needs, one or both properties can be set.
70+
#
71+
# org.exist.webdav.PROPFIND_METHOD_XML_SIZE=APPROXIMATE
72+
# org.exist.webdav.GET_METHOD_XML_SIZE=NULL

extensions/webdav/src/main/java/org/exist/webdav/ExistResourceFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class ExistResourceFactory implements ResourceFactory {
5555
/**
5656
* XML serialization options
5757
*/
58-
private Properties webDavOptions = new Properties();
58+
private final Properties webDavOptions = new Properties();
5959

6060
/**
6161
* Default constructor. Get access to instance of exist-db broker pool.
@@ -173,7 +173,7 @@ private ResourceType getResourceType(BrokerPool brokerPool, XmldbURI xmldbUri) {
173173

174174
// MacOsX finder specific files
175175
String documentSeqment = xmldbUri.lastSegment().toString();
176-
if (documentSeqment.startsWith("._") || documentSeqment.equals(".DS_Store")) {
176+
if (documentSeqment.startsWith("._") || ".DS_Store".equals(documentSeqment)) {
177177
//LOG.debug(String.format("Ignoring MacOSX file '%s'", xmldbUri.lastSegment().toString()));
178178
//return ResourceType.IGNORABLE;
179179
}

extensions/webdav/src/main/java/org/exist/webdav/MiltonCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class MiltonCollection extends MiltonResource
5252
DeletableResource, MakeCollectionableResource, PutableResource, LockingCollectionResource
5353
/*, DigestResource */, MoveableResource, CopyableResource, LockNullResource {
5454

55-
private ExistCollection existCollection;
55+
private final ExistCollection existCollection;
5656

5757
/**
5858
* Constructor of representation of a Collection in the Milton framework, without subject information.

extensions/webdav/src/main/java/org/exist/webdav/MiltonDocument.java

Lines changed: 84 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class MiltonDocument extends MiltonResource
6161
private static SIZE_METHOD getSizeMethod = null;
6262

6363
private static UserAgentHelper userAgentHelper = null;
64-
private ExistDocument existDocument;
64+
private final ExistDocument existDocument;
6565

6666
// Only for PROPFIND the estimate size for an XML document must be shown
6767
private boolean isPropFind = false;
@@ -114,52 +114,63 @@ public MiltonDocument(final Properties configuration, String host, XmldbURI uri,
114114
existDocument.initMetadata();
115115
}
116116

117-
118117
// PROPFIND method
119118
if (propfindSizeMethod == null) {
120-
// get user supplied preferred size determination approach
119+
LOG.info("Try to obtain {} from System Property", PROPFIND_METHOD_XML_SIZE);
121120
String systemProp = System.getProperty(PROPFIND_METHOD_XML_SIZE);
121+
propfindSizeMethod = getSizeMethod(systemProp);
122+
}
122123

123-
if (systemProp == null) {
124-
// Default method is approximate
125-
propfindSizeMethod = SIZE_METHOD.APPROXIMATE;
124+
if (propfindSizeMethod == null) {
125+
LOG.info("Alternatively try to obtain {} from properties file", PROPFIND_METHOD_XML_SIZE);
126+
String fileProp = configuration.getProperty(PROPFIND_METHOD_XML_SIZE);
127+
propfindSizeMethod = getSizeMethod(fileProp);
128+
}
126129

127-
} else {
128-
// Try to parse from environment property
129-
try {
130-
propfindSizeMethod = SIZE_METHOD.valueOf(systemProp.toUpperCase());
131-
132-
} catch (IllegalArgumentException ex) {
133-
LOG.debug(ex.getMessage());
134-
// Set preffered default
135-
propfindSizeMethod = SIZE_METHOD.APPROXIMATE;
136-
}
137-
}
130+
if (propfindSizeMethod == null) {
131+
LOG.info("Use default value {}", SIZE_METHOD.APPROXIMATE);
132+
propfindSizeMethod = SIZE_METHOD.APPROXIMATE;
138133
}
139134

140135
// GET method
141136
if (getSizeMethod == null) {
142-
// get user supplied preferred size determination approach
137+
LOG.info("Try to obtain {} from System Property", GET_METHOD_XML_SIZE);
143138
String systemProp = System.getProperty(GET_METHOD_XML_SIZE);
139+
getSizeMethod = getSizeMethod(systemProp);
140+
}
144141

145-
if (systemProp == null) {
146-
// Default method is NULL
147-
getSizeMethod = SIZE_METHOD.NULL;
142+
if (getSizeMethod == null) {
143+
LOG.info("Alternatively try to obtain {} from properties file", GET_METHOD_XML_SIZE);
144+
String fileProp = configuration.getProperty(GET_METHOD_XML_SIZE);
145+
getSizeMethod = getSizeMethod(fileProp);
146+
}
148147

149-
} else {
150-
// Try to parse from environment property
151-
try {
152-
getSizeMethod = SIZE_METHOD.valueOf(systemProp.toUpperCase());
153-
154-
} catch (IllegalArgumentException ex) {
155-
LOG.debug(ex.getMessage());
156-
// Set preffered default
157-
getSizeMethod = SIZE_METHOD.APPROXIMATE;
158-
}
159-
}
148+
if (getSizeMethod == null) {
149+
LOG.info("Use default value {}", SIZE_METHOD.NULL);
150+
getSizeMethod = SIZE_METHOD.NULL;
160151
}
161152

153+
}
162154

155+
/**
156+
* Determine what size methodology shall be applied.
157+
*
158+
* @param value Properties value
159+
* @return Corresponding SIZE_METHOD, or else NULL.
160+
*/
161+
SIZE_METHOD getSizeMethod(String value) {
162+
if (value == null || value.strip().isEmpty()) {
163+
return null;
164+
}
165+
166+
try {
167+
final SIZE_METHOD sizeMethod = SIZE_METHOD.valueOf(value.toUpperCase());
168+
LOG.info("Found value {}", sizeMethod);
169+
return sizeMethod;
170+
} catch (IllegalArgumentException ex) {
171+
LOG.debug(ex.getMessage());
172+
return null;
173+
}
163174
}
164175

165176
/**
@@ -207,31 +218,47 @@ public String getContentType(String accepts) {
207218
@Override
208219
public Long getContentLength() {
209220

210-
211-
// Note
212-
// Whilst for non-XML documents the exact size of the documents can
213-
// be determined by checking the administration, this is not possible
214-
// for XML documents.
215-
//
216-
// For XML documents by default the 'approximate' size is available
217-
// which can be sufficient (pagesize * nr of pages). Exact size
218-
// is dependant on many factors, the serialization parameters.
219-
//
220-
// The approximate size is a good indication of the size of document
221-
// but some WebDAV client, mainly the MacOsX Finder version, can
222-
// not deal with this guesstimate, resulting in incomplete or overcomplete
223-
// documents.
224-
//
225-
// Special for this, two system variables can be set to change the
226-
// way the size is calculated. Supported values are
227-
// NULL, EXACT, APPROXIMATE
228-
//
229-
// PROPFIND: Unfortunately both NULL and APPROXIMATE do not work for
230-
// MacOsX Finder. The default behaviour for the Finder 'user-agent' is
231-
// exact, for the others it is approximate.
232-
// This behaviour is swiched by the system properties.
233-
//
234-
// GET: the NULL value seems to be working well for macosx too.
221+
/*
222+
## Due to the way eXist-db stores XML, the exact size of an XML document when
223+
## it is serialized (e.g., sent to a WebDAV client) may vary depending upon
224+
## serialization parameters.
225+
##
226+
## For performance reasons, eXist by default only reports an approximate file size
227+
## for XML documents. (eXist reports accurate sizes for binary documents,
228+
## which aren't subject to serialization parameters.)
229+
##
230+
## The approximate size is a good indication of the size of document
231+
## but some WebDAV clients, in particular the macOS Finder version, can
232+
## not deal with this estimate, resulting in incomplete or overcomplete
233+
## documents.
234+
##
235+
## To address these various possibilities, two system variables can be set
236+
## to change the way the size is calculated.
237+
##
238+
## Supported values are APPROXIMATE, EXACT, NULL
239+
##
240+
## PROPFIND:
241+
## Unfortunately both NULL and APPROXIMATE do not work for
242+
## macOS Finder. The default behaviour for the Finder 'user-agent' is
243+
## exact, for the others it is approximate.
244+
##
245+
## GET:
246+
## The NULL value seems to be working well for macOS too.
247+
##
248+
## The system properties are:
249+
## -Dorg.exist.webdav.PROPFIND_METHOD_XML_SIZE=.. (used for listing documents in collection)
250+
## -Dorg.exist.webdav.GET_METHOD_XML_SIZE=... (used during download of one document)
251+
##
252+
## Supported values are:
253+
## NULL - document sizes are NOT reported
254+
## EXACT - document sizes are reported using document pre-serialization [Slow]
255+
## APPROXIMATE - document sizes are reported as (pagesize * number of pages)
256+
##
257+
## Depending on the WebDAV client needs, one or both properties can be set.
258+
#
259+
# org.exist.webdav.PROPFIND_METHOD_XML_SIZE=APPROXIMATE
260+
# org.exist.webdav.GET_METHOD_XML_SIZE=NULL
261+
*/
235262

236263
Long size = null;
237264

extensions/webdav/src/main/resources/org/exist/webdav/webdav.properties

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,50 @@
2323
## XML Serialization options for the WevDAV
2424
## The file is read from the classpath
2525
## Be careful changing the default values !
26-
#indent=yes
27-
#expand-xincludes=no
28-
#process-xsl-pi=no
2926
#encoding=UTF-8
30-
omit-xml-declaration=yes
27+
#expand-xincludes=no
28+
#indent=yes
3129
omit-original-xml-declaration=no
32-
output-doctype=yes
30+
omit-xml-declaration=yes
31+
output-doctype=yes
32+
#process-xsl-pi=no
33+
34+
## Due to the way eXist-db stores XML, the exact size of an XML document when
35+
## it is serialized (e.g., sent to a WebDAV client) may vary depending upon
36+
## serialization parameters.
37+
##
38+
## For performance reasons, eXist by default only reports an approximate file size
39+
## for XML documents. (eXist reports accurate sizes for binary documents,
40+
## which aren't subject to serialization parameters.)
41+
##
42+
## The approximate size is a good indication of the size of document
43+
## but some WebDAV clients, in particular the macOS Finder version, can
44+
## not deal with this estimate, resulting in incomplete or overcomplete
45+
## documents.
46+
##
47+
## To address these various possibilities, two system variables can be set
48+
## to change the way the size is calculated.
49+
##
50+
## Supported values are APPROXIMATE, EXACT, NULL
51+
##
52+
## PROPFIND:
53+
## Unfortunately both NULL and APPROXIMATE do not work for
54+
## macOS Finder. The default behaviour for the Finder 'user-agent' is
55+
## exact, for the others it is approximate.
56+
##
57+
## GET:
58+
## The NULL value seems to be working well for macOS too.
59+
##
60+
## The system properties are:
61+
## -Dorg.exist.webdav.PROPFIND_METHOD_XML_SIZE=.. (used for listing documents in collection)
62+
## -Dorg.exist.webdav.GET_METHOD_XML_SIZE=... (used during download of one document)
63+
##
64+
## Supported values are:
65+
## NULL - document sizes are NOT reported
66+
## EXACT - document sizes are reported using document pre-serialization [Slow]
67+
## APPROXIMATE - document sizes are reported as (pagesize * number of pages)
68+
##
69+
## Depending on the WebDAV client needs, one or both properties can be set.
70+
#
71+
# org.exist.webdav.PROPFIND_METHOD_XML_SIZE=APPROXIMATE
72+
# org.exist.webdav.GET_METHOD_XML_SIZE=NULL

0 commit comments

Comments
 (0)