Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

LCD_DocumentImpl.cc

Go to the documentation of this file.
00001 // $Id: LCD_DocumentImpl.cc,v 1.11 2004/02/02 22:12:48 uid561 Exp $
00002 //
00003 // LCD_Document.cxx
00004 //
00005 // Implementation file for the LCD classes supporting DOM:
00006 //
00007 //  LCD_DocumentImpl         implementation of above
00008 //  LCD_DocManager           keeps track of all active LCD_Document's
00009 //
00010 // Other relevant classes have implementation, if any, in header file:
00011 //  LCD_Document             largely virtual class describing interface
00012 //  LCD_DocListener          entirely virtual
00013 //
00014 // Classes to handle the set of all XML documents known to a program
00015 // (i.e., for which there are DOMs)
00016 
00017 // There is a class LCD_DocumentImpl (should perhaps be an implementation of an
00018 // interface) which acts as a small database describing a DOM.  There
00019 // will be one instance per DOM.
00020 
00021 // LCD_DocumentImpl has an enhanced set of query functions as compared to
00022 // DOM_Document.  (Maybe I should change the name to LCD_Document.
00023 // And maybe it should inherit from DOM_Document, except that,
00024 // according to the DOM parser's documentation, the DOM_* classes
00025 // cannot be subclassed.)
00026 
00027 // There is another class (LCD_DocManager) which keeps track of all
00028 // LCD_DocumentImpls.  There will be only one instance per program.
00029 
00030 // The class LCD_DocListener just defines an interface for signing up
00031 // to be notified of changes to a document.
00032 
00033 #include "xercesc/util/PlatformUtils.hpp"
00034 #include <algorithm>
00035 //#include <strstream>
00036 #include <list>
00037 #include <iterator>
00038 #include <iostream>
00039 
00040 // see /afs/slac.stanford.edu/package/gcc/src/egcs-1.1.2/libio/strstream.h
00041 #include "xercesc/dom/deprecated/DOM_Document.hpp"
00042 #include "xercesc/dom/deprecated/DOM_Element.hpp"
00043 #include "xercesc/dom/deprecated/DOMString.hpp"
00044 #include "xercesc/dom/deprecated/DOMParser.hpp"
00045 XERCES_CPP_NAMESPACE_USE
00046 
00047 #include "LCD_DocListener.hh"
00048 #include "LCD_DocumentImpl.hh"
00049 // #include "LCD_DocManager.h"
00050 #include "LCD_DocumentUtil.hh"
00051 #include "LCD_DocErrorReporter.hh"
00052 
00053 //#include <util/StdOut.hpp>
00054 
00055 // XMLStdErr lcdErrStrm;
00056 // using namespace std;
00057 
00058 /*
00059  * Comment
00060  */
00061 LCD_DocumentImpl::LCD_DocumentImpl(std::string XMLfilespec) {
00062   // This method should only be invoked by the  LCD_DocManager
00063   DOM_Element elt;
00064 
00065   errReporter = new LCD_DocErrorReporter();
00066 
00067   parser = new DOMParser();
00068   parser->setErrorHandler(errReporter);
00069 
00070   listeners = new std::list<LCD_DocListener*>;
00071   filespec = XMLfilespec;
00072 }
00073 
00074 // maybe  throw exception?
00075 
00076 /*
00077  * Comment
00078  */
00079 void LCD_DocumentImpl::parse() {
00080 
00081   // static const DOMString& descripString = DOMString("descrip");
00082   const DOMString& descripString = DOMString("descrip");
00083   DOM_Element elt;
00084 
00085   parser->parse(filespec.c_str());
00086   myDoc = parser->getDocument();
00087 
00088   //  firstRead = getCurrentTime();     to be defined
00089   firstRead = 0;
00090 
00091   elt = myDoc.getDocumentElement();
00092 
00093   // dtd doctype name must match tag name of root element of doc
00094   docTypeName = elt.getTagName();
00095 
00096   descrip = elt.getAttribute(descripString);
00097 
00098 }
00099 
00100 // Wend our way through the DOM, looking for element with id attribute
00101 // whose value matches supplied id.  If elementName != "*" then only
00102 // check elements of supplied name
00103 
00104 /*
00105  * Comment
00106  */
00107 DOM_Element LCD_DocumentImpl::getElement(DOMString id,
00108                                          DOMString elementName) const {
00109   DOM_Element  docElt = myDoc.getDocumentElement();
00110   DOMString idVal;
00111   DOMString idString = DOMString("id");
00112 
00113   if ((elementName.equals(DOMString("*"))) ||
00114       (elementName.equals(docElt.getTagName()) ) ) {
00115     idVal = docElt.getAttribute(idString);
00116     if (idVal.equals(id)) return docElt;
00117   }
00118 
00119   DOM_NodeList eltList = docElt.getElementsByTagName(elementName);
00120   int          len = eltList.getLength();
00121   DOM_Node     node;
00122 
00123   for (int i = 0; i < len; i++) {
00124 
00125     node =  (eltList.item(i));
00126     DOM_Element elt = (DOM_Element &) node;
00127 
00128     // Don't use the  following because it generates the compiler message
00129     //     warning: conversion to non-const `DOM_Element &' from
00130     //     rvalue `DOM_Node'
00131     // DOM_Element elt = (DOM_Element &) (eltList.item(i));
00132 
00133     idVal = elt.getAttribute(idString);
00134 
00135     if (idVal.equals(id)) return  elt;
00136   }
00137 
00138   return DOM_Element();
00139 }
00140 
00141 /*
00142  * Comment
00143  */
00144 void LCD_DocumentImpl::registerListener(LCD_DocListener* ls) {
00145   listeners->push_front(ls);
00146 }
00147 
00148 /*
00149  * Comment
00150  */
00151 int LCD_DocumentImpl::deleteListener(LCD_DocListener* ls) {
00152 
00153   std::list<LCD_DocListener*>::iterator
00154     which = std::find(listeners->begin(), listeners->end(), ls);
00155   if (which != listeners->end()) {
00156 
00157     // delete it from list
00158     listeners->erase(which);
00159   }
00160   else {
00161     return 1;  // not found
00162   }
00163   return 0;
00164 }
00165 
00166 // TO DO!!!
00167 
00168 /*
00169  * Comment
00170  */
00171 void LCD_DocumentImpl::notifyListeners() {
00172   // fetch listeners; invoke handler for each
00173   return;
00174 }
00175 //  end LCD_DocumentImpl stuff
00176 

Generated on Thu Oct 7 18:44:46 2004 for LCDG4 by doxygen 1.3.4