1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.model.script

File ModelScriptService.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

12
89
34
1
672
277
52
0.58
2.62
34
1.53

Classes

Class Line # Actions
ModelScriptService 61 89 0% 52 28
0.792592679.3%
 

Contributing tests

This file is covered by 20 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.model.script;
21   
22    import java.util.Arrays;
23    import java.util.List;
24    import java.util.Locale;
25   
26    import javax.inject.Inject;
27    import javax.inject.Named;
28    import javax.inject.Singleton;
29   
30    import org.apache.commons.lang3.StringUtils;
31    import org.slf4j.Logger;
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.component.manager.ComponentLookupException;
34    import org.xwiki.component.manager.ComponentManager;
35    import org.xwiki.model.EntityType;
36    import org.xwiki.model.reference.AttachmentReference;
37    import org.xwiki.model.reference.ClassPropertyReference;
38    import org.xwiki.model.reference.DocumentReference;
39    import org.xwiki.model.reference.DocumentReferenceResolver;
40    import org.xwiki.model.reference.EntityReference;
41    import org.xwiki.model.reference.EntityReferenceProvider;
42    import org.xwiki.model.reference.EntityReferenceResolver;
43    import org.xwiki.model.reference.EntityReferenceSerializer;
44    import org.xwiki.model.reference.EntityReferenceTree;
45    import org.xwiki.model.reference.EntityReferenceValueProvider;
46    import org.xwiki.model.reference.ObjectPropertyReference;
47    import org.xwiki.model.reference.ObjectReference;
48    import org.xwiki.model.reference.SpaceReference;
49    import org.xwiki.model.reference.WikiReference;
50    import org.xwiki.script.service.ScriptService;
51   
52    /**
53    * Provides Model-specific Scripting APIs.
54    *
55    * @version $Id: 8afe9c0ca44c96ffab4275a932e671889deb463c $
56    * @since 2.3M1
57    */
58    @Component
59    @Named("model")
60    @Singleton
 
61    public class ModelScriptService implements ScriptService
62    {
63    /**
64    * The default hint used when resolving references.
65    */
66    private static final String DEFAULT_RESOLVER_HINT = "current";
67   
68    /**
69    * The default hint used when serializing references.
70    */
71    private static final String DEFAULT_SERIALIZER_HINT = "compact";
72   
73    /**
74    * The object used to log messages.
75    */
76    @Inject
77    private Logger logger;
78   
79    /**
80    * Used to dynamically look up component implementations based on a given hint.
81    */
82    @Inject
83    private ComponentManager componentManager;
84   
85    @Inject
86    private EntityReferenceSerializer<String> defaultSerializer;
87   
88    /**
89    * Create a Document Reference from a passed wiki, space and page names, which can be empty strings or {@code null}
90    * in which case they are resolved using the {@value #DEFAULT_RESOLVER_HINT} resolver.
91    *
92    * @param wiki the wiki reference name to use (can be empty or null)
93    * @param space the space reference name to use (can be empty or null)
94    * @param page the page reference name to use (can be empty or null)
95    * @return the typed Document Reference object or null if no Resolver with the passed hint could be found
96    * @since 2.3M2
97    */
 
98  8820 toggle public DocumentReference createDocumentReference(String wiki, String space, String page)
99    {
100  8820 return createDocumentReference(wiki, space, page, DEFAULT_RESOLVER_HINT);
101    }
102   
103    /**
104    * Create a Document Reference from a passed wiki, list of spaces and page names, which can be empty strings or
105    * {@code null} in which case they are resolved using the {@value #DEFAULT_RESOLVER_HINT} resolver.
106    *
107    * @param wiki the wiki reference name to use (can be empty or null)
108    * @param spaces the list of spaces name to use (can be empty or null)
109    * @param page the page reference name to use (can be empty or null)
110    * @return the typed Document Reference object or null if no Resolver with the passed hint could be found
111    * @since 7.2M2
112    */
 
113  1 toggle public DocumentReference createDocumentReference(String wiki, List<String> spaces, String page)
114    {
115  1 return createDocumentReference(wiki, spaces, page, DEFAULT_RESOLVER_HINT);
116    }
117   
118    /**
119    * Create a new reference with the passed {@link Locale}.
120    *
121    * @param reference the reference (with or without locale)
122    * @param locale the locale of the new reference
123    * @return the typed Document Reference object
124    * @since 5.4RC1
125    */
 
126  2 toggle public DocumentReference createDocumentReference(DocumentReference reference, Locale locale)
127    {
128  2 return new DocumentReference(reference, locale);
129    }
130   
131    /**
132    * Creates a new {@link DocumentReference} from a given page name and the reference of the parent space.
133    *
134    * @param pageName the page name
135    * @param parent the parent space reference
136    * @return the typed {@link DocumentReference} object
137    * @since 7.3M2
138    */
 
139  39 toggle public DocumentReference createDocumentReference(String pageName, SpaceReference parent)
140    {
141  39 return new DocumentReference(pageName, parent);
142    }
143   
144    /**
145    * Create a Document Reference from a passed wiki, space and page names, which can be empty strings or null in which
146    * case they are resolved against the Resolver having the hint passed as parameter. Valid hints are for example
147    * "default", "current", "currentmixed".
148    *
149    * @param wiki the wiki reference name to use (can be empty or null)
150    * @param space the space reference name to use (can be empty or null)
151    * @param page the page reference name to use (can be empty or null)
152    * @param hint the hint of the Resolver to use in case any parameter is empty or null
153    * @return the typed Document Reference object or null if no Resolver with the passed hint could be found
154    */
 
155  8828 toggle public DocumentReference createDocumentReference(String wiki, String space, String page, String hint)
156    {
157  8828 return createDocumentReference(wiki, StringUtils.isEmpty(space) ? null : Arrays.asList(space), page, hint);
158    }
159   
160    /**
161    * Create a Document Reference from a passed wiki, list of spaces and page names, which can be empty strings or null
162    * in which case they are resolved against the Resolver having the hint passed as parameter. Valid hints are for
163    * example "default", "current", "currentmixed".
164    *
165    * @param wiki the wiki reference name to use (can be empty or null)
166    * @param spaces the spaces list to use (can be empty or null)
167    * @param page the page reference name to use (can be empty or null)
168    * @param hint the hint of the Resolver to use in case any parameter is empty or null
169    * @return the typed Document Reference object or null if no Resolver with the passed hint could be found
170    *
171    * @since 7.2M2
172    */
 
173  8831 toggle public DocumentReference createDocumentReference(String wiki, List<String> spaces, String page, String hint)
174    {
175  8831 EntityReference reference = null;
176  8831 if (!StringUtils.isEmpty(wiki)) {
177  7459 reference = new EntityReference(wiki, EntityType.WIKI);
178    }
179   
180  8831 if (spaces != null && !spaces.isEmpty()) {
181  8578 for (String space : spaces) {
182  8579 reference = new EntityReference(space, EntityType.SPACE, reference);
183    }
184    }
185  8831 if (!StringUtils.isEmpty(page)) {
186  8581 reference = new EntityReference(page, EntityType.DOCUMENT, reference);
187    }
188   
189  8831 DocumentReference documentReference;
190  8831 try {
191  8831 DocumentReferenceResolver<EntityReference> resolver =
192    this.componentManager.getInstance(DocumentReferenceResolver.TYPE_REFERENCE, hint);
193  8828 documentReference = resolver.resolve(reference);
194    } catch (ComponentLookupException e) {
195  2 try {
196    // Ensure backward compatibility with older scripts that use hints like "default/reference" because at
197    // the time they were written we didn't have support for generic types in component role.
198  2 DocumentReferenceResolver<EntityReference> drr =
199    this.componentManager.getInstance(DocumentReferenceResolver.class, hint);
200  1 documentReference = drr.resolve(reference);
201  1 this.logger.warn("Deprecated usage of DocumentReferenceResolver with hint [{}]. "
202    + "Please consider using a DocumentReferenceResolver that takes into account generic types.", hint);
203    } catch (ComponentLookupException ex) {
204  1 documentReference = null;
205    }
206    }
207  8831 return documentReference;
208    }
209   
210    /**
211    * Creates an {@link AttachmentReference} from a file name and a reference to the document holding that file.
212    *
213    * @param documentReference a reference to the document the file is attached to
214    * @param fileName the name of a file attached to a document
215    * @return a reference to the specified attachment
216    * @since 2.5M2
217    */
 
218  3 toggle public AttachmentReference createAttachmentReference(DocumentReference documentReference, String fileName)
219    {
220  3 return new AttachmentReference(fileName, documentReference);
221    }
222   
223    /**
224    * Creates a {@link WikiReference} from a string representing the wiki name.
225    *
226    * @param wikiName the wiki name (eg "xwiki")
227    * @return the reference to the wiki
228    * @since 5.0M1
229    */
 
230  28 toggle public WikiReference createWikiReference(String wikiName)
231    {
232  28 return new WikiReference(wikiName);
233    }
234   
235    /**
236    * Creates a {@link SpaceReference} from a string representing the space name.
237    *
238    * @param spaceName the space name (eg "Main")
239    * @param parent the wiki reference in which the space is located
240    * @return the reference to the space
241    * @since 5.0M1
242    */
 
243  1 toggle public SpaceReference createSpaceReference(String spaceName, WikiReference parent)
244    {
245  1 return new SpaceReference(spaceName, parent);
246    }
247   
248    /**
249    * Creates a {@link SpaceReference} from a string representing the space name and the reference of the parent space.
250    *
251    * @param spaceName the space name (e.g. "Main")
252    * @param parent the reference of the parent space
253    * @return the reference to the space
254    * @since 7.3RC1
255    */
 
256  2 toggle public SpaceReference createSpaceReference(String spaceName, SpaceReference parent)
257    {
258  2 return new SpaceReference(spaceName, parent);
259    }
260   
261    /**
262    * Creates a {@link SpaceReference} from a list of string representing the space name and the name of its parents.
263    *
264    * @param spaces the list of the spaces name (eg ["A", "B", "C"])
265    * @param parent the wiki reference in which the space is located
266    * @return the reference to the space
267    * @since 7.2M2
268    */
 
269  1 toggle public SpaceReference createSpaceReference(List<String> spaces, WikiReference parent)
270    {
271  1 SpaceReference spaceReference = null;
272  1 EntityReference parentReference = parent;
273  1 for (String space : spaces) {
274  3 spaceReference = new SpaceReference(space, parentReference);
275  3 parentReference = spaceReference;
276    }
277  1 return spaceReference;
278    }
279   
280    /**
281    * Creates any {@link EntityReference} from a string.
282    *
283    * @param name the entity reference name (eg "page")
284    * @param type the entity type (eg "wiki", "space", "document", etc)
285    * @return the created reference
286    * @since 5.0M1
287    */
 
288  2 toggle public EntityReference createEntityReference(String name, EntityType type)
289    {
290  2 return new EntityReference(name, type);
291    }
292   
293    /**
294    * Creates any {@link EntityReference} from a string.
295    *
296    * @param name the entity reference name (eg "page")
297    * @param type the entity type (eg "wiki", "space", "document", etc)
298    * @param parent the entity parent
299    * @return the created reference
300    * @since 5.0M1
301    */
 
302  310 toggle public EntityReference createEntityReference(String name, EntityType type, EntityReference parent)
303    {
304  310 return new EntityReference(name, type, parent);
305    }
306   
307    /**
308    * @param stringRepresentation the space reference specified as a String (using the "wiki:space" format and with
309    * special characters escaped where required)
310    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve a space
311    * reference relative to another entity reference
312    * @return the typed Space Reference object (resolved using the {@value #DEFAULT_RESOLVER_HINT} resolver)
313    * @since 5.0M1
314    */
 
315  6894 toggle public SpaceReference resolveSpace(String stringRepresentation, Object... parameters)
316    {
317  6894 return resolveSpace(stringRepresentation, DEFAULT_RESOLVER_HINT, parameters);
318    }
319   
320    /**
321    * @param stringRepresentation the space reference specified as a String (using the "wiki:space" format and with
322    * special characters escaped where required)
323    * @param hint the hint of the Resolver to use in case any part of the reference is missing (no wiki or no space
324    * specified)
325    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve a space
326    * reference relative to another entity reference
327    * @return the typed Space Reference object or null if no Resolver with the passed hint could be found
328    * @since 5.0M1
329    */
 
330  6895 toggle public SpaceReference resolveSpace(String stringRepresentation, String hint, Object... parameters)
331    {
332  6895 try {
333  6895 EntityReferenceResolver<String> resolver =
334    this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, hint);
335  6897 return new SpaceReference(resolver.resolve(stringRepresentation, EntityType.SPACE, parameters));
336    } catch (ComponentLookupException e) {
337  0 return null;
338    }
339    }
340   
341    /**
342    * @param stringRepresentation the document reference specified as a String (using the "wiki:space.page" format and
343    * with special characters escaped where required)
344    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve a document
345    * reference relative to another entity reference
346    * @return the typed Document Reference object (resolved using the {@value #DEFAULT_RESOLVER_HINT} resolver)
347    * @since 2.3M2
348    */
 
349  13983 toggle public DocumentReference resolveDocument(String stringRepresentation, Object... parameters)
350    {
351  13983 return resolveDocument(stringRepresentation, DEFAULT_RESOLVER_HINT, parameters);
352    }
353   
354    /**
355    * @param stringRepresentation the document reference specified as a String (using the "wiki:space.page" format and
356    * with special characters escaped where required)
357    * @param hint the hint of the Resolver to use in case any part of the reference is missing (no wiki specified, no
358    * space or no page)
359    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve a document
360    * reference relative to another entity reference
361    * @return the typed Document Reference object or null if no Resolver with the passed hint could be found
362    */
 
363  28832 toggle public DocumentReference resolveDocument(String stringRepresentation, String hint, Object... parameters)
364    {
365  28835 try {
366  28834 EntityReferenceResolver<String> resolver =
367    this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, hint);
368  28835 return new DocumentReference(resolver.resolve(stringRepresentation, EntityType.DOCUMENT, parameters));
369    } catch (ComponentLookupException e) {
370  0 return null;
371    }
372    }
373   
374    /**
375    * @param stringRepresentation an attachment reference specified as {@link String} (using the "wiki:space.page@file"
376    * format and with special characters escaped where required)
377    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve an attachment
378    * reference relative to another entity reference
379    * @return the corresponding typed {@link AttachmentReference} object (resolved using the
380    * {@value #DEFAULT_RESOLVER_HINT} resolver)
381    * @since 2.5M2
382    */
 
383  51 toggle public AttachmentReference resolveAttachment(String stringRepresentation, Object... parameters)
384    {
385  51 return resolveAttachment(stringRepresentation, DEFAULT_RESOLVER_HINT, parameters);
386    }
387   
388    /**
389    * @param stringRepresentation an attachment reference specified as {@link String} (using the "wiki:space.page@file"
390    * format and with special characters escaped where required)
391    * @param hint the hint of the resolver to use in case any part of the reference is missing (no wiki specified, no
392    * space or no page)
393    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve an attachment
394    * reference relative to another entity reference
395    * @return the corresponding typed {@link AttachmentReference} object
396    * @since 2.5M2
397    */
 
398  51 toggle public AttachmentReference resolveAttachment(String stringRepresentation, String hint, Object... parameters)
399    {
400  51 try {
401  51 EntityReferenceResolver<String> resolver =
402    this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, hint);
403  51 return new AttachmentReference(resolver.resolve(stringRepresentation, EntityType.ATTACHMENT, parameters));
404    } catch (ComponentLookupException e) {
405  0 return null;
406    }
407    }
408   
409    /**
410    * @param stringRepresentation an object reference specified as {@link String} (using the "wiki:space.page^object"
411    * format and with special characters escaped where required)
412    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve an object
413    * reference relative to another entity reference
414    * @return the corresponding typed {@link ObjectReference} object (resolved using the
415    * {@value #DEFAULT_RESOLVER_HINT} resolver)
416    * @since 3.2M3
417    */
 
418  0 toggle public ObjectReference resolveObject(String stringRepresentation, Object... parameters)
419    {
420  0 return resolveObject(stringRepresentation, DEFAULT_RESOLVER_HINT, parameters);
421    }
422   
423    /**
424    * @param stringRepresentation an object reference specified as {@link String} (using the "wiki:space.page^object"
425    * format and with special characters escaped where required)
426    * @param hint the hint of the resolver to use in case any part of the reference is missing (no wiki specified, no
427    * space or no page)
428    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve an object
429    * reference relative to another entity reference
430    * @return the corresponding typed {@link ObjectReference} object
431    * @since 3.2M3
432    */
 
433  0 toggle public ObjectReference resolveObject(String stringRepresentation, String hint, Object... parameters)
434    {
435  0 try {
436  0 EntityReferenceResolver<String> resolver =
437    this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, hint);
438  0 return new ObjectReference(resolver.resolve(stringRepresentation, EntityType.OBJECT, parameters));
439    } catch (ComponentLookupException e) {
440  0 return null;
441    }
442    }
443   
444    /**
445    * @param stringRepresentation an object property reference specified as {@link String} (using the
446    * "wiki:space.page^object.property" format and with special characters escaped where required)
447    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve an object
448    * property reference relative to another entity reference
449    * @return the corresponding typed {@link ObjectPropertyReference} object (resolved using the
450    * {@value #DEFAULT_RESOLVER_HINT} resolver)
451    * @since 3.2M3
452    */
 
453  0 toggle public ObjectPropertyReference resolveObjectProperty(String stringRepresentation, Object... parameters)
454    {
455  0 return resolveObjectProperty(stringRepresentation, DEFAULT_RESOLVER_HINT, parameters);
456    }
457   
458    /**
459    * @param stringRepresentation an object property reference specified as {@link String} (using the
460    * "wiki:space.page^object.property" format and with special characters escaped where required)
461    * @param hint the hint of the resolver to use in case any part of the reference is missing (no wiki specified, no
462    * space or no page)
463    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve an object
464    * property reference relative to another entity reference
465    * @return the corresponding typed {@link ObjectPropertyReference} object
466    * @since 3.2M3
467    */
 
468  0 toggle public ObjectPropertyReference resolveObjectProperty(String stringRepresentation, String hint, Object... parameters)
469    {
470  0 try {
471  0 EntityReferenceResolver<String> resolver =
472    this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, hint);
473  0 return new ObjectPropertyReference(resolver.resolve(stringRepresentation, EntityType.OBJECT_PROPERTY,
474    parameters));
475    } catch (ComponentLookupException e) {
476  0 return null;
477    }
478    }
479   
480    /**
481    * @param stringRepresentation a class property reference specified as {@link String} (using the
482    * "wiki:Space.Class^property" format and with special characters escaped where required)
483    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve a class
484    * property reference relative to another entity reference
485    * @return the corresponding typed {@link ClassPropertyReference} object (resolved using the
486    * {@value #DEFAULT_RESOLVER_HINT} resolver)
487    * @since 5.4.2
488    * @since 6.0M1
489    */
 
490  0 toggle public ClassPropertyReference resolveClassProperty(String stringRepresentation, Object... parameters)
491    {
492  0 return resolveClassProperty(stringRepresentation, DEFAULT_RESOLVER_HINT, parameters);
493    }
494   
495    /**
496    * @param stringRepresentation a class property reference specified as {@link String} (using the
497    * "wiki:Space.Class^property" format and with special characters escaped where required)
498    * @param hint the hint of the resolver to use in case any part of the reference is missing (no wiki specified, no
499    * space or no page)
500    * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve a class
501    * property reference relative to another entity reference
502    * @return the corresponding typed {@link ClassPropertyReference} object
503    * @since 5.4.2
504    * @since 6.0M1
505    */
 
506  1 toggle public ClassPropertyReference resolveClassProperty(String stringRepresentation, String hint, Object... parameters)
507    {
508  1 try {
509  1 EntityReferenceResolver<String> resolver =
510    this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, hint);
511  1 return new ClassPropertyReference(resolver.resolve(stringRepresentation, EntityType.CLASS_PROPERTY,
512    parameters));
513    } catch (ComponentLookupException e) {
514  0 return null;
515    }
516    }
517   
518    /**
519    * @param reference the entity reference to transform into a String representation
520    * @return the string representation of the passed entity reference (using the "compact" serializer)
521    * @param parameters the optional extra parameters to pass to the Serializer; they are passed directly to
522    * {@link EntityReferenceSerializer#serialize(org.xwiki.model.reference.EntityReference, Object...)}
523    * @since 2.3M2
524    */
 
525  45 toggle public String serialize(EntityReference reference, Object... parameters)
526    {
527  45 return serialize(reference, DEFAULT_SERIALIZER_HINT, parameters);
528    }
529   
530    /**
531    * @param reference the entity reference to transform into a String representation
532    * @param hint the hint of the Serializer to use (valid hints are for example "default", "compact", "local")
533    * @param parameters the optional extra parameters to pass to the Serializer; they are passed directly to
534    * {@link EntityReferenceSerializer#serialize(org.xwiki.model.reference.EntityReference, Object...)}
535    * @return the string representation of the passed entity reference
536    */
 
537  13290 toggle public String serialize(EntityReference reference, String hint, Object... parameters)
538    {
539  13290 String result;
540  13289 try {
541  13289 EntityReferenceSerializer<String> serializer =
542    this.componentManager.getInstance(EntityReferenceSerializer.TYPE_STRING, hint);
543  13290 result = serializer.serialize(reference, parameters);
544    } catch (ComponentLookupException e) {
545  0 result = null;
546    }
547  13289 return result;
548    }
549   
550    /**
551    * Get the current value for a specific entity type, like the current space or wiki name. This doesn't return a
552    * proper entity reference, but just the string value that should be used for that type of entity.
553    *
554    * @param type the target entity type; from Velocity it's enough to use a string with the uppercase name of the
555    * entity, like {@code 'SPACE'}
556    * @return the current value for the requested entity type
557    * @since 4.3M1
558    * @deprecated since 7.4.1/8.0M1, use {@link #getEntityReference(EntityType)}
559    */
 
560  2 toggle @Deprecated
561    public String getEntityReferenceValue(EntityType type)
562    {
563  2 return getEntityReferenceValue(type, DEFAULT_RESOLVER_HINT);
564    }
565   
566    /**
567    * Get the value configured for a specific entity type, like the space name or wiki name. This doesn't return a
568    * proper entity reference, but just the string value that should be used for that type of entity.
569    *
570    * @param type the target entity type; from Velocity it's enough to use a string with the uppercase name of the
571    * entity, like {@code 'SPACE'}
572    * @param hint the hint of the value provider to use (valid hints are for example "default", "current" and
573    * "currentmixed")
574    * @return the configured value for the requested entity type, for example "Main" for the default space or "WebHome"
575    * for the default space homepage
576    * @since 4.3M1
577    * @deprecated since 7.2M1, use {@link #getEntityReference(EntityType, String)}
578    */
 
579  3 toggle @Deprecated
580    public String getEntityReferenceValue(EntityType type, String hint)
581    {
582  3 if (type == null) {
583  1 return null;
584    }
585   
586  2 try {
587  2 EntityReferenceValueProvider provider =
588    this.componentManager.getInstance(EntityReferenceValueProvider.class, hint);
589  1 return provider.getDefaultValue(type);
590    } catch (ComponentLookupException ex) {
591  1 return null;
592    }
593    }
594   
595    /**
596    * Get the current reference configured for a specific entity type, like the space reference or wiki reference. This
597    * doesn't return a full entity reference, but just the part that should be used for that type of entity.
598    *
599    * @param type the target entity type; from Velocity it's enough to use a string with the uppercase name of the
600    * entity, like {@code 'SPACE'}
601    * @return the current reference for the requested entity type, for example "Main" for the default space or
602    * "WebHome" for the default space homepage
603    * @since 7.2M1
604    */
 
605  6828 toggle public EntityReference getEntityReference(EntityType type)
606    {
607  6828 return getEntityReference(type, DEFAULT_RESOLVER_HINT);
608    }
609   
610    /**
611    * Get the reference configured for a specific entity type, like the space reference or wiki reference. This doesn't
612    * return a full entity reference, but just the part that should be used for that type of entity.
613    *
614    * @param type the target entity type; from Velocity it's enough to use a string with the uppercase name of the
615    * entity, like {@code 'SPACE'}
616    * @param hint the hint of the {@link EntityReferenceProvider} to use (valid hints are for example "default",
617    * "current" and "currentmixed")
618    * @return the configured value for the requested entity type, for example "Main" for the default space or "WebHome"
619    * for the default space homepage
620    * @since 7.2M1
621    */
 
622  8497 toggle public EntityReference getEntityReference(EntityType type, String hint)
623    {
624  8498 if (type == null) {
625  0 return null;
626    }
627   
628  8498 try {
629  8498 EntityReferenceProvider provider = this.componentManager.getInstance(EntityReferenceProvider.class, hint);
630  8498 return provider.getDefaultReference(type);
631    } catch (ComponentLookupException ex) {
632  0 return null;
633    }
634    }
635   
636    /**
637    * Convert passed references to a tree of references.
638    *
639    * @param references the references
640    * @return the references as a tree
641    * @since 5.4RC1
642    */
 
643  7 toggle public EntityReferenceTree toTree(Iterable< ? extends EntityReference> references)
644    {
645  7 return new EntityReferenceTree(references);
646    }
647   
648    /**
649    * Convert passed references to a tree of references.
650    *
651    * @param references the references
652    * @return the references as a tree
653    * @since 5.4RC1
654    */
 
655  0 toggle public EntityReferenceTree toTree(EntityReference... references)
656    {
657  0 return new EntityReferenceTree(references);
658    }
659   
660    /**
661    * Escape the passed entity name according to reference syntax.
662    *
663    * @param name the name of the entity
664    * @param type the type of the entity
665    * @return the escaped version of the passed name
666    * @since 7.2M1
667    */
 
668  0 toggle public String escape(String name, EntityType type)
669    {
670  0 return this.defaultSerializer.serialize(new EntityReference(name, type));
671    }
672    }