[Mc4j-cvs] mc4j/src/org/mc4j/console/dashboard DashboardComponent.java,1.5,1.6 DashboardLoader.java,
Brought to you by:
ghinkl
From: Greg H. <gh...@us...> - 2004-04-08 15:22:08
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/dashboard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31678/src/org/mc4j/console/dashboard Modified Files: DashboardComponent.java DashboardLoader.java DashboardManager.java Log Message: Better error handling. Added a custom entity resolver so you don't need a net connection to get dashboards to validate. Index: DashboardManager.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/dashboard/DashboardManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DashboardManager.java 7 Apr 2004 02:53:04 -0000 1.1 --- DashboardManager.java 8 Apr 2004 15:08:49 -0000 1.2 *************** *** 35,39 **** import org.mc4j.console.bean.MBeanNode; - import org.mc4j.console.util.ExceptionUtility; /** --- 35,38 ---- *************** *** 97,111 **** for (int i = 0; i < dashboardFiles.length; i++) { ! try { ! IOProvider.getDefault().getIO("Dashboard debugging",false).getOut(). ! println("Parsing dashboard: " + dashboardFiles[i].getName()); ! ! Dashboard dashboard = DashboardLoader.getInstance().buildDashboard(dashboardFiles[i]); ! this.dashboardDocuments.add(dashboard); - } catch (Exception e) { - System.out.println(ExceptionUtility.printStackTracesToString(e)); - } } StatusDisplayer.getDefault().setStatusText(oldStatus); --- 96,104 ---- for (int i = 0; i < dashboardFiles.length; i++) { ! ! Dashboard dashboard = DashboardLoader.getInstance().buildDashboard(dashboardFiles[i]); ! if (dashboard != null) this.dashboardDocuments.add(dashboard); } StatusDisplayer.getDefault().setStatusText(oldStatus); Index: DashboardComponent.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/dashboard/DashboardComponent.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DashboardComponent.java 7 Apr 2004 02:55:30 -0000 1.5 --- DashboardComponent.java 8 Apr 2004 15:08:47 -0000 1.6 *************** *** 29,33 **** * @version $Revision$($Author$ / $Date$) */ ! public interface DashboardComponent extends Refreshable{ void setContext(Map context); --- 29,33 ---- * @version $Revision$($Author$ / $Date$) */ ! public interface DashboardComponent extends Refreshable { void setContext(Map context); Index: DashboardLoader.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/dashboard/DashboardLoader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DashboardLoader.java 7 Apr 2004 03:04:25 -0000 1.1 --- DashboardLoader.java 8 Apr 2004 15:08:49 -0000 1.2 *************** *** 30,33 **** --- 30,34 ---- import org.openide.ErrorManager; + import org.openide.windows.IOProvider; import org.mc4j.console.dashboard.match.BeanCondition; *************** *** 38,42 **** --- 39,45 ---- import org.w3c.dom.Element; import org.w3c.dom.NodeList; + import org.xml.sax.InputSource; import org.xml.sax.SAXException; + import org.xml.sax.helpers.DefaultHandler; /** *************** *** 73,76 **** --- 76,81 ---- Dashboard dashboard = null; try { + //IOProvider.getDefault().getIO("Dashboard debugging",false).getOut(). + // println("Parsing dashboard: " + dashboardFile.getName()); Document document = buildDocument(new FileInputStream(dashboardFile)); *************** *** 94,99 **** --- 99,108 ---- } catch(SAXException se) { + IOProvider.getDefault().getIO("Dashboard debugging",false).getOut(). + println("Dashboard parsing failed on: " + dashboardFile.getName() + " " + se); ErrorManager.getDefault().notify(se); } catch(FileNotFoundException fnfe) { + IOProvider.getDefault().getIO("Dashboard debugging",false).getOut(). + println("Dashboard parsing failed on: " + dashboardFile.getName() + " " + fnfe); ErrorManager.getDefault().notify(fnfe); } catch(IOException ioe) { *************** *** 193,202 **** --- 202,261 ---- try { builder = factory.newDocumentBuilder(); + builder.setEntityResolver(new DTDClasspathEntityResolver()); } catch (ParserConfigurationException pce) { System.out.println(pce); } + Document document = builder.parse(is); return document; } + + public static class DTDClasspathEntityResolver extends DefaultHandler { + + public DTDClasspathEntityResolver() { + super(); + } + + /** + * <p> + * Will attempt to resolve an entity by checking for it in the classpath. + * </p> + * + * @param publicId The public identifier of the external entity + * being referenced, or null if none was supplied + * @param systemId The system identifier of the external entity being + * referenced. + * @return An InputSource object describing the new input source, or + * null to request that the parser open a regular URI connection + * to the system identifier. + * @throws SAXException indicates an error resolving the entity + */ + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException { + + InputSource inputSource = null; + + + if ("http://mc4j.sourceforge.net/Dashboard_1_0.dtd".equals(systemId)) { + + InputStream inputStream = + getClass().getClassLoader().getResourceAsStream("dashboards/Dashboard_1_0.dtd"); + + if (inputStream != null) { + inputSource = new InputSource(inputStream); + } + } + if (inputSource != null) { + return inputSource; + } else { + try { + return super.resolveEntity(publicId, systemId); + } catch (Exception e) { + // TODO GH: FIXME! IMPORTANT! + throw new UnsupportedOperationException("TODO: GH!"); + } + } + } + } } |