|
|
|
|
|
|
|
*/ |
|
/* |
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
|
* contributor license agreements. See the NOTICE file distributed with |
|
* this work for additional information regarding copyright ownership. |
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
* (the "License"); you may not use this file except in compliance with |
|
* the License. You may obtain a copy of the License at |
|
* |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
* |
|
* Unless required by applicable law or agreed to in writing, software |
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
* See the License for the specific language governing permissions and |
|
* limitations under the License. |
|
*/ |
|
|
|
package com.sun.org.apache.xerces.internal.impl.dtd.models; |
|
|
|
import com.sun.org.apache.xerces.internal.xni.QName; |
|
|
|
import com.sun.org.apache.xerces.internal.impl.dtd.XMLContentSpec; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class MixedContentModel |
|
implements ContentModelValidator { |
|
|
|
// |
|
// Data |
|
// |
|
|
|
|
|
private int fCount; |
|
|
|
|
|
private QName fChildren[]; |
|
|
|
|
|
private int fChildrenType[]; |
|
|
|
/* this is the EquivClassComparator object */ |
|
//private EquivClassComparator comparator = null; |
|
|
|
|
|
|
|
|
|
*/ |
|
private boolean fOrdered; |
|
|
|
// |
|
// Constructors |
|
// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public MixedContentModel(QName[] children, int[] type, int offset, int length , boolean ordered) { |
|
|
|
fCount = length; |
|
fChildren = new QName[fCount]; |
|
fChildrenType = new int[fCount]; |
|
for (int i = 0; i < fCount; i++) { |
|
fChildren[i] = new QName(children[offset + i]); |
|
fChildrenType[i] = type[offset + i]; |
|
} |
|
fOrdered = ordered; |
|
|
|
} |
|
|
|
// |
|
// ContentModelValidator methods |
|
// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public int validate(QName[] children, int offset, int length) { |
|
|
|
|
|
if (fOrdered) { |
|
int inIndex = 0; |
|
for (int outIndex = 0; outIndex < length; outIndex++) { |
|
|
|
|
|
final QName curChild = children[offset + outIndex]; |
|
if (curChild.localpart == null) { |
|
continue; |
|
} |
|
|
|
|
|
int type = fChildrenType[inIndex]; |
|
if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) { |
|
if (fChildren[inIndex].rawname != children[offset + outIndex].rawname) { |
|
return outIndex; |
|
} |
|
} |
|
else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) { |
|
String uri = fChildren[inIndex].uri; |
|
if (uri != null && uri != children[outIndex].uri) { |
|
return outIndex; |
|
} |
|
} |
|
else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) { |
|
if (children[outIndex].uri != null) { |
|
return outIndex; |
|
} |
|
} |
|
else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { |
|
if (fChildren[inIndex].uri == children[outIndex].uri) { |
|
return outIndex; |
|
} |
|
} |
|
|
|
|
|
inIndex++; |
|
} |
|
} |
|
|
|
|
|
else { |
|
for (int outIndex = 0; outIndex < length; outIndex++) |
|
{ |
|
|
|
final QName curChild = children[offset + outIndex]; |
|
|
|
|
|
if (curChild.localpart == null) |
|
continue; |
|
|
|
|
|
int inIndex = 0; |
|
for (; inIndex < fCount; inIndex++) |
|
{ |
|
int type = fChildrenType[inIndex]; |
|
if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) { |
|
if (curChild.rawname == fChildren[inIndex].rawname) { |
|
break; |
|
} |
|
} |
|
else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) { |
|
String uri = fChildren[inIndex].uri; |
|
if (uri == null || uri == children[outIndex].uri) { |
|
break; |
|
} |
|
} |
|
else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) { |
|
if (children[outIndex].uri == null) { |
|
break; |
|
} |
|
} |
|
else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { |
|
if (fChildren[inIndex].uri != children[outIndex].uri) { |
|
break; |
|
} |
|
} |
|
// REVISIT: What about checking for multiple ANY matches? |
|
// The content model ambiguity *could* be checked |
|
// by the caller before constructing the mixed |
|
// content model. |
|
} |
|
|
|
|
|
if (inIndex == fCount) |
|
return outIndex; |
|
} |
|
} |
|
|
|
|
|
return -1; |
|
} // validate |
|
|
|
} // class MixedContentModel |