ExcerptsMap.java
2.67 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Item
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.PropertyIterator
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Value
* javax.jcr.query.Row
*/
package com.day.cq.search.impl.misc;
import com.day.cq.search.impl.misc.Excerpt;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.query.Row;
public final class ExcerptsMap
extends AbstractMap<String, String> {
private Set<Map.Entry<String, String>> entries = new HashSet<Map.Entry<String, String>>();
public ExcerptsMap(Row row, Session session) throws RepositoryException {
Node node;
Item item = session.getItem(row.getValue("jcr:path").getString());
if (item.isNode() && (node = (Node)item).hasNode("jcr:content")) {
this.entries.add(new Entry(".", row));
node = node.getNode("jcr:content");
PropertyIterator it = node.getProperties();
while (it.hasNext()) {
Property p = it.nextProperty();
if (p.getType() != 1) continue;
this.entries.add(new Entry(p.getName(), row));
}
}
this.entries = Collections.unmodifiableSet(this.entries);
}
@Override
public Set<Map.Entry<String, String>> entrySet() {
return this.entries;
}
private static final class Entry
implements Map.Entry<String, String> {
private final String name;
private final Row row;
public Entry(String name, Row row) {
this.name = name;
this.row = row;
}
@Override
public String getKey() {
return this.name;
}
@Override
public String getValue() {
try {
Value v;
String path = "jcr:content";
if (!this.name.equals(".")) {
path = path + "/" + this.name;
}
if ((v = this.row.getValue("rep:excerpt(" + path + ")")) != null) {
return Excerpt.getFirstSpan(v.getString());
}
}
catch (RepositoryException e) {
// empty catch block
}
return null;
}
@Override
public String setValue(String s) {
throw new UnsupportedOperationException();
}
}
}