Class HtmlElementIdCreator
- java.lang.Object
-
- com.atlassian.confluence.content.render.xhtml.HtmlElementIdCreator
-
- All Implemented Interfaces:
ElementIdCreator
public class HtmlElementIdCreator extends Object implements ElementIdCreator
A non-thread safe class used to create HTML ids within a render 'context'.
-
-
Constructor Summary
Constructors Constructor Description HtmlElementIdCreator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
convertToIdHtml5(String original)
The draft HTML5 spec states that the id attribute value must be unique amongst all the IDs in the element's home subtree and must contain at least one character.String
generateId()
The current implementation is very simplistic and will simply create id's of the pattern "id-<n>".String
generateId(String basis)
The draft HTML5 spec states that the id attribute value must be unique amongst all the IDs in the element's home subtree and must contain at least one character.
-
-
-
Method Detail
-
generateId
public String generateId()
The current implementation is very simplistic and will simply create id's of the pattern "id-<n>".- Specified by:
generateId
in interfaceElementIdCreator
- Returns:
- an auto-generate id unique within the context of a particular
ConversionContext
.
-
generateId
public String generateId(String basis)
The draft HTML5 spec states that the id attribute valuemust be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.
(As specified at http://dev.w3.org/html5/spec/elements.html#the-id-attribute).This method will take an arbitrary String and ensure that the above encoding is followed as well as ensuring that the id returned is unique (within the scope of this
HtmlElementIdCreator
instance).- Specified by:
generateId
in interfaceElementIdCreator
- Parameters:
basis
- the string to be converted to an id- Returns:
- a valid id String unique to the scope of the
HtmlElementIdCreator
instance.
-
convertToIdHtml5
public static String convertToIdHtml5(String original)
The draft HTML5 spec states that the id attribute valuemust be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.
(As specified at http://dev.w3.org/html5/spec/elements.html#the-id-attribute).This method will not generate IDs that are safe to put directly into HTML or URLs. The result of this method should be appropriately encoded for the environment in which it is used.
This method will take an arbitrary String return a valid HTML5 ID derived from the original string. It will strip out all whitespace. This method does not create unique ids. You should instantiate an instance of HtmlElementIdCreator and use
generateId(String)
if you have this requirement.- Parameters:
original
- the string to be converted to an id- Returns:
- a valid id
- Since:
- 4.3
-
-