1 16 17 package org.apache.xerces.impl.dtd.models; 18 19 import org.apache.xerces.xni.QName; 20 21 import org.apache.xerces.impl.dtd.XMLContentSpec; 22 23 40 public class MixedContentModel 41 implements ContentModelValidator { 42 43 47 48 private int fCount; 49 50 51 private QName fChildren[]; 52 53 54 private int fChildrenType[]; 55 56 57 59 63 private boolean fOrdered; 64 65 69 78 public MixedContentModel(QName[] children, int[] type, int offset, int length , boolean ordered) { 79 fCount = length; 81 fChildren = new QName[fCount]; 82 fChildrenType = new int[fCount]; 83 for (int i = 0; i < fCount; i++) { 84 fChildren[i] = new QName(children[offset + i]); 85 fChildrenType[i] = type[offset + i]; 86 } 87 fOrdered = ordered; 88 89 } 90 91 95 96 119 public int validate(QName[] children, int offset, int length) { 120 121 if (fOrdered) { 123 int inIndex = 0; 124 for (int outIndex = 0; outIndex < length; outIndex++) { 125 126 final QName curChild = children[offset + outIndex]; 128 if (curChild.localpart == null) { 129 continue; 130 } 131 132 int type = fChildrenType[inIndex]; 134 if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 135 if (fChildren[inIndex].rawname != children[offset + outIndex].rawname) { 136 return outIndex; 137 } 138 } 139 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) { 140 String uri = fChildren[inIndex].uri; 141 if (uri != null && uri != children[outIndex].uri) { 142 return outIndex; 143 } 144 } 145 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) { 146 if (children[outIndex].uri != null) { 147 return outIndex; 148 } 149 } 150 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 151 if (fChildren[inIndex].uri == children[outIndex].uri) { 152 return outIndex; 153 } 154 } 155 156 inIndex++; 158 } 159 } 160 161 else { 163 for (int outIndex = 0; outIndex < length; outIndex++) 164 { 165 final QName curChild = children[offset + outIndex]; 167 168 if (curChild.localpart == null) 170 continue; 171 172 int inIndex = 0; 174 for (; inIndex < fCount; inIndex++) 175 { 176 int type = fChildrenType[inIndex]; 177 if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 178 if (curChild.rawname == fChildren[inIndex].rawname) { 179 break; 180 } 181 } 182 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) { 183 String uri = fChildren[inIndex].uri; 184 if (uri == null || uri == children[outIndex].uri) { 185 break; 186 } 187 } 188 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) { 189 if (children[outIndex].uri == null) { 190 break; 191 } 192 } 193 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 194 if (fChildren[inIndex].uri != children[outIndex].uri) { 195 break; 196 } 197 } 198 } 203 204 if (inIndex == fCount) 206 return outIndex; 207 } 208 } 209 210 return -1; 212 } 214 } | Popular Tags |