@@ -74,9 +74,15 @@ public static class DefaultResourceReferenceFactory implements IResourceReferenc
74
74
{
75
75
@ Override
76
76
public ResourceReference create (Key key )
77
+ {
78
+ return create (key , true );
79
+ }
80
+
81
+ public ResourceReference create (Key key , boolean updateCache )
77
82
{
78
83
ResourceReference result = null ;
79
- if (PackageResource .exists (key ))
84
+ if (PackageResource .exists (key .getScopeClass (), key .getName (), key .getLocale (),
85
+ key .getStyle (), key .getVariation (), updateCache ))
80
86
{
81
87
result = new PackageResourceReference (key );
82
88
}
@@ -180,17 +186,28 @@ public final ResourceReference unregisterResourceReference(final Key key)
180
186
return removed ;
181
187
}
182
188
189
+ /**
190
+ * @deprecated @see {@link ResourceReferenceRegistry#getResourceReference(Class, String, Locale, String, String, boolean, boolean, boolean)}
191
+ */
192
+ public final ResourceReference getResourceReference (final Class <?> scope , final String name ,
193
+ final Locale locale , final String style , final String variation , final boolean strict ,
194
+ final boolean createIfNotFound )
195
+ {
196
+ return getResourceReference (scope , name , locale , style , variation , strict , createIfNotFound ,
197
+ true );
198
+ }
199
+
183
200
/**
184
201
* Get a resource reference matching the parameters from the registry or if not found and
185
202
* requested, create an default resource reference and add it to the registry.
186
203
* <p>
187
204
* Part of the search is scanning the class (scope) and it's superclass for static
188
205
* ResourceReference fields. Found fields get registered automatically (but are different from
189
206
* auto-generated ResourceReferences).
190
- *
207
+ *
191
208
* @see #createDefaultResourceReference(org.apache.wicket.request.resource.ResourceReference.Key)
192
209
* @see ClassScanner
193
- *
210
+ *
194
211
* @param scope
195
212
* The scope of resource reference (e.g. the Component's class)
196
213
* @param name
@@ -206,16 +223,25 @@ public final ResourceReference unregisterResourceReference(final Key key)
206
223
* @param createIfNotFound
207
224
* If true a default resource reference is created if no entry can be found in the
208
225
* registry. The newly created resource reference will be added to the registry.
226
+ * @param updateCache
227
+ * If true, the server resource stream reference cache should be updated
209
228
* @return Either the resource reference found in the registry or, if requested, a resource
210
229
* reference automatically created based on the parameters provided. The automatically
211
230
* created resource reference will automatically be added to the registry.
212
231
*/
213
- public final ResourceReference getResourceReference (final Class <?> scope , final String name ,
214
- final Locale locale , final String style , final String variation , final boolean strict ,
215
- final boolean createIfNotFound )
232
+ public ResourceReference getResourceReference (Class <?> scope , String name , Locale locale ,
233
+ String style , String variation , boolean strict , boolean createIfNotFound , boolean updateCache )
216
234
{
217
235
return getResourceReference (new Key (scope .getName (), name , locale , style , variation ),
218
- strict , createIfNotFound );
236
+ strict , createIfNotFound , updateCache );
237
+ }
238
+
239
+ /**
240
+ * @deprecated @see {@link ResourceReferenceRegistry#getResourceReference(Key, boolean, boolean, boolean)}
241
+ */
242
+ public final ResourceReference getResourceReference (final Key key , final boolean strict ,
243
+ final boolean createIfNotFound ){
244
+ return getResourceReference (key , strict , createIfNotFound , true );
219
245
}
220
246
221
247
/**
@@ -236,12 +262,14 @@ public final ResourceReference getResourceReference(final Class<?> scope, final
236
262
* @param createIfNotFound
237
263
* If true a default resource reference is created if no entry can be found in the
238
264
* registry. The newly created resource reference will be added to the registry.
265
+ * @param strict
266
+ * If true, the server resource stream reference cache should be updated
239
267
* @return Either the resource reference found in the registry or, if requested, a resource
240
268
* reference automatically created based on the parameters provided. The automatically
241
269
* created resource reference will automatically be added to the registry.
242
270
*/
243
271
public final ResourceReference getResourceReference (final Key key , final boolean strict ,
244
- final boolean createIfNotFound )
272
+ final boolean createIfNotFound , boolean updateCache )
245
273
{
246
274
ResourceReference resource = _getResourceReference (key .getScope (), key .getName (),
247
275
key .getLocale (), key .getStyle (), key .getVariation (), strict );
@@ -262,7 +290,7 @@ public final ResourceReference getResourceReference(final Key key, final boolean
262
290
// Still nothing found => Shall a new reference be auto-created?
263
291
if ((resource == null ) && createIfNotFound )
264
292
{
265
- resource = addDefaultResourceReference (key );
293
+ resource = addDefaultResourceReference (key , updateCache );
266
294
}
267
295
}
268
296
@@ -334,12 +362,12 @@ private ResourceReference _getResourceReference(final String scope, final String
334
362
* the data making up the resource reference
335
363
* @return The default resource created
336
364
*/
337
- private ResourceReference addDefaultResourceReference (final Key key )
365
+ private ResourceReference addDefaultResourceReference (final Key key , final boolean updateCache )
338
366
{
339
367
// Can be subclassed to create other than PackagedResourceReference
340
- ResourceReference reference = createDefaultResourceReference (key );
368
+ ResourceReference reference = createDefaultResourceReference (key , updateCache );
341
369
342
- if (reference != null )
370
+ if (reference != null && updateCache )
343
371
{
344
372
// number of RRs which can be auto-added is restricted (cache size). Remove entries, and
345
373
// unregister excessive ones, if needed.
@@ -383,6 +411,14 @@ private void enforceAutoAddedCacheSize(int maxSize)
383
411
}
384
412
}
385
413
414
+ /**
415
+ * @deprecated @see {@link ResourceReferenceRegistry#createDefaultResourceReference(Key, boolean)}
416
+ */
417
+ protected ResourceReference createDefaultResourceReference (final Key key )
418
+ {
419
+ return createDefaultResourceReference (key , true );
420
+ }
421
+
386
422
/**
387
423
* Creates a default resource reference in case no registry entry and it was requested to create
388
424
* one.
@@ -393,14 +429,20 @@ private void enforceAutoAddedCacheSize(int maxSize)
393
429
* the data making up the resource reference
394
430
* @return The {@link ResourceReference} created or {@code null} if not successful
395
431
*/
396
- protected ResourceReference createDefaultResourceReference (final Key key )
432
+ protected ResourceReference createDefaultResourceReference (final Key key , final boolean updateCache )
397
433
{
398
434
IResourceReferenceFactory factory = getResourceReferenceFactory ();
399
435
if (factory == null )
400
436
{
401
437
factory = new DefaultResourceReferenceFactory ();
402
438
}
403
- return factory .create (key );
439
+ if (factory instanceof DefaultResourceReferenceFactory defaultFactory )
440
+ {
441
+ return defaultFactory .create (key , updateCache );
442
+
443
+ } else {
444
+ return factory .create (key );
445
+ }
404
446
}
405
447
406
448
/**
0 commit comments