From bd9e6617827818fd043452c08c606f07b78014a0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdesdk@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kbabel/datatools/xml/Makefile.am | 19 +++ kbabel/datatools/xml/kbabel_xmltool.desktop | 105 ++++++++++++++ kbabel/datatools/xml/main.cc | 206 ++++++++++++++++++++++++++++ kbabel/datatools/xml/main.h | 59 ++++++++ 4 files changed, 389 insertions(+) create mode 100644 kbabel/datatools/xml/Makefile.am create mode 100644 kbabel/datatools/xml/kbabel_xmltool.desktop create mode 100644 kbabel/datatools/xml/main.cc create mode 100644 kbabel/datatools/xml/main.h (limited to 'kbabel/datatools/xml') diff --git a/kbabel/datatools/xml/Makefile.am b/kbabel/datatools/xml/Makefile.am new file mode 100644 index 00000000..dbba4740 --- /dev/null +++ b/kbabel/datatools/xml/Makefile.am @@ -0,0 +1,19 @@ + +INCLUDES = -I$(srcdir)/../../common -I../../common $(all_includes) +kbabel_xmltool_la_LIBADD = $(LIB_KIO) ../../common/libkbabelcommon.la + +####### Files + +kde_module_LTLIBRARIES = kbabel_xmltool.la + +kbabel_xmltool_la_SOURCES = main.cc + +kbabel_xmltool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined + +noinst_HEADERS = main.h + +kbabel_xmltool_la_METASOURCES = AUTO + +service_DATA = kbabel_xmltool.desktop +servicedir = $(kde_servicesdir) + diff --git a/kbabel/datatools/xml/kbabel_xmltool.desktop b/kbabel/datatools/xml/kbabel_xmltool.desktop new file mode 100644 index 00000000..2b03bef9 --- /dev/null +++ b/kbabel/datatools/xml/kbabel_xmltool.desktop @@ -0,0 +1,105 @@ +[Desktop Entry] +Name=XML Validation for KBabel +Name[bg]=XML валидност - KBabel +Name[bs]=XML provjera za KBabel +Name[ca]=Validació XML per a KBabel +Name[cs]=Validace XML pro KBabel +Name[cy]=Dilysiant XML i KBabel +Name[da]=XML-validering for KBabel +Name[de]=XML-Überprüfung für KBabel +Name[el]=Έλεγχος εγκυρότητας XML για το KBabel +Name[es]=Validación XML para KBabel +Name[et]=KBabeli XML-i kontrollija +Name[eu]=XML balidazioa KBabel-entzat +Name[fa]=اعتبارسنجی XML برای KBabel +Name[fi]=XML-validointi KBabelissa +Name[fr]=Validation XML pour KBabel +Name[ga]=Bailíochtú XML le haghaidh KBabel +Name[gl]=Validación de XML para KBabel +Name[hi]=के-बेबल के लिए एक्सएमएल वेलिडेशन +Name[hu]=XML-ellenőrzés a KBabelben +Name[is]=XML staðfesting fyrir KBabel +Name[it]=Convalidatore di XML per KBabel +Name[ja]=KBabel XML 検証 +Name[ka]=XML დამოწმება KBabel-თვის +Name[kk]=KBabel-дың XML-ды тексеруі +Name[lt]=KBabel XML patikros įrankis +Name[ms]=Pengesah XML untuk KBabel +Name[nb]=XML-sjekk i KBabel +Name[nds]=XML-Prööv för KBabel +Name[ne]=केब्याबलका लागि एक्सएमएल प्रमाणीकरण +Name[nl]=XML-validatie voor KBabel +Name[nn]=XML-sjekk i KBabel +Name[pa]=ਕੇਬਬੇਲ ਲਈ XML ਪਰਮਾਣਕ +Name[pl]=Sprawdzenie XML w KBabel +Name[pt]=Validação de XML para o KBabel +Name[pt_BR]=Validação XML para o KBabel +Name[ru]=Проверка XML для KBabel +Name[sk]=Kontrola XML pre KBabel +Name[sl]=Potrjevanje XML za KBabel +Name[sr]=Овера XML-а за KBabel +Name[sr@Latn]=Overa XML-a za KBabel +Name[sv]=Validering av XML för Kbabel +Name[ta]= Kபாபேலுக்கு XML செல்லுபடி சோதனை +Name[tg]=Тафтиши XML барои KBabel +Name[tr]=KBabel için XML Onaylama +Name[uk]=Перевірка XML для KBabel +Name[zh_CN]=KBabel 的 XML 检查器 +Name[zh_TW]=KBabel XML 檢查器 +ValidationString=XML tags +X-KDE-Library=kbabel_xmltool +Type=Service +Commands=validate +Comment=Check Tags +Comment[bg]=Проверка на таговете +Comment[br]=Gwiriekaat al liketennoù +Comment[bs]=Provjeri tagove +Comment[ca]=Comprova les etiquetes +Comment[cs]=Zkontrolovat značky +Comment[cy]=Dilysu tagiau +Comment[da]=Tjek mærker +Comment[de]=Prüfung der Tags in Übersetzungen +Comment[el]=Έλεγχος ετικετών +Comment[es]=Comprobar etiquetas +Comment[et]=Siltide kontroll +Comment[eu]=Egiaztatu etiketak +Comment[fa]=بررسی برچسبها +Comment[fi]=Tarkista merkintäkoodit +Comment[fr]=Vérifier les balises +Comment[ga]=Seiceáil Clibeanna +Comment[gl]=Verificación das marcas XML/HTML +Comment[he]=בודק תגיות +Comment[hi]=टैग्स जांच करें +Comment[hu]=A tag-ek ellenőrzése +Comment[is]=Athuga tög +Comment[it]=Controlla i tag +Comment[ja]=タグを検証 +Comment[ka]=ჭდეების შემოწმება +Comment[kk]=Тегтерді тексеру +Comment[lt]=Tikrinti gaires +Comment[ms]=Periksa Tag +Comment[nb]=Sjekk tagger +Comment[nds]=XML-Betekers pröven +Comment[ne]=ट्याग जाँच गर्नुहोस् +Comment[nl]=Tags controleren +Comment[nn]=Sjekk taggar +Comment[pa]=ਟੈਗ ਜਾਂਚ +Comment[pl]=Sprawdzenie znaczników XML +Comment[pt]=Verificação das Marcas +Comment[pt_BR]=Verifica Tags +Comment[ru]=Проверить теги +Comment[sk]=Kontrola značiek +Comment[sl]=Preveri značke +Comment[sr]=Провери ознаке +Comment[sr@Latn]=Proveri oznake +Comment[sv]=Kontrollera taggar +Comment[ta]= ஒட்டு சரிபார்ப்பு +Comment[tg]=Тафтиш кардани тегҳо +Comment[tr]=Biçim İmlerini Sına +Comment[uk]=Перевірити мітки +Comment[zh_CN]=检查标签 +Comment[zh_TW]=檢查標籤 +ServiceTypes=KDataTool,KBabelValidator +DataType=CatalogItem +DataMimeTypes=application/x-kbabel-catalogitem +ReadOnly=true diff --git a/kbabel/datatools/xml/main.cc b/kbabel/datatools/xml/main.cc new file mode 100644 index 00000000..d9549014 --- /dev/null +++ b/kbabel/datatools/xml/main.cc @@ -0,0 +1,206 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2002-2003 Stanislav Visnovsky + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" + +#include + +#include +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_xmltool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +XMLTool::XMLTool( QObject* parent, const char* name, const QStringList & ) + : KDataTool( parent, name ), _cache_origin( 0 ) +{ + i18n( "what check found errors", "XML tags" ); +} + +bool XMLTool::run( const QString& command, void* data, const QString& datatype, const QString& mimetype ) +{ + if ( command != "validate" ) + { + kdDebug(KBABEL) << "XML Tool does only accept the command 'validate' and 'shortcut'" << endl; + kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; + return FALSE; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "XML Tool only accepts datatype CatalogItem" << endl; + return FALSE; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "XML Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; + return FALSE; + } + + if( command == "validate" ) + { + CatalogItem* item = (CatalogItem*)(data); + + if( _cache_origin != item->project() ) + { + _context = item->project()->miscSettings().contextInfo; + _cache_origin = item->project(); + } + + uint correctnessLevel = 0; + QString msgid = item->msgid().first(); + msgid.replace( "\\\"", "\"" ); // Change '\"' to '"' + msgid.replace( QRegExp( "&(?![a-zA-Z0-9]+;)" ), "&" ); + msgid.replace( _context, "" ); + msgid.replace("\n",""); // delete newlines + + if( _levelCache.contains(msgid) ) + { + correctnessLevel = _levelCache[msgid]; + } + else + { + // identify the level of correctness + if( isFullyCompliant(msgid) ) + { + correctnessLevel = 0; + } + else if( isNonCaseCompliant(msgid) ) + { + correctnessLevel = 1; + } + else if( isNonCaseWithoutCommonCompliant(msgid) ) + { + correctnessLevel = 2; + } + else + { + correctnessLevel = 3; + } + + _levelCache[msgid] = correctnessLevel; + } + + bool hasError = false; + + if(!item->isUntranslated()) + { + QStringList str = item->msgstr(true); + for( QStringList::Iterator form = str.begin() ; form != str.end() ; form++ ) + { + QString text=(*form); + text.replace( "\\\"", "\"" ); // Change '\"' to '"' + text.replace( QRegExp( "&(?![a-zA-Z0-9]+;)" ), "&" ); + + // isNonCaseWithoutCommonCompliant can fail + // even though higher level checks works + // see case 2. + switch( correctnessLevel ) + { + case 0: hasError = !isFullyCompliant(text); break; + case 1: hasError = !isNonCaseCompliant(text); break; + case 2: hasError = !isNonCaseWithoutCommonCompliant(text); + if (hasError) + { + hasError = !isNonCaseCompliant(text) || + !isFullyCompliant(text); + } + break; + case 3: hasError = false; break; // the original is broken + default: kdWarning() << "No compliance level, this should not happen" << endl; + } + } + } + + if(hasError) + { + item->appendError( "XML tags" ); + } + else + { + item->removeError( "XML tags" ); + } + + return !hasError; + } + return FALSE; +} + +bool XMLTool::isFullyCompliant( const QString& text) +{ + QDomDocument doc; + return doc.setContent("" + text + "" ); +} + +bool XMLTool::isNonCaseCompliant( const QString& text) +{ + QDomDocument doc; + QString test = text.lower(); + return doc.setContent("" + test + "" ); +} + +bool XMLTool::isNonCaseWithoutCommonCompliant( const QString& text) +{ + QDomDocument doc; + QString test = text.lower(); + QRegExp rx( "(
)|(
)|(

)||(<\\w+@(\\w+.)*\\w+>)" ); + test.replace( rx, "" ); + + QString a; + do + { + a = test; + test.replace( QRegExp("<[^_:A-Za-z/]"), "" ); + } while( a!=test); + + test.replace( QRegExp("<$"), "" ); + + return doc.setContent("" + test + "" ); +} + +#include "main.moc" diff --git a/kbabel/datatools/xml/main.h b/kbabel/datatools/xml/main.h new file mode 100644 index 00000000..65b231e8 --- /dev/null +++ b/kbabel/datatools/xml/main.h @@ -0,0 +1,59 @@ +/* This file is part of KBabel + based on Copyright (C) 1998, 1999 Torben Weis + 2002-2003 Stanislav Visnovsky + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#ifndef __main_h__ +#define __main_h__ + +#include "kbproject.h" + +#include +#include + +class XMLTool : public KDataTool +{ + Q_OBJECT + +public: + XMLTool( QObject* parent, const char* name, const QStringList & ); + virtual bool run( const QString& command, void* data, const QString& datatype, const QString& mimetype); +private: + bool isFullyCompliant( const QString& text); + bool isNonCaseCompliant( const QString& text); + bool isNonCaseWithoutCommonCompliant( const QString& text); + + QMap _levelCache; + + KBabel::Project::Ptr _cache_origin; + QRegExp _context; +}; + +#endif -- cgit v1.2.1