[rkward-cvs] SF.net SVN: rkward-code:[4926] trunk/rkward/rkward

tfry at users.sf.net tfry at users.sf.net
Fri Oct 17 17:43:28 UTC 2014


Revision: 4926
          http://sourceforge.net/p/rkward/code/4926
Author:   tfry
Date:     2014-10-17 17:43:27 +0000 (Fri, 17 Oct 2014)
Log Message:
-----------
Further tweak the XMLHelper-API so that a single helper instance cannot be used on more than one file.

Modified Paths:
--------------
    trunk/rkward/rkward/misc/xmlhelper.cpp
    trunk/rkward/rkward/misc/xmlhelper.h
    trunk/rkward/rkward/plugin/rkcomponentmap.cpp
    trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
    trunk/rkward/rkward/plugins/pluginmap_meta.inc
    trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp
    trunk/rkward/rkward/windows/rkhtmlwindow.cpp

Modified: trunk/rkward/rkward/misc/xmlhelper.cpp
===================================================================
--- trunk/rkward/rkward/misc/xmlhelper.cpp	2014-10-17 16:55:48 UTC (rev 4925)
+++ trunk/rkward/rkward/misc/xmlhelper.cpp	2014-10-17 17:43:27 UTC (rev 4926)
@@ -36,15 +36,13 @@
 	RK_TRACE (XML);
 }
 
-QDomElement XMLHelper::openXMLFile (const QString &filename, int debug_level, bool with_includes, bool with_snippets) {
+QDomElement XMLHelper::openXMLFile (int debug_level, bool with_includes, bool with_snippets) {
 	RK_TRACE (XML);
 
 	int error_line, error_column;
 	QString error_message;
 	QDomDocument doc;
 
-	XMLHelper::filename = filename;
-	
 	QFile f (filename);
 	if (!f.open (QIODevice::ReadOnly)) displayError (0, i18n("Could not open file %1 for reading").arg (filename), debug_level, DL_ERROR);
 	if (!doc.setContent(&f, false, &error_message, &error_line, &error_column)) {
@@ -65,7 +63,8 @@
 			inc_filename = base.filePath (inc_filename);
 
 			// import
-			QDomElement included = openXMLFile (inc_filename, debug_level, true, false);
+			XMLHelper inc_xml = XMLHelper (inc_filename);
+			QDomElement included = inc_xml.openXMLFile (debug_level, true, false);
 
 			if (!included.isNull ()) {
 				QDomElement copied = doc.importNode (included, true).toElement ();

Modified: trunk/rkward/rkward/misc/xmlhelper.h
===================================================================
--- trunk/rkward/rkward/misc/xmlhelper.h	2014-10-17 16:55:48 UTC (rev 4925)
+++ trunk/rkward/rkward/misc/xmlhelper.h	2014-10-17 17:43:27 UTC (rev 4926)
@@ -23,33 +23,28 @@
 /** a helper type used to pass a list of direct child elements of a node */
 typedef QList<QDomElement> XMLChildList;
 
-/** This class contains some convenience functions for parsing XML files (DOM). Usually you will use a static instance of this class (getStaticHelper ()), which will be created early in rkward initialization. The error-logs will be reset every time you open a new XML-file using openXMLFile (). This is fine as long as you are parsing files one by one instead of mixing several files. In the latter case you will want to create additional instances of XMLHelper (it's quite possible, this mechanism will be changed, but I want to get going before considering all implications ;-)).
+/** This class contains some convenience functions for parsing XML files (DOM). RKComponents should retrieve the instance appropriate for parsing their
+XML elements from the parent component: @see RKComponent::xmlHelper() .
 
-The functions in this class provide error-messages for illegal/problematic input. Information on the error status of the last commands is provided. More documentation to come once the API is somewhat finalized.
+The functions in this class provide error-messages for illegal/problematic input. Warning/Error messages will always be printed using the standard debugging framework (shown according to user settings).
 
-Warning/Error messages will always be printed using the standard debugging framework (shown according to user settings).
-
-TODO: Probably it's not really clever to use the debugging-framework for showing error-messages in XML-file parsing. Anyway, the only function to adjust in order to change this would be displayError ().
-
-TODO: Either something like push-context/pop-context or an added closeFile (). This way, when parsing several XML-files, we'd still get the correct messages. Internally a stack of filenames and highest_errors would be kept.
-
 @author Thomas Friedrichsmeier
 */
 class XMLHelper {
 public:
-/** create an instance of XMLHelper. */
-	XMLHelper (const QString &filename=QString ());
+/** create an instance of XMLHelper.
+ @param filename the name of the file to parse. The file is not yet opened on construction. Use openXMLFile() for that. */
+	XMLHelper (const QString &filename);
 /** destrcutor */
 	~XMLHelper ();
 	
-/** open the given filename (read-only) and do basic parsing. Internally, the file will be closed right away, so there is no need to call an additional closeFile-equivalent. Once the returned element (and any copies you make of it) goes out of scope, the entire element-tree allocated will be freed.
-When calling this function, highestError () will be reset to 0.
- at param filename the name of the file to parse
+/** Open the filename set in the constructor (read-only) and do basic parsing. Internally, the file will be closed right away, so there is no need to call an additional closeFile-equivalent. Once the returned element (and any copies you make of it) goes out of scope, the entire element-tree allocated will be freed,
+but you can re-open the file, if needed.
 @param debug_level level of debug message to generate if opening/parsing fails
 @param with_includes should the helper take care of resolving "include" elements?
 @param with_snippets should the helper take care of resolving "insert" elements?
 @returns the document-element of the file. */
-	QDomElement openXMLFile (const QString &filename, int debug_level, bool with_includes=true, bool with_snippets=true);
+	QDomElement openXMLFile (int debug_level, bool with_includes=true, bool with_snippets=true);
 
 /** resolve "snippet" elements in the given element. It is assumed that the from element will contain a "snippets" section, i.e. it is generally a document. */
 	QDomElement resolveSnippets (QDomElement &from);

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2014-10-17 16:55:48 UTC (rev 4925)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2014-10-17 17:43:27 UTC (rev 4926)
@@ -349,7 +349,7 @@
 	QDomElement element;
 	XMLChildList list;
 
-	QDomElement document_element = xml.openXMLFile (plugin_map_file_abs, DL_ERROR);
+	QDomElement document_element = xml.openXMLFile (DL_ERROR);
 	if (document_element.isNull ()) {
 		ret.addAndPrintError (DL_ERROR, i18n ("Could not open plugin map file %1. (Is not readble, or failed to parse)", plugin_map_file_abs));
 		return ret;

Modified: trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkstandardcomponent.cpp	2014-10-17 16:55:48 UTC (rev 4925)
+++ trunk/rkward/rkward/plugin/rkstandardcomponent.cpp	2014-10-17 17:43:27 UTC (rev 4926)
@@ -91,7 +91,7 @@
 
 	// open the main description file for parsing
 	XMLHelper* xml = getXmlHelper ();
-	QDomElement doc_element = xml->openXMLFile (filename, DL_ERROR);
+	QDomElement doc_element = xml->openXMLFile (DL_ERROR);
 	if (doc_element.isNull ()) {
 		KMessageBox::error (this, i18n ("There has been an error while trying to parse the description of this plugin ('%1'). Please refer to stdout for details.", filename), i18n ("Could not create plugin"));
 		kill ();
@@ -287,7 +287,7 @@
 
 	// open the main description file for parsing (again)
 	XMLHelper* xml = getXmlHelper ();
-	QDomElement doc_element = xml->openXMLFile (filename, DL_ERROR);
+	QDomElement doc_element = xml->openXMLFile (DL_ERROR);
 	int force_mode = 2;
 	if (isWizardish ()) force_mode = 1;
 

Modified: trunk/rkward/rkward/plugins/pluginmap_meta.inc
===================================================================
--- trunk/rkward/rkward/plugins/pluginmap_meta.inc	2014-10-17 16:55:48 UTC (rev 4925)
+++ trunk/rkward/rkward/plugins/pluginmap_meta.inc	2014-10-17 17:43:27 UTC (rev 4926)
@@ -2,7 +2,7 @@
 	<about
 		name="RKWard pluginmap"
 		shortinfo="Part of the official RKWard distribution"
-		version="0.6.1"
+		version="0.6.3"
 		license="GPL"
 		url="http://rkward.sf.net">
 		<author

Modified: trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2014-10-17 16:55:48 UTC (rev 4925)
+++ trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2014-10-17 17:43:27 UTC (rev 4926)
@@ -352,8 +352,8 @@
 		}
 
 		if (inf.id.isEmpty ()) {
-			XMLHelper xml = XMLHelper ();
-			QDomElement de = xml.openXMLFile (inf.filename, DL_WARNING);
+			XMLHelper xml (inf.filename);
+			QDomElement de = xml.openXMLFile (DL_WARNING);
 			inf.id = RKPluginMapFile::parseId (de, xml);
 			inf.priority = xml.getMultiChoiceAttribute (de, "priority", "hidden;low;medium;high", (int) PriorityMedium, DL_WARNING);
 		}
@@ -622,8 +622,8 @@
 	if (!plugin_map_dynamic_info.contains (pluginmapfile)) {
 		// TODO
 		PluginMapMetaInfo inf;
-		XMLHelper xml;
-		QDomElement doc_elem = xml.openXMLFile (pluginmapfile, DL_WARNING);
+		XMLHelper xml (pluginmapfile);
+		QDomElement doc_elem = xml.openXMLFile (DL_WARNING);
 		inf.about = new RKComponentAboutData (xml.getChildElement (doc_elem, "about", DL_INFO), xml);
 		inf.dependencies = RKComponentDependency::parseDependencies (xml.getChildElement (doc_elem, "dependencies", DL_INFO), xml);
 		plugin_map_dynamic_info.insert (pluginmapfile, inf);

Modified: trunk/rkward/rkward/windows/rkhtmlwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkhtmlwindow.cpp	2014-10-17 16:55:48 UTC (rev 4925)
+++ trunk/rkward/rkward/windows/rkhtmlwindow.cpp	2014-10-17 17:43:27 UTC (rev 4926)
@@ -492,11 +492,14 @@
 	bool for_component = false;		// is this a help page for a component, or a top-level help page?
 	if (url.host () == "component") for_component = true;
 
-	XMLHelper component_xml;
-	XMLHelper help_xml;
 	QStringList anchors, anchornames;
 
 	RKComponentHandle *chandle = 0;
+	if (for_component) {
+		chandle = componentPathToHandle (url.path ());
+		if (!chandle) return false;
+	}
+	XMLHelper component_xml (for_component ? chandle->getFilename () : QString ());
 	QString help_file_name;
 	QDomElement element;
 	QDomElement component_doc_element;
@@ -505,10 +508,7 @@
 
 	// determine help file, and prepare
 	if (for_component) {
-		chandle = componentPathToHandle (url.path ());
-		if (!chandle) return false;
-
-		component_doc_element = component_xml.openXMLFile (chandle->getFilename (), DL_ERROR);
+		component_doc_element = component_xml.openXMLFile (DL_ERROR);
 		if (component_doc_element.isNull ()) return false;
 		element = component_xml.getChildElement (component_doc_element, "help", DL_ERROR);
 		if (!element.isNull ()) {
@@ -521,7 +521,8 @@
 	RK_DEBUG (APP, DL_DEBUG, "rendering help page for local file %s", help_file_name.toLatin1().data());
 
 	// open help file
-	QDomElement help_doc_element = help_xml.openXMLFile (help_file_name, DL_ERROR);
+	XMLHelper help_xml (help_file_name);
+	QDomElement help_doc_element = help_xml.openXMLFile (DL_ERROR);
 	if (help_doc_element.isNull () && (!for_component)) return false;
 
 	// initialize output, and set title
@@ -638,8 +639,8 @@
 	if (for_component) {
 		element = component_xml.getChildElement (component_doc_element, "about", DL_INFO);
 		if (element.isNull ()) {
-			XMLHelper pluginmap_helper;
-			element = pluginmap_helper.openXMLFile (chandle->getPluginmapFilename (), DL_ERROR);
+			XMLHelper pluginmap_helper (chandle->getPluginmapFilename ());
+			element = pluginmap_helper.openXMLFile (DL_ERROR);
 			element = pluginmap_helper.getChildElement (element, "about", DL_INFO);
 		}
 	} else {
@@ -718,9 +719,8 @@
 			} else if (url.host () == "page") {
 				QString help_base_dir = RKCommonFunctions::getRKWardDataDir () + "pages/";
 		
-				XMLHelper xml;
-				QString help_file_name = help_base_dir + url.path () + ".rkh";
-				QDomElement doc_element = xml.openXMLFile (help_file_name, DL_WARNING);
+				XMLHelper xml (help_base_dir + url.path () + ".rkh");
+				QDomElement doc_element = xml.openXMLFile (DL_WARNING);
 				QDomElement title_element = xml.getChildElement (doc_element, "title", DL_WARNING);
 				text = title_element.text ();
 			}





More information about the rkward-tracker mailing list