JcrPropertyResource.java
1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Binary
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
*/
package com.adobe.granite.ui.clientlibs.impl;
import com.adobe.granite.ui.clientlibs.script.ScriptResource;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
public class JcrPropertyResource
implements ScriptResource {
private final Property data;
private final String name;
public JcrPropertyResource(Property data, String name) {
this.name = name;
this.data = data;
}
@Override
public String getName() {
return this.name;
}
@Override
public long getSize() {
try {
return this.data.getLength();
}
catch (RepositoryException e) {
return -1;
}
}
public Property getData() {
return this.data;
}
public String getEncoding() {
String encoding = "utf-8";
try {
if (this.data.getParent().hasProperty("{http://www.jcp.org/jcr/1.0}encoding")) {
encoding = this.data.getParent().getProperty("{http://www.jcp.org/jcr/1.0}encoding").getString();
}
}
catch (RepositoryException e) {
// empty catch block
}
return encoding;
}
@Override
public Reader getReader() throws IOException {
try {
return new InputStreamReader(this.data.getBinary().getStream(), this.getEncoding());
}
catch (RepositoryException e) {
IOException io = new IOException("Unable to provide data stream.");
io.initCause((Throwable)e);
throw io;
}
}
}