1 package com.openinventions.webappfilter.processor.test; 2 3 import com.openinventions.metaframework.*; 4 import org.apache.commons.logging.*; 5 import java.util.*; 6 import java.util.regex.*; 7 import junit.framework.*; 8 9 public class Response implements Processor { 10 private static final Log log = LogFactory.getLog(Response.class); 11 12 public void process(State state, Element context) throws Exception { 13 Element res = (Element) state.get("res"); 15 16 if (log.isDebugEnabled()) { 17 log.debug("res.body = " + res.getValue("body")); 18 log.debug("nextCommand = " + (String ) state.get("nextCommand")); 19 } 20 21 if (res.getValue("body").equals("")) { 22 state.set("filterDirection", "forward"); 23 } else { 24 Element config = (Element) state.get("config"); 25 String nextCommand = (String ) state.get("nextCommand"); 26 int numChildren = config.getNumElements("child::*"); 27 state.set("singleCommand", "true"); 28 for (int i = 1; i <= numChildren; i++) { 29 if (!config.isExists(nextCommand + "/child::*[" + i + "]")) { 30 break; 31 } 32 state.set("nextCommand", nextCommand + "/child::*[" + i + "]"); 33 Processor traverser = (Processor) state.get("traverser"); 34 traverser.process(state, null); 35 } 36 state.set("singleCommand", "false"); 37 38 ElementFactory factory = (ElementFactory) state.get("com.openinventions.metaframework.ElementFactory"); 40 state.set("req", factory.createElement("request")); 41 state.set("res", factory.createElement("response")); 42 43 if (config.isExists(nextCommand + "/../following-sibling::request[1]")) { 46 state.set("nextCommand", nextCommand + "/../following-sibling::request[1]"); 47 state.set("filterDirection", "backward"); 48 } else if (config.isExists(nextCommand + "/../../../following-sibling::test[1]")) { 49 state.set("nextCommand", nextCommand + "/../../../following-sibling::test[1]"); 50 state.set("filterDirection", "backward"); 51 } else { 52 state.set("filterDirection", "stop"); 53 } 54 } 55 } 56 } 57 108 109 110 111 112 | Popular Tags |