X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;ds=sidebyside;f=case-study%2Fjdt-after%2Fui%2Forg%2Feclipse%2Fjdt%2Finternal%2Fui%2Fjavadocexport%2FJavadocReader.java;fp=case-study%2Fjdt-after%2Fui%2Forg%2Feclipse%2Fjdt%2Finternal%2Fui%2Fjavadocexport%2FJavadocReader.java;h=6b697d706d21b4128ba8c189025e677967d8bc6f;hb=1b2798f607d741df30e5197f427381cbff326adc;hp=0000000000000000000000000000000000000000;hpb=246231e4bd9b24345490f369747c0549ca308c4d;p=ifi-stolz-refaktor.git diff --git a/case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/javadocexport/JavadocReader.java b/case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/javadocexport/JavadocReader.java new file mode 100644 index 00000000..6b697d70 --- /dev/null +++ b/case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/javadocexport/JavadocReader.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.ui.javadocexport; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.eclipse.core.runtime.Assert; + + +/** + * Reads data from an InputStream and returns a JarPackage + */ +public class JavadocReader extends Object { + + private InputStream fInputStream; + + /** + * Reads a Javadoc Ant Script from the underlying stream. It is the client's responsibility to + * close the stream. + * + * @param inputStream the input stream to read from + */ + public JavadocReader(InputStream inputStream) { + Assert.isNotNull(inputStream); + fInputStream= new BufferedInputStream(inputStream); + } + + /** + * Closes this stream. It is the clients responsibility to close the stream. + * + * @exception IOException if the stream cannot be closed + */ + public void close() throws IOException { + if (fInputStream != null) + fInputStream.close(); + } + + public Element readXML() throws IOException, SAXException { + + DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); + factory.setValidating(false); + DocumentBuilder parser= null; + try { + parser= factory.newDocumentBuilder(); + } catch (ParserConfigurationException ex) { + throw new IOException(ex.getMessage()); + } finally { + // Note: Above code is OK since clients are responsible to close the stream + } + + //find the project associated with the ant script + parser.setErrorHandler(new DefaultHandler()); + Element xmlJavadocDesc= parser.parse(new InputSource(fInputStream)).getDocumentElement(); + + NodeList targets= xmlJavadocDesc.getChildNodes(); + + for (int i= 0; i < targets.getLength(); i++) { + Node target= targets.item(i); + + //look through the XML file for the javadoc task + if (target.getNodeName().equals("target")) { //$NON-NLS-1$ + NodeList children= target.getChildNodes(); + for (int j= 0; j < children.getLength(); j++) { + Node child= children.item(j); + if (child.getNodeName().equals("javadoc") && (child.getNodeType() == Node.ELEMENT_NODE)) { //$NON-NLS-1$ + return (Element) child; + } + } + } + + } + return null; + } + +}