in xmlschema-walker/src/main/java/org/apache/ws/commons/schema/docpath/XmlSchemaPathFinder.java [761:823]
public void characters(char[] ch, int start, int length) throws SAXException {
/*
* If the most recent path node is an element with simple content,
* confirm these characters match the data type expected. If we are not
* expecting an element with simple content, and the characters don't
* represent all whitespace, throw an exception.
*/
try {
if (currentPath.getStateMachineNode().getNodeType().equals(XmlSchemaStateMachineNode.Type.ANY)
&& (anyStack != null) && !anyStack.isEmpty()) {
/*
* If this represents a wildcard element, we don't care - we
* won't be processing the content.
*/
return;
}
final XmlSchemaStateMachineNode state = getStateMachineOfOwningElement();
final XmlSchemaElement element = state.getElement();
final XmlSchemaTypeInfo elemTypeInfo = state.getElementType();
final String text = new String(ch, start, length).trim();
final boolean elemExpectsContent = ((elemTypeInfo != null) && (!elemTypeInfo.getType()
.equals(XmlSchemaTypeInfo.Type.COMPLEX) || elemTypeInfo.isMixed()));
if (!elemExpectsContent && (text.length() == 0)) {
// Nothing to see here.
return;
} else if (!elemExpectsContent && (text.length() > 0)) {
throw new IllegalStateException("Element " + state.getElement().getQName()
+ " has no content, but we received \"" + text + "\" for it.");
} else if (elemExpectsContent && (text.length() == 0) && !state.getElement().isNillable()
&& !elemTypeInfo.isMixed() && (element.getDefaultValue() == null)
&& (element.getFixedValue() == null)) {
throw new IllegalStateException("Received empty text for element "
+ state.getElement().getQName()
+ " when content was expected.");
}
XmlSchemaElementValidator.validateContent(state, text, nsContext);
currentPath.getDocumentNode().setReceivedContent(true);
final XmlSchemaPathNode<U, V> contentPath = pathMgr
.addParentSiblingOrContentNodeToPath(currentPath, XmlSchemaPathNode.Direction.CONTENT);
currentPath.setNextNode(-1, contentPath);
currentPath = contentPath;
traversedElements
.add(new TraversedElement(element.getQName(), TraversedElement.Traversal.CONTENT));
} catch (Exception e) {
throw new RuntimeException("Error occurred while processing characters; traversed path was "
+ getElementsTraversedAsString(), e);
}
}