[Yanel-commits] rev 40951 - public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet

michi at wyona.com michi at wyona.com
Wed Jan 14 16:35:56 CET 2009


Author: michi
Date: 2009-01-14 16:35:56 +0100 (Wed, 14 Jan 2009)
New Revision: 40951

Modified:
   public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
Log:
thanks to Gary the transition output/response can now be switched between XML and XHTML

Modified: public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
===================================================================
--- public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java	2009-01-14 15:20:59 UTC (rev 40950)
+++ public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java	2009-01-14 15:35:56 UTC (rev 40951)
@@ -109,6 +109,7 @@
     private static final String METHOD_POST = "POST";
     private static final String METHOD_PUT = "PUT";
     private static final String METHOD_DELETE = "DELETE";
+    private static final String HTTP_REFERRER = "Referer"; // ah, misspellings, how I hate thee (http://en.wikipedia.org/wiki/Referer)!
     private static final int INSIDE_TAG = 0;
     private static final int OUTSIDE_TAG = 1;
 
@@ -123,9 +124,12 @@
     public static final String YANEL_RESOURCE = "yanel.resource";
     public static final String YANEL_RESOURCE_REVN = YANEL_RESOURCE + ".revision";
     public static final String YANEL_RESOURCE_WORKFLOW_TRANSITION = YANEL_RESOURCE + ".workflow.transition";
+    public static final String YANEL_RESOURCE_WORKFLOW_TRANSITION_OUTPUT = YANEL_RESOURCE_WORKFLOW_TRANSITION + ".output";
     public static final String VIEW_ID_PARAM_NAME = "yanel.resource.viewid";
     public static final String RESOURCE_META_ID_PARAM_NAME = "yanel.resource.meta";
-
+    
+    private static final String CONTENT_TYPE_XHTML = "xhtml";
+    
     /**
      *
      */
@@ -221,7 +225,7 @@
             doOptions(request, response);
         } else {
             log.error("No such method implemented: " + method);
-            response.sendError(response.SC_NOT_IMPLEMENTED);
+            response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
         }
     }
 
@@ -237,7 +241,7 @@
         
         String transition = request.getParameter(YANEL_RESOURCE_WORKFLOW_TRANSITION);
         if (transition != null) {
-            executeWorkflowTransition(getResource(request, response),
+            executeWorkflowTransition(request,
                                       response,
                                       request.getParameter(YANEL_RESOURCE_REVN),
                                       transition);
@@ -650,7 +654,7 @@
     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         String transition = request.getParameter(YANEL_RESOURCE_WORKFLOW_TRANSITION);
         if (transition != null) {
-            executeWorkflowTransition(getResource(request, response),
+            executeWorkflowTransition(request,
                                       response,
                                       request.getParameter(YANEL_RESOURCE_REVN),
                                       transition);
@@ -723,19 +727,36 @@
      * @throws ServletException
      * @throws IOException
      */
-    private void executeWorkflowTransition(Resource resource,
+    private void executeWorkflowTransition(HttpServletRequest request,
                                            HttpServletResponse response,
                                            String revision,
                                            String transition)
             throws ServletException, IOException {
+        Resource resource = getResource(request, response);
+
         if (ResourceAttributeHelper.hasAttributeImplemented(resource, "Workflowable", "1")) {
             WorkflowableV1 workflowable = (WorkflowableV1)resource;
+
             try {
+                String outputFormat = request.getParameter(YANEL_RESOURCE_WORKFLOW_TRANSITION_OUTPUT);
+                StringBuilder sb = null;
+
                 workflowable.doTransition(transition, revision);
-                
+
                 response.setStatus(javax.servlet.http.HttpServletResponse.SC_OK);
-                StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
-                sb.append(workflowable.getWorkflowIntrospection());
+
+                if (outputFormat != null && CONTENT_TYPE_XHTML.equals(outputFormat.toLowerCase())) {
+                    response.setContentType("text/html; charset=" + DEFAULT_ENCODING);
+                    sb = new StringBuilder("<html><body><p>The action " + transition
+                                         + " has been performed.</p><p>Return to <a href=\"" 
+                                         + request.getHeader(HTTP_REFERRER)
+                                         + "\">the page</a>.</p></body></html>");
+
+                } else {
+                    sb = new StringBuilder("<?xml version=\"1.0\"?>");
+                    sb.append(workflowable.getWorkflowIntrospection());
+                }
+
                 PrintWriter w = response.getWriter();
                 w.print(sb);
 



More information about the Yanel-commits mailing list