@@ -61,7 +61,7 @@ public class MiltonDocument extends MiltonResource
61
61
private static SIZE_METHOD getSizeMethod = null ;
62
62
63
63
private static UserAgentHelper userAgentHelper = null ;
64
- private ExistDocument existDocument ;
64
+ private final ExistDocument existDocument ;
65
65
66
66
// Only for PROPFIND the estimate size for an XML document must be shown
67
67
private boolean isPropFind = false ;
@@ -114,52 +114,63 @@ public MiltonDocument(final Properties configuration, String host, XmldbURI uri,
114
114
existDocument .initMetadata ();
115
115
}
116
116
117
-
118
117
// PROPFIND method
119
118
if (propfindSizeMethod == null ) {
120
- // get user supplied preferred size determination approach
119
+ LOG . info ( "Try to obtain {} from System Property" , PROPFIND_METHOD_XML_SIZE );
121
120
String systemProp = System .getProperty (PROPFIND_METHOD_XML_SIZE );
121
+ propfindSizeMethod = getSizeMethod (systemProp );
122
+ }
122
123
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
+ }
126
129
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 ;
138
133
}
139
134
140
135
// GET method
141
136
if (getSizeMethod == null ) {
142
- // get user supplied preferred size determination approach
137
+ LOG . info ( "Try to obtain {} from System Property" , GET_METHOD_XML_SIZE );
143
138
String systemProp = System .getProperty (GET_METHOD_XML_SIZE );
139
+ getSizeMethod = getSizeMethod (systemProp );
140
+ }
144
141
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
+ }
148
147
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 ;
160
151
}
161
152
153
+ }
162
154
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
+ }
163
174
}
164
175
165
176
/**
@@ -207,31 +218,47 @@ public String getContentType(String accepts) {
207
218
@ Override
208
219
public Long getContentLength () {
209
220
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
+ */
235
262
236
263
Long size = null ;
237
264
0 commit comments