Advertisement
crandom

Untitled

Mar 6th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. package com.aparavi.tika_api;
  2.  
  3. import com.aparavi.tika_api.Util;
  4. import org.apache.tika.metadata.Property;
  5.  
  6. public class Metadata extends org.apache.tika.metadata.Metadata {
  7.     private final static String excludedNames[] = {
  8.         "pdf:charsPerPage",
  9.         "pdf:unmappedUnicodeCharsPerPage",
  10.         "X-Parsed-By",
  11.         "X-TIKA:EXCEPTION:embedded_stream_exception",
  12.     };
  13.  
  14.     private final static String excludedNamePrefixes[] = {
  15.         "Message:Raw-Header:",
  16.     };
  17.  
  18.     private static boolean isNameExcluded(String name) {
  19.         for (String excluded : excludedNames) {
  20.             if (name == excluded)
  21.                 return true;
  22.         }
  23.  
  24.         for (String prefix : excludedNamePrefixes) {
  25.             if (name.startsWith(prefix))
  26.                 return true;
  27.         }
  28.  
  29.         return false;
  30.     }
  31.  
  32.     public void finalize() {
  33.          // If the content type is present but unknown, remove it
  34.          if (get("Content-Type") == "application/octet-stream")
  35.             remove("Content-Type");      
  36.     }
  37.  
  38.     public void add(final String name, final String value) {
  39.         if (isNameExcluded(name))
  40.             return;
  41.  
  42.         super.add(name, Util.StripNonPrintableCharacters(value));
  43.     }
  44.  
  45.     public void set(String name, String value) {
  46.         if (isNameExcluded(name))
  47.             return;
  48.  
  49.         super.set(name, Util.StripNonPrintableCharacters(value));
  50.     }
  51.  
  52.     public void set(Property property, String[] values) {
  53.         if (isNameExcluded(property.getName()))
  54.             return;
  55.  
  56.         for(int i = 0; i < values.length; i++) {
  57.             values[i] = Util.StripNonPrintableCharacters(values[i]);
  58.         }
  59.        
  60.         super.set(property, values);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement