CMS 3D CMS Logo

Public Types | Public Member Functions | Private Member Functions | Private Attributes

stor::XHTMLMaker Class Reference

#include <XHTMLMaker.h>

List of all members.

Public Types

typedef std::map< std::string,
std::string > 
AttrMap
typedef xercesc::DOMElement Node

Public Member Functions

void addBool (Node *parent, const bool &)
void addDouble (Node *parent, const double &value, const unsigned int &precision=2)
void addHex (Node *parent, const unsigned long &)
void addInt (Node *parent, const unsigned int &)
void addInt (Node *parent, const int &)
void addInt (Node *parent, const long &)
void addInt (Node *parent, const unsigned long &)
void addInt (Node *parent, const long long &)
void addInt (Node *parent, const unsigned long long &)
NodeaddNode (const std::string &name, Node *parent, const AttrMap &attrs)
NodeaddNode (const std::string &name)
NodeaddNode (const std::string &name, const AttrMap &attrs)
NodeaddNode (const std::string &name, Node *parent)
void addText (Node *parent, const std::string &)
NodegetHead () const
void out (std::ostream &dest)
void out (const std::string &dest)
void out (std::string &dest)
void out ()
Nodestart (const std::string &title)
 XHTMLMaker ()
 ~XHTMLMaker ()

Private Member Functions

void setWriterFeatures_ ()

Private Attributes

xercesc::DOMDocument * doc_
Nodehead_
bool pageStarted_
xercesc::DOMDocumentType * typ_
xercesc::DOMWriter * writer_

Detailed Description

Helper class to build XHTML pages

Author:
mommsen
Revision:
1.12
Date:
2011/07/07 09:22:44

Definition at line 27 of file XHTMLMaker.h.


Member Typedef Documentation

typedef std::map<std::string,std::string> stor::XHTMLMaker::AttrMap

Definition at line 36 of file XHTMLMaker.h.

typedef xercesc::DOMElement stor::XHTMLMaker::Node

Typedefs

Definition at line 35 of file XHTMLMaker.h.


Constructor & Destructor Documentation

XHTMLMaker::XHTMLMaker ( )

Constructor

Definition at line 37 of file XHTMLMaker.cc.

References dtNoiseDBValidation_cfg::cerr, fetchall_from_DQM_v2::release, s_id, and BeamSplash_cfg::version.

{
  XMLCh* xls = xs_("ls");
  DOMImplementation* imp =
    DOMImplementationRegistry::getDOMImplementation(xls);

  XMLCh* xhtml_s =xs_("html") ;
  XMLCh* p_id = xs_( "-//W3C//DTD XHTML 1.0 Strict//EN" );
  XMLCh* s_id = xs_( "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" );

  typ_ = imp->createDocumentType( xhtml_s, p_id, s_id );

  XMLCh* ns_uri = xs_( "http://www.w3.org/1999/xhtml" );

  doc_ = imp->createDocument( ns_uri, xhtml_s, typ_ );


  if( !doc_ )
    {
      std::cerr << "Cannot create document" << std::endl;
      return;
    }

  XMLCh* encoding = xs_("utf-8");
  doc_->setEncoding(encoding);
  //doc_->setStandalone( true );
  XMLCh* version = xs_("1.0");
  doc_->setVersion(version);

  pageStarted_ = false;

  writer_ =
    ( (DOMImplementationLS*)imp )->createDOMWriter();

  XMLString::release(&xls);
  XMLString::release(&xhtml_s);
  XMLString::release(&p_id);
  XMLString::release(&s_id);
  XMLString::release(&ns_uri);
  XMLString::release(&encoding);
  XMLString::release(&version);

  if( !writer_ )
    {
      std::cerr << "Cannot create DOM writer" << std::endl;
      return;
    }
}
XHTMLMaker::~XHTMLMaker ( )

Destructor

Definition at line 90 of file XHTMLMaker.cc.

{
  delete doc_;
  delete writer_;
  delete typ_;
}

Member Function Documentation

void XHTMLMaker::addBool ( Node parent,
const bool &  value 
)

Add a boolean

Definition at line 264 of file XHTMLMaker.cc.

{
    addText( parent, value ? "True" : "False" );
}
void XHTMLMaker::addDouble ( Node parent,
const double &  value,
const unsigned int &  precision = 2 
)
void XHTMLMaker::addHex ( Node parent,
const unsigned long &  value 
)

Add an unsigned long in hex format

Definition at line 244 of file XHTMLMaker.cc.

References relativeConstraints::value.

Referenced by stor::SMWebPageHelper::addDOMforFiles().

{
    ostringstream tmpString;
    tmpString << "0x" << std::hex << value;
    addText( parent, tmpString.str() );
}
void XHTMLMaker::addInt ( Node parent,
const unsigned int &  value 
)

Add an unsigned int

Definition at line 194 of file XHTMLMaker.cc.

References relativeConstraints::value.

{
    ostringstream tmpString;
    tmpString << value;
    addText( parent, tmpString.str() );
}
void XHTMLMaker::addInt ( Node parent,
const long &  value 
)

Add a long

Definition at line 204 of file XHTMLMaker.cc.

References relativeConstraints::value.

{
    ostringstream tmpString;
    tmpString << value;
    addText( parent, tmpString.str() );
}
void XHTMLMaker::addInt ( Node parent,
const unsigned long &  value 
)

Add an unsigned long

Definition at line 214 of file XHTMLMaker.cc.

References relativeConstraints::value.

{
    ostringstream tmpString;
    tmpString << value;
    addText( parent, tmpString.str() );
}
void XHTMLMaker::addInt ( Node parent,
const unsigned long long &  value 
)

Add an unsigned long long

Definition at line 234 of file XHTMLMaker.cc.

References relativeConstraints::value.

{
    ostringstream tmpString;
    tmpString << value;
    addText( parent, tmpString.str() );
}
void XHTMLMaker::addInt ( Node parent,
const int &  value 
)
void XHTMLMaker::addInt ( Node parent,
const long long &  value 
)

Add a long long

Definition at line 224 of file XHTMLMaker.cc.

References relativeConstraints::value.

{
    ostringstream tmpString;
    tmpString << value;
    addText( parent, tmpString.str() );
}
XHTMLMaker::Node * XHTMLMaker::addNode ( const std::string &  name,
XHTMLMaker::Node parent,
const AttrMap attrs 
)

Add child

Definition at line 146 of file XHTMLMaker.cc.

References i, and fetchall_from_DQM_v2::release.

Referenced by stor::SMWebPageHelper::addDOMforConfigString(), smproxy::SMPSWebPageHelper::addDOMforConnectionInfo(), smproxy::SMPSWebPageHelper::addDOMforEventServers(), stor::SMWebPageHelper::addDOMforFiles(), stor::SMWebPageHelper::addDOMforFragmentMonitor(), smproxy::SMPSWebPageHelper::addDOMforHyperLinks(), stor::SMWebPageHelper::addDOMforHyperLinks(), stor::SMWebPageHelper::addDOMforResourceUsage(), stor::SMWebPageHelper::addDOMforRunMonitor(), smproxy::SMPSWebPageHelper::addDOMforSMhost(), stor::SMWebPageHelper::addDOMforStoredData(), stor::SMWebPageHelper::addDOMforSummaryInformation(), smproxy::SMPSWebPageHelper::addDOMforThroughputPerEventType(), stor::SMWebPageHelper::addDOMforThroughputStatistics(), stor::SMWebPageHelper::addFilterUnitList(), stor::SMWebPageHelper::addFragmentStats(), addNode(), stor::SMWebPageHelper::addOutputModuleStatistics(), stor::SMWebPageHelper::addOutputModuleSummary(), stor::SMWebPageHelper::addResourceBrokerDetails(), stor::SMWebPageHelper::addResourceBrokerList(), stor::SMWebPageHelper::addRowForBandwidth(), smproxy::SMPSWebPageHelper::addRowForEventServer(), smproxy::SMPSWebPageHelper::addRowForEventType(), stor::SMWebPageHelper::addRowForFramesReceived(), stor::SMWebPageHelper::addRowForLatency(), stor::SMWebPageHelper::addRowForMaxBandwidth(), stor::SMWebPageHelper::addRowForMinBandwidth(), stor::SMWebPageHelper::addRowForRate(), stor::SMWebPageHelper::addRowForThroughputStatistics(), stor::SMWebPageHelper::addRowForTotalVolume(), stor::SMWebPageHelper::addRowsForSataBeast(), stor::SMWebPageHelper::addRowsForThroughputUsage(), stor::SMWebPageHelper::addRowsForWorkers(), smproxy::SMPSWebPageHelper::addSummaryRowForEventServer(), smproxy::SMPSWebPageHelper::addSummaryRowForThroughput(), stor::SMWebPageHelper::addTableForDiskUsages(), stor::SMWebPageHelper::addTableForResourceUsages(), smproxy::SMPSWebPageHelper::dataRetrieverWebPage(), smproxy::SMPSWebPageHelper::defaultWebPage(), stor::SMWebPageHelper::listStreamRecordsStats(), stor::SMWebPageHelper::resourceBrokerOverview(), and stor::SMWebPageHelper::storedDataWebPage().

{
  XMLCh* xname = xs_(name);
  Node* el = doc_->createElement(xname);
  XMLString::release(&xname);
  parent->appendChild( el );

  for( AttrMap::const_iterator i = attrs.begin(); i != attrs.end();
         ++i )
    {
      XMLCh* xfirst = xs_(i->first);
      XMLCh* xsecond = xs_(i->second);
      el->setAttribute(xfirst, xsecond);
      XMLString::release(&xfirst);
      XMLString::release(&xsecond);
    }

  return el;

}
Node* stor::XHTMLMaker::addNode ( const std::string &  name,
const AttrMap attrs 
) [inline]

Add child to top level

Definition at line 71 of file XHTMLMaker.h.

References addNode().

    {
      return addNode( name, (Node*)0, attrs );
    }
Node* stor::XHTMLMaker::addNode ( const std::string &  name,
Node parent 
) [inline]

Add child without attributes

Definition at line 79 of file XHTMLMaker.h.

References addNode(), and relativeConstraints::empty.

    {
      AttrMap empty;
      return addNode( name, parent, empty );
    }
Node* stor::XHTMLMaker::addNode ( const std::string &  name) [inline]

Add child to top without attributes

Definition at line 88 of file XHTMLMaker.h.

References addNode().

    {
      return addNode( name, (Node*)0 );
    }
void XHTMLMaker::addText ( Node parent,
const std::string &  data 
)

Add text

Definition at line 173 of file XHTMLMaker.cc.

References fetchall_from_DQM_v2::release.

Referenced by stor::SMWebPageHelper::addDOMforConfigString(), smproxy::SMPSWebPageHelper::addDOMforConnectionInfo(), smproxy::SMPSWebPageHelper::addDOMforEventServers(), stor::SMWebPageHelper::addDOMforFiles(), stor::SMWebPageHelper::addDOMforFragmentMonitor(), smproxy::SMPSWebPageHelper::addDOMforHyperLinks(), stor::SMWebPageHelper::addDOMforHyperLinks(), stor::SMWebPageHelper::addDOMforRunMonitor(), smproxy::SMPSWebPageHelper::addDOMforSMhost(), stor::SMWebPageHelper::addDOMforStoredData(), stor::SMWebPageHelper::addDOMforSummaryInformation(), smproxy::SMPSWebPageHelper::addDOMforThroughputPerEventType(), stor::SMWebPageHelper::addDOMforThroughputStatistics(), stor::SMWebPageHelper::addFilterUnitList(), stor::SMWebPageHelper::addFragmentStats(), stor::SMWebPageHelper::addOutputModuleStatistics(), stor::SMWebPageHelper::addOutputModuleSummary(), stor::SMWebPageHelper::addResourceBrokerDetails(), stor::SMWebPageHelper::addResourceBrokerList(), stor::SMWebPageHelper::addRowForBandwidth(), smproxy::SMPSWebPageHelper::addRowForEventServer(), smproxy::SMPSWebPageHelper::addRowForEventType(), stor::SMWebPageHelper::addRowForFramesReceived(), stor::SMWebPageHelper::addRowForLatency(), stor::SMWebPageHelper::addRowForMaxBandwidth(), stor::SMWebPageHelper::addRowForMinBandwidth(), stor::SMWebPageHelper::addRowForRate(), stor::SMWebPageHelper::addRowForThroughputStatistics(), stor::SMWebPageHelper::addRowForTotalVolume(), stor::SMWebPageHelper::addRowsForSataBeast(), stor::SMWebPageHelper::addRowsForThroughputUsage(), stor::SMWebPageHelper::addRowsForWorkers(), smproxy::SMPSWebPageHelper::addSummaryRowForThroughput(), stor::SMWebPageHelper::addTableForDiskUsages(), stor::SMWebPageHelper::addTableForResourceUsages(), and stor::SMWebPageHelper::listStreamRecordsStats().

{
  XMLCh* xdata = xs_(data);
  DOMText* txt = doc_->createTextNode(xdata);
  XMLString::release(&xdata);
  parent->appendChild( txt );
}
Node* stor::XHTMLMaker::getHead ( ) const [inline]

Useful for css and javascript

Definition at line 56 of file XHTMLMaker.h.

References head_.

{ return head_; }
void XHTMLMaker::out ( std::string &  dest)

Dump the page to a string

Definition at line 328 of file XHTMLMaker.cc.

References dbtoconf::out.

{
   std::ostringstream stream;
   out( stream );
   dest = stream.str();
}
void XHTMLMaker::out ( std::ostream &  dest)

Dump the page into an output stream

Definition at line 338 of file XHTMLMaker.cc.

{
  setWriterFeatures_();
  MemBufFormatTarget* ftar = new MemBufFormatTarget();
  writer_->writeNode( ftar, *doc_ );
  dest << ftar->getRawBuffer();
  delete ftar;
}
void XHTMLMaker::out ( const std::string &  dest)

Dump the page to a local file

Definition at line 315 of file XHTMLMaker.cc.

References fetchall_from_DQM_v2::release.

{
  setWriterFeatures_();
  XMLCh* xfilename = xs_(filename);
  XMLFormatTarget* ftar = new LocalFileFormatTarget(xfilename);
  writer_->writeNode( ftar, *doc_ );
  XMLString::release(&xfilename);
  delete ftar;
}
void XHTMLMaker::out ( )
void XHTMLMaker::setWriterFeatures_ ( ) [private]

Set DOMWriter features

Definition at line 273 of file XHTMLMaker.cc.

{

  //writer_->setNewLine( (const XMLCh*)( L"\n" ) );

  if( writer_->canSetFeature( XMLUni::fgDOMWRTSplitCdataSections, true ) )
    {
      writer_->setFeature( XMLUni::fgDOMWRTSplitCdataSections, true );
    }

  if( writer_->canSetFeature( XMLUni::fgDOMWRTDiscardDefaultContent, true ) )
    {
      writer_->setFeature( XMLUni::fgDOMWRTDiscardDefaultContent, true );
    }

  if( writer_->canSetFeature( XMLUni::fgDOMWRTFormatPrettyPrint, true ) )
    {
      writer_->setFeature( XMLUni::fgDOMWRTFormatPrettyPrint, true );
    }

  if( writer_->canSetFeature( XMLUni::fgDOMWRTBOM, true ) )
    {
      writer_->setFeature( XMLUni::fgDOMWRTBOM, true );
    }

}
XHTMLMaker::Node * XHTMLMaker::start ( const std::string &  title)

Initialize page and return body element

Definition at line 101 of file XHTMLMaker.cc.

References dtNoiseDBValidation_cfg::cerr, h, and fetchall_from_DQM_v2::release.

{

  if( pageStarted_ )
    {
      std::cerr << "Page already started" << std::endl;
      return (Node*)0;
    }

  pageStarted_ = true;

  // Root element:
  Node* el_xhtml = doc_->getDocumentElement();

  // Head:
  XMLCh* h = xs_("head");
  head_ = doc_->createElement(h);
  XMLString::release(&h);
  el_xhtml->appendChild( head_ );


  // Title:
  XMLCh* xtitle = xs_("title");
  Node* el_title = doc_->createElement(xtitle);
  XMLString::release(&xtitle);
  head_->appendChild( el_title );
  xtitle = xs_(title);
  DOMText* txt_title = doc_->createTextNode(xtitle);
  XMLString::release(&xtitle);
  el_title->appendChild( txt_title );

  // Body:
  XMLCh* xbody = xs_("body");
  Node* el_body = doc_->createElement(xbody);
  XMLString::release(&xbody);
  el_xhtml->appendChild( el_body );

  return el_body;

}

Member Data Documentation

xercesc::DOMDocument* stor::XHTMLMaker::doc_ [private]

Definition at line 166 of file XHTMLMaker.h.

Definition at line 170 of file XHTMLMaker.h.

Referenced by getHead().

Definition at line 172 of file XHTMLMaker.h.

xercesc::DOMDocumentType* stor::XHTMLMaker::typ_ [private]

Definition at line 168 of file XHTMLMaker.h.

xercesc::DOMWriter* stor::XHTMLMaker::writer_ [private]

Definition at line 167 of file XHTMLMaker.h.