1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.webdav.resources.domain; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.io.OutputStream; |
24 |
|
|
25 |
|
import org.apache.jackrabbit.server.io.IOUtil; |
26 |
|
import org.apache.jackrabbit.webdav.DavConstants; |
27 |
|
import org.apache.jackrabbit.webdav.DavException; |
28 |
|
import org.apache.jackrabbit.webdav.DavResource; |
29 |
|
import org.apache.jackrabbit.webdav.DavServletResponse; |
30 |
|
import org.apache.jackrabbit.webdav.io.OutputContext; |
31 |
|
import org.apache.jackrabbit.webdav.property.DavPropertyName; |
32 |
|
import org.apache.jackrabbit.webdav.property.DefaultDavProperty; |
33 |
|
|
34 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
35 |
|
import com.xpn.xwiki.plugin.webdav.resources.XWikiDavResource; |
36 |
|
import com.xpn.xwiki.plugin.webdav.resources.partial.AbstractDavFile; |
37 |
|
|
38 |
|
|
39 |
|
@link |
40 |
|
|
41 |
|
@version |
42 |
|
|
|
|
| 81% |
Uncovered Elements: 12 (63) |
Complexity: 18 |
Complexity Density: 0.47 |
|
43 |
|
public class DavWikiFile extends AbstractDavFile |
44 |
|
{ |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
public static final String WIKI_TXT = "wiki.txt"; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
public static final String WIKI_XML = "wiki.xml"; |
54 |
|
|
55 |
|
|
56 |
|
@link |
57 |
|
|
58 |
|
private XWikiDocument parentDoc; |
59 |
|
|
|
|
| 90% |
Uncovered Elements: 2 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
60 |
9 |
@Override... |
61 |
|
public void init(XWikiDavResource parent, String name, String relativePath) |
62 |
|
throws DavException |
63 |
|
{ |
64 |
9 |
super.init(parent, name, relativePath); |
65 |
9 |
if (!(name.equals(WIKI_TXT) || name.equals(WIKI_XML))) { |
66 |
0 |
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR); |
67 |
|
} |
68 |
9 |
this.parentDoc = ((DavPage) parent).getDocument(); |
69 |
9 |
String timeStamp = DavConstants.creationDateFormat.format(parentDoc.getCreationDate()); |
70 |
9 |
getProperties().add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, timeStamp)); |
71 |
9 |
timeStamp = DavConstants.modificationDateFormat.format(parentDoc.getContentUpdateDate()); |
72 |
9 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED, timeStamp)); |
73 |
9 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETETAG, timeStamp)); |
74 |
9 |
getProperties().add( |
75 |
|
new DefaultDavProperty(DavPropertyName.GETCONTENTLANGUAGE, parentDoc.getLanguage())); |
76 |
9 |
String contentType = this.name.equals(WIKI_TXT) ? "text/plain" : "text/xml"; |
77 |
9 |
getProperties().add(new DefaultDavProperty(DavPropertyName.GETCONTENTTYPE, contentType)); |
78 |
9 |
int contentLength = |
79 |
9 |
this.name.equals(WIKI_TXT) ? parentDoc.getContent().length() : getContext().toXML( |
80 |
|
parentDoc).length(); |
81 |
9 |
getProperties().add( |
82 |
|
new DefaultDavProperty(DavPropertyName.GETCONTENTLENGTH, contentLength)); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
19 |
@Override... |
86 |
|
public boolean exists() |
87 |
|
{ |
88 |
19 |
return !parentDoc.isNew() && parentResource.getVirtualMembers().contains(this); |
89 |
|
} |
90 |
|
|
|
|
| 80.6% |
Uncovered Elements: 6 (31) |
Complexity: 9 |
Complexity Density: 0.47 |
|
91 |
3 |
@Override... |
92 |
|
public void spool(OutputContext outputContext) throws IOException |
93 |
|
{ |
94 |
|
|
95 |
3 |
if (!getContext().hasAccess("view", parentDoc.getFullName())) { |
96 |
0 |
throw new IOException("Access rights violation."); |
97 |
|
} |
98 |
3 |
outputContext.setContentLanguage(parentDoc.getLanguage()); |
99 |
3 |
int contentLength = 0; |
100 |
3 |
try { |
101 |
3 |
contentLength = |
102 |
3 |
this.name.equals(WIKI_TXT) ? parentDoc.getContent().length() : getContext() |
103 |
|
.toXML(parentDoc).length(); |
104 |
|
} catch (DavException ex) { |
105 |
0 |
throw new IOException(ex.getMessage()); |
106 |
|
} |
107 |
3 |
outputContext.setContentLength(contentLength); |
108 |
3 |
outputContext.setContentType(this.name.equals(WIKI_TXT) ? "text/plain" : "text/xml"); |
109 |
3 |
outputContext.setETag(DavConstants.modificationDateFormat.format(getModificationTime())); |
110 |
3 |
outputContext.setModificationTime(getModificationTime()); |
111 |
3 |
if (exists()) { |
112 |
3 |
OutputStream out = outputContext.getOutputStream(); |
113 |
3 |
if (out != null) { |
114 |
3 |
try { |
115 |
3 |
String content = |
116 |
3 |
this.name.equals(WIKI_TXT) ? parentDoc.getContent() : getContext().toXML( |
117 |
|
parentDoc); |
118 |
3 |
out.write(content.getBytes()); |
119 |
3 |
out.flush(); |
120 |
|
} catch (DavException ex) { |
121 |
0 |
throw new IOException(ex.getMessage()); |
122 |
|
} |
123 |
|
} |
124 |
|
} |
125 |
|
} |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
127 |
0 |
@Override... |
128 |
|
public void move(DavResource destination) throws DavException |
129 |
|
{ |
130 |
0 |
throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED); |
131 |
|
} |
132 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
133 |
6 |
@Override... |
134 |
|
public long getModificationTime() |
135 |
|
{ |
136 |
6 |
if (exists()) { |
137 |
6 |
return parentDoc.getContentUpdateDate().getTime(); |
138 |
|
} |
139 |
0 |
return IOUtil.UNDEFINED_TIME; |
140 |
|
} |
141 |
|
} |