<%@page import="kap.web.UserBean, kap.web.Info, java.io.File, java.io.IOException, javax.xml.parsers.DocumentBuilder, javax.xml.parsers.DocumentBuilderFactory, javax.xml.parsers.FactoryConfigurationError, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, org.xml.sax.SAXParseException, org.w3c.dom.Document, org.w3c.dom.Element, org.w3c.dom.Node, org.w3c.dom.NodeList, org.w3c.dom.NamedNodeMap, org.w3c.dom.DOMException" %> <%! // Declare some methods so we can use recursion //********************************************************// // add indentation, always adds -- marks public String indent ( int level ) { return ( indent ( level, true ) ); } // END public String indent ( int level ) //********************************************************// // add indentation with option -- marks public String indent ( int level, boolean last ) { StringBuffer indent = new StringBuffer(); for ( int i = 0; i < level; i++ ) { // if this is the last make it a - if ( i == level - 1 && last ) { indent.append ( "|--" ); } // end if last level else { indent.append ( "| " ); } // end else not last level } // end for each level return ( indent.toString() ); } // END public void indent ( int level ) //********************************************************// // print node at a certain level public String printNode ( Node node, int level ) { StringBuffer printedNode = new StringBuffer ( "" ); // if not level 0 pint blank line and indent if ( level > 0 ) { printedNode.append ( indent ( level, false ) + "
" ); printedNode.append ( indent ( level ) ); } // end if level not 0 // add node name printedNode.append ( node.getNodeName() + ":" ); // if attributes add them if ( node.hasAttributes() ) { NamedNodeMap attributes = node.getAttributes(); if ( attributes.getLength() > 0 ) { level++; for ( int i = 0; i < attributes.getLength(); i++ ) { Node attribute = attributes.item ( i ); printedNode.append ( indent ( level ) ); printedNode.append ( "." + attribute.getNodeName() + "=" + attribute.getNodeValue() ); } // end for each attribute level--; } // end if more than 0 attributes } // end if node has attributes // get node value String value = node.getNodeValue(); value = ( value == null ? "" : value.trim() ); // if node value not empty add it if ( value.length() > 0 ) { printedNode.append ( "node has value
" + indent ( level, false ) ); printedNode.append ( value ); } // end if value not empty // if node has children, add them if ( node.hasChildNodes() ) { level++; NodeList children = node.getChildNodes(); for ( int i = 0; i < children.getLength(); i++ ) { Node child = children.item ( i ); printedNode.append ( "
" + printNode ( child, level ) ); } // end for each child } // end if node has children return ( printedNode.toString() ); } // END public String printNode ( Node node, int level ) //********************************************************// // Convenient value getting method public String getValue ( Element element, String tagName ) { NodeList nodeList = element.getElementsByTagName ( tagName ); Node node = nodeList.item ( 0 ).getFirstChild(); // make sure value is not null if ( node.getNodeValue() == null ) { return ( "" ); } // end if value null // otherwise trim weird characters and send it on home return ( node.getNodeValue().trim() ); } // END public String getValue ( Node node, String tagName ) //********************************************************// %> <%-- END JSP DECLARATION --%>