From: <ox-...@us...> - 2003-06-12 08:15:12
|
Update of /cvsroot/sheets/sheets In directory sc8-pr-cvs1:/tmp/cvs-serv9044 Modified Files: Sheets.sheets Log Message: 1. Improved error handling of xml document parsing (now works with Xerces even though the publicId is null and an IOException gets thrown) 2. Class starting brace is now exported on the same line as the class definition to match the Sun coding conventions 3. Added a heuristic for exporting file header fragments wherein a space is put between the package header and the imports only if the imports are separated by spaces as well. Index: Sheets.sheets =================================================================== RCS file: /cvsroot/sheets/sheets/Sheets.sheets,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** Sheets.sheets 12 Jun 2003 05:20:52 -0000 1.59 --- Sheets.sheets 12 Jun 2003 08:14:29 -0000 1.60 *************** *** 91,95 **** if (members == null) return; for (int i = 0; i < members.numFragments(); i++) { ! if (i > 0) file.println(""); ((JavaFragment)members.getFragment(i)) .export(file, Profile.javaClassIndent == -1 ? Profile.standardJavaIndent : Profile.javaClassIndent); --- 91,96 ---- if (members == null) return; for (int i = 0; i < members.numFragments(); i++) { ! // we put a space before the first method too ! file.println(""); ((JavaFragment)members.getFragment(i)) .export(file, Profile.javaClassIndent == -1 ? Profile.standardJavaIndent : Profile.javaClassIndent); *************** *** 31262,31265 **** --- 31263,31269 ---- Console.batchedDisplay("Parse error while reading file: " + file); comps = new Fragment[] { new UnknownDocFragment(State.getObjectDatabase(), fileContents, null) }; + } catch (IOException e) { + Console.batchedDisplay("IO error while reading file: " + file); + comps = new Fragment[] { new UnknownDocFragment(State.getObjectDatabase(), fileContents, null) }; } catch (WrongDocumentTypeException e) { // Just return for now (eventually need to propogate this exception *************** *** 31451,31455 **** // The instant you construct the parser, it does the parsing. Get the // results out of the fragments field. ! public DocParser (String text, FragmentList links, boolean topLevel) throws SAXException, WrongDocumentTypeException { initAndParse(text, links, topLevel); } --- 31455,31459 ---- // The instant you construct the parser, it does the parsing. Get the // results out of the fragments field. ! public DocParser (String text, FragmentList links, boolean topLevel) throws SAXException, IOException, WrongDocumentTypeException { initAndParse(text, links, topLevel); } *************** *** 32910,32914 **** if (DocParser.textToXml(text, false) == null && !force) return false; ! } catch (SAXException e) { // Perhaps we should do something better, like highlight the error return false; --- 32914,32918 ---- if (DocParser.textToXml(text, false) == null && !force) return false; ! } catch (Exception e) { // Perhaps we should do something better, like highlight the error return false; *************** *** 32998,33002 **** ((Fragment)extensions.elementAt(i)).startEditing(null, false); return true; ! } catch (SAXException e) { if (!force) { // Perhaps we should do something better, like highlight the error --- 33002,33006 ---- ((Fragment)extensions.elementAt(i)).startEditing(null, false); return true; ! } catch (Exception e) { if (!force) { // Perhaps we should do something better, like highlight the error *************** *** 34144,34148 **** for (int i = 0; i < lines.length; i++) file.println(lines[i]); ! } catch (SAXException e) { // Perhaps we should do something better, like highlight the error Console.internalError(e); --- 34148,34152 ---- for (int i = 0; i < lines.length; i++) file.println(lines[i]); ! } catch (Exception e) { // Perhaps we should do something better, like highlight the error Console.internalError(e); *************** *** 34992,35007 **** section text nkramer:31710 // Parses XML text, and returns the structure. ! // Need to handle the errors better... ! static Document DocParser.textToXml (String text, boolean topLevel) throws SAXException { if (!topLevel) { // enclose non-toplevel tags with a dummy element text = "<dummy>" + text + "</dummy>"; } ! try { ! return builder.parse(new StringBufferInputStream(text)); ! } catch (IOException e) { ! Console.internalError(new Exception("IO Error while trying to parse: " + text, e)); ! } ! return null; } object nkramer:31711 --- 34996,35005 ---- section text nkramer:31710 // Parses XML text, and returns the structure. ! static Document DocParser.textToXml (String text, boolean topLevel) throws SAXException, IOException { if (!topLevel) { // enclose non-toplevel tags with a dummy element text = "<dummy>" + text + "</dummy>"; } ! return builder.parse(new StringBufferInputStream(text)); } object nkramer:31711 *************** *** 35024,35028 **** if (changed) ((Fragment) comp).replaceWith(DocParser.xmlToText(doc), true, false, null); ! } catch (SAXException e) { // Perhaps we should do something better, like highlight the error Console.internalError(e); --- 35022,35026 ---- if (changed) ((Fragment) comp).replaceWith(DocParser.xmlToText(doc), true, false, null); ! } catch (Exception e) { // Perhaps we should do something better, like highlight the error Console.internalError(e); *************** *** 64515,64525 **** String[] lines = text(); ! for (int i=0; i < lines.length; i++) { file.println(lines[i]); } ! file.println("{"); exportMembers(file); file.println("}"); - file.endFragment(); } --- 64513,64526 ---- String[] lines = text(); ! for (int i=0; i < lines.length - 1; i++) { file.println(lines[i]); } ! ! // Use the Sun convention of keeping the class start brace on the same line ! file.print(lines[lines.length - 1]); ! file.println(" {"); ! exportMembers(file); file.println("}"); file.endFragment(); } *************** *** 64875,64880 **** if (index < afterName.length() && afterName.charAt(index) == '\\n') index++; buff.append(afterName.substring(index)); ! } else buff.append(beforeName.substring(summaryStart)); String[] lines = StringSplitter.splitLines(buff.toString()); --- 64876,64886 ---- if (index < afterName.length() && afterName.charAt(index) == '\\n') index++; buff.append(afterName.substring(index)); ! } else { ! // If the body contains any blank lines, let's separate the package statement with ! // a blank line. ! if (beforeName.indexOf("\\n\\n", summaryStart) != -1) ! buff.append('\\n'); buff.append(beforeName.substring(summaryStart)); + } String[] lines = StringSplitter.splitLines(buff.toString()); *************** *** 70930,70933 **** --- 70936,70941 ---- builder.setEntityResolver(new org.xml.sax.EntityResolver() { public org.xml.sax.InputSource resolveEntity(String publicId, String systemId) { + if (publicId == null) + return null; if (publicId.equals(DOCUMENT_V11)) { return new org.xml.sax.InputSource(this.getClass().getResourceAsStream("dtd/document-v11.dtd")); *************** *** 82042,82046 **** // This constructor assumes this is not a top-level document, // and hides the extra exception ! public DocParser (String text, FragmentList links) throws SAXException { try { initAndParse(text, links, false); --- 82050,82054 ---- // This constructor assumes this is not a top-level document, // and hides the extra exception ! public DocParser (String text, FragmentList links) throws SAXException, IOException { try { initAndParse(text, links, false); *************** *** 82067,82074 **** type=java section text schin:1239 ! public void DocParser.initAndParse (String text, FragmentList links, boolean topLevel) throws SAXException, WrongDocumentTypeException { this.text = text; Document doc = textToXml(text, true); - if (doc == null) return; // some sort of fatal IOException if (topLevel && (doc.getDoctype() == null || !DOCUMENT_V11.equals(doc.getDoctype().getPublicId()) || !DOCUMENT_V12.equals(doc.getDoctype().getPublicId()))) // wrong document type --- 82075,82081 ---- type=java section text schin:1239 ! public void DocParser.initAndParse (String text, FragmentList links, boolean topLevel) throws SAXException, IOException, WrongDocumentTypeException { this.text = text; Document doc = textToXml(text, true); if (topLevel && (doc.getDoctype() == null || !DOCUMENT_V11.equals(doc.getDoctype().getPublicId()) || !DOCUMENT_V12.equals(doc.getDoctype().getPublicId()))) // wrong document type |