home *** CD-ROM | disk | FTP | other *** search
- package com.ms.xml.parser;
-
- import com.ms.xml.om.Element;
- import com.ms.xml.om.ElementImpl;
- import com.ms.xml.util.Atom;
- import com.ms.xml.util.Name;
- import com.ms.xml.util.XMLOutputStream;
- import java.io.IOException;
- import java.util.Enumeration;
- import java.util.Vector;
-
- public class AttDef {
- public static final int CDATA = 0;
- // $FF: renamed from: ID int
- public static final int field_0 = 1;
- public static final int IDREF = 2;
- public static final int IDREFS = 3;
- public static final int ENTITY = 4;
- public static final int ENTITIES = 5;
- public static final int NMTOKEN = 6;
- public static final int NMTOKENS = 7;
- public static final int NOTATION = 8;
- public static final int ENUMERATION = 9;
- public static final int DEFAULT = 0;
- public static final int REQUIRED = 1;
- public static final int IMPLIED = 2;
- public static final int FIXED = 3;
- Name name;
- byte type;
- byte presence;
- Object def;
- Vector values;
- static Name nameATTRIBUTE = Name.create("ATTRIBUTE", "XML");
- static Name nameID = Name.create("ID", "XML");
- static Name nameDEFAULT = Name.create("DEFAULT", "XML");
- static Name namePRESENCE = Name.create("PRESENCE", "XML");
- static Name nameVALUES = Name.create("VALUES", "XML");
- static Name nameTYPE = Name.create("TYPE", "XML");
-
- private void reportEmpty(Parser var1, String var2) throws ParseException {
- var1.error("Expected " + var1.tokenString(-4, var2) + " insteadof " + var1.tokenString(var1.token, (String)null));
- }
-
- final Object parseAttValue(Element var1, Parser var2, boolean var3) throws ParseException {
- Object var6 = null;
- Object var7;
- switch (this.type) {
- case 0:
- var2.scanString(var2.quote, 38, 38, 60);
- var7 = var2.text;
- if (!var3 && this.presence == 3 && !this.def.toString().equals(var2.text)) {
- this.reportMismatch(var2);
- }
- break;
- case 1:
- ++var2.simplename;
- var2.parseToken(-4, "ID");
- var2.simplename += -1;
- var2.parseToken(39, "string");
- if (!var3) {
- if (this.presence == 3 && (Name)this.def != var2.name) {
- this.reportMismatch(var2);
- }
-
- Element var9 = var2.dtd.findID(var2.name);
- if (var9 != null) {
- var2.error("ID " + var6 + " is already used on element " + var9.getTagName());
- }
-
- var2.dtd.addID(var2.name, var1);
- }
-
- var7 = var2.name;
- break;
- case 2:
- case 3:
- Vector var17 = new Vector();
- StringBuffer var21 = new StringBuffer();
- ++var2.simplename;
- int var14 = var2.parseNames(var17, 0, var21);
- var2.simplename += -1;
- if (var14 == 0) {
- this.reportEmpty(var2, "IDREF");
- }
-
- if (var14 > 1 && this.type == 2) {
- var2.error("IDREF type attribute \"" + this.name + "\" cannot refer to more than one ID.");
- }
-
- if (!var3) {
- --var14;
-
- for(; var14 >= 0; --var14) {
- Name var19 = (Name)var17.elementAt(var14);
- if (this.presence == 3) {
- if (this.type == 3) {
- this.checkFixed(var19, var2);
- } else if ((Name)this.def != var19) {
- this.reportMismatch(var2);
- }
- }
-
- if (var2.dtd.findID(var19) == null) {
- var2.dtd.addIDCheck(var19, var2.reader.line, var2.reader.column - 1, var2.reader.owner);
- }
- }
- }
-
- var7 = this.type == 2 ? var17.elementAt(0) : var17;
- break;
- case 4:
- case 5:
- StringBuffer var20 = new StringBuffer();
- Vector var16 = new Vector();
- ++var2.nouppercase;
- int var12 = var2.parseNames(var16, 0, var20);
- var2.nouppercase += -1;
- if (var12 == 0) {
- this.reportEmpty(var2, "ENTITY name");
- }
-
- if (var12 > 1 && this.type == 4) {
- var2.error("ENTITY type attribute \"" + this.name + "\" cannot refer to more than one entity.");
- }
-
- --var12;
-
- for(; var12 >= 0; --var12) {
- Name var18 = (Name)var16.elementAt(var12);
- if (var2.dtd.findEntity(var18) == null) {
- var2.error("Couldn't find entity '" + var18 + "'");
- }
-
- if (!var3 && this.presence == 3) {
- if (this.type == 5) {
- this.checkFixed(var18, var2);
- } else if (var18 != (Name)this.def) {
- this.reportMismatch(var2);
- }
- }
- }
-
- var7 = this.type == 4 ? var16.elementAt(0) : var16;
- break;
- case 6:
- case 7:
- StringBuffer var8 = new StringBuffer();
- Vector var5 = new Vector();
- ++var2.nametoken;
- int var10 = var2.parseNames(var5, 0, var8);
- var2.nametoken += -1;
- if (var10 == 0) {
- this.reportEmpty(var2, "NMTOKEN");
- }
-
- if (var10 > 1 && this.type == 6) {
- var2.error("NMTOKEN type attribute \"" + this.name + "\" cannot refer to more than one name token.");
- }
-
- if (!var3 && this.presence == 3) {
- if (this.type == 6) {
- if ((Name)this.def != (Name)var5.elementAt(0)) {
- this.reportMismatch(var2);
- }
- } else {
- for(int var11 = var5.size() - 1; var11 >= 0; --var11) {
- this.checkFixed((Name)var5.elementAt(var11), var2);
- }
- }
- }
-
- var7 = this.type == 6 ? var5.elementAt(0) : var5;
- break;
- case 8:
- case 9:
- if (this.type == 9) {
- ++var2.nametoken;
- }
-
- var2.parseToken(-4, "name");
- if (this.type == 9) {
- var2.nametoken += -1;
- }
-
- var2.parseToken(39, "string");
-
- int var4;
- for(var4 = this.values.size() - 1; var4 >= 0 && (Name)this.values.elementAt(var4) != var2.name; --var4) {
- }
-
- if (var4 < 0) {
- var2.error("Attribute value '" + var2.name + "' is not in the allowed set.");
- }
-
- if (!var3 && this.presence == 3 && var2.name != this.def) {
- this.reportMismatch(var2);
- }
-
- var7 = var2.name;
- break;
- default:
- var7 = null;
- }
-
- return var7;
- }
-
- AttDef(Name var1, int var2) {
- this(var1, var2, (Object)null, 0, (Vector)null);
- }
-
- AttDef(Name var1, int var2, Vector var3) {
- this(var1, var2, (Object)null, 0, var3);
- }
-
- AttDef(Name var1, int var2, Object var3, int var4) {
- this(var1, var2, var3, var4, (Vector)null);
- }
-
- AttDef(Name var1, int var2, Object var3, int var4, Vector var5) {
- this.name = var1;
- this.type = (byte)var2;
- this.def = var3;
- this.presence = (byte)var4;
- this.values = var5;
- }
-
- String typeToString() {
- switch (this.type) {
- case 0:
- default:
- return "CDATA";
- case 1:
- return "ID";
- case 2:
- return "IDREF";
- case 3:
- return "IDREFS";
- case 4:
- return "ENTITY";
- case 5:
- return "ENTITIES";
- case 6:
- return "NMTOKEN";
- case 7:
- return "NMTOKENS";
- case 8:
- return "NOTATION";
- case 9:
- return "ENUMERATION";
- }
- }
-
- private void reportMismatch(Parser var1) throws ParseException {
- var1.error("Attribute " + this.name + " should have the fixed value \"" + this.def + "\"");
- }
-
- private void checkFixed(Name var1, Parser var2) throws ParseException {
- Vector var3 = (Vector)this.def;
-
- int var4;
- for(var4 = var3.size() - 1; var4 >= 0 && (Name)var3.elementAt(var4) != var1; --var4) {
- }
-
- if (var4 < 0) {
- var2.error("Attribue value " + var1 + " is not in the fixed value set.");
- }
-
- }
-
- Element toSchema() {
- ElementImpl var1 = new ElementImpl(nameATTRIBUTE, 0);
- var1.setAttribute(nameID, this.name.getName());
- var1.setAttribute(nameTYPE, this.typeToString());
- if (this.presence != 0) {
- var1.setAttribute(namePRESENCE, this.presenceToString());
- }
-
- if (this.type == 9) {
- String var2 = "";
-
- for(int var3 = 0; var3 < this.values.size(); ++var3) {
- Name var4 = (Name)this.values.elementAt(var3);
- var2 = var2 + var4.toString();
- if (var3 < this.values.size() - 1) {
- var2 = var2 + " ";
- }
- }
-
- var1.setAttribute(nameVALUES, var2);
- }
-
- if (this.def != null) {
- var1.setAttribute(nameDEFAULT, this.def);
- }
-
- return var1;
- }
-
- void save(Atom var1, XMLOutputStream var2) throws IOException {
- if (this.name == Parser.nameXMLSpace) {
- var2.writeChars(this.name.getName());
- } else {
- var2.writeQualifiedName(this.name, var1);
- }
-
- switch (this.type) {
- case 0:
- var2.writeChars(" CDATA");
- break;
- case 1:
- var2.writeChars(" ID");
- break;
- case 2:
- var2.writeChars(" IDREF");
- break;
- case 3:
- var2.writeChars(" IDREFS");
- break;
- case 4:
- var2.writeChars(" ENTITY");
- break;
- case 5:
- var2.writeChars(" ENTITIES");
- break;
- case 6:
- var2.writeChars(" NMTOKEN");
- break;
- case 7:
- var2.writeChars(" NMTOKENS");
- break;
- case 8:
- var2.writeChars(" NOTATION");
- case 9:
- var2.writeChars(" (");
-
- for(int var3 = 0; var3 < this.values.size(); ++var3) {
- Name var4 = (Name)this.values.elementAt(var3);
- if (this.type == 8) {
- var2.writeQualifiedName(var4, var1);
- } else {
- var2.writeChars(var4.toString());
- }
-
- if (var3 < this.values.size() - 1) {
- var2.write(124);
- }
- }
-
- var2.write(41);
- }
-
- switch (this.presence) {
- case 0:
- case 3:
- if (this.presence == 3) {
- var2.writeChars(" #FIXED");
- }
-
- if (this.def != null) {
- var2.writeChars(" ");
- switch (this.type) {
- case 0:
- case 1:
- case 2:
- case 6:
- case 9:
- var2.writeQuotedString(this.def.toString());
- return;
- case 3:
- case 5:
- case 7:
- var2.write(34);
- int var5 = 0;
- Enumeration var6 = ((Vector)this.def).elements();
-
- while(var6.hasMoreElements()) {
- if (var5++ > 0) {
- var2.write(124);
- }
-
- if (this.type == 5) {
- var2.writeQualifiedName((Name)var6.nextElement(), var1);
- } else {
- var2.writeChars(var6.nextElement().toString());
- }
- }
-
- var2.write(34);
- return;
- case 4:
- case 8:
- var2.write(34);
- var2.writeQualifiedName((Name)this.def, var1);
- var2.write(34);
- return;
- }
- }
- default:
- return;
- case 1:
- var2.writeChars(" #REQUIRED");
- return;
- case 2:
- var2.writeChars(" #IMPLIED");
- }
- }
-
- public Object getDefault() {
- return this.def;
- }
-
- public Name getName() {
- return this.name;
- }
-
- public int getType() {
- return this.type;
- }
-
- public int getPresence() {
- return this.presence;
- }
-
- final Object parseAttribute(Element var1, Parser var2) throws ParseException {
- var2.parseToken(39, "string");
- return this.parseAttValue(var1, var2, false);
- }
-
- String presenceToString() {
- switch (this.presence) {
- case 0:
- default:
- return "DEFAULT";
- case 1:
- return "REQUIRED";
- case 2:
- return "IMPLIED";
- case 3:
- return "FIXED";
- }
- }
- }
-