|
Lines 36-42
Link Here
|
| 36 |
public IContentType findContentTypeFor(InputStream contents, String fileName) throws IOException { |
36 |
public IContentType findContentTypeFor(InputStream contents, String fileName) throws IOException { |
| 37 |
ContentTypeCatalog currentCatalog = getCatalog(); |
37 |
ContentTypeCatalog currentCatalog = getCatalog(); |
| 38 |
IContentType[] all = currentCatalog.findContentTypesFor(this, contents, fileName); |
38 |
IContentType[] all = currentCatalog.findContentTypesFor(this, contents, fileName); |
| 39 |
return all.length > 0 ? new ContentTypeHandler((ContentType) all[0], currentCatalog.getGeneration()) : null; |
39 |
return all.length > 0 ? new ContentTypeHandler((ContentType) getContentTypeWithTheHighestPriority(all), currentCatalog.getGeneration()) : null; |
|
|
40 |
} |
| 41 |
|
| 42 |
/* |
| 43 |
* Returns a content type with the highest priority from the given list. |
| 44 |
*/ |
| 45 |
private IContentType getContentTypeWithTheHighestPriority(IContentType[] contentTypes) { |
| 46 |
IContentType bestMatch = null; |
| 47 |
for (int i = 0; i < contentTypes.length; i++) { |
| 48 |
if (bestMatch == null || (((ContentType) bestMatch).getPriority() < ((ContentType) contentTypes[i]).getPriority())) { |
| 49 |
bestMatch = contentTypes[i]; |
| 50 |
if (((ContentType) bestMatch).getPriority() == ContentType.PRIORITY_HIGH) |
| 51 |
break; |
| 52 |
} |
| 53 |
} |
| 54 |
return bestMatch; |
| 40 |
} |
55 |
} |
| 41 |
|
56 |
|
| 42 |
/** |
57 |
/** |
|
Lines 46-52
Link Here
|
| 46 |
// basic implementation just gets all content types |
61 |
// basic implementation just gets all content types |
| 47 |
ContentTypeCatalog currentCatalog = getCatalog(); |
62 |
ContentTypeCatalog currentCatalog = getCatalog(); |
| 48 |
IContentType[] associated = currentCatalog.findContentTypesFor(this, fileName); |
63 |
IContentType[] associated = currentCatalog.findContentTypesFor(this, fileName); |
| 49 |
return associated.length == 0 ? null : new ContentTypeHandler((ContentType) associated[0], currentCatalog.getGeneration()); |
64 |
return associated.length == 0 ? null : new ContentTypeHandler((ContentType) getContentTypeWithTheHighestPriority(associated), currentCatalog.getGeneration()); |
| 50 |
} |
65 |
} |
| 51 |
|
66 |
|
| 52 |
/** |
67 |
/** |