From e9ae80694875f869892f13f4fcaf1170a00dea41 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/kdewebdev@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- quanta/parsers/dtd/Makefile.am | 11 + quanta/parsers/dtd/dtd.cpp | 415 ++++++++++++++++++++++++++++++++++ quanta/parsers/dtd/dtd.h | 64 ++++++ quanta/parsers/dtd/dtdparser.cpp | 362 +++++++++++++++++++++++++++++ quanta/parsers/dtd/dtdparser.h | 55 +++++ quanta/parsers/dtd/dtepcreationdlg.ui | 152 +++++++++++++ 6 files changed, 1059 insertions(+) create mode 100644 quanta/parsers/dtd/Makefile.am create mode 100644 quanta/parsers/dtd/dtd.cpp create mode 100644 quanta/parsers/dtd/dtd.h create mode 100644 quanta/parsers/dtd/dtdparser.cpp create mode 100644 quanta/parsers/dtd/dtdparser.h create mode 100644 quanta/parsers/dtd/dtepcreationdlg.ui (limited to 'quanta/parsers/dtd') diff --git a/quanta/parsers/dtd/Makefile.am b/quanta/parsers/dtd/Makefile.am new file mode 100644 index 00000000..80f647fb --- /dev/null +++ b/quanta/parsers/dtd/Makefile.am @@ -0,0 +1,11 @@ +noinst_LTLIBRARIES = libdtdparser.la +libdtdparser_la_SOURCES = dtepcreationdlg.ui dtdparser.cpp + +METASOURCES = AUTO + +AM_CPPFLAGS = -I$(top_srcdir)/quanta/parsers \ + -I$(top_srcdir)/quanta/utility \ + -I$(top_srcdir)/quanta/dialogs \ + -I$(top_builddir)/quanta/dialogs \ + -I$(top_srcdir)/lib \ + $(LIBXML_CFLAGS) $(all_includes) diff --git a/quanta/parsers/dtd/dtd.cpp b/quanta/parsers/dtd/dtd.cpp new file mode 100644 index 00000000..18e3d712 --- /dev/null +++ b/quanta/parsers/dtd/dtd.cpp @@ -0,0 +1,415 @@ +/*************************************************************************** + dtdparser.cpp - description + ------------------- + begin : Tue Jul 30 15:26:20 EEST 2002 + copyright : (C) 2002 by Jason P. Hanley + (C) 2002, 2003 Andras Mantia + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "dtd.h" +#include "../quantacommon.h" +#include "../qextfileinfo.h" + + +DTD::DTD(const KURL &dtdURL, const QString &dtepDir) +{ + m_dtdURL = dtdURL; + m_dtepDir = dtepDir + "/"+QFileInfo(dtdURL.fileName()).baseName(); //TODO: get the dir name from the DTD or from the user +} + +DTD::~DTD() +{ +} + +QStringList DTD::getTags() +{ + return tags; +} + +AttributeList* DTD::getTagAttributes(QString tag) +{ + return tagAttributes.find(tag); +} + + +QStringList DTD::getTextCompletion(QString tag) +{ + return QStringList(); +} + +void DTD::printContents() +{ + for ( QStringList::Iterator tagIt = tags.begin(); tagIt != tags.end(); ++tagIt ) { + QString tag = *tagIt; + kdDebug(24000) << tag << endl; + AttributeList *attributes = getTagAttributes(tag); + for ( uint i = 0; i < attributes->count(); i++) + { + Attribute *attribute = attributes->at(i); + QString s = " " + attribute->name + ": "; + for (uint j = 0; j < attribute->values.count(); j++) + { + s += attribute->values[j] + ", "; + } + kdDebug(24000) << s << endl; + } + } +} + +void DTD::writeTagFiles() +{ + QString dirName = m_dtepDir; + KURL u; + u.setPath(dirName); + if (!QExtFileInfo::createDir(dirName)) { + QuantaCommon::dirCreationError(0, u); + return; + } + dirName.append("/"); + for ( QStringList::Iterator tagIt = tags.begin(); tagIt != tags.end(); ++tagIt ) { + QString tag = *tagIt; + + QFile file( dirName + tag.lower() + ".tag" ); + if ( file.open( IO_WriteOnly ) ) { + QTextStream stream( &file ); + stream.setEncoding(QTextStream::UnicodeUTF8); + stream << "" << endl + << "" << endl + << "" << endl << endl; + + AttributeList *attributes = getTagAttributes(tag); + stream << QuantaCommon::xmlFromAttributes(attributes); + + stream << "" << endl + << "" << endl; + + file.close(); + } else { + kdDebug(24000) << "Unable to write tag file: " << file.name() << endl; + } + } + + KConfig config(dirName + "description.rc"); + config.setGroup("General"); + config.writeEntry("Name", QFileInfo(m_dtdURL.fileName()).baseName()); //TODO: get from the DTD! + config.writeEntry("NickName", QFileInfo(m_dtdURL.fileName()).baseName()); //TODO: get from the user! + config.sync(); +} + +bool DTD::parseDTD(const KURL &url) +{ + QString fileName = QString::null; + if (!KIO::NetAccess::download(url, fileName)) + { + KMessageBox::error(0, i18n("Cannot download the DTD from %1.").arg(url.prettyURL(0, KURL::StripFileProtocol))); + return false; + } + QFile file(fileName); + if (file.open(IO_ReadOnly)) + { + QTextStream fileStream(&file); + fileStream.setEncoding(QTextStream::UnicodeUTF8); + QString entireDTD = fileStream.read(); + file.close(); + removeComments(entireDTD); + + QString line; + QStringList lines = QStringList::split("\n",entireDTD); + QStringList::Iterator it = lines.begin(); + while (it != lines.end()) { + line = *it; + + if (line.startsWith("<")) { + while (!line.endsWith(">") && it != lines.end()) { + ++it; + line += " \\end" + *it; + } + } else if (line.startsWith("%")) { + while (!line.endsWith(";") && it != lines.end()) { + ++it; + line += *it; + } + } + + line = line.stripWhiteSpace(); + line = line.simplifyWhiteSpace(); + + //kdDebug(24000) << "Parsed line is: " << line << endl; + + if ( line.startsWith("")) + { + parseDTDEntity(line); + } + else + if (line.startsWith("")) + { + parseDTDElement(line); + } + else + if (line.startsWith("")) + { + parseDTDAttlist(line); + } + else + if (line.startsWith("%") && line.endsWith(";")) + { + line.remove(0,1); + line.truncate(line.length()-1); + KURL entityURL = url; + entityURL.setPath(url.directory()+ "/" + line + ".ent"); + parseDTD(entityURL); + } else + { + kdDebug(24000) << QString("Unknown tag: [%1]").arg(line) << endl; + } + + if (it != lines.end()) ++it; + } + } +} + +void DTD::parseDTDEntity(QString line) { + QString name; + QString *value; + + line.replace("\\end", " "); + name = line.mid(11); + int firstSpace = name.find(' '); + name = name.remove(firstSpace, name.length()-firstSpace); + + value = new QString(line.mid(11+firstSpace)); + value->remove(0, value->find("\"")+1); + value->remove(value->findRev("\""), value->length()); + + parseDTDReplace(value); + stripSpaces(value); + + entities.insert(name, value); + + //kdDebug() << "Entity --- Name: " << name << " --- Value: " << *value << endl; +} + +void DTD::parseDTDElement(const QString &l) { + QString name; + QString *value; + + QString line = l; + line.replace("\\end", " "); + name = line.mid(10); + int firstSpace = name.find(' '); + name.remove(firstSpace, name.length()-firstSpace); + + value = new QString(line.mid(10+firstSpace)); + //value->remove(0, value->find("\"")+1); + value->remove(value->find(">"), 10000); + + parseDTDReplace(&name); + parseDTDReplace(value); + + if ( name.startsWith("(") && name.endsWith(")") ) { + name.remove(0,1); + name.remove(name.length()-1,1); + QStringList multipleTags = QStringList::split("|", name); + QStringList::Iterator it = multipleTags.begin(); + while(it != multipleTags.end()) { + name = *it; + name = name.stripWhiteSpace(); + elements.insert(name, value); + tags.append(name); + //kdDebug() << "Element --- Name: " << name << " --- Value: " << *value << endl; + ++it; + } + } else { + elements.insert(name, value); + tags.append(name); + //kdDebug() << "Element --- Name: " << name << " --- Value: " << *value << endl; + } +} + +void DTD::parseDTDAttlist(const QString &l) { + QString name; + QString *value; + + QString line = l; + line.replace("\\end", " "); + name = line.mid(10); + int firstSpace = name.find(' '); + name.remove(firstSpace, name.length()-firstSpace); + + value = new QString(line.mid(10+firstSpace)); + //value->remove(0, value->find("\"")+1); + value->remove(value->find(">"), 10000); + + parseDTDReplace(&name); + parseDTDReplace(value); + + if ( name.startsWith("(") && name.endsWith(")") ) { + name.remove(0,1); + name.remove(name.length()-1,1); + QStringList multipleTags = QStringList::split("|", name); + QStringList::Iterator it = multipleTags.begin(); + while(it != multipleTags.end()) { + name = *it; + name = name.stripWhiteSpace(); + //elements.insert(name, value); + parseTagAttributeValues(name, value); + //kdDebug() << "Attlist --- Name: " << name << " --- Value: " << *value << endl; + ++it; + } + } else { + //elements.insert(name, value); + parseTagAttributeValues(name, value); + //kdDebug() << "Attlist --- Name: " << name << " --- Value: " << *value << endl; + } + +} + +void DTD::parseTagAttributeValues(const QString &name, QString *value) { + AttributeList *attributes = new AttributeList(); + + QStringList attrLines = QStringList::split("\\end",*value); + QStringList::Iterator lineIt = attrLines.begin(); + while (lineIt != attrLines.end()) //iterate through the attribute lines + { + //split the attribute line + QStringList all = QStringList::split(" ", *lineIt); + QStringList::Iterator it = all.begin(); + while(it != all.end()) + { + Attribute *attr = new Attribute(); + attr->name = *it; + //kdDebug() << "Inserting for tag " << name << ": " << *it << endl; + ++it; + + QString values = *it; + //list of possible values + if ( values.startsWith("(") && values.endsWith(")") ) + { + values.remove(0,1); + values.remove(values.length()-1,1); + attr->values = QStringList::split("|", values); + QString s = (attr->values[0]+attr->values[1]).lower(); + stripSpaces(&s); + if ((s == "truefalse") || (s == "falsetrue")) + { + attr->type = "check"; + } else + { + attr->type = "list"; + } + } else + { + attr->values = values; + attr->type = "input"; + } + + //kdDebug() << " --- values: " << *it << endl; + if (it != all.end()) + { + ++it; + QString s=*it; + if (s.startsWith("\"") && s.endsWith("\"") && it!=all.end()) + { + s.remove(0,1); + s.remove(s.length()-1,1); + attr->defaultValue = s; + } + if (s.startsWith("#") && it != all.end()) + { + s.remove(0,1); + attr->status = s.lower(); + } + if (*it == "#FIXED" && it != all.end()) + { + ++it; + attr->values.append(*it); + } + } + + if (it != all.end()) + { + ++it; + } + attributes->append(attr); + } + ++lineIt; + } + tagAttributes.insert(name, attributes); +} + +void DTD::parseDTDReplace(QString *value) { + int begin, end; + begin = value->find("%"); + end = value->find(";"); + while (begin != -1 && end != -1) { + QString replaceText = value->mid(begin+1, end-begin-1); + QString *replaceValue = entities.find(replaceText); + + if (replaceValue != 0L) { + value->replace(begin, end-begin+1, *replaceValue); + } else { + kdDebug(24000) << "Can not find entity: " << replaceText << endl; + return; + } + + begin = value->find("%"); + end = value->find(";"); + } +} + +void DTD::stripSpaces(QString *value) { + int index=-1; + while ( (index=value->find(' ',++index)) != -1 ) { + if ( value->findRev('(',index) != -1 && value->find(')',index) != -1) + value->remove(index,1); + } +} + +void DTD::removeComments(QString &value) { + int begin, end; + begin = value.find("",begin+2); + while (begin != -1 && end != -1) { + value.remove(begin, end-begin+3); + begin = value.find("",begin+2); + } + + begin = value.find("--"); + end = value.find("--",begin+2); + while (begin != -1 && end != -1) { + value.remove(begin, end-begin+2); + begin = value.find("--"); + end = value.find("--",begin+2); + } + + value.replace(QRegExp(""), ""); +} + +bool DTD::parseDTD() +{ + return parseDTD(m_dtdURL); +} diff --git a/quanta/parsers/dtd/dtd.h b/quanta/parsers/dtd/dtd.h new file mode 100644 index 00000000..45b0e213 --- /dev/null +++ b/quanta/parsers/dtd/dtd.h @@ -0,0 +1,64 @@ +/*************************************************************************** + dtdparser.cpp - description + ------------------- + begin : Tue Jul 30 15:26:20 EEST 2002 + copyright : (C) 2002 by Jason P. Hanley + (C) 2002, 2003 Andras Mantia + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef DTD_H +#define DTD_H + +//qt includes +#include + +//app includes +#include "qtag.h" + +class KURL; + +class DTD +{ + +public: + DTD(const KURL &dtdURL, const QString& dtepDir); + ~DTD(); + +public: + QStringList getTags(); + AttributeList* getTagAttributes(QString tag); + QStringList getTextCompletion(QString tag); + void printContents(); + void writeTagFiles(); + /** No descriptions */ + bool parseDTD(); + +private: + bool parseDTD(const KURL& url); + void parseDTDEntity(const QString &line); + void parseDTDElement(const QString &line); + void parseDTDAttlist(const QString &line); + void parseTagAttributeValues(const QString &name, QString *value); + void parseDTDReplace(QString *value); + void stripSpaces(QString *value); + void removeComments(QString &value); + + QDict entities; + QDict elements; + QStringList tags; + QDict tagAttributes; + /** From where to load the DTD file. */ + KURL m_dtdURL; + QString m_dtepDir; +}; + +#endif diff --git a/quanta/parsers/dtd/dtdparser.cpp b/quanta/parsers/dtd/dtdparser.cpp new file mode 100644 index 00000000..86060967 --- /dev/null +++ b/quanta/parsers/dtd/dtdparser.cpp @@ -0,0 +1,362 @@ +/*************************************************************************** + dtdparser.cpp - description + ------------------- + begin : Sun Oct 19 16:47:20 EEST 2003 + copyright : (C) 2003 Andras Mantia + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; version 2 of the License. * + * * + ***************************************************************************/ + +//qt includes +#include +#include +#include +#include +#include +#include +#include + +//kde includes +#include +#include +#include +#include +#include +#include +#include + +//other includes +#ifdef LIBXML_2_5 +#include +#endif + +#include +#include + +//own includes +#include "dtepeditdlg.h" +#include "dtdparser.h" +#include "qtag.h" +#include "dtepcreationdlg.h" +#include "quantacommon.h" +#include "qextfileinfo.h" + +#define MAX_CHILD_ELEMENTS 100 + +namespace DTD +{ + QString dirName; + xmlDtdPtr dtd_ptr; /* Pointer to the parsed DTD */ + QTextStream entityStream; +} + +void saveElement(xmlElementPtr elem, xmlBufferPtr buf); +void saveEntity(xmlEntityPtr entity, xmlBufferPtr buf); + +DTDParser::DTDParser(const KURL& dtdURL, const QString &dtepDir) +{ + m_dtdURL = dtdURL; + m_dtepDir = dtepDir; +} + +DTDParser::~DTDParser() +{ +} + +bool DTDParser::parse(const QString &targetDir, bool entitiesOnly) +{ + bool fineTune = false; + QString fileName = QString::null; + if (!KIO::NetAccess::download(m_dtdURL, fileName, 0)) + { + KMessageBox::error(0, i18n("Cannot download the DTD from %1.").arg( m_dtdURL.prettyURL(0, KURL::StripFileProtocol))); + return false; + } + DTD::dtd_ptr = xmlParseDTD(NULL, xmlCharStrndup(fileName.utf8(), fileName.utf8().length())); + if( DTD::dtd_ptr == NULL ) + { + QString errorStr = i18n("Unknown"); +#ifndef LIBXML_2_5 + xmlErrorPtr errorPtr = xmlGetLastError(); + if (errorPtr != NULL) + { + QString s = QString::fromLatin1(errorPtr->message); + if (!s.isEmpty()) + errorStr = s; + s = QString::fromLatin1(errorPtr->str1); + if (!s.isEmpty()) + errorStr += "
" + s; + s = QString::fromLatin1(errorPtr->str2); + if (!s.isEmpty()) + errorStr += "
" + s; + s = QString::fromLatin1(errorPtr->str2); + if (!s.isEmpty()) + errorStr += "
" + s; + errorStr += QString("(%1, %2)").arg(errorPtr->line).arg(errorPtr->int2); + xmlResetError(errorPtr); + } +#endif + KMessageBox::error(0, i18n("Error while parsing the DTD.
The error message is:
%1
").arg(errorStr)); + return false; + } + if (targetDir.isEmpty()) + { + KDialogBase dlg(0L, 0L, true, i18n("DTD - > DTEP Conversion"), KDialogBase::Ok | KDialogBase::Cancel); + DTEPCreationDlg w(&dlg); + dlg.setMainWidget(&w); + QString name = QString((const char*)DTD::dtd_ptr->name); + if (name == "none") + name = QFileInfo(m_dtdURL.fileName()).baseName(); + w.dtdName->setText(name); + w.nickName->setText(name); + w.directory->setText(QFileInfo(m_dtdURL.fileName()).baseName()); + w.doctype->setText(QString((const char*)DTD::dtd_ptr->ExternalID)); + w.dtdURL->setText(QString((const char*)DTD::dtd_ptr->SystemID)); + if (!dlg.exec()) + return false; + m_name = w.dtdName->text(); + m_nickName = w.nickName->text(); + m_doctype = w.doctype->text(); + m_doctype.replace(QRegExp("")); + m_dtdURLLine = w.dtdURL->text(); + m_defaultExtension = w.defaultExtension->text(); + m_caseSensitive = w.caseSensitive->isChecked(); + DTD::dirName = m_dtepDir + "/" + w.directory->text(); + fineTune = w.fineTune->isChecked(); + } else + DTD::dirName = targetDir; + KURL u; + u.setPath(DTD::dirName); + if (!QExtFileInfo::createDir(u, 0L)) { + QuantaCommon::dirCreationError(0L, u); + return false; + } + DTD::dirName.append("/"); + if (DTD::dtd_ptr->entities) + { + QFile file( DTD::dirName + "entities.tag" ); + if ( file.open( IO_WriteOnly ) ) + { + DTD::entityStream.setDevice(&file); + DTD::entityStream.setEncoding(QTextStream::UnicodeUTF8); + DTD::entityStream << "" << endl; + DTD::entityStream << "" << endl + << "" << endl; + xmlHashScan((xmlEntitiesTablePtr)DTD::dtd_ptr->entities, (xmlHashScanner)saveEntity, 0); + DTD::entityStream << "" << endl; + file.close(); + } else + { + KMessageBox::error(0L, i18n("Cannot create the
%1 file.
Check that you have write permission in the parent folder.
") + .arg(file.name())); + return false; + } + } + if (!entitiesOnly) + { + if (DTD::dtd_ptr->elements) + { + xmlHashScan((xmlElementTablePtr)DTD::dtd_ptr->elements, (xmlHashScanner)saveElement, 0); + } else + { + KMessageBox::error(0, i18n("No elements were found in the DTD.")); + return false; + } + } + xmlFreeDtd(DTD::dtd_ptr); + if (!entitiesOnly) + { + writeDescriptionRC(); + if (fineTune) + { + KDialogBase editDlg(0L, "edit_dtep", true, i18n("Configure DTEP"), KDialogBase::Ok | KDialogBase::Cancel); + DTEPEditDlg dtepDlg(DTD::dirName + "description.rc", &editDlg); + editDlg.setMainWidget(&dtepDlg); + if (editDlg.exec()) + { + dtepDlg.saveResult(); + } + } + } + return true; +} + +void DTDParser::writeDescriptionRC() +{ + KConfig config(DTD::dirName + "description.rc"); + config.setGroup("General"); + config.writeEntry("Name", m_name); + config.writeEntry("NickName", m_nickName); + config.writeEntry("DoctypeString", m_doctype); + config.writeEntry("URL", m_dtdURLLine); + config.writeEntry("DefaultExtension", m_defaultExtension); + config.writeEntry("Family", "1"); + config.writeEntry("CaseSensitive", m_caseSensitive); +// config.setGroup("Parsing rules"); +// config.writeEntry("SpecialAreas",",,"); +// config.writeEntry("SpecialAreaNames","comment,XML PI,DTD"); + + config.sync(); +} + +void saveElement(xmlElementPtr elem, xmlBufferPtr buf) +{ + Q_UNUSED(buf); + if (elem) + { + QString elemName = QString((const char*)elem->name); + QFile file( DTD::dirName + elemName + ".tag" ); + if ( file.open( IO_WriteOnly ) ) + { + QTextStream stream( &file ); + stream.setEncoding(QTextStream::UnicodeUTF8); + stream << "" << endl; + stream << "" << endl + << "" << endl + << "" << endl << endl; + + xmlElementPtr el_ptr; /* Pointer to an element description */ + xmlAttributePtr at_ptr; + el_ptr = xmlGetDtdElementDesc(DTD::dtd_ptr, elem->name); + AttributeList attributes; + attributes.setAutoDelete(true); + if (el_ptr) + { + at_ptr = el_ptr->attributes; + while (at_ptr) { + Attribute *attr = new Attribute; + attr->name = QString((const char*)at_ptr->name); + switch (at_ptr->def) { + case 1: {attr->status = "optional"; break;} //NONE + case 2: {attr->status = "required"; break;} //REQUIRED + case 3: {attr->status = "implied"; break;} //IMPLIED + case 4: {attr->status = "fixed"; break;} //FIXED + } + attr->defaultValue = QString((const char*)at_ptr->defaultValue); + xmlEnumerationPtr enum_ptr; + enum_ptr = at_ptr->tree; + while (enum_ptr) { + attr->values += QString((const char*)enum_ptr->name); + enum_ptr = enum_ptr->next; + } + QString attrtype; + switch (at_ptr->atype) { + case 9: {attrtype = "list"; break;} + default: {attrtype = "input"; break;} //TODO handle the rest of types + } + attr->type = attrtype; + attributes.append(attr); + at_ptr = at_ptr->nexth; + } + + if (!attributes.isEmpty()) + stream << QuantaCommon::xmlFromAttributes(&attributes); + const xmlChar *list_ptr[MAX_CHILD_ELEMENTS]; + int childNum = 0; + childNum = xmlValidGetPotentialChildren(el_ptr->content, list_ptr, + &childNum, MAX_CHILD_ELEMENTS); + + if (childNum > 0) + { + stream << "" << endl; + for( int i = 0; i < childNum; i++ ) + { + stream << " content && child_ptr->content->ocur) + { + //if (child_ptr->content->ocur == XML_ELEMENT_CONTENT_PLUS) + //{ + // stream << " usage=\"required\""; + // } + QString ocur; + switch (child_ptr->content->ocur) + { + case 1: {ocur = "once"; break;} + case 2: {ocur = "opt"; break;} + case 3: {ocur = "mult"; break;} + case 4: {ocur = "plus"; break;} + } + stream << " usage=\"" << ocur << "\""; + QString name = QString((const char*)child_ptr->content->name); + if (name == "#PCDATA") + name == "#text"; + stream << " name2=\"" << name << "\""; + } + stream << " />" << endl; + } + + stream << "" << endl; + stream << endl; + } + /* + xmlElementContentPtr content_ptr = el_ptr->content; + if (content_ptr) + { + stream << "" << endl; + while (content_ptr) + { + if (!QString((const char*)content_ptr->name).isEmpty()) + { + stream << " name) << "\""; + QString ocur; + switch (content_ptr->ocur) + { + case 1: {ocur = "once"; break;} + case 2: {ocur = "opt"; break;} + case 3: {ocur = "mult"; break;} + case 4: {ocur = "plus"; break;} + } + stream << " usage=\"" << ocur << "\""; + stream << " />" << endl; + } + if (content_ptr->c1) + content_ptr = content_ptr->c1; + else if (content_ptr->c2) + content_ptr = content_ptr->c2; + else + { + if (content_ptr == el_ptr->content) + break; + if (content_ptr->parent) + { + if (content_ptr == content_ptr->parent->c1) + content_ptr->c1 = 0L; + else + content_ptr->c2 = 0L; + } + content_ptr = content_ptr->parent; + } + } + stream << "" << endl; + } */ + } + stream << "" << endl + << "" << endl; + file.close(); + } + } +} + +void saveEntity(xmlEntityPtr entity, xmlBufferPtr buf) +{ + Q_UNUSED(buf); + if (entity) + { + QString name = QString((const char*)entity->name); + DTD::entityStream << "" << endl << endl; + } +} + +QString DTDParser::dirName() +{ + return DTD::dirName; +} + diff --git a/quanta/parsers/dtd/dtdparser.h b/quanta/parsers/dtd/dtdparser.h new file mode 100644 index 00000000..b5b66d01 --- /dev/null +++ b/quanta/parsers/dtd/dtdparser.h @@ -0,0 +1,55 @@ +/*************************************************************************** + dtdparser.h - description + ------------------- + begin : Sun Oct 19 16:47:20 EEST 2003 + copyright : (C) 2003 Andras Mantia + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; version 2 of the License. * + * * + ***************************************************************************/ +#ifndef DTDPARSER_H +#define DTDPARSER_H + +//qt includes +#include + +//forward declarations +class KURL; +class QString; +struct Attribute; + +/** libxml2 based XML DTD parser and DTEP creation class*/ +class DTDParser { +public: + DTDParser(const KURL& dtdURL, const QString &dtepDir); + ~DTDParser(); + QString dirName(); + /** + * Parse the DTD file. + * @param targetDir the directory of the destination DTEP. If empty, a dialog is shown to configure the destination. + * @param entitiesOnly if true, only the entities are extracted from the DTD into the entities.tag file + * @return true on success, false if some error happened + */ + bool parse(const QString &targetDir = QString::null, bool entitiesOnly = false); + +protected: + void writeDescriptionRC(); + +private: + KURL m_dtdURL; + QString m_dtepDir; + QString m_name; + QString m_nickName; + QString m_doctype; + QString m_dtdURLLine; + bool m_caseSensitive; + QString m_defaultExtension; + QDict m_tags; +}; + +#endif diff --git a/quanta/parsers/dtd/dtepcreationdlg.ui b/quanta/parsers/dtd/dtepcreationdlg.ui new file mode 100644 index 00000000..3247c7ae --- /dev/null +++ b/quanta/parsers/dtd/dtepcreationdlg.ui @@ -0,0 +1,152 @@ + +DTEPCreationDlg +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; version 2 of the License. * + * * + ***************************************************************************/ + +(C) 2003 Andras Mantia <amantia@kde.org> + + + DTEPCreationDlg + + + + 0 + 0 + 500 + 285 + + + + + 500 + 200 + + + + DTD - > DTEP Conversion + + + true + + + + unnamed + + + + nickName + + + + + dtdURL + + + + + textLabel1 + + + Name: + + + + + textLabel2 + + + Nickname: + + + + + textLabel3 + + + !DOCTYPE definition line: + + + + + directory + + + + + doctype + + + + + dtdName + + + + + textLabel5 + + + DTD URL: + + + + + textLabel4 + + + Target directory name: + + + + + textLabel1_2 + + + Default extension: + + + + + defaultExtension + + + + + caseSensitive + + + Case-sensitive tags and attributes + + + true + + + + + fineTune + + + &Fine-tune the DTEP after conversion + + + true + + + + + + directory + dtdName + nickName + doctype + dtdURL + defaultExtension + caseSensitive + + + -- cgit v1.2.1