MCPcopy Create free account
hub / github.com/GateNLP/gate-core / willReadFromUrl

Method willReadFromUrl

src/main/java/gate/DocumentFormat.java:636–674  ·  view source on GitHub ↗

Utility function to determine if reading from the URL will be done by a registered DocumentFormat. This tries to find out if there is a registered DocumentFormat for the mime type string or document URL. If yes, it is checked if that document format implements DirectLoadingDocumentFormat. If yes, r

(String mimeTypeStr, URL docUrl)

Source from the content-addressed store, hash-verified

634 * @return true if the URL will be read directly by a document format.
635 */
636 public static boolean willReadFromUrl(String mimeTypeStr, URL docUrl) {
637 // figure out if we have a document format registered for the
638 // mime type. If yes, check if the document format implemts
639 // BinaryDocumentFormat. If yes, ask the document format if we
640 // should create the content from the URL here or leave that for
641 // the DocumentFormat to do later.
642 DocumentFormat docFormat = null;
643 // If a mimeTypeStr is specified, try to get the document format
644 // registered for it
645 MimeType theType = null;
646 if (mimeTypeStr != null && mimeTypeStr.length() > 0) {
647 theType = DocumentFormat.getMimeTypeForString(mimeTypeStr);
648 if (theType != null) {
649 docFormat = DocumentFormat.getDocumentFormat(theType);
650 }
651 }
652 // If we could not get the docFormat from the mimeTypeStr, lets see
653 // if we can get it from the url
654 if (docFormat == null && docUrl != null) {
655 // if we do not have a mime type already, try to find one from the
656 // URL suffixes. Only if this fails, use the methods that actually
657 // open the URL to to get a content type or magic number
658 for (String suffix : getFileSuffixes(docUrl)) {
659 theType = getMimeType(suffix);
660 if (theType != null) {
661 break;
662 }
663 }
664 if(theType != null) {
665 docFormat = DocumentFormat.getDocumentFormat(theType);
666 }
667 if (docFormat != null) {
668 theType = DocumentFormat.getMimeType(docUrl);
669 docFormat = DocumentFormat.getDocumentFormat(theType);
670 }
671 }
672
673 return (docFormat != null && docFormat instanceof DirectLoadingDocumentFormat);
674 }
675
676
677 //StatusReporter Implementation

Callers 1

initMethod · 0.95

Calls 5

getMimeTypeForStringMethod · 0.95
getDocumentFormatMethod · 0.95
getFileSuffixesMethod · 0.95
getMimeTypeMethod · 0.95
lengthMethod · 0.45

Tested by

no test coverage detected