2 * Copyright (c) 2002-2005 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: Central place for debug-type macros
25 #ifndef SEN_FRAGMENT_H
26 #define SEN_FRAGMENT_H
31 #include <xml/attribute.h>
32 #include <SenXmlReader.h>
33 #include <SenElement.h>
34 #include <MSenFragment.h>
38 * Abstract base class declaring XML fragment interface.
42 class CSenFragment : public CBase, public MSenFragment
44 public: // New functions
47 * Getting the fragment as an XML element. This method will panic if
48 * element has not been initialized for any reason.
49 * @return the current object as element. Ownership is not transferred.
51 virtual CSenElement& AsElement() = 0;
54 * @return the current object as element. May return NULL.
55 * Caller takes ownership.
57 * Note(!): the return value (CSenElement) STRONGLY suggests that
58 * subclasses INHERIT CSenFragment in order properly comply the
59 * requirement of the ExtractElement() implementation.
61 virtual CSenElement* ExtractElement() = 0;
64 * Sets the XML reader to be used for parsing for the fragment.
65 * @param aReader: the reader to be used.
66 * Ownership is NOT transferred.
68 virtual void SetReader(CSenXmlReader& aReader) = 0;
71 * Gets the XML reader which this fragment uses for parsing.
72 * @param aReader: the reader to be used.
73 * Ownerships is not transferred.
75 virtual CSenXmlReader* Reader() = 0;
78 * Method to invoke parsing of a XML data.
79 * Note: SetReader() must be called before this method can be used.
80 * @param aXml: The XML data to be parsed.
82 virtual void ParseL(const TDesC8& aXml) = 0;
85 * Same as ParseL() except that it doesn't leave in case of an error.
86 * Instead errors are trapped and error is returned.
87 * SetReader() must be called before this method can be used.
88 * @return KErrNone or other system-wide Symbian error codes.
90 virtual TInt BuildFrom(const TDesC8& aBuf) = 0;
93 * Let the delegate MSenFragment handle the following SAX events.
94 * This fragment is made the owner of the delegate and
95 * the delegate is expected to make this MSenFragment the receiver
96 * of SAX events once it has seen the end element for itself.
97 * @param aDelegate: the fragment to start handling the SAX events.
99 virtual void DelegateParsingL(MSenFragment& aDelegate) = 0;
102 * Creates a new fragment and lets the created MSenFragment handle
103 * the following SAX events.
104 * This fragment is made the owner of the delegate and
105 * the delegate is expected to make this MSenFragment the receiver
106 * of SAX events once it has seen the end element for itself.
107 * @param aNsUri: the namespace URI of the new delegate
108 * @param aLocalName: the local name of the new delegate
109 * @param aQName: the qualified name of the new delegate
110 * @param aAttrs: the attributes which to be set for the new delegate
112 virtual void DelegateParsingL(const TDesC8& aNsUri,
113 const TDesC8& aLocalName,
114 const TDesC8& aQName,
115 const RAttributeArray& aAttrs) = 0;
118 * Sets the reader for this fragment and sets this to be the
119 * content handler of the following SAX events.
120 * @param aReader: Reader to be used.
122 virtual void ParseWithL(CSenXmlReader& aReader) = 0;
125 * Sets a new parent for this fragment.
126 * @param aFragment: the new parent.
128 virtual void SetOwner(MSenFragment& aFragment) = 0;
131 * Resumes the parsing. Usually called by the delegate fragment which was
132 * parsing itself after DelegateParsingL().
133 * @param aNsUri The namespace URI of the current element
134 * @param aLocalName The local name of the current element
135 * @param aQName The qualified name of the current element
137 virtual void ResumeParsingFromL(const TDesC8& aNsUri,
138 const TDesC8& aLocalName,
139 const TDesC8& aQName) = 0;
142 * Sets the attributes for the fragment.
143 * @param aAttrs: the array of attributes.
145 virtual void SetAttributesL(const RAttributeArray& aAttrs) = 0;
148 * Writes the start element tag to the content stream.
149 * Derivants can override the basic usage used in BaseFragment.
150 * @param aNsUri The namespace URI of the current element
151 * @param aLocalName The local name of the current element
152 * @param aQName The qualified name of the current element
153 * @param aAttrs: the array of attributes.
155 virtual void WriteStartElementL(const TDesC8& aNsUri,
156 const TDesC8& aLocalName,
157 const TDesC8& aQName,
158 const RAttributeArray& aAttrs) = 0;
161 * Writes the end element tag to the content stream.
162 * Derivants can override the basic usage used in BaseFragment.
163 * @param aNsUri The namespace URI of the current element
164 * @param aLocalName The local name of the current element
165 * @param aQName The qualified name of the current element
167 virtual void WriteEndElementL(const TDesC8& aNsUri,
168 const TDesC8& aLocalName,
169 const TDesC8& aQName) = 0;
172 * Getter for Fragment's local name.
173 * @return Localname or KNullDesC if not set.
175 virtual const TDesC8& LocalName() const = 0;
178 * Getter for Fragment's namespace URI.
179 * @return Namespace URI or KNullDesC if not set.
181 virtual const TDesC8& NsUri() const = 0;
184 * Getter for namespace prefix of this fragment.
185 * @return namespace prefix or KNullDesC if not set.
187 virtual const TDesC8& NsPrefix() const = 0;
190 * Fragment writes itself to a write stream using UTF-8 charset encoding.
191 * @param aWriteStream: The stream to write to.
193 virtual void WriteAsXMLToL(RWriteStream& aWriteStream) = 0;
196 * Gets the fragment as an unicode XML buffer.
197 * Buffer will contain all the childs etc.
198 * @return fragment as XML. Caller takes ownership.
200 virtual HBufC* AsXmlUnicodeL() = 0;
203 * Gets the fragment as an XML buffer.
204 * @return fragment as XML. Caller takes ownership.
206 virtual HBufC8* AsXmlL() = 0;
209 * Getter for the content. Returns content namespaces if there are any.
212 virtual TPtrC8 Content() = 0;
215 * Checks if fragment matches to another fragment
216 * by its content and child elements.
217 * Fragment can contain more data than the given candidate.
218 * @since Series60 3.0
219 * @param aCandidate The pattern to be matched. Must contain same or
220 * less data for match to come true.
221 * @return ETrue if content and possible children match exactly
222 * to given pattern. EFalse otherwise.
224 virtual TBool ConsistsOfL(MSenFragment& aCandidate) = 0;
227 #endif // SEN_FRAGMENT_H