Package org.olat.core.gui

Source Code of org.olat.core.gui.GUIInterna$ThreadLocalData

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* This software is protected by the OLAT software license.<br>
* Use is subject to license terms.<br>
* See LICENSE.TXT in this distribution for details.
* <p>
* Copyright (c) 1999-2006 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.<br>
* All rights reserved.
* <p>
*/
package org.olat.core.gui;

import java.util.HashMap;
import java.util.Map;

import org.olat.core.helpers.Settings;
import org.olat.core.id.Identity;


/**
* Description:<br>
* TODO: Felix Jost Class Description for Trans
*
* <P>
* Initial Date: 23.11.2006 <br>
* @author Felix Jost, http://www.goodsolutions.ch
*/
public class GUIInterna {
 
  private static final String REPLAY_URL = "replayURLs";
  private static ThreadLocalData tld = new ThreadLocalData();
 
  public static boolean isLoadPerformanceMode() {
    // FIXME:fj:b refactor to a better place when using osgi / module startup concept
    //return VelocityModule.isReusableURLs(); 
    //
    boolean tmp = tld != null ? tld.isResuableUrlsOn() : false;
    return tmp;
  }
 
  @SuppressWarnings("unchecked")
  public static Map getReplayModeData(){
    return tld.getReplayModeData();
  }
 
  @SuppressWarnings("unchecked")
  public static void setReplayModeData(Map m){
    tld.setReplayModeData(m);
  }
 
  public static void setLoadPerformanceMode(UserRequest ureq){
    if(ureq == null){
      //clear thread local data
      tld.set(null);
      return;
    }
    Boolean usessReplayUrls = (Boolean)ureq.getUserSession().getEntry(REPLAY_URL);
    //param not found in the session
    if(usessReplayUrls == null){
      Identity changeableIdentity = ureq.getIdentity();
      if(changeableIdentity != null){
        //only hit the Database if an identity is found!
        //see also OLAT-2790
        usessReplayUrls = (Boolean) ureq.getUserSession().getGuiPreferences().get(WindowManager.class, REPLAY_URL);
      } else {
        tld.setReplayModeData(null);
      }
      if(usessReplayUrls == null){
        //is null if not found
        //or it is a User request without identity
        usessReplayUrls = Boolean.FALSE;
      }
      ureq.getUserSession().putEntry(REPLAY_URL, usessReplayUrls);

     
    }
    tld.setResuableUrlsMode(usessReplayUrls.booleanValue());
  }
 
  protected static class ThreadLocalData extends ThreadLocal<Boolean> {
    /**
     * @see java.lang.ThreadLocal#initialValue()
     */
    public Boolean initialValue() {
      return null;
    }

    /**
     * @param ureq
     */
    public void setResuableUrlsMode(boolean ruMode) {
      Boolean isOn = (Settings.isReusableURLs() || ruMode) ? Boolean.TRUE:Boolean.FALSE;
      super.set(isOn);
    }

    /**
     * @return
     */
    public boolean isResuableUrlsOn() {
      //Boolean is null if the thread does not have access to the info if the user
      //has replayable URL'S on
      Boolean isOn = super.get();
      return isOn != null ? isOn.booleanValue() : false;
    }
   
   
    private Map<Object,Object> replayModeData; 
   
    public Map<Object,Object>  getReplayModeData () {
      if (replayModeData == null) replayModeData = new HashMap<Object, Object>();
      return replayModeData;
    }
   
    public void setReplayModeData (Map <Object,Object> m) {
      replayModeData = m;
    }
  }
}
TOP

Related Classes of org.olat.core.gui.GUIInterna$ThreadLocalData

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.