/** * Process the file by parsing the contents. * * @param file File input for parsing * @return The contents of the file */ public Map<String, Object> processFile(File file) { ParserEngine engine = Engines.get(FileUtil.fileExt(file)); if (engine==null) { LOGGER.error("Unable to find suitable markup engine for {}",file); return null; } return engine.parse(config, file); } }
public static ParserEngine get(String fileExtension) { return INSTANCE.getEngine(fileExtension); }
/** * Notice additional document types are added automagically before returning them * @return all supported document types */ public static String[] getDocumentTypes() { // TODO: is this needed? // make sure engines are loaded before to get document types Engines.getRecognizedExtensions(); return DEFAULT_DOC_TYPES.toArray(new String[DEFAULT_DOC_TYPES.size()]); }
private static void registerEngine(String className, String... extensions) { ParserEngine engine = tryLoadEngine(className); if (engine != null) { for (String extension : extensions) { register(extension, engine); } if (engine instanceof ErrorEngine) { LOGGER.warn("Unable to load a suitable rendering engine for extensions {}", (Object) extensions); } } } }
public static void register(String fileExtension, ParserEngine engine) { INSTANCE.registerEngine(fileExtension, engine); }
private static void registerEngine(String className, String... extensions) { ParserEngine engine = tryLoadEngine(className); if (engine != null) { for (String extension : extensions) { register(extension, engine); } if (engine instanceof ErrorEngine) { LOGGER.warn("Unable to load a suitable rendering engine for extensions {}", (Object) extensions); } } } }
/** * This method is used internally to load markup engines. Markup engines are found using descriptor files on classpath, so * adding an engine is as easy as adding a jar on classpath with the descriptor file included. */ private static void loadEngines() { try { ClassLoader cl = Engines.class.getClassLoader(); Enumeration<URL> resources = cl.getResources("META-INF/org.jbake.parser.MarkupEngines.properties"); while (resources.hasMoreElements()) { URL url = resources.nextElement(); Properties props = new Properties(); props.load(url.openStream()); for (Map.Entry<Object, Object> entry : props.entrySet()) { String className = (String) entry.getKey(); String[] extensions = ((String)entry.getValue()).split(","); registerEngine(className, extensions); } } } catch (IOException e) { LOGGER.error("Error loading Engines", e); } }
@Override public boolean accept(File pathname) { //Accept if input is a non-hidden file with registered extension //or if a non-hidden and not-ignored directory return !pathname.isHidden() && (pathname.isFile() && Engines.getRecognizedExtensions().contains(fileExt(pathname))) || (directoryOnlyIfNotIgnored(pathname)); } };
public static void register(String fileExtension, ParserEngine engine) { INSTANCE.registerEngine(fileExtension, engine); }
/** * Process the file by parsing the contents. * * @param file File input for parsing * @return The contents of the file */ public Map<String, Object> processFile(File file) { ParserEngine engine = Engines.get(FileUtil.fileExt(file)); if (engine==null) { LOGGER.error("Unable to find suitable markup engine for {}",file); return null; } return engine.parse(config, file); } }
public static ParserEngine get(String fileExtension) { return INSTANCE.getEngine(fileExtension); }
@Override public boolean accept(File pathname) { //Accept if input is a non-hidden file with NOT-registered extension //or if a non-hidden and not-ignored directory return !pathname.isHidden() && (pathname.isFile() //extension should not be from registered content extensions && !Engines.getRecognizedExtensions().contains(fileExt(pathname))) || (directoryOnlyIfNotIgnored(pathname)); } };
/** * This method is used internally to load markup engines. Markup engines are found using descriptor files on classpath, so * adding an engine is as easy as adding a jar on classpath with the descriptor file included. */ private static void loadEngines() { try { ClassLoader cl = Engines.class.getClassLoader(); Enumeration<URL> resources = cl.getResources("META-INF/org.jbake.parser.MarkupEngines.properties"); while (resources.hasMoreElements()) { URL url = resources.nextElement(); Properties props = new Properties(); props.load(url.openStream()); for (Map.Entry<Object, Object> entry : props.entrySet()) { String className = (String) entry.getKey(); String[] extensions = ((String)entry.getValue()).split(","); registerEngine(className, extensions); } } } catch (IOException e) { LOGGER.error("Error loading Engines", e); } }
/** * Notice additional document types are added automagically before returning them * @return all supported document types */ public static String[] getDocumentTypes() { // TODO: is this needed? // make sure engines are loaded before to get document types Engines.getRecognizedExtensions(); return DEFAULT_DOC_TYPES.toArray(new String[DEFAULT_DOC_TYPES.size()]); }
@Override public boolean accept(File pathname) { //Accept if input is a non-hidden file with registered extension //or if a non-hidden and not-ignored directory return !pathname.isHidden() && (pathname.isFile() && Engines.getRecognizedExtensions().contains(fileExt(pathname))) || (directoryOnlyIfNotIgnored(pathname)); } };
@Override public boolean accept(File pathname) { //Accept if input is a non-hidden file with NOT-registered extension //or if a non-hidden and not-ignored directory return !pathname.isHidden() && (pathname.isFile() //extension should not be from registered content extensions && !Engines.getRecognizedExtensions().contains(fileExt(pathname))) || (directoryOnlyIfNotIgnored(pathname)); } };