01: // IndexFeeder.java
02: // $Id: IndexFeeder.java,v 1.6 2000/08/16 21:37:27 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1998.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigadm.editors;
07:
08: import org.w3c.jigadm.RemoteResourceWrapper;
09:
10: import org.w3c.jigsaw.admin.RemoteAccessException;
11: import org.w3c.jigsaw.admin.RemoteResource;
12:
13: import java.util.Hashtable;
14: import java.util.Properties;
15: import java.util.StringTokenizer;
16: import java.util.Vector;
17:
18: /**
19: * @version $Revision: 1.6 $
20: * @author Benoît Mahé (bmahe@w3.org)
21: */
22: public class IndexFeeder implements EditorFeeder {
23:
24: public static final String FILTER_P = "feeder.filter";
25: public static final String FORBID_RULE = "*forbid*";
26:
27: String[] sdefault = { FORBID_RULE };
28: String[] extentions = null;
29: String[] s = null;
30:
31: public String[] getDefaultItems() {
32: return s;
33: }
34:
35: protected boolean match(String s, String[] extensions) {
36: for (int i = 0; i < extensions.length; i++) {
37: if (s.endsWith("." + extensions[i]))
38: return true;
39: }
40: return false;
41: }
42:
43: protected String[] filter(String[] children, String[] extensions) {
44: if (extensions == null)
45: return children;
46: Vector V = new Vector(12);
47: V.addElement(FORBID_RULE);
48: for (int i = 0; i < children.length; i++) {
49: if (match(children[i], extensions))
50: V.addElement(children[i]);
51: }
52: String filtered[] = new String[V.size()];
53: V.copyInto(filtered);
54: return filtered;
55: }
56:
57: protected RemoteResource getResource(RemoteResourceWrapper rrw,
58: Properties p) {
59: return rrw.getResource();
60: }
61:
62: protected String[] getStringArray(RemoteResourceWrapper rrw,
63: Properties p) {
64: String extensions[] = null;
65: String exts = (String) p.get(FILTER_P);
66:
67: if (exts != null) {
68: StringTokenizer st = new StringTokenizer(exts, "|");
69: int len = st.countTokens();
70: extensions = new String[len];
71: for (int i = 0; i < extensions.length; i++) {
72: extensions[i] = st.nextToken();
73: }
74: }
75: try {
76: RemoteResource rm = getResource(rrw, p);
77: if (rm.isContainer()) {
78: return filter(rm.enumerateResourceIdentifiers(),
79: extensions);
80: } else if (rm.isFrame()) {
81: //are we a frame?
82: rm = rrw.getFatherResource();
83: if ((rm != null) && (rm.isContainer()))
84: return filter(rm.enumerateResourceIdentifiers(),
85: extensions);
86: }
87: } catch (RemoteAccessException ex) {
88: //nothing to do
89: }
90: return new String[0];
91: }
92:
93: public void initialize(RemoteResourceWrapper rrw, Properties p) {
94: s = getStringArray(rrw, p);
95: if (s.length == 0)
96: s = sdefault;
97: }
98: }
|