AbstractExporter.java
8.97 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Workspace
* javax.jcr.nodetype.NodeDefinition
* javax.jcr.nodetype.NodeType
* javax.jcr.nodetype.NodeTypeManager
* org.apache.jackrabbit.util.ISO8601
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.jcr.vault.fs.io;
import com.day.jcr.vault.fs.api.Aggregate;
import com.day.jcr.vault.fs.api.AggregateManager;
import com.day.jcr.vault.fs.api.PathMapping;
import com.day.jcr.vault.fs.api.ProgressTrackerListener;
import com.day.jcr.vault.fs.api.SimplePathMapping;
import com.day.jcr.vault.fs.api.VaultFile;
import com.day.jcr.vault.fs.api.VaultFileSystem;
import com.day.jcr.vault.fs.api.VaultFsConfig;
import com.day.jcr.vault.fs.api.WorkspaceFilter;
import com.day.jcr.vault.fs.io.ExportInfo;
import com.day.jcr.vault.fs.spi.CNDWriter;
import com.day.jcr.vault.fs.spi.ProgressTracker;
import com.day.jcr.vault.fs.spi.ServiceProviderFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.NodeTypeManager;
import org.apache.jackrabbit.util.ISO8601;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public abstract class AbstractExporter {
private static final Logger log = LoggerFactory.getLogger(AbstractExporter.class);
private ProgressTracker tracker;
private boolean relativePaths;
private String rootPath = "jcr_root";
private Properties properties = new Properties();
private boolean noMetaInf;
protected ExportInfo exportInfo = new ExportInfo();
public boolean isVerbose() {
return this.tracker != null;
}
public void setVerbose(ProgressTrackerListener out) {
if (out == null) {
this.tracker = null;
} else {
if (this.tracker == null) {
this.tracker = new ProgressTracker();
}
this.tracker.setListener(out);
}
}
public boolean isRelativePaths() {
return this.relativePaths;
}
public void setProperty(String name, String value) {
this.properties.put(name, value);
}
public void setProperty(String name, Calendar value) {
this.properties.put(name, ISO8601.format((Calendar)value));
}
public void setProperties(Properties properties) {
if (properties != null) {
this.properties.putAll(properties);
}
}
public String getRootPath() {
return this.rootPath;
}
public void setRootPath(String rootPath) {
this.rootPath = rootPath;
}
public boolean isNoMetaInf() {
return this.noMetaInf;
}
public void setNoMetaInf(boolean noMetaInf) {
this.noMetaInf = noMetaInf;
}
public ExportInfo getExportInfo() {
return this.exportInfo;
}
public void setRelativePaths(boolean relativePaths) {
this.relativePaths = relativePaths;
}
public void export(VaultFile parent) throws RepositoryException, IOException {
this.export(parent, false);
}
public void export(VaultFile parent, boolean noClose) throws RepositoryException, IOException {
this.exportInfo.getEntries().clear();
this.open();
AggregateManager mgr = parent.getFileSystem().getAggregateManager();
mgr.startTracking(this.tracker == null ? null : this.tracker.getListener());
if (!this.noMetaInf) {
this.createDirectory("META-INF");
this.createDirectory("META-INF/vault");
this.track("A", "META-INF");
this.track("A", "META-INF/vault");
this.track("A", "META-INF/vault/config.xml");
this.track("A", "META-INF/vault/filter.xml");
this.track("A", "META-INF/vault/nodetypes.cnd");
this.track("A", "META-INF/vault/properties.xml");
this.writeFile(mgr.getConfig().getSource(), "META-INF/vault/config.xml");
WorkspaceFilter filter = mgr.getWorkspaceFilter();
String mountPath = mgr.getRoot().getPath();
String rootPath = parent.getPath();
if (rootPath.equals("/")) {
rootPath = "";
}
if (mountPath.length() > 0 || rootPath.length() > 0) {
filter = filter.translate(new SimplePathMapping(mountPath, rootPath));
}
this.writeFile(filter.getSource(), "META-INF/vault/filter.xml");
}
this.export(parent, "");
if (!this.noMetaInf) {
this.writeFile(this.getNodeTypes(mgr.getSession(), mgr.getNodeTypes()), "META-INF/vault/nodetypes.cnd");
this.setProperty("created", Calendar.getInstance());
this.setProperty("createdBy", mgr.getUserId());
this.setProperty("packageFormatVersion", String.valueOf(2));
ByteArrayOutputStream tmpOut = new ByteArrayOutputStream();
this.properties.storeToXML(tmpOut, "FileVault Package Properties", "utf-8");
this.writeFile(new ByteArrayInputStream(tmpOut.toByteArray()), "META-INF/vault/properties.xml");
}
if (!noClose) {
this.close();
}
mgr.stopTracking();
}
public void export(VaultFile parent, String relPath) throws RepositoryException, IOException {
for (VaultFile vaultFile : parent.getChildren()) {
String path = relPath + "/" + vaultFile.getName();
if (vaultFile.isDirectory()) {
this.createDirectory(vaultFile, path);
this.export(vaultFile, path);
continue;
}
this.writeFile(vaultFile, path);
}
}
protected void track(String action, String path) {
if ("E".equals(action)) {
log.error("{} {}", (Object)action, (Object)path);
} else {
log.debug("{} {}", (Object)action, (Object)path);
}
if (this.tracker != null) {
this.tracker.track(action, path);
}
}
protected void track(Exception e, String path) {
log.error("E {} ({})", (Object)path, (Object)e.toString());
if (this.tracker != null) {
this.tracker.track(e, path);
}
}
protected String getPlatformFilePath(VaultFile file, String relPath) {
StringBuilder buf = new StringBuilder(this.rootPath);
if (this.isRelativePaths()) {
if (buf.length() > 0) {
buf.append("/");
}
buf.append(relPath);
} else {
buf.append(file.getPath());
}
return buf.toString();
}
private InputStream getNodeTypes(Session s, Collection<String> nodeTypes) throws IOException, RepositoryException {
NodeTypeManager ntMgr = s.getWorkspace().getNodeTypeManager();
HashSet<String> written = new HashSet<String>();
written.addAll(ServiceProviderFactory.getProvider().getBuiltInNodeTypeNames());
StringWriter out = new StringWriter();
CNDWriter w = ServiceProviderFactory.getProvider().getCNDWriter(out, s, true);
for (String nt : nodeTypes) {
this.writeNodeType(ntMgr.getNodeType(nt), w, written);
}
w.close();
return new ByteArrayInputStream(out.getBuffer().toString().getBytes("utf-8"));
}
private void writeNodeType(NodeType nt, CNDWriter w, Set<String> written) throws IOException, RepositoryException {
if (nt != null && !written.contains(nt.getName())) {
written.add(nt.getName());
w.write(nt);
for (NodeType s : nt.getSupertypes()) {
this.writeNodeType(s, w, written);
}
for (NodeType n : nt.getChildNodeDefinitions()) {
this.writeNodeType(n.getDefaultPrimaryType(), w, written);
if (n.getRequiredPrimaryTypes() == null) continue;
for (NodeType r : n.getRequiredPrimaryTypes()) {
this.writeNodeType(r, w, written);
}
}
}
}
public abstract void open() throws IOException, RepositoryException;
public abstract void close() throws IOException, RepositoryException;
public abstract void createDirectory(String var1) throws IOException;
public abstract void createDirectory(VaultFile var1, String var2) throws RepositoryException, IOException;
public abstract void writeFile(InputStream var1, String var2) throws IOException;
public abstract void writeFile(VaultFile var1, String var2) throws RepositoryException, IOException;
}