public ClassNoaaEmailParser() {}
public VirtualFileStructure parse(FileInputStream emailFile)
throws ParserException {
try {
VirtualFile root = VirtualFile.createRootDir();
Scanner s = new Scanner(emailFile);
StringBuffer sb = new StringBuffer("");
while (s.hasNextLine())
sb.append(s.nextLine() + "\n");
if (!validEmail(sb.toString()))
throw new ParserException(
"Email not a IASI data processed notification email");
Pattern cdPattern = Pattern.compile("\\s*cd\\s{1,}.{1,}?(?:\\s|$)");
Matcher cdMatcher = cdPattern.matcher(sb);
Pattern getPattern = Pattern.compile("\\s*get\\s{1,}.{1,}?(?:\\s|$)");
Matcher getMatcher = getPattern.matcher(sb);
VirtualFile vf = null;
while (cdMatcher.find() && getMatcher.find()) {
String cdCommand = sb.substring(cdMatcher.start(), cdMatcher.end());
String directory = cdCommand.trim().split(" ")[1];
vf = new VirtualFile(root, directory, true);
vf.setNoDirs(true);
String getCommand = sb.substring(getMatcher.start(), getMatcher.end());
String file = getCommand.trim().split(" ")[1];
if (file.endsWith("*")) {
vf.addChild(new VirtualFile(file.substring(0,
file.length() - 1), false));
vf.addChild(new VirtualFile(file.substring(0,
file.length() - 1)
+ ".sig", false));
} else {
vf.addChild(new VirtualFile(file, false));
}
}
Pattern ftpPattern = Pattern.compile("\\sftp\\..*?\\s");
Matcher ftpMatcher = ftpPattern.matcher(sb);