KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > net > ProxyItem


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: ProxyItem.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.net;
21
22 import org.apache.lenya.xml.XPointerFactory;
23 import org.apache.regexp.RE;
24 import org.apache.regexp.RESyntaxException;
25 import org.w3c.dom.Element JavaDoc;
26
27
28 /**
29  * DOCUMENT ME!
30  */

31 public class ProxyItem {
32     RE filter = null;
33     boolean action = false;
34
35     /**
36      * Creates a new ProxyItem object.
37      *
38      * @param itemElement DOCUMENT ME!
39      */

40     public ProxyItem(Element JavaDoc itemElement) {
41         XPointerFactory xpf = new XPointerFactory();
42
43         if (itemElement.getNodeName().equals("include")) {
44             action = true;
45         } else {
46             action = false;
47         }
48
49         try {
50             filter = new RE(xpf.getElementValue(itemElement));
51         } catch (RESyntaxException e) {
52             System.err.println(this.getClass().getName() + ": " + e);
53         }
54     }
55
56     /**
57      * DOCUMENT ME!
58      *
59      * @param hostname DOCUMENT ME!
60      *
61      * @return DOCUMENT ME!
62      */

63     public int check(String JavaDoc hostname) {
64         if (filter.match(hostname)) {
65             if (action) {
66                 return 1;
67             } else {
68                 return -1;
69             }
70         } else {
71             return 0;
72         }
73     }
74 }
75
Popular Tags