gloox  1.0.16
xhtmlim.cpp
1 /*
2  Copyright (c) 2007-2015 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #include "xhtmlim.h"
15 
16 #include "tag.h"
17 
18 namespace gloox
19 {
20 
21  XHtmlIM::XHtmlIM( const Tag* xhtml )
22  : StanzaExtension( ExtXHtmlIM ), m_xhtml( 0 )
23  {
24  if( !xhtml|| xhtml->name() != "html" || xhtml->xmlns() != XMLNS_XHTML_IM )
25  return;
26 
27  if( !xhtml->hasChild( "body", XMLNS, "http://www.w3.org/1999/xhtml" ) )
28  return;
29 
30  m_xhtml = xhtml->clone();
31  }
32 
34  {
35  delete m_xhtml;
36  }
37 
38  const std::string& XHtmlIM::filterString() const
39  {
40  static const std::string filter = "/message/html[@xmlns='" + XMLNS_XHTML_IM + "']";
41  return filter;
42  }
43 
44  Tag* XHtmlIM::tag() const
45  {
46  return m_xhtml->clone();
47  }
48 
50  {
51  XHtmlIM* x = new XHtmlIM();
52  x->m_xhtml = m_xhtml ? m_xhtml->clone() : 0;
53  return x;
54  }
55 
56 }
const std::string XMLNS
Definition: gloox.cpp:121
virtual StanzaExtension * clone() const
Definition: xhtmlim.cpp:49
XHtmlIM(const Tag *xhtml=0)
Definition: xhtmlim.cpp:21
virtual ~XHtmlIM()
Definition: xhtmlim.cpp:33
The namespace for the gloox library.
Definition: adhoc.cpp:27
This is a wrapper of an XHTML-IM (XEP-0071) message body.
Definition: xhtmlim.h:34
This class abstracts a stanza extension, which is usually an element in a specific namespace...
const std::string & xmlns() const
Definition: tag.cpp:542
virtual const std::string & filterString() const
Definition: xhtmlim.cpp:38
Tag * clone() const
Definition: tag.cpp:669
bool hasChild(const std::string &name, const std::string &attr=EmptyString, const std::string &value=EmptyString) const
Definition: tag.cpp:614
virtual Tag * tag() const
Definition: xhtmlim.cpp:44
const std::string & name() const
Definition: tag.h:394
const std::string XMLNS_XHTML_IM
Definition: gloox.cpp:36
This is an abstraction of an XML element.
Definition: tag.h:46