Skip to content

Commit

Permalink
Smaller code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dizzzz authored and duncdrum committed Jan 1, 2025
1 parent 54bf193 commit 00c45cc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/exist/console/xquery/ConsoleModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,27 @@ public class ConsoleModule extends AbstractInternalModule {

private static ConsoleAdapter adapter = null;

public static void log(String channel, String message) {
public static void log(final String channel, final String message) {
log(channel, false, message);
}

public static void log(String channel, boolean json, String message) {
public static void log(final String channel, final boolean json, final String message) {
if (adapter != null) {
adapter.log(channel, json, message);
}
}

public static void log(String channel, String source, int line, int column, String message) {
public static void log(final String channel, final String source, final int line, final int column, final String message) {
log(channel, source, line, column, false, message);
}

public static void log(String channel, String source, int line, int column, boolean json, String message) {
public static void log(final String channel, final String source, final int line, final int column, final boolean json, final String message) {
if (adapter != null) {
adapter.log(channel, source, line, column, json, message);
}
}

public static void send(String channel, String json) {
public static void send(final String channel, final String json) {
if (adapter != null) {
adapter.send(channel, json);
}
Expand All @@ -80,7 +80,7 @@ public static void setAdapter(final ConsoleAdapter consoleAdapter) {
adapter = consoleAdapter;
}

public ConsoleModule(Map<String, List<? extends Object>> parameters) {
public ConsoleModule(final Map<String, List<?>> parameters) {
super(functions, parameters, false);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/exist/console/xquery/JMXToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public class JMXToken extends BasicFunction {
new FunctionReturnSequenceType(Type.STRING, Cardinality.ZERO_OR_ONE, "The authentication token")
);

public JMXToken(XQueryContext context) {
public JMXToken(final XQueryContext context) {
super(context, signature);
}

@Override
public Sequence eval(Sequence[] sequences, Sequence sequence) throws XPathException {
public Sequence eval(final Sequence[] sequences, final Sequence sequence) throws XPathException {
if (!context.getEffectiveUser().hasDbaRole()) {
throw new XPathException(this, "Only a dba user is allowed to retrieve the JMX access token.");
}
Expand All @@ -74,7 +74,7 @@ public Sequence eval(Sequence[] sequences, Sequence sequence) throws XPathExcept
if (key != null) {
return new StringValue(key);
}
} catch (IOException ex) {
} catch (final IOException ex) {
throw new XPathException(this, "Exception while reading token file: " + ex.getMessage(), ex);
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/org/exist/console/xquery/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public class Log extends BasicFunction {

public final static FunctionSignature signatures[] = {
public final static FunctionSignature[] signatures = {
new FunctionSignature(
new QName("log", ConsoleModule.NAMESPACE_URI, ConsoleModule.PREFIX),
"Logs a message to the logger using the template given in the first parameter and " +
Expand Down Expand Up @@ -119,40 +119,40 @@ public class Log extends BasicFunction {

private Expression parent = null;

public Log(XQueryContext context, FunctionSignature signature) {
public Log(final XQueryContext context, final FunctionSignature signature) {
super(context, signature);
}

@Override
public void analyze(AnalyzeContextInfo contextInfo) throws XPathException {
public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException {
super.analyze(contextInfo);
parent = contextInfo.getParent();
}

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
final Properties outputProperties = new Properties(SERIALIZATION_PROPERTIES);
if (isCalledAs("dump")) {
final String channel = getArgumentCount() == 0 ? "default" : args[0].getStringValue();
Set<String> varsToPrint = null;
if (getArgumentCount() == 2) {
varsToPrint = new HashSet<String>();
for (SequenceIterator i = args[1].iterate(); i.hasNext(); ) {
varsToPrint = new HashSet<>();
for (final SequenceIterator i = args[1].iterate(); i.hasNext(); ) {
varsToPrint.add(i.nextItem().getStringValue());
}
}
StringWriter writer = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(writer);
final StringWriter writer = new StringWriter();
final JSONWriter jsonWriter = new JSONWriter(writer);
try {
jsonWriter.startDocument();
jsonWriter.startElement("", "result", "result");

Map<QName, Variable> vars = context.getLocalVariables();
for (Map.Entry<QName, Variable> var: vars.entrySet()) {
String name = var.getKey().toString();
final Map<QName, Variable> vars = context.getLocalVariables();
for (final Map.Entry<QName, Variable> var: vars.entrySet()) {
final String name = var.getKey().toString();
if (varsToPrint == null || varsToPrint.contains(name)) {
jsonWriter.startElement("", name, name);
StringBuilder value = new StringBuilder();
final StringBuilder value = new StringBuilder();
printItems(value, outputProperties, false, var.getValue().getValue());
jsonWriter.characters(value);
jsonWriter.endElement("", name, name);
Expand All @@ -167,7 +167,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
} else {
ConsoleModule.log(channel, parent.getSource().pathOrContentOrShortIdentifier(), parent.getLine(), parent.getColumn(), true, msg);
}
} catch (TransformerException e) {
} catch (final TransformerException e) {
e.printStackTrace();
}

Expand All @@ -194,25 +194,25 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
return Sequence.EMPTY_SEQUENCE;
}

private void printItems(StringBuilder out, Properties outputProperties, boolean jsonFormat, Sequence sequence) throws XPathException {
for (SequenceIterator i = sequence.iterate(); i.hasNext(); ) {
private void printItems(final StringBuilder out, final Properties outputProperties, final boolean jsonFormat, final Sequence sequence) throws XPathException {
for (final SequenceIterator i = sequence.iterate(); i.hasNext(); ) {
final Item item = i.nextItem();
if (Type.subTypeOf(item.getType(), Type.NODE)) {
final Serializer serializer = context.getBroker().getSerializer();
serializer.reset();
try {
serializer.setProperties(outputProperties);
out.append(serializer.serialize((NodeValue) item));
} catch (SAXException e) {
} catch (final SAXException e) {
out.append(e.getMessage());
}
} else if (item.getType() == Type.MAP_ITEM || item.getType() == Type.ARRAY_ITEM) {
final StringWriter writer = new StringWriter();
final XQuerySerializer xqSerializer = new XQuerySerializer(context.getBroker(), JSON_SERIALIZATION_PROPERTIES, writer);
try {
xqSerializer.serialize(item.toSequence());
out.append(writer.toString());
} catch (SAXException e) {
out.append(writer);
} catch (final SAXException e) {
throw new XPathException(this, e.getMessage());
}
} else if (jsonFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void log(final String channel, final boolean json, final String message)
}

@Override
public void log(String channel, String source, int line, int column, String message) {
public void log(final String channel, final String source, final int line, final int column, final String message) {
log(channel, source, line, column, false, message);
}

Expand All @@ -80,7 +80,7 @@ public void send(final String channel, final String jsonString) {
private String getTimestamp() {
try {
return new DateTimeValue().getStringValue();
} catch (XPathException e) {
} catch (final XPathException e) {
return null;
}
}
Expand Down

0 comments on commit 00c45cc

Please sign in to comment.