/** * Recursively evaluates an element. * * @param element the element * @return the result of processing the element * @throws ProcessorException if there is an error in processing */ @SuppressWarnings("unchecked") public String evaluate(Element element) throws ProcessorException { // Is it a valid element? if (element == null) { return ""; } // Search for the tag in the processor registry. Class<? extends P> processorClass = null; String elementNamespaceURI = element.getNamespaceURI(); Document elementDocument = element.getDocument(); boolean emitXMLNS = elementDocument != null && (element.equals(element.getDocument().getRootElement()) || (elementNamespaceURI != null && !elementNamespaceURI.equals( element.getDocument().getRootElement().getNamespaceURI()))); if (elementNamespaceURI == null || this._registry.getNamespaceURI().equals(elementNamespaceURI)) { processorClass = this._registry.get(element.getName()); // Process the element with a new instance of the processor. return Classes.getNewInstance(processorClass, "Processor", this._core).process(element, this); } // otherwise (if this element is from a different namespace) if (element.getContent().size() == 0) { return JDOM.renderEmptyElement(element, emitXMLNS); } // otherwise... return JDOM.renderStartTag(element, emitXMLNS) + evaluate(element.getContent()) + JDOM.renderEndTag(element); }