1 /* gnu.classpath.tools.doclets.htmldoclet.ExternalDocSet
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 package gnu.classpath.tools.doclets.htmldoclet;
23 import java.io.BufferedReader;
25 import java.io.FileNotFoundException;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.io.InputStreamReader;
30 import java.net.MalformedURLException;
33 import java.util.HashSet;
34 import java.util.Properties;
37 import com.sun.javadoc.ClassDoc;
39 public class ExternalDocSet
42 private String packageListDir;
43 private URL docSetDirectoryURL;
45 public String getPackageListDir()
47 return packageListDir;
50 public ExternalDocSet(String url,
51 String packageListDir)
54 this.packageListDir = packageListDir;
57 private Set packageNames = new HashSet();
58 private boolean javadocCompatible;
60 public void load(File targetDirectory)
61 throws IOException, MalformedURLException
63 if (!url.endsWith("/")) {
67 this.docSetDirectoryURL = new URL(targetDirectory.toURL(),
70 URL packageListDirURL;
71 if (null != packageListDir) {
72 if (!packageListDir.endsWith("/")) {
73 packageListDir += "/";
75 packageListDirURL = new URL(new File(System.getProperty("user.dir")).toURL(),
79 packageListDirURL = docSetDirectoryURL;
82 URL packageListURL = new URL(packageListDirURL,
84 InputStream in = packageListURL.openStream();
90 throw new FileNotFoundException(packageListURL.toString());
93 URL gjdocPropertiesURL = new URL(packageListDirURL,
96 InputStream propertiesIn = gjdocPropertiesURL.openStream();
98 Properties properties = new Properties();
99 properties.load(propertiesIn);
100 propertiesIn.close();
102 String gjdocCompatProperty = properties.getProperty("gjdoc.compat");
103 if (null != gjdocCompatProperty) {
104 javadocCompatible = "true".equals(properties.getProperty("gjdoc.compat"));
107 javadocCompatible = true;
111 javadocCompatible = true;
114 catch (FileNotFoundException e) {
115 javadocCompatible = true;
119 public String getPackageDocURL(String packageName)
122 URL packageURL = new URL(docSetDirectoryURL,
123 packageName.replace('.', '/'));
124 return packageURL.toString();
126 catch (MalformedURLException e) {
127 // This should not happen since we know that packageName is a
128 // proper Java identifiers, so the resulting URL can't be
130 throw new RuntimeException(e);
134 public String getClassDocURL(String packageName, String typeName)
137 URL fileURL = new URL(docSetDirectoryURL,
138 packageName.replace('.', '/') + "/" + typeName + ".html");
139 return fileURL.toString();
141 catch (MalformedURLException e) {
142 // This should not happen since we know that packageName and
143 // typeName are proper Java identifiers, so the resulting URL
145 throw new RuntimeException(e);
149 protected void readPackages(InputStream in)
152 BufferedReader reader
153 = new BufferedReader(new InputStreamReader(in, "UTF-8"));
155 while ((line = reader.readLine()) != null) {
157 packageNames.add(line);
161 public Set getPackageNames()
166 public boolean isJavadocCompatible()
168 return javadocCompatible;