最近開發的一個文檔管理系統


最近在琢磨着開發一個文檔管理系統。 打算用之前配置的ssh的基本框架來搭建,配合剛學一點皮毛的extjs。首先看一下大致的界面效果

 

大致說明下程序的組織結構:

 

后端:采用spring+hibernate+struts2的框架設置,這個框架是之前開發別的系統中使用的,這里繼續沿用。在項目的具體的實現中其實只用了登錄,注冊這些基本的功能。關於框架的配置部分不再贅述。講一點自己的心得體會。在開發過程中,我喜歡將通用的東西,寫到單獨的包中,以便以后可以沿用。目前簡單的編寫了json,session,filter,interceptor,dao(基本的dao層),xml,util等層。感覺確實在項目移植中起到了很好的簡化作用。之后將舉其中一例說明。

前端:extjs框架,目前采用開發的方法大致是js+html,通常在我的html中,

<script type="text/javascript" src="./common/main.js"></script>
		<script type="text/javascript" src="./common/uploadfile.js"></script>
		<script type="text/javascript" src="./common/highsearch.js"></script>
		
		<script type="text/javascript">
		//document.execCommand("BackgroundImageCache", false, true) 
		var curpath;//全局變量
    	Ext.onReady(function(){
    		new Ext.clNameSpace.topBar({
    			renderTo:'topbar-div'
    		});
    		new Ext.clNameSpace.mainPanel({
    			renderTo:'main-div'
    		});		
         
    	});

  會這樣編寫,具體的panel繼承編寫,並在html中引用。調用Ext.onReady方法進行相應的呈現。 目前的缺點是,panel比較復雜,代碼量比較大,重用的代碼風格不是很好。 下面也會對其進行舉例介紹。

 

前面提到過,我將后端代碼可以重用的部分抽象出來,方便代碼重用,而這個可重用的類,統一放在comm的包里面。舉個例子, 在進行ssh開發的時候,我們通常對dao層會進行基本的抽象。

public interface IBaseDao<T> {

    public T getById(java.io.Serializable id);
    public List<T> getAll();
    public List<T> getByProperty(String property,Object value);
    public List<T> getByExample(T example);
    public void delete(T entity);
    public void update(T entity);
    public java.io.Serializable save(T entity);
    public T load(Class entityClass,java.io.Serializable id);
    public List<T> getAllWithCache();
    public List<T> getByPage(String hql,int beginIndex,int everyPage);
    
}

首先創建如上的泛型接口,之后創建相對應的BaseDao抽象類

public abstract class BaseDao<T> extends HibernateDaoSupport implements IBaseDao<T>{
    
    public List<T> getByPage(final String hql, final int beginIndex, final int everyPage) {
        // TODO Auto-generated method stub
        return super.getHibernateTemplate().executeFind(new HibernateCallback(){
            public Object doInHibernate(Session session) throws HibernateException,SQLException{
                Query query = session.createQuery(hql);
                query.setFirstResult(beginIndex);
                query.setMaxResults(everyPage);
                return query.list();
            }
        });
        
    }

具體的實現,我們不做過多介紹,這樣實現的好處是,在我們具體的業務層實現的時候,可以繼承這個BaseDao類,從而節省基本的增刪改查的編寫。提高一些效率。

同樣對於filter,比如我們的loginfilter,characterEncodingFilter等都可以抽象出來,對於不同的項目稍作修改即可滿足要求。而xml更是我們常用的功能了,這部分也要抽象出來。

上面是對自己框架的一些簡單介紹,剛工作不久,里面肯定存在很多問題。

 

下面這部分是我們業務核心文件的管理功能, 對於開發這樣的文件管理系統,不知道各位有什么真知灼見。我這里采用最簡單的方法。之前有對linux文件系統進行了解,但是因為時間有限。我只做了一小步來模擬文件系統。對於每個文件夾,我采用自己的一個單獨的文件進行目錄的管理,作為我的系統文件,名字是abcdeedcba.data ,在這個文件中,我們保存系統目錄和文件的屬性,方便以后的信息閱讀和檢索。而目錄和文件是不同的信息,我們用兩個類來實現

/**
 * 目錄信息
 * @author chilei 
 *
 */
public class DirectoryInfor implements Serializable{
    
    private String dirName;
    private String dirPath;

文件信息

/**
 * 文件信息
 * @author chilei
 *
 */
public class FileInfor implements Serializable{
    
    private String fileName;
    private String filePath;
    private String fileTitle;
    private String keywords;
    private String describe;
    private String filemaster;
    private int downloadtimes;
    private Date uploadtime;
    private String fileSize;
    private String fileType;
    private int version;
    private String versionDescribe;

對於上傳,下載這些操作,我用一個管理類來實現,這類簡單的采用了synchronized來做多線性的互斥。效率不高。有待改進,

*/
public class DirMgr {

    private static final String inforFileName = "abceddecba.data";
    private static final String rootPath = SysInfo.rootpath;

    /**
     * 初始化
     * 
     * @param path
     * @throws Exception
     */
    public static void dirInit(String path) throws Exception {
        DirectoryInfor result = new DirectoryInfor();

        File file = new File(path);
        String[] filea = path.split("\\" + File.separator);
        String tName = filea[filea.length - 1];
        // System.out.println(tName);
        File[] subFile = file.listFiles();
        List<DirectoryInfor> dirList = new ArrayList<DirectoryInfor>();
        List<FileInfor> fileList = new ArrayList<FileInfor>();
        if (subFile != null) {
            for (int i = 0; i < subFile.length; i++) {

                // 目錄or文件
                if (subFile[i].isDirectory()) {
                    // System.out.println(subFile[i]);
                    String[] tmpInfor = subFile[i].toString().split(
                            "\\" + File.separator);
                    DirectoryInfor tmp = new DirectoryInfor();
                    if (tmpInfor.length > 0) {
                        String dirName = tmpInfor[tmpInfor.length - 1];
                        tmp.setDirName(dirName);
                    }

                    tmp.setDirPath(subFile[i].toString());
                    dirList.add(tmp);

                } else {

                }
            }
            result.setDirList(dirList);
            result.setDirName(tName);
            result.setDirPath(path);
        }
        // 文件流
        FileOutputStream outstream = new FileOutputStream(path + File.separator
                + inforFileName);
        ObjectOutputStream out = new ObjectOutputStream(outstream);
        out.writeObject(result);
        out.close();

    }

    /**
     * 反序列化
     * 
     * @param path
     * @return
     * @throws Exception
     */
    public static synchronized DirectoryInfor dirDeserialize(String path)
            throws Exception {
        File abcde = new File(path + File.separator + inforFileName);
        if (!abcde.exists()) {
            dirInit(path);
        }
        FileInputStream instream = new FileInputStream(path + File.separator
                + inforFileName);
        ObjectInputStream in = new ObjectInputStream(instream);
        DirectoryInfor result = (DirectoryInfor) in.readObject();

        return result;
    }

    /**
     * 往已有的目錄中增加目錄
     * 
     * @param parentPath
     * @param dirName
     * @throws Exception
     */
    public synchronized static boolean addDir(String parentPath, String dirName)

沒有貼完整代碼,這樣實現的原因,我考慮一是可以比較方便的進行擴展,二是,我們要保存一些文件關鍵詞,下載次數等。 這些信息存放在數據庫中也不見得效率特別高。主要對於每個子目錄的文件個數應該也不是特別多。

之后我考慮的一個問題是如何進行文件的檢索,目前是分兩種情況,已經知道目錄,和未知道目錄,前一種只要在該目錄底下,分析abcdeedcba.data文件既可以找到我們的文件,而后一種需要從根目錄來檢索。這樣如果我們簡單的進行順序檢索,效率應當很低,知道我們應采用一種樹形結構來建立相關索引。目前考慮紅黑樹或者B樹,(這部分尚未開發,正在開發中)。

 

對於文件下載,之前做項目的時候,都是直接給出<href>的鏈接,感覺這樣不是特別好,而且經常容易出現文件直接打開的情況,還暴露自己的程序目錄,增加了系統的隱患。這次采用流的方式實現的。將文件內容轉換為inputStream這樣的流格式。有關這部分,請參照流文件下載。 感覺這樣仍然不是特別號,目前也正在考慮中。

 

最后還實現了預覽一部分文件的功能,用了flexpaper控件,這部分比較沒有技術含量,就是文件->pdf->swf文件三種格式之間的轉換。效果就是類似百度文庫的那樣的效果。

 

OK,簡單介紹了自己開發的系統,不知道各位是否有收獲。 

下一步考慮的事情: 全文檢索和 利用hadoop來進行分布式開發配置,   比如多人同時在線修改同一個文件等這樣的功能。

發此文的目的就是:不知道這樣的系統是否有一定的應用價值呢?是否有人願意一起同我把這系統做做?

                                                                  迷茫困惑

                                                                        化蛹成蝶

 

 

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM