-
Notifications
You must be signed in to change notification settings - Fork 59
/
XSLTransformDlg.cpp
119 lines (92 loc) · 3.8 KB
/
XSLTransformDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// XSLTransformDlg.cpp : implementation file
//
#include "StdAfx.h"
#include "Scintilla.h"
#include "XMLTools.h"
#include "XSLTransformDlg.h"
#include "Report.h"
#include "menuCmdID.h"
#include "XmlWrapperInterface.h"
#include "MSXMLWrapper.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//extern void updateProxyConfig();
/////////////////////////////////////////////////////////////////////////////
// CXSLTransformDlg dialog
CXSLTransformDlg::CXSLTransformDlg(CWnd* pParent /*=NULL*/, unsigned long flags /*= 0*/)
: CDialog(CXSLTransformDlg::IDD, pParent) {
//{{AFX_DATA_INIT(CXSLTransformDlg)
m_sSelectedFile = _T("");
m_sXSLTOptions = _T("");
//}}AFX_DATA_INIT
this->m_iFlags = flags;
}
void CXSLTransformDlg::DoDataExchange(CDataExchange* pDX) {
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXSLTransformDlg)
DDX_Text(pDX, IDC_EDIT_XSLTFILE, m_sSelectedFile);
DDX_Text(pDX, IDC_EDIT_XSLTOPTIONS, m_sXSLTOptions);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CXSLTransformDlg, CDialog)
//{{AFX_MSG_MAP(CXSLTransformDlg)
ON_BN_CLICKED(IDC_BTN_TRANSFORM, OnBtnTransform)
ON_BN_CLICKED(IDC_BTN_BROWSEXSLTFILE, OnBtnBrowseXSLTFile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXSLTransformDlg message handlers
HWND CXSLTransformDlg::getCurrentHScintilla(int which) {
return (which == 0)?nppData._scintillaMainHandle:nppData._scintillaSecondHandle;
}
BOOL CXSLTransformDlg::OnInitDialog() {
CDialog::OnInitDialog();
CRect myRect;
GetWindowRect(&myRect);
MoveWindow(myRect.left+100, myRect.top+100, myRect.Width(), myRect.Height());
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CXSLTransformDlg::OnBtnTransform() {
this->UpdateData();
if (this->m_sSelectedFile.GetLength() <= 0) {
Report::_printf_err(L"Cannot continue, missing parameters. Please select a file.");
return;
}
int currentEdit;
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)¤tEdit);
HWND hCurrentEditView = getCurrentHScintilla(currentEdit);
size_t currentLength = (size_t) ::SendMessage(hCurrentEditView, SCI_GETLENGTH, 0, 0);
char* data = new char[currentLength + sizeof(char)];
if (!data) return; // allocation error, abort check
memset(data, '\0', currentLength + sizeof(char));
::SendMessage(hCurrentEditView, SCI_GETTEXT, currentLength + sizeof(char), reinterpret_cast<LPARAM>(data));
XmlWrapperInterface* wrapper = new MSXMLWrapper(data, currentLength);
delete[] data; data = NULL;
XSLTransformResultType res;
if (wrapper->xslTransform(m_sSelectedFile.GetString(), &res, m_sXSLTOptions.GetString())) {
::SendMessage(nppData._nppHandle, NPPM_MENUCOMMAND, 0, IDM_FILE_NEW);
if (res.encoding != UniMode::uniEnd) Report::setEncoding(res.encoding, hCurrentEditView);
::SendMessage(hCurrentEditView, SCI_SETTEXT, 0, reinterpret_cast<LPARAM>(res.data.c_str()));
}
else {
std::vector<ErrorEntryType> errors = wrapper->getLastErrors();
displayXMLErrors(errors, hCurrentEditView, L"Error while XSL transformation");
}
delete wrapper;
}
CStringW CXSLTransformDlg::ShowOpenFileDlg(CStringW filetypes) {
CFileDialog dlg(TRUE, NULL, NULL, NULL, filetypes);
INT_PTR ret = dlg.DoModal();
if (ret == IDOK) {
return dlg.GetPathName();
}
return "";
}
void CXSLTransformDlg::OnBtnBrowseXSLTFile() {
CStringW ret = ShowOpenFileDlg("XML/XSL Files|*.xml;*.xsl|All files|*.*|");
if (ret.GetLength()) GetDlgItem(IDC_EDIT_XSLTFILE)->SetWindowText(ret);
}