KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openinventions > webappfilter > processor > test > Response


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 JavaDoc {
13         // if response body empty, still moving forward
14
Element res = (Element) state.get("res");
15
16         if (log.isDebugEnabled()) {
17             log.debug("res.body = " + res.getValue("body"));
18             log.debug("nextCommand = " + (String JavaDoc) 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 JavaDoc nextCommand = (String JavaDoc) 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             // reset requests and responses
39
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             // Try to traverse the following request in this test,
44
// else go to new test
45
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 /* ====================================================================
58  * The webappfilter License, Version 1.1
59  *
60  * Copyright (c) 2002 Ivar Chan. All rights
61  * reserved.
62  *
63  * Redistribution and use in source and binary forms, with or without
64  * modification, are permitted provided that the following conditions
65  * are met:
66  *
67  * 1. Redistributions of source code must retain the above copyright
68  * notice, this list of conditions and the following disclaimer.
69  *
70  * 2. Redistributions in binary form must reproduce the above copyright
71  * notice, this list of conditions and the following disclaimer in
72  * the documentation and/or other materials provided with the
73  * distribution.
74  *
75  * 3. The end-user documentation included with the redistribution,
76  * if any, must include the following acknowledgment:
77  * "This product includes software developed by
78  * Ivar Chan (http://www.openinventions.com/webappfilter/)."
79  * Alternately, this acknowledgment may appear in the software itself,
80  * if and wherever such third-party acknowledgments normally appear.
81  *
82  * 4. The name "webappfilter" must not be used to endorse or promote products
83  * derived from this software without prior written permission. For
84  * written permission, please contact ivarchan@acm.org.
85  *
86  * 5. Products derived from this software may not be called "webappfilter",
87  * nor may "webappfilter" appear in their name, without
88  * prior written permission of Ivar Chan.
89  *
90  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
91  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
92  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
93  * DISCLAIMED. IN NO EVENT SHALL THE IVAR CHAN BE LIABLE FOR ANY
94  * DIRECT, INDIRECT, INCIDENTAL,
95  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
96  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
97  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
98  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
99  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
100  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101  * SUCH DAMAGE.
102  * ====================================================================
103  *
104  * This software consists of voluntary contributions made by many
105  * individuals. For more information on webappfilter, please see
106  * <http://www.openinventions/webappfilter/>.
107  */

108
109
110
111
112
Popular Tags