Class SnippetMacro
java.lang.Object
org.apache.maven.doxia.macro.AbstractMacro
org.apache.maven.doxia.macro.snippet.SnippetMacro
- All Implemented Interfaces:
LogEnabled
,Macro
A macro that prints out the content of a file or a URL.
-
Field Summary
FieldsModifier and TypeFieldDescriptionHolds the cache.private boolean
Debug.private static final int
private boolean
in case of Exception during snippet download error will ignored and empty content returned.Holds the time cache.private long
One hour default cache. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
cacheSnippet
(URL url, String id, String content) Puts the given snippet into the cache.void
execute
(Sink sink, MacroRequest request) Execute the current macro using the given MacroRequest, and emit events into the given sink.private String
getCachedSnippet
(URL url, String id) Return a snippet from the cache.private StringBuffer
getSnippet
(URL url, String encoding, String id) Return a snippet of the given url.(package private) long
getTimeCached
(URL url, String id) Return the absolute value of when the snippet has been cached.private String
globalSnippetId
(URL url, String id) Return a global identifier for the snippet.(package private) boolean
isCacheTimedout
(URL url, String id) Return true if the snippet has been cached longer than the current timeout.private void
removeFromCache
(URL url, String id) Removes the snippet from the cache.void
setCacheTimeout
(int time) Set the cache timeout.(package private) long
timeInCache
(URL url, String id) Return the time the snippet has been cached.Methods inherited from class org.apache.maven.doxia.macro.AbstractMacro
enableLogging, getAttributesFromMap, getLog, required
-
Field Details
-
cache
Holds the cache. -
HOUR
private static final int HOUR- See Also:
-
timeout
private long timeoutOne hour default cache. -
timeCached
Holds the time cache. -
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
Execute 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
Return a snippet from the cache.- Parameters:
url
- The URL to parse.id
- The id of the snippet.- Returns:
- The snippet.
-
isCacheTimedout
Return true if the snippet has been cached longer than the current timeout.- Parameters:
url
- The URL to parse.id
- The id of the snippet.- Returns:
- True if timeout exceeded.
-
timeInCache
Return the time the snippet has been cached.- Parameters:
url
- The URL to parse.id
- The id of the snippet.- Returns:
- The cache time.
-
getTimeCached
Return the absolute value of when the snippet has been cached.- Parameters:
url
- The URL to parse.id
- The id of the snippet.- Returns:
- The cache time.
-
removeFromCache
Removes the snippet from the cache.- Parameters:
url
- The URL to parse.id
- The id of the snippet.
-
globalSnippetId
Return a global identifier for the snippet.- Parameters:
url
- The URL to parse.id
- The id of the snippet.- Returns:
- An identifier, concatenated url and id, or just url.toString() if id is empty or null.
-
cacheSnippet
Puts the given snippet into the cache.- Parameters:
url
- The URL to parse.id
- The id of the snippet.content
- The content of the snippet.
-
setCacheTimeout
public void setCacheTimeout(int time) Set the cache timeout.- Parameters:
time
- The timeout to set.
-