@Test public void testParseMetadata() { assumeTrue(canRun()); final String expectedNcInst = "NCAR (National Center for Atmospheric Research, Boulder, CO, USA)"; final String expectedModelNameEnglish = "NCAR CCSM"; final String expectedProgramId = "Source file unknown Version unknown Date unknown"; final String expectedProjectId = "IPCC Fourth Assessment"; final String expectedRealization = "1"; final String expectedTitle = "model output prepared for IPCC AR4"; final String expectedSub8Name = "\":ua"; final String expectedSub8Desc = "[1x17x128x256] eastward_wind (32-bit floating-point)"; GDALParser parser = new GDALParser(); InputStream stream = TestGDALParser.class .getResourceAsStream("/test-documents/sresa1b_ncar_ccsm3_0_run1_200001.nc"); Metadata met = new Metadata(); BodyContentHandler handler = new BodyContentHandler(); try { parser.parse(stream, handler, met, new ParseContext()); assertNotNull(met); assertNotNull(met.get("NC_GLOBAL#institution")); assertEquals(expectedNcInst, met.get("NC_GLOBAL#institution")); assertNotNull(met.get("NC_GLOBAL#model_name_english")); assertEquals(expectedModelNameEnglish, met.get("NC_GLOBAL#model_name_english")); assertNotNull(met.get("NC_GLOBAL#prg_ID")); assertEquals(expectedProgramId, met.get("NC_GLOBAL#prg_ID")); assertNotNull(met.get("NC_GLOBAL#prg_ID")); assertEquals(expectedProgramId, met.get("NC_GLOBAL#prg_ID")); assertNotNull(met.get("NC_GLOBAL#project_id")); assertEquals(expectedProjectId, met.get("NC_GLOBAL#project_id")); assertNotNull(met.get("NC_GLOBAL#realization")); assertEquals(expectedRealization, met.get("NC_GLOBAL#realization")); assertNotNull(met.get("NC_GLOBAL#title")); assertEquals(expectedTitle, met.get("NC_GLOBAL#title")); assertNotNull(met.get("SUBDATASET_8_NAME")); assertTrue(met.get("SUBDATASET_8_NAME").endsWith(expectedSub8Name)); assertNotNull(met.get("SUBDATASET_8_DESC")); assertEquals(expectedSub8Desc, met.get("SUBDATASET_8_DESC")); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (!ExternalParser.check("gdalinfo")) { return; } TemporaryResources tmp = new TemporaryResources(); TikaInputStream tis = TikaInputStream.get(stream, tmp); String runCommand = processCommand(tis); String output = execCommand(new String[]{runCommand}); extractMetFromOutput(output, metadata); applyPatternsToOutput(output, metadata, getPatterns()); processOutput(handler, metadata, output); }
GDALParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (!ExternalParser.check("gdalinfo")) { return; } TemporaryResources tmp = new TemporaryResources(); TikaInputStream tis = TikaInputStream.get(stream, tmp); String runCommand = processCommand(tis); String output = execCommand(new String[]{runCommand}); extractMetFromOutput(output, metadata); applyPatternsToOutput(output, metadata, getPatterns()); processOutput(handler, metadata, output); } }
GDALParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (!ExternalParser.check("gdalinfo")) { return; } TemporaryResources tmp = new TemporaryResources(); TikaInputStream tis = TikaInputStream.get(stream, tmp); String runCommand = processCommand(tis); String output = execCommand(new String[]{runCommand}); extractMetFromOutput(output, metadata); applyPatternsToOutput(output, metadata, getPatterns()); processOutput(handler, metadata, output); } GDALParser(); }
GDALParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (!ExternalParser.check("gdalinfo")) { return; } TemporaryResources tmp = new TemporaryResources(); TikaInputStream tis = TikaInputStream.get(stream, tmp); String runCommand = processCommand(tis); String output = execCommand(new String[]{runCommand}); extractMetFromOutput(output, metadata); applyPatternsToOutput(output, metadata, getPatterns()); processOutput(handler, metadata, output); } GDALParser(); void setCommand(String command); String getCommand(); String processCommand(InputStream stream); @Override Set<MediaType> getSupportedTypes(ParseContext context); @Override void parse(InputStream stream, ContentHandler handler,
                      Metadata metadata, ParseContext context); }
GDALParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (!ExternalParser.check("gdalinfo")) { return; } TemporaryResources tmp = new TemporaryResources(); TikaInputStream tis = TikaInputStream.get(stream, tmp); String runCommand = processCommand(tis); String output = execCommand(new String[]{runCommand}); extractMetFromOutput(output, metadata); applyPatternsToOutput(output, metadata, getPatterns()); processOutput(handler, metadata, output); } GDALParser(); void setCommand(String command); String getCommand(); String processCommand(InputStream stream); @Override Set<MediaType> getSupportedTypes(ParseContext context); @Override void parse(InputStream stream, ContentHandler handler,
                      Metadata metadata, ParseContext context);  }