1.1 --- a/src/share/classes/com/sun/tools/javadoc/DocImpl.java Fri Mar 04 19:53:03 2011 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javadoc/DocImpl.java Fri Mar 04 19:56:02 2011 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -25,6 +25,7 @@ 1.11 1.12 package com.sun.tools.javadoc; 1.13 1.14 +import java.io.DataInputStream; 1.15 import java.io.InputStream; 1.16 import java.io.IOException; 1.17 import java.text.CollationKey; 1.18 @@ -33,6 +34,8 @@ 1.19 import com.sun.javadoc.*; 1.20 1.21 import com.sun.tools.javac.util.Position; 1.22 +import java.util.regex.Matcher; 1.23 +import java.util.regex.Pattern; 1.24 1.25 /** 1.26 * abstract base class of all Doc classes. Doc item's are representations 1.27 @@ -166,51 +169,28 @@ 1.28 * Utility for subclasses which read HTML documentation files. 1.29 */ 1.30 String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException { 1.31 - int filesize = input.available(); 1.32 - byte[] filecontents = new byte[filesize]; 1.33 - input.read(filecontents, 0, filesize); 1.34 - input.close(); 1.35 + byte[] filecontents = new byte[input.available()]; 1.36 + try { 1.37 + DataInputStream dataIn = new DataInputStream(input); 1.38 + dataIn.readFully(filecontents); 1.39 + } finally { 1.40 + input.close(); 1.41 + } 1.42 String encoding = env.getEncoding(); 1.43 String rawDoc = (encoding!=null) 1.44 ? new String(filecontents, encoding) 1.45 : new String(filecontents); 1.46 - String upper = null; 1.47 - int bodyIdx = rawDoc.indexOf("<body"); 1.48 - if (bodyIdx == -1) { 1.49 - bodyIdx = rawDoc.indexOf("<BODY"); 1.50 - if (bodyIdx == -1) { 1.51 - upper = rawDoc.toUpperCase(); 1.52 - bodyIdx = upper.indexOf("<BODY"); 1.53 - if (bodyIdx == -1) { 1.54 - env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), 1.55 - "javadoc.Body_missing_from_html_file"); 1.56 - return ""; 1.57 - } 1.58 - } 1.59 - } 1.60 - bodyIdx = rawDoc.indexOf('>', bodyIdx); 1.61 - if (bodyIdx == -1) { 1.62 - env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), 1.63 - "javadoc.Body_missing_from_html_file"); 1.64 + Pattern bodyPat = Pattern.compile("(?is).*<body\\b[^>]*>(.*)</body\\b.*"); 1.65 + Matcher m = bodyPat.matcher(rawDoc); 1.66 + if (m.matches()) { 1.67 + return m.group(1); 1.68 + } else { 1.69 + String key = rawDoc.matches("(?is).*<body\\b.*") 1.70 + ? "javadoc.End_body_missing_from_html_file" 1.71 + : "javadoc.Body_missing_from_html_file"; 1.72 + env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key); 1.73 return ""; 1.74 } 1.75 - ++bodyIdx; 1.76 - int endIdx = rawDoc.indexOf("</body", bodyIdx); 1.77 - if (endIdx == -1) { 1.78 - endIdx = rawDoc.indexOf("</BODY", bodyIdx); 1.79 - if (endIdx == -1) { 1.80 - if (upper == null) { 1.81 - upper = rawDoc.toUpperCase(); 1.82 - } 1.83 - endIdx = upper.indexOf("</BODY", bodyIdx); 1.84 - if (endIdx == -1) { 1.85 - env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), 1.86 - "javadoc.End_body_missing_from_html_file"); 1.87 - return ""; 1.88 - } 1.89 - } 1.90 - } 1.91 - return rawDoc.substring(bodyIdx, endIdx); 1.92 } 1.93 1.94 /** 1.95 @@ -256,6 +236,7 @@ 1.96 /** 1.97 * Returns a string representation of this Doc item. 1.98 */ 1.99 + @Override 1.100 public String toString() { 1.101 return qualifiedName(); 1.102 }