xlawrence 2005/11/09 17:57:34 CET
Modified files:
core/src/webapp/jsp/jahia/javascript serverdatetime.js
Added files:
core/src/java/org/jahia/ajax AjaxAction.java
core/src/java/org/jahia/ajax/actionmenus
GetMenuItemsAction.java
core/src/java/org/jahia/ajax/serverdatetime
GetClientServerTimeDiffAction.java
GetServerTimeAction.java
Removed files:
core/src/java/org/jahia/ajax AjaxDispatchAction.java
AjaxServlet.java
core/src/java/org/jahia/ajax/serverdatetime
DateTimeAction.java
Log:
- Updated AJAX java related code to only use Struts Actions
- updated ParamBean and related class in order to be able to give extra
parameters in the constructor and private method buildcustomParameters
- cleanUp and optimizations
Revision Changes Path
1.1 +275 -0 jahia/core/src/java/org/jahia/ajax/AjaxAction.java (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/ajax/AjaxAction.java?rev=1.1&content-type=text/plain
1.2 +0 -107
jahia/core/src/java/org/jahia/ajax/AjaxDispatchAction.java (dead)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/ajax/AjaxDispatchAction.java?rev=1.1&content-type=text/plain
1.9 +0 -409 jahia/core/src/java/org/jahia/ajax/AjaxServlet.java
(dead)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/ajax/AjaxServlet.java?rev=1.8&content-type=text/plain
1.1 +342 -0
jahia/core/src/java/org/jahia/ajax/actionmenus/GetMenuItemsAction.java (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/ajax/actionmenus/GetMenuItemsAction.java?rev=1.1&content-type=text/plain
1.2 +0 -162
jahia/core/src/java/org/jahia/ajax/serverdatetime/DateTimeAction.java (dead)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/ajax/serverdatetime/DateTimeAction.java?rev=1.1&content-type=text/plain
1.1 +121 -0
jahia/core/src/java/org/jahia/ajax/serverdatetime/GetClientServerTimeDiffAction.java
(new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/ajax/serverdatetime/GetClientServerTimeDiffAction.java?rev=1.1&content-type=text/plain
1.1 +114 -0
jahia/core/src/java/org/jahia/ajax/serverdatetime/GetServerTimeAction.java (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/ajax/serverdatetime/GetServerTimeAction.java?rev=1.1&content-type=text/plain
1.4 +4 -4
jahia/core/src/webapp/jsp/jahia/javascript/serverdatetime.js
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/webapp/jsp/jahia/javascript/serverdatetime.js.diff?r1=1.3&r2=1.4&f=h
Index: serverdatetime.js
===================================================================
RCS file:
/home/cvs/repository/jahia/core/src/webapp/jsp/jahia/javascript/serverdatetime.js,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- serverdatetime.js 22 Aug 2005 09:33:00 -0000 1.3
+++ serverdatetime.js 9 Nov 2005 16:57:32 -0000 1.4
@@ -119,8 +119,8 @@
try {
// correct values are "POST" or "GET" (HTTP methods).
var method = "GET" ;
- var url = context + "/ajaxaction/DateTime";
- var data = "method=getServerTime&dateformat=" + dateFormat +
"&timeZoneOffSet=" + timeZoneOffSet;
+ var url = context + "/ajaxaction/GetServerTime";
+ var data = "dateformat=" + dateFormat + "&timeZoneOffSet=" +
timeZoneOffSet;
if (method == "GET") {
url += "?" + data;
@@ -188,8 +188,8 @@
try {
// correct values are "POST" or "GET" (HTTP methods).
var method = "GET" ;
- var url = context + "/ajaxaction/DateTime";
- var data =
"method=getServerClientTimeDiff&clientTime="+clientTime+"&timeZoneOffSet=" +
clientTimeZoneOffSet;
+ var url = context + "/ajaxaction/GetClientServerTimeDiff";
+ var data = "clientTime="+clientTime+"&timeZoneOffSet=" +
clientTimeZoneOffSet;
if (method == "GET") {
url += "?" + data;
Index: AjaxAction.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . 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;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
/**
* Represents an Abstract Struts Action that will be sub-classed to implement
* request processing for AJAX calls. It contains utility methods and 1
abstract method.
*
* @author Xavier Lawrence
*/
public abstract class AjaxAction extends Action {
private static final org.apache.log4j.Logger logger =
org.apache.log4j.Logger.getLogger(AjaxAction.class);
protected static final String DELIMITER = ";;";
protected static final String CHARSET = "UTF-8";
protected static final String XML_HEADER =
"<?xml version=\"1.0\" encoding=\"" + CHARSET + "\"?>\n";
protected static final String CACHE_CONTROL = "Cache-Control";
protected static final String NO_CACHE = "no-cache";
protected static final String XML_CONTENT = "text/xml";
/**
* Simple utility method to retreive a parameter from a request and send
* an error message (status 400) in case the parameter is not found.
*
* @param request The current HttpServletRequest
* @param response The HttpServletResponse linked to the current request
* @param name The parameter name
* @return A String containing the value of the given parameter
* @throws ServletException
* @throws IOException
*/
protected String getParameter(final HttpServletRequest request,
final HttpServletResponse response,
final String name)
throws ServletException, IOException {
if (request == null) {
throw new NullPointerException("'request' cannot be null");
}
if (response == null) {
throw new NullPointerException("'response' cannot be null");
}
if (name == null) {
throw new NullPointerException("'name' cannot be null");
}
final String value = request.getParameter(name);
if (value == null) {
logger.fatal("Missing required '" + name + "' parameter in
request.");
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"Missing required '" + name + "' parameter in request.");
throw new ServletException("Missing required '" + name + "'
parameter in request.");
}
return value;
}
/**
* Simple utility method to retreive a parameter from a request. If the
value is not found,
* it will return the defaultValue.
*
* @param request The current HttpServletRequest
* @param name The parameter name
* @param defaultValue The default value to return in case the parameter
is not found
* @return A String representing the value of the parameter
or the defaultValue
* in case the parameter is not found.
*/
protected String getParameter(final HttpServletRequest request,
final String name,
final String defaultValue) {
if (request == null) {
throw new NullPointerException("'request' cannot be null");
}
if (name == null) {
throw new NullPointerException("'name' cannot be null");
}
if (defaultValue == null) {
throw new NullPointerException("'defaultValue' cannot be null");
}
final String value = request.getParameter(name);
if (value == null) {
return defaultValue;
}
return value;
}
/**
* Simple utility method to build a String representing an XML node and
its
* value.
*
* @param buff The StringBuffer that will be used to store the result
* @param tagName The XML tag name
* @param tagValue The XML tag value.
*/
protected void buildXmlElement (final StringBuffer buff,
final String tagName,
final String tagValue) {
if (buff == null) {
throw new NullPointerException("'buff' cannot be null");
}
if (tagName == null) {
throw new NullPointerException("'tagName' cannot be null");
}
if (tagValue == null || tagValue.length() == 0) {
return;
}
buff.append("<").append(tagName).append(">");
buff.append(tagValue);
buff.append("</").append(tagName).append(">\n");
}
/**
* Simple utility method to build a String representing an XML node and
its
* value.
*
* @param tagName The XML tag name
* @param tagValue The XML tag value.
* @return A String representing the XML element
*/
protected String buildXmlElement(final String tagName,
final String tagValue) {
if (tagName == null) {
throw new NullPointerException("'tagName' cannot be null");
}
if (tagValue == null || tagValue.length() == 0) {
return "";
}
final StringBuffer buff = new StringBuffer();
buff.append("<").append(tagName).append(">");
buff.append(tagValue);
buff.append("</").append(tagName).append(">\n");
return buff.toString();
}
/**
* Builds the response message creating XML elements with the data given
and then sends the response back
* to the client application.
*
* @param xmlTagNames The Collection of tag names (Order is important,
type of elements must be String)
* @param xmlTagValues The Collection of tag values (Order is important,
type of elements must be String)
* @param response HttpServletResponse for the current Re
* @throws IOException
*/
protected void sendResponse(final Collection xmlTagNames,
final Collection xmlTagValues,
final HttpServletResponse response)
throws IOException {
sendResponse((String[]) xmlTagNames.toArray(new String[]{}),
(String[]) xmlTagValues.toArray(new String[]{}),
response);
}
/**
* Builds the response message creating XML elements with the data given
and then sends the response back
* to the client application.
*
* @param xmlTagNames The array of tag names (Order is important)
* @param xmlTagValues The array of tag values (Order is important)
* @param response
* @throws IOException
*/
protected void sendResponse(final String[] xmlTagNames,
final String[] xmlTagValues,
final HttpServletResponse response)
throws IOException {
if (xmlTagNames == null) {
throw new NullPointerException("'xmlTagNames' cannot be null");
}
if (xmlTagValues == null) {
throw new NullPointerException("'xmlTagValues' cannot be null");
}
if (xmlTagNames.length != xmlTagValues.length) {
throw new IllegalArgumentException("'xmlTagNames' and
'xmlTagValues' must have the same length");
}
final StringBuffer buff = new StringBuffer();
buff.append(XML_HEADER);
for (int i=0; i<xmlTagNames.length; i++) {
final String tagName = xmlTagNames[i];
final String tagValue = xmlTagValues[i];
buildXmlElement(buff, tagName, tagValue);
}
//logger.debug("Response:\n" + buff);
final byte[] bytes = buff.toString().getBytes(CHARSET);
response.setContentType(XML_CONTENT); // mandatory, do not
remove ! (see AJAX spec)
response.setHeader(CACHE_CONTROL, NO_CACHE); // mandatory, do not
remove ! (see AJAX spec)
response.setContentLength(bytes.length);
response.setStatus(HttpServletResponse.SC_OK);
final OutputStream out = response.getOutputStream();
out.write(bytes);
out.flush();
}
/**
* Abstract method that will execute the AJAX Action in the implementing
sub-classes.
*
* @see Action#execute(org.apache.struts.action.ActionMapping,
org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
*
* @param mapping Struts ActionMapping
* @param form Struts ActionForm
* @param request The current HttpServletRequest
* @param response The HttpServletResponse linked to the
current request
* @return ActionForward Struts ActionForward
* @throws IOException
* @throws ServletException
*/
public abstract ActionForward execute(final ActionMapping mapping,
final ActionForm form,
final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException;
}
Index: GetMenuItemsAction.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . 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.actionmenus;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.jahia.ajax.AjaxAction;
import org.jahia.data.beans.*;
import org.jahia.data.containers.JahiaContainer;
import org.jahia.data.containers.JahiaContainerList;
import org.jahia.data.fields.JahiaField;
import org.jahia.data.fields.LoadFlags;
import org.jahia.exceptions.JahiaException;
import org.jahia.gui.GuiBean;
import org.jahia.gui.HTMLToolBox;
import org.jahia.gui.menuIdPropsBean;
import org.jahia.hibernate.manager.SpringContextSingleton;
import org.jahia.params.ProcessingContext;
import org.jahia.params.ProcessingContextFactory;
import org.jahia.registries.ServicesRegistry;
import org.jahia.services.acl.JahiaBaseACL;
import org.jahia.services.pages.JahiaPage;
import org.jahia.services.usermanager.JahiaUser;
import org.jahia.services.version.EntryLoadRequest;
import org.springframework.beans.factory.BeanFactory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
/**
* Gets the items of a specific Action Menu
*
* @author Xavier Lawrence
*/
public class GetMenuItemsAction extends AjaxAction {
private static final String AJAX_FIELDSET = "fieldset";
private static final String AJAX_LAUNCHER = "launcher";
private static final String AJAX_IMAGE = "image";
private static final String AJAX_METHOD = "method";
private static final String KEY = "key";
private static final String TYPE = "type";
private static final String DEF = "def";
private static final String PARENT = "parent";
private static final String PAGE = "page";
private static final String PARAMS = "params";
private static final String DEFAULT_LOCK_IMAGE = "lock_grey.gif";
private static final String MENU_ID_PROP_BEAN =
"org.jahia.gui.menuIdPropsBean";
private static final String RESSOURCE_BUNDLE = "resourceBundle";
private static final String LOCK_ICON = "lockIcon";
private static final String SLASH = "/";
private static final String GIF = ".gif";
private static final org.apache.log4j.Logger logger =
org.apache.log4j.Logger.getLogger(GetMenuItemsAction.class);
private static final ServicesRegistry servicesRegistry =
ServicesRegistry.getInstance();
private static final BeanFactory bf =
SpringContextSingleton.getInstance().getContext();
private static final ProcessingContextFactory pcf =
(ProcessingContextFactory) bf.
getBean(ProcessingContextFactory.class.getName());
/**
* Returns the menu items for the specified Action Menu
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward (null)
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/
public ActionForward execute(final ActionMapping mapping,
final ActionForm form,
final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
logger.debug("GetMenuItemsAction - execute");
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 JahiaPage currentPage = jParams.getPage();
final JahiaUser currentUser = jParams.getUser();
if (currentUser == null || currentPage == null ||
! currentPage.getACL().getPermission(currentUser,
JahiaBaseACL.WRITE_RIGHTS)) {
logger.warn("Unauthorized attempt to use AJAX Servlet");
response.sendError(HttpServletResponse.SC_FORBIDDEN,
"Must be logged in and have 'Write' access");
return null;
}
final int pid = jParams.getPageID();
logger.debug("jParams: pid = " + pid +
", user = " + currentUser.getName() +
", mode = " + jParams.getOperationMode() +
", lang = " + jParams.getLocale() +
", site: " + jParams.getSite());
final String objectType = getParameter(request, response, TYPE);
final String objectID = getParameter(request, response, KEY);
final String definitionID = getParameter(request, response, DEF);
final String parentID = getParameter(request, response, PARENT);
logger.info("ProcessMenuRequest: objectType=" + objectType +
", objectID=" + objectID +
", definitionID=" + definitionID +
", parentID=" + parentID +
", pageID=" + pid);
// The unique contentObject ID
final int objID = Integer.parseInt(objectID);
final EntryLoadRequest elr = new
EntryLoadRequest(EntryLoadRequest.
STAGING_WORKFLOW_STATE,
0,
jParams.getLocales());
jParams.setSubstituteEntryLoadRequest(elr);
final ContentBean bean;
// Action Menu for a page
if (PageBean.TYPE.equals(objectType)) {
bean = new PageBean(currentPage, jParams);
// Action Menu for a ContainerList
} else if (ContainerListBean.TYPE.equals(objectType)) {
final JahiaContainerList list;
if (objID > 0) {
list = servicesRegistry.getJahiaContainersService().
loadContainerListInfo(objID, elr);
} else {
final int parentid = Integer.parseInt(parentID);
if (parentid == pid) {
list = new JahiaContainerList(0, 0,
pid, Integer.parseInt(definitionID), 0);
} else {
list = new JahiaContainerList(0, parentid,
pid, Integer.parseInt(definitionID), 0);
}
}
logger.debug("ContainerListID: " + list.getID() + ", def: " +
list.getDefinition().getID());
bean = new ContainerListBean(list, jParams);
// Action Menu for a Container
} else if (ContainerBean.TYPE.equals(objectType)) {
final JahiaContainer container =
servicesRegistry.getJahiaContainersService().
loadContainerInfo(objID, elr);
bean = new ContainerBean(container, jParams);
// Action Menu for a Field
} else if (FieldBean.TYPE.equals(objectType)) {
final JahiaField field =
servicesRegistry.getJahiaFieldService().
loadField(objID, LoadFlags.ALL, jParams, elr);
bean = new FieldBean(field, jParams);
} else {
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"Unknown 'ObjectType' value ! 'ObjectType' value
should be '" +
PageBean.TYPE + "', '" +
ContainerListBean.TYPE + "', '" +
ContainerBean.TYPE + "' or '" +
FieldBean.TYPE + "'.");
return null;
}
// Get all the information regarding the Action entries
final Map info = getActionsInfo(bean, jParams);
logger.debug("ActionsInfo:\n" + info);
jParams.resetSubstituteEntryLoadRequest();
// Fill up the tag names (Order matters !!!)
final Vector xmlTagNames = new Vector ();
xmlTagNames.addElement(KEY);
xmlTagNames.addElement(TYPE);
xmlTagNames.addElement(DEF);
xmlTagNames.addElement(PARENT);
xmlTagNames.addElement(PAGE);
if (info.containsKey(AJAX_FIELDSET)) {
xmlTagNames.addElement(AJAX_FIELDSET);
}
xmlTagNames.addElement(AJAX_LAUNCHER);
xmlTagNames.addElement(AJAX_IMAGE);
xmlTagNames.addElement(AJAX_METHOD);
// Fill up the tag values (Order matters !!!)
final Vector xmlTagValues = new Vector();
xmlTagValues.addElement(objectID);
xmlTagValues.addElement(objectType);
xmlTagValues.addElement(definitionID);
xmlTagValues.addElement(parentID);
xmlTagValues.addElement(Integer.toString(pid));
if (info.containsKey(AJAX_FIELDSET)) {
xmlTagValues.addElement(info.get(AJAX_FIELDSET));
}
xmlTagValues.addElement(info.get(AJAX_LAUNCHER));
xmlTagValues.addElement(info.get(AJAX_IMAGE));
xmlTagValues.addElement(info.get(AJAX_METHOD));
// Build and send the response message...
sendResponse(xmlTagNames, xmlTagValues, response);
} catch (Exception e) {
logger.fatal("Unable to process the request !", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Unable to process the request ! Msg: " + e.getMessage());
}
return null;
}
/**
* Retrieves all the information required to build the actual action menu.
*
* @param bean The ContentBean for which the menu will be built
* @param jParams ProcessingContext
* @throws org.jahia.exceptions.JahiaException
*
*/
protected Map getActionsInfo(final ContentBean bean,
final ProcessingContext jParams) throws
JahiaException {
final GuiBean gui = new GuiBean(jParams);
final HTMLToolBox box = new HTMLToolBox(gui, jParams);
final Map result = new HashMap();
final menuIdPropsBean menuIdProps = (menuIdPropsBean)
bf.getBean(MENU_ID_PROP_BEAN);
final Map objectInfo =
menuIdProps.get(box.buildUniqueContentID(bean));
logger.debug("objectInfo for ContentBean " + bean.getID() + ": " +
objectInfo);
if (objectInfo.get("useFieldSet").equals(Boolean.TRUE)) {
final String param;
if (bean.isCompletelyLocked()) {
param = "complete";
} else if (bean.isPartiallyLocked()) {
param = "partial";
} else {
param = null;
}
result.put(AJAX_FIELDSET, param);
}
final Iterator actionURIIter =
bean.getActionURIBeans().entrySet().iterator();
final StringBuffer launchers = new StringBuffer();
final StringBuffer methods = new StringBuffer();
final StringBuffer images = new StringBuffer();
while (actionURIIter.hasNext()) {
final Map.Entry curEntry = (Map.Entry) actionURIIter.next();
final ActionURIBean curActionURIBean = (ActionURIBean)
curEntry.getValue();
if (curActionURIBean.isAuthorized()) {
launchers.append(curActionURIBean.getLauncherUri()).append(DELIMITER);
final String resourceBundle = (String)
objectInfo.get(RESSOURCE_BUNDLE);
methods.append(box.getResource(resourceBundle,
curActionURIBean.getName())).append(DELIMITER);
images.append(box.getURLImageContext());
if (curActionURIBean.isLocked()) {
final String lockIcon = (String)
objectInfo.get(LOCK_ICON);
if (lockIcon == null) {
images.append(SLASH).append(DEFAULT_LOCK_IMAGE);
} else {
images.append(SLASH).append(lockIcon);
}
} else {
images.append(SLASH).append(curActionURIBean.getName()).
append(GIF);
}
images.append(DELIMITER);
}
}
if (methods.length() > 0) {
result.put(AJAX_LAUNCHER, launchers.toString());
result.put(AJAX_METHOD, methods.toString());
result.put(AJAX_IMAGE, images.toString());
}
return result;
}
}
Index: GetClientServerTimeDiffAction.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . 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.serverdatetime;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.jahia.ajax.AjaxAction;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.TimeZone;
/**
* Gets the TimeZone difference between the client and the server.
*
* @author Xavier Lawrence
*/
public class GetClientServerTimeDiffAction extends AjaxAction {
private static final String SERVER_CLIENT_TIME_DIFF =
"serverClientTimeDiff";
private static final org.apache.log4j.Logger logger =
org.apache.log4j.Logger.getLogger(GetServerTimeAction.class);
/**
* Returns the server client different number of minutes + secondes in
millis
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward (null)
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/
public ActionForward execute(final ActionMapping mapping,
final ActionForm form,
final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
logger.debug("GetServerTimeAction - execute");
try {
final String clientTimeVal = getParameter(request, response,
"clientTime");
long clientTime;
try {
clientTime = Long.parseLong(clientTimeVal);
} catch (Throwable t) {
clientTime = 0;
}
final String timeZoneOffSetVal = getParameter(request, response,
"timeZoneOffSet");
long timeZoneOffSet;
try {
timeZoneOffSet = Long.parseLong(timeZoneOffSetVal);
} catch (Throwable t) {
timeZoneOffSet = 0;
}
final Date now = new Date();
final int hostTimeZone =
TimeZone.getDefault().getOffset(now.getTime());
// client Time in UTC
clientTime = clientTime - timeZoneOffSet;
// servet Time in UTC
final long serverTime = now.getTime() - hostTimeZone;
final long diffTime = serverTime - clientTime;
// Build and send the response message...
sendResponse(new String[]{SERVER_CLIENT_TIME_DIFF},
new String[]{String.valueOf(diffTime)},
response);
} catch (Exception e) {
logger.fatal("Unable to process the request !", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Unable to process the request ! Msg: " + e.getMessage());
}
return null;
}
}
Index: GetServerTimeAction.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . 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.serverdatetime;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.jahia.ajax.AjaxAction;
import org.jahia.data.fields.JahiaDateFieldUtil;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
/**
* Gets the Server current time and returns it to the client.
*
* @author Xavier Lawrence
*/
public class GetServerTimeAction extends AjaxAction {
private static final String SERVER_TIME = "servertime";
private static final org.apache.log4j.Logger logger =
org.apache.log4j.Logger.getLogger(GetServerTimeAction.class);
/**
* Returns the server time
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward (null)
* @throws IOException
* @throws ServletException
*/
public ActionForward execute(final ActionMapping mapping,
final ActionForm form,
final HttpServletRequest request,
final HttpServletResponse response)
throws IOException, ServletException {
logger.debug("GetServerTimeAction - execute");
try {
final String dateformat = getParameter(request, response,
"dateformat");
final SimpleDateFormat df =
JahiaDateFieldUtil.getSimpleDateFormat(dateformat,
dateformat, Locale.getDefault());
final String timeZoneOffSetVal = getParameter(request, response,
"timeZoneOffSet");
long timeZoneOffSet;
try {
timeZoneOffSet = Long.parseLong(timeZoneOffSetVal);
} catch (Throwable t) {
timeZoneOffSet = 0;
}
final Date now = new Date();
final int hostTimeZone =
TimeZone.getDefault().getOffset(now.getTime());
timeZoneOffSet = hostTimeZone - timeZoneOffSet;
// Build and send the response message...
sendResponse(new String[]{SERVER_TIME},
new String[]{df.format(new Date(now.getTime() +
timeZoneOffSet))},
response);
} catch (Exception e) {
logger.fatal("Unable to process the request !", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Unable to process the request ! Msg: " + e.getMessage());
}
return null;
}
}