NodeBackupImpl.java
2.25 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.jcr.JcrUtil
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Value
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.compat.codeupgrade.impl;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.compat.codeupgrade.internal.api.NodeBackup;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class NodeBackupImpl
implements NodeBackup {
private final Logger log;
private final String backupRootPath;
private long fakeTimestamp;
private final SimpleDateFormat pathFormat;
public static final String PATH_PROPERTY_NAME = "propertyPath";
public static final String OLD_VALUE_PROPERTY_NAME = "oldValue";
public static final String FOLDER_TYPE = "sling:Folder";
NodeBackupImpl(String backupRootPath) {
this.log = LoggerFactory.getLogger(this.getClass());
this.backupRootPath = backupRootPath;
this.fakeTimestamp = System.currentTimeMillis();
this.pathFormat = new SimpleDateFormat("yyyy/MM/dd/HHmmss/SSS");
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void backup(Property p) throws RepositoryException {
String path = null;
NodeBackupImpl nodeBackupImpl = this;
synchronized (nodeBackupImpl) {
++this.fakeTimestamp;
path = this.backupRootPath + "/" + this.pathFormat.format(new Date(this.fakeTimestamp));
}
Node backup = JcrUtil.createPath((String)path, (String)"sling:Folder", (Session)p.getSession());
backup.setProperty("propertyPath", p.getPath());
Value v = p.getValue();
if (v.getType() == 2) {
backup.setProperty("oldValue", v.getStream());
} else {
backup.setProperty("oldValue", v.getString());
}
this.log.debug("Property {} backed up under {}", (Object)p.getPath(), (Object)backup.getPath());
}
}