filters

TagProcessing.cc

00001 /*
00002    This file is part of the KDE project
00003    Copyright (C) 2001, 2002, 2004 Nicolas GOUTTE <goutte@kde.org>
00004    Copyright (c) 2001 IABG mbH. All rights reserved.
00005                       Contact: Wolf-Michael Bolle <Bolle@IABG.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021 */
00022 
00023 /*
00024    This file is based on the old file:
00025     /home/kde/koffice/filters/kword/ascii/asciiexport.cc
00026 
00027    The old file was copyrighted by
00028     Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00029     Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved.
00030                        Contact: Wolf-Michael Bolle <Bolle@GMX.de>
00031 
00032    The old file was licensed under the terms of the GNU Library General Public
00033    License version 2.
00034 */
00035 
00036 #include <kdebug.h>
00037 #include <qdom.h>
00038 
00039 #include "TagProcessing.h"
00040 
00041 #define DEBUG_KWORD_TAGS
00042 // #define DEBUG_KWORD_IGNORED_TAGS
00043 
00044 
00045 void ProcessSubtags ( const QDomNode             &parentNode,
00046                       QValueList<TagProcessing>  &tagProcessingList,
00047                       KWEFKWordLeader            *leader)
00048 {
00049     //kdDebug(30508) << "Starting ProcessSubtags for node: " << parentNode.nodeName() << endl;
00050 
00051     QDomNode childNode;
00052 
00053     for ( childNode = parentNode.firstChild (); !childNode.isNull (); childNode = childNode.nextSibling () )
00054     {
00055         if ( childNode.isElement () )
00056         {
00057             bool found = false;
00058 
00059             QValueList<TagProcessing>::Iterator  tagProcessingIt;
00060 
00061             for ( tagProcessingIt = tagProcessingList.begin ();
00062                   tagProcessingIt != tagProcessingList.end ();
00063                   tagProcessingIt++ )
00064             {
00065                 if ( childNode.nodeName () == (*tagProcessingIt).name )
00066                 {
00067                     found = true;
00068 
00069                     if ( (*tagProcessingIt).processor != NULL )
00070                     {
00071                         ((*tagProcessingIt).processor) ( childNode, (*tagProcessingIt).data, leader );
00072                     }
00073 #ifdef DEBUG_KWORD_IGNORED_TAGS
00074                     else
00075                     {
00076                         kdDebug(30508) << "Ignoring " << childNode.nodeName ()
00077                             << " tag in " << parentNode.nodeName () << endl;
00078                     }
00079 #endif
00080                     break;
00081                 }
00082             }
00083 
00084             if ( !found )
00085             {
00086                 kdDebug(30508) << "Unexpected tag " << childNode.nodeName ()
00087                     << " in " << parentNode.nodeName () << "!" << endl;
00088             }
00089         }
00090     }
00091     //kdDebug(30508) << "Ending ProcessSubtags for node: " << parentNode.nodeName() << endl;
00092 }
00093 
00094 void AllowNoSubtags ( const QDomNode& myNode, KWEFKWordLeader *leader )
00095 {
00096 #ifdef DEBUG_KWORD_TAGS
00097     QString outputText;
00098     QValueList<TagProcessing> tagProcessingList;
00099     ProcessSubtags (myNode, tagProcessingList, leader);
00100 #else
00101     @_UNUSED( leader ):
00102 #endif
00103 }
00104 
00105 AttrProcessing::AttrProcessing ( const QString& n, const QString& t, void *d )
00106     : name (n), data (d)
00107 {
00108     if ( t == "int" )
00109         type = AttrInt;
00110     else if ( t == "QString" )
00111         type = AttrQString;
00112     else if ( t == "double" )
00113         type = AttrDouble;
00114     else if ( t == "bool" )
00115         type = AttrBool;
00116     else if ( t.isEmpty() )
00117         type = AttrNull;
00118     else
00119     {
00120         kdWarning(30508) << "Unknown type: " << t << " for element " << n << " assuming NULL" << endl;
00121         type = AttrNull;
00122     }
00123 }
00124 
00125 
00126 void ProcessAttributes ( const QDomNode              &myNode,
00127                          QValueList<AttrProcessing>  &attrProcessingList )
00128 {
00129     //kdDebug(30508) << "Starting ProcessAttributes for node: " << myNode.nodeName() << endl;
00130 
00131     QDomNamedNodeMap myAttribs ( myNode.attributes () );
00132     //kdDebug(30508) << "Attributes = " << myAttribs.length () <<endl;
00133     for ( uint i = 0; i <  myAttribs.length (); i++ )
00134     {
00135         QDomAttr myAttrib ( myAttribs.item (i).toAttr () );
00136 
00137         if ( !myAttrib.isNull () )
00138         {
00139             bool found = false;
00140 
00141             QValueList<AttrProcessing>::Iterator attrProcessingIt;
00142 
00143             for ( attrProcessingIt = attrProcessingList.begin ();
00144                   attrProcessingIt != attrProcessingList.end ();
00145                   attrProcessingIt++ )
00146             {
00147               //kdDebug(30508) << "NAME: " << myAttrib.name () << " == " << (*attrProcessingIt).name <<endl;
00148                 if ( myAttrib.name () == (*attrProcessingIt).name )
00149                 {
00150                     found = true;
00151 
00152                     if ( (*attrProcessingIt).data != NULL )
00153                     {
00154                         switch ( (*attrProcessingIt).type )
00155                         {
00156                         case AttrProcessing::AttrQString:
00157                             {
00158                                 *((QString *) (*attrProcessingIt).data) = myAttrib.value ();
00159                                 break;
00160                             }
00161                         case AttrProcessing::AttrInt:
00162                             {
00163                                 *((int *) (*attrProcessingIt).data) = myAttrib.value ().toInt ();
00164                                 break;
00165                             }
00166                         case AttrProcessing::AttrDouble:
00167                             {
00168                                 *((double *) (*attrProcessingIt).data) = myAttrib.value ().toDouble ();
00169                                 break;
00170                             }
00171                         case AttrProcessing::AttrBool:
00172                             {
00173                                 const QString strAttr ( myAttrib.value().simplifyWhiteSpace() );
00174                                 bool flag;
00175                                 if ((strAttr=="yes")||(strAttr=="1")||(strAttr=="true"))
00176                                 {
00177                                     flag=true;
00178                                 }
00179                                 else if ((strAttr=="no")||(strAttr=="0")||(strAttr=="false"))
00180                                 {
00181                                     flag=false;
00182                                 }
00183                                 else
00184                                 {
00185                                     flag=false;
00186                                     kdWarning(30508) << "Unknown value for a boolean: " << strAttr
00187                                         << " in tag " << myNode.nodeName () << ", attribute "
00188                                         << myAttrib.name() << endl;
00189                                 }
00190                                 *((bool *) (*attrProcessingIt).data) = flag;
00191                                 break;
00192                             }
00193                         case AttrProcessing::AttrNull:
00194                             break;
00195                         default:
00196                             {
00197                                 kdDebug(30508) << "Unexpected data type " << int( (*attrProcessingIt).type )
00198                                     << " in " << myNode.nodeName ()
00199                                     << " attribute " << (*attrProcessingIt).name
00200                                     << endl;
00201                                 break;
00202                             }
00203                         }
00204                     }
00205 #ifdef DEBUG_KWORD_IGNORED_TAGS
00206                     else
00207                     {
00208                         kdDebug(30508) << "Ignoring " << myNode.nodeName()
00209                             << " attribute " << (*attrProcessingIt).name
00210                             << endl;
00211                     }
00212 #endif
00213                     break;
00214                 }
00215             }
00216 
00217             if ( !found )
00218             {
00219                 kdWarning(30508) << "Unexpected attribute " << myAttrib.name ()
00220                     << " in " << myNode.nodeName () << "!" << endl;
00221             }
00222         }
00223     }
00224     //kdDebug(30508) << "Ending ProcessAttributes for node: " << myNode.nodeName() << endl;
00225 }
00226 
00227 void AllowNoAttributes ( const QDomNode & myNode )
00228 {
00229 #ifdef DEBUG_KWORD_TAGS
00230     QValueList<AttrProcessing> attrProcessingList;
00231     ProcessAttributes (myNode, attrProcessingList);
00232 #else
00233     Q_UNUSED( myNode );
00234 #endif
00235 }
KDE Home | KDE Accessibility Home | Description of Access Keys