void IGXMLScanner::sendCharData()

in src/xercesc/internal/IGXMLScanner2.cpp [1337:1517]


void IGXMLScanner::sendCharData(XMLBuffer& toSend)
{
    // If no data in the buffer, then nothing to do
    if (toSend.isEmpty())
        return;

    //  We do different things according to whether we are validating or
    //  not. If not, its always just characters; else, it depends on the
    //  current element's content model.
    if (fValidate)
    {
        // Get the raw data we need for the callback
        const XMLCh* rawBuf = toSend.getRawBuffer();
        XMLSize_t len = toSend.getLen();

        // And see if the current element is a 'Children' style content model
        const ElemStack::StackElem* topElem = fElemStack.topElement();

        // Get the character data opts for the current element
        XMLElementDecl::CharDataOpts charOpts = XMLElementDecl::AllCharData;
        if(fGrammar->getGrammarType() == Grammar::SchemaGrammarType)
        {
            // And see if the current element is a 'Children' style content model
            ComplexTypeInfo *currType = ((SchemaValidator*)fValidator)->getCurrentTypeInfo();
            if(currType)
            {
                SchemaElementDecl::ModelTypes modelType = (SchemaElementDecl::ModelTypes) currType->getContentType();
                if(modelType == SchemaElementDecl::Children ||
                   modelType == SchemaElementDecl::ElementOnlyEmpty)
                    charOpts = XMLElementDecl::SpacesOk;
                else if(modelType == SchemaElementDecl::Empty)
                    charOpts = XMLElementDecl::NoCharData;
            }
        } else // DTD grammar
            charOpts = topElem->fThisElement->getCharDataOpts();

        if (charOpts == XMLElementDecl::NoCharData)
        {
            // They definitely cannot handle any type of char data
            fValidator->emitError(XMLValid::NoCharDataInCM);
            //if(fGrammarType == Grammar::SchemaGrammarType)
            //{
              //  if (getPSVIHandler())
              //  {
                    // REVISIT:
                    // PSVIElement->setValidity(PSVIItem::VALIDITY_INVALID);
              //  }
           // }
        }
        else if (fReaderMgr.getCurrentReader()->isAllSpaces(rawBuf, len))
        {
            //  Its all spaces. So, if they can take spaces, then send it
            //  as ignorable whitespace. If they can handle any char data
            //  send it as characters.
            if (charOpts == XMLElementDecl::SpacesOk) {
                if (fDocHandler)
                    fDocHandler->ignorableWhitespace(rawBuf, len, false);
            }
            else if (charOpts == XMLElementDecl::AllCharData)
            {
                if (fGrammarType != Grammar::SchemaGrammarType)
                {
                    if (fDocHandler)
                        fDocHandler->docCharacters(rawBuf, len, false);
                }
                else
                {
                    XMLSize_t xsLen;
                    const XMLCh* xsNormalized;
                    SchemaValidator *schemaValidator = (SchemaValidator *)fValidator;
                    DatatypeValidator* tempDV = ((SchemaValidator*) fValidator)->getCurrentDatatypeValidator();
                    if (tempDV && tempDV->getWSFacet() != DatatypeValidator::PRESERVE)
                    {
                        // normalize the character according to schema whitespace facet
                        ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, rawBuf, fWSNormalizeBuf);
                        xsNormalized = fWSNormalizeBuf.getRawBuffer();
                        xsLen = fWSNormalizeBuf.getLen();
                    }
                    else {
                        xsNormalized = rawBuf;
                        xsLen = len ;
                    }

                    // tell the schema validation about the character data for checkContent later
                    schemaValidator->setDatatypeBuffer(xsNormalized);

                    // call all active identity constraints
                    if (toCheckIdentityConstraint() && fICHandler->getMatcherCount()) {
                        fContent.append(xsNormalized, xsLen);
                    }

                    if (fDocHandler) {
                        if (fNormalizeData) {
                           fDocHandler->docCharacters(xsNormalized, xsLen, false);
                        }
                        else {
                            fDocHandler->docCharacters(rawBuf, len, false);
                        }
                    }
                }
            }
        }
        else
        {
            //  If they can take any char data, then send it. Otherwise, they
            //  can only handle whitespace and can't handle this stuff so
            //  issue an error.
            if (charOpts == XMLElementDecl::AllCharData)
            {
                if (fGrammarType != Grammar::SchemaGrammarType)
                {
                    if (fDocHandler)
                        fDocHandler->docCharacters(rawBuf, len, false);
                }
                else
                {
                    XMLSize_t xsLen;
                    const XMLCh* xsNormalized;
                    SchemaValidator *schemaValidator = (SchemaValidator*)fValidator;
                    DatatypeValidator* tempDV = ((SchemaValidator*) fValidator)->getCurrentDatatypeValidator();
                    if (tempDV && tempDV->getWSFacet() != DatatypeValidator::PRESERVE)
                    {
                        // normalize the character according to schema whitespace facet
                        ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, rawBuf, fWSNormalizeBuf);
                        xsNormalized = fWSNormalizeBuf.getRawBuffer();
                        xsLen = fWSNormalizeBuf.getLen();
                    }
                    else {
                        xsNormalized = rawBuf;
                        xsLen = len;
                    }

                    // tell the schema validation about the character data for checkContent later
                    schemaValidator->setDatatypeBuffer(xsNormalized);

                    // call all active identity constraints
                    if (toCheckIdentityConstraint() && fICHandler->getMatcherCount()) {
                        fContent.append(xsNormalized, xsLen);
                    }

                    if (fDocHandler) {
                        if (fNormalizeData) {
                            fDocHandler->docCharacters(xsNormalized, xsLen, false);
                        }
                        else {
                            fDocHandler->docCharacters(rawBuf, len, false);
                        }
                    }
                }
            }
            else
            {
                fValidator->emitError(XMLValid::NoCharDataInCM);
                if(fGrammarType == Grammar::SchemaGrammarType)
                {
                    if (getPSVIHandler())
                    {
                        // REVISIT:
                        // PSVIAttribute->setValidity(PSVIItem::VALIDITY_INVALID);
                    }
                }
            }
        }
    }
    else
    {
        // call all active identity constraints
        if (fGrammarType == Grammar::SchemaGrammarType) {

            if (toCheckIdentityConstraint() && fICHandler->getMatcherCount())
                fContent.append(toSend.getRawBuffer(), toSend.getLen());
        }

        // Always assume its just char data if not validating
        if (fDocHandler)
            fDocHandler->docCharacters(toSend.getRawBuffer(), toSend.getLen(), false);
    }

    // Reset buffer
    toSend.reset();
}