1 57 58 package com.sun.org.apache.xerces.internal.impl.dtd.models; 59 60 import com.sun.org.apache.xerces.internal.xni.QName; 61 62 import com.sun.org.apache.xerces.internal.impl.dtd.XMLContentSpec; 63 64 80 public class MixedContentModel 81 implements ContentModelValidator { 82 83 87 88 private int fCount; 89 90 91 private QName fChildren[]; 92 93 94 private int fChildrenType[]; 95 96 97 99 103 private boolean fOrdered; 104 105 109 120 public MixedContentModel(QName[] children, int[] type, int offset, int length , boolean ordered) { 121 fCount = length; 123 fChildren = new QName[fCount]; 124 fChildrenType = new int[fCount]; 125 for (int i = 0; i < fCount; i++) { 126 fChildren[i] = new QName(children[offset + i]); 127 fChildrenType[i] = type[offset + i]; 128 } 129 fOrdered = ordered; 130 131 } 132 133 137 138 161 public int validate(QName[] children, int offset, int length) { 162 163 if (fOrdered) { 165 int inIndex = 0; 166 for (int outIndex = 0; outIndex < length; outIndex++) { 167 168 final QName curChild = children[offset + outIndex]; 170 if (curChild.localpart == null) { 171 continue; 172 } 173 174 int type = fChildrenType[inIndex]; 176 if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 177 if (fChildren[inIndex].rawname != children[offset + outIndex].rawname) { 178 return outIndex; 179 } 180 } 181 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) { 182 String uri = fChildren[inIndex].uri; 183 if (uri != null && uri != children[outIndex].uri) { 184 return outIndex; 185 } 186 } 187 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) { 188 if (children[outIndex].uri != null) { 189 return outIndex; 190 } 191 } 192 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 193 if (fChildren[inIndex].uri == children[outIndex].uri) { 194 return outIndex; 195 } 196 } 197 198 inIndex++; 200 } 201 } 202 203 else { 205 for (int outIndex = 0; outIndex < length; outIndex++) 206 { 207 final QName curChild = children[offset + outIndex]; 209 210 if (curChild.localpart == null) 212 continue; 213 214 int inIndex = 0; 216 for (; inIndex < fCount; inIndex++) 217 { 218 int type = fChildrenType[inIndex]; 219 if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 220 if (curChild.rawname == fChildren[inIndex].rawname) { 221 break; 222 } 223 } 224 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) { 225 String uri = fChildren[inIndex].uri; 226 if (uri == null || uri == children[outIndex].uri) { 227 break; 228 } 229 } 230 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) { 231 if (children[outIndex].uri == null) { 232 break; 233 } 234 } 235 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 236 if (fChildren[inIndex].uri != children[outIndex].uri) { 237 break; 238 } 239 } 240 } 245 246 if (inIndex == fCount) 248 return outIndex; 249 } 250 } 251 252 return -1; 254 } 256 } | Popular Tags |