engine/src/PodcastUtils.cpp
author Sebastian Brannstrom <sebastianb@symbian.org>
Sat, 13 Nov 2010 13:54:36 +0000
branch3rded
changeset 343 9c56bf585696
parent 279 5a44ec2f6f4d
child 366 f015466e6642
child 390 d7abecc9d189
permissions -rw-r--r--
Catching up with 5th edition
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
{
275
e2c3225833c3 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
		}
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    76
// miscellaneous cleanup
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 279
diff changeset
    77
	DP("    miscellaneous cleanup");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
	const TChar KLineBreak(CEditableText::ELineBreak); 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
	_LIT(KNewLine, "\n");
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
    80
	_LIT(KNewLineWindows, "\r\n");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
	ReplaceString(str, KNewLine, KNullDesC);
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
    82
	ReplaceString(str, KNewLineWindows, KNullDesC);
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    83
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    84
// strip out HTML tags
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 279
diff changeset
    85
	DP("    strip out HTML tags");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
	TInt startPos = str.Locate('<');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
	TInt endPos = str.Locate('>');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
	HBufC* tmpBuf = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
	TPtr tmp(tmpBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
		//DP1("Cleaning out %S", &str.Mid(startPos, endPos-startPos+1));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
		tmp.Copy(str.Left(startPos));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
		TPtrC ptr=str.Mid(startPos, endPos-startPos+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
		_LIT(KHtmlBr, "<br>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
		_LIT(KHtmlBr2, "<br />");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
		_LIT(KHtmlBr3, "<br/>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
		_LIT(KHtmlP, "<p>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
		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
    99
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
			tmp.Append(KLineBreak);
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
		else if (ptr.CompareF(KHtmlP) == 0)
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
			tmp.Append(KLineBreak);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
			tmp.Append(KLineBreak);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
		if (str.Length() > endPos+1) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
			tmp.Append(str.Mid(endPos+1));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
		str.Copy(tmp);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
		startPos = str.Locate('<');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
		endPos = str.Locate('>');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
	}
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   116
		
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 279
diff changeset
   117
// change HTML encoded chars to unicode
275
e2c3225833c3 Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
   118
	DP("    change HTML encoded chars to unicode");
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   119
	startPos = str.Locate('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   120
	endPos = str.Locate(';');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   121
	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   122
		{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   123
		TPtrC ptr(str.Mid(startPos+1, endPos-startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   124
		// check for whitespace
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   125
		if (ptr.Locate(' ') == KErrNotFound)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   126
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   127
			// numerical constant
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   128
			if (ptr[0] == '#')
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   129
				{ 
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   130
				TUint length = endPos - startPos;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   131
				if (length > 2)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   132
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   133
					tmp.Copy(str.Left(startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   134
					ptr.Set(str.Mid(startPos+2, length-2));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   135
					
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   136
					TUint charCode = 0;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   137
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   138
					if (ptr[0] == 'x')
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   139
						{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   140
						// hexadecimal
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   141
						ptr.Set(ptr.Mid(1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   142
						TLex16 lex(ptr);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   143
						lex.Val(charCode, EHex);	
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   144
						}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   145
					else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   146
						{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   147
						//decimal
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   148
						TLex16 lex(ptr);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   149
						lex.Val(charCode, EDecimal);	
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   150
						}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   151
					
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   152
					TChar charChar(charCode);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   153
					tmp.Append(charChar);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   154
					tmp.Append(str.Mid(endPos+1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   155
					str.Copy(tmp);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   156
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   157
				}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   158
			// literal constant
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   159
			else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   160
				{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   161
				_LIT(KAmp, "amp;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   162
				_LIT(KQuot, "quot;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   163
				_LIT(KNbsp, "nbsp;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   164
				_LIT(KCopy, "copy;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   165
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   166
				// copy start of string
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   167
				tmp.Copy(str.Left(startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   168
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   169
				if (ptr.CompareF(KAmp) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   170
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   171
					tmp.Append('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   172
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   173
				else if (ptr.CompareF(KQuot) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   174
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   175
					tmp.Append('"');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   176
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   177
				else if (ptr.CompareF(KNbsp) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   178
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   179
					tmp.Append(' ');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   180
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   181
				else if (ptr.CompareF(KCopy) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   182
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   183
					tmp.Append('\xA9');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   184
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   185
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   186
				// copy end of string
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   187
				tmp.Append(str.Mid(endPos+1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   188
				str.Copy(tmp);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   189
				}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   190
			}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   191
		
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   192
		TInt newPos = str.Mid(startPos+1).Locate('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   193
		
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   194
		if (newPos != KErrNotFound)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   195
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   196
			startPos = startPos+1 + newPos;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   197
			endPos = str.Locate(';');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   198
			}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   199
		else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   200
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   201
			startPos = KErrNotFound;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   202
			endPos = KErrNotFound;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   203
			}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   204
		}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   205
		
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
	CleanupStack::PopAndDestroy(tmpBuf);
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   207
	
161
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   208
	if(str.Length()>1)
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   209
		{
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   210
		// chop away newlines at start
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 279
diff changeset
   211
		DP("    chop away newlines at start");
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 279
diff changeset
   212
		while (str.Length() > 0 && (str[0] == KLineBreak))  {
161
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   213
			str = str.Mid(1);
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   214
		}
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   215
		
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   216
		// chop away newlines at end
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 279
diff changeset
   217
		DP("    chop away newlines at end");
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 279
diff changeset
   218
		while (str.Length() > 0 && (str[str.Length()-1] == KLineBreak)) {
161
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   219
			str = str.Left(str.Length()-1);
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   220
		}
19
9219912415dc Even more improved HTML cleaning
teknolog
parents: 18
diff changeset
   221
161
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   222
		str.Trim();
ce4f70a6d1d2 KTV fix for bug 2818
ktv
parents: 60
diff changeset
   223
		}
275
e2c3225833c3 Fix for bug 2818
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 161
diff changeset
   224
	DP("PodcastUtils::CleanHtmlL END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
15
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   227
EXPORT_C void PodcastUtils::RemoveAllFormatting(TDes & aString)
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   228
	{
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   229
	// 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
   230
	ReplaceString(aString,_L("\r\n"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   231
	
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   232
	ReplaceString(aString,_L("\n"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   233
	ReplaceString(aString,_L("\r"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   234
	
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   235
	}
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   236
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
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
   238
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
	TInt pos=aString.Find(aStringToReplace);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
	TInt offset = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
	while (pos != KErrNotFound)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
		aString.Replace(offset+pos, aStringToReplace.Length(), aReplacement);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
		offset += pos + aStringToReplace.Length()+1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
		if (offset > aString.Length())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
			return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
		pos=aString.Mid(offset).Find(aStringToReplace);
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
	}
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
EXPORT_C void PodcastUtils::ReplaceChar(TDes & aString, TUint aCharToReplace, TUint aReplacement)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
	TInt strLen=aString.Length();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
	for (TInt i=0; i < strLen; i++)
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
		if (aString[i] == aCharToReplace)
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
			aString[i] = aReplacement;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
			}
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
	}
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
EXPORT_C void PodcastUtils::EnsureProperPathName(TFileName &aPath)
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
	// from the SDK: The following characters cannot occur in the path: < >: " / |*
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
	ReplaceChar(aPath, '/', '_'); // better not to add \\ in case we have multiple /
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
	ReplaceChar(aPath, ':', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
	ReplaceChar(aPath, '?', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
	ReplaceChar(aPath, '|', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
	ReplaceChar(aPath, '*', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
	ReplaceChar(aPath, '<', '_');
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
	//buf.Append(_L("\\"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
EXPORT_C void PodcastUtils::FileNameFromUrl(const TDesC& aUrl, TFileName &aFileName)
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
	TInt pos = aUrl.LocateReverse('/');
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
	if (pos != KErrNotFound) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
		{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
		TPtrC str = aUrl.Mid(pos+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
		pos = str.Locate('?');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
		if (pos != KErrNotFound) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
			aFileName.Copy(str.Left(pos));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
			} 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
		else 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
			aFileName.Copy(str);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
			}
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
	DP2("FileNameFromUrl in: %S, out: %S", &aUrl, &aFileName);
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
EXPORT_C void PodcastUtils::SQLEncode(TDes &aString)
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
	ReplaceString(aString, _L("\""), _L("\"\""));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
	//ReplaceString(aString, _L("'"), _L("''"));	
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
EXPORT_C void PodcastUtils::XMLEncode(TDes &aString)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   309
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
	ReplaceString(aString, _L("\""), _L("&quot;"));	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   311
	ReplaceString(aString, _L("<"), _L("&lt;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
	ReplaceString(aString, _L(">"), _L("&gt;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
	ReplaceString(aString, _L("&"), _L("&amp;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
	}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   315
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   316
EXPORT_C TBool PodcastUtils::IsVideoShow(TDesC &aUrl)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   317
	{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   318
	if (aUrl.Find(KVideoFormat1) != KErrNotFound ||
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   319
			aUrl.Find(KVideoFormat2) != KErrNotFound ||
279
5a44ec2f6f4d Fix for bug 3626 - show filenames are now generated from UIDs
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 275
diff changeset
   320
			aUrl.Find(KVideoFormat3) != KErrNotFound ||
5a44ec2f6f4d Fix for bug 3626 - show filenames are now generated from UIDs
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 275
diff changeset
   321
			aUrl.Find(KVideoFormat4) != KErrNotFound)
60
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
		return ETrue;
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   324
		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   325
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   326
	return EFalse;
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 21
diff changeset
   327
	}