BOOL vmsMetalinkFile::ReadVerificationNode(IXMLDOMNode *pNode, vmsMetalinkFile_File *file) { IXMLDOMNodeListPtr spNodeList; pNode->get_childNodes (&spNodeList); if (spNodeList == NULL) return FALSE; IXMLDOMNodePtr spItem; while (SUCCEEDED (spNodeList->nextNode (&spItem)) && spItem != NULL) { CComBSTR bstrName; spItem->get_nodeName (&bstrName); if (bstrName == L"hash") { vmsMetalinkFile_File_Hash hash; if (ReadHashNode (spItem, &hash)) file->vHashes.add (hash); } spItem = NULL; } return TRUE; }
BOOL vmsMetalinkFile::ReadFilesNode(IXMLDOMNode *pFiles) { IXMLDOMNodeListPtr spNodeList; pFiles->get_childNodes (&spNodeList); if (spNodeList == NULL) return FALSE; IXMLDOMNodePtr spItem; BOOL bHasOkFileNode = FALSE; while (SUCCEEDED (spNodeList->nextNode (&spItem)) && spItem != NULL) { CComBSTR bstrName; spItem->get_nodeName (&bstrName); if (bstrName == L"file") { if (ReadFileNode (spItem)) bHasOkFileNode = TRUE; } spItem = NULL; } return bHasOkFileNode; }
BOOL vmsMetalinkFile::ReadResourcesNode(IXMLDOMNode *pNode, vmsMetalinkFile_File *file) { IXMLDOMNodeListPtr spNodeList; pNode->get_childNodes (&spNodeList); if (spNodeList == NULL) return FALSE; IXMLDOMNodePtr spItem; while (SUCCEEDED (spNodeList->nextNode (&spItem)) && spItem != NULL) { CComBSTR bstrName; spItem->get_nodeName (&bstrName); if (bstrName == L"url") { vmsMetalinkFile_File_Url url; if (ReadUrlNode (spItem, &url)) file->vMirrors.add (url); } spItem = NULL; } return TRUE; }
BOOL vmsMetalinkFile::Parse(LPCSTR pszFile) { USES_CONVERSION; IXMLDOMDocumentPtr spXML; IXMLDOMNodePtr spNode; spXML.CreateInstance (__uuidof (DOMDocument)); if (spXML == NULL) return FALSE; spXML->put_async (FALSE); VARIANT_BOOL bRes; spXML->load (COleVariant (pszFile), &bRes); if (bRes == FALSE) return FALSE; spXML->selectSingleNode (L"metalink", &spNode); if (spNode == NULL) return FALSE; IXMLDOMNodeListPtr spNodeList; spNode->get_childNodes (&spNodeList); if (spNodeList == NULL) return FALSE; IXMLDOMNodePtr spItem; BOOL bHasOkFilesNode = FALSE; while (SUCCEEDED (spNodeList->nextNode (&spItem)) && spItem != NULL) { CComBSTR bstrName; spItem->get_nodeName (&bstrName); if (bstrName == L"description") { CComBSTR bstrText; spItem->get_text (&bstrText); m_strDescription = W2A (bstrText); } else if (bstrName == L"files") { if (ReadFilesNode (spItem)) bHasOkFilesNode = TRUE; } spItem = NULL; } return bHasOkFilesNode; }
void CXMLTree::InsetXMLNode(MSXML2::IXMLDOMNodePtr iNode, HTREEITEM hParentItem) { IXMLDOMNodeListPtr iChildren = iNode->childNodes; IXMLDOMNodePtr iChild = NULL; while ((iChild = iChildren->nextNode()) != NULL) { CString s((BSTR) iChild->nodeName); HTREEITEM i = InsertItem(s, hParentItem); iChild.AddRef(); SetItemData(i, (DWORD) (IXMLDOMNode *) iChild); //rekurze InsetXMLNode(iChild, i); } }
BOOL vmsMetalinkFile::ReadFileNode(IXMLDOMNode *pFile) { USES_CONVERSION; IXMLDOMNodeListPtr spNodeList; pFile->get_childNodes (&spNodeList); if (spNodeList == NULL) return FALSE; vmsMetalinkFile_File file; IXMLDOMNamedNodeMapPtr spAttrs; pFile->get_attributes (&spAttrs); if (spAttrs != NULL) { IXMLDOMNodePtr spFileName; spAttrs->getNamedItem (L"name", &spFileName); if (spFileName != NULL) { COleVariant vt; spFileName->get_nodeValue (&vt); ASSERT (vt.vt == VT_BSTR); if (vt.vt == VT_BSTR) file.strName = W2A (vt.bstrVal); } } IXMLDOMNodePtr spItem; while (SUCCEEDED (spNodeList->nextNode (&spItem)) && spItem != NULL) { CComBSTR bstrName; spItem->get_nodeName (&bstrName); if (bstrName == L"verification") { ReadVerificationNode (spItem, &file); } else if (bstrName == L"resources") { ReadResourcesNode (spItem, &file); } else if (bstrName == L"os") { CComBSTR bstrText; spItem->get_text (&bstrText); file.strOS = W2A (bstrText); } spItem = NULL; } if (file.vMirrors.size () == 0) return FALSE; m_vFiles.add (file); return TRUE; }
void CPageEvents::OnOK() { // Save any changes made to the currently-selected node's attributes UpdateNodeFromItem(m_lParamSelected); // Inspect the <Event> nodes of the document if (NULL != m_spXMLDoc) { // Get all of the <Event> nodes in the document IXMLDOMNodeListPtr spNodeList; VERIFY(SUCCEEDED(m_spXMLDoc->getElementsByTagName(m_bstrEvent, &spNodeList))); // Process each node IXMLDOMNodePtr spNode; do { // Get the next node of the child list VERIFY(SUCCEEDED(spNodeList->nextNode(&spNode))); if (NULL != spNode) { // Query for the IXMLDOMElement interface IXMLDOMElementPtr spElement(spNode); ASSERT(NULL != spElement); // Get the event id attribute CComVariant varEventID; spElement->getAttribute(m_bstrID, &varEventID); VERIFY(SUCCEEDED(varEventID.ChangeType(VT_I4))); AGCEventID idEventBegin = (AGCEventID)(V_UI4(&varEventID)); AGCEventID idEventEnd = (AGCEventID)(idEventBegin + 1); // Get the LogAsNTEvent attribute IXMLDOMAttributePtr spAttrNT; if (S_OK == spElement->getAttributeNode(m_bstrLogAsNTEvent, &spAttrNT)) { CComVariant varLog2NT; spAttrNT->get_value(&varLog2NT); VERIFY(SUCCEEDED(varLog2NT.ChangeType(VT_BOOL))); // Add this event id to the range, if it should be logged if (V_BOOL(&varLog2NT)) m_spRangesNT->AddByValues(idEventBegin, idEventEnd); } // Get the LogAsDBEvent attribute IXMLDOMAttributePtr spAttrDB; if (S_OK == spElement->getAttributeNode(m_bstrLogAsDBEvent, &spAttrDB)) { CComVariant varLog2DB; spAttrDB->get_value(&varLog2DB); VERIFY(SUCCEEDED(varLog2DB.ChangeType(VT_BOOL))); // Add this event id to the range, if it should be logged if (V_BOOL(&varLog2DB)) m_spRangesDB->AddByValues(idEventBegin, idEventEnd); } } } while (NULL != spNode); // Set the enabled ranges of the event logger object VERIFY(SUCCEEDED(m_spEventLogger->put_EnabledNTEvents(m_spRangesNT))); VERIFY(SUCCEEDED(m_spEventLogger->put_EnabledDBEvents(m_spRangesDB))); } // Perform default processing CPropertyPage::OnOK(); }
HRESULT CPageEvents::AddXMLNodeToTree(IXMLDOMNode* pNode, HTREEITEM hParent) { // Get the list of child nodes IXMLDOMNodeListPtr spChildren; RETURN_FAILED(pNode->get_childNodes(&spChildren)); // Process each child node IXMLDOMNodePtr spChild; do { // Get the next node of the child list RETURN_FAILED(spChildren->nextNode(&spChild)); if (NULL != spChild) { // Get the child node's tagname int iImage; CString strType; CString strID; bool bIsGroup, bIsEvent; CComBSTR bstrText; IXMLDOMElementPtr spElement(spChild); if (NULL != spElement) { CComBSTR bstrTagName; RETURN_FAILED(spElement->get_tagName(&bstrTagName)); if (bstrTagName.Length()) { // Accept the Event and EventGroup tag names if (0 == wcscmp(bstrTagName, m_bstrEvent)) { bIsGroup = false; bIsEvent = true; } else if (0 == wcscmp(bstrTagName, m_bstrEventGroup)) { bIsGroup = true; bIsEvent = false; } // Get the display attributes if this is a group or event node if (bIsGroup || bIsEvent) { // Get the type of the element CComBSTR bstrSeverity; GetElementSeverity(spElement, &bstrSeverity); iImage = ImageFromSeverity(bstrSeverity); strType = TypeFromSeverity(bstrSeverity); // Get the id of the element CComBSTR bstrID; GetElementID(spElement, &bstrID); strID = bstrID; // Get the name of the element RETURN_FAILED(GetElementDisplayName(spElement, &bstrText)); } } } // Add the node to the tree and list controls if (bstrText.Length()) { // Typecast the element pointer as an LPARAM IXMLDOMElement* pElement = spElement.Detach(); LPARAM lParam = reinterpret_cast<LPARAM>(pElement); // Insert the element into the tree USES_CONVERSION; LPCTSTR pszText = OLE2CT(bstrText); UINT mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; HTREEITEM hItem = m_tree.InsertItem(mask, pszText, iImage, iImage, 0, 0, lParam, hParent, TVI_LAST); // Insert the element into the list, if its not an <EventGroup> if (!bIsGroup) { int iItem = m_listEvents.GetItemCount(); iItem = m_listEvents.InsertItem(LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM, iItem, strType, 0, 0, iImage, lParam); if (-1 != iItem) { // Keep a reference on the element pointer in the LPARAM pElement->AddRef(); // Keep track of maximum widths int cx = m_listEvents.GetStringWidth(strType + " "); m_cxMaxType = max(m_cxMaxType, cx); cx = m_listEvents.GetStringWidth(strID + " "); m_cxMaxID = max(m_cxMaxID, cx); // Set the subitems m_listEvents.SetItem(iItem, 1, LVIF_TEXT, strID, 0, 0, 0, 0); m_listEvents.SetItem(iItem, 2, LVIF_TEXT, pszText, 0, 0, 0, 0); } } // Recurse into node, if it's a group if (bIsGroup) { RETURN_FAILED(AddXMLNodeToTree(spChild, hItem)); } } } } while (NULL != spChild); // Indicate success return S_OK; }