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;
19 
20 import org.w3c.dom.DOMException;
21 import org.w3c.dom.smil.SMILRootLayoutElement;
22 
23 public class SmilRootLayoutElementImpl extends SmilElementImpl implements
24         SMILRootLayoutElement {
25 
26     private static final String WIDTH_ATTRIBUTE_NAME = "width";
27     private static final String HEIGHT_ATTRIBUTE_NAME = "height";
28     private static final String BACKGROUND_COLOR_ATTRIBUTE_NAME = "backgroundColor";
29     private static final String TITLE_ATTRIBUTE_NAME = "title";
30 
SmilRootLayoutElementImpl(SmilDocumentImpl owner, String tagName)31     SmilRootLayoutElementImpl(SmilDocumentImpl owner, String tagName) {
32         super(owner, tagName);
33     }
34 
getBackgroundColor()35     public String getBackgroundColor() {
36         return this.getAttribute(BACKGROUND_COLOR_ATTRIBUTE_NAME);
37     }
38 
getHeight()39     public int getHeight() {
40         String heightString = this.getAttribute(HEIGHT_ATTRIBUTE_NAME);
41         return parseAbsoluteLength(heightString);
42     }
43 
getTitle()44     public String getTitle() {
45         return this.getAttribute(TITLE_ATTRIBUTE_NAME);
46     }
47 
getWidth()48     public int getWidth() {
49         String widthString = this.getAttribute(WIDTH_ATTRIBUTE_NAME);
50         return parseAbsoluteLength(widthString);
51     }
52 
setBackgroundColor(String backgroundColor)53     public void setBackgroundColor(String backgroundColor) throws DOMException {
54         this.setAttribute(BACKGROUND_COLOR_ATTRIBUTE_NAME, backgroundColor);
55     }
56 
setHeight(int height)57     public void setHeight(int height) throws DOMException {
58         this.setAttribute(HEIGHT_ATTRIBUTE_NAME, String.valueOf(height) + "px");
59 
60     }
61 
setTitle(String title)62     public void setTitle(String title) throws DOMException {
63         this.setAttribute(TITLE_ATTRIBUTE_NAME, title);
64     }
65 
setWidth(int width)66     public void setWidth(int width) throws DOMException {
67         this.setAttribute(WIDTH_ATTRIBUTE_NAME, String.valueOf(width) + "px");
68     }
69 
70     /*
71      * Internal Interface
72      */
73 
parseAbsoluteLength(String length)74     private int parseAbsoluteLength(String length) {
75         if (length.endsWith("px")) {
76             length = length.substring(0, length.indexOf("px"));
77         }
78         try {
79             return Integer.parseInt(length);
80         } catch (NumberFormatException e) {
81             return 0;
82         }
83     }
84 }
85