01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.outerj.daisy.htmlcleaner;
17:
18: import java.util.Set;
19: import java.util.HashSet;
20:
21: class ElementDescriptor {
22: /** Allowed attributes. */
23: private Set<String> attributes = new HashSet<String>();
24: private String[] attributeNames;
25: /** Allowed children. */
26: private Set<String> children = new HashSet<String>();
27: private String name;
28:
29: public ElementDescriptor(String name) {
30: this .name = name;
31: }
32:
33: public void addAttribute(String name) {
34: attributes.add(name);
35: attributeNames = null;
36: }
37:
38: public void addChild(String name) {
39: children.add(name);
40: }
41:
42: public Set<String> getAttributes() {
43: return attributes;
44: }
45:
46: public void setAttributes(Set<String> attributes) {
47: this .attributes = attributes;
48: this .attributeNames = null;
49: }
50:
51: public Set<String> getChildren() {
52: return children;
53: }
54:
55: public void setChildren(Set<String> children) {
56: this .children = children;
57: }
58:
59: public String getName() {
60: return name;
61: }
62:
63: public String[] getAttributeNames() {
64: if (attributeNames == null)
65: attributeNames = attributes.toArray(new String[attributes
66: .size()]);
67: return attributeNames;
68: }
69:
70: public boolean childAllowed(String name) {
71: return children.contains(name);
72: }
73:
74: public boolean attributeAllowed(String name) {
75: return attributes.contains(name);
76: }
77: }
|