Class SnippetMacro

java.lang.Object
org.apache.maven.doxia.macro.AbstractMacro
org.apache.maven.doxia.macro.snippet.SnippetMacro
All Implemented Interfaces:
LogEnabled, Macro

@Component(role=Macro.class, hint="snippet") public class SnippetMacro extends AbstractMacro
A macro that prints out the content of a file or a URL.
  • Field Details

    • cache

      private static Map<String,String> cache
      Holds the cache.
    • HOUR

      private static final int HOUR
      See Also:
    • timeout

      private long timeout
      One hour default cache.
    • timeCached

      private static Map<String,Long> timeCached
      Holds the time cache.
    • debug

      private boolean debug
      Debug.
    • ignoreDownloadError

      private boolean ignoreDownloadError
      in case of Exception during snippet download error will ignored and empty content returned.
  • Constructor Details

    • SnippetMacro

      public SnippetMacro()
  • Method Details

    • execute

      public void execute(Sink sink, MacroRequest request) throws MacroExecutionException
      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

      private StringBuffer getSnippet(URL url, String encoding, String id) throws IOException
      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

      private String getCachedSnippet(URL url, String id)
      Return a snippet from the cache.
      Parameters:
      url - The URL to parse.
      id - The id of the snippet.
      Returns:
      The snippet.
    • isCacheTimedout

      boolean isCacheTimedout(URL url, String id)
      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

      long timeInCache(URL url, String id)
      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

      long getTimeCached(URL url, String id)
      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

      private void removeFromCache(URL url, String id)
      Removes the snippet from the cache.
      Parameters:
      url - The URL to parse.
      id - The id of the snippet.
    • globalSnippetId

      private String globalSnippetId(URL url, String id)
      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

      public void cacheSnippet(URL url, String id, String content)
      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.