Cq62ConfContentUpgrade.java
3.01 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Value
* org.apache.jackrabbit.commons.JcrUtils
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.compat.codeupgrade.impl.cq62;
import com.day.cq.compat.codeupgrade.internal.api.ProgressInfoProvider;
import java.util.Arrays;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import org.apache.jackrabbit.commons.JcrUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Cq62ConfContentUpgrade
implements ProgressInfoProvider {
private final Logger log;
private static final String[] DEFAULT_FALLBACK_CONFIG = new String[]{"/libs", "/apps", "/conf/global"};
private String progressInfo;
public Cq62ConfContentUpgrade() {
this.log = LoggerFactory.getLogger(this.getClass());
}
@Override
public String getProgressInfo() {
return this.progressInfo;
}
void setProgressInfo(String info) {
this.progressInfo = info;
this.log.info(this.progressInfo);
}
public void doUpgrade(Session session) throws RepositoryException {
this.setProgressInfo("Converting and removing /content/@cq:conf");
Node content = session.getNode("/content");
if (content.hasProperty("cq:conf")) {
try {
Object[] paths;
Property prop = content.getProperty("cq:conf");
if (prop.isMultiple()) {
Value[] values = prop.getValues();
paths = new String[values.length];
for (int i = 0; i < values.length; ++i) {
paths[i] = values[i].getString();
}
} else {
paths = new String[]{prop.getString()};
}
if (!Arrays.equals(paths, DEFAULT_FALLBACK_CONFIG)) {
this.setConfMgrOSGiConfiguration(session, (String[])paths);
}
prop.remove();
session.save();
}
catch (RepositoryException e) {
this.log.error("Could not convert cq:conf property on /content to OSGi configuration confmgr.fallback.paths of com.adobe.granite.confmgr.impl.ConfMgrImpl", (Throwable)e);
}
}
}
private void setConfMgrOSGiConfiguration(Session session, String[] fallbackPaths) throws RepositoryException {
this.log.info("Converting /content/@cq:conf into OSGi configuration at /apps/system/config/com.adobe.granite.confmgr.impl.ConfMgrImpl");
Node config = JcrUtils.getOrCreateByPath((Node)session.getNode("/apps"), (String)"system/config/com.adobe.granite.confmgr.impl.ConfMgrImpl", (boolean)false, (String)"sling:Folder", (String)"sling:OsgiConfig", (boolean)false);
config.setProperty("confmgr.fallback.paths", fallbackPaths);
}
}