@Test public void testMetaXmlMissing() throws Exception { FileParser parser = new OpenOfficeWriterParser(); File file = TestFiles.missing_meta_xml_entry.get(); parser.parse(file, new ParseContext(file.getName())); }
@Override protected final ParseResult parse( @NotNull File file, @NotNull ParseContext context) throws ParseException { OpenDocumentParser tikaParser = new OpenDocumentParser(); BodyContentHandler contentHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); TikaInputStream in = null; try { in = TikaInputStream.get(Paths.get(file.getPath())); tikaParser.parse(in, contentHandler, metadata, ParseService.tikaContext()); ParseResult result = new ParseResult(contentHandler.toString()) .setTitle(metadata.get(TikaCoreProperties.TITLE)) .addAuthor(metadata.get(TikaCoreProperties.CREATOR)) .addMiscMetadata(metadata.get(TikaCoreProperties.DESCRIPTION)) .addMiscMetadata(metadata.get(TikaCoreProperties.TRANSITION_SUBJECT_TO_OO_SUBJECT)) .addMiscMetadata(metadata.get(TikaCoreProperties.KEYWORDS)); for (String name : metadata.names()) { if (name.startsWith("custom:")) { result.addMiscMetadata(metadata.get(name)); } } return result; } catch (CharConversionException e) { if (matchesPasswordError(e)) { throw new ParseException(Msg.doc_pw_protected.get()); } else { throw new ParseException(e); } } catch (IOException | SAXException | TikaException e) { throw new ParseException(e); } catch (RuntimeException e) { throw new ParseException(e); } finally { Closeables.closeQuietly(in); } }
OpenOfficeParser extends FileParser { @Override protected final ParseResult parse( @NotNull File file, @NotNull ParseContext context) throws ParseException { OpenDocumentParser tikaParser = new OpenDocumentParser(); BodyContentHandler contentHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); TikaInputStream in = null; try { in = TikaInputStream.get(Paths.get(file.getPath())); tikaParser.parse(in, contentHandler, metadata, ParseService.tikaContext()); ParseResult result = new ParseResult(contentHandler.toString()) .setTitle(metadata.get(TikaCoreProperties.TITLE)) .addAuthor(metadata.get(TikaCoreProperties.CREATOR)) .addMiscMetadata(metadata.get(TikaCoreProperties.DESCRIPTION)) .addMiscMetadata(metadata.get(TikaCoreProperties.TRANSITION_SUBJECT_TO_OO_SUBJECT)) .addMiscMetadata(metadata.get(TikaCoreProperties.KEYWORDS)); for (String name : metadata.names()) { if (name.startsWith("custom:")) { result.addMiscMetadata(metadata.get(name)); } } return result; } catch (CharConversionException e) { if (matchesPasswordError(e)) { throw new ParseException(Msg.doc_pw_protected.get()); } else { throw new ParseException(e); } } catch (IOException | SAXException | TikaException e) { throw new ParseException(e); } catch (RuntimeException e) { throw new ParseException(e); } finally { Closeables.closeQuietly(in); } } }
OpenOfficeParser extends FileParser { @Override protected final ParseResult parse( @NotNull File file, @NotNull ParseContext context) throws ParseException { OpenDocumentParser tikaParser = new OpenDocumentParser(); BodyContentHandler contentHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); TikaInputStream in = null; try { in = TikaInputStream.get(Paths.get(file.getPath())); tikaParser.parse(in, contentHandler, metadata, ParseService.tikaContext()); ParseResult result = new ParseResult(contentHandler.toString()) .setTitle(metadata.get(TikaCoreProperties.TITLE)) .addAuthor(metadata.get(TikaCoreProperties.CREATOR)) .addMiscMetadata(metadata.get(TikaCoreProperties.DESCRIPTION)) .addMiscMetadata(metadata.get(TikaCoreProperties.TRANSITION_SUBJECT_TO_OO_SUBJECT)) .addMiscMetadata(metadata.get(TikaCoreProperties.KEYWORDS)); for (String name : metadata.names()) { if (name.startsWith("custom:")) { result.addMiscMetadata(metadata.get(name)); } } return result; } catch (CharConversionException e) { if (matchesPasswordError(e)) { throw new ParseException(Msg.doc_pw_protected.get()); } else { throw new ParseException(e); } } catch (IOException | SAXException | TikaException e) { throw new ParseException(e); } catch (RuntimeException e) { throw new ParseException(e); } finally { Closeables.closeQuietly(in); } } private  OpenOfficeParser(@NotNull String typeLabel, @NotNull String... extensions); }
OpenOfficeParser extends FileParser { @Override protected final ParseResult parse( @NotNull File file, @NotNull ParseContext context) throws ParseException { OpenDocumentParser tikaParser = new OpenDocumentParser(); BodyContentHandler contentHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); TikaInputStream in = null; try { in = TikaInputStream.get(Paths.get(file.getPath())); tikaParser.parse(in, contentHandler, metadata, ParseService.tikaContext()); ParseResult result = new ParseResult(contentHandler.toString()) .setTitle(metadata.get(TikaCoreProperties.TITLE)) .addAuthor(metadata.get(TikaCoreProperties.CREATOR)) .addMiscMetadata(metadata.get(TikaCoreProperties.DESCRIPTION)) .addMiscMetadata(metadata.get(TikaCoreProperties.TRANSITION_SUBJECT_TO_OO_SUBJECT)) .addMiscMetadata(metadata.get(TikaCoreProperties.KEYWORDS)); for (String name : metadata.names()) { if (name.startsWith("custom:")) { result.addMiscMetadata(metadata.get(name)); } } return result; } catch (CharConversionException e) { if (matchesPasswordError(e)) { throw new ParseException(Msg.doc_pw_protected.get()); } else { throw new ParseException(e); } } catch (IOException | SAXException | TikaException e) { throw new ParseException(e); } catch (RuntimeException e) { throw new ParseException(e); } finally { Closeables.closeQuietly(in); } } private  OpenOfficeParser(@NotNull String typeLabel, @NotNull String... extensions); final String getTypeLabel(); }
OpenOfficeParser extends FileParser { @Override protected final ParseResult parse( @NotNull File file, @NotNull ParseContext context) throws ParseException { OpenDocumentParser tikaParser = new OpenDocumentParser(); BodyContentHandler contentHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); TikaInputStream in = null; try { in = TikaInputStream.get(Paths.get(file.getPath())); tikaParser.parse(in, contentHandler, metadata, ParseService.tikaContext()); ParseResult result = new ParseResult(contentHandler.toString()) .setTitle(metadata.get(TikaCoreProperties.TITLE)) .addAuthor(metadata.get(TikaCoreProperties.CREATOR)) .addMiscMetadata(metadata.get(TikaCoreProperties.DESCRIPTION)) .addMiscMetadata(metadata.get(TikaCoreProperties.TRANSITION_SUBJECT_TO_OO_SUBJECT)) .addMiscMetadata(metadata.get(TikaCoreProperties.KEYWORDS)); for (String name : metadata.names()) { if (name.startsWith("custom:")) { result.addMiscMetadata(metadata.get(name)); } } return result; } catch (CharConversionException e) { if (matchesPasswordError(e)) { throw new ParseException(Msg.doc_pw_protected.get()); } else { throw new ParseException(e); } } catch (IOException | SAXException | TikaException e) { throw new ParseException(e); } catch (RuntimeException e) { throw new ParseException(e); } finally { Closeables.closeQuietly(in); } } private  OpenOfficeParser(@NotNull String typeLabel, @NotNull String... extensions); final String getTypeLabel();  }