Changeset 3637


Ignore:
Timestamp:
Aug 7, 2007, 11:17:37 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #710: Allow subclasses to AbstractFlatFileParser? to participate in auto-detection of file format

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/src/docbook/developerdoc/plugin_developer.xml

    r3609 r3637  
    17781778   try
    17791779   {
     1780      ffp.nextSection();
    17801781      FlatFileParser.LineType result = ffp.parseHeaders();
    1781       return result != FlatFileParser.LineType.UNKNOWN;
     1782      if (result == FlatFileParser.LineType.UNKNOWN)
     1783      {
     1784         return false;
     1785      }
     1786      else
     1787      {
     1788         return isImportable(ffp);
     1789      }
    17821790   }
    17831791   catch (IOException ex)
     
    19371945      <listitem>
    19381946        <para>
    1939         Implement the <methodname>Plugin.getAbout()</methodname> and
    1940         <methodname>Plugin.getMainType()</methodname> methods. See
     1947        Implement the <methodname>Plugin.getAbout()</methodname> method. See
    19411948        <xref linkend="plugin_developer.api.interfaces.plugin" /> for more information.
    19421949        </para>
     
    20542061   ffp.setMinDataColumns(12);
    20552062   return ffp;
     2063}
     2064</programlisting>
     2065        </listitem>
     2066      </varlistentry>
     2067     
     2068      <varlistentry>
     2069        <term>
     2070          <methodsynopsis language="java">
     2071            <modifier>protected</modifier>
     2072            <type>boolean</type>
     2073            <methodname>isImportable</methodname>
     2074            <methodparam>
     2075              <type>FlatFileParser</type>
     2076              <parameter>ffp</parameter>
     2077            </methodparam>
     2078            <exceptionname>IOException</exceptionname>
     2079          </methodsynopsis>
     2080        </term>
     2081        <listitem>
     2082          <para>
     2083          This method is called from the <methodname>isImportable(InputStream)</methodname>
     2084          method, AFTER <methodname>FlatFileParser.nextSection()</methodname> and
     2085          <methodname>FlatFileParser.parseHeaders()</methodname> has been called
     2086          a single time and if the <methodname>parseHeaders</methodname> method didn't
     2087          stop on an unknown line. The default implementation of this method always returns
     2088          TRUE, since obviously some data has been found. A subclass may override this method
     2089          if it wants to do more checks, for example, make that a certain header is present
     2090          with a certain value. It may also continut parsing the file. Here is a code example from
     2091          the <classname>PrintMapFlatFileImporter</classname> which checks if a
     2092          <constant>FormatName</constant> header is present and contains either
     2093          <constant>TAM</constant> or <constant>MwBr</constant>.
     2094          </para>
     2095         
     2096          <programlisting>
     2097/**
     2098   Check that the file is a TAM or MwBr file.
     2099   @return TRUE if a FormatName header is present and contains "TAM" or "MwBr", FALSE
     2100      otherwise
     2101*/
     2102@Override
     2103protected boolean isImportable(FlatFileParser ffp)
     2104{
     2105   String formatName = ffp.getHeader("FormatName");
     2106   return formatName != null &amp;&amp;
     2107      (formatName.contains("TAM") || formatName.contains("MwBr"));
    20562108}
    20572109</programlisting>
  • trunk/src/plugins/core/net/sf/basedb/plugins/AbstractFlatFileImporter.java

    r3626 r3637  
    493493    FlatFileParser ffp = getInitializedFlatFileParser();
    494494    ffp.setInputStream(in, getCharset());
     495    ffp.setDefaultNumberFormat(getNumberFormat());
    495496    try
    496497    {
     498      ffp.nextSection();
    497499      FlatFileParser.LineType result = ffp.parseHeaders();
    498       return result != FlatFileParser.LineType.UNKNOWN;
     500      if (result == FlatFileParser.LineType.UNKNOWN)
     501      {
     502        return false;
     503      }
     504      else
     505      {
     506        return isImportable(ffp);
     507      }
    499508    }
    500509    catch (IOException ex)
     
    657666
    658667  /**
     668    This method is called by the {@link #isImportable(InputStream)} method after
     669    {@link FlatFileParser#nextSection()} and {@link FlatFileParser#parseHeaders()}
     670    has been called and if data has been found. Thus, the default implementation of this
     671    method always returns TRUE. Subclasses may override this method to do more checks, for
     672    example to make sure certain headers are present or parse more data from the file.
     673   
     674    @param ffp The FlatFileParser object used to parse the file
     675    @return Always TRUE
     676    @since 2.4
     677   */
     678  protected boolean isImportable(FlatFileParser ffp)
     679    throws IOException
     680  {
     681    return true;
     682  }
     683 
     684  /**
    659685    Called just before parsing of the file begins. A subclass
    660686    may override this method if it needs to initialise some
  • trunk/src/plugins/core/net/sf/basedb/plugins/IlluminaRawDataImporter.java

    r3626 r3637  
    321321  }
    322322
     323  /**
     324    Check that the first line contains the text "Illumina"
     325    @return TRUE if the first line contains "Illumina", FALSE
     326      otherwise
     327  */
     328  @Override
     329  protected boolean isImportable(FlatFileParser ffp)
     330  {
     331    String firstLine = ffp.getLineCount() >= 1 ? ffp.getLine(0).line() : null;
     332    return firstLine != null && firstLine.contains("Illumina") ;
     333  }
    323334 
    324335  @Override
  • trunk/src/plugins/core/net/sf/basedb/plugins/PrintMapFlatFileImporter.java

    r3628 r3637  
    275275    -------------------------------------------
    276276  */
     277  /**
     278    Check that the file is a TAM or MwBr file.
     279    @return TRUE if a FormatName header is present and contains "TAM" or "MwBr", FALSE
     280      otherwise
     281  */
     282  @Override
     283  protected boolean isImportable(FlatFileParser ffp)
     284  {
     285    String formatName = ffp.getHeader("FormatName");
     286    return formatName != null && (formatName.contains("TAM") || formatName.contains("MwBr"));
     287  }
    277288
    278289  /**
Note: See TracChangeset for help on using the changeset viewer.