xml/wbxmlparser/src/sd_wml/wml1_1stringdictionary00.cpp
changeset 0 e35f40988205
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32std.h>
       
    17 #include <ecom/implementationproxy.h>
       
    18 
       
    19 #include <xml/xmlframeworkerrors.h>
       
    20 #include <xml/plugins/dictionarycodepage.h>
       
    21 
       
    22 #include "wml1_1stringdictionary00.h"
       
    23 #include "wml1_1codepage00tagtable.h"
       
    24 #include "wml1_1codepage00attributetable.h"
       
    25 #include "wml1_1codepage00attributevaluetable.h"
       
    26 
       
    27 
       
    28 using namespace Xml;
       
    29 
       
    30 
       
    31 MStringDictionary* CWml1_1StringDictionary00::NewL(TAny* aStringPool)
       
    32 	{
       
    33 	CWml1_1StringDictionary00* self = new(ELeave) CWml1_1StringDictionary00(reinterpret_cast<RStringPool*>(aStringPool));
       
    34 	CleanupStack::PushL(self);
       
    35 	self->ConstructL();
       
    36 	CleanupStack::Pop(self);
       
    37 	return (static_cast<MStringDictionary*>(self));
       
    38 	}
       
    39 
       
    40 
       
    41 
       
    42 CWml1_1StringDictionary00::CWml1_1StringDictionary00(RStringPool* aStringPool)
       
    43 :	iStringPool(*aStringPool),
       
    44 	iCodePage(0)
       
    45 	{
       
    46 	// do nothing;
       
    47 	}
       
    48 
       
    49 
       
    50 
       
    51 void CWml1_1StringDictionary00::ConstructL()
       
    52 	{
       
    53 	// we don't own this stringpool
       
    54 	iStringPool.OpenL(Wml1_1CodePage00TagTable::Table);
       
    55 	iStringPool.OpenL(Wml1_1CodePage00AttributeTable::Table);
       
    56 	iStringPool.OpenL(Wml1_1CodePage00AttributeValueTable::Table);
       
    57 
       
    58 	iCodepage00Table = CDictionaryCodePage::NewL(
       
    59 		&Wml1_1CodePage00TagTable::Table, 
       
    60 		&Wml1_1CodePage00AttributeTable::Table, 
       
    61 		&Wml1_1CodePage00AttributeValueTable::Table, 
       
    62 		0); // codepage
       
    63 
       
    64 	// Construct the correlation mapping
       
    65 	iCodepage00Table->ConstructIndexMappingL(iTagCodePage00, CDictionaryCodePage::EStringTypeElement);
       
    66 	iCodepage00Table->ConstructIndexMappingL(iAttributeCodePage00, CDictionaryCodePage::EStringTypeAttribute);
       
    67 	iCodepage00Table->ConstructIndexMappingL(iAttributeValueCodePage00, CDictionaryCodePage::EStringTypeAttributeValue);
       
    68 	}
       
    69 
       
    70 
       
    71 
       
    72 
       
    73 void CWml1_1StringDictionary00::Release()
       
    74 	{
       
    75 	delete (this);
       
    76 	}
       
    77 
       
    78 
       
    79 
       
    80 
       
    81 CWml1_1StringDictionary00::~CWml1_1StringDictionary00()
       
    82 	{
       
    83 	if (iCodepage00Table)
       
    84 		{
       
    85 		delete iCodepage00Table;
       
    86 		}
       
    87 	}
       
    88 
       
    89 
       
    90 
       
    91 void CWml1_1StringDictionary00::ElementL(TInt aToken, RString& aElement) const
       
    92 	{
       
    93 	TInt index = iCodepage00Table->StringPoolIndexFromToken(
       
    94 					aToken, CDictionaryCodePage::EStringTypeElement);
       
    95 
       
    96 	if (index == KErrXmlStringPoolTableNotFound)
       
    97 		{
       
    98 		User::Leave(KErrXmlUnsupportedElement);
       
    99 		}
       
   100 
       
   101 	// when we have multiple codepages per string dictionary we'd do something like iCodepageTable[n]->StringTable()
       
   102 	aElement = iStringPool.String(
       
   103 		index,
       
   104 		*(iCodepage00Table->StringTable(CDictionaryCodePage::EStringTypeElement)));
       
   105 	}
       
   106 
       
   107 
       
   108 
       
   109 void CWml1_1StringDictionary00::AttributeL(TInt aToken, RString& aAttribute) const
       
   110 	{
       
   111 	TInt index = iCodepage00Table->StringPoolIndexFromToken(
       
   112 					aToken, CDictionaryCodePage::EStringTypeAttribute);
       
   113 
       
   114 	if (index == KErrXmlStringPoolTableNotFound)
       
   115 		{
       
   116 		User::Leave(KErrXmlUnsupportedAttribute);
       
   117 		}
       
   118 
       
   119 	// when we have multiple codepages per string dictionary we'd do something like iCodepageTable[n]->StringTable()
       
   120 	aAttribute = iStringPool.String(
       
   121 		index,
       
   122 		*(iCodepage00Table->StringTable(CDictionaryCodePage::EStringTypeAttribute)));
       
   123 	};
       
   124 
       
   125 
       
   126 
       
   127 void CWml1_1StringDictionary00::AttributeValuePairL(TInt aToken, RString& aAttribute, RString& aValue) const
       
   128 	{
       
   129 	AttributeL(aToken, aAttribute);
       
   130 	AttributeValueL(aToken, aValue);
       
   131 	};
       
   132 	
       
   133 
       
   134 
       
   135 void CWml1_1StringDictionary00::AttributeValueL(TInt aToken, RString& aValue) const
       
   136 	{
       
   137 	TInt index = iCodepage00Table->StringPoolIndexFromToken(
       
   138 					aToken, CDictionaryCodePage::EStringTypeAttributeValue);
       
   139 
       
   140 	if (index == KErrXmlStringPoolTableNotFound)
       
   141 		{
       
   142 		User::Leave(KErrXmlUnsupportedAttributeValue);
       
   143 		}
       
   144 
       
   145 	// when we have multiple codepages per string dictionary we'd do something like iCodepageTable[n]->StringTable()
       
   146 	aValue = iStringPool.String(
       
   147 		index,
       
   148 		*(iCodepage00Table->StringTable(CDictionaryCodePage::EStringTypeAttributeValue)));
       
   149 	};
       
   150 
       
   151 
       
   152 
       
   153 TBool CWml1_1StringDictionary00::CompareThisDictionary(const RString& aDictionaryDescription) const
       
   154 	{
       
   155 	// If this string dictionary has many codepages then all these comparisons should go here.
       
   156 	// Remember, the string dictionary loads up all the RStringTables into its RStringPool
       
   157 	// on construction. So if the comparison fails we do not have it.
       
   158 	return (
       
   159 		(aDictionaryDescription == iStringPool.String(Wml1_1CodePage00TagTable::EUri, Wml1_1CodePage00TagTable::Table))		||
       
   160 		(aDictionaryDescription == iStringPool.String(Wml1_1CodePage00TagTable::EPublicId, Wml1_1CodePage00TagTable::Table))||
       
   161 		(aDictionaryDescription == iStringPool.String(Wml1_1CodePage00TagTable::EFormalPublicId, Wml1_1CodePage00TagTable::Table)));
       
   162 	}
       
   163 
       
   164 
       
   165 
       
   166 TInt CWml1_1StringDictionary00::SwitchCodePage(TInt aCodePage)
       
   167 	{
       
   168 	// We only have one codepage sp can't switch
       
   169 	if (aCodePage != iCodePage)
       
   170 		{
       
   171 		return KErrXmlMissingStringDictionary;
       
   172 		}
       
   173 	return iCodePage;
       
   174 	}
       
   175 
       
   176 		
       
   177 
       
   178 
       
   179 		
       
   180 /**
       
   181 This method obtains the public identifier from the StringTable.
       
   182 Either the formal or non formal public id will do.
       
   183 The stringDictionary .rss files must list both these as wbxml
       
   184 documents have one or the other.
       
   185 
       
   186 @param				aPubId The public identifier for this string 
       
   187 					dictionary.
       
   188 */
       
   189 
       
   190 void CWml1_1StringDictionary00::PublicIdentifier(RString& aPubId)
       
   191 	{
       
   192 	// Better to use the element table as some documents don't have attributes.
       
   193 	aPubId = iStringPool.String(
       
   194 		Wml1_1CodePage00TagTable::EFormalPublicId,
       
   195 		*(iCodepage00Table->StringTable(CDictionaryCodePage::EStringTypeElement)));
       
   196 	}
       
   197 
       
   198 
       
   199 /**
       
   200 The element types in the Device Information DTD are defined within
       
   201 a namespace associated with the Uri/Urn available from the StringTable.
       
   202 The RString need not be closed, but closing is harmless. 
       
   203 
       
   204 @param				aUri The associated namespace for this string 
       
   205 					dictionary.
       
   206 */
       
   207 
       
   208 void CWml1_1StringDictionary00::NamespaceUri(RString& aUri)
       
   209 	{
       
   210 	// Better to use the element table as some documents don't have attributes.
       
   211 	aUri = iStringPool.String(
       
   212 		Wml1_1CodePage00TagTable::EUri,
       
   213 		*(iCodepage00Table->StringTable(CDictionaryCodePage::EStringTypeElement)));
       
   214 	}
       
   215 
       
   216 
       
   217 
       
   218 
       
   219 // __________________________________________________________________________
       
   220 // Exported proxy for instantiation method resolution
       
   221 // Define the interface UIDs
       
   222 const TImplementationProxy ImplementationTable[] = {
       
   223 	IMPLEMENTATION_PROXY_ENTRY(0x101FCABC,CWml1_1StringDictionary00::NewL)
       
   224 };
       
   225 
       
   226 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   227 	{
       
   228 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   229 
       
   230 	return ImplementationTable;
       
   231 	}
       
   232