engine/src/PodcastUtils.cpp
author teknolog
Sat, 27 Feb 2010 14:40:44 +0000
changeset 18 cda6e6257514
parent 15 93d9f66bf50b
child 19 9219912415dc
permissions -rw-r--r--
Improved HTML cleaning
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
{
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    71
// miscellaneous cleanup
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
	const TChar KLineBreak(CEditableText::ELineBreak); 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
	_LIT(KNewLine, "\n");
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    74
	//	ReplaceChar(str, '"', '\'');
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
	ReplaceString(str, KNewLine, KNullDesC);
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    76
	str.Trim();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    78
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    79
// strip out HTML tags
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
    80
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
	TInt startPos = str.Locate('<');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
	TInt endPos = str.Locate('>');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
	HBufC* tmpBuf = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
	TPtr tmp(tmpBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
		//DP1("Cleaning out %S", &str.Mid(startPos, endPos-startPos+1));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
		tmp.Copy(str.Left(startPos));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
		TPtrC ptr=str.Mid(startPos, endPos-startPos+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
		_LIT(KHtmlBr, "<br>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
		_LIT(KHtmlBr2, "<br />");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
		_LIT(KHtmlBr3, "<br/>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
		_LIT(KHtmlP, "<p>");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
		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
    94
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
			tmp.Append(KLineBreak);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
		else if (ptr.CompareF(KHtmlP) == 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
			tmp.Append(KLineBreak);
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
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
		if (str.Length() > endPos+1) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
			tmp.Append(str.Mid(endPos+1));
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
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
		str.Copy(tmp);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
		startPos = str.Locate('<');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
		endPos = str.Locate('>');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
	}
18
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   111
		
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   112
// change HTML encoded chars to unicode
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   113
	startPos = str.Locate('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   114
	endPos = str.Locate(';');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   115
	while (startPos != KErrNotFound && endPos != KErrNotFound && endPos > startPos)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   116
		{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   117
		TPtrC ptr(str.Mid(startPos+1, endPos-startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   118
		// check for whitespace
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   119
		if (ptr.Locate(' ') == KErrNotFound)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   120
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   121
			// numerical constant
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   122
			if (ptr[0] == '#')
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   123
				{ 
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   124
				TUint length = endPos - startPos;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   125
				if (length > 2)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   126
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   127
					tmp.Copy(str.Left(startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   128
					ptr.Set(str.Mid(startPos+2, length-2));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   129
					
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   130
					TUint charCode = 0;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   131
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   132
					if (ptr[0] == 'x')
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   133
						{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   134
						// hexadecimal
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   135
						ptr.Set(ptr.Mid(1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   136
						TLex16 lex(ptr);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   137
						lex.Val(charCode, EHex);	
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   138
						}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   139
					else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   140
						{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   141
						//decimal
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, EDecimal);	
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   144
						}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   145
					
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   146
					TChar charChar(charCode);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   147
					tmp.Append(charChar);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   148
					tmp.Append(str.Mid(endPos+1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   149
					str.Copy(tmp);
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
			// literal constant
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   153
			else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   154
				{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   155
				_LIT(KAmp, "amp;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   156
				_LIT(KQuot, "quot;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   157
				_LIT(KNbsp, "nbsp;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   158
				_LIT(KCopy, "copy;");
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   159
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   160
				// copy start of string
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   161
				tmp.Copy(str.Left(startPos));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   162
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   163
				if (ptr.CompareF(KAmp) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   164
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   165
					tmp.Append('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   166
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   167
				else if (ptr.CompareF(KQuot) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   168
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   169
					tmp.Append('"');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   170
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   171
				else if (ptr.CompareF(KNbsp) == 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(KCopy) == 0)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   176
					{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   177
					tmp.Append('\xA9');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   178
					}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   179
				
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   180
				// copy end of string
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   181
				tmp.Append(str.Mid(endPos+1));
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   182
				str.Copy(tmp);
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   183
				}
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
		TInt newPos = str.Mid(startPos+1).Locate('&');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   187
		
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   188
		if (newPos != KErrNotFound)
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   189
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   190
			startPos = startPos+1 + newPos;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   191
			endPos = str.Locate(';');
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   192
			}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   193
		else
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   194
			{
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   195
			startPos = KErrNotFound;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   196
			endPos = KErrNotFound;
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   197
			}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   198
		}
cda6e6257514 Improved HTML cleaning
teknolog
parents: 15
diff changeset
   199
		
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
	CleanupStack::PopAndDestroy(tmpBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   202
15
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   203
EXPORT_C void PodcastUtils::RemoveAllFormatting(TDes & aString)
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   204
	{
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   205
	// 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
   206
	ReplaceString(aString,_L("\r\n"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   207
	
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   208
	ReplaceString(aString,_L("\n"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   209
	ReplaceString(aString,_L("\r"), _L(" "));
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   210
	
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   211
	}
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 2
diff changeset
   212
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
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
   214
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
	TInt pos=aString.Find(aStringToReplace);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
	TInt offset = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
	while (pos != KErrNotFound)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
		aString.Replace(offset+pos, aStringToReplace.Length(), aReplacement);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
		offset += pos + aStringToReplace.Length()+1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
		if (offset > aString.Length())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
			return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
			}
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
		pos=aString.Mid(offset).Find(aStringToReplace);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
EXPORT_C void PodcastUtils::ReplaceChar(TDes & aString, TUint aCharToReplace, TUint aReplacement)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
	TInt strLen=aString.Length();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
	for (TInt i=0; i < strLen; i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
		if (aString[i] == aCharToReplace)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
			aString[i] = 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
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
EXPORT_C void PodcastUtils::EnsureProperPathName(TFileName &aPath)
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
	// from the SDK: The following characters cannot occur in the path: < >: " / |*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
	ReplaceChar(aPath, '/', '_'); // better not to add \\ in case we have multiple /
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
	ReplaceChar(aPath, ':', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
	ReplaceChar(aPath, '?', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
	ReplaceChar(aPath, '|', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
	ReplaceChar(aPath, '*', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
	ReplaceChar(aPath, '<', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
	ReplaceChar(aPath, '>', '_');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
	ReplaceChar(aPath, '"', '_');
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
	//buf.Append(_L("\\"));
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
EXPORT_C void PodcastUtils::FileNameFromUrl(const TDesC& aUrl, TFileName &aFileName)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
	TInt pos = aUrl.LocateReverse('/');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
	if (pos != KErrNotFound) 
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
		TPtrC str = aUrl.Mid(pos+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
		pos = str.Locate('?');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
		if (pos != KErrNotFound) 
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
			aFileName.Copy(str.Left(pos));
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
		else 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
			aFileName.Copy(str);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
			}
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
	DP2("FileNameFromUrl in: %S, out: %S", &aUrl, &aFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
EXPORT_C void PodcastUtils::SQLEncode(TDes &aString)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
	ReplaceString(aString, _L("\""), _L("\"\""));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
	//ReplaceString(aString, _L("'"), _L("''"));	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
	}
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
EXPORT_C void PodcastUtils::XMLEncode(TDes &aString)
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
	ReplaceString(aString, _L("\""), _L("&quot;"));	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
	ReplaceString(aString, _L("<"), _L("&lt;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
	ReplaceString(aString, _L(">"), _L("&gt;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
	ReplaceString(aString, _L("&"), _L("&amp;"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
	}