You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2002/02/06 23:21:50 UTC

cvs commit: xml-xerces/c/src/xercesc/validators/schema XUtil.hpp XUtil.cpp GeneralAttributeCheck.hpp GeneralAttributeCheck.cpp

knoaman     02/02/06 14:21:50

  Modified:    c/src/xercesc/validators/schema XUtil.hpp XUtil.cpp
                        GeneralAttributeCheck.hpp GeneralAttributeCheck.cpp
  Log:
  Use IDOM for schema processing.
  
  Revision  Changes    Path
  1.2       +18 -0     xml-xerces/c/src/xercesc/validators/schema/XUtil.hpp
  
  Index: XUtil.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/XUtil.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XUtil.hpp	1 Feb 2002 22:22:50 -0000	1.1
  +++ XUtil.hpp	6 Feb 2002 22:21:49 -0000	1.2
  @@ -56,8 +56,11 @@
   
   /*
    * $Log: XUtil.hpp,v $
  - * Revision 1.1  2002/02/01 22:22:50  peiyongz
  - * Initial revision
  + * Revision 1.2  2002/02/06 22:21:49  knoaman
  + * Use IDOM for schema processing.
  + *
  + * Revision 1.1.1.1  2002/02/01 22:22:50  peiyongz
  + * sane_include
    *
    * Revision 1.3  2001/11/02 14:13:45  knoaman
    * Add support for identity constraints.
  @@ -78,6 +81,9 @@
   #include <xercesc/dom/DOM_NamedNodeMap.hpp>
   #include <xercesc/dom/DOM_Node.hpp>
   
  +class IDOM_Node;
  +class IDOM_Element;
  +
   /**
    * Some useful utility methods.
    */
  @@ -107,6 +113,8 @@
   
       // Finds and returns the first child element node.
       static DOM_Element getFirstChildElement(const DOM_Node &parent);
  +    static IDOM_Element* getFirstChildElement(const IDOM_Node* const parent);
  +
       // Finds and returns the first child element node with the given name.
       static DOM_Element getFirstChildElement(const DOM_Node    &parent
   		                                  , const XMLCh* const elemName);
  @@ -126,6 +134,10 @@
                                               , const XMLCh** const elemNames
                                               , const XMLCh* const uriStr
                                               , unsigned int        length);
  +    static IDOM_Element* getFirstChildElementNS(const IDOM_Node* const parent
  +                                              , const XMLCh** const elemNames
  +                                              , const XMLCh* const uriStr
  +                                              , unsigned int       length);
   
       // Finds and returns the last child element node.
       static DOM_Element getLastChildElement(const DOM_Node &parent);
  @@ -145,6 +157,8 @@
   
       // Finds and returns the next sibling element node.
       static DOM_Element getNextSiblingElement(const DOM_Node &node);
  +    static IDOM_Element* getNextSiblingElement(const IDOM_Node* const node);
  +
       // Finds and returns the next sibling element node with the given name.
       static DOM_Element getNextSiblingElement(const DOM_Node    &node
   		                                   , const XMLCh* const elemName);
  @@ -165,6 +179,10 @@
                                                , const XMLCh** const elemNames
                                                , const XMLCh* const uriStr
                                                , unsigned int        length);
  +    static IDOM_Element* getNextSiblingElementNS(const IDOM_Node* const node
  +                                               , const XMLCh** const elemNames
  +                                               , const XMLCh* const uriStr
  +                                               , unsigned int        length);
   
   protected:
       // -----------------------------------------------------------------------
  
  
  
  1.2       +92 -0     xml-xerces/c/src/xercesc/validators/schema/XUtil.cpp
  
  Index: XUtil.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/XUtil.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XUtil.cpp	1 Feb 2002 22:22:50 -0000	1.1
  +++ XUtil.cpp	6 Feb 2002 22:21:49 -0000	1.2
  @@ -56,8 +56,11 @@
   
   /*
    * $Log: XUtil.cpp,v $
  - * Revision 1.1  2002/02/01 22:22:50  peiyongz
  - * Initial revision
  + * Revision 1.2  2002/02/06 22:21:49  knoaman
  + * Use IDOM for schema processing.
  + *
  + * Revision 1.1.1.1  2002/02/01 22:22:50  peiyongz
  + * sane_include
    *
    * Revision 1.6  2001/12/05 20:12:30  knoaman
    * Use getLocalName instead of getNodeName.
  @@ -90,6 +93,10 @@
   #include <xercesc/dom/ElementImpl.hpp>
   #include <xercesc/dom/DocumentImpl.hpp>
   #include <xercesc/util/IllegalArgumentException.hpp>
  +#include <xercesc/idom/IDOM_Element.hpp>
  +#include <xercesc/idom/IDOM_Document.hpp>
  +#include <xercesc/idom/IDOM_NamedNodeMap.hpp>
  +#include <xercesc/idom/IDOM_Node.hpp>
   
   void XUtil::copyInto(const DOM_Node &src, DOM_Node &dest)
   {
  @@ -238,6 +245,24 @@
       return DOM_Element();
   }
   
  +// Finds and returns the first child element node.
  +IDOM_Element* XUtil::getFirstChildElement(const IDOM_Node* const parent)
  +{
  +    // search for node
  +    IDOM_Node* child = parent->getFirstChild();
  +
  +    while (child != 0)
  +	{
  +        if (child->getNodeType() == IDOM_Node::ELEMENT_NODE)
  +            return (IDOM_Element*)child;
  +
  +        child = child->getNextSibling();
  +    }
  +
  +    // not found
  +    return 0;
  +}
  +
   // Finds and returns the first child node with the given name.
   DOM_Element XUtil::getFirstChildElement(const DOM_Node    &parent
                                         , const XMLCh* const elemName)
  @@ -333,6 +358,31 @@
       return DOM_Element();
   }
   
  +IDOM_Element* XUtil::getFirstChildElementNS(const IDOM_Node* const parent
  +                                          , const XMLCh** const elemNames
  +                                          , const XMLCh* const uriStr
  +                                          , unsigned int        length)
  +{
  +    // search for node
  +    IDOM_Node* child = parent->getFirstChild();
  +    while (child != 0)
  +	{
  +        if (child->getNodeType() == IDOM_Node::ELEMENT_NODE)
  +		{
  +            for (unsigned int i = 0; i < length; i++)
  +			{
  +                if (!XMLString::compareString(child->getNamespaceURI(), uriStr) &&
  +                    !XMLString::compareString(child->getLocalName(), elemNames[i]))
  +                    return (IDOM_Element*)child;
  +			}
  +		}
  +        child = child->getNextSibling();
  +    }
  +
  +    // not found
  +    return 0;
  +}
  +
   // Finds and returns the last child element node.
   DOM_Element XUtil::getLastChildElement(const DOM_Node &parent) {
   
  @@ -436,6 +486,23 @@
       return DOM_Element();
   }
   
  +IDOM_Element* XUtil::getNextSiblingElement(const IDOM_Node* const node)
  +{
  +    // search for node
  +    IDOM_Node* sibling = node->getNextSibling();
  +
  +    while (sibling != 0)
  +	{
  +        if (sibling->getNodeType() == IDOM_Node::ELEMENT_NODE)
  +            return (IDOM_Element*)sibling;
  +
  +        sibling = sibling->getNextSibling();
  +    }
  +
  +    // not found
  +    return 0;
  +}
  +
   // Finds and returns the next sibling element node with the give name.
   DOM_Element XUtil::getNextSiblingElement(const DOM_Node    &node
                                          , const XMLCh* const elemName)
  @@ -528,5 +595,30 @@
   
       // not found
       return DOM_Element();
  +}
  +
  +IDOM_Element* XUtil::getNextSiblingElementNS(const IDOM_Node* const node
  +                                           , const XMLCh** const elemNames
  +                                           , const XMLCh* const uriStr
  +									       , unsigned int        length)
  +{
  +    // search for node
  +    IDOM_Node* sibling = node->getNextSibling();
  +    while (sibling != 0)
  +	{
  +        if (sibling->getNodeType() == IDOM_Node::ELEMENT_NODE)
  +		{
  +            for (unsigned int i = 0; i < length; i++)
  +			{
  +                if (!XMLString::compareString(sibling->getNamespaceURI(), uriStr) &&
  +                    !XMLString::compareString(sibling->getLocalName(), elemNames[i]))
  +                    return (IDOM_Element*)sibling;
  +			}
  +		}
  +        sibling = sibling->getNextSibling();
  +    }
  +
  +    // not found
  +    return 0;
   }
   
  
  
  
  1.2       +3 -3      xml-xerces/c/src/xercesc/validators/schema/GeneralAttributeCheck.hpp
  
  Index: GeneralAttributeCheck.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/GeneralAttributeCheck.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GeneralAttributeCheck.hpp	1 Feb 2002 22:22:45 -0000	1.1
  +++ GeneralAttributeCheck.hpp	6 Feb 2002 22:21:49 -0000	1.2
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: GeneralAttributeCheck.hpp,v 1.1 2002/02/01 22:22:45 peiyongz Exp $
  + * $Id: GeneralAttributeCheck.hpp,v 1.2 2002/02/06 22:21:49 knoaman Exp $
    */
   
   #if !defined(GENERALATTRIBUTECHECK_HPP)
  @@ -73,13 +73,13 @@
   #include <xercesc/util/RefVectorOf.hpp>
   #include <xercesc/util/RefHashTableOf.hpp>
   #include <xercesc/util/RefHash2KeysTableOf.hpp>
  -#include <xercesc/dom/DOM_Element.hpp>
   #include <xercesc/validators/datatype/IDDatatypeValidator.hpp>
   
   // ---------------------------------------------------------------------------
   //  Forward declaration
   // ---------------------------------------------------------------------------
   class TraverseSchema;
  +class IDOM_Element;
   
   
   class AttributeInfo {
  @@ -145,7 +145,7 @@
       // -----------------------------------------------------------------------
       //  Validation methods
       // -----------------------------------------------------------------------
  -    void checkAttributes(const DOM_Element& elem,
  +    void checkAttributes(const IDOM_Element* const elem,
                            const unsigned short elemContext,
                            TraverseSchema* const schema);
   
  
  
  
  1.2       +31 -53    xml-xerces/c/src/xercesc/validators/schema/GeneralAttributeCheck.cpp
  
  Index: GeneralAttributeCheck.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/GeneralAttributeCheck.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GeneralAttributeCheck.cpp	1 Feb 2002 22:22:45 -0000	1.1
  +++ GeneralAttributeCheck.cpp	6 Feb 2002 22:21:49 -0000	1.2
  @@ -56,8 +56,11 @@
   
   /*
    * $Log: GeneralAttributeCheck.cpp,v $
  - * Revision 1.1  2002/02/01 22:22:45  peiyongz
  - * Initial revision
  + * Revision 1.2  2002/02/06 22:21:49  knoaman
  + * Use IDOM for schema processing.
  + *
  + * Revision 1.1.1.1  2002/02/01 22:22:45  peiyongz
  + * sane_include
    *
    * Revision 1.16  2002/01/02 19:50:34  knoaman
    * Fix for error message when checking for attributes with a namespace prefix.
  @@ -119,7 +122,7 @@
   #include <xercesc/util/XMLString.hpp>
   #include <xercesc/util/XMLUniDefs.hpp>
   #include <xercesc/util/Janitor.hpp>
  -#include <xercesc/dom/DOM_NamedNodeMap.hpp>
  +#include <xercesc/idom/IDOM_NamedNodeMap.hpp>
   #include <xercesc/framework/XMLErrorCodes.hpp>
   #include <xercesc/validators/schema/TraverseSchema.hpp>
   #include <xercesc/util/PlatformUtils.hpp>
  @@ -855,7 +858,7 @@
   //  GeneralAttributeCheck: Validation methods
   // ---------------------------------------------------------------------------
   void
  -GeneralAttributeCheck::checkAttributes(const DOM_Element& elem,
  +GeneralAttributeCheck::checkAttributes(const IDOM_Element* const elem,
                                          const unsigned short elemContext,
                                          TraverseSchema* const schema) {
   
  @@ -863,26 +866,16 @@
           return;
       }
   
  -    DOMString                   name = elem.getLocalName();
       int                         prefixContext = globalPrefix;
  -    unsigned int                nameLen = name.length();
  -    XMLCh*                      elemName = 0;
  +    const XMLCh*                elemName = elem->getLocalName();
       const XMLCh*                contextStr = fgGlobal;
       RefVectorOf<AttributeInfo>* elemAttrs = 0;
   
  -    if (nameLen) {
  -        elemName = new XMLCh[nameLen + 1];
  -        XMLString::copyNString(elemName, name.rawBuffer(), nameLen);
  -        elemName[nameLen] = chNull;
  -    }
  -
  -    ArrayJanitor<XMLCh> janName(elemName);
  -
       if (elemContext == LocalContext) {
   
           contextStr = fgLocal;
   
  -        if (elem.getAttribute(SchemaSymbols::fgATT_REF) == 0) {
  +        if (elem->getAttributeNode(SchemaSymbols::fgATT_REF) == 0) {
               prefixContext = localNamePrefix;
           }
           else {
  @@ -912,7 +905,6 @@
   
       unsigned int           size = elemAttrs->size();
       RefHashTableOf<XMLCh>  attNameList(5);
  -    XMLBuffer              aBuffer(128);
   
       for (unsigned int i=0; i< size; i++) {
   
  @@ -921,17 +913,14 @@
           if (attInfo) {
   
               XMLCh* attName = attInfo->getName();
  -            DOMString attValue = elem.getAttribute(attName);
  -            DOM_Attr attNode = elem.getAttributeNode(attName);
  -            unsigned int attValueLen = attValue.length();
  +            const XMLCh* attValue = elem->getAttribute(attName);
  +            IDOM_Attr* attNode = elem->getAttributeNode(attName);
  +            unsigned int attValueLen = XMLString::stringLen(attValue);
   
               attNameList.put((void*) attName, 0);
   
               if (attValueLen > 0) {
  -
  -                aBuffer.set(attValue.rawBuffer(), attValueLen);
  -                validate(attName, aBuffer.getRawBuffer(),
  -                         attInfo->getValidatorIndex(), schema);
  +                validate(attName, attValue, attInfo->getValidatorIndex(), schema);
               }
               else if (attNode == 0) {
                   if (attInfo->getDefaultOption() == Att_Required) {
  @@ -945,65 +934,56 @@
       // ------------------------------------------------------------------
       // Check for disallowed attributes
       // ------------------------------------------------------------------
  -    DOM_NamedNodeMap eltAttrs = elem.getAttributes();
  -    int attrCount = eltAttrs.getLength();
  +    IDOM_NamedNodeMap* eltAttrs = elem->getAttributes();
  +    int attrCount = eltAttrs->getLength();
   
       for (int j = 0; j < attrCount; j++) {
   
  -        DOM_Node  attribute = eltAttrs.item(j);
  +        IDOM_Node*  attribute = eltAttrs->item(j);
   
  -        if (attribute.isNull()) {
  +        if (!attribute) {
               break;
           }
   
           // Bypass attributes that start with xml
  -        DOMString attName = attribute.getNodeName();
  -        aBuffer.set(attName.rawBuffer(), attName.length());
  -        XMLCh* tmpName = aBuffer.getRawBuffer();
  -
  -        if ((*tmpName == chLatin_X || *tmpName == chLatin_x)
  -           && (*(tmpName+1) == chLatin_M || *(tmpName+1) == chLatin_m)
  -           && (*(tmpName+2) == chLatin_L || *(tmpName+2) == chLatin_l)) {
  +        const XMLCh* attName = attribute->getNodeName();
  +
  +        if ((*attName == chLatin_X || *attName == chLatin_x)
  +           && (*(attName+1) == chLatin_M || *(attName+1) == chLatin_m)
  +           && (*(attName+2) == chLatin_L || *(attName+2) == chLatin_l)) {
               continue;
           }
   
           // for attributes with namespace prefix
  -        DOMString attrURI = attribute.getNamespaceURI();
  +        const XMLCh* attrURI = attribute->getNamespaceURI();
   
  -        if (attrURI != 0 && attrURI.length() != 0) {
  +        if (attrURI != 0 && XMLString::stringLen(attrURI) != 0) {
   
               // attributes with schema namespace are not allowed
               // and not allowed on "documentation" and "appInfo"
  -            if (attrURI.equals(SchemaSymbols::fgURI_SCHEMAFORSCHEMA) ||
  +            if (!XMLString::compareString(attrURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA) ||
                   !XMLString::compareString(elemName, SchemaSymbols::fgELT_APPINFO) ||
                   !XMLString::compareString(elemName, SchemaSymbols::fgELT_DOCUMENTATION)) {
   
                   schema->reportSchemaError(XMLUni::fgXMLErrDomain,
  -                    XMLErrs::AttributeDisallowed, tmpName, contextStr, elemName);
  +                    XMLErrs::AttributeDisallowed, attName, contextStr, elemName);
               } else {
   
                   // Try for a "lax" validation
  -                XMLBuffer tmpBuf(128);
  -
  -                tmpBuf.set(attrURI.rawBuffer(), attrURI.length());
  -                attName = attribute.getLocalName();
  -                aBuffer.set(attName.rawBuffer(), attName.length());
  -                tmpName = aBuffer.getRawBuffer();
  -                DatatypeValidator* dv = schema->getDatatypeValidator(tmpBuf.getRawBuffer(), tmpName);
  +                DatatypeValidator* dv = schema->getDatatypeValidator(attrURI, attribute->getLocalName());
   
                   if (dv) {
   
  -                    DOMString attrVal = attribute.getNodeValue();
  -                    tmpBuf.set(attrVal.rawBuffer(), attrVal.length());
  +                    const XMLCh* attrVal = attribute->getNodeValue();
   
                       try {
  -                        dv->validate(tmpBuf.getRawBuffer());
  +                        dv->validate(attrVal);
                       }
                       catch(const XMLException& excep) {
                           schema->reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DisplayErrorMessage, excep.getMessage());
                       }
                       catch(...) {
  -                        schema->reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::InvalidAttValue, tmpBuf.getRawBuffer(), tmpName);
  +                        schema->reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::InvalidAttValue, attrVal, attName);
                       }
                   }
                   // REVISIT:
  @@ -1014,14 +994,12 @@
               continue;
           }
   
  -        attName = attribute.getLocalName();
  -        aBuffer.set(attName.rawBuffer(), attName.length());
  -        tmpName = aBuffer.getRawBuffer();
  +        attName = attribute->getLocalName();
   
           // check whether this attribute is allowed
  -        if (!attNameList.containsKey(tmpName)) {
  +        if (!attNameList.containsKey(attName)) {
               schema->reportSchemaError(XMLUni::fgXMLErrDomain,
  -                XMLErrs::AttributeDisallowed, tmpName, contextStr, elemName);
  +                XMLErrs::AttributeDisallowed, attName, contextStr, elemName);
           }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org