xlawrence 2005/11/09 19:01:12 CET
Modified files:
core/src/java/org/jahia/ajax AjaxAction.java
core/src/java/org/jahia/ajax/actionmenus
GetMenuItemsAction.java
Log:
just tidy up a few things (code + javadoc)
Revision Changes Path
1.2 +49 -58 jahia/core/src/java/org/jahia/ajax/AjaxAction.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/ajax/AjaxAction.java.diff?r1=1.1&r2=1.2&f=h
1.2 +14 -13
jahia/core/src/java/org/jahia/ajax/actionmenus/GetMenuItemsAction.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/ajax/actionmenus/GetMenuItemsAction.java.diff?r1=1.1&r2=1.2&f=h
Index: AjaxAction.java
===================================================================
RCS file:
/home/cvs/repository/jahia/core/src/java/org/jahia/ajax/AjaxAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AjaxAction.java 9 Nov 2005 16:57:33 -0000 1.1
+++ AjaxAction.java 9 Nov 2005 18:01:11 -0000 1.2
@@ -74,16 +74,16 @@
* 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
+ * @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 If the specified parameter is not found
* @throws IOException
*/
- protected String getParameter(final HttpServletRequest request,
- final HttpServletResponse response,
- final String name)
+ protected final String getParameter(final HttpServletRequest request,
+ final HttpServletResponse response,
+ final String name)
throws ServletException, IOException {
if (request == null) {
throw new NullPointerException("'request' cannot be null");
@@ -97,10 +97,10 @@
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.");
+ final String msg = "Missing required '" + name + "' parameter in
request.";
+ logger.error(msg);
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
+ throw new ServletException(msg);
}
return value;
}
@@ -112,12 +112,12 @@
* @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.
+ * @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) {
+ protected final String getParameter(final HttpServletRequest request,
+ final String name,
+ final String defaultValue) {
if (request == null) {
throw new NullPointerException("'request' cannot be null");
}
@@ -139,13 +139,13 @@
* 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) {
+ * @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 final void buildXmlElement(final StringBuffer buff,
+ final String tagName,
+ final String tagValue) {
if (buff == null) {
throw new NullPointerException("'buff' cannot be null");
}
@@ -154,11 +154,8 @@
throw new NullPointerException("'tagName' cannot be null");
}
- if (tagValue == null || tagValue.length() == 0) {
- return;
- }
buff.append("<").append(tagName).append(">");
- buff.append(tagValue);
+ buff.append( (tagValue == null ? "" : tagValue) );
buff.append("</").append(tagName).append(">\n");
}
@@ -166,23 +163,19 @@
* 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.
+ * @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) {
+ protected final 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( (tagValue == null ? "" : tagValue) );
buff.append("</").append(tagName).append(">\n");
return buff.toString();
}
@@ -191,14 +184,14 @@
* 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
+ * @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 Request
* @throws IOException
*/
- protected void sendResponse(final Collection xmlTagNames,
- final Collection xmlTagValues,
- final HttpServletResponse response)
+ protected final void sendResponse(final Collection xmlTagNames,
+ final Collection xmlTagValues,
+ final HttpServletResponse response)
throws IOException {
sendResponse((String[]) xmlTagNames.toArray(new String[]{}),
(String[]) xmlTagValues.toArray(new String[]{}),
@@ -209,16 +202,15 @@
* 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
+ * @param xmlTagNames The array of tag names (Order is important)
+ * @param xmlTagValues The array of tag values (Order is important)
+ * @param response The HttpServletResponse linked to the current
request
* @throws IOException
*/
- protected void sendResponse(final String[] xmlTagNames,
- final String[] xmlTagValues,
- final HttpServletResponse response)
+ protected final void sendResponse(final String[] xmlTagNames,
+ final String[] xmlTagValues,
+ final HttpServletResponse response)
throws IOException {
-
if (xmlTagNames == null) {
throw new NullPointerException("'xmlTagNames' cannot be null");
}
@@ -234,7 +226,7 @@
final StringBuffer buff = new StringBuffer();
buff.append(XML_HEADER);
- for (int i=0; i<xmlTagNames.length; i++) {
+ for (int i = 0; i < xmlTagNames.length; i++) {
final String tagName = xmlTagNames[i];
final String tagValue = xmlTagValues[i];
@@ -257,15 +249,14 @@
/**
* 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
+ * @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
+ * @see Action#execute(ActionMapping, ActionForm, HttpServletRequest,
HttpServletResponse)
*/
public abstract ActionForward execute(final ActionMapping mapping,
final ActionForm form,
Index: GetMenuItemsAction.java
===================================================================
RCS file:
/home/cvs/repository/jahia/core/src/java/org/jahia/ajax/actionmenus/GetMenuItemsAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GetMenuItemsAction.java 9 Nov 2005 16:57:33 -0000 1.1
+++ GetMenuItemsAction.java 9 Nov 2005 18:01:11 -0000 1.2
@@ -106,15 +106,15 @@
(ProcessingContextFactory) bf.
getBean(ProcessingContextFactory.class.getName());
/**
- * Returns the menu items for the specified Action Menu
+ * 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
+ * @throws IOException
+ * @throws ServletException
*/
public ActionForward execute(final ActionMapping mapping,
final ActionForm form,
@@ -137,9 +137,9 @@
if (currentUser == null || currentPage == null ||
! currentPage.getACL().getPermission(currentUser,
JahiaBaseACL.WRITE_RIGHTS)) {
- logger.warn("Unauthorized attempt to use AJAX Servlet");
+ logger.warn("Unauthorized attempt to use AJAX Struts Action
- GetMenuItemsAction");
response.sendError(HttpServletResponse.SC_FORBIDDEN,
- "Must be logged in and have 'Write' access");
+ "Error: Must be logged in and have 'Write' access");
return null;
}
@@ -209,16 +209,17 @@
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 + "'.");
+ final String msg = "Unknown 'ObjectType' value !
'ObjectType' value should be '" +
+ PageBean.TYPE + "', '" + ContainerListBean.TYPE +
"', '" +
+ ContainerBean.TYPE + "' or '" + FieldBean.TYPE +
"'.";
+ logger.fatal(msg);
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
return null;
}
// Get all the information regarding the Action entries
final Map info = getActionsInfo(bean, jParams);
- logger.debug("ActionsInfo:\n" + info);
+ // logger.debug("ActionsInfo:\n" + info);
jParams.resetSubstituteEntryLoadRequest();
@@ -264,9 +265,9 @@
/**
* 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
+ * @param bean The ContentBean for which the menu will be built
+ * @param jParams ProcessingContext
+ * @throws JahiaException
*
*/
protected Map getActionsInfo(final ContentBean bean,