1 9 10 package org.dom4j.samples.applets; 11 12 import java.applet.Applet ; 13 import java.awt.Graphics ; 14 15 import org.dom4j.Document; 16 import org.dom4j.DocumentException; 17 import org.dom4j.DocumentHelper; 18 import org.dom4j.io.OutputFormat; 19 import org.dom4j.io.XMLWriter; 20 21 28 public class SimpleAppletDemo extends Applet { 29 30 private static String DEMO_XML = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" 31 + "<web-app>\n" 32 + "<servlet>\n" 33 + "<servlet-name>snoop</servlet-name>\n" 34 + "<servlet-class>SnoopServlet</servlet-class>\n" 35 + "</servlet>\n" 36 + "</web-app>"; 37 38 private Document demoDocument; 39 40 private StringBuffer buffer; 41 42 45 public void start() { 46 try { 47 demoDocument = DocumentHelper.parseText(DEMO_XML); 48 new XMLWriter(OutputFormat.createPrettyPrint()).write(demoDocument); 49 } catch (DocumentException documentEx) { 50 documentEx.printStackTrace(); 51 } catch (Exception ex) { 52 ex.printStackTrace(); 53 } 54 55 demoXPath(); 56 repaint(); 57 } 58 59 62 private void demoXPath() { 63 this.buffer = new StringBuffer ("The name of the servlet is :"); 64 this.buffer.append(demoDocument 65 .valueOf("/web-app/servlet[1]/servlet-name")); 66 this.buffer.append(" and the class is "); 67 this.buffer.append(demoDocument 68 .valueOf("/web-app/servlet[1]/servlet-class")); 69 } 70 71 74 public void paint(Graphics g) { 75 g.drawRect(0, 0, getSize().width - 1, getSize().height - 1); 76 g.drawString(this.buffer.toString(), 5, 15); 77 } 78 79 } 80 81 119 120 | Popular Tags |