1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ims.rcs.uce.presence.pidfparser.pidf; 18 19 import android.util.Log; 20 21 import com.android.ims.rcs.uce.presence.pidfparser.ElementBase; 22 import com.android.ims.rcs.uce.util.UceUtils; 23 24 import org.xmlpull.v1.XmlPullParser; 25 import org.xmlpull.v1.XmlPullParserException; 26 import org.xmlpull.v1.XmlSerializer; 27 28 import java.io.IOException; 29 30 /** 31 * The "status" element of the pidf. 32 */ 33 public class Status extends ElementBase { 34 private static final String LOG_TAG = UceUtils.getLogPrefix() + "Status"; 35 36 /** The name of this element */ 37 public static final String ELEMENT_NAME = "status"; 38 39 // The "status" element contain one optional "basic" element. 40 private Basic mBasic; 41 Status()42 public Status() { 43 } 44 45 @Override initNamespace()46 protected String initNamespace() { 47 return PidfConstant.NAMESPACE; 48 } 49 50 @Override initElementName()51 protected String initElementName() { 52 return ELEMENT_NAME; 53 } 54 setBasic(Basic basic)55 public void setBasic(Basic basic) { 56 mBasic = basic; 57 } 58 getBasic()59 public Basic getBasic() { 60 return mBasic; 61 } 62 63 @Override serialize(XmlSerializer serializer)64 public void serialize(XmlSerializer serializer) throws IOException { 65 if (mBasic == null) { 66 return; 67 } 68 final String namespace = getNamespace(); 69 final String element = getElementName(); 70 serializer.startTag(namespace, element); 71 mBasic.serialize(serializer); 72 serializer.endTag(namespace, element); 73 } 74 75 @Override parse(XmlPullParser parser)76 public void parse(XmlPullParser parser) throws IOException, XmlPullParserException { 77 String namespace = parser.getNamespace(); 78 String name = parser.getName(); 79 80 if (!verifyParsingElement(namespace, name)) { 81 throw new XmlPullParserException("Incorrect element: " + namespace + ", " + name); 82 } 83 84 // Move to the next tag to get the Basic element. 85 int eventType = parser.nextTag(); 86 87 // Get the value if the event type is text. 88 if (eventType == XmlPullParser.START_TAG) { 89 Basic basic = new Basic(); 90 basic.parse(parser); 91 mBasic = basic; 92 } else { 93 Log.d(LOG_TAG, "The eventType is not START_TAG=" + eventType); 94 } 95 96 // Move to the end tag. 97 moveToElementEndTag(parser, eventType); 98 } 99 } 100