import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import java.util.*; import java.io.*; public class Frame1 extends JFrame { // variable declaration ArrayList vxml = new ArrayList(); // used to strore the xml content ArrayList vXMLRule = new ArrayList(); // used to store the rule after the xml content ArrayList position = new ArrayList(); // this will depreciate the previous approach JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JFileChooser source = new JFileChooser(); JFileChooser destination = new JFileChooser() ; JButton cmdConvert = new JButton(); JButton cmdClose = new JButton(); Border border1; TitledBorder titledBorder1; Border border2; //Construct the frame public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { border1 = BorderFactory.createLineBorder(SystemColor.controlText,1); titledBorder1 = new TitledBorder(""); border2 = BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.white,Color.white,new java.awt.Color(134, 134, 134),new java.awt.Color(93, 93, 93)); jLabel1.setFont(new java.awt.Font("Dialog", 0, 14)); jLabel1.setText("Source"); jLabel1.setBounds(new Rectangle(186, 86, 60, 17)); this.getContentPane().setLayout(null); this.getContentPane().setBackground(SystemColor.scrollbar); this.setSize(new Dimension(1058, 712)); this.setTitle("Converter"); jLabel2.setFont(new java.awt.Font("Dialog", 0, 14)); jLabel2.setText("Destination"); jLabel2.setBounds(new Rectangle(774, 81, 79, 17)); source.setBorder(border1); source.setBounds(new Rectangle(30, 117, 403, 279)); destination.setBorder(border1); destination.setDialogType(1); destination.setBounds(new Rectangle(594, 117, 414, 278)); cmdConvert.setBorder(border1); cmdConvert.setText("Convert"); cmdConvert.setBounds(new Rectangle(340, 528, 140, 46)); cmdConvert.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { cmdConvert_actionPerformed(e); } }); cmdClose.setBorder(border1); cmdClose.setMaximumSize(new Dimension(77, 27)); cmdClose.setMinimumSize(new Dimension(77, 27)); cmdClose.setPreferredSize(new Dimension(77, 27)); cmdClose.setText("Close"); cmdClose.setBounds(new Rectangle(481, 528, 140, 46)); cmdClose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { cmdClose_actionPerformed(e); } }); this.getContentPane().add(destination, null); this.getContentPane().add(jLabel1, null); this.getContentPane().add(jLabel2, null); this.getContentPane().add(source, null); this.getContentPane().add(cmdClose, null); this.getContentPane().add(cmdConvert, null); } //Overridden so we can exit on System Close protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if(e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void cmdClose_actionPerformed(ActionEvent e) { dispose(); System.exit(0); } // heart of this whole program void cmdConvert_actionPerformed(ActionEvent e) { BufferedReader in = null; File inFile; File outFile; // JOptionPane.showMessageDialog (this,source.getSelectedFile ()); // JOptionPane.showMessageDialog (this,destination.getSelectedFile ()); if(((inFile= source.getSelectedFile ()) == null) || ((outFile=destination.getSelectedFile ()) == null)) { JOptionPane.showMessageDialog (this," you need to specify the source and destination files"); return; } JOptionPane.showMessageDialog (this," specifed the source and destination files"); String line; try { int loc = -1; // used to determine the begining location of the xml tag int end = -1; // used to determine the ending location of the xml tag String xmlString; boolean xmlFound = false; boolean actionflag = false; boolean addflag = false; int indexPosition = 0; in = new BufferedReader(new InputStreamReader(new FileInputStream(new File(inFile.getPath ())))); while((line= in.readLine()) != null) { line = line.trim (); xmlFound = false; while( (loc = findString(line,"xml",loc+1)) != -1) { xmlFound = true; if ((end = findCharacter(line,loc)) == -1) System.out.println("error in the string "); else { xmlString = line.substring (loc+1, end); if((indexPosition = isExisting(xmlString)) == -1) { if ( vxml.add (xmlString) == false) System.out.println(" Error : unable to add xmlContent into ArrayList "); else { position.add (new Integer(vxml.size ()-1)); } } else { position.add ( new Integer(indexPosition)); } } } // end of xml content occured if (actionStart(line) == true) actionflag = true; // if (actionflag == true) { if (findString(line,"goto",0) == -1 ) if(addflag == false) addflag = true; // if(actionEnd(line) == true) { // actionflag = false; // } // } if (addflag == true) { line = addToAction(line); addflag = false; } if (xmlFound == false) { vXMLRule.add (line); } else { vXMLRule.add (modifyLine(line)); } }// end of file occured } catch (FileNotFoundException fnfe) { JOptionPane.showMessageDialog (null,"File Does Not Exist"); } catch (IOException ioe) { JOptionPane.showMessageDialog (null," IOException raised"); } writeToFile(outFile.getPath ()); } // returns the location of string s2 in string s1 from a specified location int findString(String s1,String s2, int loc) { s1 = s1.trim ().toLowerCase (); s2 = s2.trim ().toLowerCase (); if(s1.length () < s2.length ()) return -1; for(int index1 = loc, index2 = 0; index1 < s1.length (); index1++ ) { if(s1.charAt (index1) == s2.charAt (index2)) { index2++; if ( index2 == s2.length ()) { return (index1+1); } } else index2=0; } return -1; // indicates character not found } String addToAction(String s) { String p=""; for(int index =0; index < s.length (); index++) { if (s.charAt (index) == '}'){ index -- ; if(index > 0) p = s.substring (0,index); s = p.concat ("return ; }"); return s; } } return s; } boolean actionStart(String s) { for(int index =0; index < s.length (); index++) { switch (s.charAt (index)){ case '{' : return true; // There is no break as return will cause control to go from function } } return false; // indicates character not found } boolean actionEnd(String s) { for(int index =0; index < s.length (); index++) { switch (s.charAt (index)){ case '}' : return true; // There is no break as return will cause control to go from function } } return false; // indicates character not found } // returns the location of the character from a string, from a specified location int findCharacter(String s, int loc) { for(int index =loc; index < s.length (); index++) { switch (s.charAt (index)){ case '<' : case '>' : case '=' : case '!' : case ',' : return index; // There is no break as return will cause control to go from function } } return -1; // indicates character not found } // converts xmltags to appropriate format needed String modifyLine(String s) { String term=""; int end = 0; int start = 0; int index=0; int pos=0; for(index=0, start=0,end=0; index"); //print xmlTagSequence pointer out.println (" char *xmlTagSequence[] = {"); // print the xml tags for(index=0; (index+1) < vxml.size (); index++) out.println("\"" + (String) vxml.get (index) + ".\" ,"); out.println("\"" + (String) vxml.get (index) + ".\""); out.println ("}"); // print the noofxmlTagSequences out.println ("static int noOfxmlTagSequences = " + vxml.size ()+";"); // print the char [] for xmltagsequences out.println ("char *xmlTagValue[" +vxml.size () + "];"); // print the function rulematch out.println ("int ruleConfigure( __u32 saddr, __u32 daddr, __u16 sport, __u16 dport, __u8protocol) {"); // print the rules for(index =0; index 0 || s.compareToIgnoreCase ("match") > 0) return true; return false; } /* // display the contents of the ArrayList vxml void showVXML( ArrayList v) { String s; System.out.println (" The contents of the vector are "); for(int index =0; index < v.size (); index++){ s = (String) v.get (index); System.out.println ("index " + index + " value " + s); } } // display the contents of the ArrayList vXMLRule void showRule( ArrayList v) { String s; System.out.println (" The contents of the vector are "); for(int index =0; index < v.size (); index++){ s = (String) v.get (index); System.out.println ( s); } } */ int isExisting(String s){ String p; s=s.trim (); for(int index =0; index < vxml.size (); index++){ p = (String) vxml.get (index); if (p.equalsIgnoreCase (s)) return index; } return -1; } }// end of class