SF.net SVN: mx4j:[2276] branches/patches_3.1.0-beta1/mx4j/tools/src/main/ java/mx4j/tools/adaptor/http

[email protected] Mon, 23 Mar 2009 01:02:55 +0000
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Revision: 2276
          http://mx4j.svn.sourceforge.net/mx4j/?rev=2276&view=rev
Author:   altheengineer
Date:     2009-03-23 01:02:54 +0000 (Mon, 23 Mar 2009)

Log Message:
-----------
Added feature to allow applying XSL to raw output of an operation.

Modified Paths:
--------------
    branches/patches_3.1.0-beta1/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/InvokeOperationCommandProcessor.java
    branches/patches_3.1.0-beta1/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean.xsl

Modified: branches/patches_3.1.0-beta1/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/InvokeOperationCommandProcessor.java
===================================================================
--- branches/patches_3.1.0-beta1/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/InvokeOperationCommandProcessor.java	2009-03-22 21:31:33 UTC (rev 2275)
+++ branches/patches_3.1.0-beta1/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/InvokeOperationCommandProcessor.java	2009-03-23 01:02:54 UTC (rev 2276)
@@ -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,8 +29,10 @@
  */
 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()
    {
@@ -37,6 +40,7 @@
 
    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");
@@ -50,8 +54,8 @@
       String returnUnescaped = in.getVariable(RETURN_UNESCAPED_PARAM_NAME);
       if (returnUnescaped == null) {
          returnUnescaped = "false";
-      } else if ("true".equalsIgnoreCase(returnUnescaped) && in.getVariable("template") == null) {
-         in.getVariables().put("template", XSL_DOC_NAME_FOR_RENDER_INVOKE_PLAIN);
+      } 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(""))
@@ -174,11 +178,17 @@
                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);
                }

Modified: branches/patches_3.1.0-beta1/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean.xsl
===================================================================
--- branches/patches_3.1.0-beta1/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean.xsl	2009-03-22 21:31:33 UTC (rev 2275)
+++ branches/patches_3.1.0-beta1/mx4j/tools/src/main/java/mx4j/tools/adaptor/http/xsl/mbean.xsl	2009-03-23 01:02:54 UTC (rev 2276)
@@ -106,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">


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

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com