Search in sources :

Example 1 with AttrImpl

use of com.android.mms.dom.AttrImpl in project qksms by moezbhatti.

the class SlideshowActivity method isMMSConformance.

/**
 * @return whether the Smil has MMS conformance layout.
 * Refer to MMS Conformance Document OMA-MMS-CONF-v1_2-20050301-A
 */
private static final boolean isMMSConformance(SMILDocument smilDoc) {
    SMILElement head = smilDoc.getHead();
    if (head == null) {
        // No 'head' element
        return false;
    }
    NodeList children = head.getChildNodes();
    if (children == null || children.getLength() != 1) {
        // The 'head' element should have only one child.
        return false;
    }
    Node layout = children.item(0);
    if (layout == null || !"layout".equals(layout.getNodeName())) {
        // The child is not layout element
        return false;
    }
    NodeList layoutChildren = layout.getChildNodes();
    if (layoutChildren == null) {
        // The 'layout' element has no child.
        return false;
    }
    int num = layoutChildren.getLength();
    if (num <= 0) {
        // The 'layout' element has no child.
        return false;
    }
    for (int i = 0; i < num; i++) {
        Node layoutChild = layoutChildren.item(i);
        if (layoutChild == null) {
            // The 'layout' child is null.
            return false;
        }
        String name = layoutChild.getNodeName();
        if ("root-layout".equals(name)) {
            continue;
        } else if ("region".equals(name)) {
            NamedNodeMap map = layoutChild.getAttributes();
            for (int j = 0; j < map.getLength(); j++) {
                Node node = map.item(j);
                if (node == null) {
                    return false;
                }
                String attrName = node.getNodeName();
                // The attr should be one of left, top, height, width, fit and id
                if ("left".equals(attrName) || "top".equals(attrName) || "height".equals(attrName) || "width".equals(attrName) || "fit".equals(attrName)) {
                    continue;
                } else if ("id".equals(attrName)) {
                    String value;
                    if (node instanceof AttrImpl) {
                        value = ((AttrImpl) node).getValue();
                    } else {
                        return false;
                    }
                    if ("Text".equals(value) || "Image".equals(value)) {
                        continue;
                    } else {
                        // The id attr is not 'Text' or 'Image'
                        return false;
                    }
                } else {
                    return false;
                }
            }
        } else {
            // The 'layout' element has the child other than 'root-layout' or 'region'
            return false;
        }
    }
    return true;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) SMILElement(org.w3c.dom.smil.SMILElement) AttrImpl(com.android.mms.dom.AttrImpl)

Aggregations

AttrImpl (com.android.mms.dom.AttrImpl)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 SMILElement (org.w3c.dom.smil.SMILElement)1