tdraier     2005/10/28 12:56:18 CEST

  Modified files:
    core/src/java/org/jahia/engines/importexport 
                                                 ManageContentPicker.java 
  Log:
  avoid content pick loops
  
  Revision  Changes    Path
  1.43      +74 -60    
jahia/core/src/java/org/jahia/engines/importexport/ManageContentPicker.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/engines/importexport/ManageContentPicker.java.diff?r1=1.42&r2=1.43&f=h
  
  
  
  Index: ManageContentPicker.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/engines/importexport/ManageContentPicker.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- ManageContentPicker.java  20 Oct 2005 16:55:54 -0000      1.42
  +++ ManageContentPicker.java  28 Oct 2005 10:56:17 -0000      1.43
  @@ -2,6 +2,7 @@
   
   import org.jahia.content.ContainerDefinitionKey;
   import org.jahia.content.ContentObject;
  +import org.jahia.content.ObjectKey;
   import org.jahia.data.containers.JahiaContainerDefinition;
   import org.jahia.data.search.JahiaContainerSearchHit;
   import org.jahia.data.search.JahiaSearchHit;
  @@ -34,7 +35,7 @@
    *
    * @author Thomas Draier, joe Pillot
    * @author ${User}
  - * @version $Id: ManageContentPicker.java,v 1.42 2005/10/20 16:55:54 dpillot 
Exp $
  + * @version $Id: ManageContentPicker.java,v 1.43 2005/10/28 10:56:17 tdraier 
Exp $
    */
   public class ManageContentPicker {
       private static org.apache.log4j.Logger logger =
  @@ -539,82 +540,92 @@
   
                           //is compatible
                           if (ie.isCompatible(thisJcd, currentJcd)) {
  -
  -                            String key = Integer.toString(current.getID());
  -                            int pageID = contentContainer.getPageID();
  -                            logger.debug("found compatible?" + key);
  -                            String t = key;
  -                            List l =  
getChildFieldsOnly(contentContainer.getChilds(null, lr, null));
  -
  -                            for (Iterator iterator1 = l.iterator(); 
iterator1.hasNext();) {
  -                                ContentField contentField = (ContentField) 
iterator1.next();
  -                                String value = 
contentField.getValue(processingContext, lr);
  -                                if (value != null && 
!value.trim().equals("") && !value.equals("<empty>")) {
  -                                    t = value;
  -                                    if(value.length()>12) 
t=value.substring(0,12)+" (...)";
  -                                    logger.debug("tkey=" + t);
  +                            ContentObject dest = object;
  +                            while (dest != null) {
  +                                if 
(dest.getObjectKey().equals(current.getObjectKey())) {
                                       break;
                                   }
  +                                dest = 
dest.getParent(EntryLoadRequest.STAGED);
                               }
  +                            if (dest == null) {
  +                                String key = 
Integer.toString(current.getID());
  +                                int pageID = contentContainer.getPageID();
  +                                logger.debug("found compatible?" + key);
  +                                String t = key;
  +                                List l =  
getChildFieldsOnly(contentContainer.getChilds(null, lr, null));
   
  -                            for (Iterator iterator1 = l.iterator(); 
iterator1.hasNext();) {
  -                                ContentField contentField = (ContentField) 
iterator1.next();
  -                                if (contentField instanceof 
ContentSmallTextField) {
  +                                for (Iterator iterator1 = l.iterator(); 
iterator1.hasNext();) {
  +                                    ContentField contentField = 
(ContentField) iterator1.next();
                                       String value = 
contentField.getValue(processingContext, lr);
                                       if (value != null && 
!value.trim().equals("") && !value.equals("<empty>")) {
                                           t = value;
  -                                        pageID = contentField.getPageID();
  -                                        logger.debug("smalltext:" + t + " 
pageID" + pageID);
  +                                        if(value.length()>12) 
t=value.substring(0,12)+" (...)";
  +                                        logger.debug("tkey=" + t);
                                           break;
                                       }
                                   }
  -                            }
   
  -                            //looping list of childs to check page type?
  -                            for (Iterator iterator1 = l.iterator(); 
iterator1.hasNext();) {
  -                                ContentField contentField = (ContentField) 
iterator1.next();
  -                                if (contentField instanceof 
ContentPageField) {
  -                                    ContentPage contentPage = 
((ContentPageField) contentField).getContentPage(lr);
  -                                    t = contentPage.getTitle(lr);
  -                                    pageID = contentPage.getID();
  -                                    logger.debug("page:" + t + " pageID" + 
pageID);
  -                                    break;
  +                                for (Iterator iterator1 = l.iterator(); 
iterator1.hasNext();) {
  +                                    ContentField contentField = 
(ContentField) iterator1.next();
  +                                    if (contentField instanceof 
ContentSmallTextField) {
  +                                        String value = 
contentField.getValue(processingContext, lr);
  +                                        if (value != null && 
!value.trim().equals("") && !value.equals("<empty>")) {
  +                                            t = value;
  +                                            pageID = 
contentField.getPageID();
  +                                            logger.debug("smalltext:" + t + 
" pageID" + pageID);
  +                                            break;
  +                                        }
  +                                    }
                                   }
  -                            }
  -                            if (jahiaSearchHit.getParsedObject()!= null) {
  -                                //logger.debug("fields of searchhit" + 
jahiaSearchHit.getParsedObject().getFields());
  -                            }
   
  -                            if (results.containsKey(key)) {
  -                                JahiaContainerSearchHit hit = 
(JahiaContainerSearchHit) results.get(key);
  -                                hit.setScore(score + hit.getScore());
  -                                logger.debug("improving score :" + key + " 
new score:" + hit.getScore());
  -                                break;
  -                            } else {
  -                                JahiaContainerSearchHit hit = new 
JahiaContainerSearchHit(jahiaSearchHit.getParsedObject());
  -                                hit.setId(key);
  -                                
hit.setPage(contentContainer.getPage().getPage(processingContext));
  -                                hit.setPageId(pageID);
  -                                
hit.setURL(processingContext.composePageUrl(pageID));
  -                                hit.setTeaser(t);
  -                                hit.setScore(score);
  -                                List metadata = 
contentContainer.getMetadatas();
  -                                logger.debug("metadata : "+metadata);
  -                                Hashtable fields = 
hit.getParsedObject().getFields();
  -                                
fillSearchHitWithMetadataValues(fields,contentContainer,"creator",new 
String[]{""},processingContext);
  -                                
fillSearchHitWithMetadataValues(fields,contentContainer,"lastContributor",new 
String[]{""},processingContext);
  -                                
fillSearchHitWithMetadataValues(fields,contentContainer,"creationDate",new 
String[]{""},processingContext);
  -                                
fillSearchHitWithMetadataValues(fields,contentContainer,"lastPublishingDate",new
 String[]{""},processingContext);
  -
  -                                while (current != null) {
  -                                    current = current.getParent(null);
  -                                    if (current != null && 
current.getPickedObject() != null) {
  +                                //looping list of childs to check page type?
  +                                for (Iterator iterator1 = l.iterator(); 
iterator1.hasNext();) {
  +                                    ContentField contentField = 
(ContentField) iterator1.next();
  +                                    if (contentField instanceof 
ContentPageField) {
  +                                        ContentPage contentPage = 
((ContentPageField) contentField).getContentPage(lr);
  +                                        t = contentPage.getTitle(lr);
  +                                        pageID = contentPage.getID();
  +                                        logger.debug("page:" + t + " pageID" 
+ pageID);
                                           break;
                                       }
                                   }
  +                                if (jahiaSearchHit.getParsedObject()!= null) 
{
  +                                    //logger.debug("fields of searchhit" + 
jahiaSearchHit.getParsedObject().getFields());
  +                                }
   
  -                                results.put(key, hit);
  -                                break;
  +                                if (results.containsKey(key)) {
  +                                    JahiaContainerSearchHit hit = 
(JahiaContainerSearchHit) results.get(key);
  +                                    hit.setScore(score + hit.getScore());
  +                                    logger.debug("improving score :" + key + 
" new score:" + hit.getScore());
  +                                    break;
  +                                } else {
  +                                    JahiaContainerSearchHit hit = new 
JahiaContainerSearchHit(jahiaSearchHit.getParsedObject());
  +                                    hit.setId(key);
  +                                    
hit.setPage(contentContainer.getPage().getPage(processingContext));
  +                                    hit.setPageId(pageID);
  +                                    
hit.setURL(processingContext.composePageUrl(pageID));
  +                                    hit.setTeaser(t);
  +                                    hit.setScore(score);
  +                                    List metadata = 
contentContainer.getMetadatas();
  +                                    logger.debug("metadata : "+metadata);
  +                                    Hashtable fields = 
hit.getParsedObject().getFields();
  +                                    
fillSearchHitWithMetadataValues(fields,contentContainer,"creator",new 
String[]{""},processingContext);
  +                                    
fillSearchHitWithMetadataValues(fields,contentContainer,"lastContributor",new 
String[]{""},processingContext);
  +                                    
fillSearchHitWithMetadataValues(fields,contentContainer,"creationDate",new 
String[]{""},processingContext);
  +                                    
fillSearchHitWithMetadataValues(fields,contentContainer,"lastPublishingDate",new
 String[]{""},processingContext);
  +
  +                                    while (current != null) {
  +                                        current = current.getParent(null);
  +                                        if (current != null && 
current.getPickedObject() != null) {
  +                                            break;
  +                                        }
  +                                    }
  +
  +                                    results.put(key, hit);
  +                                    break;
  +                                }
  +                            } else {
  +                                logger.debug("loop detected");
                               }
                           } else {
                               logger.debug("no-compatible");
  @@ -788,6 +799,9 @@
   }
   /**
    * $Log: ManageContentPicker.java,v $
  + * Revision 1.43  2005/10/28 10:56:17  tdraier
  + * avoid content pick loops
  + *
    * Revision 1.42  2005/10/20 16:55:54  dpillot
    * internationalization & bug NFE fix
    *
  

Reply via email to