コード例 #1
0
  /**
   * Output the file model.
   *
   * @param w the output writer.
   * @throws IOException if there is a problem.
   */
  public void execute(PrintWriter w) throws IOException {
    this.w = w;
    w.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    w.println("<file");
    w.print(" ");
    w.println(XMLUtil.toAttribute("name", fileModel.getDisplayName()));
    w.print(" ");
    w.println(XMLUtil.toAttribute("last-modified", "" + fileModel.getLastModified()));
    if (fileModel.getSourceFile() != null) {
      w.print(" ");
      w.println(XMLUtil.toAttribute("file", fileModel.getSourceFile().getAbsolutePath()));
    }
    w.println(">");
    createLimited();
    if (fileModel.getSourceFile() != null && fileModel.getSourceFile().exists()) {
      try {
        outputContents();
      } finally {
        closeSourceFile();
      }
    }

    outputSummary();

    w.println("</file>");
  }
コード例 #2
0
 private void printAttr(String name, Object value) throws IOException {
   if (value == null) {
     return;
   }
   w.print("   ");
   w.println(XMLUtil.toAttribute(name, value.toString()));
 }
コード例 #3
0
 private void outputContents() throws IOException {
   sourceReader = new BufferedReader(open());
   int lineNumber = 1;
   while (true) {
     String line = sourceReader.readLine();
     if (line == null) {
       break;
     }
     if (!near(lineNumber)) {
       lineNumber++;
       continue;
     }
     w.print("  <line number='" + lineNumber + "'>");
     w.print(XMLUtil.escapeContent(line));
     w.println("</line>");
     lineNumber++;
   }
 }