📄 jahia.java
字号:
final static JahiaPrivateSettings getPrivateSettings() { return jSettings; } //------------------------------------------------------------------------- /** * Return the License Key * */ public static final LicenseKey getLicenseKey() { if ( mLicenseKey == null ){ return null; } return (LicenseKey)mLicenseKey.clone(); } /** * Return true if this class has been fully initiated * * @return boolean true if this class has been fully initaited */ public static final boolean isInitiated() { return mInitiated; } /** * Get the Jahia Lock. * Use this to force Jahia to ignore all requests except for those of the current session. * * * @param user the user must be a root admin * @param session the session * @return byte[] lock, the lock or null if the lock is not available. */ public static final synchronized byte[] getLock( JahiaUser user, HttpSession session ) throws JahiaException { if ( !isInitiated() ){ return null; } byte[] lock = null; Hashtable lockParams = JahiaLocksRegistry.getInstance().getLock (JAHIA_LOCK_NAME); if ( !user.isAdminMember(0) ){ // a super admin user throw new JahiaException( CLASS_NAME+".getLock", "No rigth to get the lock on Jahia", JahiaException.LOCK_ERROR, JahiaException.ERROR ); } if (lockParams == null) { lock = MakeLock (user, session); } else { if (JahiaLocksRegistry.getInstance().isLockValid (JAHIA_LOCK_NAME)) { // Check if the session is the one that locked Jahia. String sessionID = (String)lockParams.get(JAHIA_LOCK_SESSION_ID); if (sessionID.equals(session.getId())) { // reset the timeout time JahiaLocksRegistry.getInstance().resetLockTimeout(JAHIA_LOCK_NAME); lock = (byte[])lockParams.get(JAHIA_LOCK); } } else { // the lock has been timed out and is available. lock = MakeLock (user, session); } } session.setAttribute(JAHIA_LOCK_NAME,lock); return lock; } private static byte[] MakeLock (JahiaUser user, HttpSession session) throws JahiaSessionExpirationException { Hashtable lockParams = new Hashtable (); byte[] lock = new byte[1]; lockParams.put (JAHIA_LOCK_USER, user); lockParams.put (JAHIA_LOCK_SESSION_ID, session.getId()); lockParams.put (JAHIA_LOCK, lock); // create the lock in the registry. int timeout = session.getMaxInactiveInterval(); JahiaLocksRegistry.getInstance().setLock (JAHIA_LOCK_NAME, lockParams, timeout); return lock; } /** * To free the lock, you must give back the lock object stored in your session. * The JAHIA_LOCK attribute in session is set to null * * @param lock the original lock */ public static final synchronized boolean releaseLock( byte[] lock ){ if ( !isInitiated() ){ return false; } if ( lock == null ){ return false; } Hashtable lockParams = JahiaLocksRegistry.getInstance().getLock (JAHIA_LOCK_NAME); byte[] storedLock = (byte[])lockParams.get(JAHIA_LOCK); if ( lock == storedLock ){ JahiaLocksRegistry.getInstance().removeLock (JAHIA_LOCK_NAME); return true; } return false; } /** * Check if Jahia is authorized to process request from current session * * @return boolean false if no access allowed */ public static final synchronized boolean checkLockAccess( HttpSession session ) { if ( !isInitiated() ){ //JahiaConsole.println(CLASS_NAME+".checkLockAccess","Jahia is not initialized"); return false; } //JahiaConsole.println(CLASS_NAME+".checkLockAccess","Jahia is initialized"); Hashtable lockParams = JahiaLocksRegistry.getInstance().getLock (JAHIA_LOCK_NAME); if (lockParams == null) { //JahiaConsole.println(CLASS_NAME+".checkLockAccess","lock params in session is null"); return true; // Jahia is not locked } else { if (JahiaLocksRegistry.getInstance().isLockValid (JAHIA_LOCK_NAME)) { //JahiaConsole.println(CLASS_NAME+".checkLockAccess",JAHIA_LOCK_NAME + " lock is valid"); // Check if the session is the one that locked Jahia. String sessionID = (String)lockParams.get(JAHIA_LOCK_SESSION_ID); if (sessionID.equals(session.getId())) { // reset the timeout time JahiaLocksRegistry.getInstance().resetLockTimeout(JAHIA_LOCK_NAME); return true; } } else { //JahiaConsole.println(CLASS_NAME+".checkLockAccess",JAHIA_LOCK_NAME + " lock no more valid"); return true; // no more lock } } return false; } /** * Check if the current JDK we are running Jahia on is supported. The * supported JDK string is a specially encoded String that checks only * the versions. * * The accepted format is the following : * version <= x <= version * or * version < x < version * The "x" character is mandatory ! * * @param currentJDKVersion the current JDK version we are using, this is * a valid version object. * @param supportedJDKString * @return */ private boolean isSupportedJDKVersion( Version currentJDKVersion, String supportedJDKString ) { if (supportedJDKString == null) { // we deactivate the check if we specify no supported JDKs return true; } String workString = supportedJDKString.toLowerCase(); int xPos = workString.indexOf("x"); if (xPos == -1) { JahiaConsole.println("Jahia.isSupportedJDKVersion", "Invalid supported_jdk_versions initialization " + " parameter in web.xml, it MUST be in the " + " following format : 1.2 < x <= 1.3 (the 'x' " + "character is mandatory and was missing in " + "this case : [" + supportedJDKString + "] )"); return false; } String leftArg = workString.substring(0, xPos).trim(); String rightArg = workString.substring(xPos + 1).trim(); if (leftArg.endsWith("<=")) { String leftVersionStr = leftArg.substring(0, leftArg.length() - 2).trim(); Version lowerVersion = null; try { lowerVersion = new Version(leftVersionStr); } catch (NumberFormatException nfe) { JahiaConsole.printe("Jahia.isSupportedJDKVersion", nfe); return false; } if (lowerVersion.compareTo(currentJDKVersion) > 0) { return false; } } else if (leftArg.endsWith("<")) { String leftVersionStr = leftArg.substring(0, leftArg.length() - 1).trim(); Version lowerVersion = null; try { lowerVersion = new Version(leftVersionStr); } catch (NumberFormatException nfe) { JahiaConsole.printe("Jahia.isSupportedJDKVersion", nfe); return false; } if (lowerVersion.compareTo(currentJDKVersion) >= 0) { return false; } } else { JahiaConsole.println("Jahia.isSupportedJDKVersion", "Invalid supported_jdk_versions initialization " + " parameter in web.xml, it MUST be in the " + " following format : 1.2 < x <= 1.3. Current string : [" + supportedJDKString + "] )"); return false; } if (rightArg.startsWith("<=")) { String rightVersionStr = rightArg.substring(2).trim(); Version upperVersion = null; try { upperVersion = new Version(rightVersionStr); } catch (NumberFormatException nfe) { JahiaConsole.printe("Jahia.isSupportedJDKVersion", nfe); return false; } if (upperVersion.compareTo(currentJDKVersion) < 0) { return false; } } else if (rightArg.startsWith("<")) { String rightVersionStr = rightArg.substring(1).trim(); Version upperVersion = null; try { upperVersion = new Version(rightVersionStr); } catch (NumberFormatException nfe) { JahiaConsole.printe("Jahia.isSupportedJDKVersion", nfe); return false; } if (upperVersion.compareTo(currentJDKVersion) <= 0) { return false; } } else { JahiaConsole.println("Jahia.isSupportedJDKVersion", "Invalid supported_jdk_versions initialization " + " parameter in web.xml, it MUST be in the " + " following format : 1.2 < x <= 1.3. Current string : [" + supportedJDKString + "] )"); return false; } return true; } final public static ParamBean getThreadParamBean () { return (ParamBean) paramBeanThreadLocal.get(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -