/** * Process the header of the file. * * @param context the parser context */ private void processDefaultHeader(ParserContext context) { for (String line : context.getFileLines()) { if (hasHeaderSeparator(line)) { break; } processHeaderLine(line, context.getDocumentModel()); } }
public static ParserEngine get(String fileExtension) { return INSTANCE.getEngine(fileExtension); }
@Override public void processBody(ParserContext context) { StringBuilder body = new StringBuilder(context.getBody().length()); if (!context.hasHeader()) { for (String line : context.getFileLines()) { body.append(line).append("\n"); } context.setBody(body.toString()); } processAsciiDoc(context); }
private void processAsciiDoc(ParserContext context) { Options options = getAsciiDocOptionsAndAttributes(context); final Asciidoctor asciidoctor = getEngine(options); context.setBody(asciidoctor.render(context.getBody(), options)); }
private void sanitizeTags(ParserContext context) { if (context.getTags() != null) { String[] tags = (String[]) context.getTags(); for (int i = 0; i < tags.length; i++) { tags[i] = sanitizeValue(tags[i]); if (context.getConfig().getSanitizeTag()) { tags[i] = tags[i].replace(" ", "-"); } } context.setTags(tags); } }
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 void setTags(String[] tags) { getDocumentModel().put(Crawler.Attributes.TAGS, tags); } }
/** * 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 void setDefaultStatus() { getDocumentModel().put(Crawler.Attributes.STATUS, getConfig().getDefaultStatus()); }
public static void register(String fileExtension, ParserEngine engine) { INSTANCE.registerEngine(fileExtension, engine); }
private String[] getTags(String tagsPart) { String[] tags = tagsPart.split(","); for (int i = 0; i < tags.length; i++) tags[i] = sanitizeValue(tags[i]); return tags; }
/** * 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 void processHeaderLine(String line, Map<String, Object> content) { String[] parts = line.split("=", 2); if (!line.isEmpty() && parts.length == 2) { storeHeaderValue(parts[0], parts[1], content); } }
@Override public Map<String, Object> parse(Configuration config, File file, String contentPath) { return parse(new DefaultJBakeConfiguration((CompositeConfiguration) config), file); }
public Object getTags() { return getDocumentModel().get(Crawler.Attributes.TAGS); }
public Object getDate() { return getDocumentModel().get(Crawler.Attributes.DATE); }
public void setDate(Date date) { getDocumentModel().put(Crawler.Attributes.DATE, date); }
public String getStatus() { if (getDocumentModel().containsKey(Crawler.Attributes.STATUS)) { return getDocumentModel().get(Crawler.Attributes.STATUS).toString(); } return ""; }
public String getType() { if (getDocumentModel().containsKey(Crawler.Attributes.TYPE)) { return getDocumentModel().get(Crawler.Attributes.TYPE).toString(); } return ""; }