- protected void println(StringBuilder sb, int indent, Object ... objs) {
- for(int i=0;i<indent;++i) {
- sb.append(' ');
- }
- for(Object o : objs) {
- sb.append(o.toString());
- }
- sb.append('\n');
- }
-
- protected String printCell(StringBuilder sb, int indent, String current, String prev) {
- if(current.equals(prev)) {
- println(sb,indent,DUPL);
- } else {
- printCell(sb,indent,current);
- }
- return current; // use to set prev...
- }
-
- protected void printCell(StringBuilder sb, int indent, String current) {
- println(sb,indent,"<td>",current,"</td>");
- }
-
- public synchronized void inc() {
- ++count;
- }
-
- public int count() {
- return count;
- }
+ /**
+ * Record the fact that a particular Notification was marked as "sent" by Emailer.
+ *
+ * @param trans
+ * @param approver
+ * @param ln
+ */
+ public abstract void record(AuthzTrans trans, StringBuilder query, String id, List<String> notified, LastNotified ln);
+
+ /**
+ * Get Notify Body based on key of
+ * type|name
+ */
+ public static NotifyBody get(String key) {
+ return bodyMap.get(key);
+ }
+
+ /**
+ * Return set of loaded NotifyBodies
+ *
+ */
+ public static Collection<NotifyBody> getAll() {
+ // Note: The same Notify Body is entered several times with different keys.
+ // Therefore, need a Set of Values, not all the Values.
+ Set<NotifyBody> set = new HashSet<>();
+ set.addAll(bodyMap.values());
+ return set;
+ }
+
+ /**
+ * @param propAccess
+ * @throws URISyntaxException
+ *
+ */
+ public static void load(Access access) throws APIException, IOException {
+ // class load available NotifyBodies
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Package pkg = NotifyBody.class.getPackage();
+ String path = pkg.getName().replace('.', '/');
+ URL url = cl.getResource(path);
+ List<String> classNames = new ArrayList<>();
+ String urlString = url.toString();
+ if(urlString.startsWith("jar:file:")) {
+ int exclam = urlString.lastIndexOf('!');
+ JarFile jf = new JarFile(urlString.substring(9,exclam));
+ try {
+ Enumeration<JarEntry> jfe = jf.entries();
+ while(jfe.hasMoreElements()) {
+ String name = jfe.nextElement().getName();
+ if(name.startsWith(path) && name.endsWith(".class")) {
+ classNames.add(name.substring(0,name.length()-6).replace('/', '.'));
+ }
+ }
+ } finally {
+ jf.close();
+ }
+ } else {
+ File dir = new File(url.getFile());
+ for( String f : dir.list()) {
+ if(f.endsWith(".class")) {
+ classNames.add(pkg.getName()+'.'+f.substring(0,f.length()-6));
+ }
+ }
+ }
+ for(String cls : classNames) {
+ try {
+ Class<?> c = cl.loadClass(cls);
+ if(c!=null) {
+ if(!Modifier.isAbstract(c.getModifiers())) {
+ Constructor<?> cst = c.getConstructor(Access.class);
+ NotifyBody nb = (NotifyBody)cst.newInstance(access);
+ if(nb!=null) {
+ bodyMap.put("info|"+nb.name, nb);
+ bodyMap.put(nb.type+'|'+nb.name, nb);
+ }
+ }
+ }
+ } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ protected void print(StringBuilder sb, int indent, Object ... objs) {
+ for(int i=0;i<indent;++i) {
+ sb.append(' ');
+ }
+ for(Object o : objs) {
+ sb.append(o.toString());
+ }
+ }
+
+ protected void println(StringBuilder sb, int indent, Object ... objs) {
+ print(sb,indent,objs);
+ sb.append('\n');
+ }
+
+ protected void printf(StringBuilder sb, int indent, String fmt, Object ... objs) {
+ print(sb,indent,String.format(fmt, objs));
+ }
+
+ protected String printCell(StringBuilder sb, int indent, String current, String prev) {
+ if(current.equals(prev)) {
+ println(sb,indent,DUPL);
+ } else {
+ printCell(sb,indent,current);
+ }
+ return current; // use to set prev...
+ }
+
+ protected void printCell(StringBuilder sb, int indent, String current) {
+ println(sb,indent,"<td>",current,"</td>");
+ }
+
+ public synchronized void inc() {
+ ++count;
+ }
+
+ public int count() {
+ return count;
+ }