BinaryLessDurboImportTransformer.java
3.54 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.durbo.DurboInput
* com.day.durbo.DurboInput$Node
* com.day.durbo.DurboInput$Property
* javax.jcr.Binary
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Value
* javax.jcr.ValueFactory
* org.apache.jackrabbit.commons.jackrabbit.SimpleReferenceBinary
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.replication.impl.content.durbo;
import com.day.cq.replication.ReplicationException;
import com.day.cq.replication.impl.bl.BinaryLessUtils;
import com.day.cq.replication.impl.content.durbo.DurboImportConfiguration;
import com.day.cq.replication.impl.content.durbo.DurboImportTransformer;
import com.day.durbo.DurboInput;
import java.io.IOException;
import java.util.List;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
import org.apache.jackrabbit.commons.jackrabbit.SimpleReferenceBinary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BinaryLessDurboImportTransformer
extends DurboImportTransformer {
private static final Logger logger = LoggerFactory.getLogger(DurboImportTransformer.class);
BinaryLessDurboImportTransformer(DurboImportConfiguration configuration, Session session, DurboInput input) throws RepositoryException {
super(configuration, session, input);
}
@Override
protected void importSingleValue(DurboInput.Property property, Node createdNode, String name, Value value) throws RepositoryException {
String propertyName = BinaryLessUtils.decodeProperty(name);
if (propertyName != null) {
String propertyString = property.getString();
try {
String referenceString;
int u = propertyString.lastIndexOf(58);
int size = 0;
if (u > 0) {
referenceString = propertyString.substring(0, u);
size = Integer.valueOf(propertyString.substring(u + 1));
} else {
referenceString = propertyString;
}
SimpleReferenceBinary ref = new SimpleReferenceBinary(referenceString);
Binary referencedBinary = this.session.getValueFactory().createValue((Binary)ref).getBinary();
if (size > 0 && (long)size != referencedBinary.getSize()) {
if (logger.isWarnEnabled()) {
logger.warn("the referenced binary exists but content length doesn't match, need to resend it");
}
throw new RepositoryException("referenced binary content length doesn't match");
}
createdNode.setProperty(propertyName, referencedBinary);
if (logger.isDebugEnabled()) {
logger.debug("property {} of {} set using a reference", new Object[]{propertyName, createdNode});
}
}
catch (Throwable t) {
this.failedPaths.add(createdNode.getPath() + "/" + propertyName);
if (logger.isWarnEnabled()) {
logger.warn("could not retrieve binary from reference for property {} of node {}", new Object[]{propertyName, createdNode});
}
createdNode.setProperty(propertyName, "");
}
} else {
createdNode.setProperty(name, value);
}
}
}