Class DefinitionEnhancementHandler
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.cms.transformation.AbstractEnhancementHandler
-
- org.ametys.plugins.glossary.transformation.DefinitionEnhancementHandler
-
- All Implemented Interfaces:
Component
,Contextualizable
,LogEnabled
,Serviceable
,ContentHandler
,LexicalHandler
public class DefinitionEnhancementHandler extends AbstractEnhancementHandler implements Component, Serviceable, Contextualizable
Definition enhancement handler.
-
-
Field Summary
Fields Modifier and Type Field Description private static Set<String>
__IGNORE_NAMESPACES
The namespaces in which to ignore the glossary words.private static Set<String>
__IGNORE_TAGS
The tags in which to ignore the glossary words.protected Context
_context
The avalon context.protected Map<String,Definition>
_definitions
The word definitions.protected String
_glossaryHref
The glossary page href.protected Map<String,Integer>
_ignoredNamespaceStack
Ignored namespace stack.private int
_inIgnoredTag
True if we are processing a paragraph, false otherwise.private RenderingContextHandler
_renderingContextHandler
protected AmetysObjectResolver
_resolver
The ametys object resolver.protected SiteManager
_siteManager
The site managerprotected URIResolverExtensionPoint
_uriResolver
The page URI resolver.static String
ROLE
The Avalon role.-
Fields inherited from class org.ametys.cms.transformation.AbstractEnhancementHandler
_contentHandler, _inUnmodifiableContent, _lexicalHandler, PROCESSING_INSTRUCTION_UNMODIFIABLE
-
-
Constructor Summary
Constructors Constructor Description DefinitionEnhancementHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_charactersWithDefinitions(char[] ch, int start, int length, Content content)
SAX characters, generating definition tags on words that are present in the glossary.protected Map<String,Definition>
_getDefinitions(String siteName, String lang)
Get all the words with definitions to display.protected Page
_getGlossaryPage(String siteName, String language)
Get the glossary page in a given site and language.protected String
_getGlossaryPageHref(String siteName, String language)
Get the glossary page in a given site and language.protected Map<String,Definition>
_getWordsAndDefinitions(String siteName, String lang)
Get all the words with definitions to display.protected Pattern
_getWordsPattern(Set<String> words)
Get a regexp that matches any of the definition words.protected boolean
_searchCharacters()
Test if the currently processed characters have to be searched for glossary words or ignored.void
characters(char[] ch, int start, int length)
void
contextualize(Context context)
void
endElement(String uri, String localName, String qName)
void
service(ServiceManager serviceManager)
void
startDocument()
void
startElement(String uri, String localName, String qName, Attributes atts)
-
Methods inherited from class org.ametys.cms.transformation.AbstractEnhancementHandler
comment, endCDATA, endDocument, endDTD, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, saxError, setContentHandler, setDocumentLocator, setLexicalHandler, skippedEntity, startCDATA, startDTD, startEntity, startPrefixMapping
-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
__IGNORE_TAGS
private static final Set<String> __IGNORE_TAGS
The tags in which to ignore the glossary words.
-
__IGNORE_NAMESPACES
private static final Set<String> __IGNORE_NAMESPACES
The namespaces in which to ignore the glossary words.
-
_resolver
protected AmetysObjectResolver _resolver
The ametys object resolver.
-
_siteManager
protected SiteManager _siteManager
The site manager
-
_uriResolver
protected URIResolverExtensionPoint _uriResolver
The page URI resolver.
-
_definitions
protected Map<String,Definition> _definitions
The word definitions.
-
_glossaryHref
protected String _glossaryHref
The glossary page href.
-
_ignoredNamespaceStack
protected Map<String,Integer> _ignoredNamespaceStack
Ignored namespace stack.
-
_inIgnoredTag
private int _inIgnoredTag
True if we are processing a paragraph, false otherwise.
-
_renderingContextHandler
private RenderingContextHandler _renderingContextHandler
-
-
Constructor Detail
-
DefinitionEnhancementHandler
public DefinitionEnhancementHandler()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
startDocument
public void startDocument() throws SAXException
- Specified by:
startDocument
in interfaceContentHandler
- Overrides:
startDocument
in classAbstractEnhancementHandler
- Throws:
SAXException
-
startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classAbstractEnhancementHandler
- Throws:
SAXException
-
endElement
public void endElement(String uri, String localName, String qName) throws SAXException
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classAbstractEnhancementHandler
- Throws:
SAXException
-
characters
public void characters(char[] ch, int start, int length) throws SAXException
- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classAbstractEnhancementHandler
- Throws:
SAXException
-
_searchCharacters
protected boolean _searchCharacters()
Test if the currently processed characters have to be searched for glossary words or ignored.- Returns:
- true to search the characters for glossary words, false to ignore.
-
_charactersWithDefinitions
protected void _charactersWithDefinitions(char[] ch, int start, int length, Content content) throws SAXException
SAX characters, generating definition tags on words that are present in the glossary.- Parameters:
ch
- the characters from the XML document.start
- the start position in the array.length
- the number of characters to read from the array.content
- the content.- Throws:
SAXException
- if an error occurs generating the XML.
-
_getDefinitions
protected Map<String,Definition> _getDefinitions(String siteName, String lang)
Get all the words with definitions to display.- Parameters:
siteName
- the site name.lang
- the language.- Returns:
- an exhaustive set of the words.
-
_getWordsAndDefinitions
protected Map<String,Definition> _getWordsAndDefinitions(String siteName, String lang)
Get all the words with definitions to display.- Parameters:
siteName
- the site name.lang
- the language.- Returns:
- an exhaustive set of the words.
-
_getWordsPattern
protected Pattern _getWordsPattern(Set<String> words)
Get a regexp that matches any of the definition words.- Parameters:
words
- the words.- Returns:
- the pattern.
-
_getGlossaryPageHref
protected String _getGlossaryPageHref(String siteName, String language)
Get the glossary page in a given site and language.- Parameters:
siteName
- the site name.language
- the language.- Returns:
- the glossary page.
-
_getGlossaryPage
protected Page _getGlossaryPage(String siteName, String language)
Get the glossary page in a given site and language.- Parameters:
siteName
- the site name.language
- the language.- Returns:
- the glossary page.
-
-