mcardle     2005/08/18 17:54:19 CEST

  Added files:
    core/src/java/org/jahia/aop EsiJspContentDetectionAspect.java 
  Log:
  updates for ESI support
  
  Revision  Changes    Path
  1.1       +894 -0    
jahia/core/src/java/org/jahia/aop/EsiJspContentDetectionAspect.java (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/aop/EsiJspContentDetectionAspect.java?rev=1.1&content-type=text/plain
  
  
  
  Index: EsiJspContentDetectionAspect.java
  ====================================================================
  package org.jahia.aop;
  
  import org.codehaus.aspectwerkz.joinpoint.*;
  import org.jahia.registries.ServicesRegistry;
  import org.jahia.services.esi.JesiObject;
  import org.jahia.services.esi.Fragment;
  import java.util.EmptyStackException;
  import org.jahia.data.containers.JahiaContainerList;
  import org.jahia.services.esi.Template;
  import org.jahia.data.beans.ContainerListBean;
  import org.jahia.data.containers.JahiaContainer;
  import org.jahia.data.beans.ContainerBean;
  import org.jahia.data.beans.FieldBean;
  import org.jahia.data.fields.JahiaField;
  import org.jahia.services.pages.JahiaPage;
  import org.jahia.data.beans.PageBean;
  
  //import org.codehaus.aspectwerkz.joinpoint.MemberSignature;
  
  /** Aspect to capture content object accesses in JSPs and Tags. Used for ESI 
cache Invalidation purposes.
   *
   * */
  public class EsiJspContentDetectionAspect {
  
      //private static org.apache.log4j.Logger logger =
      //    org.apache.log4j.Logger.getLogger(MarcAspectWerkz.class);
  
      private int indent = -1;
  
      private static boolean debug = true;
  
      /**
       *  Aspect which detects access to a ContainerList (usually from JSP 
pages or tags)
       * and adds its ID to the closest enclosing ESI object (e.g. Fragment or 
Template)
        * @param joinPoint
       * @throws Throwable
       */
      public void addContainerList (JoinPoint joinPoint)
         throws Throwable {
          Object obj = joinPoint.getCallee();
          if (obj instanceof FieldBean)
             addContent(joinPoint, (ContainerListBean)obj, 
"ContainerListBean","addContainerList");
          else if (obj instanceof JahiaField)
              addContent(joinPoint, (JahiaContainerList)obj, 
"JahiaContainerList","addContainerList");
      }
      /**
        *  Aspect which detects access to a Container (usually from JSP pages 
or tags)
        * and adds its ID to the closest enclosing ESI object (e.g. Fragment or 
Template)
         * @param joinPoint
        * @throws Throwable
        */
  
      public void addContainer (JoinPoint joinPoint)
           throws Throwable {
            Object obj = joinPoint.getCallee();
            if (obj instanceof FieldBean)
               addContent(joinPoint, (ContainerBean)obj, 
"ContainerBean","addContainer");
            else if (obj instanceof JahiaField)
                addContent(joinPoint, (JahiaContainer)obj, 
"JahiaContainer","addContainer");
        }
      /**
        *  Aspect which detects access to a Field (usually from JSP pages or 
tags)
        * and adds its ID to the closest enclosing ESI object (e.g. Fragment or 
Template)
         * @param joinPoint
        * @throws Throwable
        */
      public void addField (JoinPoint joinPoint)
      throws Throwable {
       Object obj = joinPoint.getCallee();
       if (obj instanceof FieldBean)
          addContent(joinPoint, (FieldBean)obj, "FieldBean","addField");
       else if (obj instanceof JahiaField)
           addContent(joinPoint, (JahiaField)obj, "JahiaField","addField");
   }
      /**
        *  Aspect which detects access to a Page (usually from JSP pages or 
tags)
        * and adds its ID to the closest enclosing ESI object (e.g. Fragment or 
Template)
         * @param joinPoint
        * @throws Throwable
        */
  
      public void addPage (JoinPoint joinPoint)
          throws Throwable {
           Object obj = joinPoint.getCallee();
           if (obj instanceof PageBean)
              addContent(joinPoint, (PageBean)obj, "PageBean","addPage");
           else if (obj instanceof JahiaPage)
               addContent(joinPoint, (JahiaPage)obj, "JahiaPage","addPage");
       }
  
      /**
        *  Aspect which detects a method which returns a Container (usually 
called from JSP pages or tags)
        * and adds its ID to the closest enclosing ESI object (e.g. Fragment or 
Template)
         * @param joinPoint
       *   @param returnValue returned Container
        * @throws Throwable
        */
      public void addContainerSET (JoinPoint joinPoint, 
org.jahia.data.containers.JahiaContainer returnValue)
          throws Throwable {
                      addContent(joinPoint, returnValue, 
"JahiaContainer","addContainerSET");
       }
  
          /**
        *  Aspect which detects a method which returns a ContainerList (usually 
called from JSP pages or tags)
        * and adds its ID to the closest enclosing ESI object (e.g. Fragment or 
Template)
         * @param joinPoint
       *   @param returnValue returned ContainerList
        * @throws Throwable
        */
      public void addContainerListSET (JoinPoint joinPoint, 
org.jahia.data.containers.JahiaContainerList returnValue)
         throws Throwable {
              addContent(joinPoint, returnValue, 
"JahiaContainerList","addContainerListSET");
      }
  
      /**
       * adds the detected object's ID to the closest enclosing ESI object 
(e.g. Fragment or Template)
       *
       * @param joinPoint
       * @param aspObj  joinPoint.getCalleeClass() content Object
       * @param ObjType type
       * @param aspectName name of the aspect method called, for debug purposes 
only
       * @throws Throwable
       */
      public static void addContent (final JoinPoint joinPoint, Object aspObj, 
final String ObjType , final String aspectName)
          throws Throwable {
          if (debug) {
              MemberSignature signature = (MemberSignature) 
joinPoint.getSignature();
  
              System.err.println(
                      "!!!!!!!!!!!!!!!!!!!!!!!!!! -------\n "+aspectName+" 
aspect: "
                              + joinPoint.getCalleeClass().getName() + "::"
                              + signature.getName() + "\n" + 
joinPoint.toString());
              System.err.println("-------\n aspObj: "+ aspObj);
          }
  
          //Check to see if we are inside an Template/Fragment object, if not 
exit
          JesiObject jesiObj = null;
          try {
              jesiObj = (JesiObject) 
ServicesRegistry.getInstance().getEsiService().tagStackPeek();
          } catch(EmptyStackException ex) {
              System.err.println("     QUITTING 
EsiJspContentDetectionAspect."+aspectName+"() as OUTSIDE FRAGMENT OR TEMPLATE");
              return;
          }
  
          if (debug) {
              //System.err.println(aspectName+"[" + 
this.getClass().getClassLoader().hashCode() + "] ");
              //System.err.println(aspectName+" this[" + this + "] ");
  
              MethodRtti mrtti = (MethodRtti) joinPoint.getRtti();
              System.err.println(" MethodRtti  
Method:"+mrtti.getMethod().toString());
              //    +" Return type:"+mrtti.getReturnType() );
              Object[] parameters = mrtti.getParameterValues();
              for (int i = 0, j = parameters.length; i < j; i++) {
                  System.err.println("                param "+i+" 
Name:"+parameters[i]);
              }
          }
          String contentType = null;
          int objID = -1;
  
          if (aspObj instanceof PageBean) {
              objID = ((PageBean) aspObj).getID();
              jesiObj.addPage(objID);
              contentType = "PageBean";
          }
          else if (aspObj instanceof JahiaPage) {
              objID = ((JahiaPage) aspObj).getID();
              jesiObj.addPage(objID );
              contentType = "JahiaPage";
          }
          else if (aspObj instanceof JahiaField) {
              objID = ((JahiaField) aspObj).getID();
              jesiObj.addField(objID );
              contentType = "JahiaField";
          }
          else if (aspObj instanceof FieldBean) {
              objID =((FieldBean) aspObj).getID();
              jesiObj.addField( objID );
              contentType = "FieldBean";
          }
          else if (aspObj instanceof JahiaContainer) {
              objID =((JahiaContainer) aspObj).getID();
              jesiObj.addContainer(objID);
              contentType = "JahiaContainer";
              int ctnListID = ((JahiaContainer) aspObj).getListID();
              addParentContainerList(ctnListID, jesiObj, aspectName, 
contentType, objID);
          }
          else if (aspObj instanceof ContainerBean) {
              objID =((ContainerBean) aspObj).getID();
              jesiObj.addContainer(objID);
              contentType = "ContainerBean";
              int ctnListID = ((ContainerBean) aspObj).getContainerListID();
              addParentContainerList(ctnListID, jesiObj, aspectName, 
contentType, objID);
          }
          else if (aspObj instanceof JahiaContainerList) {
              objID =((JahiaContainerList) aspObj).getID();
              jesiObj.addContainerList(objID);
              contentType = "JahiaContainerList";
              int ctnID = ((JahiaContainerList) aspObj).getParentEntryID();
              addParentContainer(ctnID, jesiObj, aspectName, contentType, 
objID);
          }
          else if (aspObj instanceof ContainerListBean) {
              objID =((ContainerListBean) aspObj).getID();
              jesiObj.addContainerList(objID);
              contentType = "ContainerListBean";
              int ctnID = ((ContainerListBean) aspObj).getParentContainerID();
              addParentContainer(ctnID, jesiObj, aspectName, contentType, 
objID);
          }
          else  System.err.println("  " + aspectName + ":  Not a recognized 
object type : " + aspObj);
  
          if (debug) System.err.println("           " + aspectName + ":  added 
" + contentType + " " +
                  " ID[" +objID + "]"
                  + " to " + jesiObj.getObjDetails());
  
      }
  
      /**
       *  Add the parent ContainerList (if it exists) of any detected Container 
to the same enclosing ESI object.
       * Since if it changes then the odds are all its containers (including 
the one we are adding) will also
       * change. Get it?
       *
       * @param parentCtnListID the parent ContainerList of the Container
       * @param jesiObj joinPoint.getCalleeClass() content Object
       * @param aspectName name of the aspect method called, for debug purposes 
only
       * @param contentType name of the content object, for debug purposes only
       * @param ctnID the Container
       */
      private static void addParentContainerList(int parentCtnListID, 
JesiObject jesiObj, final String aspectName,
                                                 final String contentType, 
final int ctnID) {
  
          if (parentCtnListID > 0) {  // make sure the parent object is not the 
page, or some temp object with negative ID
              jesiObj.addContainerList(parentCtnListID);
                       if (debug) System.err.println("           
"+aspectName+":  added Parent ContainerList ID[" + parentCtnListID + "] for "
                               +contentType + " ID[" + ctnID + "]" + " to 
"+jesiObj.getObjDetails());
          } else if (debug) System.err.println(" Could not get Parent 
ContentContainerList for ContentContainer ID[" + ctnID + "]");
      }
  
       /**
       *  Add the parent Container (if it exists) of any detected ContainerList 
to the same enclosing ESI object.
       * Since if it changes then the odds are all its contents will also 
(including the ContainerList we are adding)
       * change. Get it?
       *
       * @param parentCtnID the parent Container of the ContainerList
       * @param jesiObj joinPoint.getCalleeClass() content Object
       * @param aspectName name of the aspect method called, for debug purposes 
only
       * @param contentType name of the content object, for debug purposes only
       * @param ctnListID the ContainerList
       */
      private static void addParentContainer(int parentCtnID, JesiObject 
jesiObj, final String aspectName,
                                             final String contentType, final 
int ctnListID) {
          //Add the parent Container also (if any), as if it changes, then the 
odds are all its contents will also
  
          if (parentCtnID > 0) {  // make sure the parent object is not the 
page, or some temp object with negative ID
              jesiObj.addContainer(parentCtnID);
              if (debug) System.err.println("           " + aspectName + ":  
added Parent Container ID[" + parentCtnID + "] for "
                      + contentType + " ID[" + ctnListID + "]" + " to " + 
jesiObj.getObjDetails());
  
          } else if (debug) System.err.println(" Could not get Parent 
JahiaContainer for JahiaContainerList ID[" + ctnListID + "]");
      }
  
  
  
  
  
  
      /** a method for pretty formatting */
      private void log(String message) {
          for (int i = 0; i < indent; i++) {
              System.err.print(" ");
          }
          //System.err.print("DemoAspect[" + 
this.getClass().getClassLoader().hashCode() + "] ");
          System.err.println("DemoAspect this[" + this + "] ");
          System.err.println(message);
      }
  
      /** An around advice is just a method with this JoinPoint parameter */
      public Object trace(JoinPoint jp) throws Throwable {
          indent++;
          log("--> " + jp.toString());
          System.err.print("DemoAspect jp.getCaller[" + jp.getCaller() + "] ");
          Object result = jp.proceed(); // will call the next advice or target 
method, field access, constructor etc
                  MemberSignature signature = 
(MemberSignature)jp.getSignature();
          /*System.err.println("ENTER: " + jp.getTargetClass().getName() + "::" 
+ signature.getName());
  
                  System.out.println(
                  "--> "
                  + jp.getCalleeClass().getName()
                  + "::"
                  + signature.getName()
          );
                  System.out.println(
                  "--> "
                  + signature.getDeclaringType().getName()
                  + "::"
                  + signature.getName()
          );*/
          MethodRtti mrtti = (MethodRtti) jp.getRtti();
          System.err.println(" MethodRtti  
Method:"+mrtti.getMethod().toString());
          //    +" Return type:"+mrtti.getReturnType() );
          Object[] parameters = mrtti.getParameterValues();
          for (int i = 0, j = parameters.length; i < j; i++) {
              System.err.println("                param "+i+" 
Name:"+parameters[i]);
          }
  
          log("<--");
          indent--;
          return result;
      }
      //*******************************************************************
  
  
  
      /*
          public void addContainerList (JoinPoint joinPoint)
              throws Throwable {
  
              if (debug) {
              MemberSignature signature = (MemberSignature) 
joinPoint.getSignature();
  
              System.err.println(
                  "-------\n addContainerList aspect: AFTER() : "
                  + joinPoint.getCalleeClass().getName()
                  + "::"
                  + signature.getName()
                  + "\n"
                  + joinPoint.toString()    );
              }
              JesiObject obj = null;
              try {
                  obj = (JesiObject) 
ServicesRegistry.getInstance().getEsiService().tagStackPeek();
              } catch(EmptyStackException ex) {
                  System.err.println("     QUITTING 
EsiJspContentDetectionAspect.addContainerList() as OUTSIDE FRAGMENT OR 
TEMPLATE");
                  return;
              }
  
      //        System.err.println("addContainerList[" + 
this.getClass().getClassLoader().hashCode() + "] ");
      //        System.err.println("addContainerList this[" + this + "] ");
  
              MethodRtti mrtti = (MethodRtti) joinPoint.getRtti();
              System.err.println(" MethodRtti  
Method:"+mrtti.getMethod().toString());
              //    +" Return type:"+mrtti.getReturnType() );
              Object[] parameters = mrtti.getParameterValues();
              for (int i = 0, j = parameters.length; i < j; i++) {
                  System.err.println("                param "+i+" 
Name:"+parameters[i]);
              }
  
              if (obj instanceof Fragment) {
                  //Fragment fr = (Fragment) obj;
                  //following might not be necessary, but do it anyway
                  Fragment frg = 
ServicesRegistry.getInstance().getEsiService().getFragment(
                      ((Fragment)obj).fragID);
  
                    if (joinPoint.getCallee() instanceof JahiaContainerList ) {
                        JahiaContainerList ctnlist = (JahiaContainerList) 
(joinPoint.getCallee());
                        frg.addContainerList(ctnlist.getID(), 
ctnlist.getPageID());
                        if (debug) System.err.println("           COMONNNN   
JahiaContainerList:  added ContainerList " +
                                           ctnlist.getID()
                                           + " [" + 
ctnlist.getDefinition().getName() + "]"
                                           + " to Fragment " + frg.fragID + " 
on pageID: " +
                                           frg.pageID);
                    }
                    else if (joinPoint.getCallee() instanceof ContainerListBean 
) {
                        ContainerListBean ctnlistbean = (ContainerListBean) 
(joinPoint.getCallee());
                            frg.addContainerList(ctnlistbean.getId(), 
ctnlistbean.getPageID());
                            if (debug) System.err.println("           COMONNNN  
ContainerListBEAN:   added ContainerList " +
                                               ctnlistbean.getId()+ " [" + 
ctnlistbean.getTitle() + "]"
                                               + " to Fragment " + frg.fragID + 
" on pageID: " +
                                               frg.pageID);
                    }
              }
              else if (obj instanceof Template) {
                  //Temaplate tpl = (Template) obj;
                  //following might not be necessary, but do it anyway
                  Template tpl = 
ServicesRegistry.getInstance().getEsiService().getTemplate(
                      ((Template)obj).pageID);
                   //System.err.println("     
joinPoint.getCalleeClass().getID() "+joinPoint.getCalleeClass().getID());
                   if (joinPoint.getCallee() instanceof JahiaContainerList ) {
                       JahiaContainerList ctnlist = (JahiaContainerList) 
(joinPoint.getCallee());
                       
tpl.addContainerList(ctnlist.getID(),ctnlist.getPageID());
                       if (debug) System.err.println("           HOURRRAYYY     
added ContainerList "+ctnlist.getID()
                                          + " [" + 
ctnlist.getDefinition().getName() + "]"
                                      +" to Template on pageID: "+tpl.pageID);
                                 }
                   else if (joinPoint.getCallee() instanceof ContainerListBean 
) {
                        ContainerListBean ctnlistbean = (ContainerListBean) 
(joinPoint.getCallee());
                        tpl.addContainerList(ctnlistbean.getId(), 
ctnlistbean.getPageID());
                        if (debug) System.err.println("           HOURRRAYYY  
ContainerListBEAN:   added ContainerList " +
                                             ctnlistbean.getId()+ " [" + 
ctnlistbean.getTitle() + "]"
                                            +" to Template on pageID: 
"+tpl.pageID);
                    }
              }
              else System.err.println("HOUSTON!!!!!!!!!!!!! 
EsiJspContentDetectionAspect: obj is not of type template or fragment... 
obj:"+obj);
  
          }
  
      */
      //*******************************************************************
  
         /*
      public void addContainer (JoinPoint joinPoint)
          throws Throwable {
  
          if (debug) {
          MemberSignature signature = (MemberSignature) 
joinPoint.getSignature();
  
          System.err.println(
              "-------\n addContainer aspect: AFTER() : "
              + joinPoint.getCalleeClass().getName()
              + "::"
              + signature.getName()
              + "\n"
              + joinPoint.toString()    );
          }
          JesiObject obj = null;
          try {
              obj = (JesiObject) 
ServicesRegistry.getInstance().getEsiService().tagStackPeek();
          } catch(EmptyStackException ex) {
              System.err.println("     QUITTING 
EsiJspContentDetectionAspect.addContainer() as OUTSIDE FRAGMENT OR TEMPLATE");
              return;
          }
  
          if (debug) System.err.println("addContainer[" + 
this.getClass().getClassLoader().hashCode() + "] ");
          if (debug) System.err.println("addContainer this[" + this + "] ");
  
          if (debug) {
              MethodRtti mrtti = (MethodRtti) joinPoint.getRtti();
              System.err.println(" MethodRtti  Method:" + 
mrtti.getMethod().toString());
              //    +" Return type:"+mrtti.getReturnType() );
              Object[] parameters = mrtti.getParameterValues();
              for (int i = 0, j = parameters.length; i < j; i++) {
                  System.err.println("                param " + i + " Name:" + 
parameters[i]);
              }
          }
          if (obj instanceof Fragment) {
              //Fragment fr = (Fragment) obj;
              //following might not be necessary, but do it anyway
              Fragment frg = 
ServicesRegistry.getInstance().getEsiService().getFragment(
                  ((Fragment)obj).fragID);
  
                if (joinPoint.getCallee() instanceof JahiaContainer ) {
                    JahiaContainer ctn = (JahiaContainer) 
(joinPoint.getCallee());
                    frg.addContainer(ctn.getID(), ctn.getPageID());
                    if (debug) System.err.println("           COMONNNN   
JahiaContainer:  added Container " +
                                       ctn.getID()+ " [" + 
ctn.getDefinition().getName() + "]"
                                       + " to Fragment " + frg.fragID + " on 
pageID: " +
                                       frg.pageID);
                }
                else if (joinPoint.getCallee() instanceof ContainerBean ) {
                    ContainerBean ctnbean = (ContainerBean) 
(joinPoint.getCallee());
                        frg.addContainer(ctnbean.getId(), ctnbean.getPageID());
                        if (debug) System.err.println("           COMONNNN  
ContainerBEAN:   added Container " +
                                           ctnbean.getId()+ " [" + 
ctnbean.getDefinition().getName() + "]"
                                           + " to Fragment " + frg.fragID + " 
on pageID: " +
                                           frg.pageID);
                }
          }
          else if (obj instanceof Template) {
              //Temaplate tpl = (Template) obj;
              //following might not be necessary, but do it anyway
              Template tpl = 
ServicesRegistry.getInstance().getEsiService().getTemplate(
                  ((Template)obj).pageID);
               //System.err.println("     joinPoint.getCalleeClass().getID() 
"+joinPoint.getCalleeClass().getID());
               if (joinPoint.getCallee() instanceof JahiaContainer ) {
                   JahiaContainer ctn = (JahiaContainer) 
(joinPoint.getCallee());
                   tpl.addContainer(ctn.getID(),ctn.getPageID());
                   if (debug) System.err.println("           HOURRRAYYY     
added Container "+ctn.getID()
                                      + " [" + ctn.getDefinition().getName() + 
"]"
                                  +" to Template on pageID: "+tpl.pageID);
                             }
               else if (joinPoint.getCallee() instanceof ContainerBean ) {
                    ContainerBean ctnbean = (ContainerBean) 
(joinPoint.getCallee());
                    tpl.addContainer(ctnbean.getId(), ctnbean.getPageID());
                    if (debug) System.err.println("           HOURRRAYYY  
ContainerBEAN:   added Container " +
                                         ctnbean.getId() + " [" + 
ctnbean.getDefinition().getName() + "]"
                                        +" to Template on pageID: "+tpl.pageID);
                }
          } else System.err.println("HOUSTON!!!!!!!!!!!!! 
EsiJspContentDetectionAspect: obj is not of type template or fragment... 
obj:"+obj);
      } */
  
  
  
      //*******************************************************************
       /*
         public void addField (JoinPoint joinPoint)
             throws Throwable {
  
             if (debug) {
             MemberSignature signature = (MemberSignature) 
joinPoint.getSignature();
  
             System.err.println(
                 "-------\n addField aspect: AFTER() : "
                 + joinPoint.getCalleeClass().getName()
                 + "::"
                 + signature.getName()
                 + "\n"
                 + joinPoint.toString()    );
             }
  
             JesiObject obj = null;
             try {
                 obj = (JesiObject) 
ServicesRegistry.getInstance().getEsiService().tagStackPeek();
             } catch(EmptyStackException ex) {
                 System.err.println("     QUITTING 
EsiJspContentDetectionAspect.addField() as OUTSIDE FRAGMENT OR TEMPLATE");
                 return;
             }
  
             if (debug) {
             System.err.println("addField[" + 
this.getClass().getClassLoader().hashCode() + "] ");
             System.err.println("addField this[" + this + "] ");
  
             MethodRtti mrtti = (MethodRtti) joinPoint.getRtti();
             System.err.println(" MethodRtti  
Method:"+mrtti.getMethod().toString());
             //    +" Return type:"+mrtti.getReturnType() );
             Object[] parameters = mrtti.getParameterValues();
             for (int i = 0, j = parameters.length; i < j; i++) {
                 System.err.println("                param "+i+" 
Name:"+parameters[i]);
             }
             }
  
             if (obj instanceof Fragment) {
                 //Fragment fr = (Fragment) obj;
                 //following might not be necessary, but do it anyway
                 Fragment frg = 
ServicesRegistry.getInstance().getEsiService().getFragment(
                     ((Fragment)obj).fragID);
  
                   if (joinPoint.getCallee() instanceof JahiaField ) {
                       JahiaField fd = (JahiaField) (joinPoint.getCallee());
                       frg.addField(fd.getID(), fd.getPageID());
                       if (debug) System.err.println("           COMONNNN   
JahiaField:  added Field " +
                                          fd.getID()+ " [" + fd.getValue() + "]"
                                          + " to Fragment " + frg.fragID + " on 
pageID: " +
                                          frg.pageID);
                   }
                   else if (joinPoint.getCallee() instanceof FieldBean ) {
                       FieldBean fdbean = (FieldBean) (joinPoint.getCallee());
                           frg.addField(fdbean.getId(), fdbean.getPageID());
                           if (debug) System.err.println("           COMONNNN  
FieldBEAN:   added Field " +
                                              fdbean.getId() + " [" + 
fdbean.getTitle() + "]"
                                              + " to Fragment " + frg.fragID + 
" on pageID: " +
                                              frg.pageID);
                   }
             }
             else if (obj instanceof Template) {
                 //Temaplate tpl = (Template) obj;
                 //following might not be necessary, but do it anyway
                 Template tpl = 
ServicesRegistry.getInstance().getEsiService().getTemplate(
                     ((Template)obj).pageID);
                  //System.err.println("     joinPoint.getCalleeClass().getID() 
"+joinPoint.getCalleeClass().getID());
                  if (joinPoint.getCallee() instanceof JahiaField ) {
                      JahiaField fd = (JahiaField) (joinPoint.getCallee());
                      tpl.addField(fd.getID(),fd.getPageID());
                      if (debug) System.err.println("           HOURRRAYYY     
added Field "+fd.getID()
                                         + " [" + fd.getValue() + "]"
                                     +" to Template on pageID: "+tpl.pageID);
                                }
                  else if (joinPoint.getCallee() instanceof FieldBean ) {
                       FieldBean fdbean = (FieldBean) (joinPoint.getCallee());
                       tpl.addField(fdbean.getId(), fdbean.getPageID());
                       if (debug) System.err.println("           HOURRRAYYY  
FieldBEAN:   added Field " +
                                            fdbean.getId()  + " [" + 
fdbean.getValue() + "]"
                                           +" to Template on pageID: 
"+tpl.pageID);
                   }
             } else System.err.println("HOUSTON!!!!!!!!!!!!! 
EsiJspContentDetectionAspect: obj is not of type template or fragment... 
obj:"+obj);
      }*/
  
  
      //*******************************************************************
   /*
     public void addPage (JoinPoint joinPoint)
         throws Throwable {
  
         if (debug) {
         MemberSignature signature = (MemberSignature) joinPoint.getSignature();
  
         System.err.println(
             "-------\n addPage aspect: AFTER() : "
             + joinPoint.getCalleeClass().getName()
             + "::"
             + signature.getName()
             + "\n"
             + joinPoint.toString()    );
         }
  
         JesiObject obj = null;
         try {
             obj = (JesiObject) 
ServicesRegistry.getInstance().getEsiService().tagStackPeek();
         } catch(EmptyStackException ex) {
             System.err.println("     QUITTING 
EsiJspContentDetectionAspect.addPage() as OUTSIDE FRAGMENT OR TEMPLATE");
             return;
         }
  
         if (debug) {
         System.err.println("addPage[" + 
this.getClass().getClassLoader().hashCode() + "] ");
         System.err.println("addPage this[" + this + "] ");
  
         MethodRtti mrtti = (MethodRtti) joinPoint.getRtti();
         System.err.println(" MethodRtti  
Method:"+mrtti.getMethod().toString());
         //    +" Return type:"+mrtti.getReturnType() );
         Object[] parameters = mrtti.getParameterValues();
         for (int i = 0, j = parameters.length; i < j; i++) {
             System.err.println("                param "+i+" 
Name:"+parameters[i]);
         }
         }
  
         if (obj instanceof Fragment) {
             //Fragment fr = (Fragment) obj;
             //following might not be necessary, but do it anyway
             Fragment frg = 
ServicesRegistry.getInstance().getEsiService().getFragment(
                 ((Fragment)obj).fragID);
  
               if (joinPoint.getCallee() instanceof JahiaPage ) {
                   JahiaPage pg = (JahiaPage) (joinPoint.getCallee());
                   frg.addPage(pg.getID());
                   if (debug) System.err.println("           COMONNNN   
JahiaPage:  added Page " +
                                      pg.getID() + " [" + pg.getTitle() + "]"
                                      + " to Fragment " + frg.fragID + " on 
pageID: " +
                                      frg.pageID);
               }
               else if (joinPoint.getCallee() instanceof PageBean ) {
                   PageBean pgbean = (PageBean) (joinPoint.getCallee());
                       frg.addPage(pgbean.getID());
                       if (debug) System.err.println("           COMONNNN  
PageBEAN:   added Page " +
                                          pgbean.getID() + " [" + 
pgbean.getTitle() + "]"
                                          + " to Fragment " + frg.fragID + " on 
pageID: " +
                                          frg.pageID);
               }
         }
         else if (obj instanceof Template) {
             //Temaplate tpl = (Template) obj;
             //following might not be necessary, but do it anyway
             Template tpl = 
ServicesRegistry.getInstance().getEsiService().getTemplate(
                 ((Template)obj).pageID);
              //System.err.println("     joinPoint.getCalleeClass().getID() 
"+joinPoint.getCalleeClass().getID());
              if (joinPoint.getCallee() instanceof JahiaPage ) {
                  JahiaPage pg = (JahiaPage) (joinPoint.getCallee());
                  tpl.addPage(pg.getID());
                  if (debug) System.err.println("           HOURRRAYYY     
added Page "+pg.getID()
                                     + " [" + pg.getTitle() + "]"
                                 +" to Template on pageID: "+tpl.pageID);
                            }
              else if (joinPoint.getCallee() instanceof PageBean ) {
                   PageBean pgbean = (PageBean) (joinPoint.getCallee());
                   tpl.addPage(pgbean.getId());
                   if (debug) System.err.println("           HOURRRAYYY  
PageBEAN:   added Page " +
                                        pgbean.getId() + " [" + 
pgbean.getTitle() + "]"
                                       +" to Template on pageID: "+tpl.pageID);
               }
         } else System.err.println("HOUSTON!!!!!!!!!!!!! 
EsiJspContentDetectionAspect: obj is not of type template or fragment... 
obj:"+obj);
  }   */
  
  
  
    /*
     public void addContainerListSET (JoinPoint joinPoint, 
org.jahia.data.containers.JahiaContainerList returnValue)
         throws Throwable {
  
         if (debug) {
         MemberSignature signature = (MemberSignature) joinPoint.getSignature();
  
         System.err.println(
             "!!!!!!!!!!!!!!!!!!!!!!!!!! -------\n addContainerListSET aspect: "
             + joinPoint.getCalleeClass().getName()
             + "::"
             + signature.getName()
             + "\n"
             + joinPoint.toString());
  
            System.err.println(
          "-------\n returnValue: "
          + returnValue);
         }
                  JesiObject obj = null;
                  try {
                      obj = (JesiObject) 
ServicesRegistry.getInstance().getEsiService().tagStackPeek();
                  } catch(EmptyStackException ex) {
                      System.err.println("     QUITTING 
EsiJspContentDetectionAspect.addContainerListSET() as OUTSIDE FRAGMENT OR 
TEMPLATE");
                      return;
                  }
  
                  if (debug) {
                      System.err.println("addContainerListSET[" +
                                   this.getClass().getClassLoader().hashCode() 
+ "] ");
                      System.err.println("addContainerListSET this[" + this +"] 
");
  
                      MethodRtti mrtti = (MethodRtti) joinPoint.getRtti();
                      System.err.println(" MethodRtti  Method:" + 
mrtti.getMethod().toString());
                      //    +" Return type:"+mrtti.getReturnType() );
                      Object[] parameters = mrtti.getParameterValues();
                      for (int i = 0, j = parameters.length; i < j; i++) {
                          System.err.println("                param " + i + " 
Name:" + parameters[i]);
                      }
                  }
                  if (obj instanceof Fragment) {
                      //Fragment fr = (Fragment) obj;
                      //following might not be necessary, but do it anyway
                      Fragment frg = 
ServicesRegistry.getInstance().getEsiService().getFragment(
                          ((Fragment)obj).fragID);
  
                         frg.addContainerList(returnValue.getID(), 
returnValue.getPageID() );
                            if (debug) System.err.println("           
HOURRRAYYY   addContainerListSET:  added ContainerList " +
                                               returnValue.getID() + " [" + 
returnValue.getDefinition().getName() + "]"
                                               + " to Fragment " + frg.fragID + 
" on pageID: " +
                                               frg.pageID);
                  }
                  else if (obj instanceof Template) {
                      //Temaplate tpl = (Template) obj;
                      //following might not be necessary, but do it anyway
                      Template tpl = 
ServicesRegistry.getInstance().getEsiService().getTemplate(
                          ((Template)obj).pageID);
                       //System.err.println("     
joinPoint.getCalleeClass().getID() "+joinPoint.getCalleeClass().getID());
  
                       tpl.addContainerList(returnValue.getID(), 
returnValue.getPageID() );
                          if (debug) System.err.println("           HOURRRAYYY  
 addContainerListSET:  added ContainerList " +
                                             returnValue.getID() + " [" + 
returnValue.getDefinition().getName() + "]"
                                             + " to Template " + tpl.pageID);
                 } else System.err.println("HOUSTON!!!!!!!!!!!!! 
EsiJspContentDetectionAspect: obj is not of type template or fragment... 
obj:"+obj);
      }  */
  
  
      //*******************************************************************
   /*    public void detectedActionMenu (JoinPoint joinPoint)
           throws Throwable {
  
           if (debug) {
           MemberSignature signature = (MemberSignature) 
joinPoint.getSignature();
  
            System.err.println(
               "-------\n detectedActionMenu aspect: AFTER() : "
               + joinPoint.getCalleeClass().getName()
               + "::"
               + signature.getName()
               + "\n"
               + joinPoint.toString()    );
           }
           JesiObject obj = null;
           try {
               obj = (JesiObject) 
ServicesRegistry.getInstance().getEsiService().tagStackPeek();
           } catch(EmptyStackException ex) {
               System.err.println("     QUITTING 
EsiJspContentDetectionAspect.detectedActionMenu() as OUTSIDE FRAGMENT OR 
TEMPLATE");
               return;
           }
  
          if (debug) {
           System.err.println("detectedActionMenu[" + 
this.getClass().getClassLoader().hashCode() + "] ");
           System.err.println("detectedActionMenu this[" + this + "] ");
  
           MethodRtti mrtti = (MethodRtti) joinPoint.getRtti();
           System.err.println(" MethodRtti  
Method:"+mrtti.getMethod().toString());
           //    +" Return type:"+mrtti.getReturnType() );
           Object[] parameters = mrtti.getParameterValues();
           for (int i = 0, j = parameters.length; i < j; i++) {
               System.err.println("                param "+i+" 
Name:"+parameters[i]);
           }
          }
           if (joinPoint.getCallee() instanceof ActionMenuTag ) {
  
               ActionMenuTag actag = (ActionMenuTag) (joinPoint.getCallee());
  
               if (obj instanceof Fragment) {
                   //Fragment fr = (Fragment) obj;
                   //following might not be necessary, but do it anyway
                   Fragment frg = 
ServicesRegistry.getInstance().getEsiService().
                                  getFragment(( (Fragment) obj).fragID);
                   actag.setFragid(Integer.toString(frg.fragID));
                   actag.setPid(Integer.toString(frg.pageID));
  
                   if (debug) System.err.println("           HOWDY     found 
ActionMenuTag inside Fragment #"+ frg.fragID
                        + " on pageID: " + frg.pageID);
  
               } else if (obj instanceof Template) {
                   //Temaplate tpl = (Template) obj;
                   //following might not be necessary, but do it anyway
                   Template tpl = 
ServicesRegistry.getInstance().getEsiService().
                                  getTemplate(( (Template) obj).pageID);
                   actag.setPid(Integer.toString(tpl.pageID));
  
                   if (debug) System.err.println("           HOWDY     found 
ActionMenuTag inside a Template "
                                + " on pageID: " + tpl.pageID);
  
               } else System.err.println("HOUSTON!!!!!!!!!!!!! 
EsiJspContentDetectionAspect: obj is not of type template or fragment... obj:" 
+ obj);
           }
      }
       */
      //*******************************************************************
      /* public void returnContainer (JoinPoint joinPoint, Object returnValue)
           throws Throwable {
           MemberSignature signature = (MemberSignature) 
joinPoint.getSignature();
  
           System.err.println(
               "-------\n returnContainer aspect: "
               + joinPoint.getCalleeClass().getName()
               + "::"
               + signature.getName()
               + "\n"
               + joinPoint.toString());
  
           System.err.println(
               "-------\n returnValue: "
               + returnValue);
  
       }
  
      public void returnContainer (JoinPoint joinPoint)
              throws Throwable {
              MemberSignature signature = (MemberSignature) 
joinPoint.getSignature();
  
              System.err.println(
                  "-------\n returnContainer aspect: "
                  + joinPoint.getCalleeClass().getName()
                  + "::"
                  + signature.getName()
                  + "\n"
                  + joinPoint.toString());
  
  
       }*/
  
  
  
  
  }
  /*
  addContainer aspect: AFTER() : 
org.jahia.data.containers.JahiaContainerList::getContainers
  addContainer[4414010] addContainer [EMAIL PROTECTED]  MethodRtti  
Method:public java.util.Enumeration org.jahia.data.containers.J
  ahiaContainerList.getContainers()
   */
  
  /*
      public void addContainerSET (JoinPoint joinPoint, 
org.jahia.data.containers.JahiaContainer returnValue)
          throws Throwable {
  
          if (debug) {
          MemberSignature signature = (MemberSignature) 
joinPoint.getSignature();
  
          System.err.println(
              "!!!!!!!!!!!!!!!!!!!!!!!!!! -------\n addContainerSET aspect: "
              + joinPoint.getCalleeClass().getName()
              + "::"
              + signature.getName()
              + "\n"
              + joinPoint.toString());
  
             System.err.println(
           "-------\n returnValue: "
           + returnValue);
          }
                   JesiObject obj = null;
                   try {
                       obj = (JesiObject) 
ServicesRegistry.getInstance().getEsiService().tagStackPeek();
                   } catch(EmptyStackException ex) {
                       System.err.println("     QUITTING 
EsiJspContentDetectionAspect.addContainerSET() as OUTSIDE FRAGMENT OR 
TEMPLATE");
                       return;
                   }
  
                   if (debug) {
                   System.err.println("addContainerSET[" + 
this.getClass().getClassLoader().hashCode() + "] ");
                   System.err.println("addContainerSET this[" + this + "] ");
  
                   MethodRtti mrtti = (MethodRtti) joinPoint.getRtti();
                   System.err.println(" MethodRtti  
Method:"+mrtti.getMethod().toString());
                   //    +" Return type:"+mrtti.getReturnType() );
                   Object[] parameters = mrtti.getParameterValues();
                   for (int i = 0, j = parameters.length; i < j; i++) {
                       System.err.println("                param "+i+" 
Name:"+parameters[i]);
                   }
                   }
                   if (obj instanceof Fragment) {
                       //Fragment fr = (Fragment) obj;
                       //following might not be necessary, but do it anyway
                       Fragment frg = 
ServicesRegistry.getInstance().getEsiService().getFragment(
                           ((Fragment)obj).fragID);
  
                          frg.addContainer(returnValue.getID(), 
returnValue.getPageID() );
                             if (debug) System.err.println("           
HOURRRAYYY   addContainerSET:  added Container " +
                                                returnValue.getID() //+ " [" + 
returnValue.getDefinition().getName() + "]"
                                                + " to Fragment " + frg.fragID 
+ " on pageID: " +
                                                frg.pageID);
                   }
                   else if (obj instanceof Template) {
                       //Temaplate tpl = (Template) obj;
                       //following might not be necessary, but do it anyway
                       Template tpl = 
ServicesRegistry.getInstance().getEsiService().getTemplate(
                           ((Template)obj).pageID);
                        //System.err.println("     
joinPoint.getCalleeClass().getID() "+joinPoint.getCalleeClass().getID());
  
                        tpl.addContainer(returnValue.getID(), 
returnValue.getPageID() );
                           if (debug) System.err.println("           HOURRRAYYY 
  addContainerSET:  added Container " +
                                              returnValue.getID() //+ " [" + 
returnValue.getDefinition().getName() + "]"
                                              + " to Template " + tpl.pageID);
  
                   } else System.err.println("HOUSTON!!!!!!!!!!!!! 
EsiJspContentDetectionAspect: obj is not of type template or fragment... 
obj:"+obj);
  
       }    */
  
       

Reply via email to