DataStoreUtil.java
4.56 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.util.FileUtil
* com.scene7.is.util.callbacks.Option
* com.scene7.is.util.collections.CollectionUtil
* javax.jcr.Binary
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.commons.lang.StringUtils
* org.apache.jackrabbit.api.ReferenceBinary
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.dam.s7imaging.impl.cs;
import com.scene7.is.util.FileUtil;
import com.scene7.is.util.callbacks.Option;
import com.scene7.is.util.collections.CollectionUtil;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Properties;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.commons.lang.StringUtils;
import org.apache.jackrabbit.api.ReferenceBinary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DataStoreUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(DataStoreUtil.class);
private static final String PN_FILE_DATA = "jcr:content/jcr:data";
private static final String FILE_DATASTORE_CONFIG = "install/org.apache.jackrabbit.oak.plugins.blob.datastore.FileDataStore.cfg";
private static final String PATH_PROP = "path";
private static Option<Properties> readProps(File src) {
if (!src.exists()) {
return Option.none();
}
try {
return Option.some((Object)CollectionUtil.props((File)src));
}
catch (IOException e) {
String message = "Error reading configuration from '" + src + "' (datastore support will be disabled): " + e.getMessage();
LOGGER.error(message, (Throwable)e);
return Option.none();
}
}
private static Option<File> resolvePath(File root, String path) {
try {
return Option.some((Object)FileUtil.resolveFile((File)root, (String)path));
}
catch (IOException e) {
String message = "Error resolving data store path '" + root + "', '" + path + "' (datastore support will be disabled):" + e.getMessage();
LOGGER.error(message, (Throwable)e);
return Option.none();
}
}
public static Option<File> getDataStoreRoot(String slingHomeDir) {
if (slingHomeDir == null) {
return Option.none();
}
File slingHome = new File(slingHomeDir);
File configFile = new File(slingHome, "install/org.apache.jackrabbit.oak.plugins.blob.datastore.FileDataStore.cfg");
for (Properties configProps : DataStoreUtil.readProps(configFile)) {
String storePath = configProps.getProperty("path");
if (storePath != null) {
return DataStoreUtil.resolvePath(slingHome.getParentFile(), storePath);
}
File store = new File(slingHome, "repository/datastore");
if (store.exists() && store.isDirectory()) {
return Option.some((Object)store);
}
store = new File(slingHome, "repository/repository/datastore");
if (!store.exists() || !store.isDirectory()) continue;
return Option.some((Object)store);
}
return Option.none();
}
public static Option<File> getDataStoreRef(Node ntFile) throws RepositoryException {
Binary binary;
Property property;
if (ntFile.hasProperty("jcr:content/jcr:data") && (property = ntFile.getProperty("jcr:content/jcr:data")).getType() == 2 && (binary = property.getBinary()) instanceof ReferenceBinary) {
String ref = ((ReferenceBinary)binary).getReference();
if ((ref = StringUtils.substringBefore((String)ref, (String)":")) == null) {
return Option.none();
}
File file = new File(ref.substring(0, 2));
file = new File(file, ref.substring(2, 4));
file = new File(file, ref.substring(4, 6));
file = new File(file, ref);
return Option.some((Object)file);
}
return Option.none();
}
public static Option<String> getDataStorePath(Node ntFile, File dataStoreRoot) throws RepositoryException {
Iterator i$ = DataStoreUtil.getDataStoreRef(ntFile).iterator();
if (i$.hasNext()) {
File ref = (File)i$.next();
File resolved = new File(dataStoreRoot, ref.getPath());
return Option.some((Object)resolved.getAbsolutePath());
}
return Option.none();
}
private DataStoreUtil() {
}
}