1/**
2 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 *     http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14package org.jivesoftware.smackx.provider;
15
16import org.jivesoftware.smack.packet.PacketExtension;
17import org.jivesoftware.smack.provider.PacketExtensionProvider;
18import org.jivesoftware.smackx.packet.Header;
19import org.xmlpull.v1.XmlPullParser;
20
21/**
22 * Parses the header element as defined in <a href="http://xmpp.org/extensions/xep-0131">Stanza Headers and Internet Metadata (SHIM)</a>.
23 *
24 * @author Robin Collier
25 */
26public class HeaderProvider implements PacketExtensionProvider
27{
28	public PacketExtension parseExtension(XmlPullParser parser) throws Exception
29	{
30		String name = parser.getAttributeValue(null, "name");
31		String value = null;
32
33		parser.next();
34
35		if (parser.getEventType() == XmlPullParser.TEXT)
36			value = parser.getText();
37
38		while(parser.getEventType() != XmlPullParser.END_TAG)
39			parser.next();
40
41		return new Header(name, value);
42	}
43
44}
45