knguyen     2005/04/28 16:57:36 CEST

  Modified files:
    core/src/java/org/jahia/data/containers 
                                            ContainerMetadataFilterBean.java 
                                            ContainerMetadataSorterBean.java 
                                            ContainerSorterBean.java 
                                            
ContainerSorterByContainerDefinition.java 
  Log:
  - metadata filter and sorter completed
  
  Revision  Changes    Path
  1.3       +70 -71    
jahia/core/src/java/org/jahia/data/containers/ContainerMetadataFilterBean.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/data/containers/ContainerMetadataFilterBean.java.diff?r1=1.2&r2=1.3&f=h
  1.2       +91 -23    
jahia/core/src/java/org/jahia/data/containers/ContainerMetadataSorterBean.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/data/containers/ContainerMetadataSorterBean.java.diff?r1=1.1&r2=1.2&f=h
  1.11      +10 -10    
jahia/core/src/java/org/jahia/data/containers/ContainerSorterBean.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/data/containers/ContainerSorterBean.java.diff?r1=1.10&r2=1.11&f=h
  1.9       +1 -1      
jahia/core/src/java/org/jahia/data/containers/ContainerSorterByContainerDefinition.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/data/containers/ContainerSorterByContainerDefinition.java.diff?r1=1.8&r2=1.9&f=h
  
  
  
  Index: ContainerMetadataFilterBean.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/data/containers/ContainerMetadataFilterBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ContainerMetadataFilterBean.java  10 Aug 2004 17:49:43 -0000      1.2
  +++ ContainerMetadataFilterBean.java  28 Apr 2005 14:57:36 -0000      1.3
  @@ -73,9 +73,7 @@
       public ContainerMetadataFilterBean(String metadataName,
                                          ParamBean jParams,
                                          EntryLoadRequest entryLoadRequest){
  -        super(metadataName,entryLoadRequest);
  -        this.user = jParams.getUser();
  -        this.site = jParams.getSite();
  +        this(metadataName,false,jParams,entryLoadRequest);
       }
   
       
//--------------------------------------------------------------------------
  @@ -90,9 +88,24 @@
                                          boolean numberFiltering,
                                          ParamBean jParams,
                                          EntryLoadRequest entryLoadRequest){
  -        super(metadataName, numberFiltering, entryLoadRequest);
  -        this.user = jParams.getUser();
  -        this.site = jParams.getSite();
  +        this(metadataName,numberFiltering,false,jParams,entryLoadRequest);
  +    }
  +
  +    
//--------------------------------------------------------------------------
  +    /**
  +     * Constructor
  +     *
  +     * @param String metadataName, the metadata name of the field on which 
to apply filtering.
  +     * @param boolean numberFiltering, if true force to convert filed value 
to long representation
  +     * @param multipleFieldValue
  +     * @param entryLoadRequest
  +     */
  +    public ContainerMetadataFilterBean(String metadataName,
  +                                       boolean numberFiltering,
  +                                       boolean multipleFieldValue,
  +                                       ParamBean jParams,
  +                                       EntryLoadRequest entryLoadRequest){
  +        
this(metadataName,numberFiltering,null,multipleFieldValue,jParams,entryLoadRequest);
       }
   
       
//--------------------------------------------------------------------------
  @@ -106,10 +119,11 @@
        */
       public ContainerMetadataFilterBean(String metadataName,
                                          boolean numberFiltering,
  +                                       String numberFormat,
                                          boolean multipleFieldValue,
                                          ParamBean jParams,
                                          EntryLoadRequest entryLoadRequest){
  -        super(metadataName, numberFiltering,multipleFieldValue, 
entryLoadRequest);
  +        super(metadataName, numberFiltering, 
numberFormat,multipleFieldValue, entryLoadRequest);
           this.user = jParams.getUser();
           this.site = jParams.getSite();
       }
  @@ -181,7 +195,6 @@
           Enumeration keys = datas.keys();
           ObjectKey objectKey = null;
           String S = null;
  -        Long L = null;
           ContentObject contentObject = null;
           ContentContainerList containerList = null;
   
  @@ -189,37 +202,29 @@
           {
               objectKey = (ObjectKey)keys.nextElement();
               S = (String)datas.get(objectKey);
  -            L = null;
  -            try {
  -                L = Long.valueOf(S);
  -            } catch ( Throwable t ){
  -            }
  -            if ( L != null )
  +            boolean match = false;
  +            int size = this.getClauses().size();
  +            int i = 0;
  +            while ( (i<size) && !match )
               {
  -                boolean match = false;
  -                int size = this.getClauses().size();
  -                int i = 0;
  -                while ( (i<size) && !match )
  +                fClause = (FilterClause)this .getClauses().get(i);
  +                if ( fClause != null && fClause.isValid() )
                   {
  -                    fClause = (FilterClause)this .getClauses().get(i);
  -                    if ( fClause != null && fClause.isValid() )
  -                    {
  -                        match = fClause.compare(L.longValue());
  -                    }
  -                    i++;
  +                    match = fClause.compareNumber(S,this.numberFormat);
                   }
  -                if ( match )
  -                {
  -                    contentObject = ContentObject
  -                                    .getContentObjectFromMetadata(objectKey);
  -                    if ( contentObject != null &&
  -                         contentObject instanceof ContentContainer ){
  -                        containerList = 
(ContentContainerList)((ContentContainer)
  -                                                               contentObject)
  -                                        
.getParent(this.getEntryLoadRequest());
  -                        if ( containerList != null && 
containerList.getID()==ctnListID){
  -                            result.set(contentObject.getID());
  -                        }
  +                i++;
  +            }
  +            if ( match )
  +            {
  +                contentObject = ContentObject
  +                                .getContentObjectFromMetadata(objectKey);
  +                if ( contentObject != null &&
  +                     contentObject instanceof ContentContainer ){
  +                    containerList = (ContentContainerList)((ContentContainer)
  +                                                           contentObject)
  +                                    .getParent(this.getEntryLoadRequest());
  +                    if ( containerList != null && 
containerList.getID()==ctnListID){
  +                        result.set(contentObject.getID());
                       }
                   }
               }
  @@ -433,56 +438,50 @@
           Enumeration keys = datas.keys();
           ObjectKey objectKey = null;
           String S = null;
  -        Long L = null;
  +        String v = null;
           ContentObject contentObject = null;
   
           while ( keys.hasMoreElements() )
           {
               objectKey = (ObjectKey)keys.nextElement();
               S = (String)datas.get(objectKey);
  -            L = null;
  +            v = null;
               boolean match = false;
               String[] vals = 
JahiaTools.getTokens(S,JahiaField.MULTIPLE_VALUES_SEP);
               int nbVals = vals.length;
               int i = 0;
               while ( (i<nbVals) && !match ){
  -                try {
  -                    L = Long.valueOf((String)vals[i]);
  -                } catch ( Throwable t ){
  -                }
  -                if ( L != null )
  +                v = (String)vals[i];
  +                int size = this.getClauses().size();
  +                int j = 0;
  +                while ( (j<size) && !match )
                   {
  -                    int size = this.getClauses().size();
  -                    int j = 0;
  -                    while ( (j<size) && !match )
  +                    fClause = (FilterClause)this.getClauses().get(j);
  +                    if ( fClause != null && fClause.isValid() )
                       {
  -                        fClause = (FilterClause)this.getClauses().get(j);
  -                        if ( fClause != null && fClause.isValid() )
  -                        {
  -                            match = fClause.compare(L.longValue());
  -                        }
  -                        j++;
  +                        match = fClause.compareNumber(v,this.numberFormat);
                       }
  -                    if ( match )
  -                    {
  -                        contentObject = ContentObject
  -                                        
.getContentObjectFromMetadata(objectKey);
  -                        if ( contentObject != null &&
  -                             contentObject instanceof ContentContainer ){
  -                            if ( siteId == -1 || contentObject.getSiteID() 
== siteId ){
  -                                try {
  -                                    ContentDefinition contentDefinition =
  -                                        ContentDefinition.
  -                                        getContentDefinitionInstance(
  -                                        contentObject.getDefinitionKey(this
  -                                        .getEntryLoadRequest()));
  -                                    if ( contentDefinition != null &&
  -                                         
containerDefinitionName.equals(contentDefinition.getName()) ){
  -                                        result.set(contentObject.getID());
  -                                    }
  -                                } catch ( Throwable t ){
  -                                    logger.debug(t);
  +                    j++;
  +                }
  +                if ( match )
  +                {
  +                    contentObject = ContentObject
  +                                    .getContentObjectFromMetadata(objectKey);
  +                    if ( contentObject != null &&
  +                         contentObject instanceof ContentContainer ){
  +                        if ( siteId == -1 || contentObject.getSiteID() == 
siteId ){
  +                            try {
  +                                ContentDefinition contentDefinition =
  +                                    ContentDefinition.
  +                                    getContentDefinitionInstance(
  +                                    contentObject.getDefinitionKey(this
  +                                    .getEntryLoadRequest()));
  +                                if ( contentDefinition != null &&
  +                                     
containerDefinitionName.equals(contentDefinition.getName()) ){
  +                                    result.set(contentObject.getID());
                                   }
  +                            } catch ( Throwable t ){
  +                                logger.debug(t);
                               }
                           }
                       }
  
  
  
  Index: ContainerMetadataSorterBean.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/data/containers/ContainerMetadataSorterBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ContainerMetadataSorterBean.java  10 Aug 2004 17:49:43 -0000      1.1
  +++ ContainerMetadataSorterBean.java  28 Apr 2005 14:57:36 -0000      1.2
  @@ -21,6 +21,7 @@
   import java.util.Collections;
   import java.util.Vector;
   import java.util.Locale;
  +import java.text.Collator;
   
   import org.jahia.content.JahiaObject;
   import org.jahia.data.fields.JahiaField;
  @@ -73,9 +74,7 @@
                                          ParamBean jParams)
       throws JahiaException
       {
  -        super(ctnListID, fieldName);
  -        this.site = jParams.getSite();
  -        this.user = jParams.getUser();
  +        this(ctnListID,fieldName,jParams,jParams.getEntryLoadRequest());
       }
   
       
//--------------------------------------------------------------------------
  @@ -92,9 +91,26 @@
                                          EntryLoadRequest entryLoadRequest)
       throws JahiaException
       {
  -        super(ctnListID, fieldName, entryLoadRequest);
  -        this.site = jParams.getSite();
  -        this.user = jParams.getUser();
  +        
this(ctnListID,fieldName,false,jParams,jParams.getEntryLoadRequest());
  +    }
  +
  +    
//--------------------------------------------------------------------------
  +    /**
  +     * Sort containers of a given container List
  +     *
  +     * @param int ctnListID, the container list id.
  +     * @param String the field name, the field on which to sort.
  +     * @param boolean , force field values to be converted to long 
representation before sorting ( if true ).
  +     * @param entryLoadRequest
  +     * @throws JahiaException
  +     */
  +    public ContainerMetadataSorterBean(int ctnListID, String fieldName,
  +                                       boolean numberSort,
  +                                       ParamBean jParams,
  +                                       EntryLoadRequest entryLoadRequest)
  +    throws JahiaException
  +    {
  +        this(ctnListID, 
fieldName,numberSort,null,jParams,jParams.getEntryLoadRequest());
       }
   
       
//--------------------------------------------------------------------------
  @@ -104,16 +120,27 @@
        * @param int ctnListID, the container list id.
        * @param String the field name, the field on which to sort.
        * @param boolean , force field values to be converted to long 
representation before sorting ( if true ).
  +     * @param numberFormat , @see NumberFormats , the default is 
NumberFormat.LONG_FORMAT
        * @param entryLoadRequest
        * @throws JahiaException
        */
  +    /**
  +     * 
  +     * @param ctnListID
  +     * @param fieldName
  +     * @param numberSort
  +     * @param jParams
  +     * @param entryLoadRequest
  +     * @throws JahiaException
  +     */ 
       public ContainerMetadataSorterBean(int ctnListID, String fieldName,
                                          boolean numberSort,
  +                                       String numberFormat,
                                          ParamBean jParams,
                                          EntryLoadRequest entryLoadRequest)
       throws JahiaException
       {
  -        super(ctnListID, fieldName, numberSort, entryLoadRequest);
  +        super(ctnListID, fieldName, numberSort, numberFormat, 
entryLoadRequest);
           this.site = jParams.getSite();
           this.user = jParams.getUser();
       }
  @@ -130,9 +157,7 @@
                                          ParamBean jParams, String fieldName)
       throws JahiaException
       {
  -        super(containerListName, jParams, fieldName);
  -        this.site = jParams.getSite();
  -        this.user = jParams.getUser();
  +        
this(containerListName,jParams,fieldName,jParams.getEntryLoadRequest());
       }
   
       
//--------------------------------------------------------------------------
  @@ -169,9 +194,7 @@
                                          String fieldName, boolean numberSort)
       throws JahiaException
       {
  -        super(containerListName, jParams, fieldName, numberSort);
  -        this.site = jParams.getSite();
  -        this.user = jParams.getUser();
  +        
this(containerListName,jParams,fieldName,numberSort,jParams.getEntryLoadRequest());
       }
   
       
//--------------------------------------------------------------------------
  @@ -191,7 +214,29 @@
                                          EntryLoadRequest entryLoadRequest)
       throws JahiaException
       {
  -        super(containerListName, jParams, fieldName, numberSort, 
entryLoadRequest);
  +        this(containerListName, jParams, fieldName, numberSort, null, 
entryLoadRequest);
  +    }
  +
  +    
//--------------------------------------------------------------------------
  +    /**
  +     * Sort containers of a given container List.
  +     *
  +     * @param String containerListName, the container list name.
  +     * @param ParamBean, the param bean.
  +     * @param String the field name, the field on which to sort.
  +     * @param boolean , force field values to be converted to long 
representation before sorting ( if true ).
  +     * @param numberFormat , @see NumberFormats , the default is 
NumberFormat.LONG_FORMAT
  +     * @param entryLoadRequest
  +     * @throws JahiaException
  +     */
  +    public ContainerMetadataSorterBean(String containerListName,
  +                                       ParamBean jParams,
  +                                       String fieldName, boolean numberSort, 
  +                                       String numberFormat,
  +                                       EntryLoadRequest entryLoadRequest)
  +    throws JahiaException
  +    {
  +        super(containerListName, jParams, fieldName, numberSort, 
numberFormat, entryLoadRequest);
           this.site = jParams.getSite();
           this.user = jParams.getUser();
       }
  @@ -213,7 +258,34 @@
                                          boolean numberSort)
       throws JahiaException
       {
  -        super(-1,fieldName,numberSort,entryLoadRequest);
  +        
this(-1,jParams,fieldName,containerDefinitionName,numberSort,null,entryLoadRequest);
  +    }
  +
  +    
//--------------------------------------------------------------------------
  +    /**
  +     * Constructor for sorting container from a whole Jahia site or from all 
sites,
  +     * given the container definition name.
  +     *
  +     *
  +     * @param siteId
  +     * @param jParams
  +     * @param fieldName
  +     * @param containerDefinitionName
  +     * @param entryLoadRequest
  +     * @param numberSort , force field values to be converted to long 
representation before sorting ( if true ).
  +     * @param numberFormat , @see NumberFormats , the default is 
NumberFormat.LONG_FORMAT
  +     * @throws JahiaException
  +     */
  +    public ContainerMetadataSorterBean(int siteId, ParamBean jParams,
  +                                       String fieldName,
  +                                       String containerDefinitionName,
  +                                       boolean numberSort,
  +                                       String numberFormat,
  +                                       EntryLoadRequest entryLoadRequest
  +                                       )
  +    throws JahiaException
  +    {
  +        super(-1,fieldName,numberSort,numberFormat,entryLoadRequest);
           this.siteId = siteId;
           this.containerDefinitionName = containerDefinitionName;
           this.siteLevel = true;
  @@ -342,16 +414,11 @@
                       }
   
                       if (convertValueAsLong) {
  -                        try {
  -                            obj = new DataBean(contentContainer.getID(),
  -                                               Long.parseLong(fieldValue));
  -                        } catch (Throwable t) {
  -                            // we want to display the ctn anyway
  -                            obj = new DataBean(contentContainer.getID(), -1);
  -                        }
  +                        obj = new DataBean(contentContainer.getID(),
  +                                           fieldValue);
                       } else {
                           obj = new StrDataBean(contentContainer.getID(),
  -                                              fieldValue);
  +                                              fieldValue, 
this.getCollator());
                       }
                       if (obj != null) {
                           datas.add(obj);
  @@ -361,4 +428,5 @@
           }
           return datas;
       }
  +
   }
  
  
  
  Index: ContainerSorterBean.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/data/containers/ContainerSorterBean.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ContainerSorterBean.java  28 Apr 2005 14:06:24 -0000      1.10
  +++ ContainerSorterBean.java  28 Apr 2005 14:57:36 -0000      1.11
  @@ -833,12 +833,21 @@
           return datas;
       }
   
  +    public String toString() {
  +        StringBuffer buf = new StringBuffer();
  +        if (result != null) {
  +            buf.append("Result:");
  +            buf.append(result);
  +        }
  +        return buf.toString();
  +    }
  +
       /**
        *  Return the collator instantiated with the first locale from the 
internal EntryLoadRequest.
        *  If the entryLoadRequest is null, the localtor is instantiated with 
the default locale of the system
        * @return
        */
  -    private Collator getCollator(){
  +    protected Collator getCollator(){
           Collator collator = Collator.getInstance();
           if ( this.getEntryLoadRequest() != null ){
               Locale locale = null;
  @@ -850,13 +859,4 @@
           return collator;
       }
   
  -    public String toString() {
  -        StringBuffer buf = new StringBuffer();
  -        if (result != null) {
  -            buf.append("Result:");
  -            buf.append(result);
  -        }
  -        return buf.toString();
  -    }
  -
   }
  
  
  
  Index: ContainerSorterByContainerDefinition.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/data/containers/ContainerSorterByContainerDefinition.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ContainerSorterByContainerDefinition.java 28 Apr 2005 14:06:24 -0000      
1.8
  +++ ContainerSorterByContainerDefinition.java 28 Apr 2005 14:57:36 -0000      
1.9
  @@ -763,7 +763,7 @@
        *  If the entryLoadRequest is null, the localtor is instantiated with 
the default locale of the system
        * @return
        */
  -    private Collator getCollator(){
  +    protected Collator getCollator(){
           Collator collator = Collator.getInstance();
           if ( this.getEntryLoadRequest() != null ){
               Locale locale = null;
  

Reply via email to