Changeset 3643


Ignore:
Timestamp:
Aug 8, 2007, 2:32:47 PM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #451: Zipped download

Added user and plug-in developer documentation

Location:
trunk
Files:
7 edited

Legend:

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

    r3637 r3643  
    36023602        BASE distribution comes with support for ZIP files
    36033603        (<classname>net.sf.basedb.plugins.ZipFileUnpacker</classname>)
    3604         and TAR files (<classname>net.sf.basedb.plugins.ZipFileUnpacker</classname>).
     3604        and TAR files (<classname>net.sf.basedb.plugins.TarFileUnpacker</classname>).
    36053605      </para>
    36063606      <para>
     
    37983798     
    37993799    </sect2>
     3800   
     3801    <sect2 id="plugin_developer.other.packer">
     3802      <title>File packer plug-ins</title>
     3803   
     3804      <para>
     3805        BASE has support for compressing and downloading a set of selected files and/or
     3806        directories. This functionality is provided by a plug-in, the
     3807        <classname>PackedFileExporter</classname>. This plug-in doesn't do the actual
     3808        packing itself. This is delegated to classes implementing the
     3809        <interfacename>net.sf.basedb.util.zip.FilePacker</interfacename> interface.
     3810      </para>
     3811     
     3812      <para>
     3813        BASE ships with a number of packing methods, including ZIP and TAR. To
     3814        add support for other methods you have to provide an implementation
     3815        of the <interfacename>FilePacker</interfacename>
     3816        interface. Then, create a new configuration for the <classname>PackerFileExporter</classname>
     3817        and enter the name of your class in the configuration wizard.
     3818      </para>
     3819     
     3820      <para>
     3821        The <interfacename>FilePacker</interfacename> interface is not a regular
     3822        plug-in interface (ie. it is not a subinterface to
     3823        <interfacename>Plugin</interfacename>). This means that you don't have to
     3824        mess with configuration or job parameters. Another difference is that your
     3825        class must be installed in Tomcat's classpath (ie. in one of the
     3826        <filename>WEB-INF/classes</filename> or <filename>WEB-INF/lib</filename>
     3827        folders).
     3828      </para>
     3829     
     3830      <variablelist>
     3831        <title>Methods in the <interfacename>FilePacker</interfacename> interface</title>
     3832        <varlistentry>
     3833          <term>
     3834            <methodsynopsis language="java">
     3835              <modifier>public</modifier>
     3836              <type>String</type>
     3837              <methodname>getDescription</methodname>
     3838            </methodsynopsis>
     3839          </term>
     3840          <listitem>
     3841            <para>
     3842            Return a short description the file format that is suitable for use
     3843            in dropdown lists in client applications. For example:
     3844            <constant>Zip-archive (.zip)</constant> or <constant>TAR-archive (.tar)</constant>.
     3845            </para>
     3846          </listitem>
     3847        </varlistentry>
     3848        <varlistentry>
     3849          <term>
     3850            <methodsynopsis language="java">
     3851              <modifier>public</modifier>
     3852              <type>String</type>
     3853              <methodname>getFileExtension</methodname>
     3854            </methodsynopsis>
     3855          </term>
     3856          <listitem>
     3857            <para>
     3858            Return the default file extension of the packed format. The returned
     3859            value should not include the dot. For example:
     3860            <constant>zip</constant> or <constant>tar</constant>.
     3861            </para>
     3862          </listitem>
     3863        </varlistentry>
     3864        <varlistentry>
     3865          <term>
     3866            <methodsynopsis language="java">
     3867              <modifier>public</modifier>
     3868              <type>String</type>
     3869              <methodname>getMimeType</methodname>
     3870            </methodsynopsis>
     3871          </term>
     3872          <listitem>
     3873            <para>
     3874            Return the standard MIME type of the packed file format.
     3875            For example:
     3876            <constant>application/zip</constant> or <constant>application/x-tar</constant>.
     3877            </para>
     3878          </listitem>
     3879        </varlistentry>
     3880        <varlistentry>
     3881          <term>
     3882            <methodsynopsis language="java">
     3883              <modifier>public</modifier>
     3884              <void />
     3885              <methodname>setOutputStream</methodname>
     3886              <methodparam>
     3887                <type>OutputStream</type>
     3888                <parameter>out</parameter>
     3889              </methodparam>
     3890              <exceptionname>IOException</exceptionname>
     3891            </methodsynopsis>
     3892          </term>
     3893          <listitem>
     3894            <para>
     3895            Sets the outputstream that the packer should write the packed
     3896            files to.
     3897            </para>
     3898          </listitem>
     3899        </varlistentry>
     3900        <varlistentry>
     3901          <term>
     3902            <methodsynopsis language="java">
     3903              <modifier>public</modifier>
     3904              <void />
     3905              <methodname>pack</methodname>
     3906              <methodparam>
     3907                <type>String</type>
     3908                <parameter>entryName</parameter>
     3909              </methodparam>
     3910              <methodparam>
     3911                <type>InputStream</type>
     3912                <parameter>in</parameter>
     3913              </methodparam>
     3914              <methodparam>
     3915                <type>long</type>
     3916                <parameter>size</parameter>
     3917              </methodparam>
     3918              <methodparam>
     3919                <type>long</type>
     3920                <parameter>lastModified</parameter>
     3921              </methodparam>
     3922              <exceptionname>IOException</exceptionname>
     3923            </methodsynopsis>
     3924          </term>
     3925          <listitem>
     3926            <para>
     3927            Add another file or directory to the packed file. The
     3928            <parameter>entryName</parameter> is the name of the new entry, including
     3929            path information. The <parameter>in</parameter> is the stream to read
     3930            the file data from. If <parameter>in</parameter> is <constant>null</constant>
     3931            then the entry denotes a directory. The <parameter>size</parameter> parameter
     3932            gives the size in bytes of the file (zero for empty files or directories).
     3933            The <parameter>lastModified</parameter>
     3934            is that time the file was last modified or 0 if not known.
     3935            </para>
     3936          </listitem>
     3937        </varlistentry>
     3938        <varlistentry>
     3939          <term>
     3940            <methodsynopsis language="java">
     3941              <modifier>public</modifier>
     3942              <void />
     3943              <methodname>close</methodname>
     3944              <exceptionname>IOException</exceptionname>
     3945            </methodsynopsis>
     3946          </term>
     3947          <listitem>
     3948            <para>
     3949            Finish the packing. The packer should release any resources, flush
     3950            all data. It should not close the <varname>out</varname> stream
     3951            set in the <methodname>setOutputStream</methodname> method since
     3952            this is done by the calling code.
     3953            </para>
     3954          </listitem>
     3955        </varlistentry>
     3956       
     3957      </variablelist>
     3958     
     3959    </sect2>
    38003960  </sect1>
    38013961 
  • trunk/doc/src/docbook/userdoc/file_system.xml

    r3563 r3643  
    685685        </para>
    686686      </sect3>
     687      <sect3 id="file_system.handling.actions.zippeddownload">
     688        <title>Download/compress multiple files</title>
     689       
     690        <para>
     691        You can download multiple files/directories at the same time. First,
     692        from the file browser, select one or more files/directories. Then, click
     693        on the &gbExport; button. Select the <userinput>Packed file exporter</userinput>
     694        plug-in and choose one of the file formats below it. On the &gbNext;
     695        page you can specify other options for the download:
     696        </para>
     697       
     698        <itemizedlist>
     699        <listitem>
     700          <para>
     701            <guilabel>Save as</guilabel>: The path to a file on the BASE file system
     702            where the selected files and directories should be packed. Leave this
     703            field empty to download the files to your own computer.
     704          </para>
     705        </listitem>
     706        <listitem>
     707          <para>
     708            <guilabel>Overwrite</guilabel>: If you are saving to the BASE file system
     709            you may select if it is allowed to overwrite an existing file or not.
     710          </para>
     711        </listitem>
     712        <listitem>
     713          <para>
     714            <guilabel>Remove files/directories</guilabel>: If you select this option
     715            the selected files and directories will be marked as removed. You must still
     716            go to the <guilabel>Trashcan</guilabel> and remove the items permanently.
     717          </para>
     718        </listitem>
     719        </itemizedlist>
     720       
     721      </sect3>
    687722    </sect2>
    688723    <sect2 id="file_system.handling.directories">
  • trunk/src/core/net/sf/basedb/util/zip/Bzip2FilePacker.java

    r3641 r3643  
    5656  */
    5757  /**
    58     @return "BZipped Tar-archive (.tar.bz2)"
     58    @return "BZipped TAR-archive (.tar.bz2)"
    5959  */
    6060  public String getDescription()
    6161  {
    62     return "BZipped Tar-archive (.tar.bz2)";
     62    return "BZipped TAR-archive (.tar.bz2)";
    6363  }
    6464  /**
  • trunk/src/core/net/sf/basedb/util/zip/FilePacker.java

    r3641 r3643  
    7575    Compress the uncompressed input stream to an entry with the given
    7676    name into the outputstream.
    77     @param entryName The name of the packed resource
     77    @param entryName The name of the packed resource, including path
     78      information
    7879      @param in The input stream to read uncompressed data from, or null
    7980        if the entry represents a directory
  • trunk/src/core/net/sf/basedb/util/zip/GzipFilePacker.java

    r3641 r3643  
    5454  */
    5555  /**
    56     @return "GZipped Tar-archive (.tar.gz)"
     56    @return "GZipped TAR-archive (.tar.gz)"
    5757  */
    5858  public String getDescription()
    5959  {
    60     return "GZipped Tar-archive (.tar.gz)";
     60    return "GZipped TAR-archive (.tar.gz)";
    6161  }
    6262  /**
  • trunk/src/core/net/sf/basedb/util/zip/TarFilePacker.java

    r3641 r3643  
    5757  */
    5858  /**
    59     @return "Tar-archive (.tar)"
     59    @return "TAR-archive (.tar)"
    6060  */
    6161  public String getDescription()
    6262  {
    63     return "Tar-archive (.tar)";
     63    return "TAR-archive (.tar)";
    6464  }
    6565  /**
  • trunk/src/plugins/core/net/sf/basedb/plugins/PackedFileExporter.java

    r3641 r3643  
    2626
    2727import net.sf.basedb.core.BaseException;
     28import net.sf.basedb.core.BasicItem;
    2829import net.sf.basedb.core.BooleanParameterType;
    2930import net.sf.basedb.core.DbControl;
     
    269270        // Verify that all selected files and directories are children to the root directory
    270271        Directory root = (Directory)request.getParameterValue("root");
    271         for (Nameable item : selectedFilesAndDirs)
    272         {
    273           Directory dir = null;
    274           if (item.getType() == Item.FILE)
     272        DbControl dc = sc.newDbControl();
     273        try
     274        {
     275          for (Nameable item : selectedFilesAndDirs)
    275276          {
    276             dir = ((File)item).getDirectory();
     277            dc.reattachItem((BasicItem)item);
     278            Directory dir = null;
     279            if (item.getType() == Item.FILE)
     280            {
     281              dir = ((File)item).getDirectory();
     282            }
     283            else
     284            {
     285              dir = ((Directory)item).getParent();
     286            }
     287            if (!root.equals(dir))
     288            {
     289              response.setError(item.getType().toString() + " is not located in root directory: " + root.getPath().toString(), null);
     290              return;
     291            }
    277292          }
    278           else
    279           {
    280             dir = ((Directory)item).getParent();
    281           }
    282           if (!root.equals(dir))
    283           {
    284             response.setError(item.getType().toString() + " is not located in root directory: " + root.getPath().toString(), null);
    285             return;
    286           }
     293        }
     294        finally
     295        {
     296          if (dc != null) dc.close();
    287297        }
    288298       
Note: See TracChangeset for help on using the changeset viewer.