10 #include <xercesc/framework/StdOutFormatTarget.hpp>
11 #include <xercesc/framework/LocalFileFormatTarget.hpp>
12 #include <xercesc/framework/MemBufFormatTarget.hpp>
15 using namespace xercesc;
23 inline XMLCh* xs_(
const std::string& str )
27 return xercesc::XMLString::transcode(str.c_str());
30 inline XMLCh* xs_(
const char* str)
32 return xercesc::XMLString::transcode(str);
37 XHTMLMaker::XHTMLMaker()
39 XMLCh* xls = xs_(
"ls");
40 DOMImplementation* imp =
41 DOMImplementationRegistry::getDOMImplementation(xls);
43 XMLCh* xhtml_s =xs_(
"html") ;
44 XMLCh* p_id = xs_(
"-//W3C//DTD XHTML 1.0 Strict//EN" );
45 XMLCh*
s_id = xs_(
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" );
47 typ_ = imp->createDocumentType( xhtml_s, p_id, s_id );
49 XMLCh* ns_uri = xs_(
"http://www.w3.org/1999/xhtml" );
51 doc_ = imp->createDocument( ns_uri, xhtml_s, typ_ );
56 std::cerr <<
"Cannot create document" << std::endl;
60 XMLCh* encoding = xs_(
"utf-8");
61 doc_->setEncoding(encoding);
64 doc_->setVersion(version);
69 ( (DOMImplementationLS*)imp )->createDOMWriter();
81 std::cerr <<
"Cannot create DOM writer" << std::endl;
90 XHTMLMaker::~XHTMLMaker()
106 std::cerr <<
"Page already started" << std::endl;
113 Node* el_xhtml = doc_->getDocumentElement();
116 XMLCh*
h = xs_(
"head");
117 head_ = doc_->createElement(h);
119 el_xhtml->appendChild( head_ );
123 XMLCh* xtitle = xs_(
"title");
124 Node* el_title = doc_->createElement(xtitle);
126 head_->appendChild( el_title );
128 DOMText* txt_title = doc_->createTextNode(xtitle);
130 el_title->appendChild( txt_title );
133 XMLCh* xbody = xs_(
"body");
134 Node* el_body = doc_->createElement(xbody);
136 el_xhtml->appendChild( el_body );
150 XMLCh* xname = xs_(name);
151 Node* el = doc_->createElement(xname);
153 parent->appendChild( el );
155 for( AttrMap::const_iterator
i = attrs.begin();
i != attrs.end();
158 XMLCh* xfirst = xs_(
i->first);
159 XMLCh* xsecond = xs_(
i->second);
160 el->setAttribute(xfirst, xsecond);
175 XMLCh* xdata = xs_(data);
176 DOMText* txt = doc_->createTextNode(xdata);
178 parent->appendChild( txt );
186 ostringstream tmpString;
188 addText( parent, tmpString.str() );
196 ostringstream tmpString;
198 addText( parent, tmpString.str() );
206 ostringstream tmpString;
208 addText( parent, tmpString.str() );
216 ostringstream tmpString;
218 addText( parent, tmpString.str() );
226 ostringstream tmpString;
228 addText( parent, tmpString.str() );
236 ostringstream tmpString;
238 addText( parent, tmpString.str() );
246 ostringstream tmpString;
247 tmpString <<
"0x" << std::hex <<
value;
248 addText( parent, tmpString.str() );
254 void XHTMLMaker::addDouble(
Node*
parent,
const double&
value,
const unsigned int& precision )
256 ostringstream tmpString;
257 tmpString << fixed << std::setprecision( precision ) <<
value;
258 addText( parent, tmpString.str() );
266 addText( parent, value ?
"True" :
"False" );
273 void XHTMLMaker::setWriterFeatures_()
278 if( writer_->canSetFeature( XMLUni::fgDOMWRTSplitCdataSections,
true ) )
280 writer_->setFeature( XMLUni::fgDOMWRTSplitCdataSections,
true );
283 if( writer_->canSetFeature( XMLUni::fgDOMWRTDiscardDefaultContent,
true ) )
285 writer_->setFeature( XMLUni::fgDOMWRTDiscardDefaultContent,
true );
288 if( writer_->canSetFeature( XMLUni::fgDOMWRTFormatPrettyPrint,
true ) )
290 writer_->setFeature( XMLUni::fgDOMWRTFormatPrettyPrint,
true );
293 if( writer_->canSetFeature( XMLUni::fgDOMWRTBOM,
true ) )
295 writer_->setFeature( XMLUni::fgDOMWRTBOM,
true );
305 setWriterFeatures_();
306 XMLFormatTarget* ftar =
new StdOutFormatTarget();
308 writer_->writeNode( ftar, *doc_ );
317 setWriterFeatures_();
318 XMLCh* xfilename = xs_(filename);
319 XMLFormatTarget* ftar =
new LocalFileFormatTarget(xfilename);
320 writer_->writeNode( ftar, *doc_ );
330 std::ostringstream stream;
340 setWriterFeatures_();
341 MemBufFormatTarget* ftar =
new MemBufFormatTarget();
342 writer_->writeNode( ftar, *doc_ );
343 dest << ftar->getRawBuffer();
std::map< std::string, std::string > AttrMap
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
char data[epos_bytes_allocation]