org.basex.build.fs
Class NewFSParser

java.lang.Object
  extended by org.basex.core.Progress
      extended by org.basex.build.Parser
          extended by org.basex.build.fs.NewFSParser

public final class NewFSParser
extends Parser

Imports/shreds/parses a file hierarchy into a database. The overall process of importing a file hierarchy can be described as follows:

  1. The import is invoked by the CreateFS command. To import on the command line type: $ create fs [path] [dbname]
  2. This class NewFSParser instantiates the parsers to extract metadata and content from files.

Author:
Workgroup DBIS, University of Konstanz 2005-09, ISC License, Alexander Holupirek, alex@holupirek.de, Bastian Lemke

Nested Class Summary
static class NewFSParser.NS
          All namespaces used in NewFSParser.
 
Field Summary
 java.lang.String mountpoint
          Path to FUSE mountpoint.
 java.lang.String mybackingpath
          Path to root of the backing store for this import.
static boolean VERBOSE
          If true, verbose debug messages are created (e.g. for corrupt files).
 
Fields inherited from class org.basex.build.Parser
doc, io, prop
 
Constructor Summary
NewFSParser(java.lang.String path, Prop pr)
          Constructor to parse single file nodes.
NewFSParser(java.lang.String path, java.lang.String mp, java.lang.String bs, Prop pr)
          Constructor.
 
Method Summary
static boolean deleteDir(java.io.File dir)
          Deletes a non-empty directory.
 java.lang.String det()
          Returns short information on this process.
 void endContent()
          Closes the last opened content element.
 void endXMLContent()
          Closes the last opened XML content element.
 boolean isParseable(BufferedFileChannel f, java.lang.String suffix)
          Checks if a parser for the given suffix is available and the file is in the correct format.
 void metaEvent(Metadata m)
          Generates the xml representation for a key-value pair and adds it to the current file element.
 void parse(Builder build)
          Main entry point for the import of a file hierarchy.
 void parseFileFragment(BufferedFileChannel bfc, java.lang.String title, java.lang.String suffix)
           Parses a fragment of a file, e.g. a picture inside an ID3 frame.
 void parseWithFallbackParser(BufferedFileChannel bfc, boolean content)
           Parses the file with the fallback parser.
 void parseXML()
          Parses a xml file.
 double prog()
          Returns progress information.
static void register(java.lang.String suffix, java.lang.Class<? extends AbstractParser> c)
          Registers a parser implementation with the fs parser.
static void registerFallback(java.lang.Class<? extends AbstractParser> c)
          Registers a fallback parser implementation with the fs parser.
 void startContent(long offset, long size)
          Generates the xml representation for a new content element inside the current file or content node node.
 void startXMLContent(long offset, long size)
          Generates the xml representation for a new XML content element inside the current file or content node node.
 void textContent(long offset, long size, byte[] text, boolean preserveSpace)
          Adds a text element.
 void textContent(long offset, long size, java.lang.String text, boolean preserveSpace)
          Adds a text element.
 void textContent(long offset, long size, TokenBuilder text, boolean preserveSpace)
           Adds a text element.
 java.lang.String tit()
          Returns short information on this process.
 
Methods inherited from class org.basex.build.Parser
emptyParser, xmlParser
 
Methods inherited from class org.basex.core.Progress
checkStop, detail, progress, progress, stop, title
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERBOSE

public static final boolean VERBOSE
If true, verbose debug messages are created (e.g. for corrupt files).

See Also:
Constant Field Values

mountpoint

public final java.lang.String mountpoint
Path to FUSE mountpoint.


mybackingpath

public final java.lang.String mybackingpath
Path to root of the backing store for this import.

Constructor Detail

NewFSParser

public NewFSParser(java.lang.String path,
                   java.lang.String mp,
                   java.lang.String bs,
                   Prop pr)
Constructor.

Parameters:
path - the traversal starts from
mp - mount point for fuse
bs - path to root of backing store for BLOBs on Windows systems. If set to true, the path reference is ignored
pr - database properties

NewFSParser

public NewFSParser(java.lang.String path,
                   Prop pr)
Constructor to parse single file nodes.

Parameters:
path - String to file node to parse
pr - database properties
Method Detail

register

public static void register(java.lang.String suffix,
                            java.lang.Class<? extends AbstractParser> c)
Registers a parser implementation with the fs parser.

Parameters:
suffix - the suffix to register the parser implementation for.
c - the parser implementation class.

registerFallback

public static void registerFallback(java.lang.Class<? extends AbstractParser> c)
Registers a fallback parser implementation with the fs parser.

Parameters:
c - the parser implementation class.

parse

public void parse(Builder build)
           throws java.io.IOException
Main entry point for the import of a file hierarchy. Instantiates the engine and starts the traversal.

Specified by:
parse in class Parser
Parameters:
build - instance passed by CreateFS.
Throws:
java.io.IOException - I/O exception

parseFileFragment

public void parseFileFragment(BufferedFileChannel bfc,
                              java.lang.String title,
                              java.lang.String suffix)
                       throws java.io.IOException

Parses a fragment of a file, e.g. a picture inside an ID3 frame.

This method is intended to be called only from within a parser implementation. The parser implementation must create a subchannel of its BufferedFileChannel instance via BufferedFileChannel.subChannel(int).

Parameters:
bfc - the BufferedFileChannel to read from.
title - the title to set for the fragment. Set to null if there is no title to set.
suffix - the file suffix.
Throws:
java.io.IOException - if any error occurs while reading from the file.

parseWithFallbackParser

public void parseWithFallbackParser(BufferedFileChannel bfc,
                                    boolean content)
                             throws java.io.IOException

Parses the file with the fallback parser.

This method is intended to be called from a parser implementation that failed to parse a file.

Parameters:
bfc - the BufferedFileChannel to read from.
content - parses the content if true or the metadata otherwise.
Throws:
java.io.IOException - if any error occurs while reading from the file.

tit

public java.lang.String tit()
Description copied from class: Progress
Returns short information on this process. Can be overwritten to give more detailed information.

Overrides:
tit in class Progress
Returns:
header information

det

public java.lang.String det()
Description copied from class: Progress
Returns short information on this process.

Overrides:
det in class Progress
Returns:
header information

prog

public double prog()
Description copied from class: Progress
Returns progress information. Can be overwritten to give more detailed information.

Overrides:
prog in class Progress
Returns:
header information

deleteDir

public static boolean deleteDir(java.io.File dir)
Deletes a non-empty directory.

Parameters:
dir - to be deleted.
Returns:
boolean true for success, false for failure.

metaEvent

public void metaEvent(Metadata m)
               throws java.io.IOException
Generates the xml representation for a key-value pair and adds it to the current file element.

Parameters:
m - the Metadata object containing all metadata information.
Throws:
java.io.IOException - if any error occurs while generating the xml code.

textContent

public void textContent(long offset,
                        long size,
                        java.lang.String text,
                        boolean preserveSpace)
                 throws java.io.IOException
Adds a text element. If the position of the text content is unknown, the offset should be set to -1.

Parameters:
offset - the absolute position of the first byte of the file fragment represented by this content element inside the current file.
size - the size of the content element.
text - the text to add.
preserveSpace - if true, the xml attribute xml:space is set.
Throws:
java.io.IOException - if any error occurs while reading from the file.

textContent

public void textContent(long offset,
                        long size,
                        byte[] text,
                        boolean preserveSpace)
                 throws java.io.IOException
Adds a text element. If the position of the text content is unknown, the offset should be set to -1.

Parameters:
offset - the absolute position of the first byte of the file fragment represented by this content element inside the current file.
size - the size of the content element.
text - the text to add.
preserveSpace - if true, the xml attribute xml:space is set.
Throws:
java.io.IOException - if any error occurs while reading from the file.

textContent

public void textContent(long offset,
                        long size,
                        TokenBuilder text,
                        boolean preserveSpace)
                 throws java.io.IOException

Adds a text element. If the position of the text content is unknown, the offset should be set to -1. text must contain only valid UTF-8 characters! Otherwise the generated XML document may be not well-formed.

Parameters:
offset - the absolute position of the first byte of the file fragment represented by this content element inside the current file.
size - the size of the content element.
text - the text to add.
preserveSpace - if true, the xml attribute xml:space is set.
Throws:
java.io.IOException - if any error occurs while reading from the file.

startContent

public void startContent(long offset,
                         long size)
                  throws java.io.IOException
Generates the xml representation for a new content element inside the current file or content node node.

Parameters:
offset - the absolute position of the first byte of the file fragment represented by this content element inside the current file.
size - the size of the content element.
Throws:
java.io.IOException - if any error occurs while reading from the file.

endContent

public void endContent()
                throws java.io.IOException
Closes the last opened content element.

Throws:
java.io.IOException - if any error occurs while reading from the file.

startXMLContent

public void startXMLContent(long offset,
                            long size)
                     throws java.io.IOException
Generates the xml representation for a new XML content element inside the current file or content node node.

Parameters:
offset - the absolute position of the first byte of the file fragment represented by this content element inside the current file.
size - the size of the content element.
Throws:
java.io.IOException - if any error occurs while reading from the file.

endXMLContent

public void endXMLContent()
                   throws java.io.IOException
Closes the last opened XML content element.

Throws:
java.io.IOException - if any error occurs while reading from the file.

parseXML

public void parseXML()
              throws java.io.IOException
Parses a xml file.

Throws:
java.io.IOException - if any error occurs while generating the xml code.

isParseable

public boolean isParseable(BufferedFileChannel f,
                           java.lang.String suffix)
                    throws java.io.IOException
Checks if a parser for the given suffix is available and the file is in the correct format.

Parameters:
f - the BufferedFileChannel to check.
suffix - the file suffix.
Returns:
true if the data is supported.
Throws:
java.io.IOException - if any error occurs while reading from the file.