30
30
import org .exist .xmldb .LocalCollection ;
31
31
import org .exist .xmldb .txn .bridge .InTxnLocalCollection ;
32
32
import org .exist .xquery .BasicFunction ;
33
+ import org .exist .xquery .Expression ;
33
34
import org .exist .xquery .FunctionSignature ;
34
35
import org .exist .xquery .XPathException ;
35
36
import org .exist .xquery .XQueryContext ;
43
44
import org .xmldb .api .base .XMLDBException ;
44
45
import org .xmldb .api .modules .CollectionManagementService ;
45
46
47
+ import static org .exist .xquery .XPathException .execAndAddErrorIfMissing ;
48
+
46
49
/**
47
50
* @author Luigi P. Bai, [email protected] , 2004
48
51
* @author gev
@@ -65,35 +68,35 @@ public XMLDBAbstractCollectionManipulator(final XQueryContext context, final Fun
65
68
this .errorIfAbsent = errorIfAbsent ;
66
69
}
67
70
68
- public static LocalCollection getLocalCollection (final XQueryContext context , final String name ) throws XMLDBException {
71
+ public static LocalCollection getLocalCollection (final Expression callingExpression , final XQueryContext context , final String name ) throws XMLDBException {
69
72
try {
70
- return new InTxnLocalCollection (context .getSubject (), context .getBroker ().getBrokerPool (), null , new AnyURIValue (name ).toXmldbURI ());
73
+ return new InTxnLocalCollection (context .getSubject (), context .getBroker ().getBrokerPool (), null , execAndAddErrorIfMissing ( callingExpression , () -> new AnyURIValue (name ).toXmldbURI () ));
71
74
} catch (final XPathException e ) {
72
75
throw new XMLDBException (ErrorCodes .INVALID_URI , e );
73
76
}
74
77
}
75
78
76
- public static Collection getCollection (final XQueryContext context , final String collectionUri , final Optional <String > username , final Optional <String > password ) throws XMLDBException {
79
+ public static Collection getCollection (final Expression callingExpression , final XQueryContext context , final String collectionUri , final Optional <String > username , final Optional <String > password ) throws XMLDBException {
77
80
final Collection collection ;
78
81
if (!collectionUri .startsWith ("xmldb:" )) {
79
82
// Must be a LOCAL collection
80
- collection = getLocalCollection (context , collectionUri );
83
+ collection = getLocalCollection (callingExpression , context , collectionUri );
81
84
82
85
} else if (collectionUri .startsWith ("xmldb:exist:///" )) {
83
86
// Must be a LOCAL collection
84
- collection = getLocalCollection (context , collectionUri .replaceFirst ("xmldb:exist://" , "" ));
87
+ collection = getLocalCollection (callingExpression , context , collectionUri .replaceFirst ("xmldb:exist://" , "" ));
85
88
86
89
} else if (collectionUri .startsWith ("xmldb:exist://embedded-eXist-server" )) {
87
90
// Must be a LOCAL collection
88
- collection = getLocalCollection (context , collectionUri .replaceFirst ("xmldb:exist://embedded-eXist-server" , "" ));
91
+ collection = getLocalCollection (callingExpression , context , collectionUri .replaceFirst ("xmldb:exist://embedded-eXist-server" , "" ));
89
92
90
93
} else if (collectionUri .startsWith ("xmldb:exist://localhost" )) {
91
94
// Must be a LOCAL collection
92
- collection = getLocalCollection (context , collectionUri .replaceFirst ("xmldb:exist://localhost" , "" ));
95
+ collection = getLocalCollection (callingExpression , context , collectionUri .replaceFirst ("xmldb:exist://localhost" , "" ));
93
96
94
97
} else if (collectionUri .startsWith ("xmldb:exist://127.0.0.1" )) {
95
98
// Must be a LOCAL collection
96
- collection = getLocalCollection (context , collectionUri .replaceFirst ("xmldb:exist://127.0.0.1" , "" ));
99
+ collection = getLocalCollection (callingExpression , context , collectionUri .replaceFirst ("xmldb:exist://127.0.0.1" , "" ));
97
100
98
101
} else {
99
102
// Right now, the collection is retrieved as GUEST. Need to figure out how to
@@ -131,7 +134,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence)
131
134
}
132
135
try {
133
136
//TODO: use xmldbURI
134
- collection = getLocalCollection (context , internalCol .getURI ().toString ());
137
+ collection = getLocalCollection (this , context , internalCol .getURI ().toString ());
135
138
if (LOGGER .isDebugEnabled ()) {
136
139
LOGGER .debug ("Loaded collection {}" , collection .getName ());
137
140
}
@@ -148,7 +151,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence)
148
151
final String collectionURI = args [paramNumber ].getStringValue ();
149
152
if (collectionURI != null ) {
150
153
try {
151
- collection = getCollection (context , collectionURI , Optional .empty (), Optional .empty ());
154
+ collection = getCollection (this , context , collectionURI , Optional .empty (), Optional .empty ());
152
155
} catch (final XMLDBException xe ) {
153
156
if (errorIfAbsent ) {
154
157
throw new XPathException (this , "Could not locate collection: " + collectionURI , xe );
@@ -187,9 +190,9 @@ static public final Collection createCollection(final Collection parentColl, fin
187
190
return child ;
188
191
}
189
192
190
- static public final Collection createCollectionPath (final Collection parentColl , final String relPath ) throws XMLDBException , XPathException {
193
+ protected final Collection createCollectionPath (final Collection parentColl , final String relPath ) throws XMLDBException , XPathException {
191
194
Collection current = parentColl ;
192
- final StringTokenizer tok = new StringTokenizer (new AnyURIValue (relPath ).toXmldbURI ().toString (), "/" );
195
+ final StringTokenizer tok = new StringTokenizer (execAndAddErrorIfMissing ( this , () -> new AnyURIValue (relPath ).toXmldbURI ().toString () ), "/" );
193
196
while (tok .hasMoreTokens ()) {
194
197
final String token = tok .nextToken ();
195
198
current = createCollection (current , token );
0 commit comments