Package org.xwiki.rendering.util
Class IdGenerator
java.lang.Object
org.xwiki.rendering.util.IdGenerator
Stateful generator of id attributes. It's stateful since it remembers the generated ids. Thus a new instance of it
should be used for each document.
- Since:
- 1.6M1
- Version:
- $Id: e646bbe2120dffa44b087cb8ba6848314c9a175d $
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty id generator.IdGenerator(IdGenerator idGenerator) Clone an id generator. -
Method Summary
Modifier and TypeMethodDescriptiongenerateUniqueId(String text) Same asgenerateUniqueId(String, String)but with a fixed prefix of "I".generateUniqueId(String prefix, String text) Generate a unique id attribute using the passed text as the seed value.voidRemove the saved previously generated id to make it available again.voidreset()Reset the known generated ids.
-
Constructor Details
-
IdGenerator
public IdGenerator()Create an empty id generator. -
IdGenerator
Clone an id generator.- Parameters:
idGenerator- the id generator to copy- Since:
- 10.5RC1, 9.11.6
-
-
Method Details
-
generateUniqueId
Same asgenerateUniqueId(String, String)but with a fixed prefix of "I".- Parameters:
text- the text used to generate the unique id- Returns:
- the unique id. For example "Hello world" will generate "IHelloworld".
-
generateUniqueId
Generate a unique id attribute using the passed text as the seed value. The generated id complies with the XHTML specification. Extract from XHTML RFC:When defining fragment identifiers to be backward-compatible, only strings matching the pattern [A-Za-z][A-Za-z0-9:_.-]* should be used.This method is thread-safe since 14.2RC1 and 13.10.4.
- Parameters:
prefix- the prefix of the identifier. Has to match [a-zA-Z].text- the text used to generate the unique id- Returns:
- the unique id. For example "Hello world" will generate prefix + "Helloworld".
-
remove
Remove the saved previously generated id to make it available again.- Parameters:
id- the id to remove from the generated ids.
-
reset
public void reset()Reset the known generated ids.
-