engine/src/PodcastUtils.cpp
author Sebastian Brannstrom <sebastianb@symbian.org>
Sat, 16 Oct 2010 15:36:19 +0100
branchsymbian1
changeset 240 03e8cc4066ba
parent 161 ce4f70a6d1d2
child 246 140a404c6b53
permissions -rw-r--r--
Fix for bug 2818
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     1
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     2
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     3
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     4
* All rights reserved.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     5
* This component and the accompanying materials are made available
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     6
* under the terms of the License "Eclipse Public License v1.0"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     7
* which accompanies this distribution, and is available
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     8
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     9
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    10
* Initial Contributors:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    11
* EmbedDev AB - initial contribution.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    12
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    13
* Contributors:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    15
* Description:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    16
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    17
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    18
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    19
#include <e32std.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    20
#include <e32base.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
#include <TXTETEXT.H> // for ELineBreak
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
#include "PodcastUtils.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
#include "debug.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
#include "FeedEngine.h" // for KMaxDescriptionLength
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
EXPORT_C void PodcastUtils::FixProtocolsL(TDes &aUrl)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    27
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
	HBufC* urlCopy = aUrl.AllocLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
	TPtr urlCopyPtr (urlCopy->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
	urlCopyPtr.LowerCase();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
	// url is always present so access that								
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
	// Some pod links are written in format itpc://mylink.net/podcast.xml
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
	// Symbian HTTP stack does not like itpc:// 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
	// Try to use a HTTP instead.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
	TInt p = urlCopyPtr.Find(KItpcPrefix);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
	if (p >= 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
		aUrl.Delete(p, KItpcPrefix().Length());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
	// Some pod links are written in format pcast://mylink.net/podcast.xml
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
	// Symbian HTTP stack does not like itpc:// 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
	// Try to use a HTTP instead.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
	p = urlCopyPtr.Find(KPcastPrefix);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
	if (p >= 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
		aUrl.Delete(p, KPcastPrefix().Length());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
	// The URL must start with http://, otherwise the HTTP stack fails.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
	TInt pos = urlCopyPtr.Find(KURLPrefix);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
	if (pos == KErrNotFound)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
		HBufC* newUrl = HBufC::NewL(aUrl.Length() + KURLPrefix().Length());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
		TPtr ptr = newUrl->Des();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
		ptr.Append(KURLPrefix());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
		ptr.Append(aUrl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
		// replace the url buffer
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
		aUrl.Copy(*newUrl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
		delete newUrl;					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
	CleanupStack::PopAndDestroy(urlCopy);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
EXPORT_C void PodcastUtils::CleanHtmlL(TDes &str)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
{
240
03e8cc4066ba Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
    71
	DP("PodcastUtils::CleanHtmlL BEGIN");
21
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 19
diff changeset
    72
	if (str.Length() == 0)
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 19
diff changeset
    73
		{
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 19
diff changeset
    74
		return;
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 19
diff changeset
    75
		}
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 19
diff changeset
    76
	
240
03e8cc4066ba Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
    77
	DP("    miscellaneous");
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    78
// miscellaneous cleanup
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
	const TChar KLineBreak(CEditableText::ELineBreak); 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
	_LIT(KNewLine, "\n");
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
    81
	_LIT(KNewLineWindows, "\r\n");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
	ReplaceString(str, KNewLine, KNullDesC);
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
    83
	ReplaceString(str, KNewLineWindows, KNullDesC);
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    84
240
03e8cc4066ba Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
    85
	DP("    strip HTML");
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    86
// strip out HTML tags
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    87
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
	TInt startPos = str.Locate('<');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
	TInt endPos = str.Locate('>');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
	HBufC* tmpBuf = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
	TPtr tmp(tmpBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
		//DP1("Cleaning out %S", &str.Mid(startPos, endPos-startPos+1));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
		tmp.Copy(str.Left(startPos));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
		TPtrC ptr=str.Mid(startPos, endPos-startPos+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
		_LIT(KHtmlBr, "<br>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
		_LIT(KHtmlBr2, "<br />");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
		_LIT(KHtmlBr3, "<br/>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
		_LIT(KHtmlP, "<p>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
		if (ptr.CompareF(KHtmlBr)== 0 || ptr.CompareF(KHtmlBr2)== 0 || ptr.CompareF(KHtmlBr3)== 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
			tmp.Append(KLineBreak);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
		else if (ptr.CompareF(KHtmlP) == 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
			tmp.Append(KLineBreak);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
			tmp.Append(KLineBreak);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
		if (str.Length() > endPos+1) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
			tmp.Append(str.Mid(endPos+1));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
		str.Copy(tmp);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
		startPos = str.Locate('<');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
		endPos = str.Locate('>');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
	}
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   118
		
240
03e8cc4066ba Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
   119
	DP("    change HTML encoded chars to unicode");
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   120
// change HTML encoded chars to unicode
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   121
	startPos = str.Locate('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   122
	endPos = str.Locate(';');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   123
	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   124
		{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   125
		TPtrC ptr(str.Mid(startPos+1, endPos-startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   126
		// check for whitespace
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   127
		if (ptr.Locate(' ') == KErrNotFound)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   128
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   129
			// numerical constant
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   130
			if (ptr[0] == '#')
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   131
				{ 
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   132
				TUint length = endPos - startPos;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   133
				if (length > 2)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   134
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   135
					tmp.Copy(str.Left(startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   136
					ptr.Set(str.Mid(startPos+2, length-2));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   137
					
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   138
					TUint charCode = 0;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   139
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   140
					if (ptr[0] == 'x')
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   141
						{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   142
						// hexadecimal
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   143
						ptr.Set(ptr.Mid(1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   144
						TLex16 lex(ptr);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   145
						lex.Val(charCode, EHex);	
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   146
						}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   147
					else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   148
						{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   149
						//decimal
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   150
						TLex16 lex(ptr);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   151
						lex.Val(charCode, EDecimal);	
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   152
						}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   153
					
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   154
					TChar charChar(charCode);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   155
					tmp.Append(charChar);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   156
					tmp.Append(str.Mid(endPos+1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   157
					str.Copy(tmp);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   158
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   159
				}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   160
			// literal constant
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   161
			else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   162
				{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   163
				_LIT(KAmp, "amp;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   164
				_LIT(KQuot, "quot;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   165
				_LIT(KNbsp, "nbsp;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   166
				_LIT(KCopy, "copy;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   167
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   168
				// copy start of string
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   169
				tmp.Copy(str.Left(startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   170
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   171
				if (ptr.CompareF(KAmp) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   172
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   173
					tmp.Append('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   174
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   175
				else if (ptr.CompareF(KQuot) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   176
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   177
					tmp.Append('"');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   178
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   179
				else if (ptr.CompareF(KNbsp) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   180
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   181
					tmp.Append(' ');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   182
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   183
				else if (ptr.CompareF(KCopy) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   184
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   185
					tmp.Append('\xA9');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   186
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   187
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   188
				// copy end of string
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   189
				tmp.Append(str.Mid(endPos+1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   190
				str.Copy(tmp);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   191
				}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   192
			}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   193
		
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   194
		TInt newPos = str.Mid(startPos+1).Locate('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   195
		
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   196
		if (newPos != KErrNotFound)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   197
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   198
			startPos = startPos+1 + newPos;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   199
			endPos = str.Locate(';');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   200
			}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   201
		else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   202
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   203
			startPos = KErrNotFound;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   204
			endPos = KErrNotFound;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   205
			}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   206
		}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   207
		
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
	CleanupStack::PopAndDestroy(tmpBuf);
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   209
	
240
03e8cc4066ba Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
   210
	DP("    trim");
161
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   211
	if(str.Length()>1)
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   212
		{
240
03e8cc4066ba Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
   213
		DP1("str.Length() ==%d", str.Length());
161
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   214
		// chop away newlines at start
240
03e8cc4066ba Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
   215
		while (str.Length() && (str[0] == KLineBreak))  {
03e8cc4066ba Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
   216
			DP("mid");
161
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   217
			str = str.Mid(1);
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   218
		}
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   219
		
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   220
		// chop away newlines at end
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   221
	
240
03e8cc4066ba Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
   222
		while (str.Length() && (str[str.Length()-1] == KLineBreak)) {
03e8cc4066ba Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
   223
			DP("left");
161
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   224
			str = str.Left(str.Length()-1);
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   225
		}
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   226
161
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   227
		str.Trim();
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   228
		}
240
03e8cc4066ba Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
   229
	DP("PodcastUtils::CleanHtmlL END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
15
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   232
EXPORT_C void PodcastUtils::RemoveAllFormatting(TDes & aString)
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   233
	{
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   234
	// check for combination first so we prevent adding two spaces 
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   235
	ReplaceString(aString,_L("\r\n"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   236
	
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   237
	ReplaceString(aString,_L("\n"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   238
	ReplaceString(aString,_L("\r"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   239
	
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   240
	}
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   241
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
EXPORT_C void PodcastUtils::ReplaceString(TDes & aString, const TDesC& aStringToReplace, const TDesC& aReplacement)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
	TInt pos=aString.Find(aStringToReplace);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
	TInt offset = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
	while (pos != KErrNotFound)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
		aString.Replace(offset+pos, aStringToReplace.Length(), aReplacement);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
		offset += pos + aStringToReplace.Length()+1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
		if (offset > aString.Length())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
			return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
		pos=aString.Mid(offset).Find(aStringToReplace);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
EXPORT_C void PodcastUtils::ReplaceChar(TDes & aString, TUint aCharToReplace, TUint aReplacement)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
	TInt strLen=aString.Length();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
	for (TInt i=0; i < strLen; i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
		if (aString[i] == aCharToReplace)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
			aString[i] = aReplacement;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
EXPORT_C void PodcastUtils::EnsureProperPathName(TFileName &aPath)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
	// from the SDK: The following characters cannot occur in the path: < >: " / |*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
	ReplaceChar(aPath, '/', '_'); // better not to add \\ in case we have multiple /
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
	ReplaceChar(aPath, ':', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
	ReplaceChar(aPath, '?', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
	ReplaceChar(aPath, '|', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
	ReplaceChar(aPath, '*', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
	ReplaceChar(aPath, '<', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
	ReplaceChar(aPath, '>', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
	ReplaceChar(aPath, '"', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   284
	//buf.Append(_L("\\"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   285
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   286
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
EXPORT_C void PodcastUtils::FileNameFromUrl(const TDesC& aUrl, TFileName &aFileName)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
	TInt pos = aUrl.LocateReverse('/');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
	if (pos != KErrNotFound) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
		{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
		TPtrC str = aUrl.Mid(pos+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
		pos = str.Locate('?');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
		if (pos != KErrNotFound) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
			aFileName.Copy(str.Left(pos));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
			} 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
		else 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
			aFileName.Copy(str);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
	DP2("FileNameFromUrl in: %S, out: %S", &aUrl, &aFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   306
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   307
EXPORT_C void PodcastUtils::SQLEncode(TDes &aString)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   309
	ReplaceString(aString, _L("\""), _L("\"\""));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
	//ReplaceString(aString, _L("'"), _L("''"));	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   311
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
EXPORT_C void PodcastUtils::XMLEncode(TDes &aString)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   315
	ReplaceString(aString, _L("\""), _L("&quot;"));	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
	ReplaceString(aString, _L("<"), _L("&lt;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
	ReplaceString(aString, _L(">"), _L("&gt;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   318
	ReplaceString(aString, _L("&"), _L("&amp;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   319
	}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   320
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   321
EXPORT_C TBool PodcastUtils::IsVideoShow(TDesC &aUrl)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   322
	{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   323
	if (aUrl.Find(KVideoFormat1) != KErrNotFound ||
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   324
			aUrl.Find(KVideoFormat2) != KErrNotFound ||
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   325
			aUrl.Find(KVideoFormat3) != KErrNotFound)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   326
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   327
		return ETrue;
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   328
		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   329
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   330
	return EFalse;
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   331
	}