OSDN Git Service

libjava/ChangeLog:
[pf3gnuchains/gcc-fork.git] / libjava / classpath / tools / gnu / classpath / tools / doclets / htmldoclet / ExternalDocSet.java
1 /* gnu.classpath.tools.doclets.htmldoclet.ExternalDocSet
2    Copyright (C) 2004 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
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)
9 any later version.
10  
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.
15
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
19 02111-1307 USA. */
20
21 package gnu.classpath.tools.doclets.htmldoclet;
22
23 import java.io.BufferedReader;
24 import java.io.File;
25 import java.io.FileNotFoundException;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.io.InputStreamReader;
29
30 import java.net.MalformedURLException;
31 import java.net.URL;
32
33 import java.util.HashSet;
34 import java.util.Properties;
35 import java.util.Set;
36
37 import com.sun.javadoc.ClassDoc;
38
39 public class ExternalDocSet
40 {
41    private String url;
42    private String packageListDir;
43    private URL docSetDirectoryURL;
44
45    public String getPackageListDir()
46    {
47       return packageListDir;
48    }
49
50    public ExternalDocSet(String url,
51                          String packageListDir)
52    {
53       this.url = url;
54       this.packageListDir = packageListDir;
55    }
56
57    private Set packageNames = new HashSet();
58    private boolean javadocCompatible;
59
60    public void load(File targetDirectory)
61       throws IOException, MalformedURLException
62    {
63       if (!url.endsWith("/")) {
64          url += "/";
65       }
66
67       this.docSetDirectoryURL = new URL(targetDirectory.toURL(),
68                                         url);
69
70       URL packageListDirURL;
71       if (null != packageListDir) {
72          if (!packageListDir.endsWith("/")) {
73            packageListDir += "/";
74          }
75          packageListDirURL = new URL(new File(System.getProperty("user.dir")).toURL(),
76                                      packageListDir);
77       }
78       else {
79          packageListDirURL = docSetDirectoryURL;
80       }
81
82       URL packageListURL = new URL(packageListDirURL,
83                                     "package-list");
84       InputStream in = packageListURL.openStream();
85       if (null != in) {
86          readPackages(in);
87          in.close();
88       }
89       else {
90          throw new FileNotFoundException(packageListURL.toString());
91       }
92
93       URL gjdocPropertiesURL = new URL(packageListDirURL,
94                                        "gjdoc.properties");
95       try {
96           InputStream propertiesIn = gjdocPropertiesURL.openStream();
97           if (null != in) {
98               Properties properties = new Properties();
99               properties.load(propertiesIn);
100               propertiesIn.close();
101          
102               String gjdocCompatProperty = properties.getProperty("gjdoc.compat");
103               if (null != gjdocCompatProperty) {
104                   javadocCompatible = "true".equals(properties.getProperty("gjdoc.compat"));
105               }
106               else {
107                   javadocCompatible = true;
108               }
109           }
110           else {
111               javadocCompatible = true;
112           }
113       } 
114       catch (FileNotFoundException e) {
115           javadocCompatible = true;
116       }
117    }
118
119    public String getPackageDocURL(String packageName)
120    {
121       try {
122          URL packageURL = new URL(docSetDirectoryURL,
123                                   packageName.replace('.', '/'));
124          return packageURL.toString();
125       }
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
129          // invalid
130          throw new RuntimeException(e);
131       }
132    }
133
134    public String getClassDocURL(String packageName, String typeName)
135    {
136       try {
137          URL fileURL = new URL(docSetDirectoryURL,
138                                packageName.replace('.', '/') + "/" + typeName + ".html");
139          return fileURL.toString();
140       }
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
144          // can't be invalid
145          throw new RuntimeException(e);
146       }
147    }
148
149    protected void readPackages(InputStream in)
150       throws IOException
151    {
152       BufferedReader reader
153          = new BufferedReader(new InputStreamReader(in, "UTF-8"));
154       String line;
155       while ((line = reader.readLine()) != null) {
156          line = line.trim();
157          packageNames.add(line);
158       }
159    }
160
161    public Set getPackageNames()
162    {
163       return packageNames;
164    }
165
166    public boolean isJavadocCompatible()
167    {
168       return javadocCompatible;
169    }
170 }