| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.vfs.internal.attach; |
| 21 |
|
|
| 22 |
|
import java.io.IOException; |
| 23 |
|
import java.io.InputStream; |
| 24 |
|
import java.io.OutputStream; |
| 25 |
|
import java.net.URI; |
| 26 |
|
import java.util.Set; |
| 27 |
|
|
| 28 |
|
import javax.annotation.concurrent.Immutable; |
| 29 |
|
|
| 30 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
| 31 |
|
|
| 32 |
|
import net.java.truecommons.cio.Entry; |
| 33 |
|
import net.java.truecommons.cio.InputSocket; |
| 34 |
|
import net.java.truecommons.cio.IoBufferPool; |
| 35 |
|
import net.java.truecommons.cio.IoEntry; |
| 36 |
|
import net.java.truecommons.cio.OutputSocket; |
| 37 |
|
import net.java.truecommons.shed.BitField; |
| 38 |
|
import net.java.truevfs.kernel.spec.FsAbstractNode; |
| 39 |
|
import net.java.truevfs.kernel.spec.FsAccessOption; |
| 40 |
|
import net.java.truevfs.kernel.spec.FsNodeName; |
| 41 |
|
import net.java.truevfs.kernel.spec.FsReadOnlyFileSystemException; |
| 42 |
|
import net.java.truevfs.kernel.spec.sl.IoBufferPoolLocator; |
| 43 |
|
|
| 44 |
|
import static net.java.truecommons.cio.Entry.Access.READ; |
| 45 |
|
import static net.java.truecommons.cio.Entry.Access.WRITE; |
| 46 |
|
import static net.java.truecommons.cio.Entry.Size.DATA; |
| 47 |
|
import static net.java.truecommons.cio.Entry.Type.FILE; |
| 48 |
|
import static net.java.truevfs.kernel.spec.FsAccessOptions.NONE; |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
@version |
| 54 |
|
@since |
| 55 |
|
|
| 56 |
|
@Immutable |
| |
|
| 56.1% |
Uncovered Elements: 25 (57) |
Complexity: 23 |
Complexity Density: 0.72 |
|
| 57 |
|
public class AttachNode extends FsAbstractNode implements IoEntry<AttachNode> |
| 58 |
|
{ |
| 59 |
|
private final URI uri; |
| 60 |
|
|
| 61 |
|
private final AttachController controller; |
| 62 |
|
|
| 63 |
|
private final String name; |
| 64 |
|
|
| 65 |
|
private XWikiModelNode xwikiModelNode; |
| 66 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 67 |
4 |
AttachNode(final AttachController controller, final FsNodeName name)... |
| 68 |
|
{ |
| 69 |
2 |
assert null != controller; |
| 70 |
4 |
this.controller = controller; |
| 71 |
4 |
this.name = name.toString(); |
| 72 |
4 |
this.uri = controller.resolve(name).getUri(); |
| 73 |
4 |
this.xwikiModelNode = new XWikiModelNode(controller, name); |
| 74 |
|
} |
| 75 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 76 |
2 |
IoBufferPool getPool()... |
| 77 |
|
{ |
| 78 |
2 |
return IoBufferPoolLocator.SINGLETON.get(); |
| 79 |
|
} |
| 80 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 81 |
2 |
protected InputStream newInputStream() throws IOException... |
| 82 |
|
{ |
| 83 |
|
|
| 84 |
2 |
try { |
| 85 |
2 |
return this.xwikiModelNode.getAttachment().getContentInputStream(this.xwikiModelNode.getXWikiContext()); |
| 86 |
|
} catch (Exception e) { |
| 87 |
0 |
throw new IOException(String.format( |
| 88 |
|
"Failed to get attachment content for attachment [%s] in URI [%s]", this.name, this.uri), e); |
| 89 |
|
} |
| 90 |
|
} |
| 91 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 92 |
0 |
protected OutputStream newOutputStream() throws IOException... |
| 93 |
|
{ |
| 94 |
0 |
throw new FsReadOnlyFileSystemException(this.controller.getMountPoint()); |
| 95 |
|
} |
| 96 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 97 |
0 |
@Override... |
| 98 |
|
public String getName() |
| 99 |
|
{ |
| 100 |
0 |
return name; |
| 101 |
|
} |
| 102 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 103 |
2 |
@Override... |
| 104 |
|
public BitField<Type> getTypes() |
| 105 |
|
{ |
| 106 |
|
|
| 107 |
|
|
| 108 |
2 |
return this.xwikiModelNode.hasAttachment() ? FILE_TYPE : NO_TYPES; |
| 109 |
|
} |
| 110 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 111 |
2 |
@Override... |
| 112 |
|
public boolean isType(final Type type) |
| 113 |
|
{ |
| 114 |
2 |
return type == FILE && getTypes().is(FILE); |
| 115 |
|
} |
| 116 |
|
|
| |
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 117 |
2 |
@Override... |
| 118 |
|
public long getSize(final Size type) |
| 119 |
|
{ |
| 120 |
2 |
if (DATA != type) { |
| 121 |
0 |
return UNKNOWN; |
| 122 |
|
} |
| 123 |
|
|
| 124 |
2 |
try { |
| 125 |
2 |
XWikiAttachment attachment = this.xwikiModelNode.getAttachment(); |
| 126 |
2 |
return attachment.getContentSize(this.xwikiModelNode.getXWikiContext()); |
| 127 |
|
} catch (Exception e) { |
| 128 |
0 |
return UNKNOWN; |
| 129 |
|
} |
| 130 |
|
} |
| 131 |
|
|
| |
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 132 |
2 |
@Override... |
| 133 |
|
@SuppressWarnings("deprecation") |
| 134 |
|
public long getTime(Access type) |
| 135 |
|
{ |
| 136 |
2 |
if (WRITE != type) { |
| 137 |
0 |
return UNKNOWN; |
| 138 |
|
} |
| 139 |
|
|
| 140 |
2 |
try { |
| 141 |
2 |
XWikiAttachment attachment = this.xwikiModelNode.getAttachment(); |
| 142 |
2 |
return attachment.getDate().getTime(); |
| 143 |
|
} catch (IOException e) { |
| 144 |
0 |
return UNKNOWN; |
| 145 |
|
} |
| 146 |
|
} |
| 147 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 148 |
0 |
@Override... |
| 149 |
|
public Boolean isPermitted(final Access type, final Entity entity) |
| 150 |
|
{ |
| 151 |
0 |
if (READ != type) { |
| 152 |
0 |
return null; |
| 153 |
|
} |
| 154 |
0 |
return true; |
| 155 |
|
} |
| 156 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 157 |
0 |
@Override... |
| 158 |
|
public Set<String> getMembers() |
| 159 |
|
{ |
| 160 |
0 |
return null; |
| 161 |
|
} |
| 162 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 163 |
2 |
@Override... |
| 164 |
|
public final InputSocket<AttachNode> input() |
| 165 |
|
{ |
| 166 |
2 |
return input(NONE); |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
|
| 170 |
|
@param |
| 171 |
|
@return |
| 172 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 173 |
4 |
protected InputSocket<AttachNode> input(BitField<FsAccessOption> options)... |
| 174 |
|
{ |
| 175 |
4 |
return new AttachInputSocket(options, this); |
| 176 |
|
} |
| 177 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 178 |
0 |
@Override... |
| 179 |
|
public final OutputSocket<AttachNode> output() |
| 180 |
|
{ |
| 181 |
0 |
return output(NONE, null); |
| 182 |
|
} |
| 183 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 184 |
0 |
protected OutputSocket<AttachNode> output(BitField<FsAccessOption> options, Entry template)... |
| 185 |
|
{ |
| 186 |
0 |
return new AttachOutputSocket(options, this, template); |
| 187 |
|
} |
| 188 |
|
} |