KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > contineo > core > transfer > ZipImport


1 package org.contineo.core.transfer;
2
3 import java.io.File JavaDoc;
4
5 import org.apache.log4j.Level;
6 import org.apache.log4j.Logger;
7 import org.contineo.admin.Menu;
8 import org.contineo.core.FileBean;
9 import org.contineo.core.LoggingManager;
10 import org.contineo.core.ZipBean;
11 import org.contineo.core.config.SettingConfigurator;
12 import org.contineo.documan.CheckinDocUtil;
13
14 /**
15  * Created on 16.12.2004
16  * @author micha
17  */

18 public class ZipImport {
19     
20     private SettingConfigurator settings;
21     private String JavaDoc username;
22     private Logger logger;
23
24     public ZipImport() {
25         settings = new SettingConfigurator();
26         username = "";
27         logger = LoggingManager.getLogger(this.getClass());
28     }
29     
30     public void process(String JavaDoc zipsource, Menu parent, String JavaDoc user) {
31         username = user;
32         String JavaDoc userpath = settings.getValue("userdir");
33         if (!userpath.endsWith(File.pathSeparator))
34             userpath += "/";
35         userpath += username + "/unzip";
36         if (FileBean.exists(userpath))
37             FileBean.deleteDir(userpath);
38         FileBean.createDir(userpath);
39         ZipBean.unzip(zipsource, userpath);
40         File JavaDoc file = new File JavaDoc(userpath);
41         File JavaDoc[] files = file.listFiles();
42         for (int i=0; i<files.length; i++)
43             addEntry(files[i], parent);
44         FileBean.deleteDir(userpath);
45     }
46     
47     /** Stores a file in the repository of contineo and inserts some information
48      * in the database of contineo (menu, document, version, history, searchdocument).
49      * @param file
50      * @param parent
51      */

52     protected void addEntry(File JavaDoc file, Menu parent) {
53         try {
54             String JavaDoc menuName = file.getName();
55             if (file.isDirectory()) { // creates a contineo folder
56
Menu menu = CheckinDocUtil.createFolder(parent, menuName);
57                 File JavaDoc files[] = file.listFiles();
58                 for (int i=0; i<files.length; i++)
59                     addEntry(files[i], menu);
60             } else { //creates a contineo document
61
CheckinDocUtil.createDocument(file, parent, username);
62             }
63         } catch (Exception JavaDoc e) {
64             if (logger.isEnabledFor(Level.ERROR))
65                 logger.error(e.getMessage());
66         }
67     }
68 }
Popular Tags