Java tutorial
//package com.java2s; //License from project: Common Public License import org.w3c.dom.Element; public class Main { /** * */ public static final String DITA_ELEM_TAGNAME = "dita"; public static final String DITA_ARCH_NS = "http://dita.oasis-open.org/architecture/2005/"; public static final String DITA_ARCH_VERSION_ATTNAME = "DITAArchVersion"; public static final String DITA_MAP_TYPE = "map/map"; public static final String DITA_CLASS_ATTNAME = "class"; /** * Returns true if the element appears to be a map or within a map. * @param elem * @return True or false */ public static boolean isDitaMap(Element elem) { Element root = elem.getOwnerDocument().getDocumentElement(); if (root != null && isInDitaDocument(root)) { return isDitaType(root, DITA_MAP_TYPE); } return false; } /** * Returns true if the element's containing document * @param elem * @return */ public static boolean isInDitaDocument(Element elem) { Element root = elem.getOwnerDocument().getDocumentElement(); Element cand = root; if (cand.getTagName().equals(DITA_ELEM_TAGNAME)) { // FIXME: This a little weak but unlikely to return false positives. return true; } return root.hasAttributeNS(DITA_ARCH_NS, DITA_ARCH_VERSION_ATTNAME); } public static boolean isDitaType(Element element, String ditaMapType) { String classValue = element.getAttribute(DITA_CLASS_ATTNAME); if (classValue != null) { // NOTE: because class values always start with "+" or "-", // index can never be 0. return (classValue.indexOf(" " + ditaMapType.trim() + " ") > 0 || classValue.endsWith(" " + ditaMapType.trim())); } return false; } }