|
1 // Copyright (c) 2006-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 // XForms functions |
|
15 // |
|
16 |
|
17 #include "xmlengdomdefs.h" |
|
18 #include <xml/dom/xmlengdocument.h> |
|
19 #include <xml/dom/xmlengxformsinstancemap.h> |
|
20 #include <stdapis/libxml2/libxml2_hash.h> |
|
21 #include <xml/utils/xmlengmem.h> |
|
22 #include <xml/utils/xmlengxestrings.h> |
|
23 |
|
24 const TInt KHashTableSize = 10; |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // Initializes internal storage. Leaves created object on cleanup stack. |
|
28 // @return New CXFormsInstanceMap object. |
|
29 // @exception Leave on OOM. |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 EXPORT_C CXmlEngXFormsInstanceMap* CXmlEngXFormsInstanceMap::NewLC() |
|
33 { |
|
34 CXmlEngXFormsInstanceMap* instance = new(ELeave) CXmlEngXFormsInstanceMap(); |
|
35 CleanupStack::PushL(instance); |
|
36 instance->ConstructL(); |
|
37 return instance; |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // Initializes internal storage. |
|
42 // @return New CXFormsInstanceMap object. |
|
43 // @exception Leave on OOM. |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C CXmlEngXFormsInstanceMap* CXmlEngXFormsInstanceMap::NewL() |
|
47 { |
|
48 CXmlEngXFormsInstanceMap* instance = NewLC(); |
|
49 CleanupStack::Pop(instance); |
|
50 return instance; |
|
51 } |
|
52 |
|
53 void CXmlEngXFormsInstanceMap::ConstructL() |
|
54 { |
|
55 iInternal = xmlHashCreate(KHashTableSize); |
|
56 OOM_IF_NULL(iInternal); |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Destructor. Frees internal storage, but <b>does not</b> free the Document |
|
61 // instances that were added. These are owned by the caller. |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C CXmlEngXFormsInstanceMap::~CXmlEngXFormsInstanceMap() |
|
65 { |
|
66 xmlHashFree( |
|
67 static_cast<xmlHashTablePtr>(iInternal), |
|
68 (xmlHashDeallocator) NULL); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Adds entry to container. Document is associated with a name. If an entry |
|
73 // with the same name already exists this method does nothing. |
|
74 // @param[in] aInstance The DOM document to be stored. |
|
75 // @param[in] aName The name that is associated with the document. |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C void CXmlEngXFormsInstanceMap::AddEntryL( |
|
79 RXmlEngDocument& aInstance, |
|
80 const TDesC8& aName ) |
|
81 { |
|
82 xmlChar* name = xmlCharFromDesC8L(aName); |
|
83 if ( 0 > xmlHashAddEntry( |
|
84 static_cast<xmlHashTablePtr>(iInternal), |
|
85 name, |
|
86 INTERNAL_DOCPTR(aInstance)) |
|
87 ) |
|
88 { |
|
89 delete name; |
|
90 TEST_OOM_FLAG; |
|
91 // else: there is already instance with such name |
|
92 } |
|
93 else |
|
94 { |
|
95 delete name; |
|
96 } |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // Removes an entry from the container. If the entry does not exists |
|
101 // method does nothing. Note that document is <b>not freed</b>. |
|
102 // @param[in] aName Name of entry to remove. |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C void CXmlEngXFormsInstanceMap::RemoveEntryL( |
|
106 const TDesC8& aName ) |
|
107 { |
|
108 xmlChar* name = xmlCharFromDesC8L(aName); |
|
109 xmlHashRemoveEntry( |
|
110 static_cast<xmlHashTablePtr>(iInternal), |
|
111 name, |
|
112 (xmlHashDeallocator) NULL); |
|
113 delete name; |
|
114 } |