Class SnippetMacro
java.lang.Object
org.apache.maven.doxia.macro.AbstractMacro
org.apache.maven.doxia.macro.snippet.SnippetMacro
- All Implemented Interfaces:
Macro
A macro that prints out the (source code) content of a file or a URL.
-
Field Summary
FieldsModifier and TypeFieldDescriptionHolds the cache.private booleanDebug.private static final intprivate booleanin case of Exception during snippet download error will ignored and empty content returned.private static final org.slf4j.LoggerHolds the time cache.private longOne hour default cache. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcacheSnippet(URL url, String id, String content) Puts the given snippet into the cache.voidexecute(Sink sink, MacroRequest request) Execute the current macro using the given MacroRequest, and emit events into the given sink.private StringgetCachedSnippet(URL url, String id) Return a snippet from the cache.private StringBuffergetSnippet(URL url, String encoding, String id) Return a snippet of the given url.(package private) longgetTimeCached(URL url, String id) Return the absolute value of when the snippet has been cached.private StringglobalSnippetId(URL url, String id) Return a global identifier for the snippet.(package private) booleanisCacheTimedout(URL url, String id) Return true if the snippet has been cached longer than the current timeout.private voidremoveFromCache(URL url, String id) Removes the snippet from the cache.voidsetCacheTimeout(int time) Set the cache timeout.(package private) longtimeInCache(URL url, String id) Return the time the snippet has been cached.Methods inherited from class AbstractMacro
getAttributesFromMap
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
cache
-
HOUR
private static final int HOUR- See Also:
-
timeout
private long timeoutOne hour default cache. -
timeCached
-
debug
private boolean debugDebug. -
ignoreDownloadError
private boolean ignoreDownloadErrorin case of Exception during snippet download error will ignored and empty content returned.
-
-
Constructor Details
-
SnippetMacro
public SnippetMacro()
-
-
Method Details
-
execute
Description copied from interface:MacroExecute the current macro using the given MacroRequest, and emit events into the given sink.- Parameters:
sink- The sink to receive the events.request- The corresponding MacroRequest.- Throws:
MacroExecutionException- if an error occurred during execution.
-
getSnippet
Return a snippet of the given url.- Parameters:
url- The URL to parse.encoding- The encoding of the URL to parse.id- The id of the snippet.- Returns:
- The snippet.
- Throws:
IOException- if something goes wrong.
-
getCachedSnippet
-
isCacheTimedout
-
timeInCache
-
getTimeCached
-
removeFromCache
-
globalSnippetId
-
cacheSnippet
-
setCacheTimeout
public void setCacheTimeout(int time) Set the cache timeout.- Parameters:
time- The timeout to set.
-