Hauptseite | Liste aller Namensbereiche | Klassenhierarchie | Übersicht | Auflistung der Dateien | Elemente eines Namensbereiches | Datenstruktur-Elemente | Datei-Elemente

UnitSax2ContentHandler.cpp

gehe zur Dokumentation dieser Datei
00001 // Copyright (C) 2004 Bernhard Assmann <bernie@tuxomania.net>
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //  
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //  
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 //  
00017 
00018 #include <xercesc/util/XMLString.hpp>
00019 #include <xercesc/sax/Locator.hpp>
00020 
00021 #include <string>
00022 
00023 #include "psfa/UnitSax2ContentHandler.hpp"
00024 #include "psfa/Helper.hpp"
00025 #include "psfa/Config.hpp"
00026 
00027 
00028 
00029 psfa::UnitSax2ContentHandler::UnitSax2ContentHandler( const std::string pool,
00030                         std::vector< IndexData_SP >&
00031                         dataList )
00032   : mode_(start),
00033     locator_(0),
00034     pool_(pool),
00035     aktFile_(""),
00036     aktUnit_(""),
00037     aktKontext_(""),
00038     dataList_(dataList)
00039 {
00040   using psfahelper::splitString;
00041   
00042   Config* conf = Config::getConfig();
00043   splitString( conf->getConfigValue( pool,  "tags" ),
00044           tagNames_ );
00045   splitString( conf->getConfigValue( pool,  "kontexts" ),
00046           kontextNames_ );
00047   unitTag_ = conf->getConfigValue( pool_,  "unitTag" );
00048 
00049 }
00050 
00051 
00052 
00053 psfa::UnitSax2ContentHandler::~UnitSax2ContentHandler() 
00054 {
00055     
00056     
00057 }
00058 
00059 
00060 
00061 void 
00062 psfa::UnitSax2ContentHandler::characters( const XMLCh* const chars,
00063                  const unsigned int length ) 
00064 {
00065   using xercesc::XMLString;
00066   using psfahelper::onlyWhiteSpace;
00067   using psfahelper::stripWhiteSpace;
00068     
00069   switch( mode_ ) {
00070   case index:
00071     {
00072       std::string content( chars, chars+length);
00073       bool ignore = onlyWhiteSpace( content );
00074       if( ignore ) {
00075    indexData_->content = "";
00076       }
00077       else {
00078    indexData_->content = stripWhiteSpace( content );
00079       }
00080       indexData_->lineStop = locator_->getLineNumber();
00081       indexData_->columnStop = locator_->getColumnNumber();
00082     }
00083     break;
00084   case unit:
00085     {
00086       std::string content(chars, chars+length);
00087       bool ignore = psfahelper::onlyWhiteSpace( content );
00088       if( ignore ) {
00089    aktUnit_ = "Einheit ohne Namen";
00090       }
00091       else {
00092    aktUnit_ = stripWhiteSpace( content );
00093       }
00094     }
00095     break;
00096   default:
00097     break;
00098   }
00099   return;
00100 }
00101 
00102 
00103 
00104 void 
00105 psfa::UnitSax2ContentHandler::endDocument() 
00106 {
00107 
00108 }
00109 
00110 
00111 
00112 void 
00113 psfa::UnitSax2ContentHandler::endElement( const XMLCh* const,
00114                  const XMLCh* const,
00115                  const XMLCh* const ) 
00116 {
00117   switch( mode_ ) {
00118   case index:
00119     dataList_.push_back( indexData_ );
00120     mode_ = start;
00121     break;
00122   case unit:
00123     mode_ = start;
00124     break;
00125   default:
00126     break;
00127   }
00128   return;
00129 }
00130 
00131 
00132 
00133 void 
00134 psfa::UnitSax2ContentHandler::ignorableWhitespace( const XMLCh* const,
00135                      const unsigned int )
00136 {
00137 
00138 }
00139 
00140 
00141     
00142 void 
00143 psfa::UnitSax2ContentHandler::processingInstruction( const XMLCh* const,
00144                        const XMLCh* const ) 
00145 {
00146     
00147 }
00148 
00149 
00150 
00151 void 
00152 psfa::UnitSax2ContentHandler::setDocumentLocator ( const xercesc::Locator* locator ) 
00153 {
00154   locator_ = locator;
00155   return;
00156 }
00157 
00158 
00159     
00160 void 
00161 psfa::UnitSax2ContentHandler::startDocument() 
00162 {
00163     
00164 }
00165 
00166 
00167     
00168 void 
00169 psfa::UnitSax2ContentHandler::startElement( const XMLCh* const,
00170                    const XMLCh* const,
00171                    const XMLCh* const qname,
00172                    const xercesc::Attributes& attrs ) 
00173 {
00174   using std::string;
00175   using std::vector;
00176   using std::find;
00177   using psfahelper::getXMLChLength;
00178   using psfahelper::stripWhiteSpace;
00179   typedef vector< string > sVec;
00180   
00181   string::size_type i = getXMLChLength( qname );
00182   string tagName( qname, qname + i );
00183   if( unitTag_ == tagName ) {
00184     mode_ = unit;
00185     return;
00186   }
00187   
00188   sVec::iterator nEnd = kontextNames_.end();
00189   sVec::iterator match = find( kontextNames_.begin(),
00190                 nEnd,
00191                 tagName );
00192   if( match != nEnd ) {
00193     aktKontext_ = tagName;
00194     return;
00195   }
00196 
00197   nEnd   = tagNames_.end();
00198   match  = find( tagNames_.begin(), nEnd, tagName );
00199   if( match != nEnd && mode_ == start ) {
00200     indexData_ = IndexData_SP( new IndexData );
00201     indexData_->file = aktFile_;
00202     indexData_->unit = aktUnit_;
00203     indexData_->kontext = aktKontext_;
00204     indexData_->tag = tagName;
00205     unsigned int l = attrs.getLength();
00206     if( l != 0 ) {
00207       for( unsigned int i = 0; i < l; ++i ) {
00208    const XMLCh* const aName  = attrs.getLocalName( i );
00209    const XMLCh* const aValue = attrs.getValue( i );
00210    string::size_type s = getXMLChLength( aName );
00211    string name( aName, aName + s );
00212    s = getXMLChLength( aValue );
00213    string value( aValue, aValue + s );
00214    AttMap::value_type att( stripWhiteSpace( name ),
00215             stripWhiteSpace( value ) 
00216             );
00217    indexData_->attributes.insert( att );
00218       }
00219     }
00220     indexData_->lineStart = locator_->getLineNumber();
00221     indexData_->columnStart = locator_->getColumnNumber();
00222     mode_ = index;
00223   }
00224   return;
00225 }
00226 
00227 
00228     
00229 void 
00230 psfa::UnitSax2ContentHandler::startPrefixMapping( const XMLCh* const,
00231                     const XMLCh* const ) 
00232 {
00233     
00234 }
00235 
00236     
00237 
00238 void
00239 psfa::UnitSax2ContentHandler::endPrefixMapping( const XMLCh* const ) 
00240 {
00241     
00242     
00243 }
00244 
00245    
00246     
00247 void 
00248 psfa::UnitSax2ContentHandler::skippedEntity( const XMLCh* const ) 
00249 {
00250     
00251 }
00252 
00253 
00254 void
00255 psfa::UnitSax2ContentHandler::setFileName( const std::string name )
00256 {
00257   aktFile_ = name;
00258   return;
00259 }

Erzeugt am Mon Jul 12 11:45:04 2004 für PSFA von doxygen 1.3.4