Source code: org/merlotxml/util/xml/xml4j/DTDAttributeImpl.java
1 /*
2 ====================================================================
3 Copyright (c) 1999-2000 ChannelPoint, Inc.. All rights reserved.
4 ====================================================================
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 1. Redistribution of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12
13 2. Redistribution in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16
17 3. All advertising materials mentioning features or use of this
18 software must display the following acknowledgment: "This product
19 includes software developed by ChannelPoint, Inc. for use in the
20 Merlot XML Editor (http://www.channelpoint.com/merlot/)."
21
22 4. Any names trademarked by ChannelPoint, Inc. must not be used to
23 endorse or promote products derived from this software without prior
24 written permission. For written permission, please contact
25 legal@channelpoint.com.
26
27 5. Products derived from this software may not be called "Merlot"
28 nor may "Merlot" appear in their names without prior written
29 permission of ChannelPoint, Inc.
30
31 6. Redistribution of any form whatsoever must retain the following
32 acknowledgment: "This product includes software developed by
33 ChannelPoint, Inc. for use in the Merlot XML Editor
34 (http://www.channelpoint.com/merlot/)."
35
36 THIS SOFTWARE IS PROVIDED BY CHANNELPOINT, INC. "AS IS" AND ANY EXPRESSED OR
37 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
38 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
39 EVENT SHALL CHANNELPOINT, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
40 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
45 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 ====================================================================
47
48 For more information on ChannelPoint, Inc. please see http://www.channelpoint.com.
49 For information on the Merlot project, please see
50 http://www.channelpoint.com/merlot.
51 */
52
53
54 // Copyright 1999 ChannelPoint, Inc., All Rights Reserved.
55
56 package org.merlotxml.util.xml.xml4j;
57
58 import java.io.*;
59 import java.util.*;
60
61 import com.ibm.xml.parser.*;
62 import org.merlotxml.util.xml.*;
63
64
65 /**
66 * DTDAttribute
67 *
68 *
69 * @author Kelly A. Campbell
70 * @version $Id: DTDAttributeImpl.java,v 1.1.1.1 2001/07/02 15:41:28 flament Exp $
71 */
72
73 public class DTDAttributeImpl implements DTDAttribute, DTDConstants
74 {
75 private DTD _doc = null;
76 private AttDef _attDef = null;
77
78 public DTDAttributeImpl(DTD doc, AttDef attr)
79 {
80 _doc = doc;
81 _attDef = attr;
82
83 }
84
85 public String getName()
86 {
87 return _attDef.getName();
88 }
89
90 public int getType()
91 {
92 AttDef d = _attDef;
93
94 // translate from the IBM type defs to ours
95 int i = d.getDeclaredType();
96
97 switch (i) {
98
99 case AttDef.NAME_TOKEN_GROUP:
100 return TOKEN_GROUP;
101
102 case AttDef.CDATA:
103 return CDATA;
104
105 case AttDef.NMTOKENS:
106 return NMTOKENS;
107
108 case AttDef.NMTOKEN:
109 return NMTOKEN;
110
111 case AttDef.ID:
112 return ID;
113
114 case AttDef.IDREF:
115 return IDREF;
116
117 /*=$**/
118 // ajout cas IDREFS
119 case AttDef.IDREFS:
120 return IDREFS;
121 /*=$**/
122
123 default:
124 return NONE;
125 }
126
127 }
128
129
130 public int getDefaultType()
131 {
132 AttDef d = _attDef;
133 int i = d.getDefaultType();
134 switch (i) {
135 case AttDef.IMPLIED:
136 return IMPLIED;
137 case AttDef.REQUIRED:
138 return REQUIRED;
139 case NONE:
140 return NONE;
141 default:
142 return NONE;
143 }
144
145 }
146
147 public Enumeration getTokens()
148 {
149 int t = getType();
150 Enumeration e;
151 Vector v;
152
153 switch (t) {
154 case TOKEN_GROUP:
155 return _attDef.elements();
156 case CDATA:
157 return null;
158 case NMTOKEN:
159 v = new Vector();
160 v.addElement(_attDef.elementAt(0));
161 return v.elements();
162 case NMTOKENS:
163 return _attDef.elements();
164 default:
165 return null;
166 }
167
168 }
169
170
171
172 public String getDefaultValue()
173 {
174 return _attDef.getDefaultStringValue();
175 }
176
177
178 }