head 1.10; access; symbols; locks; strict; comment @# @; 1.10 date 2001.05.14.04.59.57; author linus; state Exp; branches; next 1.9; 1.9 date 2001.05.11.18.51.15; author linus; state Exp; branches; next 1.8; 1.8 date 2001.05.08.19.25.14; author linus; state Exp; branches; next 1.7; 1.7 date 2001.05.08.19.06.44; author linus; state Exp; branches; next 1.6; 1.6 date 2001.05.08.15.07.07; author linus; state Exp; branches; next 1.5; 1.5 date 2001.05.07.02.50.34; author linus; state Exp; branches; next 1.4; 1.4 date 2001.05.06.01.56.53; author linus; state Exp; branches; next 1.3; 1.3 date 2001.05.03.16.14.41; author linus; state Exp; branches; next 1.2; 1.2 date 2001.05.03.06.42.54; author linus; state Exp; branches; next 1.1; 1.1 date 2001.05.02.23.54.04; author linus; state Exp; branches; next ; desc @reads the file ok @ 1.10 log @add getDown @ text @import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; import java.io.FileWriter; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.DocumentBuilder; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.w3c.dom.Document; import org.apache.xerces.dom.DocumentImpl; import org.w3c.dom.DOMException; /** * manage the status xml doc * methods are: * load( path_to_input_file ) * exists( String map, String hostname ) returns index or -1 * add( map, host, badlist, state, paged, since ) * update( map, host, badlist, state, paged ) * delete( map, host ) * save( path_to_output_xml_file ) * getPage( index ) * getState( index ) * getDown( index ) */ public class status { protected int statusnum = 0; protected ArrayList statusmap = new ArrayList(); protected ArrayList statusname = new ArrayList(); protected ArrayList statuslabel = new ArrayList(); protected ArrayList statusdown = new ArrayList(); protected ArrayList statusstate = new ArrayList(); protected ArrayList statussince = new ArrayList(); protected ArrayList statuspage = new ArrayList(); //---------- // getDataFromNode of type 3 and not empty //---------- String getDataFromNode( org.w3c.dom.Node nod ) { org.w3c.dom.NodeList nodes = nod.getChildNodes(); for ( int i=0; i< nodes.getLength(); i++ ) { org.w3c.dom.Node node = nodes.item(i); int type = node.getNodeType(); String val = node.getNodeValue(); String name = node.getNodeName(); if ( type == 3 ) { if ( val != null ) { return( val ); } } } return( null ); } //---------- // getDataFromNode type 3 whose type 1 parents match str //---------- String getDataFromNode( org.w3c.dom.Node nod, String str ) { org.w3c.dom.NodeList nodes = nod.getChildNodes(); for ( int i=0; i< nodes.getLength(); i++ ) { org.w3c.dom.Node node = nodes.item(i); int type = node.getNodeType(); String val = node.getNodeValue(); String name = node.getNodeName(); // System.out.println( "type: " + type + " nodename: " + name + " value: " + val ); if ( type == 1 && name != null ) { if ( name.equals( str )) { if ( node.hasChildNodes() ) { org.w3c.dom.NodeList nads = node.getChildNodes(); for ( int j = 0; j < nads.getLength(); j++ ) { node = nads.item(j); type = node.getNodeType(); val = node.getNodeValue(); name = node.getNodeName(); if ( type == 3 && val != null ) { return( val ); } } } } } } return( null ); } //---------- // recurseNodes //---------- void recurseNodes( org.w3c.dom.NodeList nodes ) throws IOException { for (int i=0; i= 0 ) // update { statusmap.set( x, map ); statusname.set( x, host ); statuslabel.set( x, label ); statusdown.set( x, badlist ); statusstate.set( x, state ); // no since statuspage.set( x, paged ); } return( x ); } //---------- // add status entry of map host badlist status since paged //---------- void add( String map, String host, String label, String badlist, String state, String paged, String since ) { statusmap.add( map ); statusname.add( host ); statuslabel.add( label ); statusdown.add( badlist ); statusstate.add( state ); statussince.add( since ); statuspage.add( paged ); statusnum++; // System.out.println( "add map:" + map + " host:" + host + " label:" + label + " badlist:" + badlist + " state:" + state + " paged:" + paged + " since:" + since + " #:" + statusnum ); } //---------- // listToTags dump arraylists into doc form //---------- void save( String fname ) { Document doc; org.w3c.dom.Element root = null; org.w3c.dom.Element item = null; org.w3c.dom.Element kid = null; doc = new DocumentImpl(); root = doc.createElement( "status" ); for ( int i = 0; i < statusnum; i++ ) { String smap = (String)statusmap.get( i ); String sname = (String)statusname.get( i ); String slabel = (String)statuslabel.get( i ); String sdown = (String)statusdown.get( i ); String sstate = (String)statusstate.get( i ); String ssince = (String)statussince.get( i ); String spage = (String)statuspage.get( i ); //dump empty entries if ( smap.length() > 0 && sname.length() > 0 && sdown.length() > 0 && sstate.length() > 0 && ssince.length() > 0 && spage.length() > 0 && slabel.length() > 0 ) { kid = doc.createElement( "system" ); item = doc.createElement( "mapname" ); item.appendChild( doc.createTextNode( smap )); kid.appendChild (item); item = doc.createElement ("hostname"); item.appendChild( doc.createTextNode( sname )); kid.appendChild( item ); item = doc.createElement ("label"); item.appendChild( doc.createTextNode( slabel )); kid.appendChild( item ); item = doc.createElement( "down" ); item.appendChild( doc.createTextNode( sdown )); kid.appendChild( item ); item = doc.createElement( "state" ); item.appendChild( doc.createTextNode( sstate )); kid.appendChild( item ); item = doc.createElement( "since" ); item.appendChild( doc.createTextNode( ssince )); kid.appendChild( item ); item = doc.createElement( "page" ); item.appendChild( doc.createTextNode( spage )); kid.appendChild( item ); root.appendChild( kid ); } } int level = 0; try { FileWriter xFile = new FileWriter( fname ); PrintWriter newFile = new PrintWriter( xFile ); printTree( root, newFile, level ); newFile.close(); } catch (IOException ioe) { // I/O error ioe.printStackTrace(); return; } } // ------------------ // print a tree in xml code by calling printBranches on every type 1 node // ------------------ void printTree( org.w3c.dom.Node rootNode, PrintWriter Out, int level ) { int type = rootNode.getNodeType(); String name = rootNode.getNodeName(); Out.println(""); if ( type == 1 ) Out.println("<" + name + ">"); printBranches( rootNode, Out, level ); if ( type == 1 ) Out.println(""); } // ------------------ // print a branch in xml code // ------------------ void printBranches( org.w3c.dom.Node rootNode, PrintWriter Out, int level ) { int j; org.w3c.dom.NodeList nodes = rootNode.getChildNodes(); for (int i=0; i"); } if ( type == 3 ) { String s = node.getNodeValue(); if ( s.trim().compareTo( "" ) != 0 ) { Out.print( s ); } } if ( node.hasChildNodes() ) { printBranches( node, Out, level + 1 ); } if ( type == 1 ) { Out.println(""); } } } // eo printTree //---------- } // eoclass //---------- @ 1.9 log @rm msglog @ text @d29 1 d200 9 @ 1.8 log @rem debug @ text @a16 1 import msglog; a41 1 msglog mlog = new msglog(); d164 1 a164 1 mlog.write( "\n** Parsing error" d167 1 a167 1 mlog.write(" " + spe.getMessage() ); @ 1.7 log @add label support @ text @a315 1 System.out.println( "Slabel: " + slabel ); @ 1.6 log @fix @ text @d37 1 d125 1 d250 1 d263 1 a263 1 int update( String map, String host, String badlist, String state, String paged ) d270 1 d281 1 a281 1 void add( String map, String host, String badlist, String state, String paged, String since ) d285 1 d291 1 d311 1 d316 1 d319 2 a320 1 sstate.length() > 0 && ssince.length() > 0 && spage.length() > 0 ) d328 3 @ 1.5 log @fix @ text @d27 1 a27 1 * write( path_to_output_xml_file ) d204 1 a204 1 String getstate( int index ) d210 1 a210 1 // getpage index d213 1 a213 1 String getpage( int index ) @ 1.4 log @works @ text @d43 3 a45 1 d67 4 a70 1 String getDataFromNode( org.w3c.dom.Node nod, String str ) d106 3 a156 1 // mlog.write("Root element is " + doc.getDocumentElement().getNodeName() + " "); @ 1.3 log @wrong tag name in save() @ text @d34 1 a34 1 protected int statusnum; d140 1 a140 1 DocumentBuilder builder = factory.newDocumentBuilder(); d142 11 a152 7 FileInputStream fs = new FileInputStream( f ); doc = builder.parse( fs ); doc.getDocumentElement().normalize(); // mlog.write("Root element is " + doc.getDocumentElement().getNodeName() + " "); org.w3c.dom.NodeList nodeList = doc.getChildNodes(); recurseNodes( nodeList ); d217 1 d220 4 a223 1 if ( !map.equals((String)statusmap.get( i ) )&& !host.equals((String)statusname.get( i )) ) d225 1 d309 2 a310 2 kid.appendChild( item ); item = doc.createElement( "hostname" ); @ 1.2 log @works!! @ text @d298 1 a298 1 item = doc.createElement( "map" ); d301 1 a301 1 item = doc.createElement( "name" ); @ 1.1 log @Initial revision @ text @d2 4 a6 2 import java.io.PrintStream; import java.io.FileInputStream; d15 1 d20 10 a29 1 * read the status xml doc in and pick out the necessary bits of info d38 2 a39 1 protected ArrayList statusstat = new ArrayList(); d116 3 a118 2 statusdown.add( getDataFromNode( node, "down" )); statusstat.add( getDataFromNode( node, "stats" )); d131 4 a134 1 void status() d141 1 a141 1 File f = new File( "../tmp/status.xml" ); d146 1 a146 1 mlog.write("Root element is " + doc.getDocumentElement().getNodeName() + " "); d189 200 a388 1 } @