LCOV - code coverage report
Current view: top level - snapwebsites - qdomreceiver.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 54 0.0 %
Date: 2019-12-15 17:13:15 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Snap Websites Servers -- generate a DOM from the output of an XML Query
       2             : // Copyright (c) 2011-2019  Made to Order Software Corp.  All Rights Reserved
       3             : //
       4             : // This program is free software; you can redistribute it and/or modify
       5             : // it under the terms of the GNU General Public License as published by
       6             : // the Free Software Foundation; either version 2 of the License, or
       7             : // (at your option) any later version.
       8             : //
       9             : // This program is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             : // GNU General Public License for more details.
      13             : //
      14             : // You should have received a copy of the GNU General Public License
      15             : // along with this program; if not, write to the Free Software
      16             : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      17             : 
      18             : 
      19             : // self
      20             : //
      21             : #include "snapwebsites/qdomreceiver.h"
      22             : 
      23             : 
      24             : // last include
      25             : //
      26             : #include <snapdev/poison.h>
      27             : 
      28             : 
      29             : 
      30             : 
      31             : 
      32             : 
      33           0 : QDomReceiver::QDomReceiver(QXmlNamePool namepool, QDomDocument doc)
      34             :     : f_namepool(namepool)
      35           0 :     , f_doc(doc)
      36             : {
      37           0 :     f_element = doc.documentElement();
      38           0 : }
      39             : 
      40           0 : QDomReceiver::~QDomReceiver()
      41             : {
      42           0 : }
      43             : 
      44           0 : void QDomReceiver::atomicValue(const QVariant& )
      45             : {
      46           0 : }
      47             : 
      48           0 : void QDomReceiver::attribute(const QXmlName& name, const QStringRef& value)
      49             : {
      50           0 :     if(name.prefix(f_namepool).isEmpty())
      51             :     {
      52           0 :         f_element.setAttribute(name.localName(f_namepool), value.toString());
      53             :     }
      54             :     else
      55             :     {
      56           0 :         f_element.setAttributeNS(name.prefix(f_namepool), name.localName(f_namepool), value.toString());
      57             :     }
      58           0 : }
      59             : 
      60           0 : void QDomReceiver::characters(const QStringRef& value)
      61             : {
      62           0 :     f_element.appendChild(f_doc.createTextNode(value.toString()));
      63           0 : }
      64             : 
      65           0 : void QDomReceiver::comment(const QString& value)
      66             : {
      67           0 :     f_element.appendChild(f_doc.createComment(value));
      68           0 : }
      69             : 
      70           0 : void QDomReceiver::endDocument()
      71             : {
      72             :     // we're done
      73           0 : }
      74             : 
      75           0 : void QDomReceiver::endElement()
      76             : {
      77             :     // elements are automatically closed, but we want to move up in the tree
      78           0 :     f_element = f_element.parentNode().toElement();
      79           0 : }
      80             : 
      81           0 : void QDomReceiver::endOfSequence()
      82             : {
      83             :     // nothing to do here
      84           0 : }
      85             : 
      86           0 : void QDomReceiver::namespaceBinding(const QXmlName& name)
      87             : {
      88           0 :     QString uri(name.namespaceUri(f_namepool));
      89           0 :     if(!uri.isEmpty())
      90             :     {
      91             :         // prefix is saved as a suffix in an attribute name
      92           0 :         QString prefix(name.prefix(f_namepool));
      93           0 :         if(!prefix.isEmpty())
      94             :         {
      95           0 :             prefix = ":" + prefix;
      96             :         }
      97           0 :         f_element.setAttribute("xmlns" + prefix, uri);
      98             :     }
      99           0 : }
     100             : 
     101           0 : void QDomReceiver::processingInstruction(const QXmlName& target, const QString& value )
     102             : {
     103             :     // prefix is saved as a suffix in a processing instruction
     104           0 :     QString prefix(target.prefix(f_namepool));
     105           0 :     if(!prefix.isEmpty())
     106             :     {
     107           0 :         prefix = ":" + prefix;
     108             :     }
     109           0 :     f_element.appendChild(f_doc.createProcessingInstruction(target.localName(f_namepool) + prefix, value));
     110           0 : }
     111             : 
     112           0 : void QDomReceiver::startDocument()
     113             : {
     114             :     // should we create docs here?
     115           0 : }
     116             : 
     117           0 : void QDomReceiver::startElement(const QXmlName& name)
     118             : {
     119           0 :     QString prefix(name.prefix(f_namepool));
     120           0 :     if(!prefix.isEmpty())
     121             :     {
     122           0 :         prefix += ":";
     123             :     }
     124           0 :     QDomElement element(f_doc.createElement(prefix + name.localName(f_namepool)));
     125           0 :     if(f_element.isNull())
     126             :     {
     127           0 :         f_doc.appendChild(element);
     128             :     }
     129             :     else
     130             :     {
     131           0 :         f_element.appendChild(element);
     132             :     }
     133           0 :     f_element = element;
     134           0 : }
     135             : 
     136           0 : void QDomReceiver::startOfSequence()
     137             : {
     138             :     // nothing to do here
     139           0 : }
     140             : 
     141             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13