Skip to content

Commit

Permalink
Used try with resource to for
Browse files Browse the repository at this point in the history
MNode.parse method
  • Loading branch information
dixitdeepak committed Nov 4, 2024
1 parent 31b26a6 commit f08bc1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,15 @@ class ExecutionContextFactoryImpl implements ExecutionContextFactory {

URL defaultConfUrl = this.class.getClassLoader().getResource("MoquiDefaultConf.xml")
if (defaultConfUrl == null) throw new IllegalArgumentException("Could not find MoquiDefaultConf.xml file on the classpath")
MNode newConfigXmlRoot = MNode.parse(defaultConfUrl.toString(), defaultConfUrl.newInputStream())
//MNode newConfigXmlRoot = MNode.parse(defaultConfUrl.toString(), defaultConfUrl.newInputStream())
try (InputStream is = defaultConfUrl.newInputStream()) {
MNode newConfigXmlRoot = MNode.parse(defaultConfUrl.toString(), is)

// just merge the component configuration, needed before component init is done
mergeConfigComponentNodes(newConfigXmlRoot, runtimeConfXmlRoot)

return newConfigXmlRoot
}
}
protected void initComponents(MNode baseConfigNode) {
File versionJsonFile = new File(runtimePath + "/version.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,14 @@ class ScreenFacadeImpl implements ScreenFacade {
}

protected synchronized MNode makeWidgetTemplatesNodeByLocation(String templateLocation) {
MNode templatesNode = (MNode) widgetTemplateLocationCache.get(templateLocation)
//MNode templatesNode = (MNode) widgetTemplateLocationCache.get(templateLocation)
try (InputStream is = ecfi.resourceFacade.getLocationStream(templateLocation)) {
if (templatesNode != null) return templatesNode

templatesNode = MNode.parse(templateLocation, ecfi.resourceFacade.getLocationStream(templateLocation))
//templatesNode = MNode.parse(templateLocation, ecfi.resourceFacade.getLocationStream(templateLocation))
templatesNode = MNode.parse(templateLocation, is)
widgetTemplateLocationCache.put(templateLocation, templatesNode)
}
return templatesNode
}

Expand Down
10 changes: 6 additions & 4 deletions framework/src/main/java/org/moqui/util/MNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ public static MNode parse(ResourceReference rr) throws BaseException {
MNode cached = parsedNodeCache.get(location);
if (cached != null && cached.lastModified >= rr.getLastModified()) return cached;

MNode node = parse(location, rr.openStream());
//MNode node = parse(location, rr.openStream());
try (InputStream is = rr.openStream()) {
MNode node = parse(location, is);
node.lastModified = rr.getLastModified();
if (node.lastModified > 0) parsedNodeCache.put(location, node);
return node;
} catch (IOException e) {
throw new BaseException(e);
}
}
/** Parse from an InputStream and close the stream */
public static MNode parse(String location, InputStream is) throws BaseException {
Expand All @@ -69,9 +74,6 @@ public static MNode parse(String location, InputStream is) throws BaseException
} catch (IOException e) {
logger.error("Error closing XML stream from " + location, e);
throw new BaseException("Error parsing XML stream from " + location, e);
} finally {
try { is.close(); }
catch (IOException e) { logger.error("Error closing XML stream from " + location, e); }
}
}
public static MNode parse(File fl) throws BaseException {
Expand Down

0 comments on commit f08bc1a

Please sign in to comment.