if (parentType instanceof SimpleType) { stype = (SimpleType) parentType; } else if (parentType instanceof ComplexType && ((ComplexType) parentType).isSimpleContent()) { stype = ((ComplexType) parentType).getSimpleContentType(); !((ComplexType) parentType).isSimpleContent() && !((ComplexType) parentType).isMixedContent() && !Whitespace.isWhite(getStringValueCS())) { XPathException err = new XPathException("Complex type " + parentType.getDescription() +
/** * Decide whether an element is in the set of white-space preserving element types * * @param name identifies the name of the element being tested * @param schemaType the type annotation of the element being tested * @return STRIP_DEFAULT: strip spaces unless xml:space tells you not to. */ public int isSpacePreserving(NodeName name, SchemaType schemaType) { if (schemaType != Untyped.getInstance() && schemaType.isComplexType() && !((ComplexType) schemaType).isSimpleContent() && !((ComplexType) schemaType).isMixedContent()) { return Stripper.ALWAYS_STRIP; } else { return Stripper.ALWAYS_PRESERVE; } }
public void startElement(NodeName elemName, SchemaType type, Location location, int properties) throws XPathException { // System.err.println("startElement " + nameCode); nextReceiver.startElement(elemName, type, location, properties); byte preserveParent = stripStack[top]; byte preserve = (byte) (preserveParent & (PRESERVE_PARENT | ASSERTIONS_EXIST)); int elementStrip = isSpacePreserving(elemName, type); if (elementStrip == ALWAYS_PRESERVE) { preserve |= ALWAYS_PRESERVE; } else if (elementStrip == ALWAYS_STRIP) { preserve |= ALWAYS_STRIP; } if (type != Untyped.getInstance()) { if (preserve == 0) { // if the element has simple content, whitespace stripping is disabled if (type.isSimpleType() || ((ComplexType) type).isSimpleContent()) { preserve |= SIMPLE_CONTENT; } } if (type instanceof ComplexType && ((ComplexType) type).hasAssertions()) { preserve |= ASSERTIONS_EXIST; } } // put "preserve" value on top of stack top++; if (top >= stripStack.length) { stripStack = Arrays.copyOf(stripStack, top * 2); } stripStack[top] = preserve; }
/** * Test whether a type annotation code represents the type xs:ID or one of its subtypes * @param typeCode the type annotation to be tested * @return true if the type annotation represents an xs:ID */ public boolean isIdCode(int typeCode) { typeCode &= NamePool.FP_MASK; if (typeCode == StandardNames.XS_ID) { return true; } else if (typeCode < 1024) { // No other built-in type is an ID return false; } else { SchemaType type = config.getSchemaType(typeCode); if (type == null) { return false; // this shouldn't happen, but there's no need to crash right here } if (type.isAtomicType()) { return isSubType((AtomicType)type, BuiltInAtomicType.ID); } if (type instanceof ComplexType && ((ComplexType)type).isSimpleContent()) { SimpleType contentType = ((ComplexType)type).getSimpleContentType(); if (contentType.isAtomicType()) { return isSubType((AtomicType)contentType, BuiltInAtomicType.ID); } } return false; } }
while (extensions.hasNext()) { ComplexType extension = (ComplexType)extensions.next(); if (extension.allowsAttributes()) { found = true; break; ComplexType extension = (ComplexType)extensions.next(); try { if (extension.getAttributeUseType(targetfp) != null) { found = true; break; } else if (((ComplexType)contentType).isSimpleContent() && (axis==Axis.CHILD || axis==Axis.DESCENDANT || axis==Axis.DESCENDANT_OR_SELF) && (kind==Type.ELEMENT || kind==Type.DOCUMENT)) { ", as this type requires simple content", this); return new Literal(EmptySequence.getInstance()); } else if (((ComplexType)contentType).isEmptyContent() && (axis==Axis.CHILD || axis==Axis.DESCENDANT || axis==Axis.DESCENDANT_OR_SELF)) { for (Iterator iter=config.getExtensionsOfType(contentType); iter.hasNext();) { ComplexType extension = (ComplexType)iter.next(); if (!extension.isEmptyContent()) { return this; } else if (axis==Axis.ATTRIBUTE && targetfp != -1) { try { SchemaType schemaType = ((ComplexType)contentType).getAttributeUseType(targetfp); if (schemaType == null) {
err.setLocator(this); throw err; } else if (((ComplexType)parentType).isSimpleContent()) { XPathException err = new XPathException("Element " + env.getNamePool().getDisplayName(nameCode) + " is not permitted here: the containing element has a complex type with simple content"); type = ((ComplexType)parentType).getElementParticleType(nameCode & 0xfffff); } catch (SchemaException e) { throw new XPathException(e);
public void startElement (int nameCode, int typeCode, int locationId, int properties) throws XPathException { // System.err.println("startElement " + nameCode); nextReceiver.startElement(nameCode, typeCode, locationId, properties); byte preserveParent = stripStack[top]; byte preserve = (byte)(preserveParent & PRESERVE_PARENT); byte elementStrip = isSpacePreserving(nameCode); if (elementStrip == ALWAYS_PRESERVE) { preserve |= ALWAYS_PRESERVE; } else if (elementStrip == ALWAYS_STRIP) { preserve |= ALWAYS_STRIP; } if (preserve == 0 && typeCode != -1 && typeCode != StandardNames.XS_UNTYPED) { // if the element has simple content, whitespace stripping is disabled SchemaType type = getConfiguration().getSchemaType(typeCode); if (type.isSimpleType() || ((ComplexType)type).isSimpleContent()) { preserve |= CANNOT_STRIP; } } // put "preserve" value on top of stack top++; if (top >= stripStack.length) { byte[] newStack = new byte[top*2]; System.arraycopy(stripStack, 0, newStack, 0, top); stripStack = newStack; } stripStack[top] = preserve; }
type = ((ComplexType)parentType).getAttributeUseType(fp); } catch (SchemaException e) { throw new XPathException(e);
/** * Returns whether this text node contains <a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204#infoitem.character'> * element content whitespace</a>, often abusively called "ignorable whitespace". The text node is * determined to contain whitespace in element content during the load * of the document or if validation occurs while using * <code>Document.normalizeDocument()</code>. * * @since DOM Level 3 */ public boolean isElementContentWhitespace() { if (node.getNodeKind() != Type.TEXT) { throw new UnsupportedOperationException("Method is defined only on text nodes"); } if (!Whitespace.isWhite(node.getStringValue())) { return false; } NodeInfo parent = node.getParent(); if (parent == null) { return false; } SchemaType type = parent.getSchemaType(); return type.isComplexType() && !((ComplexType) type).isMixedContent(); }
int variety1 = ((ComplexType) n1.getSchemaType()).getVariety(); int variety2 = ((ComplexType) n2.getSchemaType()).getVariety(); if (variety1 != variety2) { explain(config, "both elements have complex type, but a different variety", flags, n1, n2); final SchemaType type1 = n1.getSchemaType(); final SchemaType type2 = n2.getSchemaType(); final boolean isSimple1 = type1.isSimpleType() || ((ComplexType) type1).isSimpleContent(); final boolean isSimple2 = type2.isSimpleType() || ((ComplexType) type2).isSimpleContent(); if (isSimple1 != isSimple2) { explain(config, "one element has a simple type, the other does not", flags, n1, n2);
} else if (((ComplexType)contentType).isSimpleContent() && (axis==Axis.CHILD || axis==Axis.DESCENDANT || axis==Axis.DESCENDANT_OR_SELF) && (kind==Type.ELEMENT || kind==Type.DOCUMENT)) { contentType.getDescription() + ", as this type requires simple content", this); } else if (((ComplexType)contentType).isEmptyContent() && (axis==Axis.CHILD || axis==Axis.DESCENDANT || axis==Axis.DESCENDANT_OR_SELF)) { for (Iterator iter=visitor.getConfiguration().getExtensionsOfType(contentType); iter.hasNext();) { ComplexType extension = (ComplexType)iter.next(); if (!extension.isEmptyContent()) { return this; } else if (axis==Axis.ATTRIBUTE && targetfp != -1) { try { SchemaType schemaType = ((ComplexType)contentType).getAttributeUseType(targetfp); if (schemaType == null) { String n = env.getNamePool().getDisplayName(targetfp); ((ComplexType)contentType).gatherAllPermittedChildren(children); if (children.isEmpty()) { env.issueWarning("The complex type " + contentType.getDescription() + SchemaType schemaType = ((ComplexType)contentType).getElementParticleType(childElement); if (schemaType == null) { String n = env.getNamePool().getDisplayName(childElement); Token.INTERSECT, new ContentTypeTest(Type.ELEMENT, schemaType, env.getConfiguration()));
/** * Test whether a type annotation code represents the type xs:ID or one of its subtypes * @param typeCode the type annotation to be tested * @return true if the type annotation represents an xs:ID */ public boolean isIdCode(int typeCode) { typeCode &= NamePool.FP_MASK; if (typeCode == StandardNames.XS_ID) { return true; } else if (typeCode < 1024) { // No other built-in type is an ID return false; } else { SchemaType type = config.getSchemaType(typeCode); if (type == null) { return false; // this shouldn't happen, but there's no need to crash right here } if (type.isAtomicType()) { return isSubType((AtomicType)type, BuiltInAtomicType.ID); } if (type instanceof ComplexType && ((ComplexType)type).isSimpleContent()) { SimpleType contentType = ((ComplexType)type).getSimpleContentType(); if (contentType.isAtomicType()) { return isSubType((AtomicType)contentType, BuiltInAtomicType.ID); } } return false; } }
err.setLocator(this); throw err; } else if (((ComplexType)parentType).isSimpleContent()) { XPathException err = new XPathException("Element " + env.getNamePool().getDisplayName(nameCode) + " is not permitted here: the containing element has a complex type with simple content"); type = ((ComplexType)parentType).getElementParticleType(nameCode & 0xfffff, true); } catch (SchemaException e) { throw new XPathException(e);
/** * Decide whether an element is in the set of white-space preserving element types * * @param name identifies the name of the element being tested * @param schemaType the type annotation of the element being tested * @return STRIP_DEFAULT: strip spaces unless xml:space tells you not to. */ public int isSpacePreserving(NodeName name, SchemaType schemaType) { if (schemaType != Untyped.getInstance() && schemaType.isComplexType() && !((ComplexType) schemaType).isSimpleContent() && !((ComplexType) schemaType).isMixedContent()) { return Stripper.ALWAYS_STRIP; } else { return Stripper.ALWAYS_PRESERVE; } }
public void startElement (int nameCode, int typeCode, int locationId, int properties) throws XPathException { // System.err.println("startElement " + nameCode); nextReceiver.startElement(nameCode, typeCode, locationId, properties); byte preserveParent = stripStack[top]; byte preserve = (byte)(preserveParent & PRESERVE_PARENT); byte elementStrip = isSpacePreserving(nameCode); if (elementStrip == ALWAYS_PRESERVE) { preserve |= ALWAYS_PRESERVE; } else if (elementStrip == ALWAYS_STRIP) { preserve |= ALWAYS_STRIP; } if (preserve == 0 && typeCode != -1 && typeCode != StandardNames.XS_UNTYPED) { // if the element has simple content, whitespace stripping is disabled SchemaType type = getConfiguration().getSchemaType(typeCode); if (type.isSimpleType() || ((ComplexType)type).isSimpleContent()) { preserve |= CANNOT_STRIP; } } // put "preserve" value on top of stack top++; if (top >= stripStack.length) { byte[] newStack = new byte[top*2]; System.arraycopy(stripStack, 0, newStack, 0, top); stripStack = newStack; } stripStack[top] = preserve; }
public void startElement(NodeName elemName, SchemaType type, Location location, int properties) throws XPathException { // System.err.println("startElement " + nameCode); nextReceiver.startElement(elemName, type, location, properties); byte preserveParent = stripStack[top]; byte preserve = (byte) (preserveParent & (PRESERVE_PARENT | ASSERTIONS_EXIST)); int elementStrip = isSpacePreserving(elemName, type); if (elementStrip == ALWAYS_PRESERVE) { preserve |= ALWAYS_PRESERVE; } else if (elementStrip == ALWAYS_STRIP) { preserve |= ALWAYS_STRIP; } if (type != Untyped.getInstance()) { if (preserve == 0) { // if the element has simple content, whitespace stripping is disabled if (type.isSimpleType() || ((ComplexType) type).isSimpleContent()) { preserve |= SIMPLE_CONTENT; } } if (type instanceof ComplexType && ((ComplexType) type).hasAssertions()) { preserve |= ASSERTIONS_EXIST; } } // put "preserve" value on top of stack top++; if (top >= stripStack.length) { stripStack = Arrays.copyOf(stripStack, top * 2); } stripStack[top] = preserve; }
type = ((ComplexType)parentType).getAttributeUseType(fp); } catch (SchemaException e) { throw new XPathException(e);
/** * Returns whether this text node contains <a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204#infoitem.character'> * element content whitespace</a>, often abusively called "ignorable whitespace". The text node is * determined to contain whitespace in element content during the load * of the document or if validation occurs while using * <code>Document.normalizeDocument()</code>. * * @since DOM Level 3 */ public boolean isElementContentWhitespace() { if (node.getNodeKind() != Type.TEXT) { throw new UnsupportedOperationException("Method is defined only on text nodes"); } if (!Whitespace.isWhite(node.getStringValue())) { return false; } NodeInfo parent = node.getParent(); if (parent == null) { return false; } SchemaType type = parent.getSchemaType(); return type.isComplexType() && !((ComplexType) type).isMixedContent(); }
int variety1 = ((ComplexType) n1.getSchemaType()).getVariety(); int variety2 = ((ComplexType) n2.getSchemaType()).getVariety(); if (variety1 != variety2) { explain(config, "both elements have complex type, but a different variety", flags, n1, n2); final SchemaType type1 = n1.getSchemaType(); final SchemaType type2 = n2.getSchemaType(); final boolean isSimple1 = type1.isSimpleType() || ((ComplexType) type1).isSimpleContent(); final boolean isSimple2 = type2.isSimpleType() || ((ComplexType) type2).isSimpleContent(); if (isSimple1 != isSimple2) { explain(config, "one element has a simple type, the other does not", flags, n1, n2);
while (extensions.hasNext()) { ComplexType extension = (ComplexType) extensions.next(); if (extension.allowsAttributes()) { found = true; break; ComplexType extension = (ComplexType) extensions.next(); try { if (extension.getAttributeUseType(targetName) != null) { found = true; break; } else if (((ComplexType) contentType).isSimpleContent() && (axis == AxisInfo.CHILD || axis == AxisInfo.DESCENDANT || axis == AxisInfo.DESCENDANT_OR_SELF) && UType.PARENT_NODE_KINDS.subsumes(kind)) { } else if (((ComplexType) contentType).isEmptyContent() && (axis == AxisInfo.CHILD || axis == AxisInfo.DESCENDANT || axis == AxisInfo.DESCENDANT_OR_SELF)) { for (Iterator iter = config.getExtensionsOfType(contentType); iter.hasNext(); ) { ComplexType extension = (ComplexType) iter.next(); if (!extension.isEmptyContent()) { return this; if (targetfp == -1) { if (warnings) { if (!((ComplexType) contentType).allowsAttributes()) { visitor.issueWarning( "The complex type " + contentType.getDescription() +