View Javadoc

1   package com.atlassian.plugin.webresource;
2   
3   import java.io.IOException;
4   import java.io.OutputStream;
5   
6   /**
7    * This should only be used for annotating Javascript resources. It will wrap each Javascript resource
8    * in a try/catch block with console logging in the catch.
9    * 
10   * This implementation is stateless.
11   */
12  class TryCatchJsResourceContentAnnotator implements ResourceContentAnnotator
13  {
14      @Override
15      public void before(OutputStream stream) throws IOException
16      {
17          stream.write("try {\n".getBytes());
18      }
19  
20      @Override
21      public void after(OutputStream stream) throws IOException
22      {
23          stream.write(("\n} catch (err) {\n    if (console && console.log && console.error) {\n        console.log(\"Error running batched script.\");\n        console.error(err);\n    }\n}\n\n").getBytes());
24      }
25  }