cp-tools-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Cp-tools-discuss] Parsing package.html files


From: Mark Wielaard
Subject: [Cp-tools-discuss] Parsing package.html files
Date: 07 May 2002 00:06:26 +0200

Hi,

We had the following discussion on the Classpath mailing list.

On Mon, 2002-05-06 at 21:07, Julian Scheid wrote:
> Julian Scheid wrote:
>  > Mark Wielaard wrote:
>  > > I checked in stubs for all java and javax subpackages.
>  > > But now that I run gjdoc it seems that it does not like the fact that
>  > > there are <title> tags in it. It gives errors like:
>  > > "WARNING: Invalid Unicode character 0x0 in javadoc markup has been
>  > > stripped" And it prints both the title and the first paragraph of the
>  > > package.html. Are my package.html file wrongly constructed?
>  >
>  > No, they are not. See
>  > 
> http://java.sun.com/j2se/javadoc/writingdoccomments/index.html#packagecomments
>  > for further details. The stylesheet ought to copy only the <body>
>  > contents, but currently it copies the full file. I'll fix that tonight.
> 
> It's not a problem with the XSLT sheet but with the Gjdoc engine
> which should pass only the body contents to the Doclet API.
> This makes matters worse.
> 
> The clean solution of this problem would require gjdoc to parse HTML,
> something that wasn't necessary so far and needs to be implemented.
> 
> But Javadoc requires the <html><body>...</body></html> structure and so,
> to be compatible with Javadoc, Gjdoc needs to parse package.html in the
> long run. I've added a task (#962) in savannah.

The attached patch does a very simple "parse". It finds a body start and
end tag either as lowercase or uppercase. If either of the two is not
found it falls back to passing the complete package.html file.

It also contains a small bug fix for not reading the complete
package.html file into the buffer. Which could sometimes happen when the
file was large.

This makes it handle the Classpath package files correctly.

Cheers,

Mark
diff -u -r1.5 Main.java
--- src/gnu/classpath/tools/gjdoc/Main.java     24 Feb 2002 05:58:46 -0000      
1.5
+++ src/gnu/classpath/tools/gjdoc/Main.java     6 May 2002 22:04:39 -0000
@@ -1224,9 +1224,28 @@
                  long packageDocSize=packageDocFile.length();
                  char[] packageDocBuf=new char[(int)(packageDocSize)];
                  FileReader fr=new FileReader(packageDocFile);
-                 fr.read(packageDocBuf);
+                 int i = fr.read(packageDocBuf);
+                 while (i > 0) {
+                     packageDocSize -= i;
+                     i = fr.read(packageDocBuf, i, (int)packageDocSize);
+                 }
                  fr.close();
-                 rc.setRawCommentText(new String(packageDocBuf));
+
+                 // We only need the part between the begin and end body tag.
+                 String html = new String(packageDocBuf);
+                 int start = html.indexOf("<body");
+                 if (start == -1)
+                     start = html.indexOf("<BODY");
+                 int end = html.indexOf("</body>");
+                 if (end == -1)
+                     end = html.indexOf("</BODY>");
+                 if (start != 1 && end != -1) {
+                     // Start is end of body tag.
+                     start = html.indexOf('>', start) + 1;
+                     html = html.substring(start, end);
+                 }
+
+                 rc.setRawCommentText(html);
               }
               catch (IOException e) {
                  printWarning("Error while reading documentation for package 
"+packageName+": "+e.getMessage());

reply via email to

[Prev in Thread] Current Thread [Next in Thread]