1 11 package org.eclipse.jdt.internal.ui.javadocexport; 12 13 import java.io.BufferedInputStream ; 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 17 import javax.xml.parsers.DocumentBuilder ; 18 import javax.xml.parsers.DocumentBuilderFactory ; 19 import javax.xml.parsers.ParserConfigurationException ; 20 21 import org.eclipse.core.runtime.Assert; 22 23 import org.w3c.dom.Element ; 24 import org.w3c.dom.Node ; 25 import org.w3c.dom.NodeList ; 26 import org.xml.sax.InputSource ; 27 import org.xml.sax.SAXException ; 28 29 30 33 public class JavadocReader extends Object { 34 35 private InputStream fInputStream; 36 37 41 public JavadocReader(InputStream inputStream) { 42 Assert.isNotNull(inputStream); 43 fInputStream= new BufferedInputStream (inputStream); 44 } 45 46 52 public void close() throws IOException { 53 if (fInputStream != null) 54 fInputStream.close(); 55 } 56 57 public Element readXML() throws IOException , SAXException { 58 59 DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); 60 factory.setValidating(false); 61 DocumentBuilder parser= null; 62 try { 63 parser= factory.newDocumentBuilder(); 64 } catch (ParserConfigurationException ex) { 65 throw new IOException (ex.getMessage()); 66 } finally { 67 } 69 70 Element xmlJavadocDesc= parser.parse(new InputSource (fInputStream)).getDocumentElement(); 72 73 NodeList targets= xmlJavadocDesc.getChildNodes(); 74 75 for (int i= 0; i < targets.getLength(); i++) { 76 Node target= targets.item(i); 77 78 if (target.getNodeName().equals("target")) { NodeList children= target.getChildNodes(); 81 for (int j= 0; j < children.getLength(); j++) { 82 Node child= children.item(j); 83 if (child.getNodeName().equals("javadoc") && (child.getNodeType() == Node.ELEMENT_NODE)) { return (Element ) child; 85 } 86 } 87 } 88 89 } 90 return null; 91 } 92 93 } 94 | Popular Tags |