在MainServlet中,当初始化Resource Code完毕后,就开始初始化公司信息,对应代码如下:if (_log.isDebugEnabled()) { _log.debug("Initialize companies"); } try { initCompanies(); } ..
它会调用initCompanies()方法:
protected void initCompanies() throws Exception { ServletContext servletContext = getServletContext(); String[] webIds = PortalInstances.getWebIds(); for (int i = 0; i < webIds.length; i++) { PortalInstances.initCompany(servletContext, webIds[i]); } }从这里可以看出,它先02行获得Servlet上下文,然后04行获得webId的数组:
分析04行:
我们跟进到PortalInstances的getWebIds方法:
public static String[] getWebIds() { return _instance._getWebIds(); }它最终是调用_getWebIds()方法:
private String[] _getWebIds() { if (_webIds != null) { return _webIds; } if (Validator.isNull(PropsValues.COMPANY_DEFAULT_WEB_ID)) { throw new RuntimeException("Default web id must not be null"); } try { List<Company> companies = CompanyLocalServiceUtil.getCompanies( false); List<String> webIdsList = new ArrayList<String>(companies.size()); for (Company company : companies) { String webId = company.getWebId(); if (webId.equals(PropsValues.COMPANY_DEFAULT_WEB_ID)) { webIdsList.add(0, webId); } else { webIdsList.add(webId); } } _webIds = webIdsList.toArray(new String[webIdsList.size()]); } catch (Exception e) { _log.error(e, e); } if ((_webIds == null) || (_webIds.length == 0)) { _webIds = new String[] {PropsValues.COMPANY_DEFAULT_WEB_ID}; } return _webIds; }