Author: knguyen
Date: Mon Sep  3 13:09:53 2007
New Revision: 18354

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D18354&repname=
=3Djahia
Log:
Add indexation rule Page Path Condition allowing matching of content by Sub=
tree. =


Added:
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/search/in=
dexingscheduler/impl/condition/ContentPagePathRuleCondition.java

Added: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/search=
/indexingscheduler/impl/condition/ContentPagePathRuleCondition.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-5-0-SP-BRANCH/core/src/java/org/jahia/services/search/indexingscheduler/im=
pl/condition/ContentPagePathRuleCondition.java&rev=3D18354&repname=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
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/search/in=
dexingscheduler/impl/condition/ContentPagePathRuleCondition.java (added)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/search/in=
dexingscheduler/impl/condition/ContentPagePathRuleCondition.java Mon Sep  3=
 13:09:53 2007
@@ -0,0 +1,107 @@
+package org.jahia.services.search.indexingscheduler.impl.condition;
+
+import org.jahia.services.search.indexingscheduler.RuleCondition;
+import org.jahia.services.search.indexingscheduler.RuleEvaluationContext;
+import org.jahia.services.search.valves.SearchIndexProcessValveUtils;
+import org.jahia.services.pages.ContentPage;
+import org.jahia.services.version.EntryLoadRequest;
+import org.jahia.exceptions.JahiaException;
+import org.jahia.content.ContentObject;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * A Rule that matches agains the action being performed
+ *
+ * User: hollis
+ * Date: 23 ao=C3=BBt 2007
+ * Time: 15:05:48
+ * To change this template use File | Settings | File Templates.
+ */
+public class ContentPagePathRuleCondition implements RuleCondition {
+
+    private static org.apache.log4j.Logger logger =3D
+        org.apache.log4j.Logger.getLogger(ContentPagePathRuleCondition.cla=
ss);
+
+    private List parentNodePages =3D new ArrayList();
+    private List contentPagePaths =3D null;
+    public ContentPagePathRuleCondition() {
+    }
+
+    public ContentPagePathRuleCondition(List parentNodePages) {
+        this();
+        this.parentNodePages =3D parentNodePages;
+        loadContentPagePaths();
+    }
+
+    public boolean evaluate(RuleEvaluationContext ctx) throws JahiaExcepti=
on {
+        if ( contentPagePaths =3D=3D null ){
+            synchronized(ContentPagePathRuleCondition.class){
+                if ( contentPagePaths =3D=3D null ){
+                    loadContentPagePaths();
+                }
+            }
+        }
+        if ( contentPagePaths =3D=3D null || contentPagePaths.isEmpty() ){
+            return false;
+        }
+        String pagePath =3D null;
+        String objectPagePath =3D null;
+        ContentObject contentObject =3D ctx.getContentObject();
+        if ( contentObject =3D=3D null ){
+            try {
+                contentObject =3D ContentObject.getContentObjectInstance(c=
tx.getObjectKey());
+            } catch ( Throwable t ){
+                logger.debug("Error retrieving contentObject " + ctx.getOb=
jectKey(),t);
+                return false;
+            }
+        }
+        if ( contentObject =3D=3D null ){
+            return false;
+        }
+        objectPagePath =3D SearchIndexProcessValveUtils.buildContentPagePa=
th(contentObject,
+                EntryLoadRequest.STAGING_WORKFLOW_STATE);
+        if ( objectPagePath =3D=3D null ){
+            return false;
+        }
+        for(Iterator it=3D contentPagePaths.iterator(); it.hasNext();){
+            pagePath =3D (String)it.next();
+            if (objectPagePath.startsWith(pagePath)){
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public List getParentNodePages() {
+        return parentNodePages;
+    }
+
+    public void setParentNodePages(List parentNodePages) {
+        this.parentNodePages =3D parentNodePages;
+        if ( this.parentNodePages =3D=3D null ){
+            this.parentNodePages =3D new ArrayList();
+        }
+    }
+
+    protected void loadContentPagePaths(){
+        contentPagePaths =3D new ArrayList();
+        String id =3D null;
+        String pagePath =3D null;
+        for(Iterator it=3D parentNodePages.iterator(); it.hasNext();){
+            id =3D (String)it.next();
+            try {
+                ContentPage contentPage =3D ContentPage.getPage(Integer.pa=
rseInt(id));
+                pagePath =3D SearchIndexProcessValveUtils.buildContentPage=
Path(contentPage,
+                        EntryLoadRequest.STAGING_WORKFLOW_STATE);
+                if ( pagePath !=3D null ){
+                    contentPagePaths.add(pagePath);
+                }
+            } catch ( Throwable t ) {
+                logger.debug("Exception occurred evaluating content page p=
ath for page id=3D" + id);
+            }
+        }
+    }
+}

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to