Ejemplo n.º 1
0
  /**
   * 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);
  }
Ejemplo n.º 2
0
 /**
  * Processes whatever is at the given URL and returns a response.
  *
  * @param url where to find what is to be processed
  * @return the result of processing whatever is found at the URL
  * @throws ProcessorException if there is a problem processing what is found at the URL
  */
 public String processResponse(URL url) throws ProcessorException {
   return evaluate(JDOM.getDocument(url, this._logger));
 }