|
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 // Methods for all kind of text nodes |
|
15 // |
|
16 |
|
17 #include <xml/dom/xmlengbinarycontainer.h> |
|
18 #include <stdapis/libxml2/libxml2_tree.h> |
|
19 #include "xmlengdomdefs.h" |
|
20 #include <stdapis/libxml2/libxml2_globals.h> |
|
21 |
|
22 // ------------------------------------------------------------------------------- |
|
23 // @return Binary contents of the container |
|
24 // |
|
25 // ------------------------------------------------------------------------------- |
|
26 // |
|
27 EXPORT_C TPtrC8 TXmlEngBinaryContainer::Contents() const |
|
28 { |
|
29 return TPtrC8((const TUint8*)LIBXML_NODE->content, (TInt)LIBXML_NODE->properties); |
|
30 } |
|
31 |
|
32 // ------------------------------------------------------------------------------- |
|
33 // Sets contents of binary container |
|
34 // |
|
35 // @param aNewContents The actual value to store |
|
36 // ------------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C void TXmlEngBinaryContainer::SetContentsL( const TDesC8& aNewContents ) |
|
39 { |
|
40 if (!LIBXML_NODE) |
|
41 { |
|
42 User::Leave(KXmlEngErrNullNode); |
|
43 } |
|
44 // Note: TXmlEngBinaryContainer is treated internally by Libxml2 as text nodes. |
|
45 // Hence, appending 0 at the end to ensure that text is not parsed beyond actual data in any case. |
|
46 |
|
47 TUint len = aNewContents.Size(); |
|
48 unsigned char* str = new(ELeave) unsigned char[len + 1]; |
|
49 memcpy(str, aNewContents.Ptr(), len); |
|
50 str[len] = 0; |
|
51 |
|
52 if (LIBXML_NODE->content |
|
53 && |
|
54 !(LIBXML_NODE->doc && |
|
55 LIBXML_NODE->doc->dict && |
|
56 xmlDictOwns(LIBXML_NODE->doc->dict, LIBXML_NODE->content))) |
|
57 { |
|
58 xmlFree(LIBXML_NODE->content); |
|
59 } |
|
60 LIBXML_NODE->properties = (xmlAttr*) len; |
|
61 LIBXML_NODE->content = str; |
|
62 } |
|
63 |
|
64 // ------------------------------------------------------------------------------- |
|
65 // Extends the contents of binary container by appending aContents |
|
66 // |
|
67 // @param aContents Content to be appended to current content |
|
68 // ------------------------------------------------------------------------------- |
|
69 // |
|
70 EXPORT_C void TXmlEngBinaryContainer::AppendContentsL( const TDesC8& aData ) |
|
71 { |
|
72 if (!LIBXML_NODE) |
|
73 { |
|
74 User::Leave(KXmlEngErrNullNode); |
|
75 } |
|
76 |
|
77 // Note: TXmlEngBinaryContainer is treated internally by Libxml2 as text nodes. |
|
78 // Hence, appending 0 at the end to ensure that text is not parsed beyond actual data in any case. |
|
79 |
|
80 TPtrC8 prevContent = Contents(); |
|
81 TInt len = prevContent.Length() + aData.Length(); |
|
82 unsigned char* newContent = new(ELeave) unsigned char[len + 1]; |
|
83 |
|
84 TAny* last = Mem::Copy((TAny*)newContent, prevContent.Ptr(), prevContent.Length()); |
|
85 memcpy(last, aData.Ptr(), aData.Length()); |
|
86 newContent[len] = 0; |
|
87 |
|
88 if (LIBXML_NODE->content |
|
89 && |
|
90 !(LIBXML_NODE->doc && |
|
91 LIBXML_NODE->doc->dict && |
|
92 xmlDictOwns(LIBXML_NODE->doc->dict, LIBXML_NODE->content))) |
|
93 { |
|
94 xmlFree(LIBXML_NODE->content); |
|
95 } |
|
96 LIBXML_NODE->properties = (xmlAttr*) len; |
|
97 LIBXML_NODE->content = (unsigned char *)newContent; |
|
98 } |