@@ -77,6 +77,9 @@ public class DocumentImpl extends NodeImpl<DocumentImpl> implements Resource, Do
77
77
78
78
//public static final byte DOCUMENT_NODE_SIGNATURE = 0x0F;
79
79
80
+ public static final byte NO_XMLDECL = 0 ;
81
+ public static final byte HAS_XMLDECL = 1 ;
82
+
80
83
public static final byte NO_DOCTYPE = 0 ;
81
84
public static final byte HAS_DOCTYPE = 1 ;
82
85
@@ -140,6 +143,11 @@ public class DocumentImpl extends NodeImpl<DocumentImpl> implements Resource, Do
140
143
*/
141
144
protected int userLock = 0 ;
142
145
146
+ /**
147
+ * The document's XML Declaration - if specified.
148
+ */
149
+ @ Nullable private XMLDeclarationImpl xmlDecl = null ;
150
+
143
151
/**
144
152
* The document's doctype declaration - if specified.
145
153
*/
@@ -203,7 +211,7 @@ public DocumentImpl(final Expression expression, final BrokerPool pool, @Nullabl
203
211
final XmldbURI fileURI ) {
204
212
this (expression , pool , collection , docId , fileURI ,
205
213
PermissionFactory .getDefaultResourcePermission (pool .getSecurityManager ()), 0 , null ,
206
- System .currentTimeMillis (), null , null , null );
214
+ System .currentTimeMillis (), null , null , null , null );
207
215
}
208
216
209
217
/**
@@ -225,7 +233,7 @@ public DocumentImpl(final int docId, final DocumentImpl prevDoc) {
225
233
*/
226
234
public DocumentImpl (final Expression expression , final int docId , final DocumentImpl prevDoc ) {
227
235
this (expression , prevDoc .pool , prevDoc .collection , docId , prevDoc .fileURI , prevDoc .permissions .copy (), 0 , null ,
228
- System .currentTimeMillis (), null , null , null );
236
+ System .currentTimeMillis (), null , null , null , null );
229
237
}
230
238
231
239
/**
@@ -242,13 +250,40 @@ public DocumentImpl(final Expression expression, final int docId, final Document
242
250
* @param lastModified the last modified time of the document, or null to use the {@code created} time
243
251
* @param mimeType the media type of the document, or null for application/xml
244
252
* @param docType the document type, or null
253
+ *
254
+ * @deprecated Use {@link DocumentImpl(BrokerPool, Collection, int, XmldbURI, Permission, int, long[], long, Long, String, XMLDeclarationImpl, DocumentType)}
255
+ */
256
+ @ Deprecated
257
+ public DocumentImpl (final BrokerPool pool , @ Nullable final Collection collection ,
258
+ final int docId , final XmldbURI fileURI , final Permission permissions ,
259
+ final int children , @ Nullable final long [] childAddress ,
260
+ final long created , @ Nullable final Long lastModified , @ Nullable final String mimeType ,
261
+ @ Nullable final DocumentType docType ) {
262
+ this (null , pool , collection , docId , fileURI , permissions , children , childAddress , created , lastModified , mimeType , null , docType );
263
+ }
264
+
265
+ /**
266
+ * Creates a new persistent Document instance to replace an existing document instance.
267
+ *
268
+ * @param pool The broker pool
269
+ * @param collection The Collection which holds this document
270
+ * @param docId the id of the document
271
+ * @param fileURI The name of the document
272
+ * @param permissions the permissions of the document
273
+ * @param children the number of children that the document has
274
+ * @param childAddress the addresses of the child nodes
275
+ * @param created the created time of the document
276
+ * @param lastModified the last modified time of the document, or null to use the {@code created} time
277
+ * @param mimeType the media type of the document, or null for application/xml
278
+ * @param xmlDecl the XML Declaration, or null
279
+ * @param docType the document type, or null
245
280
*/
246
281
public DocumentImpl (final BrokerPool pool , @ Nullable final Collection collection ,
247
282
final int docId , final XmldbURI fileURI , final Permission permissions ,
248
283
final int children , @ Nullable final long [] childAddress ,
249
284
final long created , @ Nullable final Long lastModified , @ Nullable final String mimeType ,
250
- @ Nullable final DocumentType docType ) {
251
- this (null , pool , collection , docId , fileURI , permissions , children , childAddress , created , lastModified , mimeType , docType );
285
+ @ Nullable final XMLDeclarationImpl xmlDecl , @ Nullable final DocumentType docType ) {
286
+ this (null , pool , collection , docId , fileURI , permissions , children , childAddress , created , lastModified , mimeType , xmlDecl , docType );
252
287
}
253
288
254
289
/**
@@ -266,12 +301,40 @@ public DocumentImpl(final BrokerPool pool, @Nullable final Collection collection
266
301
* @param lastModified the last modified time of the document, or null to use the {@code created} time
267
302
* @param mimeType the media type of the document, or null for application/xml
268
303
* @param docType the document type, or null
304
+ *
305
+ * @deprecated Use {@link DocumentImpl(Expression, BrokerPool, Collection, int ,XmldbURI, Permission, int, long[], long, Long, String, XMLDeclarationImpl, DocumentType)}
269
306
*/
307
+ @ Deprecated
270
308
public DocumentImpl (final Expression expression , final BrokerPool pool , @ Nullable final Collection collection ,
271
309
final int docId , final XmldbURI fileURI , final Permission permissions ,
272
310
final int children , @ Nullable final long [] childAddress ,
273
311
final long created , @ Nullable final Long lastModified , @ Nullable final String mimeType ,
274
312
@ Nullable final DocumentType docType ) {
313
+ this (expression , pool , collection , docId , fileURI , permissions , children , childAddress , created , lastModified , mimeType , null , docType );
314
+ }
315
+
316
+ /**
317
+ * Creates a new persistent Document instance to replace an existing document instance.
318
+ *
319
+ * @param expression the expression from which the document instance derives
320
+ * @param pool The broker pool
321
+ * @param collection The Collection which holds this document
322
+ * @param docId the id of the document
323
+ * @param fileURI The name of the document
324
+ * @param permissions the permissions of the document
325
+ * @param children the number of children that the document has
326
+ * @param childAddress the addresses of the child nodes
327
+ * @param created the created time of the document
328
+ * @param lastModified the last modified time of the document, or null to use the {@code created} time
329
+ * @param mimeType the media type of the document, or null for application/xml
330
+ * @param xmlDecl the XML Declaration, or null
331
+ * @param docType the document type, or null
332
+ */
333
+ public DocumentImpl (final Expression expression , final BrokerPool pool , @ Nullable final Collection collection ,
334
+ final int docId , final XmldbURI fileURI , final Permission permissions ,
335
+ final int children , @ Nullable final long [] childAddress ,
336
+ final long created , @ Nullable final Long lastModified , @ Nullable final String mimeType ,
337
+ @ Nullable final XMLDeclarationImpl xmlDecl , @ Nullable final DocumentType docType ) {
275
338
super (expression );
276
339
this .pool = pool ;
277
340
@@ -286,6 +349,7 @@ public DocumentImpl(final Expression expression, final BrokerPool pool, @Nullabl
286
349
this .created = created ;
287
350
this .lastModified = lastModified == null ? created : lastModified ;
288
351
this .mimeType = mimeType == null ? MimeType .XML_TYPE .getName () : mimeType ;
352
+ this .xmlDecl = xmlDecl ;
289
353
this .docType = docType ;
290
354
291
355
//inherit the group to the resource if current collection is setGid
@@ -790,6 +854,12 @@ void writeDocumentAttributes(final SymbolTable symbolTable, final VariableByteOu
790
854
ostream .writeInt (symbolTable .getMimeTypeId (mimeType ));
791
855
ostream .writeInt (pageCount );
792
856
ostream .writeInt (userLock );
857
+ if (xmlDecl != null ) {
858
+ ostream .writeByte (HAS_XMLDECL );
859
+ xmlDecl .write (ostream );
860
+ } else {
861
+ ostream .writeByte (NO_XMLDECL );
862
+ }
793
863
if (docType != null ) {
794
864
ostream .writeByte (HAS_DOCTYPE );
795
865
((DocumentTypeImpl ) docType ).write (ostream );
@@ -833,6 +903,12 @@ public static DocumentImpl read(final BrokerPool pool, final VariableByteInput i
833
903
final String mimeType = pool .getSymbols ().getMimeType (mimeTypeSymbolsIndex );
834
904
final int pageCount = istream .readInt ();
835
905
final int userLock = istream .readInt ();
906
+ final XMLDeclarationImpl xmlDecl ;
907
+ if (istream .readByte () == HAS_XMLDECL ) {
908
+ xmlDecl = XMLDeclarationImpl .read (istream );
909
+ } else {
910
+ xmlDecl = null ;
911
+ }
836
912
final DocumentTypeImpl docType ;
837
913
if (istream .readByte () == HAS_DOCTYPE ) {
838
914
docType = DocumentTypeImpl .read (istream );
@@ -846,7 +922,7 @@ public static DocumentImpl read(final BrokerPool pool, final VariableByteInput i
846
922
lockToken = null ;
847
923
}
848
924
849
- final DocumentImpl doc = new DocumentImpl (null , pool , null , docId , fileURI , permissions , children , childAddress , created , lastModified , mimeType , docType );
925
+ final DocumentImpl doc = new DocumentImpl (null , pool , null , docId , fileURI , permissions , children , childAddress , created , lastModified , mimeType , xmlDecl , docType );
850
926
doc .pageCount = pageCount ;
851
927
doc .userLock = userLock ;
852
928
doc .lockToken = lockToken ;
@@ -1027,6 +1103,21 @@ protected NodeList findElementsByTagName(final NodeHandle root, final QName qnam
1027
1103
return NodeSet .EMPTY_SET ;
1028
1104
}
1029
1105
1106
+ /**
1107
+ * The method <code>setXmlDeclaration</code>
1108
+ *
1109
+ * @param xmlDecl a <code>XMLDeclarationImpl</code> value
1110
+ */
1111
+ @ EnsureContainerLocked (mode =WRITE_LOCK )
1112
+ public void setXmlDeclaration (final XMLDeclarationImpl xmlDecl ) {
1113
+ this .xmlDecl = xmlDecl ;
1114
+ }
1115
+
1116
+ @ EnsureContainerLocked (mode =READ_LOCK )
1117
+ public @ Nullable XMLDeclarationImpl getXmlDeclaration () {
1118
+ return xmlDecl ;
1119
+ }
1120
+
1030
1121
/************************************************
1031
1122
*
1032
1123
* NodeImpl methods
0 commit comments