2 * Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Class implements XML DOM fragment using libxml2 classes
26 #ifndef SEN_DOM_FRAGMENT_BASE_H
27 #define SEN_DOM_FRAGMENT_BASE_H
30 #include <SenFragmentBase.h>
32 // FORWARD DECLARATIONS
38 * Class implements DOM fragment functionality
39 * The implementation further extends CSenBaseFragment
40 * functionality. In DOM fragment, all child elements
41 * are parsed into separate element objects. This makes
42 * it possible to reference any child which offer methods
43 * declared in XML element interface. Any such element
44 * can also be easily extracted (detached) from this
46 * @lib SenFragment.dll
49 class CSenDomFragmentBase : public CSenFragmentBase
51 public: // Constructors and destructor
54 * Basic contructor. Should be used only for parsing new fragments etc.
55 * Constructing DomFragments for other use should be done with at least
56 * localname parameter.
59 IMPORT_C static CSenDomFragmentBase* NewL();
64 * @param aElement Element to copy construction data from.
66 IMPORT_C static CSenDomFragmentBase* NewL(
67 const TXmlEngElement& aElement);
72 * @param aLocalName is the XML localname of this fragment
74 IMPORT_C static CSenDomFragmentBase* NewL(const TDesC8& aLocalName);
79 * @param aNsUri is the XML namespace user of this fragment
80 * @param aLocalName is the XML localname of this fragment
82 IMPORT_C static CSenDomFragmentBase* NewL(const TDesC8& aNsUri,
83 const TDesC8& aLocalName);
88 * @param aNsUri is the XML namespace user of this fragment
89 * @param aLocalName is the XML localname of this fragment
90 * @param aPrefix is the XML prefix of this fragment
92 IMPORT_C static CSenDomFragmentBase* NewL(const TDesC8& aNsUri,
93 const TDesC8& aLocalName,
94 const TDesC8& aPrefix);
99 * @param aNsUri is the XML namespace of this fragment
100 * @param aLocalName is the XML localname of this fragment
101 * @param aPrefix is the prefix of this fragment
102 * @param aAttrs are the XML attributes of this fragment
104 IMPORT_C static CSenDomFragmentBase* NewL(const TDesC8& aNsUri,
105 const TDesC8& aLocalName,
106 const TDesC8& aPrefix,
107 const RAttributeArray& aAttrs);
111 * @since Series60 4.0
112 * @param aNsUri is the XML namespace of this fragment
113 * @param aLocalName is the XML localname of this fragment
114 * @param aPrefix is the prefix of this fragment
115 * @param aAttrs are the XML attributes of this fragment
116 * @param aParent is the parent XML element of this fragment
118 IMPORT_C static CSenDomFragmentBase* NewL(const TDesC8& aNsUri,
119 const TDesC8& aLocalName,
120 const TDesC8& aPrefix,
121 const RAttributeArray& aAttrs,
122 TXmlEngElement& aParent);
126 * @since Series60 4.0
127 * @param aNsUri is the XML namespace of this fragment
128 * @param aLocalName is the XML localname of this fragment
129 * @param aPrefix is the prefix of this fragment
130 * @param aAttrs are the XML attributes of this fragment
131 * @param aParent is the parent XML element of this fragment
132 * @param aOwnerDocument is the document which will be the owner of
133 * the elements of this fragment
135 IMPORT_C static CSenDomFragmentBase* NewL(const TDesC8& aNsUri,
136 const TDesC8& aLocalName,
137 const TDesC8& aPrefix,
138 const RAttributeArray& aAttrs,
139 TXmlEngElement& aParent,
140 RSenDocument& aOwnerDocument);
144 IMPORT_C virtual ~CSenDomFragmentBase();
149 * Initiates the parsing chain where new delegate will be created with
150 * given parameters and parsing will be delegated to it. Should not be
152 * @since Series60 4.0
153 * @param aElement The RTagInfo class holding information that describes
155 * @param aAttributes The attributes of the new element
156 * @param aErrorCode Error code
158 IMPORT_C virtual void ExpandL(const RTagInfo& aElement,
159 const RAttributeArray& aAttributes,
162 // Functions from base classes
164 // From CSenBaseFragment
167 * Resumes the parsing. Usually called by the delegate fragment which was
168 * parsing itself after DelegateParsingL().
169 * @since Series60 4.0
170 * @param aElement The RTagInfo class holding information that describes
172 * @param aErrorCode Error code
174 IMPORT_C virtual void OnResumeParsingFromL(const RTagInfo& aElement,
178 * Sets the attributes for the fragment.
179 * @since Series60 4.0
180 * @param aAttributes The array of attributes.
182 IMPORT_C virtual void AddAttributesL(const RAttributeArray& aAttrs);
185 * Gets the fragment data as an UTF-8 form XML.
186 * @since Series60 4.0
187 * @return fragment as XML. Caller takes ownership.
189 IMPORT_C virtual HBufC8* AsXmlL();
192 * Callback function implementing the XML content handler interface.
193 * Inheriting classes can override these.
194 * @since Series60 4.0
195 * @see MContentHandler
197 IMPORT_C virtual void OnStartElementL(const RTagInfo& aElement,
198 const RAttributeArray& aAttributes,
202 * Callback function implementing the XML content handler interface.
203 * Inheriting classes can override these.
204 * @since Series60 4.0
205 * @see MContentHandler
207 IMPORT_C virtual void OnContentL(const TDesC8& aBytes,
211 * Overriding content writing from CSenBaseFragment to do nothing in
212 * DOM fragment (because the tree is expanded).
213 * @since Series60 4.0
214 * @param aElement The RTagInfo class holding information that
215 * describes the element.
216 * @param aAttributes The attributes of the new element
218 IMPORT_C void OnWriteStartElementL(const RTagInfo& aElement,
219 const RAttributeArray& aAttributes);
222 * Overriding content writing from CSenBaseFragment to do nothing in
223 * DOM fragment (because the tree is expanded).
224 * @since Series60 4.0
225 * @param aElement The RTagInfo class holding information that
226 * describes the element.
228 IMPORT_C void OnWriteEndElementL(const RTagInfo& aElement);
230 * Callback function implementing the XML content handler interface.
231 * Inheriting classes can override these.
232 * @since Series60 4.0
233 * @see MContentHandler
235 IMPORT_C virtual void OnEndElementL(const RTagInfo& aElement, TInt aErrorCode);
238 * Callback function implementing the XML content handler interface.
239 * Inheriting classes can override these.
240 * @since Series60 4.0
241 * @see MContentHandler
243 IMPORT_C virtual void OnStartDocumentL(const RDocumentParameters& aDocParam, TInt aErrorCode);
246 * Callback function implementing the XML content handler interface.
247 * Inheriting classes can override these.
248 * @since Series60 4.0
249 * @see MContentHandler
251 IMPORT_C virtual void OnEndDocumentL(TInt aErrorCode);
254 * Callback function implementing the XML content handler interface.
255 * Inheriting classes can override these.
256 * @since Series60 4.0
257 * @see MContentHandler
259 IMPORT_C virtual void OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aErrorCode);
262 * Callback function implementing the XML content handler interface.
263 * Inheriting classes can override these.
264 * @since Series60 4.0
265 * @see MContentHandler
267 IMPORT_C virtual void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode);
270 * Callback function implementing the XML content handler interface.
271 * Inheriting classes can override these.
272 * @since Series60 4.0
273 * @see MContentHandler
275 IMPORT_C virtual void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt ErrorCode);
278 * Callback function implementing the XML content handler interface.
279 * Inheriting classes can override these.
280 * @since Series60 4.0
281 * @see MContentHandler
283 IMPORT_C virtual void OnSkippedEntityL(const RString& aName, TInt aErrorCode);
286 * Callback function implementing the XML content handler interface.
287 * Inheriting classes can override these.
288 * @since Series60 4.0
289 * @see MContentHandler
291 IMPORT_C virtual void OnProcessingInstructionL(const TDesC8& aTarget, const TDesC8& aData, TInt aErrorCode);
294 * Callback function implementing the XML content handler interface.
295 * Inheriting classes can override these.
296 * @since Series60 4.0
297 * @see MContentHandler
299 IMPORT_C virtual void OnError(TInt aErrorCode);
302 * Callback function implementing the XML content handler interface.
303 * Inheriting classes can override these.
304 * @since Series60 4.0
305 * @see MContentHandler
307 IMPORT_C virtual TAny* GetExtendedInterface(const TInt32 aUid);
309 // From CSenBaseFragment
310 IMPORT_C virtual TPtrC8 ContentL();
312 IMPORT_C virtual TXmlEngNamespace Namespace(const TDesC8& aPrefix);
314 // IMPORT_C virtual void DetachL();
316 IMPORT_C virtual void ResetContentL();
318 IMPORT_C virtual TPtrC8 LocalName() const;
320 IMPORT_C virtual TPtrC8 NsUri() const;
322 IMPORT_C virtual TPtrC8 NsPrefix() const;
324 IMPORT_C virtual TXmlEngElement AsElementL();
326 IMPORT_C virtual RSenDocument& AsDocumentL();
328 IMPORT_C virtual TXmlEngElement ExtractElement();
330 IMPORT_C virtual void OnDelegateParsingL(CSenFragmentBase& aDelegate);
332 IMPORT_C virtual void OnDelegateParsingL(const RTagInfo& aElement,
333 const RAttributeArray& aAttributes,
336 IMPORT_C virtual void SetOwner(CSenFragmentBase& aFragment);
338 IMPORT_C virtual HBufC* AsXmlUnicodeL();
340 IMPORT_C virtual void WriteAsXMLToL(RWriteStream& aWs);
342 IMPORT_C virtual TBool ConsistsOfL(CSenFragmentBase& aCandidate);
344 IMPORT_C void SetContentHandler(CSenFragmentBase& aContentHandler);
346 protected: // From CSenBaseFragment
348 void RenameL(const TDesC8& aLocalName, const TDesC8& aPrefix, const TDesC8& aNamespace);
350 void RenameL(const TDesC8& aLocalName, const TDesC8& aNamespace);
352 void RenameLocalNameL(const TDesC8& aLocalName);
354 void RenameNamespaceL(const TDesC8& aNamespace);
356 void RenamePrefixL(const TDesC8& aPrefix);
358 void RenameNamespaceL(const TDesC8& aPrefix, const TDesC8& aNamespace);
360 IMPORT_C TXmlEngElement SetContentOfL(const TDesC8& aLocalName,
361 const TDesC8& aContent);
363 IMPORT_C TPtrC8 ContentOf(const TDesC8& aLocalName);
365 IMPORT_C virtual TBool ConsistsOfL(TXmlEngElement& aElement, TXmlEngElement& aCandidate);
367 IMPORT_C virtual void AddNamespacesL();
372 * C++ default constructor.
374 IMPORT_C CSenDomFragmentBase();
377 * "ConstructL" method for calling the base classes ones.
378 * @since Series60 4.0
380 IMPORT_C void BaseConstructL();
383 * "ConstructL" method for calling the base classes ones.
384 * @since Series60 4.0
385 * @param aElement is the XML element of this fragment.
387 IMPORT_C void BaseConstructL(const TXmlEngElement& aElement);
390 * "ConstructL" method for calling the base classes ones.
391 * @since Series60 4.0
392 * @param aLocalName The local name of the element
394 IMPORT_C void BaseConstructL(const TDesC8& aLocalName);
397 * "ConstructL" method for calling the base classes ones.
398 * @since Series60 4.0
399 * @param aNsUri The namespace URI of the element
400 * @param aLocalName The local name of the element
402 IMPORT_C void BaseConstructL(const TDesC8& aNsUri,
403 const TDesC8& aLocalName);
406 * "ConstructL" method for calling the base classes ones.
407 * @since Series60 4.0
408 * @param aNsUri The namespace URI of the element
409 * @param aLocalName The local name of the element
410 * @param aPrefix The prefix of the element
412 IMPORT_C void BaseConstructL(const TDesC8& aNsUri,
413 const TDesC8& aLocalName,
414 const TDesC8& aPrefix);
417 * "ConstructL" method for calling the base classes ones.
418 * @since Series60 4.0
419 * @param aNsUri The namespace URI of the element
420 * @param aLocalName The local name of the element
421 * @param aPrefix The prefix of the element
422 * @param aAttrs The attributes of the element
424 IMPORT_C void BaseConstructL(const TDesC8& aNsUri,
425 const TDesC8& aLocalName,
426 const TDesC8& aPrefix,
427 const RAttributeArray& aAttrs);
430 * "ConstructL" method for calling the base classes ones.
431 * @since Series60 4.0
432 * @param aNsUri The namespace URI of the element
433 * @param aLocalName The local name of the element
434 * @param aPrefix The prefix of the element
435 * @param aAttrs The attributes of the element
436 * @param aParent The parent of the element
438 IMPORT_C void BaseConstructL(const TDesC8& aNsUri,
439 const TDesC8& aLocalName,
440 const TDesC8& aPrefix,
441 const RAttributeArray& aAttrs,
442 TXmlEngElement& aParent);
445 * "ConstructL" method for calling the base classes ones.
446 * @since Series60 4.0
447 * @param aNsUri The namespace URI of the element
448 * @param aLocalName The local name of the element
449 * @param aPrefix The prefix of the element
450 * @param aAttrs The attributes of the element
451 * @param aParent The parent of the element
452 * @param aOwnerDocument The document which will be the owner of
453 * the elements of this fragment
455 IMPORT_C void BaseConstructL(const TDesC8& aNsUri,
456 const TDesC8& aLocalName,
457 const TDesC8& aPrefix,
458 const RAttributeArray& aAttrs,
459 TXmlEngElement& aParent,
460 RSenDocument& aOwnerDocument);
463 * Callback functions which implement the XML content handler interface.
464 * Inheriting classes can override these.
467 // From CSenBaseFragment
470 CSenDomFragmentBase* ipDomDelegate;
473 #endif //SEN_DOM_FRAGMENT_BASE_H