KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > containers > ContainerFilterByLoadRequest


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
//
14
//
15
//
16

17
18 package org.jahia.data.containers;
19
20
21 import java.util.Vector JavaDoc;
22
23 import org.jahia.exceptions.JahiaException;
24 import org.jahia.registries.*;
25 import org.jahia.services.version.EntryLoadRequest;
26 import java.io.Serializable JavaDoc;
27 import java.util.BitSet JavaDoc;
28
29
30
31 /**
32  * This filter can be used to filter containers that exists for a given
33  * EntryLoadRequest :
34  *
35  * - live, staging workflow mode...
36  * - multi-langue
37  *
38  * @see ContainerFilters
39  * @see JahiaContainerSet
40  * @author Khue Nguyen <a HREF="mailto:khue@jahia.org">khue@jahia.org</a>
41  */

42 public class ContainerFilterByLoadRequest implements Serializable JavaDoc, ContainerFilterInterface{
43
44     private static org.apache.log4j.Logger logger =
45         org.apache.log4j.Logger.getLogger(ContainerFilterByCategories.class);
46
47     private EntryLoadRequest entryLoadRequest = EntryLoadRequest.CURRENT;
48
49     private ContainerFilters containerFilters = null;
50
51     //--------------------------------------------------------------------------
52
/**
53      * Constructor
54      *
55      * @param entryLoadRequest
56      */

57     public ContainerFilterByLoadRequest(EntryLoadRequest entryLoadRequest){
58
59         if ( entryLoadRequest != null ){
60             this.entryLoadRequest = entryLoadRequest;
61         }
62     }
63
64     //--------------------------------------------------------------------------
65
/**
66      * Perform filtering.
67      * The expected result is a bit set of matching container ids.
68      *
69      * @param int ctnListID, the container list id
70      * @return BitSet bits, the expected result as a bit set of matching ctn ids,each bit position set to true correspond to matching ctn ids.
71      */

72     public BitSet JavaDoc doFilter(int ctnListID)
73     throws JahiaException
74     {
75         BitSet JavaDoc result = null;
76
77         result = doFiltering(ctnListID);
78
79         return result;
80     }
81
82     //--------------------------------------------------------------------------
83
/**
84      * The expected result is a bit set of matching container ids.
85      *
86      * @param int ctnListID, the container list id
87      * @return BitSet bits, the expected result as a bit set of matching ctn ids,each bit position set to true correspond to matching ctn ids.
88      */

89     private BitSet JavaDoc doFiltering(int ctnListID)
90     throws JahiaException
91     {
92         BitSet JavaDoc result = new BitSet JavaDoc();
93         Vector JavaDoc ids = ServicesRegistry.getInstance().getJahiaContainersService()
94                 .getctnidsInList(ctnListID,this.entryLoadRequest);
95         int size = ids.size();
96         for (int i=0; i<size; i++){
97             Integer JavaDoc I = (Integer JavaDoc)ids.get(i);
98             result.set(I.intValue());
99         }
100         return result;
101     }
102
103     //--------------------------------------------------------------------------
104
/**
105      * Return the select statement, build with the clauses for all container list of the site.
106      *
107      * @param int ctnListID, the container list id
108      * @return String , the sql statement. Null on error
109      */

110     public String JavaDoc getSelect(int ctnListID)
111     {
112         return ctnListID + "_" + this.entryLoadRequest.toString();
113     }
114
115     //--------------------------------------------------------------------------
116
/**
117      * Set reference to a containerFilters
118      *
119      * @return
120      * @throws JahiaException
121      */

122     public void setContainerFilters(ContainerFilters containerFilters){
123         this.containerFilters = containerFilters;
124     }
125
126     //--------------------------------------------------------------------------
127
/**
128      * Perform filtering on a given site or all sites
129      *
130      * The expected result is a bit set of matching container ids.
131      *
132      * If siteId = -1 , returns results from all sites
133      *
134      * If the containerDefinitionName is null, return result from all containers
135      * no regards to it definition !
136      *
137      * @todo : actually, return all containers no distinction of type
138      *
139      * @param siteId
140      * @param containerDefinitionName
141      * @return BitSet bits, the expected result as a bit set of matching ctn ids,each bit position set to true correspond to matching ctn ids.
142      * @throws JahiaException
143      */

144     public BitSet JavaDoc doFilterBySite(int siteId, String JavaDoc containerDefinitionName, int listId)
145     throws JahiaException
146     {
147
148         BitSet JavaDoc result = null;
149         result = doFilteringBySite(siteId, containerDefinitionName);
150         return result;
151     }
152
153     //--------------------------------------------------------------------------
154
/**
155      * siteId and containerDefinitionName are ignored here
156      *
157      * @param siteId
158      * @return BitSet bits, the expected result as a bit set of matching ctn ids,each bit position set to true correspond to matching ctn ids.
159      * @throws JahiaException
160      */

161     private BitSet JavaDoc doFilteringBySite(int siteId,
162             String JavaDoc containerDefinitionName)
163     throws JahiaException
164     {
165         BitSet JavaDoc result = new BitSet JavaDoc();
166         Vector JavaDoc ids = ServicesRegistry.getInstance().getJahiaContainersService()
167                    .getCtnIds(this.entryLoadRequest);
168         int size = ids.size();
169         for (int i=0; i<size; i++){
170             Integer JavaDoc I = (Integer JavaDoc)ids.get(i);
171             result.set(I.intValue());
172         }
173         return result;
174     }
175
176     //--------------------------------------------------------------------------
177
/**
178      * Return the select statement, build with the clauses for a given site.
179      * If siteId = -1 -> build query for all sites
180      *
181      * If the containerDefinitionName is null, return result from all containers
182      * no regards to it definition !
183      *
184      * @param siteId
185      * @param containerDefinitionName
186      * @return
187      */

188     public String JavaDoc getSelectBySiteID(int siteId, String JavaDoc containerDefinitionName)
189     {
190         // It's a dummy select
191
return siteId + "_" + containerDefinitionName + "_"
192                 + this.entryLoadRequest.toString();
193     }
194
195 }
196
Popular Tags