[xiph-commits] r8318 - in trunk/oggdsf/src: lib/codecs/cmml/libWinCMMLParse tests/testCMMLParser

illiminable at motherfish-iii.xiph.org illiminable at motherfish-iii.xiph.org
Tue Nov 30 09:03:10 PST 2004


Author: illiminable
Date: 2004-11-30 09:03:10 -0800 (Tue, 30 Nov 2004)
New Revision: 8318

Modified:
   trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.cpp
   trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.h
   trunk/oggdsf/src/tests/testCMMLParser/testCMMLParser.cpp
Log:
* CMML Parser seems pretty conformat now.

Modified: trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.cpp
===================================================================
--- trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.cpp	2004-11-30 16:16:31 UTC (rev 8317)
+++ trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.cpp	2004-11-30 17:03:10 UTC (rev 8318)
@@ -238,8 +238,141 @@
 	return retVal;
 }
 
+bool CMMLParser::parseCMMLRootTag(MSXML2::IXMLDOMNode* inCMMLRootNode, C_CMMLRootTag* outCMMLRoot) {
+	MSXML2::IXMLDOMNamedNodeMap*	locAttribMap	= NULL;
+	MSXML2::IXMLDOMNodeList*		locChildNodes	= NULL;
+	MSXML2::IXMLDOMNode*			locNode			= NULL;
+	HRESULT							locHR			= S_FALSE;
+	long							locNumNodes		= 0;
+	BSTR							locBStr			= NULL;
+	wstring							locNodeName		= L"";
 
 
+	unsigned long					locNum_clip		= 0;
+	unsigned long					locNum_head		= 0;
+	unsigned long					locNum_stream	= 0;
+	unsigned long					locNumUnknown	= 0;
+
+	bool retVal = true;
+	
+	//---------------Attributes-----------------
+	locHR = inCMMLRootNode->get_attributes(&locAttribMap);
+
+	outCMMLRoot->setId(getNamedAttribValue(L"id", locAttribMap));
+	outCMMLRoot->setLang(getNamedAttribValue(L"lang", locAttribMap));
+	outCMMLRoot->setDirn(getNamedAttribValue(L"dir", locAttribMap));
+	
+	//------------------------------------------
+	//--------------Child Nodes-----------------
+	locHR = inCMMLRootNode->get_childNodes(&locChildNodes);
+	locHR = locChildNodes->get_length(&locNumNodes);
+
+	for (int i = 0; i < locNumNodes; i++) {
+		locHR = locChildNodes->get_item(i, &locNode);
+		locHR = locNode->get_nodeName(&locBStr);
+		//TODO::: Needs checks ??
+
+		locNodeName = locBStr;
+		if (locNodeName == L"stream") {
+			//If it exists it must be first
+			if (		(locNum_stream == 0)
+					&&	(locNum_clip == 0)
+					&&	(locNum_head == 0)) {
+				//OPTIONALLY ONE stream tag
+				C_StreamTag* locStream = new C_StreamTag;
+			
+				if (parseStreamTag(locNode, locStream)) {
+					outCMMLRoot->setStream(locStream);
+					locNum_stream++;
+				} else {
+					delete locStream;
+					outCMMLRoot->setStream(NULL);
+				}
+			} else {
+				retVal = false;
+			}
+
+
+		} else if (locNodeName == L"head") {
+			
+			//MUST HAVE ONE head tag
+			if (		(locNum_stream <= 1)
+					&&	(locNum_clip == 0)
+					&&	(locNum_head == 0)) {
+			
+				C_HeadTag* locHead = new C_HeadTag;
+			
+				if (parseHeadTag(locNode, locHead)) {
+					outCMMLRoot->setHead(locHead);
+					locNum_head++;
+				} else {
+					delete locHead;	
+					retVal = false;
+				}
+			} else {
+				retVal = false;
+
+			}
+		} else if (locNodeName == L"clip") {
+
+			//ZERO OR MORE clip tags
+			if (		(locNum_stream <= 1)
+					&&	(locNum_head == 1)) {
+
+				C_ClipTag* locClip = new C_ClipTag;
+			
+				if(parseClipTag(locNode, locClip)) {
+					outCMMLRoot->clipList()->addTag(locClip);
+					locNum_clip++;
+				} else {
+					delete locClip;
+				}
+			} else { 
+				retVal = false;
+			}
+			
+		} else {
+			locNumUnknown++;
+		}
+	}
+
+	retVal		=		(retVal)
+						&&	(locNum_stream <= 1)
+						&&	(locNum_head == 1);
+						
+
+
+	SysFreeString(locBStr);
+	if (locAttribMap != NULL)					locAttribMap->Release();
+	if (locNode != NULL)						locNode->Release();
+	if (locChildNodes != NULL)					locChildNodes->Release();
+	return retVal;
+}
+
+
+bool CMMLParser::parseCMMLRootTag(wstring inCMMLRootText, C_CMMLRootTag* outCMMLRoot) {
+	HRESULT						locHR				= S_FALSE;
+	MSXML2::IXMLDOMDocument*	locXMLCMMLRootFrag	= NULL;
+	MSXML2::IXMLDOMNode*		locCMMLRootNode			= NULL;
+		
+	bool retVal = setupXMLHandles(inCMMLRootText, &locXMLCMMLRootFrag);
+
+	if (retVal) {
+		locCMMLRootNode = getNamedNode(L"cmml", locXMLCMMLRootFrag);
+		
+		if (locCMMLRootNode != NULL) {
+			
+			retVal = parseCMMLRootTag(locCMMLRootNode, outCMMLRoot);
+		} else {
+			retVal = false;
+		}
+	}
+
+	if (locXMLCMMLRootFrag != NULL)					locXMLCMMLRootFrag->Release();
+	if (locCMMLRootNode != NULL)						locCMMLRootNode->Release();
+
+	return retVal;
+}
 bool CMMLParser::parseHeadTag(MSXML2::IXMLDOMNode* inHeadNode, C_HeadTag* outHead) {
 	MSXML2::IXMLDOMNamedNodeMap*	locAttribMap	= NULL;
 	MSXML2::IXMLDOMNodeList*		locChildNodes	= NULL;

Modified: trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.h
===================================================================
--- trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.h	2004-11-30 16:16:31 UTC (rev 8317)
+++ trunk/oggdsf/src/lib/codecs/cmml/libWinCMMLParse/CMMLParser.h	2004-11-30 17:03:10 UTC (rev 8318)
@@ -50,6 +50,7 @@
 	//bool parseCMMLDoc(string inCMMLDocText, C_CMMLDoc* outDoc);
 	bool parseClipTag(wstring inClipText, C_ClipTag* outClip);
 	bool parseHeadTag(wstring inHeadText, C_HeadTag* outHead);
+	bool parseCMMLRootTag(wstring inCMMLRootText, C_CMMLRootTag* outCMMLRoot);
 
 	bool parseHeadTag(MSXML2::IXMLDOMNode* inHeadNode, C_HeadTag* outHead);
 	bool parseAnchorTag(MSXML2::IXMLDOMNode* inAnchorNode, C_AnchorTag* outAnchor);
@@ -62,6 +63,7 @@
 	bool parseDescTag(MSXML2::IXMLDOMNode* inDescNode, C_DescTag* outDesc);
 	bool parseBaseTag(MSXML2::IXMLDOMNode* inBaseNode, C_BaseTag* outBase);
 	bool parseParamTag(MSXML2::IXMLDOMNode* inParamNode, C_ParamTag* outParam);
+	bool parseCMMLRootTag(MSXML2::IXMLDOMNode* inCMMLRootNode, C_CMMLRootTag* outCMMLRoot);
 
 
 

Modified: trunk/oggdsf/src/tests/testCMMLParser/testCMMLParser.cpp
===================================================================
--- trunk/oggdsf/src/tests/testCMMLParser/testCMMLParser.cpp	2004-11-30 16:16:31 UTC (rev 8317)
+++ trunk/oggdsf/src/tests/testCMMLParser/testCMMLParser.cpp	2004-11-30 17:03:10 UTC (rev 8318)
@@ -45,6 +45,25 @@
 	return locWasOK;
 }
 
+bool testCMMLRootParse(wstring inCMMLRootString) {
+	CMMLParser locParser;
+
+	wcout << "Original"<<endl<<inCMMLRootString<<endl<<endl;
+
+	C_CMMLRootTag locCMMLRoot;
+	
+	bool locWasOK = locParser.parseCMMLRootTag(inCMMLRootString, &locCMMLRoot);
+
+	if (locWasOK) {
+		wcout<<"Parsed OK"<<endl<<endl<<locCMMLRoot.toString()<<endl<<endl;
+	} else {
+		wcout<<"*** PARSE FAILED ***"<<endl<<endl;
+	}
+
+	return locWasOK;
+
+}
+
 int __cdecl _tmain(int argc, _TCHAR* argv[])
 {
 	//Valid minimal
@@ -92,10 +111,33 @@
 	wstring clip_5 = L"<clip id=\"dolphin\" start=\"npt:3.5\" end=\"npt:5:5.9\"><a href\"http:\\linktome.com\" class=\"someClass\">Random anchor text</a><img src=\"dolphin.jpg\"/><desc>Here, Joe caught sight of a dolphin in the ocean.</desc><meta name=\"Subject\" content=\"dolphin\"/></clip>";
 	testClipParse(clip_5);
 
-	//VALID
+	//Valid
 	wstring clip_6 = L"<clip id=\"dolphin\" start=\"npt:3.5\" end=\"npt:5:5.9\"><a href=\"http:\\linktome.com\" class=\"someClass\">Random anchor text</a><img src=\"dolphin.jpg\"/><desc>Here, Joe caught sight of a dolphin in the ocean.</desc><meta name=\"Subject\" content=\"dolphin\"/></clip>";
 	testClipParse(clip_6);
 
+
+	//Valid
+	wstring cmml_1 = L"<cmml lang=\"en\"><head id=\"headID\" lang=\"en\" dir=\"ltr\" profile=\"some profile\"><base href=\"http://baseurl.com\"/><title lang=\"fr\">Types of fish</title><meta name=\"Producer\" content=\"Joe Ordinary\" scheme=\"some scheme\"/><meta name=\"DC.Author\" content=\"Joe's friend\"/></head><clip id=\"dolphin\" lang=\"en\" start=\"npt:3.5\" end=\"npt:5:5.9\"><img alt=\"Picture of dolphin\" src=\"dolphin.jpg\"/><desc id=\"descID\" lang=\"fr\">Here, Joe caught sight of a dolphin in the ocean.</desc><meta name=\"Subject\" content=\"dolphin\"/></clip></cmml>";
+	testCMMLRootParse(cmml_1);
+
+	//INVALID: No title
+	wstring cmml_2 = L"<cmml lang=\"en\"><head id=\"headID\" lang=\"en\" dir=\"ltr\" profile=\"some profile\"><base href=\"http://baseurl.com\"/><meta name=\"Producer\" content=\"Joe Ordinary\" scheme=\"some scheme\"/><meta name=\"DC.Author\" content=\"Joe's friend\"/></head><clip id=\"dolphin\" lang=\"en\" start=\"npt:3.5\" end=\"npt:5:5.9\"><img alt=\"Picture of dolphin\" src=\"dolphin.jpg\"/><desc id=\"descID\" lang=\"fr\">Here, Joe caught sight of a dolphin in the ocean.</desc><meta name=\"Subject\" content=\"dolphin\"/></clip></cmml>";
+	testCMMLRootParse(cmml_2);
+
+	//INVALID: No head
+	wstring cmml_3 = L"<cmml lang=\"en\"><clip id=\"dolphin\" lang=\"en\" start=\"npt:3.5\" end=\"npt:5:5.9\"><img alt=\"Picture of dolphin\" src=\"dolphin.jpg\"/><desc id=\"descID\" lang=\"fr\">Here, Joe caught sight of a dolphin in the ocean.</desc><meta name=\"Subject\" content=\"dolphin\"/></clip></cmml>";
+	testCMMLRootParse(cmml_3);
+
+	//INVALID: Random data
+	wstring cmml_4 = L"asdfasd fasd fasdf ds ";
+	testCMMLRootParse(cmml_4);
+
+	//INVALID: valid xml but invalid cmml
+	wstring cmml_5 = L"<blue><red>random stuff</red><green>But still valid XML</green></blue>";
+	testCMMLRootParse(cmml_5);
+
+
+
 	return 0;
 }
 



More information about the commits mailing list