1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.objects.classes; |
21 |
|
|
22 |
|
import javax.script.ScriptContext; |
23 |
|
|
24 |
|
import org.xwiki.script.ScriptContextManager; |
25 |
|
|
26 |
|
import com.xpn.xwiki.XWikiContext; |
27 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
28 |
|
import com.xpn.xwiki.objects.BaseCollection; |
29 |
|
import com.xpn.xwiki.objects.BaseObject; |
30 |
|
import com.xpn.xwiki.objects.BaseProperty; |
31 |
|
import com.xpn.xwiki.objects.StringProperty; |
32 |
|
import com.xpn.xwiki.objects.meta.PropertyMetaClass; |
33 |
|
import com.xpn.xwiki.web.Utils; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
|
|
| 13.8% |
Uncovered Elements: 25 (29) |
Complexity: 10 |
Complexity Density: 0.5 |
|
42 |
|
public class ComputedFieldClass extends PropertyClass |
43 |
|
{ |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
protected static final String XCLASSNAME = "computedfield"; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
protected static final String FIELD_SCRIPT = "script"; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@param |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
6 |
public ComputedFieldClass(PropertyMetaClass wclass)... |
60 |
|
{ |
61 |
6 |
super(XCLASSNAME, "Computed Field", wclass); |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
6 |
public ComputedFieldClass()... |
68 |
|
{ |
69 |
6 |
this(null); |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
@param |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
public void setScript(String sValue)... |
78 |
|
{ |
79 |
0 |
setLargeStringValue(FIELD_SCRIPT, sValue); |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@return |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
87 |
0 |
public String getScript()... |
88 |
|
{ |
89 |
0 |
String sValue = getLargeStringValue(FIELD_SCRIPT); |
90 |
0 |
return sValue; |
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
0 |
@Override... |
94 |
|
public BaseProperty fromString(String value) |
95 |
|
{ |
96 |
0 |
return null; |
97 |
|
} |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
99 |
0 |
@Override... |
100 |
|
public BaseProperty newProperty() |
101 |
|
{ |
102 |
0 |
BaseProperty property = new StringProperty(); |
103 |
0 |
property.setName(getName()); |
104 |
0 |
return property; |
105 |
|
} |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
|
107 |
0 |
@Override... |
108 |
|
public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, |
109 |
|
XWikiContext context) |
110 |
|
{ |
111 |
0 |
String script = getScript(); |
112 |
|
|
113 |
0 |
try { |
114 |
0 |
ScriptContext scontext = Utils.getComponent(ScriptContextManager.class).getCurrentScriptContext(); |
115 |
0 |
scontext.setAttribute("name", name, ScriptContext.ENGINE_SCOPE); |
116 |
0 |
scontext.setAttribute("prefix", prefix, ScriptContext.ENGINE_SCOPE); |
117 |
0 |
scontext.setAttribute("object", new com.xpn.xwiki.api.Object((BaseObject) object, context), |
118 |
|
ScriptContext.ENGINE_SCOPE); |
119 |
|
|
120 |
0 |
XWikiDocument classDocument = object.getXClass(context).getOwnerDocument(); |
121 |
|
|
122 |
0 |
String result = renderContentInContext(script, classDocument.getSyntax().toIdString(), |
123 |
|
classDocument.getAuthorReference(), context); |
124 |
|
|
125 |
0 |
buffer.append(result); |
126 |
|
} catch (Exception e) { |
127 |
|
|
128 |
0 |
buffer.append(e.getMessage()); |
129 |
|
} |
130 |
|
} |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
0 |
@Override... |
133 |
|
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, |
134 |
|
XWikiContext context) |
135 |
|
{ |
136 |
0 |
displayView(buffer, name, prefix, object, context); |
137 |
|
} |
138 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
139 |
0 |
@Override... |
140 |
|
public void displayHidden(StringBuffer buffer, String name, String prefix, BaseCollection object, |
141 |
|
XWikiContext context) |
142 |
|
{ |
143 |
|
} |
144 |
|
} |