コード例 #1
0
ファイル: XMLTransformer.java プロジェクト: tharman/text
  public void write(String text, boolean fromSource) {
    if (LOG.isLoggable(Level.FINER)) {
      LOG.finer(
          "Inserting Text: '"
              + text.replaceAll("[\r\n]+", "\\\\n")
              + "' ("
              + (fromSource ? "from source" : "generated")
              + ")");
    }
    try {
      final int textLength = text.length();
      final StringBuilder inserted = new StringBuilder();
      if (fromSource) {
        final boolean preserveSpace = isSpacePreserved();
        for (int cc = 0; cc < textLength; cc++) {
          char currentChar = text.charAt(cc);
          if (!preserveSpace
              && configuration.isCompressingWhitespace()
              && Character.isWhitespace(lastChar)
              && Character.isWhitespace(currentChar)) {
            mapOffsetDelta(0, 1);
            continue;
          }
          if (currentChar == '\n' || currentChar == '\r') {
            currentChar = ' ';
          }
          textBuffer.write(Character.toString(lastChar = currentChar).getBytes());
          inserted.append(lastChar);
          mapOffsetDelta(1, 1);
        }
      } else {
        textBuffer.write(text.getBytes());
        inserted.append(text);
        mapOffsetDelta(inserted.length(), 0);
      }

      final String insertedStr = inserted.toString();
      for (XMLTransformerModule<T> m : configuration.getModules()) {
        m.textWritten(this, text, insertedStr);
      }
    } catch (IOException e) {
      throw Throwables.propagate(e);
    }
  }
コード例 #2
0
ファイル: XMLTransformer.java プロジェクト: tharman/text
 public XMLTransformer(XMLTransformerConfiguration<T> configuration) {
   this.configuration = configuration;
   this.modules = configuration.getModules();
 }