src/core/net/sf/basedb/util/zip/PackUtil.java

Code
Comments
Other
Rev Date Author Line
5758 23 Sep 11 nicklas 1 /**
5758 23 Sep 11 nicklas 2   $Id$
5758 23 Sep 11 nicklas 3
5758 23 Sep 11 nicklas 4   Copyright (C) 2011 Nicklas Nordborg
5758 23 Sep 11 nicklas 5
5758 23 Sep 11 nicklas 6   This file is part of BASE - BioArray Software Environment.
5758 23 Sep 11 nicklas 7   Available at http://base.thep.lu.se/
5758 23 Sep 11 nicklas 8
5758 23 Sep 11 nicklas 9   BASE is free software; you can redistribute it and/or
5758 23 Sep 11 nicklas 10   modify it under the terms of the GNU General Public License
5758 23 Sep 11 nicklas 11   as published by the Free Software Foundation; either version 3
5758 23 Sep 11 nicklas 12   of the License, or (at your option) any later version.
5758 23 Sep 11 nicklas 13
5758 23 Sep 11 nicklas 14   BASE is distributed in the hope that it will be useful,
5758 23 Sep 11 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
5758 23 Sep 11 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5758 23 Sep 11 nicklas 17   GNU General Public License for more details.
5758 23 Sep 11 nicklas 18
5758 23 Sep 11 nicklas 19   You should have received a copy of the GNU General Public License
5758 23 Sep 11 nicklas 20   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 29   @author Nicklas
5758 23 Sep 11 nicklas 30   @since 3.0
5758 23 Sep 11 nicklas 31   @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 37     Copy certain properties from the archive file to the unpacked
5758 23 Sep 11 nicklas 38     file. Only properies that have been set on the archive
5758 23 Sep 11 nicklas 39     file are copied.
5758 23 Sep 11 nicklas 40     
5758 23 Sep 11 nicklas 41     <ul>
5758 23 Sep 11 nicklas 42     <li>Description
5758 23 Sep 11 nicklas 43     <li>Character set (only if the MIME type on the unpacked file start with 'text/')
5758 23 Sep 11 nicklas 44     <li>Item subtype
5758 23 Sep 11 nicklas 45     <li>Write protected flag
5758 23 Sep 11 nicklas 46     </ul>
5758 23 Sep 11 nicklas 47     
5758 23 Sep 11 nicklas 48     @param archive The master archive (or null if not known)
5758 23 Sep 11 nicklas 49     @param unpacked The file that is being unpacked
5758 23 Sep 11 nicklas 50     @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 56     // 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 60     // 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 68     // 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 77     // 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 }