Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Source.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/xmlUtil/src/Source.cxx,v 1.3 2002/07/23 20:01:20 jrb Exp $
00002 
00003 #include "xmlUtil/Source.h"
00004 #include <dom/DOMString.hpp>
00005 #include <dom/DOM_Text.hpp>
00006 #include "xml/Dom.h"
00007 
00008 
00009 namespace { 
00010   // private utility to strip off $ 
00011   char * stripDollar(char* toStrip) {
00012     const char dollar = '$';
00013     
00014     char   nothing = 0;
00015     unsigned len = strlen(toStrip);
00016     
00017     if (dollar == toStrip[len - 1]) {
00018       len--;
00019       toStrip[len] = nothing;
00020     }
00021     if (dollar == toStrip[0]) {
00022       return (toStrip + 1);
00023     }
00024     return toStrip;
00025   }
00026 }      // end of blank namespace
00027 
00028 namespace xmlUtil {
00029   Source::Source(DOM_Document doc, const char * creator,
00030       const char* creatorCVSID) : m_doc(doc), m_creator(creator)  {
00031     
00032     char * tmp = new char[strlen(creatorCVSID) + 1];
00033     strcpy(tmp, creatorCVSID);
00034     m_myCVSID = std::string(stripDollar(tmp));
00035     delete [] tmp;
00036   }
00037 
00038   void Source::add(DOM_Element parentArg) {
00039     static char * unknownId = "unidentified input file";
00040     DOM_Element docElt = m_doc.getDocumentElement();
00041     DOM_Element parent = parentArg;
00042     if (parent == DOM_Element()) {
00043       parent = docElt;
00044     }
00045 
00046     DOM_Element source = m_doc.createElement("source");
00047 
00048     // Document element should have a CVSid attribute
00049     DOMString idAtt = docElt.getAttribute("CVSid");
00050     char * strippedRaw;
00051     char * myRaw = 0;
00052 
00053     if (idAtt != DOMString() ){
00054       const char * raw   = xml::Dom::transToChar(idAtt);
00055       unsigned   len = strlen(raw);
00056       if (len) {
00057         myRaw = new char[len+1];
00058         strcpy(myRaw, raw);
00059         strippedRaw = stripDollar(myRaw);
00060       }
00061     }
00062     else strippedRaw = unknownId;
00063 
00064     DOMString newAtt = DOMString(strippedRaw);
00065 
00066     source.setAttribute("inputId", newAtt);
00067 
00068     // Already have creator ID as std::string
00069     source.setAttribute(DOMString("creatorId"),
00070                         DOMString(m_myCVSID.c_str()));
00071     
00072     std::string theText = 
00073       std::string("Do not edit! This file automatically created by ");
00074     theText.append(m_creator);
00075     DOM_Text    sourceText = m_doc.createTextNode(theText.c_str()); 
00076 
00077 
00078     source.appendChild(sourceText);
00079 
00080     if (myRaw) delete [] myRaw;
00081     // Finally need to insert this node as the first child of specified elt
00082     parent.insertBefore(source, parent.getFirstChild());
00083   }
00084 }

Generated on Wed Oct 16 14:02:48 2002 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001