@Test public void testRtfWithImage() throws Exception { File file = TestFiles.rtf_with_image.get(); RtfParser parser = new RtfParser(); ParseContext context = new ParseContext(file.getName()); FileInputStream in = new FileInputStream(file); parser.parse(in, context); in.close(); }
protected ParseResult parse(InputStream in, ParseContext context) throws ParseException { BodyContentHandler bodyHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); try { org.apache.tika.parser.ParseContext tikaContext = ParseService.tikaContext(); TikaConfig tikaConfig = new TikaConfig(new ClassLoader() { protected URL findResource(String name) { if ("tika-mimetypes.xml".equals(name)) { return getResource("org/apache/tika/tika-mimetypes.xml"); } return null; } }); tikaContext.set(TikaConfig.class, tikaConfig); new RTFParser().parse(in, bodyHandler, metadata, tikaContext); return new ParseResult(bodyHandler.toString()) .addAuthor(metadata.get(TikaCoreProperties.CREATOR)) .setTitle(metadata.get(TikaCoreProperties.TITLE)) .addMiscMetadata(metadata.get(Metadata.SUBJECT)) .addMiscMetadata(metadata.get(TikaCoreProperties.KEYWORDS)); } catch (AssertionError e) { throw new ParseException(e); } catch (Exception e) { throw new ParseException(e); } }
RtfParser extends StreamParser { protected ParseResult parse(InputStream in, ParseContext context) throws ParseException { BodyContentHandler bodyHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); try { org.apache.tika.parser.ParseContext tikaContext = ParseService.tikaContext(); TikaConfig tikaConfig = new TikaConfig(new ClassLoader() { protected URL findResource(String name) { if ("tika-mimetypes.xml".equals(name)) { return getResource("org/apache/tika/tika-mimetypes.xml"); } return null; } }); tikaContext.set(TikaConfig.class, tikaConfig); new RTFParser().parse(in, bodyHandler, metadata, tikaContext); return new ParseResult(bodyHandler.toString()) .addAuthor(metadata.get(TikaCoreProperties.CREATOR)) .setTitle(metadata.get(TikaCoreProperties.TITLE)) .addMiscMetadata(metadata.get(Metadata.SUBJECT)) .addMiscMetadata(metadata.get(TikaCoreProperties.KEYWORDS)); } catch (AssertionError e) { throw new ParseException(e); } catch (Exception e) { throw new ParseException(e); } } }
RtfParser extends StreamParser { protected ParseResult parse(InputStream in, ParseContext context) throws ParseException { BodyContentHandler bodyHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); try { org.apache.tika.parser.ParseContext tikaContext = ParseService.tikaContext(); TikaConfig tikaConfig = new TikaConfig(new ClassLoader() { protected URL findResource(String name) { if ("tika-mimetypes.xml".equals(name)) { return getResource("org/apache/tika/tika-mimetypes.xml"); } return null; } }); tikaContext.set(TikaConfig.class, tikaConfig); new RTFParser().parse(in, bodyHandler, metadata, tikaContext); return new ParseResult(bodyHandler.toString()) .addAuthor(metadata.get(TikaCoreProperties.CREATOR)) .setTitle(metadata.get(TikaCoreProperties.TITLE)) .addMiscMetadata(metadata.get(Metadata.SUBJECT)) .addMiscMetadata(metadata.get(TikaCoreProperties.KEYWORDS)); } catch (AssertionError e) { throw new ParseException(e); } catch (Exception e) { throw new ParseException(e); } }  }
RtfParser extends StreamParser { protected ParseResult parse(InputStream in, ParseContext context) throws ParseException { BodyContentHandler bodyHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); try { org.apache.tika.parser.ParseContext tikaContext = ParseService.tikaContext(); TikaConfig tikaConfig = new TikaConfig(new ClassLoader() { protected URL findResource(String name) { if ("tika-mimetypes.xml".equals(name)) { return getResource("org/apache/tika/tika-mimetypes.xml"); } return null; } }); tikaContext.set(TikaConfig.class, tikaConfig); new RTFParser().parse(in, bodyHandler, metadata, tikaContext); return new ParseResult(bodyHandler.toString()) .addAuthor(metadata.get(TikaCoreProperties.CREATOR)) .setTitle(metadata.get(TikaCoreProperties.TITLE)) .addMiscMetadata(metadata.get(Metadata.SUBJECT)) .addMiscMetadata(metadata.get(TikaCoreProperties.KEYWORDS)); } catch (AssertionError e) { throw new ParseException(e); } catch (Exception e) { throw new ParseException(e); } }  String getTypeLabel(); }
RtfParser extends StreamParser { protected ParseResult parse(InputStream in, ParseContext context) throws ParseException { BodyContentHandler bodyHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); try { org.apache.tika.parser.ParseContext tikaContext = ParseService.tikaContext(); TikaConfig tikaConfig = new TikaConfig(new ClassLoader() { protected URL findResource(String name) { if ("tika-mimetypes.xml".equals(name)) { return getResource("org/apache/tika/tika-mimetypes.xml"); } return null; } }); tikaContext.set(TikaConfig.class, tikaConfig); new RTFParser().parse(in, bodyHandler, metadata, tikaContext); return new ParseResult(bodyHandler.toString()) .addAuthor(metadata.get(TikaCoreProperties.CREATOR)) .setTitle(metadata.get(TikaCoreProperties.TITLE)) .addMiscMetadata(metadata.get(Metadata.SUBJECT)) .addMiscMetadata(metadata.get(TikaCoreProperties.KEYWORDS)); } catch (AssertionError e) { throw new ParseException(e); } catch (Exception e) { throw new ParseException(e); } }  String getTypeLabel();  }