Ejemplo n.º 1
0
TokenList::TokenList(std::string& s)
  : head(NULL), tail(NULL), valid(true), postfix(false)
{
  if (!this->parseInput(s) || !checkTokenList(this))
    {
      this->valid = false;
      std::cout << "Expression '" << s << "' is invalid" << std::endl;
    }
}
Ejemplo n.º 2
0
void DTDValidator::preContentValidation(bool
#if defined(MATCH_DEBUG)
										reuseGrammar
#endif
                                       ,bool validateDefAttr)
{
    //
    //  Lets enumerate all of the elements in the element decl pool
    //  and put out an error for any that did not get declared.
    //  We also check all of the attributes as well.
    //
    NameIdPoolEnumerator<DTDElementDecl> elemEnum = fDTDGrammar->getElemEnumerator();
    fDTDGrammar->setValidated(true);
    while (elemEnum.hasMoreElements())
    {
        const DTDElementDecl& curElem = elemEnum.nextElement();
        const DTDElementDecl::CreateReasons reason = curElem.getCreateReason();

        //
        //  See if this element decl was ever marked as declared. If
        //  not, then put out an error. In some cases its just
        //  a warning, such as being referenced in a content model.
        //
        if (reason != XMLElementDecl::Declared)
        {
            if (reason == XMLElementDecl::AttList)
            {
                getScanner()->emitError
                (
                    XMLErrs::UndeclaredElemInAttList
                    , curElem.getFullName()
                );
            }
             else if (reason == XMLElementDecl::AsRootElem)
            {
                // It's ok that the root element is not declared in the DTD
                /*
                emitError
                (
                    XMLValid::UndeclaredElemInDocType
                    , curElem.getFullName()
                );*/
            }
             else if (reason == XMLElementDecl::InContentModel)
            {
                getScanner()->emitError
                (
                    XMLErrs::UndeclaredElemInCM
                    , curElem.getFullName()
                );
            }
            else
            {
                #if defined(MATCH_DEBUG)
                  if(reuseGrammar && reason == XMLElementDecl::JustFaultIn){
                  }
                  else
                      ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::DTD_UnknownCreateReason, getScanner()->getMemoryManager());
                #endif
            }
        }

        //
        //  Check all of the attributes of the current element.
        //  We check for:
        //
        //  1) Multiple ID attributes
        //  2) That all of the default values of attributes are
        //      valid for their type.
        //  3) That for any notation types, that their lists
        //      of possible values refer to declared notations.
        //
        //  4) XML1.0(3rd edition)
        //
        //     Validity constraint: One Notation Per Element Type
        //     An element type MUST NOT have more than one NOTATION attribute specified.
        //
        //     Validity constraint: No Notation on Empty Element
        //     For compatibility, an attribute of type NOTATION MUST NOT be declared on an element declared EMPTY.
        //
        //     Validity constraint: No Duplicate Tokens
        //     The notation names in a single NotationType attribute declaration, as well as 
        //     the NmTokens in a single Enumeration attribute declaration, MUST all be distinct.
        //

        XMLAttDefList& attDefList = curElem.getAttDefList();
        bool seenId = false;
        bool seenNOTATION = false;
        bool elemEmpty = (curElem.getModelType() == DTDElementDecl::Empty);

        for(XMLSize_t i=0; i<attDefList.getAttDefCount(); i++)
        {
            const XMLAttDef& curAttDef = attDefList.getAttDef(i);

            if (curAttDef.getType() == XMLAttDef::ID)
            {
                if (seenId)
                {
                    emitError
                    (
                        XMLValid::MultipleIdAttrs
                        , curElem.getFullName()
                    );
                    break;
                }

                seenId = true;
            }
             else if (curAttDef.getType() == XMLAttDef::Notation)
            {
                if (seenNOTATION)
                {
                    emitError
                    (
                        XMLValid::ElemOneNotationAttr
                      , curElem.getFullName()
                    );

                    break;
                }

                seenNOTATION = true;

                // no notation attribute on empty element
                if (elemEmpty)
                {
                    emitError
                   (
                      XMLValid::EmptyElemNotationAttr
                    , curElem.getFullName()
                    , curAttDef.getFullName()
                    );

                    break;
                }

                //go through enumeration list to check
                // distinct 
                // notation declaration
                if (curAttDef.getEnumeration())
                {
                    checkTokenList(curAttDef, true);
                }
             }
             else if (curAttDef.getType() == XMLAttDef::Enumeration )
             {
                //go through enumeration list to check
                // distinct only
                if (curAttDef.getEnumeration())
                {
                    checkTokenList(curAttDef, false);
                }
             }

            // If it has a default/fixed value, then validate it
            if (validateDefAttr && curAttDef.getValue())
            {
                validateAttrValue
                (
                    &curAttDef
                    , curAttDef.getValue()
                    , true
                    , &curElem
                );
            }
        }
    }

    //
    //  And enumerate all of the general entities. If any of them
    //  reference a notation, then make sure the notation exists.
    //
    NameIdPoolEnumerator<DTDEntityDecl> entEnum = fDTDGrammar->getEntityEnumerator();
    while (entEnum.hasMoreElements())
    {
        const DTDEntityDecl& curEntity = entEnum.nextElement();

        if (!curEntity.getNotationName())
            continue;

        // It has a notation name, so look it up
        if (!fDTDGrammar->getNotationDecl(curEntity.getNotationName()))
        {
            emitError
            (
                XMLValid::NotationNotDeclared
                , curEntity.getNotationName()
            );
        }
    }
}