dpillot     2005/11/30 18:11:02 CET

  Modified files:
    core/src/java/org/jahia/data/beans ContainerBean.java 
  Log:
  list pickers in actionmenu
  
  Revision  Changes    Path
  1.29      +125 -3    
jahia/core/src/java/org/jahia/data/beans/ContainerBean.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/data/beans/ContainerBean.java.diff?r1=1.28&r2=1.29&f=h
  
  
  
  Index: ContainerBean.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/data/beans/ContainerBean.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- ContainerBean.java        24 Nov 2005 17:19:48 -0000      1.28
  +++ ContainerBean.java        30 Nov 2005 17:11:01 -0000      1.29
  @@ -19,6 +19,8 @@
   import org.jahia.services.containers.ContentContainer;
   import org.jahia.services.containers.ContentContainerList;
   import org.jahia.services.fields.ContentPageField;
  +import org.jahia.services.fields.ContentField;
  +import org.jahia.services.fields.ContentSmallTextField;
   import org.jahia.services.importexport.ImportExportService;
   import org.jahia.services.lock.LockKey;
   import org.jahia.services.lock.LockService;
  @@ -38,7 +40,7 @@
    * <p>Company: Jahia Ltd</p>
    *
    * @author Serge Huber, Xavier Lawrence
  - * @version $Id: ContainerBean.java,v 1.28 2005/11/24 17:19:48 dpillot Exp $
  + * @version $Id: ContainerBean.java,v 1.29 2005/11/30 17:11:01 dpillot Exp $
    */
   
   public class ContainerBean extends ContentBean implements 
PropertiesInterface {
  @@ -565,18 +567,135 @@
                   buff.append("',600,400)");
                   curActionURIBean = new ActionURIBean("picked", "", 
buff.toString());
                   actionURIs.put(curActionURIBean.getName(), curActionURIBean);
  -
  +                //looping for pickers to display the list directly in 
actionmenu
  +                Iterator pickers=theContainer.getPickerObjects().iterator();
  +                int count=0;
  +                while(pickers.hasNext() && count<4){
  +                    ContentObject co=(ContentObject) pickers.next();
  +                    ActionURIBean aub=getActionUriPicker(co);
  +                    actionURIs.put(aub.getName(), aub);
  +                    count++;
  +                }
               }
           } catch (JahiaException je) {
               logger.error("Error while retrieving action URI map for 
container " + getID(), je);
           }
       }
  +    /**
  +     *  to clean a list from pseudomodel artifacts
  +     * @param childs
  +     * @return a list
  +     */
  +    private List getChildFieldsOnly(List childs) {
  +        List results = new ArrayList();
  +        if (childs == null || childs.isEmpty()) {
  +            return results;
  +        }
  +        Iterator iterator = childs.iterator();
  +        ContentObject contentObject = null;
  +        while (iterator.hasNext()) {
  +            contentObject = (ContentObject) iterator.next();
  +            if (contentObject instanceof ContentField) {
  +                results.add(contentObject);
  +            }
  +
  +        }
  +        return results;
  +    }
  +    /**
  +     * to get the actionuri for the pickers
  +     * specific format for the launcher to be processed by addactions js 
function<br>
  +     *
  +     * @param o the picker contentobject
  +     * @return an ActionUriBean
  +     */
  +    private ActionURIBean getActionUriPicker(ContentObject o){
  +        int key=o.getID();
  +        int pageID=0;
  +        int siteID=0;
  +        String r="";
  +        String t="NA";
  +        String u="";
  +        boolean isPage=false;
  +        if (o instanceof ContentContainer) {
  +            pageID = ((ContentContainer) o).getPageID();
  +            siteID = ((ContentContainer) o).getSiteID();
  +           try {
  +                List l = 
getChildFieldsOnly(o.getChilds(processingContext.getUser(), 
EntryLoadRequest.STAGED, ProcessingContext.EDIT));
  +
  +                for (Iterator iterator1 = l.iterator(); 
iterator1.hasNext();) {
  +
  +                    ContentField contentField = (ContentField) 
iterator1.next();
  +                    String value = contentField.getValue(processingContext, 
EntryLoadRequest.STAGED);
  +                    if (value != null && !value.trim().equals("") && 
!value.equals("<empty>")) {
  +                        t = value;
  +                        if (value.length() > 12) t = value.substring(0, 12) 
+ " (...)";
  +                        logger.debug("tkey=" + t);
  +
  +                        break;
  +                    }
  +                }
  +
  +                // case the content object is text
  +                for (Iterator iterator1 = l.iterator(); 
iterator1.hasNext();) {
  +
  +                    ContentField contentField = (ContentField) 
iterator1.next();
  +                    if (contentField instanceof ContentSmallTextField) {
  +                        logger.debug("child object is smalltextField");
  +                        String value = contentField.getValue(null, 
EntryLoadRequest.STAGED);
  +                        if (value != null && !value.trim().equals("") && 
!value.equals("<empty>")) {
  +                            t = value;
  +                            pageID = contentField.getPageID();
  +                            siteID = contentField.getSiteID();
  +                            logger.debug("text value key=" + 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) {
  +                        isPage = true;
  +                        logger.debug("child object is Contentpage field");
  +                        ContentPage contentPage = ((ContentPageField) 
contentField).getContentPage(EntryLoadRequest.STAGED);
  +                        t = contentPage.getTitle(EntryLoadRequest.STAGED);
  +                        if(t==null){
  +                        t=(String) 
contentPage.getTitles(true).get(processingContext.getLocale().getDisplayName());
  +                        }
  +                        pageID = contentPage.getID();
  +                        siteID = contentPage.getSiteID();
  +                        logger.debug("page value key=" + t);
  +                        break;
  +                    }
  +                }
  +                if (!isPage) {
  +                    r = "<a href=\"" + Jahia.getContextPath() + 
Jahia.getServletPath() + "/pid/" + pageID + "\" target=\"_new\">" + t + 
"</a><br>(id:" + key + " on site" + siteID + ")";
  +                } else {
  +                    r = "<a href=\"" + Jahia.getContextPath() + 
Jahia.getServletPath() + "/pid/" + pageID + "\" target=\"_new\">" + t + 
"</a><br>(id:" + key + " on site" + siteID + ")";
  +                }
  +                u=""+ Jahia.getContextPath() + Jahia.getServletPath() + 
"/pid/" + pageID;
  +            } catch (JahiaException e) {
  +                logger.error("error", e);
  +                r="";
  +            }
  +        }
  +
  +        //todo use the ispage and the checkwriteaccess
  +
  +       //format pid,is ok for writeacess,title,url
  +        String 
launcher=""+pageID+","+o.checkWriteAccess(processingContext.getUser())+","+t+","+u;
  +        return new ActionURIBean("pickedlist","",launcher);
  +    }
  +
   
       public boolean isPicker() {
           try {
               return 
importExportService.isPicker(jahiaContainer.getContentContainer());
           } catch (JahiaException e) {
  -            e.printStackTrace();
  +            logger.error(e);
           }
           return false;
       }
  @@ -614,3 +733,9 @@
           return false;
       }
   }
  +/**
  +*  $Log: ContainerBean.java,v $
  +*  Revision 1.29  2005/11/30 17:11:01  dpillot
  +*  list pickers in actionmenu
  +*
  +*/
  \ No newline at end of file
  

Reply via email to