Package org.xwiki.rendering.util
Class IdGenerator
- java.lang.Object
-
- org.xwiki.rendering.util.IdGenerator
-
public class IdGenerator extends Object
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
Constructors Constructor Description IdGenerator()
Create an empty id generator.IdGenerator(IdGenerator idGenerator)
Clone an id generator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
generateUniqueId(String text)
Same asgenerateUniqueId(String, String)
but with a fixed prefix of "I".String
generateUniqueId(String prefix, String text)
Generate a unique id attribute using the passed text as the seed value.void
remove(String id)
Remove the saved previously generated id to make it available again.void
reset()
Reset the known generated ids.
-
-
-
Constructor Detail
-
IdGenerator
public IdGenerator()
Create an empty id generator.
-
IdGenerator
public IdGenerator(IdGenerator idGenerator)
Clone an id generator.- Parameters:
idGenerator
- the id generator to copy- Since:
- 10.5RC1, 9.11.6
-
-
Method Detail
-
generateUniqueId
public String generateUniqueId(String text)
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
public String generateUniqueId(String prefix, String text)
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
public void remove(String id)
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.
-
-