Пример #1
0
  /**
   * Writes the given {@link Text}.
   *
   * @param text <code>Text</code> to output.
   * @throws IOException DOCUMENT ME!
   */
  public void write(Text text) throws IOException {
    writeString(text.getText());

    if (autoFlush) {
      flush();
    }
  }
Пример #2
0
 /* 364:    */
 /* 365:    */ protected void writeContent(Branch branch, NamespaceStack namespaceStack)
     /* 366:    */ throws SAXException
       /* 367:    */ {
   /* 368:615 */ for (Iterator iter = branch.nodeIterator(); iter.hasNext(); )
   /* 369:    */ {
     /* 370:616 */ Object object = iter.next();
     /* 371:618 */ if ((object instanceof Element)) {
       /* 372:619 */ write((Element) object, namespaceStack);
       /* 373:620 */ } else if ((object instanceof CharacterData))
     /* 374:    */ {
       /* 375:621 */ if ((object instanceof Text))
       /* 376:    */ {
         /* 377:622 */ Text text = (Text) object;
         /* 378:623 */ write(text.getText());
         /* 379:    */ }
       /* 380:624 */ else if ((object instanceof CDATA))
       /* 381:    */ {
         /* 382:625 */ write((CDATA) object);
         /* 383:    */ }
       /* 384:626 */ else if ((object instanceof Comment))
       /* 385:    */ {
         /* 386:627 */ write((Comment) object);
         /* 387:    */ }
       /* 388:    */ else
       /* 389:    */ {
         /* 390:629 */ throw new SAXException(
             "Invalid Node in DOM4J content: " + object + " of type: " + object.getClass());
         /* 391:    */ }
       /* 392:    */ }
     /* 393:632 */ else if ((object instanceof String)) {
       /* 394:633 */ write((String) object);
       /* 395:634 */ } else if ((object instanceof Entity)) {
       /* 396:635 */ write((Entity) object);
       /* 397:636 */ } else if ((object instanceof ProcessingInstruction)) {
       /* 398:637 */ write((ProcessingInstruction) object);
       /* 399:638 */ } else if ((object instanceof Namespace)) {
       /* 400:639 */ write((Namespace) object);
       /* 401:    */ } else {
       /* 402:641 */ throw new SAXException("Invalid Node in DOM4J content: " + object);
       /* 403:    */ }
     /* 404:    */ }
   /* 405:    */ }
Пример #3
0
 public void visit(Text node) {
   String text = node.getText();
   extractUsedProperties(text);
 }
Пример #4
0
  /**
   * Outputs the content of the given element. If whitespace trimming is enabled then all adjacent
   * text nodes are appended together before the whitespace trimming occurs to avoid problems with
   * multiple text nodes being created due to text content that spans parser buffers in a SAX
   * parser.
   *
   * @param element DOCUMENT ME!
   * @throws IOException DOCUMENT ME!
   */
  protected void writeElementContent(Element element) throws IOException {
    boolean trim = format.isTrimText();
    boolean oldPreserve = preserve;

    if (trim) { // verify we have to before more expensive test
      preserve = isElementSpacePreserved(element);
      trim = !preserve;
    }

    if (trim) {
      // concatenate adjacent text nodes together
      // so that whitespace trimming works properly
      Text lastTextNode = null;
      StringBuilder buff = null;
      boolean textOnly = true;

      for (Node node : element.content()) {
        if (node instanceof Text) {
          if (lastTextNode == null) {
            lastTextNode = (Text) node;
          } else {
            if (buff == null) {
              buff = new StringBuilder(lastTextNode.getText());
            }

            buff.append((node).getText());
          }
        } else {
          if (!textOnly && format.isPadText()) {
            // only add the PAD_TEXT if the text itself starts with
            // whitespace
            char firstChar = 'a';
            if (buff != null) {
              firstChar = buff.charAt(0);
            } else if (lastTextNode != null) {
              firstChar = lastTextNode.getText().charAt(0);
            }

            if (Character.isWhitespace(firstChar)) {
              writer.write(PAD_TEXT);
            }
          }

          if (lastTextNode != null) {
            if (buff != null) {
              writeString(buff.toString());
              buff = null;
            } else {
              writeString(lastTextNode.getText());
            }

            if (format.isPadText()) {
              // only add the PAD_TEXT if the text itself ends
              // with whitespace
              char lastTextChar = 'a';
              if (buff != null) {
                lastTextChar = buff.charAt(buff.length() - 1);
              } else if (lastTextNode != null) {
                String txt = lastTextNode.getText();
                lastTextChar = txt.charAt(txt.length() - 1);
              }

              if (Character.isWhitespace(lastTextChar)) {
                writer.write(PAD_TEXT);
              }
            }

            lastTextNode = null;
          }

          textOnly = false;
          writeNode(node);
        }
      }

      if (lastTextNode != null) {
        if (!textOnly && format.isPadText()) {
          // only add the PAD_TEXT if the text itself starts with
          // whitespace
          char firstChar = 'a';
          if (buff != null) {
            firstChar = buff.charAt(0);
          } else {
            firstChar = lastTextNode.getText().charAt(0);
          }

          if (Character.isWhitespace(firstChar)) {
            writer.write(PAD_TEXT);
          }
        }

        if (buff != null) {
          writeString(buff.toString());
          buff = null;
        } else {
          writeString(lastTextNode.getText());
        }

        lastTextNode = null;
      }
    } else {
      Node lastTextNode = null;

      for (Node node : element.content()) {
        if (node instanceof Text) {
          writeNode(node);
          lastTextNode = node;
        } else {
          if ((lastTextNode != null) && format.isPadText()) {
            // only add the PAD_TEXT if the text itself ends with
            // whitespace
            String txt = lastTextNode.getText();
            char lastTextChar = txt.charAt(txt.length() - 1);

            if (Character.isWhitespace(lastTextChar)) {
              writer.write(PAD_TEXT);
            }
          }

          writeNode(node);

          // if ((lastTextNode != null) && format.isPadText()) {
          // writer.write(PAD_TEXT);
          // }

          lastTextNode = null;
        }
      }
    }

    preserve = oldPreserve;
  }