Author: cmailleux
Date: Thu Jul 12 16:42:47 2007
New Revision: 17965
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17965&repname=
=3Djahia
Log:
Port of commit [16859] Resolve issue for cofidis ContainerFilterByCategorie=
s is not working for a particular site
Modified:
trunk/core/src/java/org/jahia/data/containers/ContainerFilterByCategori=
es.java
Modified: trunk/core/src/java/org/jahia/data/containers/ContainerFilterByCa=
tegories.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/data/containers/ContainerFilterByCategories.java&rev=3D17965&repna=
me=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/data/containers/ContainerFilterByCategori=
es.java (original)
+++ trunk/core/src/java/org/jahia/data/containers/ContainerFilterByCategori=
es.java Thu Jul 12 16:42:47 2007
@@ -14,21 +14,13 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied=
. =
* See the License for the specific language governing permissions and =
* limitations under the License.
- *///
-//
-//
-//
-
-
+ */
package org.jahia.data.containers;
=
=
-import java.io.Serializable;
-import java.util.*;
-
-import org.jahia.content.ObjectKey;
-import org.jahia.content.ContentDefinition;
import org.jahia.content.ContentContainerKey;
+import org.jahia.content.ContentDefinition;
+import org.jahia.content.ObjectKey;
import org.jahia.exceptions.JahiaException;
import org.jahia.registries.ServicesRegistry;
import org.jahia.services.categories.Category;
@@ -36,36 +28,37 @@
import org.jahia.services.search.JahiaSearchConstant;
import org.jahia.services.version.EntryLoadRequest;
=
+import java.io.Serializable;
+import java.util.*;
=
=
/**
* A filter used to returns all containers in given categories.
* Same container definition name
*
+ * @author Khue Nguyen <a href=3D"mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
+ * @corrector C=C3=83=C2=A9dric Mailleux <a href=3D"mailto:[EMAIL PROTECTED]
.org">[EMAIL PROTECTED]</a>
* @see FilterClause
* @see ContainerFilters
* @see JahiaContainerSet
- * @author Khue Nguyen <a href=3D"mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
*/
-public class ContainerFilterByCategories implements Serializable, Containe=
rFilterInterface{
+public class ContainerFilterByCategories implements Serializable, Containe=
rFilterInterface {
=
private static org.apache.log4j.Logger logger =3D
- org.apache.log4j.Logger.getLogger(ContainerFilterByCategories.clas=
s);
+ org.apache.log4j.Logger.getLogger(ContainerFilterByCategories.=
class);
=
private EntryLoadRequest entryLoadRequest =3D EntryLoadRequest.CURRENT;
=
- private String containerDefinitionName;
-
private ContainerFilters containerFilters =3D null;
=
- private Set catetories;
+ private Set categories;
=
private boolean withAllContainersOfCompoundContainerList =3D false;
=
//--------------------------------------------------------------------=
------
/**
* Constructor
- *
+ * <p/>
* if withAllContainersOfCompoundContainerList =3D true,
* return all containers of the compound container list ( allowing
* to return the containers without any category
@@ -74,18 +67,20 @@
* @param jParams
* @param entryLoadRequest
* @param withAllContainersOfCompoundContainerList
+ *
*/
public ContainerFilterByCategories(Set categories,
EntryLoadRequest entryLoadRequest,
- boolean withAllContainersOfCompound=
ContainerList){
+ boolean withAllContainersOfCompound=
ContainerList) {
=
- if ( entryLoadRequest !=3D null ){
+ if (entryLoadRequest !=3D null) {
this.entryLoadRequest =3D entryLoadRequest;
}
- this.catetories =3D categories;
- if ( categories =3D=3D null ){
- categories =3D new HashSet();
- }
+ if (categories =3D=3D null) {
+ this.categories =3D new HashSet();
+ } else
+ this.categories =3D categories;
+
this.withAllContainersOfCompoundContainerList =3D
withAllContainersOfCompoundContainerList;
}
@@ -99,13 +94,8 @@
* @return BitSet bits, the expected result as a bit set of matching c=
tn ids,each bit position set to true correspond to matching ctn ids.
*/
public BitSet doFilter(int ctnListID)
- throws JahiaException
- {
- BitSet result =3D null;
-
- result =3D doFiltering(ctnListID);
-
- return result;
+ throws JahiaException {
+ return doFiltering(ctnListID);
}
=
//--------------------------------------------------------------------=
------
@@ -116,30 +106,29 @@
* @return BitSet bits, the expected result as a bit set of matching c=
tn ids,each bit position set to true correspond to matching ctn ids.
*/
private BitSet doFiltering(int ctnListID)
- throws JahiaException
- {
+ throws JahiaException {
BitSet result =3D new BitSet();
try {
- List containers =3D getContainers(this.catetories);
+ List containers =3D getContainers(this.categories, -1, null); =
// all sites search
int size =3D containers.size();
- for ( int i=3D0 ; i<size; i++ ){
+ for (int i =3D 0; i < size; i++) {
ContentContainer contentContainer =3D
- (ContentContainer)containers.get(i);
- if ( contentContainer.getParentContainerListID() =3D=3D ct=
nListID ){
+ (ContentContainer) containers.get(i);
+ if (contentContainer.getParentContainerListID() =3D=3D ctn=
ListID) {
result.set(contentContainer.getID());
}
}
- }catch ( Throwable t ){
- logger.debug("Exception :",t);
+ } catch (Throwable t) {
+ logger.debug("Exception :", t);
}
=
- if ( this.withAllContainersOfCompoundContainerList ){
+ if (this.withAllContainersOfCompoundContainerList) {
int ctnListId =3D this.containerFilters.getCtnListID();
Vector ids =3D ServicesRegistry.getInstance().getJahiaContaine=
rsService()
- .getctnidsInList(ctnListId,this.entryLoadRequest);
+ .getctnidsInList(ctnListId, this.entryLoadRequest);
int size =3D ids.size();
- for ( int i=3D0 ; i<size; i++ ){
- Integer I =3D (Integer)ids.get(i);
+ for (int i =3D 0; i < size; i++) {
+ Integer I =3D (Integer) ids.get(i);
result.set(I.intValue());
}
}
@@ -159,13 +148,12 @@
* @param int ctnListID, the container list id
* @return String , the sql statement. Null on error
*/
- public String getSelect(int ctnListID)
- {
+ public String getSelect(int ctnListID) {
String loadRequest =3D "";
- if ( this.entryLoadRequest !=3D null ){
- loadRequest =3D this.entryLoadRequest.toString();
+ if (this.entryLoadRequest !=3D null) {
+ loadRequest =3D this.entryLoadRequest.toString();
}
- return (getCategoriesSearchQuery() + "_" + loadRequest);
+ return (getCategoriesSearchQuery() + "_" + loadRequest);
}
=
//--------------------------------------------------------------------=
------
@@ -175,81 +163,72 @@
* @return
* @throws JahiaException
*/
- public void setContainerFilters(ContainerFilters containerFilters){
+ public void setContainerFilters(ContainerFilters containerFilters) {
this.containerFilters =3D containerFilters;
}
=
//--------------------------------------------------------------------=
------
/**
* Perform filtering on a given site or all sites
- *
+ * <p/>
* The expected result is a bit set of matching container ids.
- *
+ * <p/>
* If siteId =3D -1 , returns results from all sites
- *
+ * <p/>
* If the containerDefinitionName is null, return result from all cont=
ainers
* no regards to it definition !
*
- * @todo : actually, return all containers no distinction of type
- *
* @param siteId
* @param containerDefinitionName
* @return BitSet bits, the expected result as a bit set of matching c=
tn ids,each bit position set to true correspond to matching ctn ids.
* @throws JahiaException
*/
public BitSet doFilterBySite(int siteId, String containerDefinitionNam=
e, int listId)
- throws JahiaException
- {
-
- BitSet result =3D null;
- result =3D doFilteringBySite(siteId, containerDefinitionName,listI=
d);
- return result;
+ throws JahiaException {
+ return doFilteringBySite(siteId, containerDefinitionName, listId);
}
=
//--------------------------------------------------------------------=
------
/**
- *
* The expected result is a bit set of matching container ids for a gi=
ven siteId.
* if siteId =3D -1 , return result from all sites
- *
+ * <p/>
* If the containerDefinitionName is null, return result from all cont=
ainers
* no regards to it definition !
*
- *
* @param siteId
* @return BitSet bits, the expected result as a bit set of matching c=
tn ids,each bit position set to true correspond to matching ctn ids.
* @throws JahiaException
*/
private BitSet doFilteringBySite(int siteId,
- String containerDefinitionName,int listId)
- throws JahiaException
- {
+ String containerDefinitionName, int l=
istId)
+ throws JahiaException {
BitSet result =3D new BitSet();
try {
- List containers =3D getContainers(this.catetories);
+ List containers =3D getContainers(this.categories, siteId, con=
tainerDefinitionName);
int size =3D containers.size();
- for ( int i=3D0 ; i<size; i++ ){
+ for (int i =3D 0; i < size; i++) {
ContentContainer contentContainer =3D
- (ContentContainer)containers.get(i);
+ (ContentContainer) containers.get(i);
=
result.set(contentContainer.getID());
}
- }catch ( Throwable t ){
- logger.debug("Exception :",t);
+ } catch (Throwable t) {
+ logger.debug("Exception :", t);
}
=
- if ( this.withAllContainersOfCompoundContainerList ){
+ if (this.withAllContainersOfCompoundContainerList) {
Vector ids =3D ServicesRegistry.getInstance().getJahiaContaine=
rsService()
- .getctnidsInList(listId,this.entryLoadRequest);
+ .getctnidsInList(listId, this.entryLoadRequest);
int size =3D ids.size();
- for ( int i=3D0 ; i<size; i++ ){
- Integer I =3D (Integer)ids.get(i);
+ for (int i =3D 0; i < size; i++) {
+ Integer I =3D (Integer) ids.get(i);
result.set(I.intValue());
}
}
ContainerFilterByLoadRequest cfblr =3D
new ContainerFilterByLoadRequest(this.entryLoadRequest);
- BitSet result2 =3D cfblr.doFilterBySite(siteId,containerDefinition=
Name,listId);
+ BitSet result2 =3D cfblr.doFilterBySite(siteId, containerDefinitio=
nName, listId);
result.and(result2);
return result;
}
@@ -258,7 +237,7 @@
/**
* Return the select statement, build with the clauses for a given sit=
e.
* If siteId =3D -1 -> build query for all sites
- *
+ * <p/>
* If the containerDefinitionName is null, return result from all cont=
ainers
* no regards to it definition !
*
@@ -266,51 +245,50 @@
* @param containerDefinitionName
* @return
*/
- public String getSelectBySiteID(int siteId, String containerDefinition=
Name)
- {
+ public String getSelectBySiteID(int siteId, String containerDefinition=
Name) {
// It's a dummy select
String loadRequest =3D "";
- if ( this.entryLoadRequest !=3D null ){
- loadRequest =3D this.entryLoadRequest.toString();
+ if (this.entryLoadRequest !=3D null) {
+ loadRequest =3D this.entryLoadRequest.toString();
}
- return (getCategoriesSearchQuery() + "_" + loadRequest);
+ return (getCategoriesSearchQuery() + "_" + loadRequest);
}
=
- private List getContainers(Set categories)
- throws JahiaException {
+ private List getContainers(Set categories, int siteId, String containe=
rDefinitionName)
+ throws JahiaException {
=
List val =3D new ArrayList();
Iterator iterator =3D categories.iterator();
- Category category =3D null;
- while ( iterator.hasNext() ){
- category =3D (Category)iterator.next();
+ Category category;
+ while (iterator.hasNext()) {
+ category =3D (Category) iterator.next();
List allChildrenObjectKeys =3D category.getChildObjectKeys();
Iterator allChildObjectKeysIter =3D allChildrenObjectKeys.iter=
ator();
while (allChildObjectKeysIter.hasNext()) {
ObjectKey curObjectKey =3D (ObjectKey) allChildObjectKeysI=
ter.
- next();
+ next();
if (curObjectKey.getType().equals(ContentContainerKey.CONT=
AINER_TYPE)) {
try {
ContentContainer contentContainer =3D
- (ContentContainer)ContentContainer.getInst=
ance(curObjectKey);
- if ( contentContainer !=3D null ){
- if ( containerDefinitionName !=3D null ) {
+ (ContentContainer) ContentContainer.getIns=
tance(curObjectKey);
+ if (contentContainer !=3D null && (siteId =3D=3D -=
1 || siteId =3D=3D contentContainer.getSiteID())) {
+ if (containerDefinitionName !=3D null) {
try {
ContentDefinition definition =3D Conte=
ntDefinition
.getContentDefinitionInstance(=
contentContainer.getDefinitionKey(null));
- if ( definition !=3D null &&
- containerDefinitionName.equals=
IgnoreCase(definition.getName()) ){
+ if (definition !=3D null && containerD=
efinitionName.equalsIgnoreCase(
+ definition.getName())) {
val.add(contentContainer);
}
- } catch ( Throwable t) {
+ } catch (Throwable t) {
logger.debug("Error retrieving contain=
er definition for container "
- + contentContainer.getID(),t);
+ + contentContainer.getID(=
), t);
}
} else {
val.add(contentContainer);
}
}
- } catch (Throwable t){
+ } catch (Throwable t) {
logger.debug("Error loading contentContainer " + c=
urObjectKey.toString());
}
}
@@ -319,17 +297,17 @@
return val;
}
=
- private String getCategoriesSearchQuery(){
+ private String getCategoriesSearchQuery() {
StringBuffer buff =3D new StringBuffer("(");
- Iterator iterator =3D this.catetories.iterator();
- while ( iterator.hasNext() ){
- Category cat =3D (Category)iterator.next();
+ Iterator iterator =3D this.categories.iterator();
+ while (iterator.hasNext()) {
+ Category cat =3D (Category) iterator.next();
buff.append(JahiaSearchConstant.CATEGORY_ID);
buff.append(":");
- if ( cat !=3D null ){
+ if (cat !=3D null) {
buff.append(cat.getKey());
}
- if ( iterator.hasNext() ){
+ if (iterator.hasNext()) {
buff.append(" OR ");
}
}
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list