KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openinventions > webappfilter > util > StateXPath


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

87
88
Popular Tags