Author: tchemit Date: 2009-08-29 13:08:34 +0200 (Sat, 29 Aug 2009) New Revision: 556 Modified: trunk/src/main/java/org/nuiton/AbstractPlugin.java Log: adding usefull method to botain a template or resource from AbstractPlugin Modified: trunk/src/main/java/org/nuiton/AbstractPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/AbstractPlugin.java 2009-08-28 09:51:16 UTC (rev 555) +++ trunk/src/main/java/org/nuiton/AbstractPlugin.java 2009-08-29 11:08:34 UTC (rev 556) @@ -401,4 +401,44 @@ } return loader; } + + /** + * + * @param f le fichier de template + * @return l'url du fichier demande + * @throws IOException pour toute erreur de recherche + */ + protected URL getTemplate(File f) throws IOException { + URL r = null; + if (f.exists()) { + r = f.toURI().toURL(); + } else { + r = getClass().getResource(f.toString()); + } + return r; + } + + /** + * Vérifie que le fichier donné existe bien (sur le filesystem ou + * dans le class-path). + * + * @param f le fichier que l'on veut vérifié + * @throws IOException pour tout erreur de recherche + */ + protected void checkResource(File f) throws IOException { + if (!f.exists()) { + // test in classPath + InputStream r = null; + try { + r = getClass().getResourceAsStream(f.toString()); + if (r == null) { + throw new IOException("could not find ressource " + f); + } + } finally { + if (r != null) { + r.close(); + } + } + } + } }
participants (1)
-
tchemit@users.nuiton.org