import java.io.*; public class ThesisIIV2 { // ************************************************************ // * * // * 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*/writeUMLFile(""+(char)10); /*CALL*/readUMLFile(inputStrings); /*CALL*/writeUMLFile(""+(char)10); 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, for example 'UML.xml', and then Press Enter:\t"); /*CALL*/inputStrings[0]=readString(); System.out.print(" Type the Name of the Starting Chapter, for example '1 Scope', and 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 indexOfBeginingOfHeaders; int indexOfEndOfHeaders; boolean startAnalysis=false; String lineSt=""; String tempStHeaders=""; // inputStrings[0] is the name of the input file, e.g.: UML.xml // inputStrings[1] is the first header where we like to start the processing, e.g.: 1 Scope try // Read the INPUT FILE { FileReader inputFileReader = new FileReader(inputStrings[0]); // inputReader is an object 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); /* END-1 */ if(lineSt==null) // End of the input file { break; } indexOfLinkTarget=lineSt.indexOf("LinkTarget"); if(indexOfLinkTarget!=-1) // I found a line which has the "LinkTarget" string { if(startAnalysis!=true) // It will ignore all lines which have the "LinkTarget" // until it reaches a line which has both // "LinkTarget" and "First Header, e.g.: 1 Scope" // because we would like to jump from the: // "bookmark tree", "table of contents" and "many of the first chapters" { indexOfFirstHeader=lineSt.indexOf(inputStrings[1]); if(indexOfFirstHeader!=-1) // I found the first header, e.g.: "1 Scope" { startAnalysis=true; // System.out.println("\n\n"+lineSt); System.out.println("\n"+inputStrings[1]); headersAnalysis(inputStrings[1]); } } else // startAnalysis is TRUE: I already started the processing { indexOfLinkTarget=indexOfLinkTarget+10;// Because length of "LinkTarget" is 10 indexOfBeginingOfHeaders=lineSt.indexOf(">",indexOfLinkTarget); indexOfEndOfHeaders=lineSt.indexOf("<",indexOfBeginingOfHeaders); indexOfBeginingOfHeaders ++; indexOfEndOfHeaders --; tempStHeaders=lineSt.substring(indexOfBeginingOfHeaders,indexOfEndOfHeaders); /* END-2 */ if(tempStHeaders.compareTo("Index")==0) // End of the processing { break; } // System.out.println("\n"+lineSt); System.out.println("\n"+tempStHeaders); headersAnalysis(tempStHeaders); } } else // I found a regular line which has NOT the "LinkTarget" string // Therefore, I would like to do some cleaning on the XML file // by removing some useless lines/tags { if(startAnalysis==true && lineSt.compareTo("")!=0 && lineSt.compareTo("")!=0 && lineSt.compareTo("")!=0 && lineSt.compareTo("")!=0 && lineSt.compareTo("
")!=0 && lineSt.compareTo("
")!=0 && lineSt.compareTo("")!=0 && lineSt.compareTo("")!=0 && lineSt.compareTo("

UML Superstructure Specification, v2.0

")!=0) { // System.out.println(lineSt); writeUMLFile(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 tempInt=headersAnalysis(tempStHeader); tempStack[stackPointer]=tempInt; stackPointer++; tempStHeader=""; break; // Exit from WHILE(true) } // End of the IF ("1 .. 9") } // End of the IF ("62") } // End of the WHILE(true) }else // End of the IF ("div ") if(tempStDiv.equals("/Sec")) { stackPointer --; if(tempStack[stackPointer]==0) { /*CALL writeUMLFile(""+(char)10); } else if (tempStack[stackPointer]==1) { /*CALL writeUMLFile(""+(char)10); } else // periodCounter==2 like 1.2.3 { /*CALL writeUMLFile(""+(char)10); } } // // End of the IF ("/div") tempStDiv=""; } // End of the IF ("<") fileChar = inputReader.read();*/ // if(periodCounter==0) // { ///*CALL*/ writeUMLFile(""+(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); // } // ************************************************************ // * * // * headersAnalysis Method * // * * // ************************************************************ public static String headersAnalysis(String tempStHeader) { int headerType; int lengthHeader; int periodCounter=0; int firstIndex=0, secondIndex=0; char tempChar=' '; boolean type234=false; String firstPartHeader=""; String secondPartHeader=""; String thirdPartHeader=""; String finalHeader=""; // [Type/firstPart/secondPart/thirdPart/] // Type# Sample Heading Type // ------------------------------------------------------------ // 1 [Part] [I] [Structure] Part // 2 [7] [Classes] Chapter // 3 [7.3] [Class Descriptions] Section // 4 [7.3.1] [Abstraction] (from [Dependencies]) Subsection // 5 [Generalization], etc Keyword // 6 [Annex] [A] [Diagrams] End part // 7 [Index] Last Part : Cancelled // ------------------------------------------------------------ lengthHeader=tempStHeader.length(); firstIndex=tempStHeader.indexOf(" "); // Find the first "space" to seperate numbers // System.out.println(firstIndex); for(int i=0;i