1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.store.serialization.xml.internal; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.util.Date; |
24 |
|
|
25 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
26 |
|
import javax.inject.Inject; |
27 |
|
import javax.inject.Named; |
28 |
|
import javax.inject.Singleton; |
29 |
|
import org.dom4j.Element; |
30 |
|
import org.dom4j.dom.DOMElement; |
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
import org.xwiki.store.legacy.doc.internal.DeletedFilesystemAttachment; |
33 |
|
import org.xwiki.store.legacy.doc.internal.MutableDeletedFilesystemAttachment; |
34 |
|
import org.xwiki.store.serialization.xml.XMLSerializer; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
42 |
|
@Component |
43 |
|
@Named("deleted-attachment-meta/1.0") |
44 |
|
@Singleton |
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 5 |
Complexity Density: 0.31 |
|
45 |
|
public class DeletedAttachmentMetadataSerializer |
46 |
|
extends AbstractXMLSerializer<DeletedFilesystemAttachment, MutableDeletedFilesystemAttachment> |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private static final String ROOT_ELEMENT_NAME = "deletedattachment"; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
private static final String SERIALIZER_PARAM = "serializer"; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
private static final String THIS_SERIALIZER = "deletedattachment-meta/1.0"; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
private static final String DELETER = "deleter"; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
private static final String DATE_DELETED = "datedeleted"; |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
private static final String ATTACHMENT = "attachment"; |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@Inject |
82 |
|
@Named("attachment-meta/1.0") |
83 |
|
private XMLSerializer<XWikiAttachment, XWikiAttachment> attachSerializer; |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
85 |
0 |
@Override... |
86 |
|
public MutableDeletedFilesystemAttachment parse(final Element docel) throws IOException |
87 |
|
{ |
88 |
0 |
if (!ROOT_ELEMENT_NAME.equals(docel.getName())) { |
89 |
0 |
throw new IOException("XML not recognizable as deleted attachment metadata, " |
90 |
|
+ "expecting <deletedattachment> tag"); |
91 |
|
} |
92 |
0 |
if (docel.attribute(SERIALIZER_PARAM) == null |
93 |
|
|| !THIS_SERIALIZER.equals(docel.attribute(SERIALIZER_PARAM).getValue())) |
94 |
|
{ |
95 |
0 |
throw new IOException("Cannot parse this deleted attachment metadata, " |
96 |
|
+ "it was saved with a different serializer."); |
97 |
|
} |
98 |
0 |
final MutableDeletedFilesystemAttachment out = new MutableDeletedFilesystemAttachment(); |
99 |
|
|
100 |
0 |
out.setDeleter(docel.element(DELETER).getText()); |
101 |
0 |
out.setDate(new Date(Long.parseLong(docel.element(DATE_DELETED).getText()))); |
102 |
0 |
out.setAttachment(this.attachSerializer.parse(docel.element(ATTACHMENT)), null); |
103 |
|
|
104 |
0 |
return out; |
105 |
|
} |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
107 |
0 |
@Override... |
108 |
|
public void serialize(final DeletedFilesystemAttachment delAttach, final XMLWriter writer) |
109 |
|
throws IOException |
110 |
|
{ |
111 |
0 |
final Element docel = new DOMElement(ROOT_ELEMENT_NAME); |
112 |
0 |
docel.addAttribute(SERIALIZER_PARAM, THIS_SERIALIZER); |
113 |
0 |
writer.writeOpen(docel); |
114 |
|
|
115 |
0 |
writer.write(new DOMElement(DELETER).addText(delAttach.getDeleter())); |
116 |
0 |
writer.write(new DOMElement(DATE_DELETED).addText(delAttach.getDate().getTime() + "")); |
117 |
0 |
this.attachSerializer.serialize(delAttach.getAttachment(), writer); |
118 |
|
|
119 |
0 |
writer.writeClose(docel); |
120 |
|
} |
121 |
|
} |