public int go(String dirname, String header, String version, String prepend)
throws Exception {
String now = new Date().toString();
int ret = 0;
int fcount = 0;
m_root = new XFile(dirname);
m_files = m_root.getFiles(true);
for (String fname = m_files.firstItem(); fname != null; fname = m_files.nextItem()) {
if (fname.endsWith(".java")) {
int replacements = 0;
System.out.println("JAVA FILE: " + dirname + java.io.File.separator + fname);
++fcount;
XFile file = new XFile(dirname, fname);
long mod = file.lastModified() + 1000L;
StringVector sv = file.getTextLines();
StringVector svout = new StringVector();
XString xheader = new XString(header);
XString className = new XString(prepend + fname.substring(0, fname.length() - 5));
className.replace(File.separator, ".");
String modificationDateString = new Date(mod).toString();
xheader.replace(DATE, modificationDateString);
xheader.replace(NOW, now);
xheader.replace(VERSION, version);
xheader.replace(CLASSNAME, className.toString());
boolean removing = false;
svout.append(BEGIN_HEADER);
svout.append(xheader.toString());
svout.append(END_HEADER);
boolean needVersion = false;
boolean needVersionNow = false;
boolean versionInserted = false;
for (String s = sv.firstItem(); s != null; s = sv.nextItem()) {
if (removing) {
if (s.startsWith(END_HEADER)) {
removing = false;
}
} else {
if (s.startsWith(BEGIN_HEADER)) {
++replacements;
removing = true;
} else {
if (needVersionNow) {
String vstring = "";
if (s.indexOf(VERSION_MEMBER) >= 0) {
s = vstring;
} else {
svout.append(vstring);
}
needVersion = false;
needVersionNow = false;
versionInserted = true;
}
if (!versionInserted && s.indexOf("public class ") >= 0) {
needVersion = true;
}
if (needVersion) {
if (s.indexOf("{") >= 0) {
needVersionNow = true;
}
}
svout.append(s);
}
}
}
if (replacements > 0) {
++ret;
}
System.out.println("WRITING (" + replacements + ") : " + fname + " [" + modificationDateString + "]");
file.writeTextLines(svout);
file.setLastModified(mod);
} else {
//System.out.println(fname);
}
}