Example #1
0
 /**
  * Writes the relevant output.
  *
  * @param writer
  * @throws XMLStreamException
  */
 private void writeOutput(XMLStreamWriter writer) throws XMLStreamException {
   int type = getType();
   if (type == TEXT_NODE || type == SPACE_NODE) {
     writer.writeCharacters(this.getText());
   } else if (type == CDATA_SECTION_NODE) {
     writer.writeCData(this.getText());
   } else if (type == ENTITY_REFERENCE_NODE) {
     writer.writeEntityRef(this.getText());
   }
 }
 public void writeEntityRef(String name) throws XMLStreamException {
   writer.writeEntityRef(name);
 }
Example #3
0
  private void encodeXhtml(XhtmlDt theDt, XMLStreamWriter theEventWriter)
      throws XMLStreamException {
    if (theDt == null || theDt.getValue() == null || getSuppressNarratives()) {
      return;
    }

    boolean firstElement = true;
    for (XMLEvent event : theDt.getValue()) {
      switch (event.getEventType()) {
        case XMLStreamConstants.ATTRIBUTE:
          Attribute attr = (Attribute) event;
          if (isBlank(attr.getName().getPrefix())) {
            if (isBlank(attr.getName().getNamespaceURI())) {
              theEventWriter.writeAttribute(attr.getName().getLocalPart(), attr.getValue());
            } else {
              theEventWriter.writeAttribute(
                  attr.getName().getNamespaceURI(), attr.getName().getLocalPart(), attr.getValue());
            }
          } else {
            theEventWriter.writeAttribute(
                attr.getName().getPrefix(),
                attr.getName().getNamespaceURI(),
                attr.getName().getLocalPart(),
                attr.getValue());
          }

          break;
        case XMLStreamConstants.CDATA:
          theEventWriter.writeCData(((Characters) event).getData());
          break;
        case XMLStreamConstants.CHARACTERS:
        case XMLStreamConstants.SPACE:
          String data = ((Characters) event).getData();
          theEventWriter.writeCharacters(data);
          break;
        case XMLStreamConstants.COMMENT:
          theEventWriter.writeComment(((Comment) event).getText());
          break;
        case XMLStreamConstants.END_ELEMENT:
          theEventWriter.writeEndElement();
          break;
        case XMLStreamConstants.ENTITY_REFERENCE:
          EntityReference er = (EntityReference) event;
          theEventWriter.writeEntityRef(er.getName());
          break;
        case XMLStreamConstants.NAMESPACE:
          Namespace ns = (Namespace) event;
          theEventWriter.writeNamespace(ns.getPrefix(), ns.getNamespaceURI());
          break;
        case XMLStreamConstants.START_ELEMENT:
          StartElement se = event.asStartElement();
          if (firstElement) {
            if (StringUtils.isBlank(se.getName().getPrefix())) {
              String namespaceURI = se.getName().getNamespaceURI();
              if (StringUtils.isBlank(namespaceURI)) {
                namespaceURI = "http://www.w3.org/1999/xhtml";
              }
              theEventWriter.writeStartElement(se.getName().getLocalPart());
              theEventWriter.writeDefaultNamespace(namespaceURI);
            } else {
              String prefix = se.getName().getPrefix();
              String namespaceURI = se.getName().getNamespaceURI();
              theEventWriter.writeStartElement(prefix, se.getName().getLocalPart(), namespaceURI);
              theEventWriter.writeNamespace(prefix, namespaceURI);
            }
            firstElement = false;
          } else {
            if (isBlank(se.getName().getPrefix())) {
              if (isBlank(se.getName().getNamespaceURI())) {
                theEventWriter.writeStartElement(se.getName().getLocalPart());
              } else {
                if (StringUtils.isBlank(se.getName().getPrefix())) {
                  theEventWriter.writeStartElement(se.getName().getLocalPart());
                  // theEventWriter.writeDefaultNamespace(se.getName().getNamespaceURI());
                } else {
                  theEventWriter.writeStartElement(
                      se.getName().getNamespaceURI(), se.getName().getLocalPart());
                }
              }
            } else {
              theEventWriter.writeStartElement(
                  se.getName().getPrefix(),
                  se.getName().getLocalPart(),
                  se.getName().getNamespaceURI());
            }
            for (Iterator<?> attrIter = se.getAttributes(); attrIter.hasNext(); ) {
              Attribute next = (Attribute) attrIter.next();
              theEventWriter.writeAttribute(next.getName().getLocalPart(), next.getValue());
            }
          }
          break;
        case XMLStreamConstants.DTD:
        case XMLStreamConstants.END_DOCUMENT:
        case XMLStreamConstants.ENTITY_DECLARATION:
        case XMLStreamConstants.NOTATION_DECLARATION:
        case XMLStreamConstants.PROCESSING_INSTRUCTION:
        case XMLStreamConstants.START_DOCUMENT:
          break;
      }
    }
  }
 public void writeEntityRef(java.lang.String name) throws XMLStreamException {
   baseWriter.writeEntityRef(name);
 }