import java.io.*;
public class ThesisIIV1
{
// ************************************************************
// * *
// * main Method *
// * *
// ************************************************************
public static void main(String[] args) throws Exception
{
String[] inputStrings;
System.out.println("\n * * * Welcome to the UML Specification Analysis * * * \n");
/*CALL*/inputStrings=input();
/*CALL*/readUMLFile(inputStrings);
System.out.println("\n * * * End of the Document Analysis * * * \n");
}
// ************************************************************
// * *
// * input Method *
// * *
// ************************************************************
public static String[] input() throws Exception
{
String[] inputStrings={"",""}; // Two dimensional string
System.out.print(" Type the Name of the Input File, Then Press Enter:\t");
/*CALL*/inputStrings[0]=readString();
System.out.print(" Type the Name of the First Header, Then Press Enter:\t");
/*CALL*/inputStrings[1]=readString();
return inputStrings;
}
// ************************************************************
// * *
// * readString Method *
// * *
// ************************************************************
public static String readString() throws Exception
{
char tempCh;
String tempSt="";
tempCh = (char)System.in.read();
while((int)tempCh != 13 ) // Enter = 13
{
tempSt = tempSt + tempCh;
tempCh = (char)System.in.read();
}
tempCh = (char)System.in.read(); //Abort the ENTER key
return tempSt;
}
// ************************************************************
// * *
// * readUMLFile Method *
// * *
// ************************************************************
public static void readUMLFile(String[] inputStrings)
{
int indexOfLinkTarget; // "LinkTarger" is a key word for processing
int indexOfFirstHeader;
int counter=1;
boolean startAnalysis=false;
String firstTags=""; // Begining of the INPUT FILE
String lastTags="";
String lineSt="";
/*CALL*/writeUMLFile(firstTags+(char)10);
try // Read the INPUT FILE
{
FileReader inputFileReader = new FileReader(inputStrings[0]); // inputReader is an object and inputStrings[0] is the name of the input file
BufferedReader inputFileBuffer = new BufferedReader(inputFileReader);
while(true) // Until the end of the input file
{
lineSt=inputFileBuffer.readLine(); // Read a line from the input file
// System.out.println(lineSt);
if (lineSt==null) // End of the input file
{
break;
}
indexOfLinkTarget=lineSt.indexOf("LinkTarget");
if(indexOfLinkTarget!=-1) // I found a "LinkTarget"
{
if(startAnalysis!=true)
{
indexOfFirstHeader=lineSt.indexOf(inputStrings[1]);
if(indexOfFirstHeader!=-1) // I found the "First Header" and skipped the "Table of Contents"
{
// System.out.println("\n\n"+counter+")\t"+lineSt);
/*CALL*/ writeUMLFile(counter+"\t"+lineSt+(char)10);
startAnalysis=true;
}
}
else
{
counter ++;
// System.out.println(counter+")\t"+lineSt);
/*CALL*/ writeUMLFile(counter+"\t"+lineSt+(char)10);
}
}
} // End of the WHILE loop (End of the file)
inputFileReader.close();
} // End of the TRY
catch(FileNotFoundException e)
{
System.out.println("Unable to Open INPUT File");
}
catch(IOException e)
{
System.out.println("Unable to Close INPUT File");
}
/*CALL*/writeUMLFile(lastTags);
}
// ************************************************************
// * *
// * headersAnalysis Method *
// * *
// ************************************************************
public static int headersAnalysis(String tempStHeader)
{
int lengthHeader;
int periodCounter=0;
int firstIndex=0, secondIndex=0;
char tempChar=' ';
String firstPartHeader="";
String secondPartHeader="";
String thirdPartHeader="";
lengthHeader=tempStHeader.length();
firstIndex=tempStHeader.indexOf(" "); // Find the first "space" to seperate numbers
for(int i=0;i"+(char)10+""+secondPartHeader+""+(char)10);
}
else if (periodCounter==1)
{
/*CALL*/ writeUMLFile(""+(char)10+""+secondPartHeader+""+(char)10);
}
else // periodCounter==2 like 1.2.3
{
/*CALL*/ writeUMLFile(""+(char)10+""+secondPartHeader+""+
(char)10+""+thirdPartHeader+""+(char)10);
}
return periodCounter;
}
// ************************************************************
// * *
// * writeUMLFile Method *
// * *
// ************************************************************
public static void writeUMLFile(String tempString)
{
boolean x=true; //Each time you add a new string at the end of the FILE
try // Creat a new file
{
FileWriter outputFileWriter = new FileWriter("Document Headers.txt",x);
outputFileWriter.write(tempString);
outputFileWriter.close();
}
catch(FileNotFoundException e)
{
System.out.println("Unable to Open OUTPUT File");
}
catch(IOException e)
{
System.out.println("Unable to close OUTPUT File");
}
}
// ************************************************************
// ************************************************************
// ********************End Of the Program**********************
// ************************************************************
// ************************************************************
}