• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007-2008 Esmertec AG.
3  * Copyright (C) 2007-2008 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 android.util.Log;
21 
22 import org.xml.sax.Attributes;
23 import org.xml.sax.helpers.DefaultHandler;
24 import org.w3c.dom.smil.SMILDocument;
25 import org.w3c.dom.Element;
26 import org.w3c.dom.Node;
27 
28 import com.android.mms.dom.smil.SmilDocumentImpl;
29 
30 public class SmilContentHandler extends DefaultHandler {
31     private static final String TAG = "SmilContentHandler";
32     private static final boolean DEBUG = false;
33     private static final boolean LOCAL_LOGV = false;
34 
35     private SMILDocument mSmilDocument;
36     private Node mCurrentNode;
37 
38     /**
39      * Resets this handler.
40      *
41      */
reset()42     public void reset() {
43         mSmilDocument = new SmilDocumentImpl();
44         mCurrentNode = mSmilDocument;
45     }
46 
47     /**
48      * Returns the SMILDocument.
49      * @return The SMILDocument instance
50      */
getSmilDocument()51     public SMILDocument getSmilDocument() {
52         return mSmilDocument;
53     }
54 
55     @Override
startElement(String uri, String localName, String qName, Attributes attributes)56     public void startElement(String uri, String localName, String qName, Attributes attributes) {
57         if (LOCAL_LOGV) {
58             Log.v(TAG, "SmilContentHandler.startElement. Creating element " + localName);
59         }
60         Element element = mSmilDocument.createElement(localName);
61         if (attributes != null) {
62             for (int i = 0; i < attributes.getLength(); i++) {
63                 if (LOCAL_LOGV) {
64                     Log.v(TAG, "Attribute " + i +
65                         " lname = " + attributes.getLocalName(i) +
66                         " value = " + attributes.getValue(i));
67                 }
68                 element.setAttribute(attributes.getLocalName(i),
69                         attributes.getValue(i));
70             }
71         }
72         if (LOCAL_LOGV) {
73             Log.v(TAG, "Appending " + localName + " to " + mCurrentNode.getNodeName());
74         }
75         mCurrentNode.appendChild(element);
76 
77         mCurrentNode = element;
78     }
79 
80     @Override
endElement(String uri, String localName, String qName)81     public void endElement(String uri, String localName, String qName) {
82         if (LOCAL_LOGV) {
83             Log.v(TAG, "SmilContentHandler.endElement. localName " + localName);
84         }
85         mCurrentNode = mCurrentNode.getParentNode();
86     }
87 
88     @Override
characters(char[] ch, int start, int length)89     public void characters(char[] ch, int start, int length) {
90         if (LOCAL_LOGV) {
91             Log.v(TAG, "SmilContentHandler.characters. ch = " + new String(ch, start, length));
92         }
93     }
94 }
95