Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.aparavi.tika_api;
- import com.aparavi.tika_api.Util;
- import org.apache.tika.metadata.Property;
- public class Metadata extends org.apache.tika.metadata.Metadata {
- private final static String excludedNames[] = {
- "pdf:charsPerPage",
- "pdf:unmappedUnicodeCharsPerPage",
- "X-Parsed-By",
- "X-TIKA:EXCEPTION:embedded_stream_exception",
- };
- private final static String excludedNamePrefixes[] = {
- "Message:Raw-Header:",
- };
- private static boolean isNameExcluded(String name) {
- for (String excluded : excludedNames) {
- if (name == excluded)
- return true;
- }
- for (String prefix : excludedNamePrefixes) {
- if (name.startsWith(prefix))
- return true;
- }
- return false;
- }
- public void finalize() {
- // If the content type is present but unknown, remove it
- if (get("Content-Type") == "application/octet-stream")
- remove("Content-Type");
- }
- public void add(final String name, final String value) {
- if (isNameExcluded(name))
- return;
- super.add(name, Util.StripNonPrintableCharacters(value));
- }
- public void set(String name, String value) {
- if (isNameExcluded(name))
- return;
- super.set(name, Util.StripNonPrintableCharacters(value));
- }
- public void set(Property property, String[] values) {
- if (isNameExcluded(property.getName()))
- return;
- for(int i = 0; i < values.length; i++) {
- values[i] = Util.StripNonPrintableCharacters(values[i]);
- }
- super.set(property, values);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement