File: DTDElement.java

package info (click to toggle)
libdtdparser-java 1.21a-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 400 kB
  • ctags: 393
  • sloc: java: 3,143; xml: 66; makefile: 15
file content (147 lines) | stat: -rw-r--r-- 3,232 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.wutka.dtd;

import java.util.*;
import java.io.*;

/** Represents an element defined with the ELEMENT DTD tag
 *
 * @author Mark Wutka
 * @version $Revision: 1.16 $ $Date: 2002/07/19 01:20:11 $ by $Author: wutka $
 */
public class DTDElement implements DTDOutput
{
/** The name of the element */
    public String name;

/** The element's attributes */
    public Hashtable attributes;

/** The element's content */
    public DTDItem content;

    public DTDElement()
    {
        attributes = new Hashtable();
    }

    public DTDElement(String aName)
    {
        name = aName;

        attributes = new Hashtable();
    }

/** Writes out an element declaration and an attlist declaration (if necessary)
    for this element */
    public void write(PrintWriter out)
        throws IOException
    {
        out.print("<!ELEMENT ");
        out.print(name);
        out.print(" ");
        if (content != null)
        {
            content.write(out);
        }
        else
        {
            out.print("ANY");
        }
        out.println(">");
        out.println();

/*
        if (attributes.size() > 0)
        {
            out.print("<!ATTLIST ");
            out.println(name);
	    TreeMap tm=new TreeMap(attributes);
	    Collection values=tm.values();
	    Iterator iterator=values.iterator();
	    while (iterator.hasNext())
	    {
                out.print("           ");
                DTDAttribute attr = (DTDAttribute) iterator.next();
                attr.write(out);
		if (iterator.hasNext())
                	out.println();
		else
	                out.println(">");
	    }
        }
*/
    }

    public boolean equals(Object ob)
    {
        if (ob == this) return true;
        if (!(ob instanceof DTDElement)) return false;

        DTDElement other = (DTDElement) ob;

        if (name == null)
        {
            if (other.name != null) return false;
        }
        else
        {
            if (!name.equals(other.name)) return false;
        }

        if (attributes == null)
        {
            if (other.attributes != null) return false;
        }
        else
        {
            if (!attributes.equals(other.attributes)) return false;
        }

        if (content == null)
        {
            if (other.content != null) return false;
        }
        else
        {
            if (!content.equals(other.content)) return false;
        }

        return true;
    }

/** Sets the name of this element */
    public void setName(String aName)
    {
        name = aName;
    }

/** Returns the name of this element */
    public String getName()
    {
        return name;
    }

/** Stores an attribute in this element */
    public void setAttribute(String attrName, DTDAttribute attr)
    {
        attributes.put(attrName, attr);
    }

/** Gets an attribute for this element */
    public DTDAttribute getAttribute(String attrName)
    {
        return (DTDAttribute) attributes.get(attrName);
    }

/** Sets the content type of this element */
    public void setContent(DTDItem theContent)
    {
        content = theContent;
    }

/** Returns the content type of this element */
    public DTDItem getContent()
    {
        return content;
    }
}