Skip to content

Commit

Permalink
Merge pull request #284 from eXist-db/bugfix/prep-exist7
Browse files Browse the repository at this point in the history
[feature] Required changes to update to exist v7
  • Loading branch information
duncdrum authored Jan 1, 2025
2 parents 8d90f9a + a0c13bb commit eef3f8b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.source>1.8</project.build.source>
<project.build.target>1.8</project.build.target>
<project.build.source>17</project.build.source>
<project.build.target>17</project.build.target>

<exist.java-api.version>5.4.0</exist.java-api.version> <!-- The eXist-db XQuery Java Module API version -->
<exist.java-api.version>7.0.0-SNAPSHOT</exist.java-api.version> <!-- The eXist-db XQuery Java Module API version -->
<exist.processor.version>7.0.0-SNAPSHOT</exist.processor.version> <!-- The version of eXist-db needed by this EXPath Module -->

<jackson.version>2.18.2</jackson.version>
Expand Down
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
50 changes: 25 additions & 25 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 All @@ -49,7 +49,7 @@ public class Log extends BasicFunction {
new FunctionParameterSequenceType("items", Type.ITEM, Cardinality.ZERO_OR_MORE,
"Values to be printed. Will be concatenated into a single string.")
},
new FunctionReturnSequenceType(Type.EMPTY, Cardinality.EMPTY_SEQUENCE, "Empty")
new FunctionReturnSequenceType(Type.EMPTY_SEQUENCE, Cardinality.EMPTY_SEQUENCE, "Empty")
),
new FunctionSignature(
new QName("log", ConsoleModule.NAMESPACE_URI, ConsoleModule.PREFIX),
Expand All @@ -60,7 +60,7 @@ public class Log extends BasicFunction {
new FunctionParameterSequenceType("items", Type.ITEM, Cardinality.ZERO_OR_MORE,
"Values to be printed. Will be concatenated into a single string.")
},
new FunctionReturnSequenceType(Type.EMPTY, Cardinality.EMPTY_SEQUENCE, "Empty")
new FunctionReturnSequenceType(Type.EMPTY_SEQUENCE, Cardinality.EMPTY_SEQUENCE, "Empty")
),
new FunctionSignature(
new QName("send", ConsoleModule.NAMESPACE_URI, ConsoleModule.PREFIX),
Expand All @@ -71,7 +71,7 @@ public class Log extends BasicFunction {
new FunctionParameterSequenceType("items", Type.ITEM, Cardinality.ZERO_OR_ONE,
"Value to be sent. Will be transformed into JSON.")
},
new FunctionReturnSequenceType(Type.EMPTY, Cardinality.EMPTY_SEQUENCE, "Empty")
new FunctionReturnSequenceType(Type.EMPTY_SEQUENCE, Cardinality.EMPTY_SEQUENCE, "Empty")
),
new FunctionSignature(
new QName("dump", ConsoleModule.NAMESPACE_URI, ConsoleModule.PREFIX),
Expand All @@ -84,7 +84,7 @@ public class Log extends BasicFunction {
new FunctionParameterSequenceType("vars", Type.STRING, Cardinality.ONE_OR_MORE,
"The names of the variables to dump."),
},
new FunctionReturnSequenceType(Type.EMPTY, Cardinality.EMPTY_SEQUENCE, "Empty")
new FunctionReturnSequenceType(Type.EMPTY_SEQUENCE, Cardinality.EMPTY_SEQUENCE, "Empty")
),
new FunctionSignature(
new QName("dump", ConsoleModule.NAMESPACE_URI, ConsoleModule.PREFIX),
Expand All @@ -94,14 +94,14 @@ public class Log extends BasicFunction {
new FunctionParameterSequenceType("channel", Type.STRING, Cardinality.EXACTLY_ONE,
"The channel to print to.")
},
new FunctionReturnSequenceType(Type.EMPTY, Cardinality.EMPTY_SEQUENCE, "Empty")
new FunctionReturnSequenceType(Type.EMPTY_SEQUENCE, Cardinality.EMPTY_SEQUENCE, "Empty")
),
new FunctionSignature(
new QName("dump", ConsoleModule.NAMESPACE_URI, ConsoleModule.PREFIX),
"Dump the local variable stack to the console, including all variables which are visible at the " +
"point the statement appears in the code. Use with care: might produce lots of output.",
null,
new FunctionReturnSequenceType(Type.EMPTY, Cardinality.EMPTY_SEQUENCE, "Empty")
new FunctionReturnSequenceType(Type.EMPTY_SEQUENCE, Cardinality.EMPTY_SEQUENCE, "Empty")
)
};

Expand All @@ -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.getType() == Type.ARRAY) {
} 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 eef3f8b

Please sign in to comment.