org.xwiki.rendering.util
Class IdGenerator

java.lang.Object
  extended by 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$

Constructor Summary
IdGenerator()
           
 
Method Summary
 String generateUniqueId(String text)
          Same as generateUniqueId(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IdGenerator

public IdGenerator()
Method Detail

generateUniqueId

public String generateUniqueId(String text)
Same as generateUniqueId(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.

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.



Copyright © 2004-2014 XWiki. All Rights Reserved.