Re: [Actionframework-users] ActionConfigEntityResolver.java is worse than doing nothing
Status: Inactive
Brought to you by:
ptoman
From: Mark D. A. <md...@di...> - 2003-01-03 17:39:24
|
i was mis-reading the code for the dtd case. It does seem to be correct for that, sorry. However, it still fails for other external entities, such as this: <?xml version="1.0"?> <!DOCTYPE application SYSTEM "http://www.actionframework.org/dtd/ActionServlet_0_93.dtd" [ <!ENTITY echart_action_common SYSTEM "echart_action_common.xml"> ]> <application> <properties> <property name="some.property" value="17"/> </properties> &echart_action_common; </application> Below is a replacement implementation. This requires a second constructor arg of servlet.class, so a 1-line change will be required from ActionRuntime. ---------- class ActionConfigEntityResolver implements EntityResolver { private Log log; private Class loader_class; public ActionConfigEntityResolver(Log log, Class loader_class) { this.log = log; this.loader_class = loader_class; } public InputSource resolveEntity (String publicId, String systemId) { if (systemId == null || systemId.length() == 0) { log.error("[init] " + "unimplemented: resolveEntity with no SYSTEM id"); return null; } log.debug("[init] " + "Loading entity systemId: " + systemId); String resource_path; int dtd_ind = systemId.indexOf("ActionServlet_"); // special case if an http url for an ActionServlet dtd if (systemId.startsWith("http:")) { if (dtd_ind != -1 && systemId.indexOf(".dtd") != -1) resource_path = "/dtd/" + systemId.substring(dtd_ind); else { log.error("[init] " + "unimplemented: resolveEntity with http SYSTEM which is not an ActionServlet dtd: '" + systemId + "'"); return null; } } else if (systemId.startsWith("file:")) { log.error("[init] " + "unimplemented: resolveEntity with file scheme SYSTEM id: '" + systemId + "'"); return null; } else { // if not a "http" url, assume it is a file system path resource_path = systemId.startsWith("/") ? systemId : "/" + systemId; } try { InputStream is = loader_class.getResourceAsStream(resource_path); if (is == null) { log.error("[init] " + "systemId '" + systemId + "'" + " does not exist as resource '" + resource_path + "' in loader path for class '" + loader_class.getName() + "'"); } else return new InputSource(new InputStreamReader(is)); } catch (Exception e) { log.error("[init] " + "Error resolving entity systemId '" + systemId + "'" + ": " + e.getMessage(), e); } return null; } } |