5758 |
23 Sep 11 |
nicklas |
1 |
/** |
5758 |
23 Sep 11 |
nicklas |
$Id$ |
5758 |
23 Sep 11 |
nicklas |
3 |
|
5758 |
23 Sep 11 |
nicklas |
Copyright (C) 2011 Nicklas Nordborg |
5758 |
23 Sep 11 |
nicklas |
5 |
|
5758 |
23 Sep 11 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5758 |
23 Sep 11 |
nicklas |
Available at http://base.thep.lu.se/ |
5758 |
23 Sep 11 |
nicklas |
8 |
|
5758 |
23 Sep 11 |
nicklas |
BASE is free software; you can redistribute it and/or |
5758 |
23 Sep 11 |
nicklas |
modify it under the terms of the GNU General Public License |
5758 |
23 Sep 11 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5758 |
23 Sep 11 |
nicklas |
of the License, or (at your option) any later version. |
5758 |
23 Sep 11 |
nicklas |
13 |
|
5758 |
23 Sep 11 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5758 |
23 Sep 11 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5758 |
23 Sep 11 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5758 |
23 Sep 11 |
nicklas |
GNU General Public License for more details. |
5758 |
23 Sep 11 |
nicklas |
18 |
|
5758 |
23 Sep 11 |
nicklas |
You should have received a copy of the GNU General Public License |
5758 |
23 Sep 11 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5758 |
23 Sep 11 |
nicklas |
21 |
*/ |
5758 |
23 Sep 11 |
nicklas |
22 |
package net.sf.basedb.util.zip; |
5758 |
23 Sep 11 |
nicklas |
23 |
|
5758 |
23 Sep 11 |
nicklas |
24 |
import net.sf.basedb.core.File; |
5758 |
23 Sep 11 |
nicklas |
25 |
import net.sf.basedb.core.ItemSubtype; |
5758 |
23 Sep 11 |
nicklas |
26 |
|
5758 |
23 Sep 11 |
nicklas |
27 |
/** |
5758 |
23 Sep 11 |
nicklas |
28 |
|
5758 |
23 Sep 11 |
nicklas |
@author Nicklas |
5758 |
23 Sep 11 |
nicklas |
@since 3.0 |
5758 |
23 Sep 11 |
nicklas |
@base.modified $Date$ |
5758 |
23 Sep 11 |
nicklas |
32 |
*/ |
5758 |
23 Sep 11 |
nicklas |
33 |
public class PackUtil |
5758 |
23 Sep 11 |
nicklas |
34 |
{ |
5758 |
23 Sep 11 |
nicklas |
35 |
|
5758 |
23 Sep 11 |
nicklas |
36 |
/** |
5758 |
23 Sep 11 |
nicklas |
Copy certain properties from the archive file to the unpacked |
5758 |
23 Sep 11 |
nicklas |
file. Only properies that have been set on the archive |
5758 |
23 Sep 11 |
nicklas |
file are copied. |
5758 |
23 Sep 11 |
nicklas |
40 |
|
5758 |
23 Sep 11 |
nicklas |
<ul> |
5758 |
23 Sep 11 |
nicklas |
<li>Description |
5758 |
23 Sep 11 |
nicklas |
<li>Character set (only if the MIME type on the unpacked file start with 'text/') |
5758 |
23 Sep 11 |
nicklas |
<li>Item subtype |
5758 |
23 Sep 11 |
nicklas |
<li>Write protected flag |
5758 |
23 Sep 11 |
nicklas |
</ul> |
5758 |
23 Sep 11 |
nicklas |
47 |
|
5758 |
23 Sep 11 |
nicklas |
@param archive The master archive (or null if not known) |
5758 |
23 Sep 11 |
nicklas |
@param unpacked The file that is being unpacked |
5758 |
23 Sep 11 |
nicklas |
@since 3.0 |
5758 |
23 Sep 11 |
nicklas |
51 |
*/ |
5758 |
23 Sep 11 |
nicklas |
52 |
public static void copyProperties(File archive, File unpacked) |
5758 |
23 Sep 11 |
nicklas |
53 |
{ |
5758 |
23 Sep 11 |
nicklas |
54 |
if (archive == null) return; |
5758 |
23 Sep 11 |
nicklas |
55 |
|
5758 |
23 Sep 11 |
nicklas |
// Description |
5758 |
23 Sep 11 |
nicklas |
57 |
String description = archive.getDescription(); |
5758 |
23 Sep 11 |
nicklas |
58 |
if (description != null) unpacked.setDescription(description); |
5758 |
23 Sep 11 |
nicklas |
59 |
|
5758 |
23 Sep 11 |
nicklas |
// Character set |
5758 |
23 Sep 11 |
nicklas |
61 |
String characterSet = archive.getCharacterSet(); |
5758 |
23 Sep 11 |
nicklas |
62 |
String mimeType = unpacked.getMimeType(); |
5758 |
23 Sep 11 |
nicklas |
63 |
if (characterSet != null && mimeType != null && mimeType.startsWith("text/")) |
5758 |
23 Sep 11 |
nicklas |
64 |
{ |
5758 |
23 Sep 11 |
nicklas |
65 |
unpacked.setCharacterSet(archive.getCharacterSet()); |
5758 |
23 Sep 11 |
nicklas |
66 |
} |
5758 |
23 Sep 11 |
nicklas |
67 |
|
5758 |
23 Sep 11 |
nicklas |
// Subtype |
5758 |
23 Sep 11 |
nicklas |
69 |
try |
5758 |
23 Sep 11 |
nicklas |
70 |
{ |
5758 |
23 Sep 11 |
nicklas |
71 |
ItemSubtype subtype = archive.getItemSubtype(); |
5758 |
23 Sep 11 |
nicklas |
72 |
if (subtype != null) unpacked.setItemSubtype(subtype); |
5758 |
23 Sep 11 |
nicklas |
73 |
} |
5758 |
23 Sep 11 |
nicklas |
74 |
catch (Exception ex) |
5758 |
23 Sep 11 |
nicklas |
75 |
{} |
5758 |
23 Sep 11 |
nicklas |
76 |
|
5758 |
23 Sep 11 |
nicklas |
// Write protected |
5758 |
23 Sep 11 |
nicklas |
78 |
unpacked.setWriteProtected(archive.isWriteProtected()); |
5758 |
23 Sep 11 |
nicklas |
79 |
|
5758 |
23 Sep 11 |
nicklas |
80 |
} |
5758 |
23 Sep 11 |
nicklas |
81 |
|
5758 |
23 Sep 11 |
nicklas |
82 |
} |