filters
TagProcessing.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <kdebug.h>
00037 #include <qdom.h>
00038
00039 #include "TagProcessing.h"
00040
00041 #define DEBUG_KWORD_TAGS
00042
00043
00044
00045 void ProcessSubtags ( const QDomNode &parentNode,
00046 QValueList<TagProcessing> &tagProcessingList,
00047 KWEFKWordLeader *leader)
00048 {
00049
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
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
00130
00131 QDomNamedNodeMap myAttribs ( myNode.attributes () );
00132
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
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
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 }
|