Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion basex-core/src/main/java/org/basex/query/QueryContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public final class QueryContext extends Job implements Closeable {
/** Parsed modules, containing the file path and library module. */
public final TokenObjectMap<LibraryModule> libs = new TokenObjectMap<>();
/** Pre-declared modules, containing module URI and their file paths (required for test APIs). */
public final TokenObjectMap<byte[]> modDeclared = new TokenObjectMap<>();
public final TokenObjectMap<TokenList> modDeclared = new TokenObjectMap<>();
/** Stack of module files that are currently parsed. */
public final TokenList modStack = new TokenList();

Expand Down
15 changes: 10 additions & 5 deletions basex-core/src/main/java/org/basex/query/QueryParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -743,17 +743,22 @@ private void moduleImport() throws QueryException {

// add non-default namespace
if(prefix != EMPTY) {
if(sc.ns.staticURI(prefix) != null) throw error(DUPLNSDECL_X, prefix);
sc.ns.add(prefix, uri, info());
namespaces.put(prefix, uri);
final byte[] su = sc.ns.staticURI(prefix);
if(su == null) {
sc.ns.add(prefix, uri, info());
namespaces.put(prefix, uri);
} else {
final byte[] mu = sc.module == null ? null : sc.module.uri();
if(!Token.eq(su, uri) || !Token.eq(mu, uri)) throw error(DUPLNSDECL_X, prefix);
}
}

// check modules at specified locations
final ModInfo mi = new ModInfo();
if(!addLocations(mi.paths)) {
// check module files that have been pre-declared by a test API
final byte[] pth = qc.modDeclared.get(uri);
if(pth != null) mi.paths.add(pth);
final TokenList pths = qc.modDeclared.get(uri);
if(pths != null) pths.forEach(mi.paths::add);
}
mi.uri = uri;
mi.info = info();
Expand Down
3 changes: 2 additions & 1 deletion basex-core/src/main/java/org/basex/query/QueryProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.basex.query.value.*;
import org.basex.query.value.node.*;
import org.basex.query.value.seq.*;
import org.basex.util.list.*;

/**
* This class is an entry point for evaluating XQuery strings.
Expand Down Expand Up @@ -217,7 +218,7 @@ public Serializer serializer(final OutputStream os) throws IOException, QueryExc
* @param file file name
*/
public void module(final String uri, final String file) {
qc.modDeclared.put(token(uri), token(file));
qc.modDeclared.computeIfAbsent(token(uri), TokenList::new).add(token(file));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public XQMap item(final QueryContext qc, final InputInfo ii) throws QueryExcepti
} else {
final StringList locs = new StringList().add(hints);
if(locs.isEmpty()) {
final byte[] loc = qc.modDeclared.get(modUri);
if(loc != null) {
locs.add(Token.string(loc));
final TokenList files = qc.modDeclared.get(modUri);
if(files != null) {
for(final byte[] file : files) locs.add(Token.string(file));
} else {
final String path = repoFilePath(modUri, qc.context);
if(path != null) locs.add(path);
Expand Down