KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openinventions > webappfilter > processor > If


1 package com.openinventions.webappfilter.processor;
2
3 import com.openinventions.metaframework.*;
4 import org.apache.commons.logging.*;
5 import java.io.*;
6 import com.openinventions.webappfilter.processor.xpathexpression.*;
7
8 public class If implements Processor {
9     private static final Log log = LogFactory.getLog(If.class);
10     
11     public void process(State state, Element context) throws Exception JavaDoc {
12         String JavaDoc test = context.getValue("@test");
13         Boolean JavaDoc b = (Boolean JavaDoc) new XPathExpressionParser(new StringReader(test)).parse(state);
14         if (log.isDebugEnabled()) {
15             log.debug("test = " + test);
16             log.debug("b = " + b);
17         }
18         if (b.booleanValue()) {
19             String JavaDoc nextCommand = (String JavaDoc) state.get("nextCommand");
20             if (log.isDebugEnabled()) {
21                 log.debug("nextCommand = " + nextCommand);
22             }
23             state.set("nextCommand", nextCommand + "/child::*[1]");
24             state.set("relativeCommand", "/following-sibling::*[1]");
25         }
26     }
27 }
28 /* ====================================================================
29  * The webappfilter License, Version 1.1
30  *
31  * Copyright (c) 2002 Ivar Chan. All rights
32  * reserved.
33  *
34  * Redistribution and use in source and binary forms, with or without
35  * modification, are permitted provided that the following conditions
36  * are met:
37  *
38  * 1. Redistributions of source code must retain the above copyright
39  * notice, this list of conditions and the following disclaimer.
40  *
41  * 2. Redistributions in binary form must reproduce the above copyright
42  * notice, this list of conditions and the following disclaimer in
43  * the documentation and/or other materials provided with the
44  * distribution.
45  *
46  * 3. The end-user documentation included with the redistribution,
47  * if any, must include the following acknowledgment:
48  * "This product includes software developed by
49  * Ivar Chan (http://www.openinventions.com/webappfilter/)."
50  * Alternately, this acknowledgment may appear in the software itself,
51  * if and wherever such third-party acknowledgments normally appear.
52  *
53  * 4. The name "webappfilter" must not be used to endorse or promote products
54  * derived from this software without prior written permission. For
55  * written permission, please contact ivarchan@acm.org.
56  *
57  * 5. Products derived from this software may not be called "webappfilter",
58  * nor may "webappfilter" appear in their name, without
59  * prior written permission of Ivar Chan.
60  *
61  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
62  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
63  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
64  * DISCLAIMED. IN NO EVENT SHALL THE IVAR CHAN BE LIABLE FOR ANY
65  * DIRECT, INDIRECT, INCIDENTAL,
66  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
67  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
68  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
69  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
70  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
71  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72  * SUCH DAMAGE.
73  * ====================================================================
74  *
75  * This software consists of voluntary contributions made by many
76  * individuals. For more information on webappfilter, please see
77  * <http://www.openinventions/webappfilter/>.
78  */

79
Popular Tags