TVerdict CXmlEngXPathUtilsToBooleanTest::TestKXmlEngXPathUtilsToBoolean() { //Create the dom utils object TInt err = KErrNone; _LIT8(KLit1, "asdfds"); _LIT8(KLit2, "xzcvcv"); _LIT8(KLit3, "lklklk"); TBufC8<30> aLocalName(KLit1); TBufC8<30> aNamespaceUri(KLit2); TBufC8<30> aPrefix(KLit3); RXmlEngDOMImplementation domImpl; domImpl.OpenL(); RXmlEngDocument doc; doc.OpenL(domImpl); doc.CreateDocumentElementL(aLocalName, aNamespaceUri, aPrefix); TXmlEngElement aElement; //For code coverage TBool isEmpty = XmlEngXPathUtils::ToBoolean(aElement); doc.Close(); domImpl.Close(); if (KErrNone != err) { return EFail; } return EPass; }
// --------------------------------------------------------------------------- // Add <KeyName> element to <KeyInfo> node and set the value of it. // --------------------------------------------------------------------------- // void XmlSecTemplate::SetKeyInfoL(RXmlEngDocument& aTemplate, const TDesC8& aKeyName) { if(!aKeyName.Compare(KNullDesC8)) { User::Leave(KErrWrongParameter); } if(aTemplate.IsNull()) { User::Leave(KErrTemplate); } xmlNodePtr keyInfo = NULL; TXmlEngNode tmpNode = aTemplate.DocumentElement(); xmlNodePtr root = INTERNAL_NODEPTR(tmpNode); keyInfo = xmlSecFindNode(root,xmlSecNodeKeyInfo, xmlSecDSigNs); if(!keyInfo) { User::Leave(KErrTemplate); } TXmlEngElement(keyInfo).RemoveChildren(); char* name = XmlEngXmlCharFromDes8L(aKeyName); root = xmlSecTmplKeyInfoAddKeyName(keyInfo,(unsigned char*)name); delete name; if(!root) { User::Leave(KErrNoMemory); } }
// --------------------------------------------------------------------------- // Destroy Template // --------------------------------------------------------------------------- // void XmlSecTemplate::DestroyTemplate(RXmlEngDocument& aTemplate) { if(aTemplate.NotNull()) { aTemplate.Close(); } }
EXPORT_C void CXEDomEx::SaveExampleL() { RXmlEngDocument document; TBuf<KFilePathSize> filepath(iDrive); _LIT(KFilename,"\\xedomexample\\input\\XML_parsing_001.xml"); filepath.Append(KFilename); TFileName srcFileName(filepath); // Need to have a document tree for saving it // One way is get a parsed document document = iDomParser.ParseFileL(srcFileName); CleanupClosePushL(document); // The document can be modified now ... //Save it to a file TBuf<KFilePathSize> filepath2(iDrive); _LIT(KFilename2, "\\xedomexample\\output\\XML_save_file.xml"); filepath2.Append(KFilename2); document.SaveL(filepath2); // The API to save (serialize) the document onto a file //Save to a buffer _LIT8(encoding,"UTF-8"); TXmlEngSerializationOptions options(0, encoding); RBuf8 buffer; CleanupClosePushL(buffer); // The API to save (serialize) the document onto a buffer // It can take different serialization options document.SaveL( buffer, document, options); CleanupStack::PopAndDestroy(); //buffer CleanupStack::PopAndDestroy(); //document }
EXPORT_C void CXEDomEx::ParseExampleL() { RXmlEngDocument document; TBuf<KFilePathSize> filepath(iDrive); _LIT(KFilename,"\\xedomexample\\input\\XML_parsing_001.xml"); filepath.Append(KFilename); TFileName srcFileName(filepath); // The API for parsing a file, returns a handle to document document = iDomParser.ParseFileL(srcFileName); if(document.NotNull()) { // We have got the parsed dom tree,it can be used to access tree contents // using document APIs. TPtrC8 name = document.DocumentElement().Name(); // finally closed by calling Close() document.Close(); } // Parse a buffer _LIT8(docW, "<doc>xmlns=\"http://test.pl\"><test>Test Content</test></doc>" ); RXmlEngDocument document2; TPtrC8 ptrW(docW); // The API for parsing a buffer, returns a handle to document document2 = iDomParser.ParseL(ptrW); if(document2.NotNull()) { // Use the document tree and close it finally document2.Close(); } }
// --------------------------------------------------------------------------- // Set Template // --------------------------------------------------------------------------- // void XmlSecTemplate::SetTemplateL(RXmlEngDocument& aTemplate, const RXmlEngDocument& aInput) { if(aInput.IsNull()) { User::Leave(KErrTemplate); }; if(aTemplate.NotNull()) { aTemplate.Close(); } aTemplate = aInput.CloneDocumentL(); }
// --------------------------------------------------------------------------- // Set Template from buffer // --------------------------------------------------------------------------- // void XmlSecTemplate::SetTemplateFromBufferL(RXmlEngDocument& aTemplate,const TDesC8& aBuffer) { if(aTemplate.NotNull()) { aTemplate.Close(); } // load template RXmlEngDOMImplementation dom; dom.OpenL(); CleanupClosePushL(dom); RXmlEngDOMParser parser; User::LeaveIfError(parser.Open(dom)); CleanupClosePushL(parser); aTemplate = parser.ParseL(aBuffer); CleanupStack::PopAndDestroy(&parser); CleanupStack::PopAndDestroy(&dom); }
// --------------------------------------------------------------------------- // Set Template from file // --------------------------------------------------------------------------- // void XmlSecTemplate::SetTemplateFromFileL(RXmlEngDocument& aTemplate, const TDesC8& aFile, RFs& aRFs) { if(aTemplate.NotNull()) { aTemplate.Close(); } // load template HBufC16* buf = CnvUtfConverter::ConvertToUnicodeFromUtf8L(aFile); CleanupStack::PushL(buf); RXmlEngDOMImplementation dom; dom.OpenL(); CleanupClosePushL(dom); RXmlEngDOMParser parser; User::LeaveIfError(parser.Open(dom)); CleanupClosePushL(parser); aTemplate = parser.ParseFileL(aRFs,buf->Des()); CleanupStack::PopAndDestroy(&parser); CleanupStack::PopAndDestroy(&dom); CleanupStack::PopAndDestroy(buf); }
// --------------------------------------------------------------------------- // Add element to <KeyInfo> node. // --------------------------------------------------------------------------- // void XmlSecTemplate::SetKeyInfoL(RXmlEngDocument& aTemplate, TXmlEngElement aKeyProp) { if(aKeyProp.IsNull()) { User::Leave(KErrWrongParameter); } if(aTemplate.IsNull()) { User::Leave(KErrTemplate); } xmlNodePtr keyInfo = NULL; TXmlEngNode tmpNode = aTemplate.DocumentElement(); xmlNodePtr root = INTERNAL_NODEPTR(tmpNode); keyInfo = xmlSecFindNode(root,xmlSecNodeKeyInfo, xmlSecDSigNs); if(!keyInfo) { User::Leave(KErrTemplate); } TXmlEngElement keyIn(keyInfo); keyIn.RemoveChildren(); keyIn.AppendChildL(aKeyProp); }
// --------------------------------------------------------- // CCookieTimer::LoadGroupDataFromFileL // --------------------------------------------------------- // TInt CCookieManagerServer::LoadGroupDataFromFileL( RFs& afileSession ) { CLOG( ( EServer, 0, _L( "-> CCookieManagerServer::LoadGroupDataFromFileL" ) ) ); TBuf<60> groupfile(KNullDesC); groupfile.Copy( KDefaultCookieXmlFolder ); groupfile.AppendNum( RProcess().SecureId(), EHex ); groupfile.Append( KDefaultCookieGroupFile ); RXmlEngDOMImplementation DOM_impl; DOM_impl.OpenL(); RXmlEngDocument doc; RXmlEngDOMParser parser; TInt error = parser.Open( DOM_impl ); if (error == KErrNone) { TRAPD( err, doc = parser.ParseFileL( afileSession, groupfile ) ); if ( ! err ) { TXmlEngNode node; TXmlEngElement element; RXmlEngNodeList<TXmlEngElement> nodelist1; RXmlEngNodeList<TXmlEngElement> nodelist2; node = doc.DocumentElement(); node.AsElement().GetChildElements(nodelist1); CleanupClosePushL(nodelist1); CleanupClosePushL(nodelist2); while ( nodelist1.HasNext() ) //Parent Node { element = nodelist1.Next(); element.GetChildElements(nodelist2); TPtrC8 name = element.Name(); RArray<TUint32> sharedAppUidArray(5); TUint32 groupId = 0; TBool cookieSharableFlag; TBool entryHasAttributes = element.HasAttributes(); if ( entryHasAttributes ) { RXmlEngNodeList<TXmlEngAttr> attributeList; element.GetAttributes(attributeList); CleanupClosePushL(attributeList); while ( attributeList.HasNext() ) { TXmlEngAttr attr = attributeList.Next(); TPtrC8 attrName = attr.Name(); TPtrC8 attrData = attr.Value(); SettingAttribute(attrName,attrData,groupId,sharedAppUidArray,cookieSharableFlag ); } CleanupStack::PopAndDestroy(); //attributeList } while( nodelist2.HasNext() )//Child Node { element = nodelist2.Next(); if ( ! element.IsNull() ) { TPtrC8 name = element.Name(); TBool hasAttributes = element.HasAttributes(); RXmlEngNodeList<TXmlEngAttr> attributeList; element.GetAttributes(attributeList); TInt count = attributeList.Count(); CleanupClosePushL(attributeList); while ( attributeList.HasNext() ) { TXmlEngAttr attr = attributeList.Next(); TPtrC8 attrName = attr.Name(); TPtrC8 attrData = attr.Value(); SettingAttribute(attrName,attrData,groupId,sharedAppUidArray,cookieSharableFlag ); } CleanupStack::PopAndDestroy(); //attributeList } } CGroupIdInfo* groupIdInfo = CGroupIdInfo::NewL( groupId, sharedAppUidArray, cookieSharableFlag ); CleanupStack::PushL( groupIdInfo ); iGroupIdArray->AddGroupIdL( groupIdInfo ); CleanupStack::Pop( groupIdInfo ); CCookieGroupData* cookieGroupData = CCookieGroupData::NewL(groupId,sharedAppUidArray,cookieSharableFlag); CleanupStack::PushL( groupIdInfo ); iCookieGroupDataArray->AddGroupDataL(cookieGroupData); CleanupStack::Pop( groupIdInfo ); sharedAppUidArray.Close(); } CleanupStack::PopAndDestroy(); //nodelist2 CleanupStack::PopAndDestroy(); //nodelist1 } } doc.Close(); parser.Close(); DOM_impl.Close(); CLOG( ( EServer, 0, _L( "<- CCookieManagerServer::LoadGroupDataFromFileL" ) ) ); return KErrNone; }