@Test public void testPRTParserBasics() throws Exception { try (InputStream input = getResourceAsStream("/test-documents/testCADKEY.prt")) { Metadata metadata = new Metadata(); ContentHandler handler = new BodyContentHandler(); new PRTParser().parse(input, handler, metadata); assertEquals("application/x-prt", metadata.get(Metadata.CONTENT_TYPE)); assertEquals("2011-06-20T16:54:00", metadata.get(TikaCoreProperties.CREATED)); assertEquals(null, metadata.get(TikaCoreProperties.DESCRIPTION)); String contents = handler.toString(); assertContains("Front View", contents); assertContains("Back View", contents); assertContains("Bottom View", contents); assertContains("Right View", contents); assertContains("Left View", contents); assertContains("Axonometric View", contents); assertContains("You've managed to extract all the text!", contents); assertContains("This is more text", contents); assertContains("Text Inside a PRT file", contents); } }
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); Last5 l5 = new Last5(); int read; byte[] header = new byte[30]; IOUtils.readFully(stream, header); byte[] date = new byte[12]; IOUtils.readFully(stream, date); String dateStr = new String(date, US_ASCII); if(dateStr.startsWith("19") || dateStr.startsWith("20")) { String formattedDate = dateStr.substring(0, 4) + "-" + dateStr.substring(4,6) + "-" + dateStr.substring(6,8) + "T" + dateStr.substring(8,10) + ":" + dateStr.substring(10, 12) + ":00"; metadata.set(TikaCoreProperties.CREATED, formattedDate); metadata.set(TikaCoreProperties.CREATED, formattedDate); } metadata.set(Metadata.CONTENT_TYPE, PRT_MIME_TYPE); byte[] desc = new byte[500]; IOUtils.readFully(stream, desc); String description = extractText(desc, true); if(description.length() > 0) { metadata.set(TikaCoreProperties.DESCRIPTION, description); } while( (read = stream.read()) > -1) { if(read == 0xe0 || read == 0xe3 || read == 0xf0) { int nread = stream.read(); if(nread == 0x3f || nread == 0xbf) { if(read == 0xe3 && nread == 0x3f) { if(l5.is33()) { handleNoteText(stream, xhtml); } } else if(l5.is00()) { handleViewName(read, nread, stream, xhtml, l5); } } } else { l5.record(read); } } }
PRTParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); Last5 l5 = new Last5(); int read; byte[] header = new byte[30]; IOUtils.readFully(stream, header); byte[] date = new byte[12]; IOUtils.readFully(stream, date); String dateStr = new String(date, US_ASCII); if(dateStr.startsWith("19") || dateStr.startsWith("20")) { String formattedDate = dateStr.substring(0, 4) + "-" + dateStr.substring(4,6) + "-" + dateStr.substring(6,8) + "T" + dateStr.substring(8,10) + ":" + dateStr.substring(10, 12) + ":00"; metadata.set(TikaCoreProperties.CREATED, formattedDate); metadata.set(TikaCoreProperties.CREATED, formattedDate); } metadata.set(Metadata.CONTENT_TYPE, PRT_MIME_TYPE); byte[] desc = new byte[500]; IOUtils.readFully(stream, desc); String description = extractText(desc, true); if(description.length() > 0) { metadata.set(TikaCoreProperties.DESCRIPTION, description); } while( (read = stream.read()) > -1) { if(read == 0xe0 || read == 0xe3 || read == 0xf0) { int nread = stream.read(); if(nread == 0x3f || nread == 0xbf) { if(read == 0xe3 && nread == 0x3f) { if(l5.is33()) { handleNoteText(stream, xhtml); } } else if(l5.is00()) { handleViewName(read, nread, stream, xhtml, l5); } } } else { l5.record(read); } } } }
PRTParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); Last5 l5 = new Last5(); int read; byte[] header = new byte[30]; IOUtils.readFully(stream, header); byte[] date = new byte[12]; IOUtils.readFully(stream, date); String dateStr = new String(date, US_ASCII); if(dateStr.startsWith("19") || dateStr.startsWith("20")) { String formattedDate = dateStr.substring(0, 4) + "-" + dateStr.substring(4,6) + "-" + dateStr.substring(6,8) + "T" + dateStr.substring(8,10) + ":" + dateStr.substring(10, 12) + ":00"; metadata.set(TikaCoreProperties.CREATED, formattedDate); metadata.set(TikaCoreProperties.CREATED, formattedDate); } metadata.set(Metadata.CONTENT_TYPE, PRT_MIME_TYPE); byte[] desc = new byte[500]; IOUtils.readFully(stream, desc); String description = extractText(desc, true); if(description.length() > 0) { metadata.set(TikaCoreProperties.DESCRIPTION, description); } while( (read = stream.read()) > -1) { if(read == 0xe0 || read == 0xe3 || read == 0xf0) { int nread = stream.read(); if(nread == 0x3f || nread == 0xbf) { if(read == 0xe3 && nread == 0x3f) { if(l5.is33()) { handleNoteText(stream, xhtml); } } else if(l5.is00()) { handleViewName(read, nread, stream, xhtml, l5); } } } else { l5.record(read); } } }  }
PRTParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); Last5 l5 = new Last5(); int read; byte[] header = new byte[30]; IOUtils.readFully(stream, header); byte[] date = new byte[12]; IOUtils.readFully(stream, date); String dateStr = new String(date, US_ASCII); if(dateStr.startsWith("19") || dateStr.startsWith("20")) { String formattedDate = dateStr.substring(0, 4) + "-" + dateStr.substring(4,6) + "-" + dateStr.substring(6,8) + "T" + dateStr.substring(8,10) + ":" + dateStr.substring(10, 12) + ":00"; metadata.set(TikaCoreProperties.CREATED, formattedDate); metadata.set(TikaCoreProperties.CREATED, formattedDate); } metadata.set(Metadata.CONTENT_TYPE, PRT_MIME_TYPE); byte[] desc = new byte[500]; IOUtils.readFully(stream, desc); String description = extractText(desc, true); if(description.length() > 0) { metadata.set(TikaCoreProperties.DESCRIPTION, description); } while( (read = stream.read()) > -1) { if(read == 0xe0 || read == 0xe3 || read == 0xf0) { int nread = stream.read(); if(nread == 0x3f || nread == 0xbf) { if(read == 0xe3 && nread == 0x3f) { if(l5.is33()) { handleNoteText(stream, xhtml); } } else if(l5.is00()) { handleViewName(read, nread, stream, xhtml, l5); } } } else { l5.record(read); } } }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(InputStream stream, ContentHandler handler, Metadata metadata, 
          ParseContext context); }
PRTParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); Last5 l5 = new Last5(); int read; byte[] header = new byte[30]; IOUtils.readFully(stream, header); byte[] date = new byte[12]; IOUtils.readFully(stream, date); String dateStr = new String(date, US_ASCII); if(dateStr.startsWith("19") || dateStr.startsWith("20")) { String formattedDate = dateStr.substring(0, 4) + "-" + dateStr.substring(4,6) + "-" + dateStr.substring(6,8) + "T" + dateStr.substring(8,10) + ":" + dateStr.substring(10, 12) + ":00"; metadata.set(TikaCoreProperties.CREATED, formattedDate); metadata.set(TikaCoreProperties.CREATED, formattedDate); } metadata.set(Metadata.CONTENT_TYPE, PRT_MIME_TYPE); byte[] desc = new byte[500]; IOUtils.readFully(stream, desc); String description = extractText(desc, true); if(description.length() > 0) { metadata.set(TikaCoreProperties.DESCRIPTION, description); } while( (read = stream.read()) > -1) { if(read == 0xe0 || read == 0xe3 || read == 0xf0) { int nread = stream.read(); if(nread == 0x3f || nread == 0xbf) { if(read == 0xe3 && nread == 0x3f) { if(l5.is33()) { handleNoteText(stream, xhtml); } } else if(l5.is00()) { handleViewName(read, nread, stream, xhtml, l5); } } } else { l5.record(read); } } }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(InputStream stream, ContentHandler handler, Metadata metadata, 
          ParseContext context); static final String PRT_MIME_TYPE; }