org.mmbase.util.magicfile
Class BasicDetector

java.lang.Object
  extended by org.mmbase.util.magicfile.AbstractDetector
      extended by org.mmbase.util.magicfile.BasicDetector
All Implemented Interfaces:
Detector

public class BasicDetector
extends AbstractDetector

A Detector stores one entry from the magic.xml file, and contains the functionality to determines if a certain byte[] satisfies it. Implementation made on the basis of actual magic file and its manual.
TODO:
- link the info with mimetypes
- add test modifiers
- add commandline switches for warning, error and debugging messages

Ignored features of magic:
- date types
- indirect offsets (prefix of '&' in sublevel match or (address+bytes) where offset = value of address plus bytes
- AND'ing of type

BUGS:
- test string isn't read when end of line is reached in absence of a message string

Tested:
- .doc
- .rtf
- .pdf
- .sh
- .gz
- .bz2
- .html
- .rpm
- .wav

Not supported by magic file:
- StarOffice

Version:
$Id: BasicDetector.java 41722 2010-04-01 12:34:12Z michiel $

Field Summary
 
Fields inherited from class org.mmbase.util.magicfile.AbstractDetector
childList, message, valid
 
Constructor Summary
BasicDetector()
           
 
Method Summary
 void configure(Element e)
           
 char getComparator()
           
 String getDesignation()
          todo: I noticed there is also a %5.5s variation in magic...
 int getOffset()
           
 String getRawInput()
           
 String getTest()
           
 String getType()
           
 void setComparator(char comparator)
           
 void setOffset(String offset)
           
 void setTest(String test)
           
 void setType(String type)
           
 boolean test(byte[] lithmus)
           
protected  boolean testByte(byte[] lithmus)
          Test whether a byte matches
protected  boolean testLong(byte[] lithmus, int endian)
          Test whether a long matches
protected  boolean testShort(byte[] lithmus, int endian)
          Test whether a short matches
protected  boolean testString(byte[] lithmus)
          Test whether a string matches
 String toString()
           
 void toXML(FileWriter f)
          XML notatie: foo/bar bar blablabla test string etc
 void toXML(FileWriter f, int level)
           
protected  String xmlEntities(String s)
           
 
Methods inherited from class org.mmbase.util.magicfile.AbstractDetector
addChild, getExtension, getExtensions, getMimeType, setDesignation, setExtension, setMimeType, setValid, valid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicDetector

public BasicDetector()
Method Detail

setOffset

public void setOffset(String offset)

getOffset

public int getOffset()

setType

public void setType(String type)

getType

public String getType()

setTest

public void setTest(String test)

getTest

public String getTest()

setComparator

public void setComparator(char comparator)

getComparator

public char getComparator()

test

public boolean test(byte[] lithmus)
Returns:
Whether detector matches the prefix/lithmus of the file

getDesignation

public String getDesignation()
todo: I noticed there is also a %5.5s variation in magic...

Specified by:
getDesignation in interface Detector
Overrides:
getDesignation in class AbstractDetector

testString

protected boolean testString(byte[] lithmus)
Test whether a string matches


testShort

protected boolean testShort(byte[] lithmus,
                            int endian)
Test whether a short matches


testLong

protected boolean testLong(byte[] lithmus,
                           int endian)
Test whether a long matches


testByte

protected boolean testByte(byte[] lithmus)
Test whether a byte matches


getRawInput

public String getRawInput()
Returns:
Original unprocessed input line
Since:
MMBase-1.7

xmlEntities

protected String xmlEntities(String s)

toXML

public void toXML(FileWriter f)
           throws IOException
XML notatie: foo/bar bar blablabla test string etc

Throws:
IOException

toXML

public void toXML(FileWriter f,
                  int level)
           throws IOException
Parameters:
level - Indicates depth of (child) element
Throws:
IOException

configure

public void configure(Element e)
Specified by:
configure in interface Detector
Overrides:
configure in class AbstractDetector

toString

public String toString()
Overrides:
toString in class AbstractDetector
Returns:
String representation of Detector object.


MMBase 2.0-SNAPSHOT - null