package textbender.d.gene; // Copyright 2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import org.w3c.dom.*; import textbender.g.lang.ThreadSafe; import static textbender._.Textbender.TEXTBENDER_NAMESPACE; /** Recombinant texts as XML documents. * * @see * document.mod */ public final @ThreadSafe class DocumentRT { /** Standard error message that clients of * {@linkplain DocumentRT#findMetaData meta-data element} can show to user. */ public static final String FIND_META_DATA_FAILURE_MESSAGE = "unable to find element with textbender attribute 'document-meta-data'"; /** Finds a document's meta-data element. * * @param node to search, recursively (typically the document node) * * @return meta-data element, or null if none found */ public static Element findMetaData( final Node node ) { if( node instanceof Element ) { Element element = (Element)node; String metaData = element.getAttributeNS( TEXTBENDER_NAMESPACE, "document-meta-data" ); if( metaData.length() > 0 ) return element; } for( Node child = node.getFirstChild(); child != null; child = child.getNextSibling() ) { Element element = findMetaData( child ); if( element != null ) return element; } return null; } }