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

📄 managejeffile.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
// $Id: ManageJefFile.java,v 1.3 2002/04/04 08:13:24 pmartin Exp $////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////              . . . i n   j a h i a   w e   t r u s t . . .//////  ManageServer////  12.06.2001  NK  added in jahia.//package org.jahia.admin.jeffiles;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import org.jahia.bin.*;import org.jahia.params.*;import org.jahia.utils.properties.*;import org.jahia.utils.*;import org.jahia.security.license.*;import org.jahia.services.sites.*;import org.jahia.services.jef.*;import org.jahia.services.webapps_deployer.*;import org.jahia.services.usermanager.*;import org.jahia.registries.*;import org.jahia.exceptions.*;/** * desc:  This class is used by the administration to manage the * server settings of a jahia portal, like the mail notification service (when * jahia or a user generate error(s), or like the java server home disk path, * mail server, etc. * * Copyright:    Copyright (c) 2002 * Company:      Jahia Ltd * * @author Khue Nguyen * @version 1.0 */public class ManageJefFile{    private static final String CLASS_NAME  =  "ManageJefFile";    private static final String JSP_PATH    =  JahiaAdministration.JSP_PATH;	private JahiaSite site;	private JahiaUser user;	private ServicesRegistry sReg;    private static JahiaSitesService  sMgr;	private LicenseKey mLicenseKey;    /**	 * Default constructor.	 * @author  Alexandre Kraft	 *	 * @param   request       Servlet request.     * @param   response      Servlet response.     * @param   session       Servlet session for the current user.	 */    public ManageJefFile(	HttpServletRequest    request,                        	HttpServletResponse   response,                         	HttpSession           session )    throws Throwable    {					    mLicenseKey = Jahia.getLicenseKey();	    if ( mLicenseKey == null ){	        // set request attributes...    	    request.setAttribute("jahiaDisplayMessage",  "Invalid License Key");        	// redirect...        	JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" );        	return;	    }        userRequestDispatcher( request, response, session );    } // end constructor    /**     * This method is used like a dispatcher for user requests.     * @author  Alexandre Kraft     *     * @param   request       Servlet request.     * @param   response      Servlet response.     * @param   session       Servlet session for the current user.     */    private void userRequestDispatcher( HttpServletRequest    request,                                        HttpServletResponse   response,                                        HttpSession           session )    throws Throwable    {        sReg = ServicesRegistry.getInstance();        if (sReg != null) {	        sMgr =  sReg.getJahiaSitesService();	    }		        // check if the user has really admin access to this site...        user =  (JahiaUser) session.getAttribute( ParamBean.SESSION_USER );         site =  (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE );				if ( user != null && sReg != null && sMgr != null){	        String operation =  request.getParameter("sub");		        if(operation.equals("catlist")) {	            displayCategoryList( request, response, session );	        } else if(operation.equals("unlockjec")) {	            decryptJec( request, response, session );	        }		} else {       	            request.setAttribute("jahiaDisplayMessage",             						"An error occured while processing your request");       		JahiaAdministration.doRedirect( request,        										response,        										session, JSP_PATH + "menu.jsp" );		}    } // userRequestDispatcher    //-------------------------------------------------------------------------    /**     * Display the list of encrypted files categories     *     * @author  NK     * @param   request         Servlet request.     * @param   response        Servlet response.     * @param   session         HttpSession object.     */    private void displayCategoryList( 	HttpServletRequest   request,                             			HttpServletResponse  response,                             			HttpSession          session )    throws IOException, ServletException    {		JahiaConsole.println(CLASS_NAME+".displayCategoryList","started");				try {			JahiaWebAppsDeployerService appDepServ = sReg.getJahiaWebAppsDeployerService();						if ( appDepServ == null ){		        throw new JahiaException(	"Unavailable Services",		                                	"Unavailable Services", 		                                	JahiaException.SERVICE_ERROR, 		                                	JahiaException.ERROR );			}			        JahiaAdministration.doRedirect( request, 	        								response, 	        								session, 	        								JSP_PATH + "manage_jeffile.jsp" );	    } catch ( JahiaException je ){            request.setAttribute("jahiaDisplayMessage",             						"An error occured while processing your request");			JahiaAdministration.doRedirect( request, 											response, 											session, 											JSP_PATH + "menu.jsp" );	    }    }    //-------------------------------------------------------------------------    /**     * Search Jahia Encrypted Components and decrypt them      *     * @author  NK     * @param   request         Servlet request.     * @param   response        Servlet response.     * @param   session         HttpSession object.     */    private void decryptJec( HttpServletRequest   request,                             HttpServletResponse  response,                             HttpSession          session )    throws IOException, ServletException    {		JahiaConsole.println(CLASS_NAME + ".decryptJec","started");				try {			JahiaWebAppsDeployerService appDepServ = sReg.getJahiaWebAppsDeployerService();						if ( appDepServ == null ){		        throw new JahiaException(	"Unavailable Services",		                                	"Unavailable Services", 		                                	JahiaException.SERVICE_ERROR, 		                                	JahiaException.ERROR );			}					Enumeration enum = null;	        try {	            enum = sMgr.getSites();	        } catch (JahiaException ex) {		        throw new JahiaException(	"Could not retrieve the list of sites",		                                	"Could not retrieve the list of sites", 		                                	JahiaException.SERVICE_ERROR, 		                                	JahiaException.ERROR );	        }						Hashtable cryptedComp = new Hashtable();			JahiaSite siteItem = null;			String siteLabel = "";									while ( enum.hasMoreElements() ){				siteItem = (JahiaSite)enum.nextElement();							    // get the new component disk path for te current site				String path = appDepServ.getNewWebAppsPath() 											+ File.separator 											+ siteItem.getSiteKey() ;									File folder = new File(path);				File[] files = new File[0];					if ( folder.isDirectory() ){					files = folder.listFiles();				}					int size = files.length;				File f = null;				JecFile jec = null;								// get license info				int jecLicenseType			= 0;				int jecLicenseTypeRelComp 	= 0;				siteLabel = "["+siteItem.getServerName()+"]";																// decrypt Jahia Encrypted Components				for ( int i=0 ; i<size ; i++ ){					f = files[i];					if ( f.isFile() && (f.getName().toLowerCase()).endsWith(".jec") ){							boolean tryAgain = true;						boolean goSleep = false;						int status = 0;						String fileName = siteLabel + f.getName();						try {														JahiaConsole.println(CLASS_NAME+"decryptJec","Found file " + f.getAbsolutePath());								jec = new JecFile(f.getAbsolutePath());							jecLicenseType = jec.getLicenseType();							jecLicenseTypeRelComp = jec.getLicenseTypeRelComp();									if ( mLicenseKey.compareLicense(jecLicenseType,										    		  		jecLicenseTypeRelComp) ){																										jec.extractFiles();								status = JefFileConstants.UNLOCKED;								f.delete();							} else {								status = JefFileConstants.LOCKED;							}														jec = null;						} catch ( JefFileKeyNotFoundException knf ){							status = JefFileConstants.INVALID_JEF_FILE;							JahiaConsole.println(CLASS_NAME+"decryptJec","Exception " + knf.getMessage() );							File tmpFile = new File(f.getAbsolutePath() + "_error");							f.renameTo(tmpFile);							} catch ( JefFileInvalidKeyValueException ikv ){							status = JefFileConstants.INVALID_JEF_FILE;							JahiaConsole.println(CLASS_NAME+"decryptJec","Exception " + ikv.getMessage() );							File tmpFile = new File(f.getAbsolutePath() + "_error");							f.renameTo(tmpFile);							} catch ( InvalidJefFileException ijf ){							status = JefFileConstants.INVALID_JEF_FILE;							JahiaConsole.println(CLASS_NAME+"decryptJec","Exception " + ijf.getMessage() );							File tmpFile = new File(f.getAbsolutePath() + "_error");							f.renameTo(tmpFile);							} catch ( IOException ioe ){							status = JefFileConstants.IO_ERROR;							JahiaConsole.println(CLASS_NAME+"decryptJec","IOException " + ioe.getMessage());							ioe.printStackTrace();						} catch ( JahiaException je ){							status = je.getErrorCode();							JahiaConsole.println(CLASS_NAME+"decryptJec","JahiaException " + je.getMessage());							je.printStackTrace();						} catch ( Throwable t ){							status = JefFileConstants.UNKNOWN_ERROR;							JahiaConsole.println(CLASS_NAME+"decryptJec","Exception " + t.getMessage());							t.printStackTrace();						}							cryptedComp.put(fileName,new Integer(status));					}				}			}				        request.setAttribute("cryptedComp", cryptedComp);	        JahiaAdministration.doRedirect( request, 	        								response, 	        								session, 	        								JSP_PATH + "manage_jec.jsp" );	    } catch ( JahiaException je ){            request.setAttribute("jahiaDisplayMessage",             						"An error occured while processing your request");			JahiaAdministration.doRedirect( request, 											response, 											session, 											JSP_PATH + "menu.jsp" );	    }    }}

⌨️ 快捷键说明

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