MVControl.java
5.62 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.RepositoryException
* javax.jcr.Value
* javax.servlet.ServletRequest
* javax.servlet.http.HttpServletRequest
* javax.servlet.jsp.JspWriter
* javax.servlet.jsp.PageContext
* org.apache.jackrabbit.util.Text
*/
package com.day.crx.explorer.impl.ui;
import com.day.crx.explorer.impl.j2ee.JCRExplorerServlet;
import com.day.crx.explorer.impl.ui.NodeTypeTree;
import com.day.crx.explorer.impl.ui.NodeTypeTreeHTMLProvider;
import java.io.IOException;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import org.apache.jackrabbit.util.Text;
public class MVControl
implements NodeTypeTreeHTMLProvider {
public static final String ATTR_CONTEXT = "UI_MVCONTROL_CONTEXT";
public static final String PROP_NODEBROWSE_SHOWNODES = "ShowNodes";
public static final String PROP_NODEBROWSE_SHOWPROPS = "ShowProps";
public static final String PROP_HIDE_NODETYPE_ICON = "HideNodeTypeIcon";
public static final String PROP_DISABLE_MIXIN = "DisableMixinTypes";
public static final String PROP_DISABLE_PRIMARY = "DisablePrimaryTypes";
private final String name;
private final String type;
private final boolean isMultiple;
private String[] values;
private NodeTypeTree ntTree;
private Properties props = new Properties();
private Properties events = new Properties();
private boolean allowEmpty = false;
public MVControl(String name, String type, boolean isMultiple) {
this.name = name;
this.type = type;
this.isMultiple = isMultiple;
}
public void setProperty(String name, String value) {
this.props.setProperty(name, value);
}
public String getProperty(String name) {
return this.props.getProperty(name);
}
public void setAllowEmpty(boolean allow) {
this.allowEmpty = allow;
}
public void setValues(String[] values) {
this.values = values;
}
public void setValues(Value[] values) throws RepositoryException {
if (values == null) {
this.values = null;
} else {
this.values = new String[values.length];
for (int i = 0; i < values.length; ++i) {
this.values[i] = values[i].getString();
}
}
}
public void setNodeTypes(NodeTypeTree ntTree) {
this.ntTree = ntTree;
}
public void setEvent(String eventName, String function) {
this.events.setProperty(eventName, function);
}
public static void init(PageContext context) throws IOException {
Object obj = context.getAttribute("UI_MVCONTROL_CONTEXT");
if (obj == null) {
obj = new Object();
context.setAttribute("UI_MVCONTROL_CONTEXT", obj);
JspWriter out = context.getOut();
String docroot = JCRExplorerServlet.getDocrootPrefix((HttpServletRequest)context.getRequest());
out.println("<script src=\"" + docroot + "/ui/mvcontrol.js?ck=" + System.currentTimeMillis() + "\"></script>");
out.println("<script>");
out.println("MVControl.setDocroot(\"" + docroot + "\");");
out.println("</script>");
}
}
public void draw(PageContext context) throws IOException, RepositoryException {
JspWriter out = context.getOut();
out.println("<script>\nvar mv = new MVControl(\"" + Text.encodeIllegalXMLCharacters((String)this.name) + "\", \"" + Text.encodeIllegalXMLCharacters((String)this.type) + "\"," + this.isMultiple + ");");
if (this.type.equals("NodeType") && this.ntTree != null) {
this.ntTree.draw(context, this);
}
if (this.allowEmpty) {
out.println("mv.setAllowEmpty(true);");
}
for (String key2 : this.props.keySet()) {
out.println("mv.setProperty(\"" + Text.encodeIllegalXMLCharacters((String)key2) + "\",\"" + Text.encodeIllegalXMLCharacters((String)this.props.getProperty(key2)) + "\");");
}
for (String key2 : this.events.keySet()) {
out.println("mv.setEvent(\"" + Text.encodeIllegalXMLCharacters((String)key2) + "\",\"" + Text.encodeIllegalXMLCharacters((String)this.events.getProperty(key2)) + "\");");
}
out.println("mv.drawBegin();");
if (this.values != null) {
for (int i = 0; i < this.values.length; ++i) {
if (this.values[i] == null) continue;
out.println("mv.drawValue(\"" + Text.encodeIllegalXMLCharacters((String)Text.escape((String)this.values[i])) + "\");");
}
}
out.println("mv.drawEnd();\n</script>");
}
public void drawLevel(PageContext context, NodeTypeTree.Item item, int indent) throws IOException, RepositoryException {
Iterator iter = item.getChildren();
while (iter.hasNext()) {
this.drawItem(context, (NodeTypeTree.Item)iter.next(), indent);
}
}
public void drawItem(PageContext context, NodeTypeTree.Item item, int indent) throws IOException, RepositoryException {
JspWriter out = context.getOut();
out.print("mv.addNodeType(");
out.print("\"" + Text.encodeIllegalXMLCharacters((String)item.getName()) + "\"");
out.print("," + item.isMixin() + "");
out.print(",\"" + JCRExplorerServlet.getNTIcon(item.getName()) + "\"");
out.println("," + indent + ");");
this.drawLevel(context, item, indent + 1);
}
}