TInt Cdmatest::FetchLeafL( CStifItemParser& aItem ) { TInt ret( KErrNone ); // Print to UI TestModuleIf().Printf( 0, _L("Camtest"), _L("FetchLeafL") ); iResultsFunction = NULL; TInt i( 0 ); TPtrC8 nodename ( GetNextStringLC( aItem, _L( "nodename" ) )->Des() ) ; //TPtrC datafile; TPtrC datafile( KNullDesC ); i = aItem.GetNextString ( datafile ) ; if ( i != KErrNone ) { iLog->Log(_L("FetchLeafL: ERROR Reading outfile argument: 0x%X"), i ); //return i; } else { iSaveFileName = datafile; iLog->Log( _L( " Save file nameis '%S'" ), &iSaveFileName ); iResultsFunction = SaveDataL; } SetURIL(nodename) ; /* void FetchLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aType, TInt aResultsRef, TInt aStatusRef ); */ TPtrC8 parentURI(RemoveLastSeg(nodename)); HBufC8 *luid = GetLuidAllocLC( parentURI ); Adapter()->FetchLeafObjectL( *iURI, *luid, KEmptyType, 7, 8 ) ; if ( iStatus == MSmlDmAdapter::EOk ) { iLog->Log( _L("FetchLeafL: FetchLeafObjectL Successful! %d" ), iStatus ); } else { iLog->Log( _L("FetchLeafL: FetchLeafObjectL Error ! %d" ), iStatus ); ret = KErrGeneral ; } CleanupStack::PopAndDestroy( luid ); CleanupStack::PopAndDestroy( ); // nodename iLog->Log( _L("FetchLeafL Test Complete with status %d" ), ret ); return ret; }
TInt Cdmatest::UpdateLeafL( CStifItemParser& aItem ) { TInt ret( KErrNone ); // Print to UI TestModuleIf().Printf( 0, _L("Cdmatest"), _L("UpdateLeafL") ); TPtrC8 nodename( GetNextStringLC ( aItem, _L("Node name") )->Des() ) ; TPtrC8 data (GetNextStringLC( aItem, _L("datafile"))->Des() ); HBufC8 *mime = GetNextStringLC( aItem, _L("mime") ) ; SetURIL( nodename ); TPtrC8 parentURI(RemoveLastSeg(nodename)); HBufC8 *luid = GetLuidAllocLC( parentURI ); TDataType type; TPtrC8 mimePtr( *mime == KNullDesC8 ? type.Des8() : mime->Des() ); /** virtual void UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aObject, const TDesC8& aType, TInt aStatusRef ) = 0; */ Adapter()->UpdateLeafObjectL( *iURI , *luid, data, mimePtr, 3); if ( iStatus == MSmlDmAdapter::EOk ) { iLog->Log( _L("UpdateLeafL: UpdateLeafObjectL Successful! %d" ), iStatus ); } else { iLog->Log( _L("UpdateLeafL UpdateLeafObjectL Error ! %d" ), iStatus ); ret = KErrGeneral ; } CleanupStack::PopAndDestroy(); // loadfile CleanupStack::PopAndDestroy(); // luid CleanupStack::PopAndDestroy(); // mime CleanupStack::PopAndDestroy(); // nodename iLog->Log( _L("UpdateLeafL Test Complete with status %d" ), ret ); return ret; }
nsresult nsAbMDBDirectory::GetAbDatabase() { if (mURI.IsEmpty()) return NS_ERROR_NOT_INITIALIZED; if (mDatabase) return NS_OK; nsresult rv; if (m_IsMailList) { // Get the database of the parent directory. nsAutoCString parentURI(mURINoQuery); int32_t pos = parentURI.RFindChar('/'); // If we didn't find a / something really bad has happened if (pos == -1) return NS_ERROR_FAILURE; parentURI = StringHead(parentURI, pos); nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIAbDirectory> directory; rv = abManager->GetDirectory(parentURI, getter_AddRefs(directory)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIAbMDBDirectory> mdbDir(do_QueryInterface(directory, &rv)); NS_ENSURE_SUCCESS(rv, rv); rv = mdbDir->GetDatabase(getter_AddRefs(mDatabase)); } else rv = GetDatabase(getter_AddRefs(mDatabase)); if (NS_SUCCEEDED(rv)) rv = mDatabase->AddListener(this); return rv; }
nsresult nsAbMDBDirectory::GetAbDatabase() { if (mURI.IsEmpty()) return NS_ERROR_NOT_INITIALIZED; if (mDatabase) return NS_OK; nsresult rv; if (m_IsMailList) { // Get the database of the parent directory. nsCString parentURI(mURINoQuery); PRInt32 pos = parentURI.RFindChar('/'); // If we didn't find a / something really bad has happened if (pos == -1) return NS_ERROR_FAILURE; parentURI = StringHead(parentURI, pos); nsCOMPtr<nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1", &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIRDFResource> resource; rv = rdfService->GetResource(parentURI, getter_AddRefs(resource)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIAbMDBDirectory> mdbDir(do_QueryInterface(resource, &rv)); NS_ENSURE_SUCCESS(rv, rv); rv = mdbDir->GetDatabase(getter_AddRefs(mDatabase)); } else rv = GetDatabase(getter_AddRefs(mDatabase)); if (NS_SUCCEEDED(rv)) rv = mDatabase->AddListener(this); return rv; }
TInt Cdmatest::ExecuteLeafL( CStifItemParser& aItem ) { TInt ret( KErrNone ); // Print to UI TestModuleIf().Printf( 0, _L("Camtest"), _L("ExecuteLeafL") ); iResultsFunction = NULL; TPtrC8 nodename( GetNextStringLC ( aItem, _L("Nodename") )->Des() ) ; TPtrC8 data( GetNextStringLC ( aItem, _L("Input file") )->Des() ) ; SetURIL(nodename) ; /* virtual void ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aArgument, const TDesC8& aType, TInt aStatusRef ) = 0; */ TDataType type; TPtrC8 parentURI(RemoveLastSeg(nodename)); HBufC8 *luid = GetLuidAllocLC( parentURI ); Adapter()->ExecuteCommandL( *iURI, *luid, data, KEmptyType, 11 ) ; if ( iStatus == MSmlDmAdapter::EOk ) { iLog->Log( _L("ExecuteLeafL: ExecuteCommandL Successful! %d" ), iStatus ); } else { iLog->Log( _L("ExecuteLeafL: ExecuteCommandL FetchLeafObjectL Error ! %d" ), iStatus ); ret = KErrGeneral ; } CleanupStack::PopAndDestroy( luid ); // luid CleanupStack::PopAndDestroy(); // data CleanupStack::PopAndDestroy(); // nodename iLog->Log( _L("ExecuteLeafL: Test Complete with status %d" ), ret ); return ret; }
DOMDocument * XIncludeUtils::doXIncludeXMLFileDOM(const XMLCh *href, const XMLCh *relativeHref, DOMNode *includeNode, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver){ if (XIncludeUtils::isInCurrentInclusionHistoryStack(href)){ /* including something back up the current history */ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCircularInclusionLoop, href, href); return NULL; } if (XMLString::equals(href, parsedDocument->getBaseURI())){ /* trying to include itself */ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCircularInclusionDocIncludesSelf, href, href); return NULL; } /* Instantiate the DOM parser. */ XercesDOMParser parser; parser.setDoNamespaces(true); /* don't want to recurse the xi processing here */ parser.setDoXInclude(false); /* create the schema info nodes, so that we can detect conflicting notations */ parser.setCreateSchemaInfo(true); XMLInternalErrorHandler xierrhandler; parser.setErrorHandler(&xierrhandler); DOMDocument *includedNode = NULL; try { InputSource* is=NULL; Janitor<InputSource> janIS(is); if(entityResolver) { XMLResourceIdentifier resIdentifier(XMLResourceIdentifier::ExternalEntity, relativeHref, NULL, NULL, includeNode->getBaseURI()); is=entityResolver->resolveEntity(&resIdentifier); janIS.reset(is); } if(janIS.get()!=NULL) parser.parse(*janIS.get()); else parser.parse(href); /* need to be able to release the parser but keep the document */ if (!xierrhandler.getSawError() && !xierrhandler.getSawFatal()) includedNode = parser.adoptDocument(); } catch (const XMLException& /*toCatch*/) { XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeResourceErrorWarning, href, href); } catch (const DOMException& /*toCatch*/) { XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeResourceErrorWarning, href, href); } catch (...) { XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeResourceErrorWarning, href, href); } //addDocumentURIToCurrentInclusionHistoryStack(href); if(includedNode != NULL){ /* baseURI fixups - see http://www.w3.org/TR/xinclude/#base for details. */ DOMElement *topLevelElement = includedNode->getDocumentElement(); if (topLevelElement && topLevelElement->getNodeType() == DOMNode::ELEMENT_NODE ){ XMLUri parentURI(includeNode->getBaseURI()); XMLUri includedURI(includedNode->getBaseURI()); /* if the paths differ we need to add a base attribute */ if (!XMLString::equals(parentURI.getPath(), includedURI.getPath())){ if (getBaseAttrValue(topLevelElement) == NULL){ /* need to calculate the proper path difference to get the relativePath */ topLevelElement->setAttribute(fgXIBaseAttrName, relativeHref); } else { /* the included node has base of its own which takes precedence */ XIncludeLocation xil(getBaseAttrValue(topLevelElement)); if (getBaseAttrValue(includeNode) != NULL){ /* prepend any specific base modification of the xinclude node */ xil.prependPath(getBaseAttrValue(includeNode)); } topLevelElement->setAttribute(fgXIBaseAttrName, xil.getLocation()); } } } } return includedNode; }
// --------------------------------------------------------------------------- // This method assumes that currentNode is an xinclude element and parses // it accordingly, acting on what it finds. // --------------------------------------------------------------------------- bool XIncludeUtils::doDOMNodeXInclude(DOMNode *xincludeNode, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver){ bool modifiedNode = false; /* the relevant attributes to look for */ const XMLCh *href = NULL; const XMLCh *parse = NULL; const XMLCh *xpointer = NULL; const XMLCh *encoding = NULL; const XMLCh *accept = NULL; const XMLCh *acceptlanguage = NULL; DOMNode *includeParent = xincludeNode->getParentNode(); if(xincludeNode->hasAttributes()) { /* get all the attributes of the node */ DOMNamedNodeMap *pAttributes = xincludeNode->getAttributes(); XMLSize_t nSize = pAttributes->getLength(); for(XMLSize_t i=0;i<nSize;++i) { DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i); const XMLCh *attrName = pAttributeNode->getName(); /* check each attribute against the potential useful names */ if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeHREFAttrName)){ href = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeParseAttrName)){ parse = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeXPointerAttrName)){ xpointer = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeEncodingAttrName)){ encoding = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptAttrName)){ accept = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptLanguageAttrName)){ acceptlanguage = pAttributeNode->getValue(); } else { /* if any other attribute is in the xi namespace, it's an error */ const XMLCh *attrNamespaceURI = pAttributeNode->getNamespaceURI(); if (attrNamespaceURI && XMLString::equals(attrNamespaceURI, XIncludeUtils::fgXIIIncludeNamespaceURI)){ } else { /* ignore - any other attribute is allowed according to spec, and must be ignored */ } } } } // 3.1 xi:include Element // The children property of the xi:include element may include a single xi:fallback element; // the appearance of more than one xi:fallback element, an xi:include element, // or any other element from the XInclude namespace is a fatal error. DOMNode *child; DOMElement *fallback = NULL; for (child = xincludeNode->getFirstChild(); child != 0; child=child->getNextSibling()){ if(child->getNodeType()!=DOMNode::ELEMENT_NODE) continue; if ( isXIFallbackDOMNode(child) ){ if (fallback != NULL){ /* fatal error - there are more than one fallback children */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeMultipleFallbackElems, parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI()); return false; } fallback = (DOMElement*)child; } else if(isXIIncludeDOMNode(child) || XMLString::equals(child->getNamespaceURI(), XIncludeUtils::fgXIIIncludeNamespaceURI)) { /* fatal error - an xi element different from xi:fallback is a child of xi:include */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeDisallowedChild, child->getNodeName(), parsedDocument->getDocumentURI()); return false; } } if (href == NULL){ /* this is an unrecoverable error until we have xpointer support - if there is an xpointer, the current document is assumed however, there is no xpointer support yet */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeNoHref, NULL, parsedDocument->getDocumentURI()); return false; } /* set up the accept and accept-language values */ if (accept != NULL){ } if (parse == NULL){ /* use the default, as specified */ parse = XIncludeUtils::fgXIIncludeParseAttrXMLValue; } if (xpointer != NULL){ /* not supported yet */ /* Note that finding an xpointer attr along with parse="text" is a Fatal Error * - http://www.w3.org/TR/xinclude/#include-location */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeXPointerNotSupported, NULL, href); return false; } /* set up the href according to what has gone before */ XIncludeLocation hrefLoc(href); XIncludeLocation relativeLocation(href); const XMLCh *includeBase = xincludeNode->getBaseURI(); if (includeBase != NULL){ hrefLoc.prependPath(includeBase); } if (getBaseAttrValue(xincludeNode) != NULL){ relativeLocation.prependPath(getBaseAttrValue(xincludeNode)); } /* Take the relevant action - we need to retrieve the target as a whole before we can know if it was successful or not, therefore the do* methods do not modify the parsedDocument. Swapping the results in is left to the caller (i.e. here) */ DOMText *includedText = NULL; DOMDocument *includedDoc = NULL; if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrXMLValue)){ /* including a XML element */ includedDoc = doXIncludeXMLFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), xincludeNode, parsedDocument, entityResolver); } else if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrTextValue)){ /* including a text value */ includedText = doXIncludeTEXTFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), encoding, xincludeNode, parsedDocument, entityResolver); } else { /* invalid parse attribute value - fatal error according to the specification */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeInvalidParseVal, parse, parsedDocument->getDocumentURI()); return false; } RefVectorOf<DOMNode> delayedProcessing(12,false); if (includedDoc == NULL && includedText == NULL){ /* there was an error - this is now a resource error let's see if there is a fallback */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedResourceError, hrefLoc.getLocation(), parsedDocument->getDocumentURI()); if (includeParent == NULL){ includeParent = parsedDocument; } // we could be getting errors trying to insert elements at the root of the document, so we should use replaceChild; // in order to handle multiple nodes, add them to a document fragment and use that to replace the original node if (fallback){ /* baseURI fixups - see http://www.w3.org/TR/xinclude/#base for details. */ XMLUri parentURI(includeParent->getBaseURI()); XMLUri includedURI(fallback->getBaseURI()); if (fallback->hasChildNodes()){ DOMDocumentFragment* frag = parsedDocument->createDocumentFragment(); DOMNode *child = fallback->getFirstChild(); /* add the content of the fallback element, and remove the fallback elem itself */ for ( ; child != NULL ; child=child->getNextSibling()){ if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){ continue; } DOMNode *newNode = parsedDocument->importNode(child, true); /* if the paths differ we need to add a base attribute */ if (newNode->getNodeType()==DOMNode::ELEMENT_NODE && !XMLString::equals(parentURI.getPath(), includedURI.getPath())){ if (getBaseAttrValue(newNode) == NULL){ /* need to calculate the proper path difference to get the relativePath */ ((DOMElement*)newNode)->setAttribute(fgXIBaseAttrName, getBaseAttrValue(fallback->getParentNode())); } else { /* the included node has base of its own which takes precedence */ XIncludeLocation xil(getBaseAttrValue(newNode)); if (getBaseAttrValue(fallback->getParentNode()) != NULL){ /* prepend any specific base modification of the xinclude node */ xil.prependPath(getBaseAttrValue(fallback->getParentNode())); } ((DOMElement*)newNode)->setAttribute(fgXIBaseAttrName, xil.getLocation()); } } DOMNode *newChild = frag->appendChild(newNode); // don't process the node now, wait until it is placed in the final position delayedProcessing.addElement(newChild); //parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver); } includeParent->replaceChild(frag, xincludeNode); frag->release(); for(XMLSize_t i=0;i<delayedProcessing.size();i++) { DOMNode* childNode=delayedProcessing.elementAt(i); parseDOMNodeDoingXInclude(childNode, parsedDocument, entityResolver); } modifiedNode = true; } else { /* empty fallback element - simply remove it! */ includeParent->removeChild(xincludeNode); modifiedNode = true; } } else { XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedNoFallback, parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI()); return false; } } else { if (includedDoc){ /* record the successful include while we process the children */ addDocumentURIToCurrentInclusionHistoryStack(hrefLoc.getLocation()); DOMDocumentFragment* frag = parsedDocument->createDocumentFragment(); /* need to import the document prolog here */ DOMNode *child = includedDoc->getFirstChild(); for (; child != NULL; child = child->getNextSibling()) { if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE) continue; // check for NOTATION or ENTITY clash if(child->getNodeType()==DOMNode::ELEMENT_NODE && includedDoc->getDoctype()!=NULL) { DOMNamedNodeMap *pAttributes = child->getAttributes(); XMLSize_t nSize = pAttributes->getLength(); for(XMLSize_t i=0;i<nSize;++i) { DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i); const DOMTypeInfo * typeInfo=pAttributeNode->getSchemaTypeInfo(); if(typeInfo && XMLString::equals(typeInfo->getTypeNamespace(), XMLUni::fgInfosetURIName)) { if(XMLString::equals(typeInfo->getTypeName(), XMLUni::fgNotationString)) { const XMLCh* notationName=pAttributeNode->getNodeValue(); DOMNotation* notat=(DOMNotation*)includedDoc->getDoctype()->getNotations()->getNamedItem(notationName); // ensure we have a DTD if(parsedDocument->getDoctype()==NULL) parsedDocument->insertBefore(parsedDocument->createDocumentType(parsedDocument->getDocumentElement()->getNodeName(), NULL,NULL), parsedDocument->getFirstChild()); DOMNotation* myNotation=(DOMNotation*)parsedDocument->getDoctype()->getNotations()->getNamedItem(notationName); if(myNotation==NULL) { // it's missing, add it parsedDocument->getDoctype()->getNotations()->setNamedItem(parsedDocument->importNode(notat, true)); } else if(XMLString::equals(myNotation->getPublicId(), notat->getPublicId()) && XMLString::equals(myNotation->getSystemId(), notat->getSystemId()) && XMLString::equals(myNotation->getBaseURI(), notat->getBaseURI())) { // it's duplicate, ignore it } else { // it's a conflict, report it XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingNotation, notationName, parsedDocument->getDocumentURI()); } } else if(XMLString::equals(typeInfo->getTypeName(), XMLUni::fgEntityString)) { const XMLCh* entityName=pAttributeNode->getNodeValue(); DOMEntity* ent=(DOMEntity*)includedDoc->getDoctype()->getEntities()->getNamedItem(entityName); // ensure we have a DTD if(parsedDocument->getDoctype()==NULL) parsedDocument->insertBefore(parsedDocument->createDocumentType(parsedDocument->getDocumentElement()->getNodeName(), NULL,NULL), parsedDocument->getFirstChild()); DOMEntity* myEnt=(DOMEntity*)parsedDocument->getDoctype()->getEntities()->getNamedItem(entityName); if(myEnt==NULL) { // it's missing, add it parsedDocument->getDoctype()->getEntities()->setNamedItem(parsedDocument->importNode(ent, true)); } else if(XMLString::equals(myEnt->getPublicId(), ent->getPublicId()) && XMLString::equals(myEnt->getSystemId(), ent->getSystemId()) && XMLString::equals(myEnt->getBaseURI(), ent->getBaseURI())) { // it's duplicate, ignore it } else { // it's a conflict, report it XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingEntity, entityName, parsedDocument->getDocumentURI()); } } } } } DOMNode *newNode = parsedDocument->importNode(child, true); DOMNode *newChild = frag->appendChild(newNode); // don't process the node now, wait until it is placed in the final position delayedProcessing.addElement(newChild); //parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver); } includeParent->replaceChild(frag, xincludeNode); frag->release(); for(XMLSize_t i=0;i<delayedProcessing.size();i++) { DOMNode* childNode=delayedProcessing.elementAt(i); parseDOMNodeDoingXInclude(childNode, parsedDocument, entityResolver); } popFromCurrentInclusionHistoryStack(NULL); modifiedNode = true; } else if (includedText){ includeParent->replaceChild(includedText, xincludeNode); modifiedNode = true; } } if (includedDoc) includedDoc->release(); return modifiedNode; }