KickJava   Java API By Example, From Geeks To Geeks.

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


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: ProxyConf.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.net;
21
22 import java.util.Vector JavaDoc;
23
24 import org.apache.lenya.xml.XPointerFactory;
25 import org.w3c.dom.Element JavaDoc;
26
27
28 /**
29  * DOCUMENT ME!
30  */

31 public class ProxyConf {
32     String JavaDoc proxyHost = null;
33     String JavaDoc proxyPort = null;
34     Vector JavaDoc items = null;
35
36     /**
37      * Creates a new ProxyConf object.
38      *
39      * @param proxyElement DOCUMENT ME!
40      */

41     public ProxyConf(Element JavaDoc proxyElement) {
42         try {
43             items = new Vector JavaDoc();
44
45             XPointerFactory xpf = new XPointerFactory();
46
47             proxyHost = proxyElement.getAttribute("host");
48             proxyPort = proxyElement.getAttribute("port");
49
50             Vector JavaDoc filterEls = xpf.select(proxyElement, "xpointer(include|exclude)");
51
52             for (int i = 0; i < filterEls.size(); i++) {
53                 ProxyItem item = new ProxyItem((Element JavaDoc) filterEls.elementAt(i));
54                 items.addElement(item);
55             }
56         } catch (Exception JavaDoc e) {
57             System.err.println(this.getClass().getName() + ": " + e);
58         }
59     }
60
61     /**
62      * DOCUMENT ME!
63      *
64      * @param hostname DOCUMENT ME!
65      *
66      * @return DOCUMENT ME!
67      */

68     public boolean check(String JavaDoc hostname) {
69         boolean result = false;
70
71         for (int i = 0; i < items.size(); i++) {
72             int ires = ((ProxyItem) items.elementAt(i)).check(hostname);
73
74             if (ires > 0) {
75                 result = true;
76             } else if (ires < 0) {
77                 result = false;
78             }
79         }
80
81         return result;
82     }
83
84     /**
85      * DOCUMENT ME!
86      *
87      * @return DOCUMENT ME!
88      */

89     public String JavaDoc getHostName() {
90         return proxyHost;
91     }
92
93     /**
94      * DOCUMENT ME!
95      *
96      * @return DOCUMENT ME!
97      */

98     public String JavaDoc getHostPort() {
99         return proxyPort;
100     }
101 }
102
Popular Tags