engine/src/OpmlParser.cpp
changeset 60 4d230e702aa3
parent 20 c92d8384952c
child 65 bcd88ba95046
equal deleted inserted replaced
59:9569ea080d5a 60:4d230e702aa3
    71 	CleanupStack::PopAndDestroy(charset);
    71 	CleanupStack::PopAndDestroy(charset);
    72 	}
    72 	}
    73 
    73 
    74 void COpmlParser::OnEndDocumentL(TInt aErrorCode)
    74 void COpmlParser::OnEndDocumentL(TInt aErrorCode)
    75 	{
    75 	{
    76 	iFeedEngine.OpmlParsingComplete(aErrorCode, iNumFeedsAdded);
    76 	iFeedEngine.OpmlParsingCompleteL(aErrorCode, iNumFeedsAdded);
    77 	//DP("OnEndDocumentL()");
    77 	//DP("OnEndDocumentL()");
    78 	}
    78 	}
    79 
    79 
    80 void COpmlParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt /*aErrorCode*/)
    80 void COpmlParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt /*aErrorCode*/)
    81 	{
    81 	{
    94 		// <body> <outline>
    94 		// <body> <outline>
    95 		
    95 		
    96 		if(str.CompareF(KTagOutline) == 0) {
    96 		if(str.CompareF(KTagOutline) == 0) {
    97 			iOpmlState = EStateOpmlOutline;
    97 			iOpmlState = EStateOpmlOutline;
    98 		}
    98 		}
    99 		break;
    99 		
       
   100 		// there are two variations on OPML, where the <outline> tags sit either
       
   101 		// directly below <body>, or inside a collective <body> <outline>
       
   102 		// by checking if the <body> <outline> has arguments, we can support both
       
   103 		// by falling through to the nextstate
       
   104 		if (aAttributes.Count() == 0)
       
   105 			{
       
   106 			break;
       
   107 			}
   100 	case EStateOpmlOutline:
   108 	case EStateOpmlOutline:
   101 		// <body> <outline> <outline...
   109 		// <body> <outline> <outline...
   102 		if(str.CompareF(KTagOutline) == 0) {
   110 		if(str.CompareF(KTagOutline) == 0) {
   103 			iOpmlState=EStateOpmlOutlineOutline;
   111 			iOpmlState=EStateOpmlOutlineOutline;
   104 			CFeedInfo* newFeed = CFeedInfo::NewLC();
   112 			CFeedInfo* newFeed = CFeedInfo::NewLC();
   120 					hasUrl = ETrue;			
   128 					hasUrl = ETrue;			
   121 				// htmlUrl
   129 				// htmlUrl
   122 				} else if (attr16.Compare(KTagHtmlUrl) == 0) {
   130 				} else if (attr16.Compare(KTagHtmlUrl) == 0) {
   123 					newFeed->SetLinkL(*val16);
   131 					newFeed->SetLinkL(*val16);
   124 					hasUrl = ETrue;
   132 					hasUrl = ETrue;
   125 				// text=...
   133 				// title=...
   126 				} else if (attr16.Compare(KTagTitle) == 0) {
   134 				} else if (attr16.Compare(KTagTitle) == 0) {
   127 					newFeed->SetTitleL(*val16);
   135 					newFeed->SetTitleL(*val16);
   128 					newFeed->SetCustomTitle();
       
   129 					hasTitle = ETrue;
   136 					hasTitle = ETrue;
   130 				// description=
   137 				// description=
   131 				} else if (attr16.Compare(KTagDescription) == 0) {
   138 				} else if (attr16.Compare(KTagDescription) == 0) {
   132 					newFeed->SetDescriptionL(*val16);
   139 					newFeed->SetDescriptionL(*val16);
       
   140 				// text=
   133 				} else if (attr16.Compare(KTagText) == 0) {
   141 				} else if (attr16.Compare(KTagText) == 0) {
   134 					if (!hasTitle) {
   142 					if (!hasTitle) {
   135 						newFeed->SetTitleL(*val16);
   143 						newFeed->SetTitleL(*val16);
   136 						newFeed->SetCustomTitle();
       
   137 						hasTitle = ETrue;
   144 						hasTitle = ETrue;
   138 					}
   145 					}
   139 				} 
   146 				} 
   140 				CleanupStack::PopAndDestroy(val16);
   147 				CleanupStack::PopAndDestroy(val16);
   141 			}
   148 			}
   146 			
   153 			
   147 			if (!hasTitle) {
   154 			if (!hasTitle) {
   148 				newFeed->SetTitleL(newFeed->Url());
   155 				newFeed->SetTitleL(newFeed->Url());
   149 			}
   156 			}
   150 			
   157 			
       
   158 			// if the title is the same as the URL, it is hardly a custom
       
   159 			// title, so let's replace it on update
       
   160 			if (newFeed->Title().Length() &&
       
   161 					newFeed->Url().Length() &&
       
   162 					newFeed->Title().Compare(newFeed->Url()) != 0) {
       
   163 				newFeed->SetCustomTitle();
       
   164 			}
       
   165 			
   151 			if (iSearching) {
   166 			if (iSearching) {
   152 				iFeedEngine.AddSearchResultL(newFeed);
   167 				iFeedEngine.AddSearchResultL(newFeed);
   153 				CleanupStack::Pop(newFeed);
   168 				CleanupStack::Pop(newFeed);
   154 			} else {
   169 			} else {
   155 				if(iFeedEngine.AddFeedL(*newFeed))
   170 				TRAPD(err, iFeedEngine.AddFeedL(*newFeed))
       
   171 				if (err == KErrNone)
   156 					{
   172 					{
   157 					iNumFeedsAdded++;
   173 					iNumFeedsAdded++;
   158 					}
   174 					}
   159 				CleanupStack::PopAndDestroy(newFeed);
   175 				CleanupStack::PopAndDestroy(newFeed);
   160 			}
   176 			}
   227 	}
   243 	}
   228 
   244 
   229 void COpmlParser::OnError(TInt aErrorCode)
   245 void COpmlParser::OnError(TInt aErrorCode)
   230 	{
   246 	{
   231 	DP1("COpmlParser::OnError %d", aErrorCode);
   247 	DP1("COpmlParser::OnError %d", aErrorCode);
   232 	iFeedEngine.OpmlParsingComplete(aErrorCode, iNumFeedsAdded);
   248 	TRAP_IGNORE(iFeedEngine.OpmlParsingCompleteL(aErrorCode, iNumFeedsAdded));
   233 	}
   249 	}
   234 
   250 
   235 TAny* COpmlParser::GetExtendedInterface(const TInt32 /*aUid*/)
   251 TAny* COpmlParser::GetExtendedInterface(const TInt32 /*aUid*/)
   236 	{
   252 	{
   237 	//DP("GetExtendedInterface()");
   253 	//DP("GetExtendedInterface()");