Example #1
0
  public void flushCharacters(boolean finalFlush, boolean topLevel) throws SAXException {

    if (currentCharacters.length() > 0) {

      final String currentString = currentCharacters.toString();
      final char[] chars = currentString.toCharArray();
      if (StringUtils.isBlank(currentString) || !topLevel) {
        // Just output whitespace as is
        super.characters(chars, 0, chars.length);
      } else {

        // The first element received determines the type of separator
        checkDelimiters(XMLConstants.XHTML_NAMESPACE_URI, spanQName, topLevel);

        // Wrap any other text within an xhtml:span
        super.startElement(
            XMLConstants.XHTML_NAMESPACE_URI,
            "span",
            spanQName,
            getAttributesWithClass(XMLUtils.EMPTY_ATTRIBUTES));
        super.characters(chars, 0, chars.length);
        super.endElement(XMLConstants.XHTML_NAMESPACE_URI, "span", spanQName);
      }

      isCharacters = false;
      currentCharacters.setLength(0);
    }

    if (finalFlush) checkDelimiters(XMLConstants.XHTML_NAMESPACE_URI, spanQName, topLevel);
  }
Example #2
0
  public void startElement(String uri, String localname, String qName, Attributes attributes)
      throws SAXException {

    level++;
    final boolean topLevel = level == 1;

    flushCharacters(false, topLevel);

    // The first element received determines the type of separator
    checkDelimiters(uri, qName, topLevel);

    // Add or update classes on element if needed
    super.startElement(
        uri, localname, qName, topLevel ? getAttributesWithClass(attributes) : attributes);
  }