Find a DocumentFormat implementation that deals with a particular MIME type, given that type. @param aGateDocument this document will receive as a feature the associated Mime Type. The name of the feature is MimeType and its value is in the format type/subt
(gate.Document aGateDocument,
MimeType mimeType)
| 498 | * @param mimeType the mime type that is given as input |
| 499 | */ |
| 500 | static public DocumentFormat getDocumentFormat(gate.Document aGateDocument, |
| 501 | MimeType mimeType){ |
| 502 | FeatureMap aFeatureMap = null; |
| 503 | if(mimeType == null) { |
| 504 | String content = aGateDocument.getContent().toString(); |
| 505 | // reduce size for better performance |
| 506 | if(content.length() > 2048) content = content.substring(0, 2048); |
| 507 | mimeType = getTypeFromContent( content ); |
| 508 | } |
| 509 | |
| 510 | if (mimeType != null){ |
| 511 | // If the Gate Document doesn't have a feature map atached then |
| 512 | // We will create and set one. |
| 513 | if(aGateDocument.getFeatures() == null){ |
| 514 | aFeatureMap = Factory.newFeatureMap(); |
| 515 | aGateDocument.setFeatures(aFeatureMap); |
| 516 | }// end if |
| 517 | aGateDocument.getFeatures().put("MimeType",mimeType.getType() + "/" + |
| 518 | mimeType.getSubtype()); |
| 519 | |
| 520 | return mimeString2ClassHandlerMap.get(mimeType.getType() |
| 521 | + "/" + mimeType.getSubtype()); |
| 522 | }// end If |
| 523 | return null; |
| 524 | } // getDocumentFormat(aGateDocument, MimeType) |
| 525 | |
| 526 | /** |
| 527 | * Find a DocumentFormat implementation that deals with a particular |