Tab.java
2.42 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.LabeledResource
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
*/
package com.day.cq.dam.commons.schemaforms.internal;
import com.day.cq.commons.LabeledResource;
import com.day.cq.dam.commons.schemaforms.internal.Column;
import com.day.cq.dam.commons.schemaforms.internal.MergeableResource;
import com.day.cq.dam.commons.schemaforms.internal.MergedItemResource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
public class Tab
extends MergedItemResource {
public static final String TABID = "tabid";
private String id;
public Tab(Resource resource) {
super(resource);
LabeledResource label = (LabeledResource)resource.adaptTo(LabeledResource.class);
ValueMap vm = (ValueMap)resource.adaptTo(ValueMap.class);
this.id = (String)vm.get("tabid", (Object)label.getTitle());
}
public String getId() {
return this.id;
}
@Override
protected boolean merge(Resource other) {
if (other instanceof Tab) {
Tab otherTab = (Tab)other;
if (this.getId().equals(otherTab.getId())) {
Iterator<Resource> oColIt = otherTab.itemsResource.listChildren();
ArrayList<Column> extraCols = new ArrayList<Column>();
while (oColIt.hasNext()) {
boolean merged = false;
Column oCol = (Column)oColIt.next();
Iterator<Resource> colIt = this.itemsResource.listChildren();
while (colIt.hasNext()) {
Column col = (Column)colIt.next();
if (!col.merge((Resource)oCol)) continue;
merged = true;
break;
}
if (merged) continue;
extraCols.add(oCol);
}
for (Column col : extraCols) {
this.itemsResource.getItems().add((Resource)col);
}
return true;
}
}
return false;
}
@Override
protected Resource getItemResource(Resource res) {
if (res instanceof Column) {
return res;
}
return new Column(res);
}
}