Author: jukka
Date: Tue Jun 2 00:38:43 2009
New Revision: 780894
URL: http://svn.apache.org/viewvc?rev=780894&view=rev
Log:
TIKA-87: MimeTypes should allow modification of MIME types
Some type configuration code cleanups (avoid using NumberFormatException for
flow control)
Modified:
lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/Magic.java
lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MimeTypesReader.java
Modified:
lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/Magic.java
URL:
http://svn.apache.org/viewvc/lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/Magic.java?rev=780894&r1=780893&r2=780894&view=diff
==============================================================================
--- lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/Magic.java
(original)
+++ lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/Magic.java
Tue Jun 2 00:38:43 2009
@@ -24,21 +24,13 @@
*/
class Magic implements Clause, Comparable<Magic> {
- private MimeType type = null;
+ private final MimeType type;
private int priority = 50;
private Clause clause = null;
- Magic() {
- this(50);
- }
-
- Magic(int priority) {
- this.priority = priority;
- }
-
- void setType(MimeType type) {
+ Magic(MimeType type) {
this.type = type;
}
@@ -46,6 +38,10 @@
return type;
}
+ void setPriority(int priority) {
+ this.priority = priority;
+ }
+
int getPriority() {
return priority;
}
Modified:
lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MimeTypesReader.java
URL:
http://svn.apache.org/viewvc/lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MimeTypesReader.java?rev=780894&r1=780893&r2=780894&view=diff
==============================================================================
---
lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MimeTypesReader.java
(original)
+++
lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MimeTypesReader.java
Tue Jun 2 00:38:43 2009
@@ -192,15 +192,15 @@
/** Read Element named magic. */
private void readMagic(Element element, MimeType mimeType) {
- Magic magic = null;
- try {
- magic = new Magic(Integer
- .parseInt(element.getAttribute(MAGIC_PRIORITY_ATTR)));
- } catch (Exception e) {
- magic = new Magic();
+ Magic magic = new Magic(mimeType);
+
+ String priority = element.getAttribute(MAGIC_PRIORITY_ATTR);
+ if (priority != null && priority.length() > 0) {
+ magic.setPriority(Integer.parseInt(priority));
}
- magic.setType(mimeType);
+
magic.setClause(readMatches(element));
+
mimeType.addMagic(magic);
}
@@ -255,21 +255,21 @@
mask = attr.getValue();
}
}
+
// Parse OffSet
- String[] offsets = offset.split(":");
int offStart = 0;
int offEnd = 0;
- try {
- offStart = Integer.parseInt(offsets[0]);
- } catch (Exception e) {
- // WARN log + avoid loading
- }
- try {
- offEnd = Integer.parseInt(offsets[1]);
- } catch (Exception e) {
- // WARN log
+ if (offset != null) {
+ int colon = offset.indexOf(':');
+ if (colon == -1) {
+ offStart = Integer.parseInt(offset);
+ offEnd = offStart;
+ } else {
+ offStart = Integer.parseInt(offset.substring(0, colon));
+ offEnd = Integer.parseInt(offset.substring(colon + 1));
+ offEnd = Math.max(offStart, offEnd);
+ }
}
- offEnd = Math.max(offStart, offEnd);
return new MagicMatch(offStart, offEnd, type, mask, value);
}