Index: webapp/cms/plugins/web/src/org/ametys/web/site/GlobalStatisticsGenerator.java =================================================================== --- webapp/cms/plugins/web/src/org/ametys/web/site/GlobalStatisticsGenerator.java (revision 21307) +++ webapp/cms/plugins/web/src/org/ametys/web/site/GlobalStatisticsGenerator.java (working copy) @@ -26,8 +26,13 @@ import org.ametys.cms.repository.Content; import org.ametys.cms.repository.ContentQueryHelper; +import org.ametys.plugins.explorer.resources.Resource; import org.ametys.plugins.repository.AmetysObjectIterable; import org.ametys.plugins.repository.AmetysObjectResolver; +import org.ametys.plugins.repository.query.QueryHelper; +import org.ametys.plugins.repository.query.SortCriteria; +import org.ametys.web.repository.page.Page; +import org.ametys.web.repository.page.ZoneItem; import org.ametys.web.repository.site.Site; /** @@ -59,52 +64,97 @@ XMLUtils.startElement(contentHandler, "statistics"); - // Global statistics. - XMLUtils.startElement(contentHandler, "global"); - - saxContents(); + _saxTotalSites(); + _saxTotalContents(); + _saxTotalPages(); + _saxTotalServices(); - XMLUtils.endElement(contentHandler, "global"); - - // Per-site statistics. - AmetysObjectIterable sites = _siteManager.getSites(); - for (Site site : sites) - { - saxSite(site); - } + // Resources + _saxResources (); + _saxSharedResources (); XMLUtils.endElement(contentHandler, "statistics"); contentHandler.endDocument(); } - /** - * SAX the global content count. - * @throws SAXException - */ - protected void saxContents() throws SAXException + private void _saxTotalSites () throws SAXException { - String query = ContentQueryHelper.getContentXPathQuery(null); + String query = QueryHelper.getXPathQuery(null, "ametys:site", null); + AmetysObjectIterable sites = _ametysResolver.query(query); + long nbServices = sites.getSize(); + + AttributesImpl attrs = new AttributesImpl(); + attrs.addCDATAAttribute("count", Long.toString(nbServices)); + XMLUtils.createElement(contentHandler, "sites", attrs); + } + + private void _saxTotalContents () throws SAXException + { + String query = QueryHelper.getXPathQuery(null, "ametys:content", null); AmetysObjectIterable contents = _ametysResolver.query(query); + long count = contents.getSize(); + + AttributesImpl attrs = new AttributesImpl(); + attrs.addCDATAAttribute("count", Long.toString(count)); + XMLUtils.createElement(contentHandler, "contents", attrs); + } + + private void _saxTotalPages () throws SAXException + { + String query = QueryHelper.getXPathQuery(null, "ametys:page", null); + AmetysObjectIterable pages = _ametysResolver.query(query); + long count = pages.getSize(); + + AttributesImpl attrs = new AttributesImpl(); + attrs.addCDATAAttribute("count", Long.toString(count)); + XMLUtils.createElement(contentHandler, "pages", attrs); + } + + private void _saxTotalServices () throws SAXException + { + String xPathQuery = "//element(*, ametys:zoneItem)[@ametys-internal:service]"; + AmetysObjectIterable services = _ametysResolver.query(xPathQuery); + long count = services.getSize(); - int count = 0; - try + AttributesImpl attrs = new AttributesImpl(); + attrs.addCDATAAttribute("count", Long.toString(count)); + XMLUtils.createElement(contentHandler, "services", attrs); + } + + private void _saxResources () throws SAXException + { + String xPathQuery = "//element(*, ametys:site)/ametys-internal:resources//element(*, ametys:resource)"; + AmetysObjectIterable resources = _ametysResolver.query(xPathQuery); + + long count = resources.getSize(); + long length = 0; + for (Resource resource : resources) { - while (contents.hasNext()) - { - contents.next(); - count++; - } + length += resource.getLength(); } - finally + + AttributesImpl attrs = new AttributesImpl(); + attrs.addCDATAAttribute("count", Long.toString(count)); + attrs.addCDATAAttribute("length", Long.toString(length)); + XMLUtils.createElement(contentHandler, "resources", attrs); + } + + private void _saxSharedResources () throws SAXException + { + String xPathQuery = "//shared-resources//element(*, ametys:resource)"; + AmetysObjectIterable resources = _ametysResolver.query(xPathQuery); + + long count = resources.getSize(); + long length = 0; + for (Resource resource : resources) { - contents.close(); + length += resource.getLength(); } AttributesImpl attrs = new AttributesImpl(); - attrs.addCDATAAttribute("count", Integer.toString(count)); - - XMLUtils.createElement(contentHandler, "contents", attrs); + attrs.addCDATAAttribute("count", Long.toString(count)); + attrs.addCDATAAttribute("length", Long.toString(length)); + XMLUtils.createElement(contentHandler, "shared-resources", attrs); } - }