⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jahiafilemanagerbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            debugQuery(query);            stmt.execute(query);            success = true;        }        catch (SQLException ex) {            processSQLException("JahiaFilemanagerBaseService::updateFileField()",ex);            success = false;        }        finally        {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( stmt != null ) stmt.close();            } catch ( SQLException ex ) {                processSQLException("JahiaFilemanagerBaseService::updateFileField() freeing connection fails",ex);            }        }        return success;    }    /**     * Copy a file for a cloned page     *     * @param the Jahia File Field ID     * @param the cloned page ID     * @return true if no error     */    public boolean copyFileField(int oldJahiaFileFieldID, int newFieldID, int pageID) throws JahiaException    {        // Get the JahiaFile        Connection dbConn = null;        Statement stmt = null;        ResultSet rs = null;        boolean success = false;        JahiaFile aFile = null;        String fileFieldTitle = "";        try {            // get a connection to the db            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(1);            // execute the query            StringBuffer buff = new StringBuffer(1024);            buff.append(" select * from jahia_file_fields where fieldid_jahia_filefield=");            buff.append(oldJahiaFileFieldID);            //buff.append(" and fileid_jahia_filefield=id_jahia_file");            stmt = dbConn.createStatement();            debugQuery(buff.toString());            rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt,buff.toString());            while ( rs.next() )            {                int fileID = rs.getInt("fileid_jahia_filefield");                fileFieldTitle = rs.getString("title_jahia_filefield");                System.out.println("fileId: "+fileID+" title: "+fileFieldTitle);                try {                    ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                    if ( stmt != null ) stmt.close();                } catch ( SQLException ex ) {                    processSQLException("JahiaFilemanagerBaseService::  copyFileField freeing connection fails",ex);                    success = false;                }                aFile = getFileDB(fileID);            }        }        catch (SQLException ex) {            processSQLException("JahiaFilemanagerBaseService::copyFileField",ex);            success = false;        }        finally        {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( stmt != null ) stmt.close();            } catch ( SQLException ex ) {                processSQLException("JahiaFilemanagerBaseService::  copyFileField freeing connection fails",ex);            }        }        if (aFile != null)        {        // Get the File        Filemanager fmng = getFilemanager(aFile.getFilemanagerID());        String storageName = "";        if ( fmng != null ){            StringBuffer buff = new StringBuffer(getFileRepositoryRootPath());            buff.append(File.separator);            buff.append(fmng.getStoragePath());            buff.append(File.separator);            buff.append(aFile.getStorageName());            File  f = new File(buff.toString());            // Create the cloned JahiaFile            storageName = "FILE" + JahiaKeyGen.getKey(10) + aFile.getRealName();            String fullFilePath = getFileRepositoryRootPath() + File.separator + fmng.getStoragePath() + File.separator + storageName;            toConsole(" New StoragePath = " + fullFilePath);            File clonedFile = new File(fullFilePath);            // Copy file on disk            boolean flg = copyFile(f,clonedFile);        }         JahiaFile theClonedFile = new	JahiaFile(                               aFile.getFilemanagerID(),                               aFile.getFolderID(),                               aFile.getUploadUser(),                               aFile.getRealName(),                               storageName,                               aFile.getLastModifDate(),                               aFile.getSize(),                               aFile.getType(),                               aFile.getTitle(),                               aFile.getDescr()                               );        theClonedFile.setPageID(pageID);        theClonedFile.setPublic(aFile.getPublic());        toConsole(" file name :" + aFile.getRealName() + ",size=" + aFile.getSize() + ",lastModified=" + aFile.getLastModifDate() + ",type=" + aFile.getType() );        // Insert file in DB        int fID = insertFileDB (theClonedFile);        // insert data in jahiaFileField        System.out.println(" title: "+fileFieldTitle);        JahiaFileField fField = new JahiaFileField( 	newFieldID,                                                    -1, // filemanager id                                                    -1, // folder id                                                    "", // upload user                                                    "", // realname                                                    "",	// storage name                                                    0,	// modif date                                                    0,	// size                                                    "",	// type                                                    fileFieldTitle,	// title                                                    ""	); // descr        fField.setFileID(fID);        fField.setFileFieldTitle(fileFieldTitle);        boolean flag = insertJahiaFileField(fField);        success = true;        } // end if        return success;    }   //--------------------------------------------------------------------------   //   //   // DOM Representation Section   //   //   //--------------------------------------------------------------------------    //--------------------------------------------------------------------------    /**     * returns a DOM representation of the filemanager of a site     *     * @param int siteID     * @auhtor NK     */    public JahiaDOMObject getFileMgrAsDOM( int siteID )    throws JahiaException{        return FilemanagerDB.getInstance().getFileMgrAsDOM (siteID);    }    //--------------------------------------------------------------------------    /**     * returns a DOM representation of the filemanager folders of a site     *     * @param int siteID     * @auhtor NK     */    public JahiaDOMObject getFileMgrFoldersAsDOM( int siteID )    throws JahiaException{        return FolderDB.getInstance().getFileMgrFoldersAsDOM (siteID);    }    //--------------------------------------------------------------------------    /**     * returns a DOM representation of the filemanager files of a site     *     * @param int siteID     * @auhtor NK     */    public JahiaDOMObject getFileMgrFilesAsDOM( int siteID )    throws JahiaException{        return FilemanagerDB.getInstance().getFileMgrFilesAsDOM (siteID);    }    //--------------------------------------------------------------------------    /**     * return a DOM document of the Filemanager file fields of a site     *     * @param int the site id     *     * @return JahiaDOMObject a DOM representation of this object     *     * @author NK     */    public JahiaDOMObject getFileMgrFileFieldsAsDOM( int siteID )    throws JahiaException{        Connection dbConn = null;        Statement statement = null;        String output = null;        JahiaDBDOMObject dom = null;        try {            String sqlQuery = "SELECT DISTINCT jahia_file_fields.fieldid_jahia_filefield,"            +"jahia_file_fields.fileid_jahia_filefield,jahia_file_fields.title_jahia_filefield"            +" FROM jahia_file_fields,jahia_fields_data WHERE jahia_file_fields.fieldid_jahia_filefield="            +"jahia_fields_data.id_jahia_fields_data AND jahia_fields_data.jahiaid_jahia_fields_data="+siteID;            dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(1);            statement = dbConn.createStatement();            if (statement != null) {                ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery );                if (rs != null) {                    dom = new JahiaDBDOMObject();                    dom.addTable("jahia_file_fields",rs);                    return dom;                }            }        } catch (SQLException se) {            String errorMsg = "Error in getFileMgrFileFieldsAsDOM(int siteID) : " + se.getMessage();            JahiaConsole.println( "JahiaFilemanagerDB", errorMsg );            throw new JahiaException(   "Cannot load filemanager file fields from the database",                                        errorMsg, JahiaException.DATABASE_ERROR,                                        JahiaException.CRITICAL );        } finally {            try {                ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn);                if ( statement != null ) statement.close();            } catch ( SQLException ex ) {                processSQLException("JahiaFilemanagerBaseService::getFileMgrFileFieldsAsDOM error freeing connection fails",ex);            }        }        return dom;    }    //--------------------------------------------------------------------------    /**     * Return a mime type looking at full file name     *     * @param String the file name     * @return String the mime type or "" if not found     */    private String getMimeTypeFromFilename (String filename){        if ( (m_MimeTypes == null)                || (filename == null)                || (filename.lastIndexOf(".") == -1) )            return "";        String mimeType = "";        String ext = filename.substring( filename.lastIndexOf(".") + 1,                                                 filename.length());        return	getMimeTypeFromExt(ext);    }    //--------------------------------------------------------------------------    /**     * Return a mime type looking at the file extension without "."     *     * @param String the extension     * @return String the mime type or "" if not found     */    private String getMimeTypeFromExt (String extension){        if ( (m_MimeTypes == null)                || (extension == null) )            return "";        String mimeType = "";        JahiaConsole.println(CLASS_NAME+".getMimeTypeFromExt","extension=" + extension);        mimeType = m_MimeTypes.getProperty(extension.toLowerCase());        if ( mimeType == null )            mimeType = "";        return mimeType;    }    /**     * Method filter     * Filter special caracters like ',"     *     * @param input String to filter     * @return a filtered string     */    protected static String filter(String input) {        StringBuffer filtered = new StringBuffer ( input.length() );        char c;        for ( int i=0 ; i<input.length(); i++ )        {            c = input.charAt(i);            if ( c == '\'' ) {                 filtered.append( "&#39;" );            } else if ( c== '"' ) {                 filtered.append( "&#34;" );            } else {                 filtered.append(c);            }        }        return (filtered.toString());    }    /**     * Method toConsole     * For debuggin purpose     * Write any msg to the console     *     * @param msg the message to display     */     protected void toConsole(String msg){        if (false){            //System.out.println(msg);        }     }    /**     * Method debugQuery     * Outout the query for debug purpose     *     * @param query     */    protected static void debugQuery(String query) {        if ( m_DebugQuery ) {            JahiaConsole.println("JahiaFilemanagerBaseService",query);        }    }    /**     * Method processSQLException     * For debug purpose     *     * @param func the name of the calling method     * @param the SQLException     */    protected void processSQLException (String func, SQLException ex) {        if ( m_DebugQuery ){            while (ex != null) {                JahiaConsole.println("JahiaFilemanagerBaseService","SQL EXCEPTION in function [" + func + "]: SqlState = " + ex.getSQLState() + "   Error code = " + ex.getErrorCode() + "   Error msg

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -