📄 containerschangeeventlistener.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////////// 28.05.2002 NK Creationpackage org.jahia.data.containers;import java.util.*;import java.util.Date;import java.util.TimeZone;import java.util.Calendar;import org.jahia.utils.*; // JahiaConsoleimport org.jahia.exceptions.*; // Jahia Exceptionsimport org.jahia.data.events.*; // EventObjectimport org.jahia.data.containers.*; // JahiaContainersimport org.jahia.services.usermanager.*; // JahiaUser/** * Listener for containers and container list change events. * Created for container search caching purpose. * You must access this Singleton through JahiaListenersRegistry * * @see JahiaListenersRegistry * @author Khue Nguyen <a href="mailto:khue@jahia.org">khue@jahia.org</a> */public class ContainersChangeEventListener extends JahiaEventListener{ private static final String CLASS_NAME = ContainersChangeEventListener.class.getName(); private static Hashtable ctnListsLastChanges = new Hashtable(); private static Hashtable containersLastChanges = new Hashtable(); //-------------------------------------------------------------------------- /** * triggered when Jahia adds a container * * @param je the associated JahiaEvent */ public void containerAdded( JahiaEvent je ) { JahiaConsole.println("ContainersChangeEventListener.containerAdded","Started"); JahiaContainer theObject = (JahiaContainer) je.getObject(); notifyChange(theObject); } //-------------------------------------------------------------------------- /** * triggered when Jahia updates a container * * @param je the associated JahiaEvent */ public void containerUpdated( JahiaEvent je ) { JahiaConsole.println("ContainersChangeEventListener.containerUpdated","Started"); JahiaContainer theObject = (JahiaContainer) je.getObject(); notifyChange(theObject); } //-------------------------------------------------------------------------- /** * triggered when Jahia adds a container * * @param je the associated JahiaEvent */ public void containerDeleted( JahiaEvent je ) { JahiaConsole.println("ContainersChangeEventListener.containerAdded","Started"); JahiaContainer theObject = (JahiaContainer) je.getObject(); notifyChange(theObject); } //-------------------------------------------------------------------------- /** * set the last modifying time for the given container, the container list containing the container is updated too. * * @param JahiaContainer the container. */ public void notifyChange( JahiaContainer theContainer ) { if ( theContainer == null ){ return; } // Set search time TimeZone tz = TimeZone.getTimeZone("UTC"); Calendar cal = Calendar.getInstance(tz); Date nowDate = cal.getTime(); long now = nowDate.getTime(); containersLastChanges.put(new Integer(theContainer.getID()),new Long(now)); ctnListsLastChanges.put(new Integer(theContainer.getListID()),new Long(now)); } //-------------------------------------------------------------------------- /** * Returns the last modifying time for the given container list. * * @param int ctnListID, the container list id. * @return long time, the last change time. -1 if information not available. */ public static long getCtnListLastChangeTime( int ctnListID ) { Long L = (Long)ctnListsLastChanges.get(new Integer(ctnListID)); if ( L == null ){ return -1; } try { return L.longValue(); } catch ( Throwable t ){ } return -1; } //-------------------------------------------------------------------------- /** * Returns the last modifying time for the given container. * * @param int ctnID, the container id. * @return long time, the last change time. -1 if information not available. */ public static long getContainerLastChangeTime( int ctnID ) { Long L = (Long)containersLastChanges.get(new Integer(ctnID)); if ( L == null ){ return -1; } try { return L.longValue(); } catch ( Throwable t ){ } return -1; }} // end ContainersChangeEventListener
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -