KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > htmlcleaner > ElementDescriptor


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
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 package org.outerj.daisy.htmlcleaner;
17
18 import java.util.Set JavaDoc;
19 import java.util.HashSet JavaDoc;
20
21 class ElementDescriptor {
22     /** Allowed attributes. */
23     private Set JavaDoc attributes = new HashSet JavaDoc();
24     private String JavaDoc[] attributeNames;
25     /** Allowed children. */
26     private Set JavaDoc children = new HashSet JavaDoc();
27     private String JavaDoc name;
28
29     public ElementDescriptor(String JavaDoc name) {
30         this.name = name;
31     }
32
33     public void addAttribute(String JavaDoc name) {
34         attributes.add(name);
35         attributeNames = null;
36     }
37
38     public void addChild(String JavaDoc name) {
39         children.add(name);
40     }
41
42     public Set JavaDoc getAttributes() {
43         return attributes;
44     }
45
46     public void setAttributes(Set JavaDoc attributes) {
47         this.attributes = attributes;
48         this.attributeNames = null;
49     }
50
51     public Set JavaDoc getChildren() {
52         return children;
53     }
54
55     public void setChildren(Set JavaDoc children) {
56         this.children = children;
57     }
58
59     public String JavaDoc getName() {
60         return name;
61     }
62
63     public String JavaDoc[] getAttributeNames() {
64         if (attributeNames == null)
65             attributeNames = (String JavaDoc[])attributes.toArray(new String JavaDoc[attributes.size()]);
66         return attributeNames;
67     }
68
69     public boolean childAllowed(String JavaDoc name) {
70         return children.contains(name);
71     }
72
73     public boolean attributeAllowed(String JavaDoc name) {
74         return attributes.contains(name);
75     }
76 }
77
Popular Tags