在MainServlet中,当站点设置(设置会话超时,国际化语言设定)之后,就开始初始化扩展环境了,具体代码如下:if (_log.isDebugEnabled()) { _log.debug("Initialize extension environment"); } try { initExt(); } ...
它会调用initExt()方法:
protected void initExt() throws Exception { ServletContext servletContext = getServletContext(); ExtRegistry.registerPortal(servletContext); }进而调用ExtRegistry的registerPortal方法:
public static void registerPortal(ServletContext servletContext) throws Exception { Set<String> resourcePaths = servletContext.getResourcePaths("/WEB-INF"); for (String resourcePath : resourcePaths) { if (resourcePath.startsWith("/WEB-INF/ext-") && resourcePath.endsWith("-ext.xml")) { String servletContextName = resourcePath.substring( 13, resourcePath.length() - 4); Set<String> files = _readExtFiles(servletContext, resourcePath); _extMap.put(servletContextName, files); } } }从这里可以看出,它会去获取/WEB-INF/目录下所有的以ext开头或则以ext结尾的配置文件,然后去读去这些文件,解析代码位于ExtRegistry类的_readExtFiles中:
private static Set<String> _readExtFiles( ServletContext servletContext, String resourcePath) throws Exception { Set<String> files = new TreeSet<String>(); Document document = SAXReaderUtil.read( servletContext.getResourceAsStream(resourcePath)); Element rootElement = document.getRootElement(); Element filesElement = rootElement.element("files"); List<Element> fileElements = filesElement.elements("file"); for (Element fileElement : fileElements) { files.add(fileElement.getText()); } return files; }