1 23 24 package org.hammurapi.inspectors; 25 26 import java.io.FileWriter ; 27 import java.io.IOException ; 28 import java.io.Writer ; 29 import java.util.Properties ; 30 31 import org.hammurapi.InspectorBase; 32 import org.hammurapi.HammurapiException; 33 import org.hammurapi.results.AnnotationContext; 34 import org.hammurapi.results.InlineAnnotation; 35 import org.hammurapi.results.LinkedAnnotation; 36 37 import com.pavelvlasov.config.ConfigurationException; 38 import com.pavelvlasov.jsel.CompilationUnit; 39 40 51 public class SimpleAnnotationSample extends InspectorBase { 52 53 public void visit(final CompilationUnit compilationUnit) { 54 context.annotate(new LinkedAnnotation() { 55 private String path; 56 private String cuPath=compilationUnit.getRelativeName(); 57 58 public String getName() { 59 return getContext().getDescriptor().getName(); 60 } 61 62 public String getPath() { 63 return path; 64 } 65 66 public void render(final AnnotationContext context) throws HammurapiException { 67 final AnnotationContext.FileEntry linkEntry=context.getNextFile(".txt"); 68 69 try { 70 Writer out=new FileWriter (linkEntry.getFile()); 71 try { 72 out.write("Hello, world!!!"); 73 } finally { 74 out.close(); 75 } 76 } catch (IOException e) { 77 throw new HammurapiException("Cannot save "+linkEntry.getFile().getAbsolutePath(), e); 78 } 79 80 AnnotationContext.FileEntry fileEntry=context.getNextFile(context.getExtension()); 81 path=fileEntry.getPath(); try { 83 Writer out=new FileWriter (fileEntry.getFile()); 84 try { 85 out.write("<HTML><BODY><H1>My simple annotation</H1>"+ 86 "PI: "+pi+ 87 "<P><a HREF=\""+linkEntry.getPath()+"\">Greeting</a>" + 88 "</BODY></HTML>"); 89 } finally { 90 out.close(); 91 } 92 } catch (IOException e) { 93 throw new HammurapiException("Cannot save "+linkEntry.getFile().getAbsolutePath(), e); 94 } 95 } 96 97 public Properties getProperties() { 98 return null; 99 } 100 }); 101 102 context.annotate(new InlineAnnotation() { 103 104 public String getContent() { 105 return "<DIV style=\"border:solid; background-color:yellow\">Simple annotation sample</DIV>"; 106 } 107 108 public String getName() { 109 return getContext().getDescriptor().getName(); 110 } 111 112 public void render(AnnotationContext context) throws HammurapiException { 113 115 } 116 117 public Properties getProperties() { 118 return null; 119 } 120 121 }); 122 } 123 124 private Double pi; 125 126 public void setParameter(String name, Object parameter) throws ConfigurationException { 127 if ("pi".equals(name)) { 128 pi=(Double ) parameter; 129 } else { 130 throw new ConfigurationException("Parameter "+name+" is not supported"); 131 } 132 } 133 134 public String getConfigInfo() { 135 return "PI="+pi; 136 } 137 138 } 139 | Popular Tags |