1 /* 2 * Copyright (C) 2007 Esmertec AG. 3 * Copyright (C) 2007 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.mms.dom.smil.parser; 19 20 import com.google.android.mms.MmsException; 21 22 import java.io.IOException; 23 import java.io.InputStream; 24 25 import org.xml.sax.InputSource; 26 import org.xml.sax.SAXException; 27 import org.xml.sax.XMLReader; 28 import org.xml.sax.helpers.XMLReaderFactory; 29 import org.w3c.dom.smil.SMILDocument; 30 31 import com.android.mms.dom.smil.parser.SmilContentHandler; 32 33 public class SmilXmlParser { 34 private XMLReader mXmlReader; 35 private SmilContentHandler mContentHandler; 36 37 public SmilXmlParser() throws MmsException { 38 //FIXME: Now we don't have the SAXParser wrapped inside, 39 // use the Driver class temporarily. 40 System.setProperty("org.xml.sax.driver", "org.xmlpull.v1.sax2.Driver"); 41 42 try { 43 mXmlReader = XMLReaderFactory.createXMLReader(); 44 mContentHandler = new SmilContentHandler(); 45 mXmlReader.setContentHandler(mContentHandler); 46 } catch (SAXException e) { 47 throw new MmsException(e); 48 } 49 } 50 51 public SMILDocument parse(InputStream in) throws IOException, SAXException { 52 mContentHandler.reset(); 53 54 mXmlReader.parse(new InputSource(in)); 55 56 SMILDocument doc = mContentHandler.getSmilDocument(); 57 validateDocument(doc); 58 59 return doc; 60 } 61 62 private void validateDocument(SMILDocument doc) { 63 /* 64 * Calling getBody() will create "smil", "head", and "body" elements if they 65 * are not present. It will also initialize the SequentialTimeElementContainer 66 * member of SMILDocument, which could not be set on creation of the document. 67 * @see com.android.mms.dom.smil.SmilDocumentImpl#getBody() 68 */ 69 doc.getBody(); 70 71 /* 72 * Calling getLayout() will create "layout" element if it is not present. 73 * @see com.android.mms.dom.smil.SmilDocumentImpl#getLayout() 74 */ 75 doc.getLayout(); 76 } 77 } 78