40
40
*/
41
41
public class Log extends BasicFunction {
42
42
43
- public final static FunctionSignature signatures [] = {
43
+ public final static FunctionSignature [] signatures = {
44
44
new FunctionSignature (
45
45
new QName ("log" , ConsoleModule .NAMESPACE_URI , ConsoleModule .PREFIX ),
46
46
"Logs a message to the logger using the template given in the first parameter and " +
@@ -119,40 +119,40 @@ public class Log extends BasicFunction {
119
119
120
120
private Expression parent = null ;
121
121
122
- public Log (XQueryContext context , FunctionSignature signature ) {
122
+ public Log (final XQueryContext context , final FunctionSignature signature ) {
123
123
super (context , signature );
124
124
}
125
125
126
126
@ Override
127
- public void analyze (AnalyzeContextInfo contextInfo ) throws XPathException {
127
+ public void analyze (final AnalyzeContextInfo contextInfo ) throws XPathException {
128
128
super .analyze (contextInfo );
129
129
parent = contextInfo .getParent ();
130
130
}
131
131
132
132
@ Override
133
- public Sequence eval (Sequence [] args , Sequence contextSequence ) throws XPathException {
133
+ public Sequence eval (final Sequence [] args , final Sequence contextSequence ) throws XPathException {
134
134
final Properties outputProperties = new Properties (SERIALIZATION_PROPERTIES );
135
135
if (isCalledAs ("dump" )) {
136
136
final String channel = getArgumentCount () == 0 ? "default" : args [0 ].getStringValue ();
137
137
Set <String > varsToPrint = null ;
138
138
if (getArgumentCount () == 2 ) {
139
- varsToPrint = new HashSet <String >();
140
- for (SequenceIterator i = args [1 ].iterate (); i .hasNext (); ) {
139
+ varsToPrint = new HashSet <>();
140
+ for (final SequenceIterator i = args [1 ].iterate (); i .hasNext (); ) {
141
141
varsToPrint .add (i .nextItem ().getStringValue ());
142
142
}
143
143
}
144
- StringWriter writer = new StringWriter ();
145
- JSONWriter jsonWriter = new JSONWriter (writer );
144
+ final StringWriter writer = new StringWriter ();
145
+ final JSONWriter jsonWriter = new JSONWriter (writer );
146
146
try {
147
147
jsonWriter .startDocument ();
148
148
jsonWriter .startElement ("" , "result" , "result" );
149
149
150
- Map <QName , Variable > vars = context .getLocalVariables ();
151
- for (Map .Entry <QName , Variable > var : vars .entrySet ()) {
152
- String name = var .getKey ().toString ();
150
+ final Map <QName , Variable > vars = context .getLocalVariables ();
151
+ for (final Map .Entry <QName , Variable > var : vars .entrySet ()) {
152
+ final String name = var .getKey ().toString ();
153
153
if (varsToPrint == null || varsToPrint .contains (name )) {
154
154
jsonWriter .startElement ("" , name , name );
155
- StringBuilder value = new StringBuilder ();
155
+ final StringBuilder value = new StringBuilder ();
156
156
printItems (value , outputProperties , false , var .getValue ().getValue ());
157
157
jsonWriter .characters (value );
158
158
jsonWriter .endElement ("" , name , name );
@@ -167,7 +167,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
167
167
} else {
168
168
ConsoleModule .log (channel , parent .getSource ().pathOrContentOrShortIdentifier (), parent .getLine (), parent .getColumn (), true , msg );
169
169
}
170
- } catch (TransformerException e ) {
170
+ } catch (final TransformerException e ) {
171
171
e .printStackTrace ();
172
172
}
173
173
@@ -194,25 +194,25 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
194
194
return Sequence .EMPTY_SEQUENCE ;
195
195
}
196
196
197
- private void printItems (StringBuilder out , Properties outputProperties , boolean jsonFormat , Sequence sequence ) throws XPathException {
198
- for (SequenceIterator i = sequence .iterate (); i .hasNext (); ) {
197
+ private void printItems (final StringBuilder out , final Properties outputProperties , final boolean jsonFormat , final Sequence sequence ) throws XPathException {
198
+ for (final SequenceIterator i = sequence .iterate (); i .hasNext (); ) {
199
199
final Item item = i .nextItem ();
200
200
if (Type .subTypeOf (item .getType (), Type .NODE )) {
201
201
final Serializer serializer = context .getBroker ().getSerializer ();
202
202
serializer .reset ();
203
203
try {
204
204
serializer .setProperties (outputProperties );
205
205
out .append (serializer .serialize ((NodeValue ) item ));
206
- } catch (SAXException e ) {
206
+ } catch (final SAXException e ) {
207
207
out .append (e .getMessage ());
208
208
}
209
209
} else if (item .getType () == Type .MAP_ITEM || item .getType () == Type .ARRAY_ITEM ) {
210
210
final StringWriter writer = new StringWriter ();
211
211
final XQuerySerializer xqSerializer = new XQuerySerializer (context .getBroker (), JSON_SERIALIZATION_PROPERTIES , writer );
212
212
try {
213
213
xqSerializer .serialize (item .toSequence ());
214
- out .append (writer . toString () );
215
- } catch (SAXException e ) {
214
+ out .append (writer );
215
+ } catch (final SAXException e ) {
216
216
throw new XPathException (this , e .getMessage ());
217
217
}
218
218
} else if (jsonFormat ) {
0 commit comments