2006/unicorn/src/org/w3c/unicorn/action ObserveAction.java,1.38,1.39

Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/action
In directory hutz:/tmp/cvs-serv20024/src/org/w3c/unicorn/action

Modified Files:
	ObserveAction.java 
Log Message:
prepared for firstOuput before the requests are launched

Index: ObserveAction.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/action/ObserveAction.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- ObserveAction.java	21 Sep 2009 15:48:22 -0000	1.38
+++ ObserveAction.java	22 Sep 2009 12:36:40 -0000	1.39
@@ -111,8 +111,13 @@
 		try {
 			reqParams = getRequestParameters(req);
 		} catch (FileUploadException e) {
+			OutputFormater aOutputFormater = OutputFactory.createOutputFormater(
+					mapOfOutputParameter.get("format"),
+					mapOfOutputParameter.get("lang"), 
+					mapOfOutputParameter.get("mimetype"));
+			OutputModule aOutputModule = OutputFactory.createOutputModule(mapOfOutputParameter.get("output"));
 			messages.add(new Message(e));
-			createError(req, resp, null, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter);
+			createError(req, resp, null, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter, aOutputFormater, aOutputModule);
 			return;
 		}
 		
@@ -185,6 +190,12 @@
 			}
 		}
 		
+		OutputFormater aOutputFormater = OutputFactory.createOutputFormater(
+				mapOfOutputParameter.get("format"),
+				mapOfOutputParameter.get("lang"), 
+				mapOfOutputParameter.get("mimetype"));
+		OutputModule aOutputModule = OutputFactory.createOutputModule(mapOfOutputParameter.get("output"));
+		
 		// Check that all mandatory parameters are set
 		if (!reqParams.containsKey(paramPrefix + "lang")) {
 			String lang = getLanguage(null, req, null);
@@ -206,7 +217,7 @@
 		}
 		if (!reqParams.containsKey(paramPrefix + "uri") && !reqParams.containsKey(paramPrefix + "text") && !reqParams.containsKey(paramPrefix + "file")) {
 			messages.add(new Message(Message.Level.ERROR, "$message_nothing_to_validate", null));
-			createError(req, resp, reqParams, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter);
+			createError(req, resp, reqParams, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter, aOutputFormater, aOutputModule);
 			return;
 		}
 		
@@ -229,24 +240,26 @@
 		
 		// Launch the observation
 		try {
+			aOutputModule.produceFirstOutput(aOutputFormater, mapOfStringObject, mapOfSpecificParameter, resp.getWriter());
 			aUnicornCall.doTask();
 			messages.addAll(aUnicornCall.getMessages());
 			if (aUnicornCall.getResponses().size() == 0) {
 				messages.add(new Message(Message.Level.ERROR, "$message_no_observation_done", null));
-				createError(req, resp, reqParams, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter);
+				createError(req, resp, reqParams, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter, aOutputFormater, aOutputModule);
 			} else {
-				createOutput(req, resp, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter);
+				//createOutput(req, resp, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter, aOutputFormater, aOutputModule);
+				aOutputModule.produceOutput(aOutputFormater, mapOfStringObject, mapOfSpecificParameter, resp.getWriter());
 			}
 		} catch (final UnicornException ucnException) {
 			if (ucnException.getUnicornMessage() != null)
 				messages.add(ucnException.getUnicornMessage());
 			else
 				messages.add(new Message(Message.Level.ERROR, ucnException.getMessage(), null));
-			createError(req, resp, reqParams, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter);
+			createError(req, resp, reqParams, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter, aOutputFormater, aOutputModule);
 		} catch (final Exception aException) {
 			logger.error("Exception : " + aException.getMessage(), aException);
 			messages.add(new Message(aException));
-			createError(req, resp, reqParams, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter);
+			createError(req, resp, reqParams, mapOfStringObject, mapOfSpecificParameter, mapOfOutputParameter, aOutputFormater, aOutputModule);
 		} finally {
 			if ("true".equals(Property.get("DELETE_UPLOADED_FILES")) && aFileItemUploaded != null)
 				aFileItemUploaded.delete();
@@ -325,7 +338,7 @@
 	
 	private void createError(HttpServletRequest req, HttpServletResponse resp,
 			Map<String, Object> reqParams, Map<String, Object> mapOfStringObject, Map<String, String> mapOfSpecificParameter,
-			Map<String, String> mapOfOutputParameter) throws IOException, ServletException {
+			Map<String, String> mapOfOutputParameter, OutputFormater aOutputFormater, OutputModule aOutputModule) throws IOException, ServletException {
 		
 		// If text/html is the mime-type the error will be displayed directly on index
 		if (mapOfOutputParameter.get("mimetype").equals("text/html")) {
@@ -333,25 +346,15 @@
 			return;
 		}
 		
-		OutputFormater aOutputFormater = OutputFactory.createOutputFormater(
-				mapOfOutputParameter.get("format"),
-				mapOfOutputParameter.get("lang"), 
-				mapOfOutputParameter.get("mimetype"));
-		OutputModule aOutputModule = OutputFactory.createOutputModule(mapOfOutputParameter.get("output"));
 		aOutputModule.produceError(aOutputFormater, mapOfStringObject, mapOfSpecificParameter, resp.getWriter());
 	}
 	
-	private void createOutput(HttpServletRequest req, HttpServletResponse resp,
+	/*private void createOutput(HttpServletRequest req, HttpServletResponse resp,
 			Map<String, Object> mapOfStringObject, Map<String, String> mapOfSpecificParameter,
-			Map<String, String> mapOfOutputParameter) throws IOException, ServletException {
+			Map<String, String> mapOfOutputParameter, OutputFormater aOutputFormater, OutputModule aOutputModule) throws IOException, ServletException {
 		
-		OutputFormater aOutputFormater = OutputFactory.createOutputFormater(
-				mapOfOutputParameter.get("format"),
-				mapOfOutputParameter.get("lang"), 
-				mapOfOutputParameter.get("mimetype"));
-		OutputModule aOutputModule = OutputFactory.createOutputModule(mapOfOutputParameter.get("output"));
 		aOutputModule.produceOutput(aOutputFormater, mapOfStringObject, mapOfSpecificParameter, resp.getWriter());
-	}
+	}*/
 	
 	private void redirect(HttpServletRequest req, HttpServletResponse resp, Map<String, Object> reqParams, ArrayList<?> messages) throws IOException, ServletException {
 		req.setAttribute("unicorn_messages", messages);

Received on Tuesday, 22 September 2009 12:36:55 UTC