001: /*
002: *******************************************************************************
003: * Copyright (C) 1998-2005, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: *
007: * Created on Dec 3, 2003
008: *
009: *******************************************************************************
010: */
011:
012: package com.ibm.icu.dev.tool.layout;
013:
014: import java.io.PrintStream;
015: import java.io.FileOutputStream;
016: import java.io.IOException;
017: import java.util.Date;
018:
019: import com.ibm.icu.text.MessageFormat;
020:
021: public class ModuleWriter {
022: public ModuleWriter() {
023: wroteDefine = false;
024: output = null;
025: }
026:
027: public void openFile(String outputFileName) {
028: try {
029: output = new PrintStream(new FileOutputStream(
030: outputFileName));
031: } catch (IOException e) {
032: System.out.println("? Could not open " + outputFileName
033: + " for writing.");
034: return;
035: }
036:
037: wroteDefine = false;
038: System.out.println("Writing module " + outputFileName + "...");
039: }
040:
041: public void writeHeader(String define, String[] includeFiles) {
042: writeHeader(define, includeFiles, null);
043: }
044:
045: public void writeHeader(String define, String[] includeFiles,
046: String brief) {
047: MessageFormat format = new MessageFormat(moduleHeader);
048: Object args[] = { new Date(System.currentTimeMillis()) };
049:
050: output.print(format.format(args));
051:
052: if (define != null) {
053: wroteDefine = true;
054: output.print("#ifndef ");
055: output.println(define);
056:
057: output.print("#define ");
058: output.println(define);
059:
060: output.println();
061: }
062:
063: if (includeFiles != null) {
064: for (int i = 0; i < includeFiles.length; i += 1) {
065: output.print("#include \"");
066: output.print(includeFiles[i]);
067: output.println("\"");
068: }
069:
070: output.println();
071: }
072:
073: if (brief != null) {
074: output.print(brief);
075: }
076:
077: output.println(moduleBegin);
078: }
079:
080: public void writeTrailer() {
081: output.print(moduleTrailer);
082:
083: if (wroteDefine) {
084: output.println("#endif");
085:
086: }
087: }
088:
089: public void closeFile() {
090: System.out.println("Done.");
091: output.close();
092: }
093:
094: protected boolean wroteDefine;
095:
096: protected PrintStream output;
097:
098: protected static final String moduleHeader = "/*\n"
099: + " *\n"
100: + " * (C) Copyright IBM Corp. 1998-{0,date,yyyy}. All Rights Reserved.\n"
101: + " *\n"
102: + " * WARNING: THIS FILE IS MACHINE GENERATED. DO NOT HAND EDIT IT UNLESS\n"
103: + " * YOU REALLY KNOW WHAT YOU''RE DOING.\n" + " *\n"
104: + " * Generated on: {0,date,MM/dd/yyyy hh:mm:ss a z}\n"
105: + " */\n" + "\n";
106:
107: protected static final String moduleBegin = "U_NAMESPACE_BEGIN\n";
108:
109: protected static final String moduleTrailer = "U_NAMESPACE_END\n";
110:
111: }
|