Tries to extract tips for the parser as specified here - http://tika.apache.org/0.7/parser.html . The tips are not critical for successful parsing. @param doc @return metadata, not null but may be empty
(Document doc)
| 164 | * @return metadata, not null but may be empty |
| 165 | */ |
| 166 | private Metadata extractParserTips(Document doc) { |
| 167 | Metadata metadata = new Metadata(); |
| 168 | Object inputMime = doc.getFeatures().get("MimeType"); |
| 169 | if (inputMime instanceof String) { |
| 170 | if (!"application/tika".equals(inputMime)) { |
| 171 | metadata.add(Metadata.CONTENT_TYPE, (String) doc.getFeatures().get("MimeType")); |
| 172 | } |
| 173 | } |
| 174 | if (doc instanceof DocumentImpl) { |
| 175 | if (((DocumentImpl)doc).getMimeType() != null) { |
| 176 | metadata.add(Metadata.CONTENT_TYPE, ((DocumentImpl)doc).getMimeType()); |
| 177 | } |
| 178 | } |
| 179 | if (doc.getSourceUrl() != null && doc.getSourceUrl().getProtocol().startsWith("file")) { |
| 180 | try { |
| 181 | File fn =new File(doc.getSourceUrl().toURI()); |
| 182 | metadata.add(Metadata.RESOURCE_NAME_KEY, fn.getName()); |
| 183 | } catch (URISyntaxException e) { |
| 184 | log.debug("Could not extract filename from uri: " + doc.getSourceUrl(), e); |
| 185 | } catch (IllegalArgumentException e) { |
| 186 | log.debug("Could not extract filename from uri: " + doc.getSourceUrl(), e); |
| 187 | } |
| 188 | } |
| 189 | return metadata; |
| 190 | } |
| 191 | } |
no test coverage detected