dbertoni    01/05/02 08:39:30

  Modified:    c/src/DOMSupport DOMServices.cpp DOMServices.hpp
  Log:
  New getNodeData() functions.
  
  Revision  Changes    Path
  1.26      +241 -30   xml-xalan/c/src/DOMSupport/DOMServices.cpp
  
  Index: DOMServices.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/DOMServices.cpp,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- DOMServices.cpp   2001/02/11 04:37:09     1.25
  +++ DOMServices.cpp   2001/05/02 15:39:22     1.26
  @@ -337,30 +337,65 @@
   
   
   
  -void
  -DOMServices::getNodeData(
  -                     const XalanDocument&    document,
  -                     XalanDOMString&                 data)
  +inline void
  +getChildData(
  +                     const XalanNode*        child,
  +                     XalanDOMString&         data)
   {
  -     const XalanNode*        child = document.getFirstChild();
  +     const XalanNode::NodeType       theType = child->getNodeType();
   
  -     while(child != 0)
  +     if (theType == XalanNode::ELEMENT_NODE)
        {
  -             const XalanNode::NodeType       theType = child->getNodeType();
  +             const XalanElement*     const   theElementNode =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +                             (const XalanElement*)child;
  +#else
  +                             static_cast<const XalanElement*>(child);
  +#endif
   
  -             if (theType == XalanNode::ELEMENT_NODE ||
  -                     theType == XalanNode::TEXT_NODE ||
  -                     theType == XalanNode::CDATA_SECTION_NODE)
  -             {
  -                     getNodeData(*child, data);
  -             }
  +             DOMServices::getNodeData(*theElementNode, data);
  +     }
  +     else if (theType == XalanNode::TEXT_NODE ||
  +                      theType == XalanNode::CDATA_SECTION_NODE)
  +     {
  +             const XalanText*        theTextNode =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +                             (const XalanText*)child;
  +#else
  +                             static_cast<const XalanText*>(child);
  +#endif
   
  -             child = child->getNextSibling();
  +             DOMServices::getNodeData(*theTextNode, data);
        }
   }
   
   
   
  +inline void
  +getChildrenData(
  +                     const XalanNode*        firstChild,
  +                     XalanDOMString&         data)
  +{
  +     while(firstChild != 0)
  +     {
  +             getChildData(firstChild, data);
  +
  +             firstChild = firstChild->getNextSibling();
  +     }
  +}
  +
  +
  +
  +void
  +DOMServices::getNodeData(
  +                     const XalanDocument&    document,
  +                     XalanDOMString&                 data)
  +{
  +     getChildrenData(document.getFirstChild(), data);
  +}
  +
  +
  +
   XalanDOMString
   DOMServices::getNodeData(const XalanDocumentFragment&        
documentFragment)
   {
  @@ -387,15 +422,8 @@
        {
                const XalanNode* const          child = nl->item(i);
                assert(child != 0);
  -
  -             const XalanNode::NodeType       theType = child->getNodeType();
   
  -             if (theType == XalanNode::ELEMENT_NODE ||
  -                     theType == XalanNode::TEXT_NODE ||
  -                     theType == XalanNode::CDATA_SECTION_NODE)
  -             {
  -                     getNodeData(*child, data);
  -             }
  +             getChildData(child, data);
        }
   }
   
  @@ -418,21 +446,204 @@
                        const XalanElement&             element,
                        XalanDOMString&                 data)
   {
  -     const XalanNode*        child = element.getFirstChild();
  +     getChildrenData(element.getFirstChild(), data);
  +}
  +
  +
   
  -     while(child != 0)
  +void
  +DOMServices::getNodeData(
  +                     const XalanNode&        node,
  +                     FormatterListener&      formatterListener,
  +                     MemberFunctionPtr       function)
  +{
  +     switch(node.getNodeType())
        {
  -             const XalanNode::NodeType       theType = child->getNodeType();
  +     case XalanNode::DOCUMENT_FRAGMENT_NODE:
  +             {
  +                     const XalanDocumentFragment&            
theDocumentFragment =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +                             (const XalanDocumentFragment&)node;
  +#else
  +                             static_cast<const XalanDocumentFragment&>(node);
  +#endif
  +                     getNodeData(theDocumentFragment, formatterListener, 
function);
  +             }
  +             break;
   
  -             if (theType == XalanNode::ELEMENT_NODE ||
  -                     theType == XalanNode::TEXT_NODE ||
  -                     theType == XalanNode::CDATA_SECTION_NODE)
  +     case XalanNode::DOCUMENT_NODE:
                {
  -                     getNodeData(*child, data);
  +                     const XalanDocument&    theDocument =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +                             (const XalanDocument&)node;
  +#else
  +                             static_cast<const XalanDocument&>(node);
  +#endif
  +                     getNodeData(theDocument, formatterListener, function);
                }
  +             break;
  +
  +     case XalanNode::ELEMENT_NODE:
  +             {
  +                     const XalanElement&             theElement =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +                             (const XalanElement&)node;
  +#else
  +                             static_cast<const XalanElement&>(node);
  +#endif
  +                     getNodeData(theElement, formatterListener, function);
  +             }
  +             break;
  +
  +     case XalanNode::TEXT_NODE:
  +     case XalanNode::CDATA_SECTION_NODE:
  +             {
  +                     const XalanText&        theTextNode =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +                             (const XalanText&)node;
  +#else
  +                             static_cast<const XalanText&>(node);
  +#endif
   
  -             child = child->getNextSibling();
  +                             getNodeData(theTextNode, formatterListener, 
function);
  +             }
  +             break;
  +
  +     case XalanNode::ATTRIBUTE_NODE:
  +             {
  +                     const XalanAttr&                theAttr =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +                             (const XalanAttr&)node;
  +#else
  +                             static_cast<const XalanAttr&>(node);
  +#endif
  +                     getNodeData(theAttr, formatterListener, function);
  +             }
  +             break;
  +
  +     case XalanNode::COMMENT_NODE:
  +             {
  +                     const XalanComment&             theComment =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +                             (const XalanComment&)node;
  +#else
  +                             static_cast<const XalanComment&>(node);
  +#endif
  +                     getNodeData(theComment, formatterListener, function);
  +             }
  +             break;
  +
  +     case XalanNode::PROCESSING_INSTRUCTION_NODE:
  +             {
  +                     const XalanProcessingInstruction&               thePI =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +                             (const XalanProcessingInstruction&)node;
  +#else
  +                             static_cast<const 
XalanProcessingInstruction&>(node);
  +#endif
  +                     getNodeData(thePI, formatterListener, function);
  +             }
  +             break;
  +
  +     default:
  +             // ignore
  +             break;
        }
  +}
  +
  +
  +
  +inline void
  +getChildData(
  +                     const XalanNode*                                child,
  +                     FormatterListener&                              
formatterListener,
  +                     DOMServices::MemberFunctionPtr  function)
  +{
  +     const XalanNode::NodeType       theType = child->getNodeType();
  +
  +     if (theType == XalanNode::ELEMENT_NODE)
  +     {
  +             const XalanElement*     const   theElementNode =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +                             (const XalanElement*)child;
  +#else
  +                             static_cast<const XalanElement*>(child);
  +#endif
  +
  +             DOMServices::getNodeData(*theElementNode, formatterListener, 
function);
  +     }
  +     else if (theType == XalanNode::TEXT_NODE ||
  +                      theType == XalanNode::CDATA_SECTION_NODE)
  +     {
  +             const XalanText*        theTextNode =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +                             (const XalanText*)child;
  +#else
  +                             static_cast<const XalanText*>(child);
  +#endif
  +
  +             DOMServices::getNodeData(*theTextNode, formatterListener, 
function);
  +     }
  +}
  +
  +
  +
  +inline void
  +getChildrenData(
  +                     const XalanNode*                                
firstChild,
  +                     FormatterListener&                              
formatterListener,
  +                     DOMServices::MemberFunctionPtr  function)
  +{
  +     while(firstChild != 0)
  +     {
  +             getChildData(firstChild, formatterListener, function);
  +
  +             firstChild = firstChild->getNextSibling();
  +     }
  +}
  +
  +
  +
  +void
  +DOMServices::getNodeData(
  +                     const XalanDocument&    document,
  +                     FormatterListener&              formatterListener,
  +                     MemberFunctionPtr               function)
  +{
  +     getChildrenData(document.getFirstChild(), formatterListener, function);
  +}
  +
  +
  +
  +void
  +DOMServices::getNodeData(
  +                     const XalanDocumentFragment&    documentFragment,
  +                     FormatterListener&                              
formatterListener,
  +                     MemberFunctionPtr                               
function)
  +{
  +     const XalanNodeList* const      nl = documentFragment.getChildNodes();
  +     assert(nl != 0);
  +
  +     const unsigned int      n = nl->getLength();
  +
  +     for(unsigned int i = 0; i < n; ++i)
  +     {
  +             const XalanNode* const          child = nl->item(i);
  +             assert(child != 0);
  +
  +             getChildData(child, formatterListener, function);
  +     }
  +}
  +
  +
  +
  +void
  +DOMServices::getNodeData(
  +                     const XalanElement&             element,
  +                     FormatterListener&              formatterListener,
  +                     MemberFunctionPtr               function)
  +{
  +     getChildrenData(element.getFirstChild(), formatterListener, function);
   }
   
   
  
  
  
  1.20      +136 -2    xml-xalan/c/src/DOMSupport/DOMServices.hpp
  
  Index: DOMServices.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/DOMServices.hpp,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DOMServices.hpp   2001/02/11 04:37:09     1.19
  +++ DOMServices.hpp   2001/05/02 15:39:25     1.20
  @@ -75,6 +75,7 @@
   
   
   #include <PlatformSupport/DOMStringHelper.hpp>
  +#include <PlatformSupport/FormatterListener.hpp>
   
   
   
  @@ -209,7 +210,7 @@
        /**
         * Retrieves data for node
         * 
  -      * @param attribute DOM node whose data is to be returned
  +      * @param comment DOM node whose data is to be returned
         * @return a string representation of the node's data
         */
        static XalanDOMString
  @@ -221,7 +222,7 @@
        /**
         * Retrieves data for node
         * 
  -      * @param attribute DOM node whose data is to be returned
  +      * @param comment DOM node whose data is to be returned
         * @param data a string to which the node's data will be appended
         */
        static void
  @@ -344,7 +345,125 @@
                append(data, text.getData());
        }
   
  +     typedef void (FormatterListener::*MemberFunctionPtr)(const XMLCh* 
const, const unsigned int);
  +
  +     /**
  +      * Sends the data for a node to a FormatterListener
  +      * 
  +      * @param node DOM node whose data is to be returned
  +      * @param formatterListener the FormatterListener instance to receive 
the data
  +      * @param function A pointer to the member function of 
FormatterListener to call
  +      */
  +     static void
  +     getNodeData(
  +                     const XalanNode&        node,
  +                     FormatterListener&      formatterListener,
  +                     MemberFunctionPtr       function);
  +
  +     /**
  +      * Sends the data for a node to a FormatterListener
  +      * 
  +      * @param attribute DOM node whose data is to be returned
  +      * @param formatterListener the FormatterListener instance to receive 
the data
  +      * @param fRaw Whether or not the data should be sent raw.
  +      */
  +     static void
  +     getNodeData(
  +                     const XalanAttr&        attribute,
  +                     FormatterListener&      formatterListener,
  +                     MemberFunctionPtr       function)
  +     {
  +             sendData(formatterListener, function, attribute.getNodeValue());
  +     }
  +
  +     /**
  +      * Sends the data for a node to a FormatterListener
  +      * 
  +      * @param comment DOM node whose data is to be returned
  +      * @param formatterListener the FormatterListener instance to receive 
the data
  +      * @param fRaw Whether or not the data should be sent raw.
  +      */
  +     static void
  +     getNodeData(
  +                     const XalanComment&             comment,
  +                     FormatterListener&              formatterListener,
  +                     MemberFunctionPtr               function)
  +     {
  +             sendData(formatterListener, function, comment.getData());
  +     }
  +
        /**
  +      * Sends the data for a node to a FormatterListener
  +      * 
  +      * @param document DOM node whose data is to be returned
  +      * @param formatterListener the FormatterListener instance to receive 
the data
  +      * @param fRaw Whether or not the data should be sent raw.
  +      */
  +     static void
  +     getNodeData(
  +                     const XalanDocument&    document,
  +                     FormatterListener&              formatterListener,
  +                     MemberFunctionPtr               function);
  +
  +     /**
  +      * Sends the data for a node to a FormatterListener
  +      * 
  +      * @param documentFragment DOM node whose data is to be sent
  +      * @param formatterListener the FormatterListener instance to receive 
the data
  +      * @param fRaw Whether or not the data should be sent raw.
  +      */
  +     static void
  +     getNodeData(
  +                     const XalanDocumentFragment&    documentFragment,
  +                     FormatterListener&                              
formatterListener,
  +                     MemberFunctionPtr                               
function);
  +
  +     /**
  +      * Sends the data for a node to a FormatterListener
  +      * 
  +      * @param element DOM node whose data is to be returned
  +      * @param formatterListener the FormatterListener instance to receive 
the data
  +      * @param fRaw Whether or not the data should be sent raw.
  +      */
  +     static void
  +     getNodeData(
  +                     const XalanElement&             element,
  +                     FormatterListener&              formatterListener,
  +                     MemberFunctionPtr               function);
  +
  +     /**
  +      * Sends the data for a node to a FormatterListener
  +      * 
  +      * @param pi DOM node whose data is to be returned
  +      * @param formatterListener the FormatterListener instance to receive 
the data
  +      * @param fRaw Whether or not the data should be sent raw.
  +      */
  +     static void
  +     getNodeData(
  +                     const XalanProcessingInstruction&       pi,
  +                     FormatterListener&                                      
formatterListener,
  +                     MemberFunctionPtr                                       
function)
  +     {
  +             sendData(formatterListener, function, pi.getData());
  +     }
  +
  +     /**
  +      * Sends the data for a node to a FormatterListener
  +      * 
  +      * @param node DOM node whose data is to be returned
  +      * @param formatterListener the FormatterListener instance to receive 
the data
  +      * @param fRaw Whether or not the data should be sent raw.
  +      */
  +     static void
  +     getNodeData(
  +                     const XalanText&        text,
  +                     FormatterListener&      formatterListener,
  +                     MemberFunctionPtr       function)
  +     {
  +             sendData(formatterListener, function, text.getData());
  +     }
  +
  +     /**
         * Retrieve the name of the node, taking into
         * account the differences between the DOM and
         * XSLT data models.
  @@ -492,6 +611,21 @@
                        const XalanNode&        attr,
                        XalanNode&                      element);
   
  +     /**
  +      * Utility function to send data to a FormatterListener
  +      *
  +      * @param formatterListener The FormatterListener instance.
  +      * @param fRaw Whether or not the data should be sent raw.
  +      * @param data The data to send.
  +      */
  +     static void
  +     sendData(
  +                     FormatterListener&              formatterListener,
  +                     MemberFunctionPtr               function,
  +                     const XalanDOMString&   data)
  +     {
  +             (formatterListener.*function)(c_wstr(data), length(data));
  +     }
   };
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to