import java.io.*; //import java.lang.Object; public class ExtractingHeaders { // ************************************************************ // * * // * main Method * // * * // ************************************************************ public static void main(String[] args) throws Exception { System.out.println("\n\n******* UML Specification Analysis *******\n\n\n"); String f_Name = "UMLChap7-pdf Acrobat-htm Stylus-xml.xml"; // Name of the INPUT FILE int inputArray[] = new int [10]; // inputArray = inputValues(); // System.out.println("InputArray = "+inputArray[0]+"\n\n\n"); readUMLFile(f_Name,inputArray[0]); } // ************************************************************ // * * // * inputValues Method * // * * // ************************************************************ public static int[] inputValues() throws Exception { int[] inputArray = new int [10]; char chTemp; String stTemp=""; System.out.print(" Input the Number of Characters, Then Press ENTER:\t"); chTemp = (char)System.in.read(); while((int)chTemp != 13 ) // Enter = 13 { stTemp = stTemp + chTemp; chTemp = (char)System.in.read(); } chTemp = (char)System.in.read(); //Abort the ENTER key System.out.print("\n"); inputArray[0] = Integer.parseInt(stTemp); //Convert string to the integer return inputArray; } // ************************************************************ // * * // * readUMLFile Method * // * * // ************************************************************ public static void readUMLFile(String f_Name,int numChar) { int fileChar; // File characters int stackPointer=0; boolean flagSpaceChar=false; String st=""; // Begining of the INPUT FILE String tempStDiv="",tempStHeader=""; String [][]tempStack = new String [100][100]; // Vector Ve = new Vector(); writeUMLFile(st); try // Read the INPUT FILE { FileReader inputReader = new FileReader(f_Name); // inputReader is an object fileChar=inputReader.read(); while(fileChar!=-1) // It is not end of the FILE { if(fileChar==60) // 60 = "<" { // System.out.println("<"); I found "<" for(int i=0;i<3;i++) { fileChar=inputReader.read(); tempStDiv=tempStDiv+(char)fileChar; } // System.out.println(tempSt); // 3 Characters if(tempStDiv.equals("div")) { while(true) { fileChar=inputReader.read(); if (fileChar==62) // 62 = ">" { fileChar=inputReader.read(); if(fileChar >= 49 && fileChar <= 57) // 1 .. 9 { do { // System.out.println("------->"+fileChar); if(fileChar!=13 && fileChar!=10 && fileChar!=555) // Next line "\n" and "\r" { tempStHeader=tempStHeader+(char)fileChar; if(fileChar==32) // 32 = Space { flagSpaceChar=true; // I saw the first SPACE } } fileChar=inputReader.read(); if(flagSpaceChar==true && fileChar==32) //I saw the second SPACE { fileChar=555; // To skip IF in the DO loop // Syst em.out.println("Second Space: "+fileChar); }else // (flagSpaceChar == False || fileChar!=32) if(flagSpaceChar==true) // Just one SPACE or last SPACE { flagSpaceChar=false; // System.out.println("Last Space: "+fileChar); } }while(fileChar!=60); // 60 = "<" // tempStack[0] = {+tempStHeader}; // stackPointer++; // System.out.println(tempStack[0]); System.out.println(tempStHeader); tempStHeader=""; break; } // End of the IF ("1 .. 9") } // End of the IF ("62") } // End of the WHILE(true) // System.out.println("I found DIV"); } // End of the IF ("div") tempStDiv=""; } // End of the IF ("<") fileChar = inputReader.read(); } // End of the WHILE loop (End of the file) inputReader.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"); } } // ************************************************************ // * * // * 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 outputWriter = new FileWriter("Improved UML.xml",x); outputWriter.write(tempString); outputWriter.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********************** // ************************************************************ // ************************************************************ }