Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.apache.tika.parser.ParseContext;
import org.apache.tika.sax.EmbeddedContentHandler;
import org.apache.tika.sax.XHTMLContentHandler;
import org.apache.tika.utils.ExceptionUtils;
import org.apache.tika.utils.FileProcessResult;
import org.apache.tika.utils.ProcessUtils;

Expand Down Expand Up @@ -189,9 +188,9 @@ public void parse(TikaInputStream tis, ContentHandler handler, Metadata metadata
try {
jParser = jfactory.createParser(tmpFileOut);
} catch (JsonParseException e1) {
throw new TikaException("Failed to parse Json: " + ExceptionUtils.getStackTrace(e1));
throw new TikaException("Failed to parse Json", e1);
} catch (IOException e1) {
throw new TikaException("Failed to read json file: " + ExceptionUtils.getStackTrace(e1));
throw new TikaException("Failed to read json file", e1);
}
// read json token in a stream using jackson, iterate over each token. We only
// support OBJECTS, FILEHEADER and SummaryInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
import org.apache.tika.sax.XHTMLContentHandler;
import org.apache.tika.utils.ExceptionUtils;

/**
* Tika parser for Time Stamped Data Envelope (application/timestamped-data)
Expand Down Expand Up @@ -189,8 +190,7 @@ private void parseTSDContent(InputStream stream, ContentHandler handler, Metadat
}
} catch (IOException e) {
// Truncated file - record exception and work with what we got
metadata.set(TikaCoreProperties.EMBEDDED_EXCEPTION,
e.getClass().getName() + ": " + e.getMessage());
metadata.set(TikaCoreProperties.EMBEDDED_EXCEPTION, ExceptionUtils.format(e, context));
LOG.debug("Error reading TSD content (possibly truncated)", e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private void handleSrcDoc(String string) throws SAXException {
try (TikaInputStream tis = TikaInputStream.get(string.getBytes(StandardCharsets.UTF_8))) {
embeddedDocumentExtractor.parseEmbedded(tis, xhtml, m, context, true);
} catch (IOException e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, metadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, metadata, context);
}
}
}
Expand All @@ -376,7 +376,7 @@ private void handleDataURIScheme(String string) throws SAXException {
try (TikaInputStream tis = TikaInputStream.get(dataURIScheme.getInputStream())) {
embeddedDocumentExtractor.parseEmbedded(tis, xhtml, m, context, true);
} catch (IOException e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, metadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, metadata, context);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static boolean extract(File file, Metadata metadata, ParseContext context) {
} catch (SecurityException e) {
throw e;
} catch (IOException | SAXException | TikaException | RuntimeException e) {
EmbeddedDocumentUtil.recordException(e, metadata); // bad XMP must not fail the parse
EmbeddedDocumentUtil.recordException(e, metadata, context); // bad XMP must not fail the parse
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static boolean scanAndExtract(InputStream stream, Metadata metadata, ParseContex
} catch (SecurityException e) {
throw e;
} catch (IOException | SAXException | TikaException | RuntimeException e) {
EmbeddedDocumentUtil.recordException(e, metadata);
EmbeddedDocumentUtil.recordException(e, metadata, context);
}
return false;
}
Expand All @@ -76,7 +76,7 @@ static void extractRaw(byte[] xmp, Metadata metadata, ParseContext context) {
} catch (SecurityException e) {
throw e;
} catch (IOException | SAXException | TikaException | RuntimeException e) {
EmbeddedDocumentUtil.recordException(e, metadata);
EmbeddedDocumentUtil.recordException(e, metadata, context);
}
}

Expand All @@ -100,7 +100,7 @@ static void extractJpeg(InputStream stream, Metadata metadata, ParseContext cont
} catch (SecurityException e) {
throw e;
} catch (IOException | SAXException | TikaException | RuntimeException e) {
EmbeddedDocumentUtil.recordException(e, metadata);
EmbeddedDocumentUtil.recordException(e, metadata, context);
}
}

Expand All @@ -114,7 +114,7 @@ static void extractWebp(InputStream stream, Metadata metadata, ParseContext cont
} catch (SecurityException e) {
throw e;
} catch (IOException | SAXException | TikaException | RuntimeException e) {
EmbeddedDocumentUtil.recordException(e, metadata);
EmbeddedDocumentUtil.recordException(e, metadata, context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void extractPreviews(TikaInputStream tis, XHTMLContentHandler xhtml, Met
} catch (TiffStructureException | IOException e) {
//a file we cannot walk for previews should not fail the parse;
//the TIFF metadata has already been extracted at this point
EmbeddedDocumentUtil.recordException(e, metadata);
EmbeddedDocumentUtil.recordException(e, metadata, context);
return;
}
if (previews.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected void handleEmbeddedOfficeDoc(DirectoryEntry dir, Metadata metadata,
throw e;
} catch (Exception e) {
//if there's a stream error while detecting, give up
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, context);
return;
}
handleEmbeddedResource(tis, metadata,null, dir.getName(), dir.getStorageClsid(),
Expand Down Expand Up @@ -295,7 +295,7 @@ private void handleCompObj(DirectoryEntry parentDir, POIFSDocumentType type, Str
try {
contentsEntry = (DocumentEntry) parentDir.getEntry(contentsEntryName);
} catch (FileNotFoundException fnfe) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(fnfe, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(fnfe, parentMetadata, context);
return;
}

Expand All @@ -306,7 +306,7 @@ private void handleCompObj(DirectoryEntry parentDir, POIFSDocumentType type, Str
} catch (SecurityException e) {
throw e;
} catch (Exception e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, context);
return;
}
try (TikaInputStream tis = TikaInputStream.get(inp)) {
Expand Down Expand Up @@ -378,7 +378,7 @@ private void handleOLENative(DirectoryEntry dir, POIFSDocumentType type, String
} catch (SecurityException e) {
throw e;
} catch (Exception e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, context);
return;
}
if (data == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private void handleShowEmbeddedResources(HSLFSlideShow ss, XHTMLContentHandler x
}
}
} catch (IOException | TikaException e) {
EmbeddedDocumentUtil.recordException(e, parentMetadata);
EmbeddedDocumentUtil.recordException(e, parentMetadata, context);
}
i++;
}
Expand Down Expand Up @@ -428,10 +428,10 @@ private void extractMacros(HSLFSlideShow ppt, XHTMLContentHandler xhtml) {
OfficeParser.extractMacros(poifsFileSystem, xhtml,
EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context), context);
} catch (IOException | SAXException | TikaException inner) {
EmbeddedDocumentUtil.recordException(inner, parentMetadata);
EmbeddedDocumentUtil.recordException(inner, parentMetadata, context);
}
} catch (IOException e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);//swallow
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, context);//swallow
}
}
}
Expand Down Expand Up @@ -586,7 +586,7 @@ private void handleSlideEmbeddedPictures(HSLFSlideShow slideshow, XHTMLContentHa
} catch (SecurityException e) {
throw e;
} catch (Exception e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, context);
continue;
}
try (TikaInputStream picIs = TikaInputStream.get(data)) {
Expand Down Expand Up @@ -619,7 +619,7 @@ private void collectPictureSlides(ShapeContainer container, int slideNum,
pd = ((HSLFPictureShape) shape).getPictureData();
} catch (IndexOutOfBoundsException e) {
// corrupt Escher BSE record -- skip page anchoring for this shape
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, context);
continue;
}
if (pd != null) {
Expand Down Expand Up @@ -648,7 +648,7 @@ private void handleSlideEmbeddedResources(ShapeContainer shapeContainer,
data = oleShape.getObjectData();
} catch (NullPointerException e) {
/* getObjectData throws NPE some times. */
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, context);
continue;
}

Expand All @@ -668,7 +668,7 @@ private void handleSlideEmbeddedResources(ShapeContainer shapeContainer,
try {
dataStream = data.getInputStream();
} catch (Exception e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, context);
continue;
}
handleDataStream(dataStream, objID, oleShape.getProgId(), xhtml);
Expand Down Expand Up @@ -703,7 +703,7 @@ private void handleDataStream(InputStream dataStream, String objID, String progI
} catch (SecurityException e) {
throw e;
} catch (Exception e) {
EmbeddedDocumentUtil.recordException(e, parentMetadata);
EmbeddedDocumentUtil.recordException(e, parentMetadata, context);
}
}

Expand All @@ -714,7 +714,7 @@ private List<HSLFShape> getShapes(ShapeContainer shapeContainer) {
} catch (NullPointerException e) {
// Sometimes HSLF hits problems
// Please open POI bugs for any you come across!
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, context);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private void handleOLE(Row row, String cName, XHTMLContentHandler xhtml)
try {
tis = TikaInputStream.get(spc.getStream());
} catch (IOException e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, parseContext);
break;
}
if (tis != null) {
Expand All @@ -347,7 +347,7 @@ private void handleOLE(Row row, String cName, XHTMLContentHandler xhtml)
try {
ocStream = TikaInputStream.get(oc.getStream());
} catch (IOException e) {
EmbeddedDocumentUtil.recordException(e, parentMetadata);
EmbeddedDocumentUtil.recordException(e, parentMetadata, parseContext);
}
try {
handleEmbeddedResource(ocStream, null,//filename
Expand All @@ -373,14 +373,14 @@ private void handleCompoundContent(OleBlob.CompoundContent cc, XHTMLContentHandl
try {
is = cc.getStream();
} catch (IOException e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, parseContext);
return;
}

try {
fileSystem = new POIFSFileSystem(is);
} catch (Exception e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, parseContext);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static void extractMacros(POIFSFileSystem fs, ContentHandler xhtml,
m.set(TikaCoreProperties.EMBEDDED_RESOURCE_TYPE,
TikaCoreProperties.EmbeddedResourceType.MACRO.toString());
m.set(HttpHeaders.CONTENT_TYPE, "text/x-vbasic");
EmbeddedDocumentUtil.recordException(e, m);
EmbeddedDocumentUtil.recordException(e, m, context);
if (embeddedDocumentExtractor.shouldParseEmbedded(m, context)) {
embeddedDocumentExtractor.parseEmbedded(
//pass in space character so that we don't trigger a zero-byte exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ private void handleEmbedded(int length, ExtendedGUID gosid)
dif.read(buf);
} catch (IOException e) {
//store this exception in the parent's metadata
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, parseContext);
return;
}
Metadata embeddedMetadata = Metadata.newInstance(this.parseContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ private void handleEmbedded(byte[] data, XHTMLContentHandler xhtml,
embeddedMetadata, this.parseContext, false);
}
} catch (IOException e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, parseContext);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private void handleThumbnail(ContentHandler handler, Metadata metadata) throws S
WriteLimitReachedException.throwIfWriteLimitReached(ex);
//swallow otherwise
metadata.add(TikaCoreProperties.EMBEDDED_EXCEPTION,
ExceptionUtils.getStackTrace(ex));
ExceptionUtils.format(ex, context));
}
}

Expand All @@ -265,7 +265,7 @@ private void handleEmbeddedParts(XHTMLContentHandler xhtml, Metadata metadata,
} catch (SAXException | SecurityException e) {
throw e;
} catch (Exception e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, metadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, metadata, context);
}
}
}
Expand Down Expand Up @@ -378,7 +378,7 @@ private void handleEmbeddedOLE(PackagePart part, XHTMLContentHandler xhtml, Stri
try {
fs = new POIFSFileSystem(part.getInputStream());
} catch (Exception e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, context);
return;
}
TikaInputStream tis = null;
Expand Down Expand Up @@ -438,7 +438,7 @@ private void handleEmbeddedOLE(PackagePart part, XHTMLContentHandler xhtml, Stri
} catch (Ole10NativeException e) {
// Could not process an OLE 1.0 entry, so skip this part
} catch (IOException e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata, context);
} finally {
fs.close();
if (tis != null) {
Expand Down Expand Up @@ -641,7 +641,7 @@ protected Map<String, String> loadLinkedRelationships(PackagePart bodyPart,
}

} catch (InvalidFormatException e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, metadata);
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, metadata, context);
}
return linkedRelationships;
}
Expand Down Expand Up @@ -685,8 +685,7 @@ void handleGeneralTextContainingPart(String contentType, String xhtmlClassLabel,
try {
relatedPartPRC = parentPart.getRelationshipsByType(contentType);
} catch (InvalidFormatException e) {
parentMetadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING,
ExceptionUtils.getStackTrace(e));
EmbeddedDocumentUtil.recordException(e, parentMetadata, context);
}
if (relatedPartPRC != null && relatedPartPRC.size() > 0) {
AttributesImpl attributes = new AttributesImpl();
Expand Down Expand Up @@ -715,17 +714,14 @@ void handleGeneralTextContainingPart(String contentType, String xhtmlClassLabel,

} catch (IOException | TikaException e) {
balancer.drainOpenElements();
parentMetadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING,
ExceptionUtils.getStackTrace(e));
EmbeddedDocumentUtil.recordException(e, parentMetadata, context);
} catch (SAXException e) {
balancer.drainOpenElements();
WriteLimitReachedException.throwIfWriteLimitReached(e);
parentMetadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING,
ExceptionUtils.getStackTrace(e));
EmbeddedDocumentUtil.recordException(e, parentMetadata, context);
}
} catch (InvalidFormatException e) {
parentMetadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING,
ExceptionUtils.getStackTrace(e));
EmbeddedDocumentUtil.recordException(e, parentMetadata, context);
}
}
contentHandler.endElement("", "div", "div");
Expand Down
Loading
Loading