[commit] r2475 - in trunk: . Tools/ModelMigrate/FrontEnd
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Fri Apr 25 12:46:25 CDT 2014
Author: ksmyth
Date: Fri Apr 25 12:46:25 2014
New Revision: 2475
Log:
ModelMigrate: add MS XSLT
Modified:
trunk/.gitignore
trunk/Tools/ModelMigrate/FrontEnd/CMgaXslt.cpp
trunk/Tools/ModelMigrate/FrontEnd/CMgaXslt.h
trunk/Tools/ModelMigrate/FrontEnd/FileTransDlg.cpp
trunk/Tools/ModelMigrate/FrontEnd/FrontEnd.vcxproj
Modified: trunk/.gitignore
==============================================================================
--- trunk/.gitignore Fri Apr 25 10:18:08 2014 (r2474)
+++ trunk/.gitignore Fri Apr 25 12:46:25 2014 (r2475)
@@ -415,3 +415,4 @@
Tests/LeakDiff.txt
Tests/LeakDump1.txt
Tests/LeakDump2.txt
+Tools/ModelMigrate/IDLComp/GMEIDLs_h.h
Modified: trunk/Tools/ModelMigrate/FrontEnd/CMgaXslt.cpp
==============================================================================
--- trunk/Tools/ModelMigrate/FrontEnd/CMgaXslt.cpp Fri Apr 25 10:18:08 2014 (r2474)
+++ trunk/Tools/ModelMigrate/FrontEnd/CMgaXslt.cpp Fri Apr 25 12:46:25 2014 (r2475)
@@ -1,64 +1,139 @@
-#include "stdafx.h"
+//#include "stdafx.h"
+
+#define __msxml_h__
+struct IXMLElement;
+#import <msxml6.dll> no_namespace
+
+#include <Windows.h>
#include "CMgaXslt.h"
-#define DISPATCH_XSLT 0
-#if(DISPATCH_XSLT)
-// it seems Mga.MgaXSLT is not really Dispatch compatible yet
-#else
-// in this case we use MIDL produced h file from an idl file which includes only the gme idls
#include "..\IDLComp\GMEIDLs_h.h"
-#endif
+#include <stdio.h>
+#include <tchar.h>
+#include <comdef.h>
+#include <new>
-void CXslt::doNativeXslt( LPCTSTR pScrF, LPCTSTR pInF, LPCTSTR pOutF, CString& resError)
-{/*
- // native vtable based
- CComPtr<IMgaXslt> xslt;
- HRESULT hr = xslt.CoCreateInstance(L"Mga.MgaXslt");
- ASSERT( xslt != NULL );
- if( FAILED( hr) || xslt == NULL) { resError = "COM Error at CreateInstance!"; return; }
-
- CComBSTR x_scr( pScrF);
- CComBSTR f_iin( pInF);
- CComBSTR f_out( pOutF);
- CComBSTR error;
- try
- {
- hr = xslt->ApplyXslt( x_scr, f_iin, f_out, &error);
- if( FAILED( hr)) throw hr;
- } catch( HRESULT&)
+_bstr_t GetErrorInfo(HRESULT hr)
+{
+ LPWSTR errorText = NULL;
+ FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&errorText, 0, NULL);
+ if (errorText != NULL) {
+ _bstr_t ret = errorText;
+ LocalFree(errorText);
+ return ret;
+ }
+ return _bstr_t(L"Unknown error");
+}
+
+struct XslException {
+ HRESULT hr;
+ _bstr_t message;
+ explicit XslException(HRESULT hr, _bstr_t message)
+ : hr(hr), message(message)
+ {}
+};
+
+#define CHK_HR(stmt) do { HRESULT hr = (stmt); if (FAILED(hr)) throw XslException(hr, GetErrorInfo(hr)); } while(0)
+#define CHK_ALLOC(p) do { if (!(p)) { throw XslException(E_OUTOFMEMORY, L"Out of memory"); } } while(0)
+
+HRESULT VariantFromString(PCWSTR wszValue, VARIANT &Variant)
+{
+ HRESULT hr = S_OK;
+ BSTR bstrString = SysAllocString(wszValue);
+ CHK_ALLOC(bstrString);
+
+ V_VT(&Variant) = VT_BSTR;
+ V_BSTR(&Variant) = bstrString;
+
+ return hr;
+}
+
+void CreateAndInitDOM(IXMLDOMDocument **ppDoc)
+{
+ HRESULT hr = CoCreateInstance(__uuidof(DOMDocument60), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(ppDoc));
+ if (FAILED(hr))
{
- if( error && error.Length() > 0)
- resError = COLE2T( error);
- else
- resError = "COM Error!";
+ throw XslException(hr, GetErrorInfo(hr));
}
- */
+ (*ppDoc)->async = VARIANT_FALSE;
+ (*ppDoc)->validateOnParse = VARIANT_FALSE;
+ (*ppDoc)->resolveExternals = VARIANT_FALSE;
+ IXMLDOMDocument2Ptr dom2 = (*ppDoc);
+ dom2->setProperty(L"ProhibitDTD", VARIANT_FALSE);
}
-void CXslt::doDispatchXslt( LPCTSTR pScrF, LPCTSTR pInF, LPCTSTR pOutF, CString& resError)
+HRESULT LoadXMLFile(IXMLDOMDocument *pXMLDom, LPCWSTR lpszXMLFile)
{
- // dispatch based, if it worked
- CComPtr<IUnknown> unknwn;
- HRESULT hr;
- hr = unknwn.CoCreateInstance( L"Mga.MgaXslt");
- if( FAILED( hr)) { resError = "COM Error at CreateInstance!"; return; }
- CComPtr<IDispatch> disp;
- hr = unknwn.QueryInterface( &disp);
- if( FAILED( hr)) { resError = "COM Error at QueryInterface!"; return; }
- CMgaXsltDriver xslt( disp);
- CComBSTR error;
- try
+ HRESULT hr = S_OK;
+ VARIANT_BOOL varStatus;
+ _variant_t varFileName;
+ IXMLDOMParseErrorPtr pXMLErr;
+
+ CHK_HR(VariantFromString(lpszXMLFile, varFileName));
+ varStatus = pXMLDom->load(varFileName);
+
+ if(varStatus != VARIANT_TRUE)
+ {
+ _bstr_t bstrErr = pXMLDom->parseError->reason;
+ wchar_t error[512];
+ swprintf_s(error, L"Failed to load %s:\n%s\n", lpszXMLFile, static_cast<const wchar_t*>(bstrErr));
+ throw XslException(E_FAIL, error);
+ }
+
+ return hr;
+}
+
+HRESULT TransformDOM2Obj(IXMLDOMDocument *pXMLDom, IXMLDOMDocument *pXSLDoc, wchar_t* outputFilename)
+{
+ HRESULT hr = S_OK;
+ _bstr_t bstrXML;
+ IXMLDOMDocumentPtr pXMLOut;
+ IDispatchPtr pDisp;
+ _variant_t varFileName;
+
+ CreateAndInitDOM(&pXMLOut);
+ CHK_HR(pXMLOut->QueryInterface(IID_IDispatch, (void**)&pDisp));
+
+ _variant_t varXMLOut((IDispatch*)pDisp);
+
+ pXMLDom->transformNodeToObject(pXSLDoc, varXMLOut);
+ // pXMLOut->get_xml(bstrXML.GetAddress());
+
+ CHK_HR(VariantFromString(outputFilename, varFileName));
+ pXMLOut->save(varFileName);
+
+ return hr;
+}
+
+void CXslt::doNativeXslt(LPCTSTR xsltFilename, LPCTSTR inputXmlFilename, LPCTSTR outputXmlFilename, _bstr_t& resError)
+{
+ try
{
- hr = xslt.ApplyXslt( pScrF, pInF, pOutF, &error);
+ IXMLDOMDocumentPtr pXMLDom;
+ IXMLDOMDocumentPtr pXSLDoc;
+
+ CreateAndInitDOM(&pXMLDom);
+ CHK_HR(LoadXMLFile(pXMLDom, _bstr_t(inputXmlFilename)));
+ CreateAndInitDOM(&pXSLDoc);
+ CHK_HR(LoadXMLFile(pXSLDoc, _bstr_t(xsltFilename)));
- if( FAILED( hr)) throw hr;
- } catch( HRESULT&)
+ CHK_HR(TransformDOM2Obj(pXMLDom, pXSLDoc, _bstr_t(outputXmlFilename)));
+ }
+ catch (_com_error& err)
+ {
+ if (err.Description().length())
+ resError = err.Description();
+ else
+ resError = L"Unknown error";
+ }
+ catch (XslException& err)
{
- if( error && error.Length() > 0)
- resError = COLE2T( error);
- else // error is empty
- resError = "COM Error";
+ if (err.message.length())
+ resError = err.message;
+ else
+ resError = L"Unknown error";
}
-}
\ No newline at end of file
+}
Modified: trunk/Tools/ModelMigrate/FrontEnd/CMgaXslt.h
==============================================================================
--- trunk/Tools/ModelMigrate/FrontEnd/CMgaXslt.h Fri Apr 25 10:18:08 2014 (r2474)
+++ trunk/Tools/ModelMigrate/FrontEnd/CMgaXslt.h Fri Apr 25 12:46:25 2014 (r2475)
@@ -1,37 +1,8 @@
-class CXslt
-{
-public:
- static void doNativeXslt( LPCTSTR stylesheet, LPCTSTR infile, LPCTSTR outfile, CString& error);
- static void doDispatchXslt( LPCTSTR stylesheet, LPCTSTR infile, LPCTSTR outfile, CString& error);
-};
+#include <comdef.h>
-// CMgaXsltDriver wrapper class
-
-class CMgaXsltDriver : public COleDispatchDriver
+class CXslt
{
public:
- CMgaXsltDriver(){} // Calls COleDispatchDriver default constructor
- CMgaXsltDriver(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
- CMgaXsltDriver(const CMgaXsltDriver& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}
-
- // Attributes
-public:
-
- // Operations
-public:
-
- // IMgaXslt methods
-public:
- STDMETHOD(ApplyXslt)(LPCTSTR stylesheet, LPCTSTR infile, LPCTSTR outfile, BSTR * error)
- {
- HRESULT result;
- static BYTE parms[] = VTS_BSTR VTS_BSTR VTS_BSTR VTS_PBSTR ;
- InvokeHelper(0x60020000, DISPATCH_METHOD, VT_HRESULT, (void*)&result, parms, stylesheet, infile, outfile, error);
- return result;
- }
-
- // IMgaXslt properties
-public:
-
+ static void doNativeXslt(LPCTSTR stylesheet, LPCTSTR infile, LPCTSTR outfile, _bstr_t& error);
};
Modified: trunk/Tools/ModelMigrate/FrontEnd/FileTransDlg.cpp
==============================================================================
--- trunk/Tools/ModelMigrate/FrontEnd/FileTransDlg.cpp Fri Apr 25 10:18:08 2014 (r2474)
+++ trunk/Tools/ModelMigrate/FrontEnd/FileTransDlg.cpp Fri Apr 25 12:46:25 2014 (r2475)
@@ -11,6 +11,7 @@
#include "AboutDlg.h"
#include <afxwin.h>
+#include <comdef.h>
#include ".\filetransdlg.h"
#define DEF_APPEND_STR "_out"
@@ -509,9 +510,11 @@
}
}
-void FileTransDlg::apply( CString pScrF, CString pInF, CString pOutF, CString& pErrMsg)
+void FileTransDlg::apply(CString xsltFilename, CString inputXmlFilename, CString outputXmlFilename, CString& pErrMsg)
{
- CXslt::doNativeXslt( pScrF, pInF, pOutF, pErrMsg);
+ _bstr_t err;
+ CXslt::doNativeXslt(xsltFilename, inputXmlFilename, outputXmlFilename, err);
+ pErrMsg = static_cast<const TCHAR*>(err);
}
void FileTransDlg::loadMyOptions( CString& pStrVal1, CString& pStrVal2, CString& pStrVal3, CString& pStrVal4, CString& pStrVal5)
Modified: trunk/Tools/ModelMigrate/FrontEnd/FrontEnd.vcxproj
==============================================================================
--- trunk/Tools/ModelMigrate/FrontEnd/FrontEnd.vcxproj Fri Apr 25 10:18:08 2014 (r2474)
+++ trunk/Tools/ModelMigrate/FrontEnd/FrontEnd.vcxproj Fri Apr 25 12:46:25 2014 (r2475)
@@ -119,7 +119,11 @@
<ClCompile Include="AttrGlobalDlg.cpp" />
<ClCompile Include="AttrNameDlg.cpp" />
<ClCompile Include="AttrTypeChangeDlg.cpp" />
- <ClCompile Include="CMgaXslt.cpp" />
+ <ClCompile Include="CMgaXslt.cpp">
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/showIncludes %(AdditionalOptions)</AdditionalOptions>
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
+ </ClCompile>
<ClCompile Include="EnumAttrValueDlg.cpp" />
<ClCompile Include="Extractor.cpp" />
<ClCompile Include="FileListCtrl.cpp" />
More information about the gme-commit
mailing list