Author: ktlili
Date: Sun Nov 25 20:27:34 2007
New Revision: 19283

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D19283&repname=
=3Djahia
Log:
- commit portlets categories( admin view ): classes + engines

Added:
    trunk/core/src/java/org/jahia/engines/applications/ManageApplicationCat=
egoriesEngine.java
Modified:
    trunk/core/src/java/org/jahia/engines/applications/Application_Engine.j=
ava
    trunk/core/src/java/org/jahia/engines/shared/Application_Field.java

Modified: trunk/core/src/java/org/jahia/engines/applications/Application_En=
gine.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/engines/applications/Application_Engine.java&rev=3D19283&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
--- trunk/core/src/java/org/jahia/engines/applications/Application_Engine.j=
ava (original)
+++ trunk/core/src/java/org/jahia/engines/applications/Application_Engine.j=
ava Sun Nov 25 20:27:34 2007
@@ -14,10 +14,12 @@
  * 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.engines.applications;
+ */
+package org.jahia.engines.applications;
 =

 import org.jahia.data.JahiaData;
 import org.jahia.data.applications.ApplicationBean;
+import org.jahia.data.applications.EntryPointDefinition;
 import org.jahia.engines.EngineToolBox;
 import org.jahia.engines.JahiaEngine;
 import org.jahia.engines.audit.ManageLogs_Engine;
@@ -36,6 +38,8 @@
 import org.jahia.security.license.LicenseActionChecker;
 =

 import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
 =

 /**
  * Engine for editing and setting rights on template
@@ -49,6 +53,7 @@
 =

     // the temporary template to hold change until they have to be saved.
     public static final String TEMPORARY_APPLICATION_SESSION_NAME =3D "the=
TemporaryApplication";
+    public static final String PORTLETS_CATEGORIES_MAP_ATTR =3D "portletCa=
tegoriesMap";
 =

     private static Application_Engine instance;
     public static final String ENGINE_NAME =3D "application";
@@ -65,6 +70,7 @@
     private final String EDIT_STR =3D "edit";
     private final String SAVE_STR =3D "save";
     private final String CANCEL_STR =3D "cancel";
+    private final String OPEN_CATEGORIES =3D "open_categories";
     private final String LOGS_STR =3D "logs";
     private final String APPLY_STR =3D "apply";
     private final String CLOSE_STR =3D "close";
@@ -104,8 +110,8 @@
             throws JahiaException {
         ApplicationBean application =3D (ApplicationBean) theObj;
         String params =3D "?mode=3Ddisplay&appid=3D" + application.getID();
-        if(jParams instanceof ParamBean) {
-            if(((ParamBean) jParams).getRequest().getAttribute("showAllCom=
ponents")!=3Dnull) {
+        if (jParams instanceof ParamBean) {
+            if (((ParamBean) jParams).getRequest().getAttribute("showAllCo=
mponents") !=3D null) {
                 params +=3D "&showAllSites=3Dtrue";
             }
         }
@@ -127,8 +133,8 @@
      */
     public EngineValidationHelper handleActions(ProcessingContext jParams,=
 JahiaData jData)
             throws JahiaException,
-                   JahiaSessionExpirationException,
-                   JahiaForbiddenAccessException {
+            JahiaSessionExpirationException,
+            JahiaForbiddenAccessException {
         // initalizes the hashmap
         HashMap engineMap =3D initEngineMap(jParams);
 =

@@ -137,13 +143,14 @@
         JahiaUser theUser =3D jParams.getUser();
 =

         if (theApplication.getACL().getPermission(null, null, theUser, Jah=
iaBaseACL.ADMIN_RIGHTS, false, jParams.getSiteID()) &&
-            LicenseActionChecker.isAuthorizedByLicense("org.jahia.actions.=
server.admin.components.ManageComponentRights", 0)) {
+                LicenseActionChecker.isAuthorizedByLicense("org.jahia.acti=
ons.server.admin.components.ManageComponentRights", 0)) {
             engineMap.put(ADMIN_ACCESS_STR, Boolean.TRUE);
             engineMap.put("enableAuthoring", Boolean.TRUE);
             engineMap.put("enableRightView", Boolean.TRUE);
             engineMap.put(WRITE_ACCESS_STR, Boolean.TRUE);
 =

-        } else if (theApplication.getACL().getPermission(null, null, theUs=
er, JahiaBaseACL.WRITE_RIGHTS, false, jParams.getSiteID())) {
+        } else
+        if (theApplication.getACL().getPermission(null, null, theUser, Jah=
iaBaseACL.WRITE_RIGHTS, false, jParams.getSiteID())) {
             engineMap.put("enableAuthoring", Boolean.TRUE);
             engineMap.put(WRITE_ACCESS_STR, Boolean.TRUE);
         }
@@ -179,7 +186,7 @@
      */
     public void processLastScreen(ProcessingContext jParams, HashMap engin=
eMap)
             throws JahiaException,
-                   JahiaForbiddenAccessException {
+            JahiaForbiddenAccessException {
         ApplicationBean theApplication =3D (ApplicationBean) engineMap.get=
(Application_Engine.APPLICATION_SESSION_NAME);
 =

         // gets the last screen
@@ -221,7 +228,7 @@
      */
     public void processCurrentScreen(ProcessingContext jParams, HashMap en=
gineMap)
             throws JahiaException,
-                   JahiaForbiddenAccessException {
+            JahiaForbiddenAccessException {
         // gets the current screen
         // screen   =3D edit, rights, logs
         String theScreen =3D (String) engineMap.get(SCREEN_STR);
@@ -260,6 +267,13 @@
             Application_Engine.logger.debug("Saving !!");
         } else if (theScreen.equals(CANCEL_STR)) {
             engineMap.put(ENGINE_OUTPUT_FILE_PARAM, JahiaEngine.CANCEL_JSP=
);
+        } else if (theScreen.equals(OPEN_CATEGORIES)) {
+            engineMap.put(SCREEN_STR, jParams.getParameter(LASTSCREEN_STR)=
);
+            String[] objectIDs =3D jParams.getParameterValues("objectIDs");
+            if (objectIDs !=3D null && objectIDs.length > -1) {
+                engineMap.put("openCategoriesManager", Boolean.TRUE);
+                jParams.getSessionState().setAttribute("objectIDs", object=
IDs);
+            }
         }
     }
 =

@@ -271,14 +285,14 @@
      */
     private HashMap initEngineMap(ProcessingContext jParams)
             throws JahiaException,
-                   JahiaSessionExpirationException {
+            JahiaSessionExpirationException {
 =

         HashMap engineMap =3D new HashMap();
         ApplicationBean theApplication;
-        boolean showAllsites=3Dfalse;
-        if(jParams instanceof ParamBean) {
-            if(((ParamBean) jParams).getRequest().getParameter("showAllSit=
es")!=3Dnull) {
-                showAllsites=3Dtrue;
+        boolean showAllsites =3D false;
+        if (jParams instanceof ParamBean) {
+            if (((ParamBean) jParams).getRequest().getParameter("showAllSi=
tes") !=3D null) {
+                showAllsites =3D true;
             }
         }
         // gets session values
@@ -307,19 +321,23 @@
             // init the temporary template bean
             ApplicationBean theTemporaryApplication =3D
                     new ApplicationBean(theApplication.getID(), theApplica=
tion.getName(),
-                                        theApplication.getContext(), theAp=
plication.getVisibleStatus(),
-                                        theApplication.isShared(), theAppl=
ication.getRights(),
-                                        theApplication.getFilename(), theA=
pplication.getdesc(), theApplication.getType());
+                            theApplication.getContext(), theApplication.ge=
tVisibleStatus(),
+                            theApplication.isShared(), theApplication.getR=
ights(),
+                            theApplication.getFilename(), theApplication.g=
etdesc(), theApplication.getType());
+
+            // category of portlets
+            Map portletsCategoriesMap =3D computePortletCategoriesMap(theT=
emporaryApplication);
 =

             // init session
             engineMap.put(Application_Engine.APPLICATION_SESSION_NAME, the=
Application);
             engineMap.put(Application_Engine.TEMPORARY_APPLICATION_SESSION=
_NAME, theTemporaryApplication);
+            engineMap.put(Application_Engine.PORTLETS_CATEGORIES_MAP_ATTR,=
 portletsCategoriesMap);
         }
 =

         engineMap.put(RENDER_TYPE_PARAM, new Integer(JahiaEngine.RENDERTYP=
E_FORWARD));
         engineMap.put(ENGINE_NAME_PARAM, Application_Engine.ENGINE_NAME);
         String value =3D jParams.composeEngineUrl(Application_Engine.ENGIN=
E_NAME, "?appid=3D" + theApplication.getID());
-        if(showAllsites) {
+        if (showAllsites) {
             value +=3D "&showAllSites=3Dtrue";
         }
         engineMap.put(ENGINE_URL_PARAM, value);
@@ -337,12 +355,12 @@
         } else {
             engineMap.put(JSPSOURCE_STR, Application_Engine.APPLICATION_JS=
P);
         }
-        if(!showAllsites)
-            engineMap.put("restrictRightsToSite",new Integer(jParams.getSi=
teID()));
+        if (!showAllsites)
+            engineMap.put("restrictRightsToSite", new Integer(jParams.getS=
iteID()));
         else {
-            engineMap.put("showSiteKey",Boolean.TRUE);
-            engineMap.put("selectSiteInSelectUsrGrp",Boolean.TRUE);
-            engineMap.put("showAdminGroups",Boolean.TRUE);
+            engineMap.put("showSiteKey", Boolean.TRUE);
+            engineMap.put("selectSiteInSelectUsrGrp", Boolean.TRUE);
+            engineMap.put("showAdminGroups", Boolean.TRUE);
         }
         // sets engineMap for JSPs
         jParams.setAttribute(ENGINE_NAME_PARAM, "Manage Templates");
@@ -403,13 +421,13 @@
 =

         // check data integrity
         if (theTemporaryApplication.getName() =3D=3D null
-            || theTemporaryApplication.getName().trim().equals(EMPTY_STRIN=
G))
+                || theTemporaryApplication.getName().trim().equals(EMPTY_S=
TRING))
             warningMsg.append("<lu><li>The name is required.<br>");
 =

         if (!warningMsg.toString().equals(EMPTY_STRING)) {
             warningMsg.append("</lu>");
             jParams.setAttribute("Template_Engine.warningMsg",
-                                 warningMsg.toString());
+                    warningMsg.toString());
             return false;
         }
 =

@@ -423,4 +441,27 @@
 =

     }
 =

+    private Map computePortletCategoriesMap(ApplicationBean theTemporaryAp=
plication) throws JahiaException {
+        // build portletUniqueId string
+        List definitions =3D theTemporaryApplication.getEntryPointDefiniti=
ons();
+        String[] portletIDs =3D new String[definitions.size()];
+        for (int i =3D 0; i < definitions.size(); i++) {
+            EntryPointDefinition definition =3D (EntryPointDefinition) def=
initions.get(i);
+            String appID;
+            // get name and id of the current portlet Definition
+            String definitionName =3D "";
+            String uniqueID =3D "";
+            if (definition !=3D null) {
+                definitionName =3D definition.getName();
+                appID =3D "" + definition.getApplicationID();
+                uniqueID =3D appID + "::" + definitionName;
+            }
+            portletIDs[i] =3D uniqueID;
+        }
+        // build category Map. User methods of ManaApplicationCategorieEng=
ine
+        Object[] results =3D ManageApplicationCategoriesEngine.getInstance=
().loadSelectedEntryPointDefinitons(portletIDs);
+        Map portletsCategoriesMap =3D (Map) results[2];
+        return portletsCategoriesMap;
+    }
+
 }

Added: trunk/core/src/java/org/jahia/engines/applications/ManageApplication=
CategoriesEngine.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/trunk/core/src=
/java/org/jahia/engines/applications/ManageApplicationCategoriesEngine.java=
&rev=3D19283&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
--- trunk/core/src/java/org/jahia/engines/applications/ManageApplicationCat=
egoriesEngine.java (added)
+++ trunk/core/src/java/org/jahia/engines/applications/ManageApplicationCat=
egoriesEngine.java Sun Nov 25 20:27:34 2007
@@ -0,0 +1,552 @@
+package org.jahia.engines.applications;
+
+import org.jahia.engines.JahiaEngine;
+import org.jahia.engines.EngineToolBox;
+import org.jahia.engines.validation.EngineValidationHelper;
+import org.jahia.params.ProcessingContext;
+import org.jahia.exceptions.JahiaException;
+import org.jahia.exceptions.JahiaForbiddenAccessException;
+import org.jahia.data.JahiaData;
+import org.jahia.data.applications.ApplicationBean;
+import org.jahia.data.applications.EntryPointDefinition;
+import org.jahia.data.applications.EntryPointObjectKey;
+import org.jahia.registries.ServicesRegistry;
+import org.jahia.services.categories.Category;
+import org.jahia.content.ObjectKey;
+import org.jahia.content.ObjectLink;
+import org.jahia.content.CategoryKey;
+
+import java.util.*;
+
+/**
+ * Engine for categorising portlet
+ *
+ * @author ktlili
+ */
+public class ManageApplicationCategoriesEngine implements JahiaEngine {
+    // logger
+    private static final org.apache.log4j.Logger logger =3D org.apache.log=
4j.Logger.getLogger(ManageApplicationCategoriesEngine.class);
+
+    // unique instance
+    private static ManageApplicationCategoriesEngine instance;
+
+    // engine properties
+    private final String JSPSOURCE_STR =3D "jspSource";
+    private static final String ENGINE_JSP =3D "application_manage_categor=
ies";
+    private static final String ENGINE_NAME =3D "portletCategories";
+    private EngineToolBox toolBox;
+
+    // sreen
+    private final String SCREEN_STR =3D "screen";
+    private final String SAVE_STR =3D "save";
+    private final String EDIT_STR =3D "edit";
+    private final String CANCEL_STR =3D "cancel";
+    private final String APPLY_STR =3D "apply";
+    private final String CLOSE_STR =3D "close";
+
+    //categories parameter
+    public static final String PORLET_CATEGORIES =3D "portletCategories";
+    public static final String PORLET_CATEGORIES_TRUE =3D "true";
+    public static final String PORLET_CATEGORIES_LINK =3D "org.jahia.engin=
es.applications.ManageApplicationCategoriesEngine.portletCategoriesLink";
+
+    //session attr. name
+    public static final String SELECTED_PORTLETS_LIST_ATTR =3D "selectedPo=
rtletsList";
+    public static final String PORTLETS_CATEGORIES_MAP_ATTR =3D "portletCa=
tegoriesMap";
+
+    private ManageApplicationCategoriesEngine() {
+        ManageApplicationCategoriesEngine.logger.debug("***** Starting " +=
 ManageApplicationCategoriesEngine.class.getName() + " engine *****");
+        toolBox =3D EngineToolBox.getInstance();
+    }
+
+    public boolean authoriseRender(ProcessingContext jParams) {
+        // TO DO:     check if we have admin role
+
+        return true;
+    }
+
+    public String renderLink(ProcessingContext jParams, Object theObj) thr=
ows JahiaException {
+        logger.debug("Call renderLink()");
+        String params =3D "&" + PORLET_CATEGORIES + "=3D" + PORLET_CATEGOR=
IES_TRUE;
+        String link =3D jParams.composeEngineUrl(ManageApplicationCategori=
esEngine.ENGINE_NAME, params);
+        return link;
+    }
+
+    public boolean needsJahiaData(ProcessingContext jParams) {
+        return false;  //To change body of implemented methods use File | =
Settings | File Templates.
+    }
+
+    public EngineValidationHelper handleActions(ProcessingContext jParams,=
 JahiaData jData) throws JahiaException {
+        // get screen value
+        String theScreen =3D jParams.getParameter(SCREEN_STR);
+        logger.debug("Screen is " + theScreen);
+        /*Set s =3D previousEngineMap.entrySet();
+        Iterator it =3D s.iterator();
+        while (it.hasNext()) {
+            String value =3D it.next().toString();
+            logger.debug("Found [" + value + "]");
+        }*/
+
+        //case of save
+        if (theScreen !=3D null && !theScreen.equalsIgnoreCase(CANCEL_STR)=
) {
+            logger.debug("Call Save()");
+            // get selected object list
+            List selectedEntryPointDefinitionList =3D getSelectedEntryPoin=
tDefinitionList(jParams);
+
+            // ObjectKeys List
+            List entryPointDefinitionsKey =3D new ArrayList();
+
+            // compute category key
+            List[] computedList =3D computeSelectedAndClickedCategoriesLis=
t(jParams);
+            List selectedCategories =3D computedList[0];
+            List clikedCategories =3D computedList[1];
+
+            //for each selected object, add it to category
+            for (int i =3D 0; i < selectedEntryPointDefinitionList.size();=
 i++) {
+                EntryPointDefinition epd =3D (EntryPointDefinition) select=
edEntryPointDefinitionList.get(i);
+                String currentSelectedObjectKey =3D epd.getApplicationID()=
 + "_" + epd.getName();
+                logger.debug("triing to add entrypointdefintion [" + curre=
ntSelectedObjectKey + "].");
+
+                // compute entryPointKey
+                EntryPointObjectKey objKey =3D new EntryPointObjectKey(cur=
rentSelectedObjectKey);
+                if (!entryPointDefinitionsKey.contains(objKey)) {
+                    entryPointDefinitionsKey.add(objKey);
+                }
+
+                //first: load old categories for current entrypoint defini=
tion BEFORE doing changes
+                List categoriyObjectKeysToRemoveList =3D getEntryPointDefi=
nitionCategoriesKey(objKey);
+
+                // link entrypoint/category
+                logger.debug("Category to add: " + selectedCategories);
+                for (int j =3D 0; j < selectedCategories.size(); j++) {
+                    Category currentCat =3D (Category) selectedCategories.=
get(j);
+                    CategoryKey categoryKey =3D (CategoryKey) currentCat.g=
etObjectKey();
+
+                    // add entrypoint point definition
+                    if(clikedCategories.contains(currentCat)){
+                        addEntryPointDefinitionToCategory(categoryKey, obj=
Key);
+                    }
+
+                    categoriyObjectKeysToRemoveList.remove(currentCat.getK=
ey());
+
+                }
+
+                // at this level, categoriyObjectKeysToRemoveList contains=
 only categoryKeys to remove
+                logger.debug("Categories to remove: " + categoriyObjectKey=
sToRemoveList);
+                for (int j =3D 0; j < categoriyObjectKeysToRemoveList.size=
(); j++) {
+                    String currentCategoryKey =3D (String) categoriyObject=
KeysToRemoveList.get(j);
+                    Category currentCat =3D ServicesRegistry.getInstance()=
.getCategoryService().getCategory(currentCategoryKey);
+                    CategoryKey categoryKey =3D (CategoryKey) currentCat.g=
etObjectKey();
+
+                    //remove
+                    removeEntryPointDefinitionToCategory(categoryKey, objK=
ey);
+                }
+            }
+        }
+
+        logger.debug("Finish Parameter name enumeration.");
+
+        // update engine map
+        HashMap nextEngineMap =3D updateEngineMap(jParams);
+
+        // displays the screen
+        toolBox.displayScreen(jParams, nextEngineMap);
+
+        return null;
+    }
+
+    private List[] computeSelectedAndClickedCategoriesList(ProcessingConte=
xt jParams) throws JahiaException {
+        List selectedCategories =3D new ArrayList();
+        List clickedCategories =3D new ArrayList();
+        List[] result =3D new List[2];
+        Iterator it =3D jParams.getParameterNames();
+        while (it.hasNext()) {
+            String currentParamName =3D (String) it.next();
+            logger.debug("Found parameter with name: " + currentParamName);
+            boolean isCategoryParam =3D currentParamName.indexOf("category=
") > -1;
+            if (isCategoryParam) {
+                String[] values =3D jParams.getParameterValues(currentPara=
mName);
+                logger.debug("params [" + currentParamName + "] is a categ=
ory param." + values);
+                boolean hasBeenClicked =3D values !=3D null && values[0].e=
qualsIgnoreCase("true");
+
+                //patern param: category_categoryID
+                StringTokenizer st =3D new StringTokenizer(currentParamNam=
e, "_");
+                // remove category
+                st.nextToken();
+                // get ID
+                int categoryID =3D Integer.parseInt(st.nextToken());
+                //logger.debug("Category ID is: " + categoryID);
+                Category currentCat =3D ServicesRegistry.getInstance().get=
CategoryService().getCategory(categoryID);
+                selectedCategories.add(currentCat);
+                logger.debug("Current Cat. key is: " + currentCat.getKey()=
);
+                if (hasBeenClicked) {
+                    clickedCategories.add(currentCat);
+                }
+
+            } else {
+                logger.debug("Current params is NOT a category param.");
+            }
+        }
+        result[0] =3D selectedCategories;
+        result[1] =3D clickedCategories;
+        return result;
+    }
+
+
+    /*
+    * get name
+    * */
+    public String getName() {
+        return ManageApplicationCategoriesEngine.ENGINE_NAME;
+    }
+
+    /**
+     * get unique instance
+     */
+    public static synchronized ManageApplicationCategoriesEngine getInstan=
ce() {
+        if (ManageApplicationCategoriesEngine.instance =3D=3D null) {
+            ManageApplicationCategoriesEngine.instance =3D new ManageAppli=
cationCategoriesEngine();
+        }
+        return ManageApplicationCategoriesEngine.instance;
+    }
+
+    /* init engine map*/
+    private HashMap updateEngineMap(ProcessingContext jParams) {
+        logger.debug("Call updateEngineMap();");
+        HashMap engineMap =3D getEngineMap(jParams);
+
+        // put render type
+        engineMap.put(RENDER_TYPE_PARAM, new Integer(JahiaEngine.RENDERTYP=
E_FORWARD));
+
+        // put engine name
+        engineMap.put(ENGINE_NAME_PARAM, ENGINE_NAME);
+
+        // put jsp source
+        String theScreen =3D jParams.getParameter(SCREEN_STR);
+        if (theScreen !=3D null) {
+            // sets screen
+            engineMap.put(SCREEN_STR, theScreen);
+            if (theScreen.equals(SAVE_STR)) {
+                engineMap.put(JSPSOURCE_STR, CLOSE_STR);
+            } else if (theScreen.equals(APPLY_STR)) {
+                engineMap.put(JSPSOURCE_STR, APPLY_STR);
+            } else if (theScreen.equals(CANCEL_STR)) {
+                engineMap.put(JSPSOURCE_STR, CLOSE_STR);
+            } else {
+                engineMap.put(JSPSOURCE_STR, ManageApplicationCategoriesEn=
gine.ENGINE_JSP);
+            }
+        } else {
+            engineMap.put(JSPSOURCE_STR, ManageApplicationCategoriesEngine=
.ENGINE_JSP);
+            logger.debug("theScreen value is null.");
+        }
+
+        //put link to categories manager
+        String[] objectIDs =3D (String[]) jParams.getSessionState().getAtt=
ribute("objectIDs");
+        for (int i =3D 0; i < objectIDs.length; i++) {
+            logger.debug("Found value with for objectIDs: " + objectIDs[i]=
);
+        }
+
+        //put selected entryPoint List
+        try {
+            //build selected Entrypoint List
+            Object[] results =3D loadSelectedEntryPointDefinitons(objectID=
s);
+            List entryPointList =3D (List) results[0];
+            List selectedCategoryObjectKeysList =3D (List) results[1];
+            Map portletsCategoriesMap =3D (Map) results[2];
+            List selectedAllsourceCategoriyObjectKeysList =3D (List) resul=
ts[3];
+
+            // set selectedObject
+            setEntyPointDefinitionList(jParams, entryPointList);
+
+            // set hashmap objectCatgeory
+            setPortletsCategoriesMap(jParams, portletsCategoriesMap);
+
+            //add into engineMap
+            engineMap.put("selectedObjectList", entryPointList);
+            engineMap.put(PORTLETS_CATEGORIES_MAP_ATTR, portletsCategories=
Map);
+
+            jParams.getSessionState().setAttribute("org.jahia.engines.appl=
ications.ManageApplicationCategoriesEngine.categoriesKeyList", selectedCate=
goryObjectKeysList);
+            jParams.getSessionState().setAttribute("org.jahia.engines.appl=
ications.ManageApplicationCategoriesEngine.allSourcesCategoriesKeyList", se=
lectedAllsourceCategoriyObjectKeysList);
+        } catch (JahiaException e) {
+            logger.error("Can't init selectedObjectList due to:", e);
+        }
+
+        // load selected categories
+        setEngineMap(jParams, engineMap);
+
+
+        return engineMap;
+    }
+
+    private void setEngineMap(ProcessingContext jParams, HashMap engineMap=
) {
+        //update engineMap
+        jParams.setAttribute("org.jahia.engines.EngineHashMap", engineMap);
+    }
+
+    private HashMap getEngineMap(ProcessingContext jParams) {
+        //get engineMap
+        HashMap m =3D (HashMap) jParams.getAttribute("org.jahia.engines.En=
gineHashMap");
+        if (m =3D=3D null) {
+            if (m =3D=3D null) {
+                logger.debug("Engine map not found in session");
+                m =3D new HashMap();
+            }
+        }
+        return m;
+    }
+
+
+    /*
+   *
+   *  build selected entry point list
+   *
+   * */
+    public Object[] loadSelectedEntryPointDefinitons(String[] entryPointId=
s) throws JahiaException {
+        List entryPointList =3D new ArrayList();
+        List selectedCategoriyObjectKeysList =3D new ArrayList();
+        List selectedAllsourceCategoriyObjectKeysList =3D new ArrayList();
+        HashMap portletCategoriesMap =3D new HashMap();
+        Object[] result =3D new Object[4];
+        result[0] =3D new ArrayList();
+        result[1] =3D new ArrayList();
+        result[2] =3D new HashMap();
+        result[3] =3D new ArrayList();
+        for (int i =3D 0; i < entryPointIds.length; i++) {
+            logger.debug("Current EntryPointId: " + entryPointIds[i]);
+
+            // pattern of an entryPointId: applicationID::entryPointDefName
+            StringTokenizer st =3D new StringTokenizer(entryPointIds[i], "=
::");
+            String appID =3D st.nextToken();
+            String entryPoindDefName =3D st.nextToken();
+
+            // find application
+            ApplicationBean theApplication =3D ServicesRegistry.getInstanc=
e().getApplicationsManagerService().getApplication(Integer.parseInt(appID));
+            if (theApplication =3D=3D null) {
+                logger.error("ApplicationBean with id [" + appID + "] not =
found. Look in ApplicationList");
+                return result;
+            }
+
+            //find Entry Point Def
+            EntryPointDefinition epd =3D theApplication.getEntryPointDefin=
itionByName(entryPoindDefName);
+            if (epd !=3D null) {
+                // add to list
+                entryPointList.add(epd);
+                logger.debug("EntryPoint with id [" + entryPointIds[i] + "=
] added to selectedEntryPointList ");
+            } else {
+                logger.error("EntryPoint with id [" + entryPointIds[i] + "=
] NOT FOUND.");
+                return result;
+            }
+
+            //load selected categorie for current EntryPointDefinition
+            logger.debug("load selected categories...");
+            String currentObjectKey =3D appID + "_" + entryPoindDefName;
+            EntryPointObjectKey objKey =3D new EntryPointObjectKey(current=
ObjectKey);
+            List categoriesObjectKey =3D getEntryPointDefinitionCategories=
Key(objKey);
+
+            // add to to hashmap
+            portletCategoriesMap.put(currentObjectKey, categoriesObjectKey=
);
+
+            // add to major categories list.
+            for (int j =3D 0; j < categoriesObjectKey.size(); j++) {
+                Object o =3D categoriesObjectKey.get(j);
+                if (!selectedCategoriyObjectKeysList.contains(o)) {
+                    // case of new categories
+                    selectedCategoriyObjectKeysList.add(o);
+                }
+            }
+
+            // update all selectedAllSources
+            if (i =3D=3D 0) {
+                selectedAllsourceCategoriyObjectKeysList.addAll(categories=
ObjectKey);
+            } else {
+                selectedAllsourceCategoriyObjectKeysList.retainAll(categor=
iesObjectKey);
+            }
+        }
+
+        // set results
+        result[0] =3D entryPointList;
+        result[1] =3D selectedCategoriyObjectKeysList;
+        result[2] =3D portletCategoriesMap;
+        result[3] =3D selectedAllsourceCategoriyObjectKeysList;
+        return result;
+    }
+
+    public void processCurrentScreen(ProcessingContext jParams, HashMap en=
gineMap)
+            throws JahiaException {
+        logger.debug("Call procesCurrentScreen(...)");
+    }
+
+    public void processLastScreen(ProcessingContext jParams, HashMap engin=
eMap)
+            throws JahiaException,
+            JahiaForbiddenAccessException {
+
+        logger.debug("Call processLastScreen(...)");
+    }
+
+    /*
+   *
+   *  get selected portlets from session
+   *
+   * */
+    private List getSelectedEntryPointDefinitionList(ProcessingContext jPa=
rams) {
+        List selectedPortletsList =3D new ArrayList();
+
+        Object selectedPortletsListObj =3D jParams.getSessionState().getAt=
tribute(SELECTED_PORTLETS_LIST_ATTR);
+        if (selectedPortletsListObj !=3D null) {
+            logger.debug("selectedPortletsList attr. found in session");
+            if (selectedPortletsListObj instanceof List) {
+                selectedPortletsList =3D (List) selectedPortletsListObj;
+            } else {
+                logger.error("selectedPortletsList attr. found in session =
MUST be java.util.List. ");
+            }
+        } else {
+            logger.error("selectedPortletsList attr. not found in session"=
);
+
+        }
+        return selectedPortletsList;
+    }
+
+    /**
+     * set selected portlets in session
+     */
+    public void setEntyPointDefinitionList(ProcessingContext jParams, List=
 selectedPortletList) {
+        if (selectedPortletList !=3D null) {
+            jParams.getSessionState().setAttribute(SELECTED_PORTLETS_LIST_=
ATTR, selectedPortletList);
+        } else {
+            logger.error("selectedPortletsList has null value.");
+        }
+    }
+
+    /**
+     * set selected portlets in session
+     */
+    public void setPortletsCategoriesMap(ProcessingContext jParams, Map po=
rtletsCategoriesMap) {
+        if (portletsCategoriesMap !=3D null) {
+            jParams.getSessionState().setAttribute(PORTLETS_CATEGORIES_MAP=
_ATTR, portletsCategoriesMap);
+        } else {
+            logger.error("portletsCategoriesMap has null value.");
+        }
+    }
+
+
+    /**
+     * link category to an EntryPointDefinition
+     */
+    private void addEntryPointDefinitionToCategory(CategoryKey categoryKey=
, ObjectKey childKey) throws JahiaException {
+        // check if exist
+        List l =3D ObjectLink.findByLeftAndRightObjectKeys(categoryKey, ch=
ildKey);
+        if (l =3D=3D null || l.size() > 0) {
+            logger.debug("link [" + categoryKey + "," + childKey + "] alre=
ady exists");
+            logger.debug(l + "," + l.size() + l.get(0));
+            return;
+        } else {
+
+            // build parameter
+            String type =3D childKey.getType();
+            int status =3D 1;
+            Date currentDate =3D new Date();
+            String user =3D "root:0";
+            Map leftObjectMetadata =3D new HashMap();
+            Map rigthObjectMetadata =3D new HashMap();
+            Map commonObjectMetadata =3D new HashMap();
+
+            //create and save link
+            logger.debug("link [" + categoryKey + "," + childKey + "] does=
 not exist--> add link.");
+            ObjectLink.createLink(categoryKey, childKey, type, status, cur=
rentDate, user, currentDate, user, leftObjectMetadata, rigthObjectMetadata,=
 commonObjectMetadata);
+        }
+
+    }
+
+    private void removeEntryPointDefinitionToCategory(CategoryKey category=
Key, ObjectKey childKey) throws JahiaException {
+        // check if exist
+        List links =3D ObjectLink.findByLeftAndRightObjectKeys(categoryKey=
, childKey);
+        if (links =3D=3D null || links.size() > 0) {
+            logger.debug("link [" + categoryKey + "," + childKey + "] foun=
d");
+            for (int j =3D 0; j < links.size(); j++) {
+                ObjectLink objectLinkToRemove =3D (ObjectLink) links.get(j=
);
+                objectLinkToRemove.remove();
+            }
+            return;
+        } else {
+            logger.debug("link [" + categoryKey + "," + childKey + "] not =
found");
+        }
+
+    }
+
+    private void removeUnselectedCategories(List selectedEntryPointDefinit=
ionKey, List selectedCategoriesKey) throws JahiaException {
+        //for each EntryPointObjectKey, delete de-selected categories
+        logger.debug("Call remove removeUnselectedCategories()");
+        for (int i =3D 0; i < selectedEntryPointDefinitionKey.size(); i++)=
 {
+            EntryPointObjectKey currentEntryPointObjectKey =3D (EntryPoint=
ObjectKey) selectedEntryPointDefinitionKey.get(i);
+
+            // compute object link to remocve for current  EntryPointObjec=
tKey
+            List objectLinkToRemoveList =3D computeObjectLinksListToRemove=
(currentEntryPointObjectKey, selectedCategoriesKey);
+
+            //remove all link
+            removeAllObjectLinks(objectLinkToRemoveList);
+
+        }
+        logger.debug("end removeUnselectedCategories(...)");
+    }
+
+    private List computeObjectLinksListToRemove(EntryPointObjectKey object=
Key, List selectedCategoriesKey) throws JahiaException {
+
+        // old_selected_categories - current_selected_categories =3D unsel=
ected_categories
+        List objectLinkToRemoveList =3D getCategoryParentLinks(objectKey);
+        objectLinkToRemoveList.removeAll(selectedCategoriesKey);
+        return objectLinkToRemoveList;
+    }
+
+    private void removeAllObjectLinks(List links) throws JahiaException {
+        for (int j =3D 0; j < links.size(); j++) {
+            ObjectLink objectLinkToRemove =3D (ObjectLink) links.get(j);
+            objectLinkToRemove.remove();
+        }
+    }
+
+
+    /*
+    *
+    * get Category of EntryPointDefinition
+    *
+    * */
+    private List getEntryPointDefinitionCategoriesKey(EntryPointObjectKey =
objectKey) throws JahiaException {
+        List categoriesKeys =3D new ArrayList();
+
+        // get category Parent links
+        List links =3D getCategoryParentLinks(objectKey);
+
+        // for each objectlink, get category key and add it to result list
+        Iterator linkIter =3D links.iterator();
+        while (linkIter.hasNext()) {
+            ObjectLink curCategoriesLink =3D (ObjectLink) linkIter.next();
+
+            // get category key
+            int categoryID =3D curCategoriesLink.getLeftObjectKey().getIdI=
nType();
+            logger.debug("look for categoy with id [" + categoryID + "]");
+            Category currentCat =3D ServicesRegistry.getInstance().getCate=
goryService().getCategory(categoryID);
+            if (currentCat !=3D null) {
+                String categoryKey =3D currentCat.getKey();
+                logger.debug("Found category with key [" + categoryKey + "=
]");
+
+                // add category key to list
+                categoriesKeys.add(categoryKey);
+            } else {
+                logger.error("Enable to find category with id [" + categor=
yID + "]");
+            }
+        }
+        logger.debug("End enumerate selected categories");
+        return categoriesKeys;
+    }
+
+
+    /*
+   *
+   * get link that refers to (Category,EntrypointDefinition)
+   *
+   * */
+    private java.util.List getCategoryParentLinks(ObjectKey objectKey) thr=
ows JahiaException {
+        String type =3D objectKey.getType();
+        logger.debug("Look for Object link with type [" + type + "] and Ri=
ghtObjectKey [" + objectKey.getKey() + "]");
+        return ObjectLink.findByTypeAndRightObjectKey(type, objectKey);
+    }
+}

Modified: trunk/core/src/java/org/jahia/engines/shared/Application_Field.ja=
va
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/engines/shared/Application_Field.java&rev=3D19283&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
--- trunk/core/src/java/org/jahia/engines/shared/Application_Field.java (or=
iginal)
+++ trunk/core/src/java/org/jahia/engines/shared/Application_Field.java Sun=
 Nov 25 20:27:34 2007
@@ -22,10 +22,7 @@
 =

 package org.jahia.engines.shared;
 =

-import org.jahia.data.applications.ApplicationBean;
-import org.jahia.data.applications.EntryPointDefinition;
-import org.jahia.data.applications.EntryPointInstance;
-import org.jahia.data.applications.WebAppContext;
+import org.jahia.data.applications.*;
 import org.jahia.data.containers.JahiaContainer;
 import org.jahia.data.fields.FieldsEditHelper;
 import org.jahia.data.fields.FieldsEditHelperAbstract;
@@ -45,6 +42,9 @@
 import org.jahia.services.lock.LockPrerequisitesResult;
 import org.jahia.services.lock.LockPrerequisites;
 import org.jahia.services.lock.LockKey;
+import org.jahia.content.ObjectKey;
+import org.jahia.content.ObjectLink;
+import org.jahia.content.CategoryKey;
 =

 import java.security.Principal;
 import java.util.*;
@@ -58,6 +58,7 @@
     private static final String JSP_FILE =3D "/jsp/jahia/engines/shared/ap=
plication_field.jsp";
     private static final String READONLY_JSP =3D "/jsp/jahia/engines/share=
d/readonly_application_field.jsp";
     public static final String APPLICATION_ROLES =3D "applicationRoles";
+    private HashMap appRoleMembers =3D null;
 =

     /**
      * AK    19.12.2000
@@ -126,8 +127,8 @@
         if ((oldAppID =3D=3D null) || (oldAppID.intValue() =3D=3D -1)) {
             logger.debug("No webapp was selected.");
             //return true;
-        }else{
-        =

+        } else {
+
             WebAppContext appContext =3D ServicesRegistry.getInstance()
                     .getApplicationsManagerService()
                     .getApplicationContext(oldAppID.intValue());
@@ -182,7 +183,7 @@
         if (separatorPos !=3D -1) {
             String appIDStr =3D selectedEntryPoint.substring(0, separatorP=
os);
             if (appIDStr !=3D null) {
-                logger.debug("App. selected: Application["+appIDStr+"]");
+                logger.debug("App. selected: Application[" + appIDStr + "]=
");
                 return true;
             }
             logger.debug("Not app. selected");
@@ -258,8 +259,8 @@
                 }
 =

                 // add new entrypointinstance
-                if(isAppSelected(theField)){
-                    logger.debug("SelectAppId =3D "+selectedAppID);
+                if (isAppSelected(theField)) {
+                    logger.debug("SelectAppId =3D " + selectedAppID);
                     ApplicationBean newAppBean =3D ServicesRegistry.getIns=
tance().getApplicationsManagerService().getApplication(selectedAppID);
                     EntryPointDefinition newEntryPointDefinition =3D null;
                     ArrayList epDefinitions =3D newAppBean.getEntryPointDe=
finitions();
@@ -290,7 +291,7 @@
                     if (newEntryPointInstanceID !=3D -1) {
                         theField.setValue(Integer.toString(newEntryPointIn=
stanceID));
                     }
-                }else{
+                } else {
                     logger.debug("No webapp. selected ste field value to -=
1");
                     theField.setValue("-1");
                 }
@@ -307,7 +308,7 @@
             // Try to recover application role members
             appRoleMembers =3D (HashMap) engineMap.get(APPLICATION_ROLES);
             ArrayList roleMembersList =3D null;
-            if(appRoleMembers !=3D null){
+            if (appRoleMembers !=3D null) {
                 roleMembersList =3D (ArrayList) appRoleMembers.get(appID);
             }
             if (roleMembersList =3D=3D null) {
@@ -315,10 +316,10 @@
             }
             success =3D theField.save(jParams);
 =

-            if(isAppSelected(theField)) {
+            if (isAppSelected(theField)) {
                 WebAppContext appContext =3D ServicesRegistry.getInstance()
-                    .getApplicationsManagerService()
-                    .getApplicationContext(appID.intValue());
+                        .getApplicationsManagerService()
+                        .getApplicationContext(appID.intValue());
                 if (appContext !=3D null) {
                     Vector roles =3D appContext.getRoles();
                     // Handle roles changes
@@ -329,15 +330,15 @@
                             JahiaGroup grp =3D ServicesRegistry.getInstanc=
e().
                                     getJahiaGroupManagerService().
                                     lookupGroup(0,
-                                        appID + "_" + theField.getID() +
-                                                "_" + role);
+                                            appID + "_" + theField.getID()=
 +
+                                                    "_" + role);
                             if (grp =3D=3D null) {
                                 // create group
                                 grp =3D ServicesRegistry.getInstance().
                                         getJahiaGroupManagerService().
                                         createGroup(0,
                                                 appID + "_" + theField.get=
ID() + "_" +
-                                                    role, new Properties()=
);
+                                                        role, new Properti=
es());
                             }
                             HashSet membersSet =3D getFormMembers(jParams,=
 roleNb);
                             Enumeration members =3D grp.members();
@@ -412,11 +413,11 @@
         engineMap.put("createApplication_" + theField.getDefinition().getN=
ame(), Boolean.TRUE);
 =

         // all apps
-        Vector appList =3D ServicesRegistry.getInstance().getApplicationsM=
anagerService().getApplications();
+        /*Vector appList =3D ServicesRegistry.getInstance().getApplication=
sManagerService().getApplications();
 =

         // list of authorized apps
         Vector authAppList =3D new Vector();
-        logger.debug("Application list size  before appliing ACL: "+appLis=
t.size());
+        logger.debug("Application list size  before appliing ACL: " + appL=
ist.size());
         for (int i =3D 0; i < appList.size(); i++) {
             ApplicationBean app =3D (ApplicationBean) appList.get(i);
             if (app.getACL().getPermission(null, null, jParams.getUser(), =
JahiaBaseACL.READ_RIGHTS, false, jParams.getSiteID())) {
@@ -426,8 +427,17 @@
 =

         if (authAppList =3D=3D null) {
             authAppList =3D new Vector();
-        }
+        } */
+
+
+        // get allowed app. and entryPoint
+        Vector[] authAppListAndEntryPointFilter =3D getAllowedApplications=
AndEntryPointFilter(jParams);
+        Vector authAppList =3D authAppListAndEntryPointFilter[0];
+        Vector entryPoinDefinitionFilter =3D authAppListAndEntryPointFilte=
r[1];
+
+        //put in engine map
         engineMap.put("appList", authAppList.elements());
+        engineMap.put("entryPoinDefinitionFilter", entryPoinDefinitionFilt=
er);
 =

         Integer entryPointInstanceID =3D new Integer(-1);
         String selectedEntryPointDefName =3D null;
@@ -435,13 +445,13 @@
         int appID =3D -1;
         try {
             String fieldValue =3D theField.getRawValue();
-            logger.debug("Field value: "+fieldValue);
+            logger.debug("Field value: " + fieldValue);
             // fieldValue could contain appID_defName if we come from an
             // update, otherwise it simply contains an instanceID.
             if ((fieldValue !=3D null) && (fieldValue.indexOf("_") !=3D -1=
)) {
                 // we found a field value in the form appID_defName
                 appID =3D ((Integer) engineMap.get(theField.getDefinition(=
).getName() + "_appID")).intValue();
-                logger.debug("Application id: "+appID);
+                logger.debug("Application id: " + appID);
                 selectedEntryPointDefName =3D (String) engineMap.get(theFi=
eld.getDefinition().getName() + "_selectedEntryPointDefName");
                 appBean =3D ServicesRegistry.getInstance().getApplications=
ManagerService().getApplication(appID);
             } else {
@@ -476,38 +486,37 @@
                         logger.warn("Couldn't retrieve entry point definit=
ions for application " + appBean.getName());
                     } */
                 }
-            } else {
+            }
+
+            if (epInstance !=3D null) {
                 selectedEntryPointDefName =3D epInstance.getDefName();
                 int separatorPos =3D selectedEntryPointDefName.indexOf("##=
#");
                 if (separatorPos !=3D -1) {
                     String portletDefName =3D selectedEntryPointDefName.su=
bstring(0, separatorPos);
-                    String portletEntityID =3D selectedEntryPointDefName.s=
ubstring(separatorPos +
-                            "###".length());
                     selectedEntryPointDefName =3D portletDefName;
                 }
                 appID =3D epInstance.getApplicationID();
-                logger.debug("application ID from entry point instance: "+=
appID);
-                appBean =3D ServicesRegistry.getInstance().
-                        getApplicationsManagerService().getApplication(app=
ID);
+                logger.debug("application ID from entry point instance: " =
+ appID);
+                appBean =3D ServicesRegistry.getInstance().getApplications=
ManagerService().getApplication(appID);
             }
             engineMap.put(theField.getDefinition().getName() + "_entryPoin=
tInstanceID", entryPointInstanceID);
-            engineMap.put(theField.getDefinition().getName() + "_selectedE=
ntryPointDefName",
-                    selectedEntryPointDefName);
+            engineMap.put(theField.getDefinition().getName() + "_selectedE=
ntryPointDefName", selectedEntryPointDefName);
             engineMap.put(theField.getDefinition().getName() + "_appID", n=
ew Integer(appID));
-            logger.debug("Number of allowed application: "+authAppList.siz=
e());
-            if(appBean !=3D null){
-                logger.debug("Selected application ID : "+appBean.getID());
-                logger.debug("Selected application is allowed for current =
user! "+authAppList.contains(appBean));
-            }else{
-                 logger.debug("No portlet selected. ");
-            }
-
 =

+            if(logger.isDebugEnabled()){
+                logger.debug("Number of allowed application: " + authAppLi=
st.size());
+                if (appBean !=3D null) {
+                    logger.debug("Selected application ID : " + appBean.ge=
tID());
+                    logger.debug("Selected application is allowed for curr=
ent user! " + authAppList.contains(appBean));
+                } else {
+                    logger.debug("No portlet selected. ");
+                }
+            }
         }
 =

         // set auth flag
-        if (authAppList!=3Dnull && authAppList.size() > 0 && appBean !=3D =
null && !authAppList.contains(appBean) && appID !=3D -1) {
-                engineMap.put(theField.getDefinition().getName() + "_unAut=
horized", Boolean.TRUE);
+        if (authAppList !=3D null && authAppList.size() > 0 && appBean !=
=3D null && !authAppList.contains(appBean) && appID !=3D -1) {
+            engineMap.put(theField.getDefinition().getName() + "_unAuthori=
zed", Boolean.TRUE);
         }
 =

         Vector roles =3D new Vector();
@@ -628,5 +637,108 @@
         return membersSet;
     }
 =

-    private HashMap appRoleMembers =3D null;
+    // Get all entryPointDefinition
+    private Vector[] getAllowedApplicationsAndEntryPointFilter(ProcessingC=
ontext jParams) throws JahiaException {
+        // all application
+        Vector appList =3D ServicesRegistry.getInstance().getApplicationsM=
anagerService().getApplications();
+
+        // CategoryKey
+        String catId =3D jParams.getParameter("catId");
+        CategoryKey catKey =3D null;
+        if (catId !=3D null && !catId.equalsIgnoreCase("")) {
+            catKey =3D new CategoryKey(Integer.parseInt(catId));
+        }
+
+        //result Object
+        Vector entryPointFilter =3D new Vector();
+        Vector authAppList =3D new Vector();
+
+        Iterator it =3D appList.iterator();
+        while (it.hasNext()) {
+            ApplicationBean appBean =3D (ApplicationBean) it.next();
+            if (appBean.getACL().getPermission(null, null, jParams.getUser=
(), JahiaBaseACL.READ_RIGHTS, false, jParams.getSiteID())) {
+                // add to auhorised list
+                authAppList.add(appBean);
+
+                // update  entryPointFilter
+                List entryPointDefinitionList =3D appBean.getEntryPointDef=
initions();
+                for (int i =3D 0; i < entryPointDefinitionList.size(); i++=
) {
+                    EntryPointDefinition epd =3D (EntryPointDefinition) en=
tryPointDefinitionList.get(i);
+                    String currentEntryPointDefinitionKey =3D epd.getAppli=
cationID() + "_" + epd.getName();
+                    logger.debug("Check for [" + currentEntryPointDefiniti=
onKey + "].");
+
+                    // compute entryPointKey
+                    EntryPointObjectKey objKey =3D new EntryPointObjectKey=
(currentEntryPointDefinitionKey);
+                    if (catKey !=3D null) {
+                        if (isInCategory(catKey, objKey)) {
+                            entryPointFilter.add(currentEntryPointDefiniti=
onKey);
+                        }
+                    } else {
+                        entryPointFilter.add(currentEntryPointDefinitionKe=
y);
+                        logger.debug("Add all entryPoint.");
+                    }
+                }
+            } else {
+                logger.debug("Portlet of application [" + appBean.getName(=
) + "] not allowed for user: " + jParams.getUser());
+            }
+
+        }
+
+        //result
+        Vector[] result =3D new Vector[2];
+        result[0] =3D authAppList;
+        result[1] =3D entryPointFilter;
+        return result;
+    }
+
+    private boolean isInCategory(CategoryKey catKey, EntryPointObjectKey e=
pok) {
+        try {
+            List result =3D ObjectLink.findByLeftAndRightObjectKeys(catKey=
, epok);
+            return !result.isEmpty();
+        } catch (JahiaException e) {
+            logger.error("Can't find object link with parameters: [" + cat=
Key + "," + epok + "]");
+        }
+        return false;
+    }
+
+
+    // Get entryPointDefinition by category
+    private java.util.Vector getAllowedEntyPointDefinitionByCategory(Proce=
ssingContext jParams, ObjectKey objectKey) throws JahiaException {
+        Vector entryPointDefinitionList =3D new Vector();
+        // find all link that refers to an EntryPointDefintion
+
+        List entryPointDefinitionLink =3D ObjectLink.findByTypeAndLeftObje=
ctKey(EntryPointObjectKey.ENTRY_POINT_TYPE, objectKey);
+        logger.debug("Nb portlets:" + entryPointDefinitionLink.size());
+        for (int i =3D 0; i < entryPointDefinitionLink.size(); i++) {
+            ObjectLink link =3D (ObjectLink) entryPointDefinitionLink.get(=
i);
+            EntryPointObjectKey epok =3D (EntryPointObjectKey) link.getRig=
htObjectKey();
+            if (epok =3D=3D null) {
+                logger.error("EntryPointKey Not defined: " + link.getRight=
ObjectKey() + "," + link.getLeftObjectKey());
+            } else {
+
+                // get application Id and entrypoint definition name. patt=
ern: entrypoint_appid_epfdName
+                String key =3D epok.getKey();
+                logger.debug("EntryPointDefinitionkey:" + key);
+                StringTokenizer strg =3D new StringTokenizer(key, "_");
+                //remove 'entrypoint'
+                strg.nextToken();
+                // get appId
+                int appId =3D Integer.parseInt(strg.nextToken());
+                // get entrypointName
+                String entryPointName =3D strg.nextToken();
+                //find application bean
+                ApplicationBean aBean =3D ServicesRegistry.getInstance().g=
etApplicationsManagerService().getApplication(appId);
+                if (aBean.getACL().getPermission(null, null, jParams.getUs=
er(), JahiaBaseACL.READ_RIGHTS, false, jParams.getSiteID())) {
+                    // get entryPoint definition
+                    EntryPointDefinition epd =3D aBean.getEntryPointDefini=
tionByName(entryPointName);
+                    entryPointDefinitionList.add(epd);
+                } else {
+                    logger.debug("Portlet of application [" + aBean.getNam=
e() + "] not allowed for user: " + jParams.getUser());
+                }
+            }
+
+        }
+
+        return entryPointDefinitionList;
+    }
 }

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

Reply via email to