SF.net SVN: mx4j:[2277] trunk/mx4j

[email protected] Sat, 28 Mar 2009 14:05:45 +0000
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Revision: 2277
          http://mx4j.svn.sourceforge.net/mx4j/?rev=2277&view=rev
Author:   altheengineer
Date:     2009-03-28 14:05:42 +0000 (Sat, 28 Mar 2009)

Log Message:
-----------
Merged revisions 2271:2276 from https://mx4j.svn.sourceforge.net/svnroot/mx4j/branches/patches_3.1.0-beta1

- Changed Maven central config to http://repo1.maven.org/maven2 and added subversion ignores for target directories.
- Allow MBean operation parameters of type Object to be sent as Strings.
- Feature that allows user to check a checkbox near the submit button of an operation to tell the InvokeOperationCommandProcessor to render the output unescaped. If no template is supplied, the new invokeplain.xsl template will be used to render the operation's result such that it only returns the output as the result (e.g. it removes the MX4J navigation and other chrome from the output so that all you get is unescaped output).
- Added feature to allow applying XSL to raw output of an operation.

Modified Paths:
--------------
    trunk/mx4j/pom.xml
    trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/CommandProcessorUtil.java
    trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/InvokeOperationCommandProcessor.java
    trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/invoke.xsl
    trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean.xsl
    trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean_attributes.xsl
    trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/strings_en.xml

Added Paths:
-----------
    trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/invokeplain.xsl

Property Changed:
----------------
    trunk/mx4j/examples/
    trunk/mx4j/jsr003/
    trunk/mx4j/jsr160/
    trunk/mx4j/tools/


Property changes on: trunk/mx4j/examples
___________________________________________________________________
Added: svn:ignore
   + target



Property changes on: trunk/mx4j/jsr003
___________________________________________________________________
Added: svn:ignore
   + target



Property changes on: trunk/mx4j/jsr160
___________________________________________________________________
Added: svn:ignore
   + target


Modified: trunk/mx4j/pom.xml
===================================================================
--- trunk/mx4j/pom.xml	2009-03-23 01:02:54 UTC (rev 2276)
+++ trunk/mx4j/pom.xml	2009-03-28 14:05:42 UTC (rev 2277)
@@ -83,7 +83,7 @@
         <repository>
             <id>central</id>
             <name>Maven Central Repository</name>
-            <url>http://repo.mergere.com/maven2</url>
+            <url>http://repo1.maven.org/maven2</url>
         </repository>
         <repository>
             <id>apache.snapshots</id>


Property changes on: trunk/mx4j/tools
___________________________________________________________________
Added: svn:ignore
   + target


Modified: trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/CommandProcessorUtil.java
===================================================================
--- trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/CommandProcessorUtil.java	2009-03-23 01:02:54 UTC (rev 2276)
+++ trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/CommandProcessorUtil.java	2009-03-28 14:05:42 UTC (rev 2277)
@@ -77,8 +77,8 @@
    protected static Object createParameterValue(String parameterType, String parameterValue)
            throws Exception
    {
-      if (parameterType.equals("java.lang.String"))
-      {
+	  if (parameterType.equals("java.lang.String") || parameterType.equals("java.lang.Object"))
+	  {
          return parameterValue;
       }
       else if (parameterType.equals("java.lang.Integer") || parameterType.equals("int"))

Modified: trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/InvokeOperationCommandProcessor.java
===================================================================
--- trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/InvokeOperationCommandProcessor.java	2009-03-23 01:02:54 UTC (rev 2276)
+++ trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/InvokeOperationCommandProcessor.java	2009-03-28 14:05:42 UTC (rev 2277)
@@ -7,6 +7,7 @@
  */
 package mx4j.tools.adaptor.http;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -28,12 +29,18 @@
  */
 public class InvokeOperationCommandProcessor extends HttpCommandProcessorAdaptor
 {
+   private static final String RENDER_TEMPLATE_IN_PARAM_NAME = "template";
+   private static final String XSL_DOC_NAME_FOR_RENDER_INVOKE_PLAIN = "invokeplain";
+   private static final String RETURN_UNESCAPED_PARAM_NAME = "returnunescaped";
+   private static final String APPLY_TEMPLATE_TO_OUTPUT_PARAM_NAME = "templateoutput";
+
    public InvokeOperationCommandProcessor()
    {
    }
 
    public Document executeRequest(HttpInputStream in) throws IOException, JMException
    {
+	  boolean applyTemplateToOutput = ("true".equalsIgnoreCase(in.getVariable(APPLY_TEMPLATE_TO_OUTPUT_PARAM_NAME)));
       Document document = builder.newDocument();
 
       Element root = document.createElement("MBeanOperation");
@@ -44,6 +51,12 @@
 
       String objectVariable = in.getVariable("objectname");
       String operationVariable = in.getVariable("operation");
+      String returnUnescaped = in.getVariable(RETURN_UNESCAPED_PARAM_NAME);
+      if (returnUnescaped == null) {
+         returnUnescaped = "false";
+      } else if ("true".equalsIgnoreCase(returnUnescaped) && in.getVariable(RENDER_TEMPLATE_IN_PARAM_NAME) == null) {
+         in.getVariables().put(RENDER_TEMPLATE_IN_PARAM_NAME, XSL_DOC_NAME_FOR_RENDER_INVOKE_PLAIN);
+      }
       if (objectVariable == null || objectVariable.equals("")
           || operationVariable == null || operationVariable.equals(""))
       {
@@ -165,14 +178,21 @@
                operationElement.setAttribute("result", "success");
                if (returnValue != null)
                {
+                  if (applyTemplateToOutput) {
+                     return builder.parse(new ByteArrayInputStream(returnValue.toString().getBytes()));
+                  }
                   operationElement.setAttribute("returnclass", returnValue.getClass().getName());
                   operationElement.setAttribute("return", returnValue.toString());
                }
                else
                {
+                  if (applyTemplateToOutput) {
+                     return null;
+                  }
                   operationElement.setAttribute("returnclass", null);
                   operationElement.setAttribute("return", null);
                }
+               operationElement.setAttribute(RETURN_UNESCAPED_PARAM_NAME, returnUnescaped);
             }
             catch (Exception e)
             {

Modified: trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/invoke.xsl
===================================================================
--- trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/invoke.xsl	2009-03-23 01:02:54 UTC (rev 2276)
+++ trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/invoke.xsl	2009-03-28 14:05:42 UTC (rev 2277)
@@ -53,9 +53,10 @@
                         <xsl:call-template name="str">
                            <xsl:with-param name="id">invoke.operation.success.result</xsl:with-param>
                            <xsl:with-param name="p0">
-                              <xsl:call-template name="renderobject">
+                              <xsl:call-template name="renderobjectescapeoption">
                                  <xsl:with-param name="objectclass" select="@returnclass"/>
                                  <xsl:with-param name="objectvalue" select="@return"/>
+                                 <xsl:with-param name="objectvalueunescaped" select="@returnunescaped" />
                               </xsl:call-template>
                            </xsl:with-param>
                         </xsl:call-template>

Copied: trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/invokeplain.xsl (from rev 2276, branches/patches_3.1.0-beta1/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/invokeplain.xsl)
===================================================================
--- trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/invokeplain.xsl	                        (rev 0)
+++ trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/invokeplain.xsl	2009-03-28 14:05:42 UTC (rev 2277)
@@ -0,0 +1,55 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+   <xsl:output method="text" />
+
+   <!-- Overall parameters -->
+   <xsl:param name="html.stylesheet">stylesheet.css</xsl:param>
+   <xsl:param name="html.stylesheet.type">text/css</xsl:param>
+   <xsl:param name="head.title">invoke.title</xsl:param>
+
+   <!-- Request parameters -->
+   <xsl:param name="request.objectname"/>
+   <xsl:param name="request.method"/>
+
+   <xsl:include href="common.xsl"/>
+   <xsl:include href="mbean_attributes.xsl"/>
+
+   <!-- Operation invoke -->
+   <xsl:template name="operation">
+      <xsl:for-each select="Operation">
+         <xsl:if test="@result='success'">
+            <xsl:if test="not (@return='')">
+               <xsl:call-template name="str">
+                  <xsl:with-param name="id">invoke.operation.success.resultplain</xsl:with-param>
+                  <xsl:with-param name="p0">
+                     <xsl:call-template name="renderobjectescapeoption">
+                        <xsl:with-param name="objectclass" select="@returnclass"/>
+                        <xsl:with-param name="objectvalue" select="@return"/>
+                        <xsl:with-param name="objectvalueunescaped" select="@returnunescaped" />
+                     </xsl:call-template>
+                  </xsl:with-param>
+               </xsl:call-template>
+            </xsl:if>
+            <xsl:if test="@return=''">
+               <xsl:call-template name="str">
+                  <xsl:with-param name="id">invoke.operation.success.noresult</xsl:with-param>
+               </xsl:call-template>
+            </xsl:if>
+         </xsl:if>
+         <xsl:if test="@result='error'">
+            <xsl:call-template name="str">
+               <xsl:with-param name="id">invoke.operation.success.error</xsl:with-param>
+               <xsl:with-param name="p0">
+                  <xsl:value-of select="@errorMsg"/>
+               </xsl:with-param>
+            </xsl:call-template>
+         </xsl:if>
+      </xsl:for-each>
+   </xsl:template>
+   
+   <!-- Main template -->
+   <xsl:template match="MBeanOperation" name="main">
+     <xsl:call-template name="operation"/>
+   </xsl:template>
+</xsl:stylesheet>
+   

Modified: trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean.xsl
===================================================================
--- trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean.xsl	2009-03-23 01:02:54 UTC (rev 2276)
+++ trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean.xsl	2009-03-28 14:05:42 UTC (rev 2277)
@@ -25,7 +25,7 @@
    <xsl:template name="parameters" match="Parameter">
       <xsl:param name="class"/>
       <xsl:for-each select="Parameter">
-         <xsl:sort data-type="text" order="ascending" select="@id"/>
+         <xsl:sort data-type="number" order="ascending" select="@id"/>
          <xsl:variable name="type.id" select="concat('type', position()-1)"/>
          <xsl:variable name="name.id" select="concat('value', position()-1)"/>
          <xsl:variable name="type" select="@type"/>
@@ -57,6 +57,7 @@
                      or @type='java.lang.Boolean'
                      or @type='java.lang.Number'
                      or @type='java.lang.Character'
+                     or @type='java.lang.Object'
                      or @type='javax.management.ObjectName'
                      or @type='int'
                      or @type='short'
@@ -105,6 +106,21 @@
                </xsl:call-template>
             </td>
          </tr>
+         <tr>
+            <td colspan="7" width="100%" class="mbean_row">
+               <br /><strong>USAGE NOTE:</strong> You can add the following parameter combinations to the URL produced by running the operation to change the output:
+               <ul>
+                 <li><strong>returnunescaped=true</strong> - Set this parameter if you want just your output to be returned (not escaped and not surrounded by MX4J navigation)</li>
+                 <li><strong>template=<i>nameOfTemplateWithoutDotXSL</i></strong> - Set this parameter to have your output rendered by a specfic XSLT template (do not include the .xsl in the template name). If used with templateoutput, then only the output will have the template applied to it, otherwise, you will get the MX4J XML document with your result.</li>
+                 <li><strong>templateoutput=true</strong> - Set this parameter with the template parameter to have your raw output (which should be XML) rendered with the supplied template.</li>
+               </ul>
+               <br /> 
+               <br /><strong>EXAMPLE(S):</strong>
+               <br />
+<strong>&amp;returnunescaped=true&amp;template=myXSLDocNameToApplyToRawXMLOutput&amp;templateoutput=true</strong> - Adding these parameters to the end of a URL generated by clicking on an Operation that returns XML will apply an XSL document named myXSLDocNameToApplyToRawXMLOutput.xsl to the XML output.
+               <br /> 
+            </td>
+         </tr>
       </table>
       <table width="100%" cellpadding="0" cellspacing="0" border="0">
          <tr class="darkline">
@@ -165,6 +181,7 @@
                   </td>
                   <xsl:if test="$hasParameters='false'">
                      <td align="center" class="mbean_row">
+                        Check for output only: <input type="checkbox" name="returnunescaped" value="true"/> <br />
                         <input type="submit" value="{$invoke.str}"/>
                      </td>
                   </xsl:if>
@@ -214,7 +231,8 @@
                                  <xsl:with-param name="class" select="$classtype"/>
                               </xsl:call-template>
                            </table>
-                           <td align="center" valign="bottom">
+                           <td align="center" valign="bottom" class="mbean_row">
+                              Check for output only: <input type="checkbox" name="returnunescaped" value="true"/> <br />
                               <input style="pad-right: 1em;" type="submit" value="{$invoke.str}"/>
                            </td>
                         </td>

Modified: trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean_attributes.xsl
===================================================================
--- trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean_attributes.xsl	2009-03-23 01:02:54 UTC (rev 2276)
+++ trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean_attributes.xsl	2009-03-28 14:05:42 UTC (rev 2277)
@@ -195,7 +195,24 @@
    <xsl:template name="renderobject">
       <xsl:param name="objectclass"/>
       <xsl:param name="objectvalue"/>
+      <xsl:call-template name="renderobjectescapeoption">
+         <xsl:with-param name="objectclass" select="$objectclass"/>
+         <xsl:with-param name="objectvalue" select="$objectvalue"/>
+         <xsl:with-param name="objectvalueunescaped">false</xsl:with-param>
+      </xsl:call-template>
+   </xsl:template>
+
+   <xsl:template name="renderobjectescapeoption">
+      <xsl:param name="objectclass"/>
+      <xsl:param name="objectvalue"/>
+      <xsl:param name="objectvalueunescaped" />
       <xsl:choose>
+         <xsl:when test="$objectvalueunescaped='true'">
+            <!-- Use the following line when the result of an invocation
+            returns e.g. HTML or XML data
+            -->
+            <xsl:value-of select="$objectvalue" disable-output-escaping="yes" />
+         </xsl:when>
          <xsl:when test="$objectclass='javax.management.ObjectName'">
             <xsl:variable name="name_encoded">
                <xsl:call-template name="uri-encode">
@@ -209,10 +226,6 @@
             </a>
          </xsl:when>
          <xsl:otherwise>
-            <!-- Use the following line when the result of an invocation
-            returns e.g. HTML or XML data
-            <xsl:value-of select="$objectvalue" disable-output-escaping="true" />
-            -->
             <xsl:value-of select="$objectvalue"/>
          </xsl:otherwise>
       </xsl:choose>

Modified: trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/strings_en.xml
===================================================================
--- trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/strings_en.xml	2009-03-23 01:02:54 UTC (rev 2276)
+++ trunk/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/strings_en.xml	2009-03-28 14:05:42 UTC (rev 2277)
@@ -181,6 +181,7 @@
 	<str id="invoke.operation.title">MBean operation: invoke method {0} on MBean {1}</str>
 	<str id="invoke.operation.success">Invocation successful</str>
 	<str id="invoke.operation.success.result">Result value: <pre>{0}</pre></str>
+	<str id="invoke.operation.success.resultplain">{0}</str>
 	<str id="invoke.operation.success.noresult">No result</str>
 	<str id="invoke.operation.success.error">Error during MBean operation invocation<br/>Message: {0}</str>
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------