2 * Copyright (C) 2007 Esmertec AG.
3 * Copyright (C) 2007 The Android Open Source Project
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package com.android.mms.dom.smil.parser;
20 import com.google.android.mms.MmsException;
22 import java.io.IOException;
23 import java.io.InputStream;
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;
31 import com.android.mms.dom.smil.parser.SmilContentHandler;
33 public class SmilXmlParser {
34 private XMLReader mXmlReader;
35 private SmilContentHandler mContentHandler;
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");
43 mXmlReader = XMLReaderFactory.createXMLReader();
44 mContentHandler = new SmilContentHandler();
45 mXmlReader.setContentHandler(mContentHandler);
46 } catch (SAXException e) {
47 throw new MmsException(e);
51 public SMILDocument parse(InputStream in) throws IOException, SAXException {
52 mContentHandler.reset();
54 mXmlReader.parse(new InputSource(in));
56 SMILDocument doc = mContentHandler.getSmilDocument();
57 validateDocument(doc);
62 private void validateDocument(SMILDocument doc) {
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()
72 * Calling getLayout() will create "layout" element if it is not present.
73 * @see com.android.mms.dom.smil.SmilDocumentImpl#getLayout()