001: // ProxyProp.java
002: // $Id: ProxyProp.java,v 1.20 2004/01/06 10:09:34 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1996.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigsaw.proxy;
007:
008: import java.util.Enumeration;
009:
010: import java.io.File;
011:
012: import org.w3c.tools.resources.Attribute;
013: import org.w3c.tools.resources.AttributeRegistry;
014: import org.w3c.tools.resources.BooleanAttribute;
015: import org.w3c.tools.resources.IntegerAttribute;
016: import org.w3c.tools.resources.StringArrayAttribute;
017: import org.w3c.tools.resources.StringAttribute;
018:
019: import org.w3c.jigsaw.http.httpd;
020:
021: import org.w3c.jigsaw.config.PropertySet;
022:
023: import org.w3c.util.ObservableProperties;
024:
025: import org.w3c.www.protocol.http.micp.MICPProp;
026:
027: import org.w3c.www.protocol.http.HttpManager;
028: import org.w3c.www.protocol.http.cache.CacheFilter;
029: import org.w3c.www.protocol.http.cache.CacheStore;
030:
031: class ProxyProp extends PropertySet {
032: private static String title = "Proxy properties";
033:
034: private static String MICP_PROP_NAME = "micp";
035: private static String CACHE_PROP_NAME = "cache";
036: private static String PROXY_DISP_PROP_NAME = "dispatcher";
037:
038: protected static int ATTR_FILTERS = -1;
039:
040: static {
041: Class c = null;
042: Attribute a = null;
043:
044: try {
045: c = Class.forName("org.w3c.jigsaw.proxy.ProxyProp");
046: } catch (Exception ex) {
047: ex.printStackTrace();
048: System.exit(1);
049: }
050: // Register the maximum number of allowed connections:
051: a = new IntegerAttribute(HttpManager.CONN_MAX_P,
052: new Integer(20), Attribute.EDITABLE);
053: AttributeRegistry.registerAttribute(c, a);
054: // Register the timeout on the client socket
055: a = new IntegerAttribute(HttpManager.TIMEOUT_P, new Integer(
056: 300000) // default 5mn
057: , Attribute.EDITABLE);
058: AttributeRegistry.registerAttribute(c, a);
059: // Register the connection timeout on the client socket
060: a = new IntegerAttribute(HttpManager.CONN_TIMEOUT_P,
061: new Integer(1000) // default 1s
062: , Attribute.EDITABLE);
063: AttributeRegistry.registerAttribute(c, a);
064: // Register the proxy set property
065: a = new BooleanAttribute(HttpManager.PROXY_SET_P, null,
066: Attribute.EDITABLE);
067: AttributeRegistry.registerAttribute(c, a);
068: // Register the proxy host:
069: a = new StringAttribute(HttpManager.PROXY_HOST_P, null,
070: Attribute.EDITABLE);
071: AttributeRegistry.registerAttribute(c, a);
072: // Register the proxy port:
073: a = new IntegerAttribute(HttpManager.PROXY_PORT_P, new Integer(
074: 80), Attribute.EDITABLE);
075: AttributeRegistry.registerAttribute(c, a);
076: // Register the lenient parsing mode property
077: a = new BooleanAttribute(HttpManager.LENIENT_P, null,
078: Attribute.EDITABLE);
079: AttributeRegistry.registerAttribute(c, a);
080: // Register the filters property
081: a = new StringArrayAttribute(HttpManager.FILTERS_PROP_P, null,
082: Attribute.EDITABLE);
083: ATTR_FILTERS = AttributeRegistry.registerAttribute(c, a);
084: }
085:
086: /**
087: * Get this property set title.
088: * @return A String encoded title.
089: */
090:
091: public String getTitle() {
092: return title;
093: }
094:
095: /**
096: * Set value forwards the effectation to the properties.
097: * @param idx The attribute (property in that case) being set.
098: * @param value The new value for that property.
099: */
100:
101: protected String[] getFilters() {
102: return (String[]) getValue(ATTR_FILTERS, null);
103: }
104:
105: protected void initializeFiltersProps() {
106: String flt[] = getFilters();
107: if (flt == null)
108: return;
109: // FIXME! shouldget the name of the property set associated
110: // to the filter, and verify if it is present or not
111: // if not, register the property set
112: PropertySet p = null;
113: for (int i = 0; i < flt.length; i++) {
114: if (flt[i]
115: .equals("org.w3c.www.protocol.http.micp.MICPFilter")) {
116: if (server.getPropertySet(MICP_PROP_NAME) == null) {
117: p = new MICPProp(MICP_PROP_NAME, server);
118: server.registerPropertySet(p);
119: }
120: } else if (flt[i]
121: .equals("org.w3c.www.protocol.http.cache.CacheFilter")) {
122: if (server.getPropertySet(CACHE_PROP_NAME) == null) {
123: p = new CacheProp(CACHE_PROP_NAME, server);
124: server.registerPropertySet(p);
125: ObservableProperties props = server.getProperties();
126: File c = props.getFile(
127: CacheStore.CACHE_DIRECTORY_P, null);
128: if (c == null) {
129: c = new File(server.getConfigDirectory(),
130: "cache");
131: props.putValue(CacheStore.CACHE_DIRECTORY_P, c
132: .getAbsolutePath());
133: }
134: }
135: } else if (flt[i]
136: .equals("org.w3c.www.protocol.http.proxy.ProxyDispatcher")) {
137: //add ProxyDispatcher PropertySet...
138: if (server.getPropertySet(PROXY_DISP_PROP_NAME) == null) {
139: p = new ProxyDispatcherProp(PROXY_DISP_PROP_NAME,
140: server);
141: server.registerPropertySet(p);
142: }
143: }
144: }
145: }
146:
147: public synchronized void setValue(int idx, Object value) {
148: // Check access (we don't care about side effects)
149: super .setValue(idx, value);
150: if (idx == ATTR_FILTERS)
151: initializeFiltersProps();
152: }
153:
154: ProxyProp(String name, httpd server) {
155: super(name, server);
156: initializeFiltersProps();
157: }
158: }
|