Class PageAnchoring
java.lang.Object
org.apache.tika.metadata.PageAnchoring
Helpers for tagging an embedded resource's metadata with the pages or
sheets of its parent document on which it appears. Centralised so every
paginated/sheeted parser (HSLF/XSLF for PowerPoint, OpenDocumentParser
for ODP, HSSF/XSSF for Excel, PDF, ...) encodes the same convention
identically.
Convention:
indices == null: caller does not know the resource's anchoring — both single- and sequence-valued properties are left unset.indices.isEmpty(): the resource is known to be present in the container but referenced from no page/sheet — the sequence property is set to a single-element array containing the sentinel value (seeTikaPagedText.UNLINKED_PAGEandOffice.UNLINKED_SHEET).indices.size() == 1: both the single-valued and the sequence-valued property are set, the sequence carrying the one index as its only element. Consumers that only inspect the single-valued property still see the right answer.indices.size() > 1: only the sequence-valued property is set; the single-valued property is cleared, because no single index would be meaningful.
This class only mutates the metadata it is handed — it is the caller's job to compute the index set (e.g. by pre-scanning a slide file for picture references before the embedded-resource emission).
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyAnchorMetadata(Metadata target, Collection<Integer> indices, Property singleProperty, Property sequenceProperty, int unlinkedSentinel) Shared core forapplyPageMetadata(Metadata, Collection)andapplySheetMetadata(Metadata, Collection).static voidapplyPageMetadata(Metadata target, Collection<Integer> pages) ApplyTikaPagedText.PAGE_NUMBER/TikaPagedText.PAGE_NUMBERStotarget, per the page-anchoring convention.static voidapplySheetMetadata(Metadata target, Collection<Integer> sheets) ApplyOffice.SHEET_NUMBER/Office.SHEET_NUMBERStotarget, per the same convention asapplyPageMetadata(Metadata, Collection).
-
Method Details
-
applyPageMetadata
ApplyTikaPagedText.PAGE_NUMBER/TikaPagedText.PAGE_NUMBERStotarget, per the page-anchoring convention. Used by presentation parsers (PPT, PPTX, ODP), and by PDF parsers when tagging per-page embedded resources.- Parameters:
target- metadata to write topages- 1-based page numbers, an empty collection for "known unlinked", ornullfor unknown
-
applySheetMetadata
ApplyOffice.SHEET_NUMBER/Office.SHEET_NUMBERStotarget, per the same convention asapplyPageMetadata(Metadata, Collection). Used by spreadsheet parsers (HSSF, XSSF) when tagging an embedded resource with the sheets it appears on.- Parameters:
target- metadata to write tosheets- 1-based sheet numbers, an empty collection for "known unlinked", ornullfor unknown
-
applyAnchorMetadata
public static void applyAnchorMetadata(Metadata target, Collection<Integer> indices, Property singleProperty, Property sequenceProperty, int unlinkedSentinel) Shared core forapplyPageMetadata(Metadata, Collection)andapplySheetMetadata(Metadata, Collection). Exposed so future paginated-resource conventions (e.g. arbitrary index spaces other than pages/sheets) can reuse the same logic without copying it.- Parameters:
target- metadata to write to (no-op ifnull)indices- the anchor indices, ornullfor "unknown"singleProperty-internalIntegerproperty set when there is exactly one anchor indexsequenceProperty-internalIntegerSequenceproperty populated with all anchor indicesunlinkedSentinel- value used as the sole element ofsequencePropertywhenindicesis empty (known unlinked)
-