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

📄 filemanager_engine.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            engineMap.put( "fmMsg", "An error occured while processing file download" );            engineMap.put( "jspSource", RELOADPAGE_JSP );        }        JahiaField theField = (JahiaField)engineMap.get("theField");        if (theField != null) {            engineMap.put( "fieldID", new Integer(theField.getID()) );        } else {            // JahiaConsole.println("Filemanager_Engine.handleActions", "Couldn't retrieve field named <theField> from engineMap !");        }        if ( displayScreen ){            // sets engineMap for JSPs            jParams.getRequest().setAttribute( "engineTitle", "Filemanager" );            jParams.getRequest().setAttribute( "org.jahia.engines.EngineHashMap", engineMap );            // displays the screen            toolBox.displayScreen( jParams, engineMap );        }    } // end handleActions    /**     * handle file upload     *     */    protected void handleFileUpload( ParamBean jParams ,                                     HashMap engineMap ) throws JahiaException {        FileUpload fupload = null;        if ( jParams.isMultipartRequest(jParams.getRequest()) ){            try {                fupload = ServicesRegistry.getInstance().getJahiaFilemanagerService().getFileUploadHandler(jParams.getContext(),jParams.getRequest());            } catch ( ServletException sex ) {                String errorMsg = "Error handling Multipart request : " + sex.getMessage() + " -> BAILING OUT";                JahiaConsole.println( "Filemanager_Engine.handleFileUpload", errorMsg );                throw new JahiaException(   "Error handling Multipart request",                                         errorMsg, JahiaException.SERVICE_ERROR, JahiaException.ERROR );            } catch ( IOException ioe ) {                String errorMsg = "Error handling Multipart request : " + ioe.getMessage() + " -> BAILING OUT";                JahiaConsole.println( "Filemanager_Engine.handleFileUpload", errorMsg );                throw new JahiaException(   "Error handling Multipart request",                                         errorMsg, JahiaException.SERVICE_ERROR, JahiaException.ERROR );            }            // Yes, it's a file upload -> specify the FileUpload Object            //jParams.specifyRequestObj (fupload);        }        String subAction =  fupload.getParameter(SUB_ACTION);        if ( subAction == null ){            // display file upload form            engineMap.put( "jspSource", FILEUPLOAD_JSP );        } else if ( subAction.equals("save") ){            // handle save file upload            // get the active Folder            String idStr = fupload.getParameter("active_folder_id");            int folderID = 0;            if ( idStr != null ){                folderID = Integer.parseInt(idStr);            } else {                String errorMsg = "Fail initializing active Folder : ";                JahiaConsole.println( "Filemanager_Engine.handleFileUpload", errorMsg + " -> BAILING OUT" );                throw new JahiaException( errorMsg, errorMsg, JahiaException.SERVICE_ERROR,                                    JahiaException.ERROR );            }            Folder activeFolder = ServicesRegistry.getInstance().getJahiaFilemanagerService().getFolder(folderID);            if ( activeFolder == null ) {                String errorMsg = "Fail initializing active Folder : ";                JahiaConsole.println( "Filemanager_Engine.handleFileUpload", errorMsg + " -> BAILING OUT" );                throw new JahiaException( errorMsg, errorMsg, JahiaException.SERVICE_ERROR,                                    JahiaException.ERROR );            }            // get is public parameter            String strVal = fupload.getParameter("is_public");            if ( strVal == null ){                strVal = "0";            }            int isPublic = Integer.parseInt(strVal);            // get file title            String fileTitle = fupload.getParameter("file_title");            if ( strVal == null ){                fileTitle = "";            }            // get upload user            String uploadUser = jParams.getUser().getName();            int fileID = -1;            try {                fileID = ServicesRegistry.getInstance().getJahiaFilemanagerService().handleFileUpload( jParams,                                                                                                  fupload,                                                                                                  activeFolder.getFolderID(),                                                                                                  fileTitle,                                                                                                  uploadUser,                                                                                                  isPublic	);                engineMap.put( "jspSource", CLOSE_JSP );            } catch ( Throwable e ){                engineMap.put( "fmMsg", "error occured with fileupload" );                engineMap.put( "jspSource", ERROR_JSP );            }            // active Folder            strVal = fupload.getParameter("active_folder_id");            Integer activeFolderID = new Integer(strVal);            engineMap.put( "activeFolderID", activeFolderID);            engineMap.put( "fileID", new Integer(fileID) );        }        Vector datas = new Vector();        datas.add(ACTION_FILE_UPLOAD);        datas.add(null);        engineMap.put( "filemanagerUrl", Filemanager_Engine.getInstance().renderLink( jParams, datas ) );    }    /**     * handle file download     *     */    protected boolean handleFileDownload( ParamBean jParams ,                                       HashMap engineMap ) throws JahiaException {        boolean success = false;        String strVal = jParams.getRequest().getParameter("fid");        if ( strVal != null ){			int fieldID = Integer.parseInt(strVal);			JahiaField field = ServicesRegistry.getInstance().getJahiaFieldService().loadField(fieldID,jParams);			if ( field.checkReadAccess(jParams.getUser(),jParams.getSiteID()) ){				JahiaFileField fileField = ServicesRegistry.getInstance().getJahiaFilemanagerService(). getJahiaFileField(fieldID);				if ( fileField != null ){		            // get the file field associated with this file		            if ( !ServicesRegistry.getInstance().getJahiaFilemanagerService().handleFileDownload(jParams.getRequest(),		                                                                                                 jParams.getRealResponse(),		                                                                                                 fileField.getFileID()) ){		                engineMap.put( "fmMsg", "An error occured while processing file download" );		                engineMap.put( "jspSource", RELOADPAGE_JSP );		                success = false;		         	}				}			}         	return true;        }        return success;    }    /**     * handle file delete     *     */    protected boolean handleFileDelete( ParamBean jParams ,                                       HashMap engineMap ) throws JahiaException {        boolean success = true;        //System.out.println("handleFileDelete started");        String strVal = jParams.getRequest().getParameter(FORM_FILE_ITEM);        if ( strVal != null ){            int fileID = Integer.parseInt(strVal);            JahiaFile f = ServicesRegistry.getInstance().getJahiaFilemanagerService().getFileDB(fileID);            if ( f == null ){                engineMap.put( "fmMsg", "File not found" );                engineMap.put( "jspSource", ERROR_JSP );            } else {                // Check rights                boolean canDelete = jParams.getUser().isAdminMember(jParams.getJahiaID());                if ( !canDelete ){                    canDelete = (f.getUploadUser().equals(jParams.getUser().getName()));                }                if ( !canDelete ){                    throw new JahiaException(	CLASS_NAME+".handleFileDelete",                                            "User has no right to delete the file",                                            JahiaException.SECURITY_ERROR,                                            JahiaException.ERROR);                }                String subAction = jParams.getRequest().getParameter(SUB_ACTION);                if ( subAction == null ){                    //System.out.println(" subaction not found");                    engineMap.put( "fmMsg", "Comfirm you want to delete the file" );                    engineMap.put( "fileItem", f );                    engineMap.put( "jspSource", FILEDELETE_JSP );                } else if ( subAction.equals("delete") ){                    //System.out.println(" subaction is delete");                    if ( !ServicesRegistry.getInstance().getJahiaFilemanagerService().deleteFileDB(fileID) ){                        engineMap.put( "fmMsg", "An error occured while deleting the file" );                        engineMap.put( "jspSource", ERROR_JSP );                        success = false;                    } else {                        // delete from disk                        ServicesRegistry.getInstance().getJahiaFilemanagerService().deleteFile(f);                        // actually, redisplay the file upload form, but in future display the filemanager                        engineMap.put( "jspSource", CLOSE_JSP );                    }                }            }        } else {            success = false;        }        Vector datas = new Vector();        datas.add("actionFileDelete");        datas.add(null);        engineMap.put( "filemanagerUrl", renderLink( jParams, datas ) );        //engineMap.put( "fileID", new Integer(-1) );        return success;    }    /***     * inits the engine map     *     * @param        jParams             a ParamBean object     *                                   (with request and response)     * @return       a HashMap object containing all the basic values     *               needed by an engine     *     */    private HashMap initEngineMap( ParamBean jParams )        throws  JahiaException,                JahiaSessionExpirationException    {        //JahiaConsole.println ("FileManager_Engine.initEngineMap","started");        String theScreen = jParams.getRequest().getParameter( "screen" );        // gets session values        //HttpSession theSession = jParams.getRequest().getSession( true );        HttpSession theSession = jParams.getSession ();        HashMap engineMap = null;        if (theScreen == null) {            theScreen = "edit";            engineMap = (HashMap) theSession.getAttribute( "jahia_session_engineMap" );        }        if ( engineMap == null ){            engineMap = new HashMap();        }        // init engine map        engineMap.put( "jParams", jParams );        engineMap.put( "renderType", new Integer(JahiaEngine.RENDERTYPE_FORWARD) );        engineMap.put( "engineName", engineName );        theSession.setAttribute( "jahia_session_engineMap", engineMap );        // init map        engineMap.put( "screen", theScreen );        return engineMap;    } // end initEngineMap} // end Filemanager_Engine

⌨️ 快捷键说明

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