00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "keduvockvtml2writer.h"
00018
00019 #include <QtCore/QTextStream>
00020 #include <QtCore/QFile>
00021
00022 #include <KDebug>
00023
00024 #include "keduvocdocument.h"
00025 #include "keduvocexpression.h"
00026 #include "keduvocgrade.h"
00027 #include "keduvoclesson.h"
00028 #include "keduvocwordtype.h"
00029 #include "kvtml2defs.h"
00030
00031 KEduVocKvtml2Writer::KEduVocKvtml2Writer( QFile *file )
00032 {
00033
00034 m_outputFile = file;
00035 }
00036
00037
00038 bool KEduVocKvtml2Writer::writeDoc( KEduVocDocument *doc, const QString &generator )
00039 {
00040 m_doc = doc;
00041
00042 m_domDoc = QDomDocument( "kvtml PUBLIC \"kvtml2.dtd\" \"http://edu.kde.org/kanagram/kvtml2.dtd\"" );
00043 m_domDoc.appendChild( m_domDoc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
00044 QDomElement domElementKvtml = m_domDoc.createElement( "kvtml" );
00045 m_domDoc.appendChild( domElementKvtml );
00046
00047 domElementKvtml.setAttribute( KVTML_VERSION, ( QString ) "2.0" );
00048
00049
00050 QDomElement currentElement = m_domDoc.createElement( KVTML_INFORMATION );
00051 writeInformation( currentElement, generator );
00052 domElementKvtml.appendChild( currentElement );
00053
00054
00055 currentElement = m_domDoc.createElement( KVTML_IDENTIFIERS );
00056 writeIdentifiers( currentElement );
00057 domElementKvtml.appendChild( currentElement );
00058
00059
00060 currentElement = m_domDoc.createElement( KVTML_TENSES );
00061 writeTenses( currentElement );
00062 if ( currentElement.hasChildNodes() ) {
00063 domElementKvtml.appendChild( currentElement );
00064 }
00065
00066
00067 currentElement = m_domDoc.createElement( KVTML_USAGES );
00068 writeUsages( currentElement );
00069 if ( currentElement.hasChildNodes() ) {
00070 domElementKvtml.appendChild( currentElement );
00071 }
00072
00073
00074 currentElement = m_domDoc.createElement( KVTML_ENTRIES );
00075 if ( !writeEntries( currentElement ) ) {
00076
00077 return false;
00078 }
00079 domElementKvtml.appendChild( currentElement );
00080
00081
00082 currentElement = m_domDoc.createElement( KVTML_LESSONS );
00083 writeLessons( currentElement );
00084 if ( currentElement.hasChildNodes() ) {
00085 domElementKvtml.appendChild( currentElement );
00086 }
00087
00088
00089 m_wordTypeElement = m_domDoc.createElement( KVTML_WORDTYPES );
00090 writeWordTypes( m_wordTypeElement );
00091 if ( m_wordTypeElement.hasChildNodes() ) {
00092 domElementKvtml.appendChild( m_wordTypeElement );
00093 }
00094
00095 m_domDoc.appendChild( domElementKvtml );
00096
00097 QTextStream ts( m_outputFile );
00098 m_domDoc.save( ts, 2 );
00099
00100 return true;
00101 }
00102
00103 bool KEduVocKvtml2Writer::writeInformation( QDomElement &informationElement, const QString &generator )
00104 {
00105 QDomElement currentElement;
00106 QDomText textNode;
00107
00108
00109 informationElement.appendChild( newTextElement( KVTML_GENERATOR, generator ) );
00110
00111
00112 if ( !m_doc->title().isEmpty() ) {
00113 informationElement.appendChild( newTextElement( KVTML_TITLE, m_doc->title() ) );
00114 }
00115
00116
00117 if ( !m_doc->author().isEmpty() ) {
00118 informationElement.appendChild( newTextElement( KVTML_AUTHOR, m_doc->author() ) );
00119 }
00120
00121
00122 if ( !m_doc->license().isEmpty() ) {
00123 informationElement.appendChild( newTextElement( KVTML_LICENSE, m_doc->license() ) );
00124 }
00125
00126
00127 if ( !m_doc->documentComment().isEmpty() ) {
00128 informationElement.appendChild( newTextElement( KVTML_COMMENT, m_doc->documentComment() ) );
00129 }
00130
00131
00132 if ( !m_doc->category().isEmpty() ) {
00133 informationElement.appendChild( newTextElement( KVTML_CATEGORY, m_doc->category() ) );
00134 }
00135
00136 return true;
00137 }
00138
00139
00140 bool KEduVocKvtml2Writer::writeIdentifiers( QDomElement &identifiersElement )
00141 {
00142 for ( int i = 0; i < m_doc->identifierCount(); ++i ) {
00143
00144 QDomElement identifier = m_domDoc.createElement( KVTML_IDENTIFIER );
00145
00146
00147 identifier.setAttribute( KVTML_ID, QString::number( i ) );
00148
00149
00150
00151 identifier.appendChild( newTextElement( KVTML_NAME, m_doc->identifier( i ).name() ) );
00152
00153 identifier.appendChild( newTextElement( KVTML_LOCALE, m_doc->identifier( i ).locale() ) );
00154
00155
00156 QDomElement article = m_domDoc.createElement( KVTML_ARTICLE );
00157 writeArticle( article, i );
00158 if ( article.hasChildNodes() ) {
00159 identifier.appendChild( article );
00160 }
00161
00162
00163 QDomElement personalpronouns = m_domDoc.createElement( KVTML_PERSONALPRONOUNS );
00164 writePersonalPronoun( personalpronouns, m_doc->identifier(i).personalPronouns() );
00165 if ( personalpronouns.hasChildNodes() ) {
00166 identifier.appendChild( personalpronouns );
00167 }
00168
00169
00170 identifiersElement.appendChild( identifier );
00171 }
00172 return true;
00173 }
00174
00175 bool KEduVocKvtml2Writer::writeLessons( QDomElement &lessonsElement )
00176 {
00177 for( int lessonId = 0; lessonId < m_doc->lessonCount(); lessonId++ ) {
00178
00179 QDomElement thisLessonElement = m_domDoc.createElement( KVTML_CONTAINER );
00180
00181
00182 thisLessonElement.appendChild( newTextElement( KVTML_NAME, m_doc->lesson(lessonId).name() ) );
00183
00184
00185 if ( m_doc->lesson(lessonId).inPractice() ) {
00186 thisLessonElement.appendChild( newTextElement( KVTML_INPRACTICE, KVTML_TRUE ) );
00187 }
00188
00189
00190 if ( lessonId == m_doc->currentLesson() ) {
00191 thisLessonElement.appendChild( newTextElement( KVTML_CURRENT, KVTML_TRUE ) );
00192 }
00193
00194 for ( int i = 0; i < m_doc->entryCount(); ++i ) {
00195 if ( m_doc->entry(i)->lesson() == lessonId ) {
00196 QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
00197 entryElement.setAttribute( KVTML_ID, QString::number( i ) );
00198 thisLessonElement.appendChild(entryElement);
00199 }
00200 }
00201
00202 lessonsElement.appendChild( thisLessonElement );
00203 }
00204
00205 return true;
00206 }
00207
00208
00209 bool KEduVocKvtml2Writer::writeArticle( QDomElement &articleElement, int article )
00210 {
00212
00213 QDomElement singular = m_domDoc.createElement( KVTML_SINGULAR );
00214
00215 QDomElement definite = m_domDoc.createElement( KVTML_DEFINITE );
00216 QDomElement indefinite = m_domDoc.createElement( KVTML_INDEFINITE );
00217 QString def;
00218 QString indef;
00219
00220
00221 QString articleString;
00222 articleString = m_doc->identifier(article).article().article( KEduVocArticle::Singular, KEduVocArticle::Definite, KEduVocArticle::Masculine );
00223 if ( !articleString.isEmpty() ) {
00224 definite.appendChild( newTextElement( KVTML_MALE, articleString ) );
00225 }
00226 articleString = m_doc->identifier(article).article().article( KEduVocArticle::Singular, KEduVocArticle::Indefinite, KEduVocArticle::Masculine );
00227 if ( !articleString.isEmpty() ) {
00228 indefinite.appendChild( newTextElement( KVTML_MALE, articleString ) );
00229 }
00230
00231
00232 articleString = m_doc->identifier(article).article().article( KEduVocArticle::Singular, KEduVocArticle::Definite, KEduVocArticle::Feminine );
00233 if ( !articleString.isEmpty() ) {
00234 definite.appendChild( newTextElement( KVTML_FEMALE, articleString ) );
00235 }
00236 articleString = m_doc->identifier(article).article().article( KEduVocArticle::Singular, KEduVocArticle::Indefinite, KEduVocArticle::Feminine );
00237 if ( !articleString.isEmpty() ) {
00238 indefinite.appendChild( newTextElement( KVTML_FEMALE, articleString ) );
00239 }
00240
00241
00242 articleString = m_doc->identifier(article).article().article( KEduVocArticle::Singular, KEduVocArticle::Definite, KEduVocArticle::Neutral );
00243 if ( !articleString.isEmpty() ) {
00244 definite.appendChild( newTextElement( KVTML_NEUTRAL, articleString ) );
00245 }
00246 articleString = m_doc->identifier(article).article().article( KEduVocArticle::Singular, KEduVocArticle::Indefinite, KEduVocArticle::Neutral );
00247 if ( !articleString.isEmpty() ) {
00248 indefinite.appendChild( newTextElement( KVTML_NEUTRAL, articleString ) );
00249 }
00250
00251
00252
00253
00254 if ( definite.hasChildNodes() ) {
00255 singular.appendChild( definite );
00256 }
00257
00258 if ( indefinite.hasChildNodes() ) {
00259 singular.appendChild( indefinite );
00260 }
00261
00262 if ( singular.hasChildNodes() ) {
00263 articleElement.appendChild( singular );
00264 }
00265 return true;
00266 }
00267
00268 bool KEduVocKvtml2Writer::writeWordTypes( QDomElement &typesElement )
00269 {
00270 KEduVocWordType wt = m_doc->wordTypes();
00271 foreach( QString mainTypeName, wt.typeNameList() ) {
00272 kDebug() << "Writing type: " << mainTypeName;
00273 QDomElement typeDefinitionElement = m_domDoc.createElement( KVTML_CONTAINER );
00274 typeDefinitionElement.appendChild( newTextElement( KVTML_NAME, mainTypeName ) );
00275
00276 QString specialType = wt.specialType( mainTypeName );
00277 if ( !specialType.isEmpty() ) {
00278
00279 if ( specialType == m_doc->wordTypes().specialTypeNoun() ) {
00280 specialType = KVTML_SPECIALWORDTYPE_NOUN;
00281 }
00282 if ( specialType == m_doc->wordTypes().specialTypeVerb()) {
00283 specialType = KVTML_SPECIALWORDTYPE_VERB;
00284 }
00285 if ( specialType == m_doc->wordTypes().specialTypeAdverb()) {
00286 specialType = KVTML_SPECIALWORDTYPE_ADVERB;
00287 }
00288 if ( specialType == m_doc->wordTypes().specialTypeAdjective()) {
00289 specialType = KVTML_SPECIALWORDTYPE_ADJECTIVE;
00290 }
00291 typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, specialType ) );
00292 }
00293
00294
00295
00296 for(int i = 0; i<m_doc->entryCount(); i++) {
00297 QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
00298 for(int translation = 0; translation<m_doc->identifierCount(); translation++) {
00299
00300 if(m_doc->entry(i)->translation(translation).subType().isEmpty()) {
00301 if (m_doc->entry(i)->translation(translation).type()== mainTypeName) {
00302
00303 entryElement.setAttribute( KVTML_ID, QString::number( i ) );
00304
00305 QDomElement translationElement = m_domDoc.createElement( KVTML_TRANSLATION );
00306 translationElement.setAttribute( KVTML_ID, QString::number(translation) );
00307
00308 entryElement.appendChild(translationElement);
00309 }
00310 }
00311 }
00312 if (entryElement.hasChildNodes()) {
00313 typeDefinitionElement.appendChild(entryElement);
00314 }
00315 }
00316
00317
00318
00319 foreach( QString subTypeName, wt.subTypeNameList( mainTypeName ) ) {
00320 QDomElement subTypeDefinitionElement = m_domDoc.createElement( KVTML_CONTAINER );
00321 subTypeDefinitionElement.appendChild( newTextElement( KVTML_NAME, subTypeName ) );
00322 QString specialSubType = wt.specialSubType( mainTypeName, subTypeName );
00323 if ( !specialSubType.isEmpty() ) {
00324 if ( specialSubType == m_doc->wordTypes().specialTypeNounMale() ) {
00325 specialSubType = KVTML_SPECIALWORDTYPE_NOUN_MALE;
00326 }
00327 if ( specialSubType == m_doc->wordTypes().specialTypeNounFemale() ) {
00328 specialSubType = KVTML_SPECIALWORDTYPE_NOUN_FEMALE;
00329 }
00330 if ( specialSubType == m_doc->wordTypes().specialTypeNounNeutral() ) {
00331 specialSubType = KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL;
00332 }
00333 subTypeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, specialSubType ) );
00334 }
00335 typeDefinitionElement.appendChild( subTypeDefinitionElement );
00336
00337
00338
00339 for(int i = 0; i<m_doc->entryCount(); i++) {
00340 QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
00341 for(int translation = 0; translation<m_doc->identifierCount(); translation++) {
00342
00343 if(m_doc->entry(i)->translation(translation).subType() == subTypeName) {
00344 if (m_doc->entry(i)->translation(translation).type()== mainTypeName) {
00345
00346 entryElement.setAttribute( KVTML_ID, QString::number( i ) );
00347
00348 QDomElement translationElement = m_domDoc.createElement( KVTML_TRANSLATION );
00349 translationElement.setAttribute( KVTML_ID, QString::number(translation) );
00350
00351 entryElement.appendChild(translationElement);
00352 }
00353 }
00354 }
00355 if (entryElement.hasChildNodes()) {
00356 subTypeDefinitionElement.appendChild(entryElement);
00357 }
00358 }
00359 }
00360 typesElement.appendChild( typeDefinitionElement );
00361 }
00362 return true;
00363 }
00364
00365
00366 bool KEduVocKvtml2Writer::writeTenses( QDomElement &tensesElement )
00367 {
00368 foreach( QString tense, m_doc->tenseDescriptions() ) {
00369 if ( !( tense.isNull() ) ) {
00370 tensesElement.appendChild( newTextElement( KVTML_TENSE, tense ) );
00371 }
00372 }
00373
00374 return true;
00375 }
00376
00377
00378 bool KEduVocKvtml2Writer::writeUsages( QDomElement &usagesElement )
00379 {
00380 foreach( QString usage, m_doc->usages() ) {
00381 usagesElement.appendChild( newTextElement( KVTML_USAGE, usage ) );
00382 }
00383
00384 return true;
00385 }
00386
00387 bool KEduVocKvtml2Writer::writeEntries( QDomElement &entriesElement )
00388 {
00389
00390 for ( int i = 0; i < m_doc->entryCount(); ++i ) {
00391 KEduVocExpression *thisEntry = m_doc->entry( i );
00392
00393
00394 QDomElement entryElement = m_domDoc.createElement( KVTML_ENTRY );
00395
00396
00397 entryElement.setAttribute( KVTML_ID, QString::number( i ) );
00398
00399
00400 if(!thisEntry->isActive()) {
00401 entryElement.appendChild( newTextElement( KVTML_DEACTIVATED, KVTML_TRUE ) );
00402 }
00403
00404
00405 if ( thisEntry->sizeHint() > 0 ) {
00406 entryElement.appendChild( newTextElement( KVTML_SIZEHINT, QString::number( thisEntry->sizeHint() ) ) );
00407 }
00408
00409
00410 foreach( int trans, thisEntry->translationIndices() ) {
00411
00412 QDomElement translation = m_domDoc.createElement( KVTML_TRANSLATION );
00413 translation.setAttribute( KVTML_ID, QString::number( trans ) );
00414 writeTranslation( translation, thisEntry->translation( trans ) );
00415 entryElement.appendChild( translation );
00416 }
00417
00418 entriesElement.appendChild( entryElement );
00419 }
00420 return true;
00421 }
00422
00423
00424 bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEduVocTranslation &translation )
00425 {
00426
00427 translationElement.appendChild( newTextElement( KVTML_TEXT, translation.text() ) );
00428
00429
00430 if ( !translation.comment().isEmpty() ) {
00431 translationElement.appendChild( newTextElement( KVTML_COMMENT, translation.comment() ) );
00432 }
00433
00434
00435 if ( !translation.pronunciation().isEmpty() ) {
00436 translationElement.appendChild( newTextElement( KVTML_PRONUNCIATION, translation.pronunciation() ) );
00437 }
00438
00439
00440
00441 for ( int i = 0; i < m_doc->identifierCount(); ++i ) {
00442
00443 QString thisFriend = translation.falseFriend( i );
00444 if ( !thisFriend.isEmpty() ) {
00445
00446 QDomElement thisFriendElement = newTextElement( KVTML_FALSEFRIEND, thisFriend );
00447 thisFriendElement.setAttribute( KVTML_FROMID, QString::number( i ) );
00448 translationElement.appendChild( thisFriendElement );
00449 }
00450 }
00451
00452
00453 if ( !translation.antonym().isEmpty() ) {
00454 translationElement.appendChild( newTextElement( KVTML_ANTONYM, translation.antonym() ) );
00455 }
00456
00457
00458 if ( !translation.synonym().isEmpty() ) {
00459 translationElement.appendChild( newTextElement( KVTML_SYNONYM, translation.synonym() ) );
00460 }
00461
00462
00463 if ( !translation.example().isEmpty() ) {
00464 translationElement.appendChild( newTextElement( KVTML_EXAMPLE, translation.example() ) );
00465 }
00466
00467
00468 foreach( QString usage, translation.usages() ) {
00469 translationElement.appendChild( newTextElement( KVTML_USAGE, usage ) );
00470 }
00471
00472
00473 if ( !translation.paraphrase().isEmpty() ) {
00474 translationElement.appendChild( newTextElement( KVTML_PARAPHRASE, translation.paraphrase() ) );
00475 }
00476
00477
00478 for ( int i = 0; i < m_doc->identifierCount(); ++i ) {
00479 KEduVocGrade thisGrade = translation.gradeFrom( i );
00480 if ( thisGrade.practiceCount() > 0 ) {
00481 QDomElement gradeElement = m_domDoc.createElement( KVTML_GRADE );
00482 gradeElement.setAttribute( KVTML_FROMID, QString::number( i ) );
00483
00484 gradeElement.appendChild( newTextElement( KVTML_CURRENTGRADE, QString::number( thisGrade.grade() ) ) );
00485
00486
00487 gradeElement.appendChild( newTextElement( KVTML_COUNT, QString::number( thisGrade.practiceCount() ) ) );
00488
00489
00490 gradeElement.appendChild( newTextElement( KVTML_ERRORCOUNT, QString::number( thisGrade.badCount() ) ) );
00491
00492
00493 gradeElement.appendChild( newTextElement( KVTML_DATE, thisGrade.practiceDate().toString( Qt::ISODate ) ) );
00494
00495 translationElement.appendChild( gradeElement );
00496 }
00497 }
00498
00499
00500 foreach ( QString tense, translation.conjugationTenses() ) {
00501 QDomElement thisElement = m_domDoc.createElement( KVTML_CONJUGATION );
00502 writeConjugation( thisElement, translation.conjugation(tense), tense );
00503 translationElement.appendChild( thisElement );
00504 }
00505
00506
00507 if ( !translation.comparison().isEmpty() ) {
00508 QDomElement comparisonElement = m_domDoc.createElement( KVTML_COMPARISON );
00509 writeComparison( comparisonElement, translation.comparison() );
00510 translationElement.appendChild( comparisonElement );
00511 }
00512
00513
00514 if ( !translation.multipleChoice().isEmpty() ) {
00515 QDomElement multipleChoiceElement = m_domDoc.createElement( KVTML_MULTIPLECHOICE );
00516 writeMultipleChoice( multipleChoiceElement, translation.multipleChoice() );
00517 translationElement.appendChild( multipleChoiceElement );
00518 }
00519
00520
00521 if ( !translation.imageUrl().isEmpty() ) {
00522 QString urlString;
00523 if ( translation.imageUrl().url().startsWith(m_doc->url().upUrl().url()) ) {
00524
00525 urlString = KUrl::relativeUrl( m_doc->url() , translation.imageUrl() );
00526 } else {
00527 urlString = translation.imageUrl().url();
00528 }
00529 translationElement.appendChild( newTextElement( KVTML_IMAGE, urlString ) );
00530 }
00531
00532
00533 if ( !translation.soundUrl().isEmpty() ) {
00534 QString urlString;
00535 if ( translation.soundUrl().url().startsWith(m_doc->url().upUrl().url()) ) {
00536
00537 urlString = KUrl::relativeUrl( m_doc->url() , translation.soundUrl() );
00538 } else {
00539 urlString = translation.soundUrl().url();
00540 }
00541 translationElement.appendChild( newTextElement( KVTML_SOUND, urlString ) );
00542 }
00543
00544 return true;
00545 }
00546
00547 bool KEduVocKvtml2Writer::writeComparison( QDomElement &comparisonElement, const KEduVocComparison &comparison )
00548
00549
00550
00551
00552
00553
00554
00555 {
00556 comparisonElement.appendChild( newTextElement( KVTML_ABSOLUTE, comparison.l1() ) );
00557 comparisonElement.appendChild( newTextElement( KVTML_COMPARATIVE, comparison.l2() ) );
00558 comparisonElement.appendChild( newTextElement( KVTML_SUPERLATIVE, comparison.l3() ) );
00559
00560 return true;
00561 }
00562
00563
00564 bool KEduVocKvtml2Writer::writeMultipleChoice( QDomElement &multipleChoiceElement, const KEduVocMultipleChoice &mc )
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574 {
00575 QStringList choices = mc.choices();
00576 for ( int i = 0; i < choices.size(); ++i ) {
00577 multipleChoiceElement.appendChild( newTextElement( KVTML_CHOICE, choices[i] ) );
00578 }
00579
00580 return true;
00581 }
00582
00583 bool KEduVocKvtml2Writer::writeConjugation( QDomElement &conjugationElement,
00584 const KEduVocConjugation &conjugation, const QString &tense )
00585 {
00586
00587 conjugationElement.appendChild( newTextElement(KVTML_TENSE, tense) );
00588
00589 for ( KEduVocConjugation::ConjugationNumber num = KEduVocConjugation::Singular; num < KEduVocConjugation::NumberMAX; num = KEduVocConjugation::ConjugationNumber(num +1) ) {
00590 QString first = conjugation.conjugation(
00591 KEduVocConjugation::First, num );
00592 QString second = conjugation.conjugation(
00593 KEduVocConjugation::Second, num );
00594 QString third_male = conjugation.conjugation(
00595 KEduVocConjugation::ThirdMale, num );
00596 QString third_female = conjugation.conjugation(
00597 KEduVocConjugation::ThirdFemale, num );
00598 QString third_neutral = conjugation.conjugation(
00599 KEduVocConjugation::ThirdNeutralCommon, num );
00600
00601 if ( !first.isEmpty() || !second.isEmpty() || !third_female.isEmpty() ||
00602 !third_male.isEmpty() || !third_neutral.isEmpty() ) {
00603 QDomElement number;
00604 switch (num) {
00605 case KEduVocConjugation::Singular:
00606 number = m_domDoc.createElement( KVTML_SINGULAR );
00607 break;
00608 case KEduVocConjugation::Dual:
00609 number = m_domDoc.createElement( KVTML_DUAL );
00610 break;
00611 case KEduVocConjugation::Plural:
00612 number = m_domDoc.createElement( KVTML_PLURAL );
00613 break;
00614 }
00615
00616 number.appendChild( newTextElement( KVTML_1STPERSON, first ) );
00617 number.appendChild( newTextElement( KVTML_2NDPERSON, second ) );
00618 number.appendChild( newTextElement( KVTML_THIRD_MALE, third_male ) );
00619 number.appendChild( newTextElement( KVTML_THIRD_FEMALE, third_female ) );
00620 number.appendChild( newTextElement( KVTML_THIRD_NEUTRAL_COMMON, third_neutral ) );
00621
00622 conjugationElement.appendChild( number );
00623 }
00624 }
00625
00626 return true;
00627 }
00628
00629 QDomElement KEduVocKvtml2Writer::newTextElement( const QString &elementName, const QString &text )
00630 {
00631 QDomElement retval = m_domDoc.createElement( elementName );
00632 QDomText textNode = m_domDoc.createTextNode( text );
00633 retval.appendChild( textNode );
00634 return retval;
00635 }
00636
00637 bool KEduVocKvtml2Writer::writePersonalPronoun(QDomElement & pronounElement, const KEduVocPersonalPronoun & pronoun)
00638 {
00639
00640 if ( pronoun.maleFemaleDifferent() ) {
00641 pronounElement.appendChild( m_domDoc.createElement( KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT ) );
00642 }
00643 if ( pronoun.neutralExists() ) {
00644 pronounElement.appendChild( m_domDoc.createElement( KVTML_THIRD_PERSON_NEUTRAL_EXISTS ) );
00645 }
00646 if ( pronoun.dualExists() ) {
00647 pronounElement.appendChild( m_domDoc.createElement( KVTML_DUAL_EXISTS ) );
00648 }
00649
00650 for ( KEduVocConjugation::ConjugationNumber num = KEduVocConjugation::Singular; num < KEduVocConjugation::NumberMAX; num = KEduVocConjugation::ConjugationNumber(num +1) ) {
00651 QString first = pronoun.personalPronoun(
00652 KEduVocConjugation::First, num );
00653 QString second = pronoun.personalPronoun(
00654 KEduVocConjugation::Second, num );
00655 QString third_male = pronoun.personalPronoun(
00656 KEduVocConjugation::ThirdMale, num );
00657 QString third_female = pronoun.personalPronoun(
00658 KEduVocConjugation::ThirdFemale, num );
00659 QString third_neutral = pronoun.personalPronoun(
00660 KEduVocConjugation::ThirdNeutralCommon, num );
00661
00662 if ( !first.isEmpty() || !second.isEmpty() || !third_female.isEmpty() ||
00663 !third_male.isEmpty() || !third_neutral.isEmpty() ) {
00664 QDomElement number;
00665 switch (num) {
00666 case KEduVocConjugation::Singular:
00667 number = m_domDoc.createElement( KVTML_SINGULAR );
00668 break;
00669 case KEduVocConjugation::Dual:
00670 number = m_domDoc.createElement( KVTML_DUAL );
00671 break;
00672 case KEduVocConjugation::Plural:
00673 number = m_domDoc.createElement( KVTML_PLURAL );
00674 break;
00675 }
00676
00677 number.appendChild( newTextElement( KVTML_1STPERSON, first ) );
00678 number.appendChild( newTextElement( KVTML_2NDPERSON, second ) );
00679 number.appendChild( newTextElement( KVTML_THIRD_MALE, third_male ) );
00680 number.appendChild( newTextElement( KVTML_THIRD_FEMALE, third_female ) );
00681 number.appendChild( newTextElement( KVTML_THIRD_NEUTRAL_COMMON, third_neutral ) );
00682
00683 if ( pronoun.maleFemaleDifferent() ) {
00684 number.appendChild( m_domDoc.createElement( KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT ) );
00685 }
00686 if ( pronoun.neutralExists() ) {
00687 number.appendChild( m_domDoc.createElement( KVTML_THIRD_PERSON_NEUTRAL_EXISTS ) );
00688 }
00689 pronounElement.appendChild( number );
00690 }
00691 }
00692 return true;
00693 }
00694