2 * Copyright (C) 2007-2008 Esmertec AG.
3 * Copyright (C) 2007-2008 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 android.util.Config;
21 import android.util.Log;
23 import org.xml.sax.Attributes;
24 import org.xml.sax.helpers.DefaultHandler;
25 import org.w3c.dom.smil.SMILDocument;
26 import org.w3c.dom.Element;
27 import org.w3c.dom.Node;
29 import com.android.mms.dom.smil.SmilDocumentImpl;
31 public class SmilContentHandler extends DefaultHandler {
32 private static final String TAG = "SmilContentHandler";
33 private static final boolean DEBUG = false;
34 private static final boolean LOCAL_LOGV = DEBUG ? Config.LOGD : Config.LOGV;
36 private SMILDocument mSmilDocument;
37 private Node mCurrentNode;
40 * Resets this handler.
44 mSmilDocument = new SmilDocumentImpl();
45 mCurrentNode = mSmilDocument;
49 * Returns the SMILDocument.
50 * @return The SMILDocument instance
52 public SMILDocument getSmilDocument() {
57 public void startElement(String uri, String localName, String qName, Attributes attributes) {
59 Log.v(TAG, "SmilContentHandler.startElement. Creating element " + localName);
61 Element element = mSmilDocument.createElement(localName);
62 if (attributes != null) {
63 for (int i = 0; i < attributes.getLength(); i++) {
65 Log.v(TAG, "Attribute " + i +
66 " lname = " + attributes.getLocalName(i) +
67 " value = " + attributes.getValue(i));
69 element.setAttribute(attributes.getLocalName(i),
70 attributes.getValue(i));
74 Log.v(TAG, "Appending " + localName + " to " + mCurrentNode.getNodeName());
76 mCurrentNode.appendChild(element);
78 mCurrentNode = element;
82 public void endElement(String uri, String localName, String qName) {
84 Log.v(TAG, "SmilContentHandler.endElement. localName " + localName);
86 mCurrentNode = mCurrentNode.getParentNode();
90 public void characters(char[] ch, int start, int length) {
92 Log.v(TAG, "SmilContentHandler.characters. ch = " + new String(ch, start, length));