Author: xlawrence
Date: Tue Jan 10 16:53:52 2006
New Revision: 12746

URL: https://jahia.mine.nu/websvn/listing.php?sc=1&rev=12746&repname=jahia
Log:
new AJAX Struts based Action for the sitemap and WorkFlow

Added:
    trunk/core/src/java/org/jahia/ajax/sitemap/
    trunk/core/src/java/org/jahia/ajax/sitemap/GetChildPages.java
    trunk/core/src/java/org/jahia/ajax/sitemap/GetWorkFlowChildObjects.java
    trunk/core/src/java/org/jahia/ajax/sitemap/GetWorkflowEntryPoint.java
    trunk/core/src/java/org/jahia/ajax/sitemap/LockWorkFlowChildObjects.java
    trunk/core/src/java/org/jahia/ajax/sitemap/SiteMapAbstractAction.java
    trunk/core/src/java/org/jahia/ajax/sitemap/UnlockWorkFlowChildObjects.java
Modified:
    trunk/core/src/java/org/jahia/ajax/AjaxAction.java

Modified: trunk/core/src/java/org/jahia/ajax/AjaxAction.java
URL: 
https://jahia.mine.nu/websvn/diff.php?path=/trunk/core/src/java/org/jahia/ajax/AjaxAction.java&rev=12746&repname=jahia
==============================================================================
--- trunk/core/src/java/org/jahia/ajax/AjaxAction.java (original)
+++ trunk/core/src/java/org/jahia/ajax/AjaxAction.java Tue Jan 10 16:53:52 2006
@@ -41,13 +41,31 @@
 import org.apache.struts.action.ActionForm;
 import org.apache.struts.action.ActionForward;
 import org.apache.struts.action.ActionMapping;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.jahia.data.webapps.Web_App_Xml;
+import org.jahia.exceptions.JahiaException;
+import org.jahia.hibernate.manager.SpringContextSingleton;
+import org.jahia.params.ProcessingContext;
+import org.jahia.params.ProcessingContextFactory;
+import org.jahia.registries.ServicesRegistry;
+import org.springframework.beans.factory.BeanFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.StringWriter;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
 
 /**
  * Represents an Abstract Struts Action that will be sub-classed to implement
@@ -61,6 +79,16 @@
     private static final org.apache.log4j.Logger logger =
             org.apache.log4j.Logger.getLogger(AjaxAction.class);
 
+    protected static final ServicesRegistry servicesRegistry = 
ServicesRegistry.getInstance();
+
+    protected static final BeanFactory bf = 
SpringContextSingleton.getInstance().getContext();
+
+    protected static final ProcessingContextFactory pcf =
+            (ProcessingContextFactory) bf. 
getBean(ProcessingContextFactory.class.getName());
+
+    private static final DocumentBuilderFactory dbf = 
DocumentBuilderFactory.newInstance();
+    protected DocumentBuilder db;
+
     protected static final String DELIMITER = ";;";
 
     protected static final String CHARSET = "UTF-8";
@@ -70,6 +98,17 @@
     protected static final String CACHE_CONTROL = "Cache-Control";
     protected static final String NO_CACHE = "no-cache";
     protected static final String XML_CONTENT = "text/xml";
+    protected static String SERVLET_PATH;
+
+    protected static final String PARAMS = "params";
+
+    protected AjaxAction() {
+        try {
+            db = dbf.newDocumentBuilder();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
     /**
      * Simple utility method to retreive a parameter from a request and send
@@ -107,6 +146,100 @@
     }
 
     /**
+     * Simple utility method to retreive a element from a request's XML body 
and send
+     * an error message (status 400) in case the element is not found.
+     *
+     * @param request       The current HttpServletRequest
+     * @param response      The HttpServletResponse linked to the current 
request
+     * @param xmlTagName    The XML element name
+     * @return A String containing the value of the given parameter
+     * @throws ServletException If the specified parameter is not found
+     * @throws IOException
+     * @throws SAXException In case the body of the request is not a 
well-formed XML document.
+     */
+    protected final String getXmlNodeValue(final HttpServletRequest request,
+                                           final HttpServletResponse response,
+                                           final String xmlTagName)
+            throws ServletException, IOException, SAXException {
+        if (request == null) {
+            throw new NullPointerException("'request' cannot be null");
+        }
+        if (response == null) {
+            throw new NullPointerException("'response' cannot be null");
+        }
+        if (xmlTagName == null) {
+            throw new NullPointerException("'name' cannot be null");
+        }
+
+        final Document doc = db.parse(request.getInputStream());
+        final NodeList list = doc.getElementsByTagName(xmlTagName);
+        if (list == null || list.getLength() == 0) {
+            final String msg = "Missing required '" + xmlTagName + "' XML 
element in request body.";
+            logger.error(msg);
+            response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
+            throw new ServletException(msg);
+        }
+
+        final Node nodeValue = list.item(0).getFirstChild();
+        if (nodeValue == null) {
+            final String msg = "XML element '" + xmlTagName + "' has no node 
value.";
+            logger.error(msg);
+            response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
+            throw new ServletException(msg);
+        }
+        return nodeValue.getNodeValue();
+    }
+
+    /**
+     * Simple utility method to retreive a element from a request's XML body 
and send
+     * an error message (status 400) in case the element is not found.
+     *
+     * @param request    The current HttpServletRequest
+     * @param response   The HttpServletResponse linked to the current request
+     * @param xmlTagName The XML element name
+     * @return A String containing the value of the given parameter
+     * @throws ServletException If the specified parameter is not found
+     * @throws IOException
+     * @throws SAXException     In case the body of the request is not a 
well-formed XML document.
+     */
+    protected final String[] getMultipleXmlNodeValue(final HttpServletRequest 
request,
+                                                     final HttpServletResponse 
response,
+                                                     final String xmlTagName)
+            throws ServletException, IOException, SAXException {
+        if (request == null) {
+            throw new NullPointerException("'request' cannot be null");
+        }
+        if (response == null) {
+            throw new NullPointerException("'response' cannot be null");
+        }
+        if (xmlTagName == null) {
+            throw new NullPointerException("'name' cannot be null");
+        }
+
+        final Document doc = db.parse(request.getInputStream());
+        final NodeList list = doc.getElementsByTagName(xmlTagName);
+        if (list == null || list.getLength() == 0) {
+            final String msg = "Missing required '" + xmlTagName + "' XML 
element in request body.";
+            logger.error(msg);
+            response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
+            throw new ServletException(msg);
+        }
+
+        final String[] result = new String[list.getLength()];
+        for (int i = 0; i < list.getLength(); i++) {
+            final Node nodeValue = list.item(i).getFirstChild();
+            if (nodeValue == null) {
+                final String msg = "XML element '" + xmlTagName + "' has no 
node value.";
+                logger.error(msg);
+                response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
+                throw new ServletException(msg);
+            }
+            result[i] = nodeValue.getNodeValue();
+        }
+        return result;
+    }
+
+    /**
      * Simple utility method to retreive a parameter from a request. If the 
value is not found,
      * it will return the defaultValue.
      *
@@ -238,6 +371,26 @@
     }
 
     /**
+     * Sends the given Document in the HTTP response
+     *
+     * @param doc       The Document instance to send back
+     * @param response  The current HttpServletResponse instance
+     * @throws IOException If something goes wrong
+     */
+    protected final void sendResponse(final Document doc,
+                                      final HttpServletResponse response)
+            throws IOException {
+
+        final OutputFormat format = new OutputFormat(doc);          // 
Serialize DOM
+        final StringWriter stringOut = new StringWriter();          // Writer 
will be a String
+        final XMLSerializer serial = new XMLSerializer(stringOut, format);
+        serial.asDOMSerializer();                                   // As a 
DOM Serializer
+        serial.serialize(doc.getDocumentElement());
+
+        sendResponse(stringOut.toString(), response);
+    }
+
+    /**
      * Raw method to send bytes from a String
      *
      * @param resp
@@ -260,6 +413,68 @@
     }
 
     /**
+     * Constructs a String representing the URL of a page
+     *
+     * @param jParams
+     * @param pid
+     * @param languageCode
+     */
+    protected final String getPageURL(final ProcessingContext jParams,
+                                      final int pid,
+                                      final String languageCode) {
+        final StringBuffer buff = new StringBuffer();
+        buff.append(jParams.getContextPath());
+        buff.append(getPageServletPath(jParams));
+        if (languageCode != null && languageCode.length() > 0) {
+            buff.append("/lang/");
+            buff.append(languageCode);
+        }
+        buff.append("/pid/");
+        buff.append(pid);
+        return buff.toString();
+    }
+
+    /**
+     * Gets The correct Servlet Path for building page URLs.
+     *
+     * @param jParams
+     */
+    protected final String getPageServletPath(final ProcessingContext jParams) 
{
+        if (SERVLET_PATH == null) {
+            try {
+                logger.debug("Setting the SERVLET_PATH...");
+                final String path = jParams.settings().getPathResolver().
+                        resolvePath("/WEB-INF/web.xml");
+                final Web_App_Xml webXmlDoc = new Web_App_Xml(path);
+                webXmlDoc.extractDocumentData();
+
+                final HashMap mappings = webXmlDoc.getServletMappings();
+
+                // Default settings
+                if (mappings.containsKey("/Jahia/*")) {
+                    SERVLET_PATH = "/Jahia";
+                    return SERVLET_PATH;
+                }
+
+                final Iterator ite = mappings.keySet().iterator();
+                while (ite.hasNext()) {
+                    final String urlPattern = (String) ite.next();
+                    final String servletName = (String) 
mappings.get(urlPattern);
+
+                    if (servletName.equals("Jahia") && 
urlPattern.indexOf("do") < 0) {
+                        SERVLET_PATH = urlPattern.substring(0,
+                                urlPattern.lastIndexOf('/'));
+                        return SERVLET_PATH;
+                    }
+                }
+            } catch (JahiaException je) {
+                logger.error("Unable to set the ServletPath", je);
+            }
+        }
+        return SERVLET_PATH;
+    }
+
+    /**
      * Abstract method that will execute the AJAX Action in the implementing 
sub-classes.
      *
      * @param mapping           Struts ActionMapping

Added: trunk/core/src/java/org/jahia/ajax/sitemap/GetChildPages.java
URL: 
https://jahia.mine.nu/websvn/filedetails.php?path=/trunk/core/src/java/org/jahia/ajax/sitemap/GetChildPages.java&rev=12746&repname=jahia
==============================================================================
--- trunk/core/src/java/org/jahia/ajax/sitemap/GetChildPages.java (added)
+++ trunk/core/src/java/org/jahia/ajax/sitemap/GetChildPages.java Tue Jan 10 
16:53:52 2006
@@ -0,0 +1,113 @@
+/*
+ *                                   ____.
+ *                       __/\ ______|    |__/\.     _______
+ *            __   .____|    |       \   |    +----+       \
+ *    _______|  /--|    |    |    -   \  _    |    :    -   \_________
+ *   \\______: :---|    :    :           |    :    |         \________>
+ *           |__\---\_____________:______:    :____|____:_____\
+ *                                      /_____|
+ *
+ *              . . . i n   j a h i a   w e   t r u s t . . .
+ *
+ *
+ *
+ * ----- BEGIN LICENSE BLOCK -----
+ * Version: JCSL 1.0
+ *
+ * The contents of this file are subject to the Jahia Community Source License
+ * 1.0 or later (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.jahia.org/license
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the rights, obligations and limitations governing use of the contents
+ * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
+ * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
+ * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
+ *
+ * The Shared Modifications are Jahia View Helper.
+ *
+ * The Developer of the Shared Modifications is Jahia Solution S�rl.
+ * Portions created by the Initial Developer are Copyright (C) 2002 by the
+ * Initial Developer. All Rights Reserved.
+ *
+ * ----- END LICENSE BLOCK -----
+ */
+package org.jahia.ajax.sitemap;
+
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.jahia.data.fields.LoadFlags;
+import org.jahia.params.ProcessingContext;
+import org.jahia.services.pages.ContentPage;
+import org.jahia.services.usermanager.JahiaUser;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Struts AJAX based Action that collects all the direct child pages from a 
given parent page. This action would
+ * typically be used for a basic and simple sitemap
+ *
+ * @author Xavier Lawrence
+ */
+public class GetChildPages extends SiteMapAbstractAction {
+
+    private static final org.apache.log4j.Logger logger =
+            org.apache.log4j.Logger.getLogger(GetChildPages.class);
+
+    public ActionForward execute(final ActionMapping mapping,
+                                 final ActionForm form,
+                                 final HttpServletRequest request,
+                                 final HttpServletResponse response) throws 
IOException, ServletException {
+        try {
+            // Contains params that will have to given to the ParamBean 
Constructor for correct
+            // initialization of the latter
+            final String params = getParameter(request, response, PARAMS);
+            final ProcessingContext jParams = pcf.getContext(request, response,
+                    super.getServlet().getServletContext(), params);
+
+            final JahiaUser currentUser = jParams.getUser();
+
+            final String key = getXmlNodeValue(request, response, KEY);
+            final ContentPage currentObject = (ContentPage) 
getContentObjectFromString(key);
+            if (currentObject == null) {
+                logger.warn("Unable to Get Child Pages ! Object '" + key + "' 
doesn't exist");
+                response.sendError(HttpServletResponse.SC_NOT_FOUND,
+                        "Unable to Get Child Pages ! Msg: Page '" + key + "' 
doesn't exist");
+                return null;
+            }
+
+            // Get all active languages
+            final List locales = jParams.getSite().getLanguageSettings(true);
+
+            final Document resp = db.newDocument();
+            final Element root = resp.createElement("GetChildPagesResp");
+
+            final Iterator children = 
currentObject.getContentPageChilds(currentUser, LoadFlags.ALL, null, true);
+            while (children.hasNext()) {
+                final ContentPage child = (ContentPage) children.next();
+                processPage(child, jParams, locales, resp, root);
+            }
+
+            resp.appendChild(root);
+            sendResponse(resp, response);
+
+        } catch (Exception e) {
+            logger.error("Unable to process the request !", e);
+            if (! response.isCommitted()) {
+                
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                        "Unable to Get Child Pages ! Msg: " + e.getMessage());
+            }
+        }
+        return null;
+    }
+}

Added: trunk/core/src/java/org/jahia/ajax/sitemap/GetWorkFlowChildObjects.java
URL: 
https://jahia.mine.nu/websvn/filedetails.php?path=/trunk/core/src/java/org/jahia/ajax/sitemap/GetWorkFlowChildObjects.java&rev=12746&repname=jahia
==============================================================================
--- trunk/core/src/java/org/jahia/ajax/sitemap/GetWorkFlowChildObjects.java 
(added)
+++ trunk/core/src/java/org/jahia/ajax/sitemap/GetWorkFlowChildObjects.java Tue 
Jan 10 16:53:52 2006
@@ -0,0 +1,128 @@
+/*
+ *                                   ____.
+ *                       __/\ ______|    |__/\.     _______
+ *            __   .____|    |       \   |    +----+       \
+ *    _______|  /--|    |    |    -   \  _    |    :    -   \_________
+ *   \\______: :---|    :    :           |    :    |         \________>
+ *           |__\---\_____________:______:    :____|____:_____\
+ *                                      /_____|
+ *
+ *              . . . i n   j a h i a   w e   t r u s t . . .
+ *
+ *
+ *
+ * ----- BEGIN LICENSE BLOCK -----
+ * Version: JCSL 1.0
+ *
+ * The contents of this file are subject to the Jahia Community Source License
+ * 1.0 or later (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.jahia.org/license
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the rights, obligations and limitations governing use of the contents
+ * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
+ * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
+ * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
+ *
+ * The Shared Modifications are Jahia View Helper.
+ *
+ * The Developer of the Shared Modifications is Jahia Solution S�rl.
+ * Portions created by the Initial Developer are Copyright (C) 2002 by the
+ * Initial Developer. All Rights Reserved.
+ *
+ * ----- END LICENSE BLOCK -----
+ */
+package org.jahia.ajax.sitemap;
+
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.jahia.content.ContentObject;
+import org.jahia.params.ProcessingContext;
+import org.jahia.services.acl.JahiaBaseACL;
+import org.jahia.services.pages.ContentPage;
+import org.jahia.services.usermanager.JahiaUser;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Struts AJAX based Action that collects all the direct child objects or 
pages from a given parent object. It
+ * also locks the objects with workflow locks.
+ * The user needs to have Write access on the page where the WorkFlow is 
launched for the action to be executed.
+ *
+ * @author Xavier Lawrence
+ */
+public class GetWorkFlowChildObjects extends SiteMapAbstractAction {
+
+    private static final org.apache.log4j.Logger logger =
+            org.apache.log4j.Logger.getLogger(GetWorkFlowChildObjects.class);
+
+    public ActionForward execute(final ActionMapping mapping,
+                                 final ActionForm form,
+                                 final HttpServletRequest request,
+                                 final HttpServletResponse response)
+            throws IOException, ServletException {
+        try {
+            // Contains params that will have to given to the ParamBean 
Constructor for correct
+            // initialization of the latter
+            final String params = getParameter(request, response, PARAMS);
+            final ProcessingContext jParams = pcf.getContext(request, response,
+                    super.getServlet().getServletContext(), params);
+
+            final ContentPage currentPage = jParams.getContentPage();
+            final JahiaUser currentUser = jParams.getUser();
+
+            if (currentUser == null || currentPage == null ||
+                    ! currentPage.getACL().getPermission(currentUser, 
JahiaBaseACL.WRITE_RIGHTS)) {
+                logger.warn("Unauthorized attempt to use AJAX Struts Action - 
GetWorkFlowChildObjects");
+                response.sendError(HttpServletResponse.SC_FORBIDDEN,
+                        "Error: Must be logged in and have 'Write' access");
+                return null;
+            }
+
+            final String key = getXmlNodeValue(request, response, KEY);
+            final ContentObject currentObject = 
getContentObjectFromString(key);
+            if (currentObject == null) {
+                logger.warn( "Unable to Get WorkFlow Child Objects ! Object '" 
+ key + "' doesn't exist");
+                response.sendError(HttpServletResponse.SC_NOT_FOUND,
+                        "Unable to Get WorkFlow Child Objects ! Msg: Object '" 
+ key + "' doesn't exist");
+                return null;
+            }
+
+            logger.debug("Getting WorkFlow ChildObjects for object: " + key);
+
+            // Get all active languages
+            final List locales = jParams.getSite().getLanguageSettings(true);
+
+            final Document resp = db.newDocument();
+            final Element root = 
resp.createElement("GetWorkFlowChildObjectsResp");
+
+            final Iterator children = getChildObjects(currentObject, 
currentUser).iterator();
+
+            while (children.hasNext()) {
+                final ContentObject child = (ContentObject) children.next();
+                processWorkflowObject(child, jParams, currentUser, locales, 
resp, root);
+            }
+
+            resp.appendChild(root);
+            sendResponse(resp, response);
+
+        } catch (Exception e) {
+            logger.error("Unable to process the request !", e);
+            if (! response.isCommitted()) {
+                
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                        "Unable to Get WorkFlow Child Objects ! Msg: " + 
e.getMessage());
+            }
+        }
+        return null;
+    }
+}

Added: trunk/core/src/java/org/jahia/ajax/sitemap/GetWorkflowEntryPoint.java
URL: 
https://jahia.mine.nu/websvn/filedetails.php?path=/trunk/core/src/java/org/jahia/ajax/sitemap/GetWorkflowEntryPoint.java&rev=12746&repname=jahia
==============================================================================
--- trunk/core/src/java/org/jahia/ajax/sitemap/GetWorkflowEntryPoint.java 
(added)
+++ trunk/core/src/java/org/jahia/ajax/sitemap/GetWorkflowEntryPoint.java Tue 
Jan 10 16:53:52 2006
@@ -0,0 +1,85 @@
+package org.jahia.ajax.sitemap;
+
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.jahia.content.ContentObject;
+import org.jahia.params.ProcessingContext;
+import org.jahia.services.acl.JahiaBaseACL;
+import org.jahia.services.pages.ContentPage;
+import org.jahia.services.usermanager.JahiaUser;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Xavier Lawrence
+ * Date: 4 janv. 2006
+ * Time: 16:51:21
+ * To change this template use File | Settings | File Templates.
+ */
+public class GetWorkflowEntryPoint extends SiteMapAbstractAction {
+
+    private static final org.apache.log4j.Logger logger =
+            org.apache.log4j.Logger.getLogger(GetWorkflowEntryPoint.class);
+
+    public ActionForward execute(final ActionMapping mapping,
+                                 final ActionForm form,
+                                 final HttpServletRequest request,
+                                 final HttpServletResponse response) throws 
IOException, ServletException {
+        try {
+            // Contains params that will have to given to the ParamBean 
Constructor for correct
+            // initialization of the latter
+            final String params = getParameter(request, response, PARAMS);
+            final ProcessingContext jParams = pcf.getContext(request, response,
+                    super.getServlet().getServletContext(), params);
+
+            final ContentPage currentPage = jParams.getContentPage();
+            final JahiaUser currentUser = jParams.getUser();
+
+            if (currentUser == null || currentPage == null ||
+                    ! currentPage.getACL().getPermission(currentUser, 
JahiaBaseACL.WRITE_RIGHTS)) {
+                logger.warn("Unauthorized attempt to use AJAX Struts Action - 
GetWorkflowEntryPoint");
+                response.sendError(HttpServletResponse.SC_FORBIDDEN,
+                        "Error: Must be logged in and have 'Write' access");
+                return null;
+            }
+
+            final String key = getXmlNodeValue(request, response, KEY);
+            final ContentObject currentObject = 
getContentObjectFromString(key);
+            if (currentObject == null) {
+                logger.warn("Unable to Get Entry Point ! Object '" + key + "' 
doesn't exist");
+                response.sendError(HttpServletResponse.SC_NOT_FOUND,
+                        "Unable to Get Entry Point ! Msg: Object '" + key + "' 
doesn't exist");
+                return null;
+            }
+
+            logger.debug("Getting WorkFlow Entry Point: " + key);
+
+            // Get all active languages
+            final List locales = jParams.getSite().getLanguageSettings(true);
+
+            final Document resp = db.newDocument();
+            final Element root = 
resp.createElement("GetWorkflowEntryPointResp");
+
+            processWorkflowObject(currentObject, jParams, currentUser, 
locales, resp, root);
+
+            resp.appendChild(root);
+            sendResponse(resp, response);
+
+        } catch (Exception e) {
+            logger.error("Unable to process the request !", e);
+            if (! response.isCommitted()) {
+                
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                        "Unable to Get WorkFlow Entry Point ! Msg: " + 
e.getMessage());
+            }
+        }
+        return null;
+    }
+}

Added: trunk/core/src/java/org/jahia/ajax/sitemap/LockWorkFlowChildObjects.java
URL: 
https://jahia.mine.nu/websvn/filedetails.php?path=/trunk/core/src/java/org/jahia/ajax/sitemap/LockWorkFlowChildObjects.java&rev=12746&repname=jahia
==============================================================================
--- trunk/core/src/java/org/jahia/ajax/sitemap/LockWorkFlowChildObjects.java 
(added)
+++ trunk/core/src/java/org/jahia/ajax/sitemap/LockWorkFlowChildObjects.java 
Tue Jan 10 16:53:52 2006
@@ -0,0 +1,91 @@
+package org.jahia.ajax.sitemap;
+
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionForm;
+import org.jahia.params.ProcessingContext;
+import org.jahia.services.pages.ContentPage;
+import org.jahia.services.usermanager.JahiaUser;
+import org.jahia.services.acl.JahiaBaseACL;
+import org.jahia.services.lock.LockKey;
+import org.jahia.content.ContentObject;
+import org.jahia.content.ObjectKey;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+/**
+ * Struts AJAX based Action that locks all the objects of which the objectkey 
is stated in the
+ * request XML body document. This action doesn't send any response body.
+ * The user needs to have Write access on the page where the WorkFlow is 
launched.
+ *
+ * @author Xavier Lawrence
+ */
+public class LockWorkFlowChildObjects extends SiteMapAbstractAction {
+     private static final org.apache.log4j.Logger logger =
+            org.apache.log4j.Logger.getLogger(LockWorkFlowChildObjects.class);
+
+    public ActionForward execute(final ActionMapping mapping,
+                                 final ActionForm form,
+                                 final HttpServletRequest request,
+                                 final HttpServletResponse response)
+            throws IOException, ServletException {
+        try {
+            // Contains params that will have to given to the ParamBean 
Constructor for correct
+            // initialization of the latter
+            final String params = getParameter(request, response, PARAMS);
+            final ProcessingContext jParams = pcf.getContext(request, response,
+                    super.getServlet().getServletContext(), params);
+
+            final ContentPage currentPage = jParams.getContentPage();
+            final JahiaUser currentUser = jParams.getUser();
+
+            if (currentUser == null || currentPage == null ||
+                    ! currentPage.getACL().getPermission(currentUser, 
JahiaBaseACL.WRITE_RIGHTS)) {
+                logger.warn("Unauthorized attempt to use AJAX Struts Action - 
LockWorkFlowChildObjects");
+                response.sendError(HttpServletResponse.SC_FORBIDDEN,
+                        "Error: Must be logged in and have 'Write' access");
+                return null;
+            }
+
+            final String[] keys = getMultipleXmlNodeValue(request, response, 
KEY);
+
+            for (int i = 0; i < keys.length; i++) {
+                final ContentObject currentObject = 
getContentObjectFromString(keys[i]);
+                if (currentObject == null) continue;
+                final ObjectKey objectKey = currentObject.getObjectKey();
+                if (jParams.settings().areLocksActivated()) {
+                    final LockKey lockKey = 
LockKey.composeLockKey(LockKey.WORKFLOW_ACTION + "_" +
+                            objectKey.getType(), currentObject.getID(), 
currentObject.getPageID());
+                     if (lockRegistry.acquire(lockKey, currentUser, 
currentUser.getUserKey(),
+                            
jParams.getSessionState().getMaxInactiveInterval())) {
+                        logger.info("Lock acquired for object " + objectKey + 
" by " +
+                                currentUser.getUsername());
+                    } else {
+                        logger.info("Cannot acquire lock for object " + 
objectKey + " by " +
+                                currentUser.getUsername());
+                    }
+                }
+            }
+
+            final Document resp = db.newDocument();
+            final Element root = resp.createElement("lockChildObjectsResp");
+
+            resp.appendChild(root);
+            sendResponse(resp, response);
+
+        } catch (Exception e) {
+            logger.error("Unable to process the request !", e);
+            if (! response.isCommitted()) {
+                
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                        "Unable to lock Child Objects ! Msg: " + 
e.getMessage());
+            }
+        }
+
+        return null;
+    }
+}

Added: trunk/core/src/java/org/jahia/ajax/sitemap/SiteMapAbstractAction.java
URL: 
https://jahia.mine.nu/websvn/filedetails.php?path=/trunk/core/src/java/org/jahia/ajax/sitemap/SiteMapAbstractAction.java&rev=12746&repname=jahia
==============================================================================
--- trunk/core/src/java/org/jahia/ajax/sitemap/SiteMapAbstractAction.java 
(added)
+++ trunk/core/src/java/org/jahia/ajax/sitemap/SiteMapAbstractAction.java Tue 
Jan 10 16:53:52 2006
@@ -0,0 +1,362 @@
+/*
+ *                                   ____.
+ *                       __/\ ______|    |__/\.     _______
+ *            __   .____|    |       \   |    +----+       \
+ *    _______|  /--|    |    |    -   \  _    |    :    -   \_________
+ *   \\______: :---|    :    :           |    :    |         \________>
+ *           |__\---\_____________:______:    :____|____:_____\
+ *                                      /_____|
+ *
+ *              . . . i n   j a h i a   w e   t r u s t . . .
+ *
+ *
+ *
+ * ----- BEGIN LICENSE BLOCK -----
+ * Version: JCSL 1.0
+ *
+ * The contents of this file are subject to the Jahia Community Source License
+ * 1.0 or later (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.jahia.org/license
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the rights, obligations and limitations governing use of the contents
+ * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
+ * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
+ * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
+ *
+ * The Shared Modifications are Jahia View Helper.
+ *
+ * The Developer of the Shared Modifications is Jahia Solution S�rl.
+ * Portions created by the Initial Developer are Copyright (C) 2002 by the
+ * Initial Developer. All Rights Reserved.
+ *
+ * ----- END LICENSE BLOCK -----
+ */
+package org.jahia.ajax.sitemap;
+
+import org.jahia.ajax.AjaxAction;
+import org.jahia.content.*;
+import org.jahia.services.pages.ContentPage;
+import org.jahia.services.pages.JahiaPage;
+import org.jahia.services.version.EntryLoadRequest;
+import org.jahia.services.version.ActivationTestResults;
+import org.jahia.services.version.StateModificationContext;
+import org.jahia.services.version.ContentObjectEntryState;
+import org.jahia.services.workflow.WorkflowService;
+import org.jahia.services.lock.LockService;
+import org.jahia.services.lock.LockKey;
+import org.jahia.services.usermanager.JahiaUser;
+import org.jahia.services.sites.SiteLanguageSettings;
+import org.jahia.services.fields.ContentSmallTextField;
+import org.jahia.exceptions.JahiaException;
+import org.jahia.gui.HTMLToolBox;
+import org.jahia.gui.GuiBean;
+import org.jahia.params.ParamBean;
+import org.jahia.params.ProcessingContext;
+import org.jahia.engines.workflow.AdvancedWorkflowEngine;
+import org.jahia.engines.workflow.ActionEntry;
+import org.jahia.engines.workflow.WorkflowHelper;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+
+import java.util.*;
+
+/**
+ * Abstract Class that simply holds common methods regarding SiteMaps.
+ *
+ * @author Xavier Lawrence
+ */
+public abstract class SiteMapAbstractAction extends AjaxAction {
+
+    private static final org.apache.log4j.Logger logger =
+            org.apache.log4j.Logger.getLogger(SiteMapAbstractAction.class);
+
+    protected static final WorkflowService workflowService = 
servicesRegistry.getWorkflowService();
+    protected static final LockService lockRegistry = 
servicesRegistry.getLockService();
+
+    protected static final String KEY = "key";
+
+    /**
+     * Gets all the direct child objects of a given ContentObject, that have a 
separate WorkFlow associated to them.
+     *
+     * @param object      The parent ContentObject to search children from
+     * @param currentUser The current logged Jahia user
+     */
+    protected Collection getChildObjects(final ContentObject object, final 
JahiaUser currentUser) throws JahiaException {
+        final List linked = workflowService.getLinkedContentObjects(object, 
false);
+        final List linkedPages = new ArrayList();
+        for (final Iterator iterator = linked.iterator(); iterator.hasNext();) 
{
+            final ContentObject contentObject = (ContentObject) 
iterator.next();
+            if 
(contentObject.getObjectKey().getType().equals(ContentPageKey.PAGE_TYPE) &&
+                    ((ContentPage) 
contentObject).getPageType(EntryLoadRequest.STAGED) == JahiaPage.TYPE_DIRECT) {
+                linkedPages.add(contentObject);
+            }
+        }
+
+        final List fieldsHere = new ArrayList();
+        final List unlinked = 
workflowService.getUnlinkedContentObjects(object);
+        unlinked.addAll(linkedPages);
+        final Iterator iterator = unlinked.iterator();
+        while (iterator.hasNext()) {
+            final ContentObject contentObject = (ContentObject) 
iterator.next();
+            final int pageId = contentObject.getPageID();
+            if 
(!(contentObject.getObjectKey().getType().equals(ContentPageKey.PAGE_TYPE) && 
object.getID() == pageId))
+            {
+                fieldsHere.add(contentObject);
+            }
+        }
+
+        // v contains all the ContentObjects linked to a WorkFlow
+        final Vector v = new Vector();
+        final Iterator iterator2 = fieldsHere.iterator();
+
+        while (iterator2.hasNext()) {
+            final ContentObject contentObject = (ContentObject) 
iterator2.next();
+            if (contentObject.checkWriteAccess(currentUser)) {
+                if 
(!(contentObject.getObjectKey().getType().equals(ContentPageKey.PAGE_TYPE))) {
+                    final ContentObject main = 
workflowService.getMainLinkObject(contentObject);
+                    v.add(main);
+                } else {
+                    v.add(contentObject);
+                }
+            }
+        }
+
+        return v;
+    }
+
+    /**
+     * Returns the ContentObject associated with the given key
+     *
+     * @param key The ObjectKey value represented as a String
+     * @return The ContentObject or null if not found
+     */
+    protected ContentObject getContentObjectFromString(final String key) 
throws ClassNotFoundException {
+        final ObjectKey objectKey = ObjectKey.getInstance(key);
+        final JahiaObject jahiaObject = JahiaObject.getInstance(objectKey);
+        return (ContentObject) jahiaObject;
+    }
+
+    /**
+     *
+     */
+    protected void processPage(final ContentPage page,
+                               final ProcessingContext jParams,
+                               final List locales,
+                               final Document resp,
+                               final Element root) throws JahiaException {
+        final Map languagesStates = workflowService.getLanguagesStates(page);
+        final Hashtable titles;
+                if 
(jParams.getOperationMode().equals(ProcessingContext.NORMAL)) {
+                    titles = page.getTitles(ContentPage.ACTIVATED_PAGE_TITLES);
+                } else {
+                    titles = page.getTitles(ContentPage.LAST_UPDATED_TITLES);
+                }
+                String pageTitle1 = (String) 
titles.get(jParams.getLocale().toString());
+
+                if (pageTitle1 == null || pageTitle1.length() == 0) {
+                    pageTitle1 = "N/A";
+                }
+
+                final int pid = page.getID();
+                final Element item = resp.createElement("page");
+                item.setAttribute("id", String.valueOf(pid));
+                item.setAttribute("key", page.getObjectKey().toString());
+                item.setAttribute("title", pageTitle1);
+                item.setAttribute("url", getPageURL(jParams, pid, 
jParams.getLocale().toString()));
+
+                for (int j = 0; j < locales.size(); j++) {
+                    final String languageCode = ((SiteLanguageSettings) 
locales.get(j)).getCode();
+                    logger.debug("Found page: " + page.getID() + " in " + 
languageCode);
+                    final Element lang = resp.createElement("lang");
+                    lang.setAttribute("code", languageCode);
+                    final Integer languageState = (Integer) 
languagesStates.get(languageCode);
+                    if (languageState == null || languageState.intValue() == 
-1) {
+                        lang.appendChild(resp.createTextNode("-1"));
+                    } else {
+                        
lang.appendChild(resp.createTextNode(languageState.toString()));
+                    }
+                    item.appendChild(lang);
+                }
+                root.appendChild(item);
+    }
+
+    /**
+     *
+     */
+    protected void processWorkflowObject(final ContentObject object,
+                                         final ProcessingContext jParams,
+                                         final JahiaUser currentUser,
+                                         final List locales,
+                                         final Document resp,
+                                         final Element root) throws 
JahiaException {
+        final Map languagesStates = workflowService.getLanguagesStates(object);
+
+        final int id = object.getID();
+        final int pageID = object.getPageID();
+        final ObjectKey objectKey = object.getObjectKey();
+        final Element item = resp.createElement("object");
+        item.setAttribute("id", String.valueOf(id));
+        item.setAttribute("key", objectKey.toString());
+        item.setAttribute("title", getAPageTitleAnyway(object, 
jParams.getLocale().toString()));
+        item.setAttribute("url", getPageURL(jParams, pageID, 
jParams.getLocale().toString()));
+
+        final WorkflowHelper workflowHelper = 
AdvancedWorkflowEngine.getWorkflowHelper(jParams, object);
+        final List tabOptions = workflowHelper.getAllOptions();
+
+        String action = null;
+        String display = null;
+        final Iterator iterator = tabOptions.iterator();
+        while (iterator.hasNext()) {
+            final ActionEntry actionEntry = (ActionEntry) iterator.next();
+            if (display == null) {
+                display = actionEntry.getWorkflowKey();
+                action = actionEntry.getKey();
+            }
+            if 
(actionEntry.getWorkflowKey().equals(jParams.getParameter("display"))) {
+                if (!display.equals(jParams.getParameter("display"))) {
+                    display = actionEntry.getWorkflowKey();
+                    action = actionEntry.getKey();
+                }
+                if 
(actionEntry.getKey().equals(jParams.getParameter("workflowAction"))) {
+                    action = actionEntry.getKey();
+                    break;
+                }
+            }
+        }
+
+        final TreeSet additionalOptions = new TreeSet();
+        final Iterator tabOptionsiterator = tabOptions.iterator();
+        while (tabOptionsiterator.hasNext()) {
+            final ActionEntry actionEntry = (ActionEntry) 
tabOptionsiterator.next();
+            if (actionEntry.getWorkflowKey().equals(display)) {
+                if (actionEntry.getKey().equals(action)) {
+                    additionalOptions.add(actionEntry.getAdditionalKey());
+                }
+            }
+        }
+
+        final Iterator iterator2 = additionalOptions.iterator();
+        while (iterator2.hasNext()) {
+            final String additionalKey = (String) iterator2.next();
+            if (workflowHelper.isActive(object.getObjectKey(), 
jParams.getLocale().toString(), action, additionalKey)) {
+                logger.debug("additionalKey: " + additionalKey);
+                item.setAttribute("additionalKey", additionalKey);
+                break;
+            }
+        }
+
+        // Get the lock for the object
+        final HTMLToolBox html = new GuiBean(jParams).html();
+        if (jParams.settings().areLocksActivated()) {
+            final LockKey lockKey = 
LockKey.composeLockKey(LockKey.WORKFLOW_ACTION + "_" +
+                    objectKey.getType(), id, pageID);
+            if (lockRegistry.acquire(lockKey, currentUser, 
currentUser.getUserKey(),
+                    jParams.getSessionState().getMaxInactiveInterval())) {
+                logger.info("Lock acquired for object " + objectKey + " by " + 
currentUser.getUsername());
+            } else {
+                logger.info("Cannot acquire lock for object " + objectKey + " 
by " + currentUser.getUsername());
+                item.setAttribute("locked", 
html.drawLockEngineLauncher(lockKey));
+            }
+        }
+
+        final Set languageCodes = getLanguageSet(locales);
+
+        final ActivationTestResults results = 
workflowService.isValidForActivation(object, languageCodes,
+                jParams, new StateModificationContext(objectKey, 
languageCodes, false));
+
+        if (results.getWarnings().size() > 0) {
+            item.setAttribute("warnings", 
html.drawShowReportLauncher(objectKey.toString()));
+            ((ParamBean) 
jParams).getRequest().getSession().setAttribute(objectKey.toString(), results);
+        }
+
+        if (results.getErrors().size() > 0) {
+            item.setAttribute("errors", 
html.drawShowReportLauncher(objectKey.toString()));
+            ((ParamBean) 
jParams).getRequest().getSession().setAttribute(objectKey.toString(), results);
+        }
+
+        for (int j = 0; j < locales.size(); j++) {
+            final String languageCode = ((SiteLanguageSettings) 
locales.get(j)).getCode();
+            logger.debug("Found object: " + id + " in " + languageCode);
+            final Element lang = resp.createElement("lang");
+            lang.setAttribute("code", languageCode);
+            final Integer languageState = (Integer) 
languagesStates.get(languageCode);
+            if (languageState == null || languageState.intValue() == -1) {
+                lang.appendChild(resp.createTextNode("-1"));
+            } else {
+                
lang.appendChild(resp.createTextNode(languageState.toString()));
+            }
+            item.appendChild(lang);
+        }
+        root.appendChild(item);
+    }
+
+    /**
+     * Utility method to get a display Title for a ContentObject in a given 
language
+     *
+     * @param object       The ContentObject to get the title from
+     * @param languageCode The language of the title
+     * @return The title value in a String object
+     */
+    protected String getAPageTitleAnyway(final ContentObject object, final 
String languageCode) {
+        final ObjectKey objectKey = object.getObjectKey();
+        String pageTitle1;
+        if (objectKey.getType().equals(ContentPageKey.PAGE_TYPE)) {
+            final ContentPage contentPage = (ContentPage) object;
+            final Hashtable titles = 
contentPage.getTitles(ContentPage.LAST_UPDATED_TITLES);
+            pageTitle1 = (String) titles.get(languageCode);
+
+            if (pageTitle1 == null || pageTitle1.length() == 0) {
+                pageTitle1 = "N/A";
+            }
+
+        } else {
+            try {
+                final ContentDefinition def = 
ContentDefinition.getContentDefinitionInstance(object.getDefinitionKey(null));
+                pageTitle1 = def.getName();
+                if 
(objectKey.getType().equals(ContentContainerKey.CONTAINER_TYPE)) {
+                    pageTitle1 += " (Container " + objectKey.getIDInType() + 
")";
+                    try {
+                        final List l = object.getChilds(null, null, null);
+                        for (final Iterator iterator = l.iterator(); 
iterator.hasNext();) {
+                            final ContentObject contentObject = 
(ContentObject) iterator.next();
+                            if (contentObject instanceof 
ContentSmallTextField) {
+                                pageTitle1 = ((ContentSmallTextField) 
contentObject).
+                                        getValue((ContentObjectEntryState) 
contentObject.getActiveAndStagingEntryStates().last()) +
+                                        " (Container " + 
objectKey.getIDInType() + ")";
+                                break;
+                            }
+                        }
+                    } catch (JahiaException e) {
+                        logger.error(e.getMessage(), e);
+                    }
+                } else if 
(objectKey.getType().equals(ContentContainerListKey.CONTAINERLIST_TYPE)) {
+                    pageTitle1 += " (List " + objectKey.getIDInType() + ")";
+                } else if 
(objectKey.getType().equals(ContentFieldKey.FIELD_TYPE)) {
+                    pageTitle1 += " (Field " + objectKey.getIDInType() + ")";
+                }
+            } catch (ClassNotFoundException e) {
+                pageTitle1 = objectKey.toString();
+                logger.error(e, e);
+            }
+        }
+        return pageTitle1;
+    }
+
+    /**
+     * Utility method that converts a List to a Set
+     *
+     * @param locales The list that will be converted
+     * @return The Set made of the objects contained in the given List
+     */
+    protected final Set getLanguageSet(final List locales) {
+        final Set languageCodes = new HashSet();
+        for (int i = 0; i < locales.size(); i++) {
+            final String languageCode = ((SiteLanguageSettings) 
locales.get(i)).getCode();
+            languageCodes.add(languageCode);
+        }
+        return languageCodes;
+    }
+}

Added: 
trunk/core/src/java/org/jahia/ajax/sitemap/UnlockWorkFlowChildObjects.java
URL: 
https://jahia.mine.nu/websvn/filedetails.php?path=/trunk/core/src/java/org/jahia/ajax/sitemap/UnlockWorkFlowChildObjects.java&rev=12746&repname=jahia
==============================================================================
--- trunk/core/src/java/org/jahia/ajax/sitemap/UnlockWorkFlowChildObjects.java 
(added)
+++ trunk/core/src/java/org/jahia/ajax/sitemap/UnlockWorkFlowChildObjects.java 
Tue Jan 10 16:53:52 2006
@@ -0,0 +1,123 @@
+/*
+ *                                   ____.
+ *                       __/\ ______|    |__/\.     _______
+ *            __   .____|    |       \   |    +----+       \
+ *    _______|  /--|    |    |    -   \  _    |    :    -   \_________
+ *   \\______: :---|    :    :           |    :    |         \________>
+ *           |__\---\_____________:______:    :____|____:_____\
+ *                                      /_____|
+ *
+ *              . . . i n   j a h i a   w e   t r u s t . . .
+ *
+ *
+ *
+ * ----- BEGIN LICENSE BLOCK -----
+ * Version: JCSL 1.0
+ *
+ * The contents of this file are subject to the Jahia Community Source License
+ * 1.0 or later (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.jahia.org/license
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the rights, obligations and limitations governing use of the contents
+ * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
+ * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
+ * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
+ *
+ * The Shared Modifications are Jahia View Helper.
+ *
+ * The Developer of the Shared Modifications is Jahia Solution S�rl.
+ * Portions created by the Initial Developer are Copyright (C) 2002 by the
+ * Initial Developer. All Rights Reserved.
+ *
+ * ----- END LICENSE BLOCK -----
+ */
+package org.jahia.ajax.sitemap;
+
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.jahia.content.ContentObject;
+import org.jahia.content.ObjectKey;
+import org.jahia.params.ProcessingContext;
+import org.jahia.services.acl.JahiaBaseACL;
+import org.jahia.services.lock.LockKey;
+import org.jahia.services.pages.ContentPage;
+import org.jahia.services.usermanager.JahiaUser;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * Struts AJAX based Action that unlocks all the objects of which the 
objectkey is stated in the
+ * request XML body document. This action doesn't send any response body.
+ * The user needs to have Write access on the page where the WorkFlow is 
launched.
+ *
+ * @author Xavier Lawrence
+ */
+public class UnlockWorkFlowChildObjects extends SiteMapAbstractAction {
+
+    private static final org.apache.log4j.Logger logger =
+            
org.apache.log4j.Logger.getLogger(UnlockWorkFlowChildObjects.class);
+
+    public ActionForward execute(final ActionMapping mapping,
+                                 final ActionForm form,
+                                 final HttpServletRequest request,
+                                 final HttpServletResponse response)
+            throws IOException, ServletException {
+        try {
+            // Contains params that will have to given to the ParamBean 
Constructor for correct
+            // initialization of the latter
+            final String params = getParameter(request, response, PARAMS);
+            final ProcessingContext jParams = pcf.getContext(request, response,
+                    super.getServlet().getServletContext(), params);
+
+            final ContentPage currentPage = jParams.getContentPage();
+            final JahiaUser currentUser = jParams.getUser();
+
+            if (currentUser == null || currentPage == null ||
+                    ! currentPage.getACL().getPermission(currentUser, 
JahiaBaseACL.WRITE_RIGHTS)) {
+                logger.warn("Unauthorized attempt to use AJAX Struts Action - 
UnlockWorkFlowChildObjects");
+                response.sendError(HttpServletResponse.SC_FORBIDDEN,
+                        "Error: Must be logged in and have 'Write' access");
+                return null;
+            }
+
+            final String[] keys = getMultipleXmlNodeValue(request, response, 
KEY);
+
+            for (int i = 0; i < keys.length; i++) {
+                final ContentObject currentObject = 
getContentObjectFromString(keys[i]);
+                if (currentObject == null) continue;
+                final ObjectKey objectKey = currentObject.getObjectKey();
+                if (jParams.settings().areLocksActivated()) {
+                    final LockKey lockKey = 
LockKey.composeLockKey(LockKey.WORKFLOW_ACTION + "_" +
+                            objectKey.getType(), currentObject.getID(), 
currentObject.getPageID());
+                    lockRegistry.release(lockKey, currentUser, 
currentUser.getUserKey());
+                    logger.info("Lock released for object " + objectKey +
+                            " by " + currentUser.getUsername());
+                }
+            }
+
+            final Document resp = db.newDocument();
+            final Element root = resp.createElement("UnlockChildObjectsResp");
+
+            resp.appendChild(root);
+            sendResponse(resp, response);
+
+        } catch (Exception e) {
+            logger.error("Unable to process the request !", e);
+            if (! response.isCommitted()) {
+                
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                        "Unable to Unlock Child Objects ! Msg: " + 
e.getMessage());
+            }
+        }
+
+        return null;
+    }
+}

Reply via email to