2 * Copyright (C) 2011 Openismus GmbH
4 * This file is part of GWT-Glom.
6 * GWT-Glom is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
11 * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with GWT-Glom. If not, see <http://www.gnu.org/licenses/>.
20 package org.glom.web.server;
22 import java.beans.PropertyVetoException;
23 import java.sql.Connection;
24 import java.sql.SQLException;
25 import java.util.ArrayList;
26 import java.util.Hashtable;
27 import java.util.List;
28 import java.util.Locale;
30 import org.apache.commons.lang3.StringUtils;
31 import org.glom.web.server.database.DetailsDBAccess;
32 import org.glom.web.server.database.ListViewDBAccess;
33 import org.glom.web.server.database.RelatedListDBAccess;
34 import org.glom.web.server.database.RelatedListNavigation;
35 import org.glom.web.server.libglom.Document;
36 import org.glom.web.shared.DataItem;
37 import org.glom.web.shared.DocumentInfo;
38 import org.glom.web.shared.NavigationRecord;
39 import org.glom.web.shared.Reports;
40 import org.glom.web.shared.TypedDataItem;
41 import org.glom.web.shared.libglom.CustomTitle;
42 import org.glom.web.shared.libglom.Field;
43 import org.glom.web.shared.libglom.Relationship;
44 import org.glom.web.shared.libglom.Report;
45 import org.glom.web.shared.libglom.Translatable;
46 import org.glom.web.shared.libglom.layout.LayoutGroup;
47 import org.glom.web.shared.libglom.layout.LayoutItem;
48 import org.glom.web.shared.libglom.layout.LayoutItemField;
49 import org.glom.web.shared.libglom.layout.LayoutItemPortal;
50 import org.glom.web.shared.libglom.layout.UsesRelationship;
52 import com.mchange.v2.c3p0.ComboPooledDataSource;
55 * A class to hold configuration information for a given Glom document. This class retrieves layout information from
56 * libglom and data from the underlying PostgreSQL database.
58 final class ConfiguredDocument {
60 private Document document;
61 private ComboPooledDataSource cpds;
62 private boolean authenticated = false;
63 private String documentID = "";
64 private String defaultLocaleID = "";
66 private static class LayoutLocaleMap extends Hashtable<String, List<LayoutGroup>> {
67 private static final long serialVersionUID = 6542501521673767267L;
70 private static class TableLayouts {
71 public LayoutLocaleMap listLayouts;
72 public LayoutLocaleMap detailsLayouts;
75 private static class TableLayoutsForLocale extends Hashtable<String, TableLayouts> {
76 private static final long serialVersionUID = -1947929931925049013L;
78 public LayoutGroup getListLayout(final String tableName, final String locale) {
79 final List<LayoutGroup> groups = getLayout(tableName, locale, false);
84 if (groups.isEmpty()) {
91 public List<LayoutGroup> getDetailsLayout(final String tableName, final String locale) {
92 return getLayout(tableName, locale, true);
95 public void setListLayout(final String tableName, final String locale, final LayoutGroup layout) {
96 final List<LayoutGroup> list = new ArrayList<LayoutGroup>();
98 setLayout(tableName, locale, list, false);
101 public void setDetailsLayout(final String tableName, final String locale, final List<LayoutGroup> layout) {
102 setLayout(tableName, locale, layout, true);
105 private List<LayoutGroup> getLayout(final String tableName, final String locale, final boolean details) {
106 final LayoutLocaleMap map = getMap(tableName, details);
112 return map.get(locale);
115 private LayoutLocaleMap getMap(final String tableName, final boolean details) {
116 final TableLayouts tableLayouts = get(tableName);
117 if (tableLayouts == null) {
121 LayoutLocaleMap map = null;
123 map = tableLayouts.detailsLayouts;
125 map = tableLayouts.listLayouts;
131 private LayoutLocaleMap getMapWithAdd(final String tableName, final boolean details) {
132 TableLayouts tableLayouts = get(tableName);
133 if (tableLayouts == null) {
134 tableLayouts = new TableLayouts();
135 put(tableName, tableLayouts);
138 LayoutLocaleMap map = null;
140 if (tableLayouts.detailsLayouts == null) {
141 tableLayouts.detailsLayouts = new LayoutLocaleMap();
144 map = tableLayouts.detailsLayouts;
146 if (tableLayouts.listLayouts == null) {
147 tableLayouts.listLayouts = new LayoutLocaleMap();
150 map = tableLayouts.listLayouts;
156 private void setLayout(final String tableName, final String locale, final List<LayoutGroup> layout,
157 final boolean details) {
158 final LayoutLocaleMap map = getMapWithAdd(tableName, details);
160 map.put(locale, layout);
165 private final TableLayoutsForLocale mapTableLayouts = new TableLayoutsForLocale();
167 @SuppressWarnings("unused")
168 private ConfiguredDocument() {
169 // disable default constructor
172 ConfiguredDocument(final Document document) throws PropertyVetoException {
174 // load the jdbc driver
175 cpds = createAndSetupDataSource(document);
177 this.document = document;
184 private static ComboPooledDataSource createAndSetupDataSource(final Document document) {
185 final ComboPooledDataSource cpds = new ComboPooledDataSource();
187 // We don't support sqlite or self-hosting yet.
188 if ((document.getHostingMode() != Document.HostingMode.HOSTING_MODE_POSTGRES_CENTRAL)
189 && (document.getHostingMode() != Document.HostingMode.HOSTING_MODE_POSTGRES_SELF)) {
190 // TODO: We allow self-hosting here, for testing,
191 // but maybe the startup of self-hosting should happen here.
192 Log.fatal("Error configuring the database connection." + " Only PostgreSQL hosting is supported.");
193 // FIXME: Throw exception?
197 cpds.setDriverClass("org.postgresql.Driver");
198 } catch (final PropertyVetoException e) {
199 Log.fatal("Error loading the PostgreSQL JDBC driver."
200 + " Is the PostgreSQL JDBC jar available to the servlet?", e);
204 // setup the JDBC driver for the current glom document
205 String jdbcURL = "jdbc:postgresql://" + document.getConnectionServer() + ":" + document.getConnectionPort();
207 String db = document.getConnectionDatabase();
208 if (StringUtils.isEmpty(db)) {
209 // Use the default PostgreSQL database, because ComboPooledDataSource.connect() fails otherwise.
212 jdbcURL += "/" + db; // TODO: Quote the database name?
214 cpds.setJdbcUrl(jdbcURL);
220 * Sets the username and password for the database associated with the Glom document.
222 * @return true if the username and password works, false otherwise
224 boolean setUsernameAndPassword(final String username, final String password) throws SQLException {
225 cpds.setUser(username);
226 cpds.setPassword(password);
228 final int acquireRetryAttempts = cpds.getAcquireRetryAttempts();
229 cpds.setAcquireRetryAttempts(1);
230 Connection conn = null;
232 // FIXME find a better way to check authentication
233 // it's possible that the connection could be failing for another reason
234 conn = cpds.getConnection();
235 authenticated = true;
236 } catch (final SQLException e) {
237 Log.info(Utils.getFileName(document.getFileURI()), e.getMessage());
238 Log.info(Utils.getFileName(document.getFileURI()),
239 "Connection Failed. Maybe the username or password is not correct.");
240 authenticated = false;
245 cpds.setAcquireRetryAttempts(acquireRetryAttempts);
247 return authenticated;
250 Document getDocument() {
254 ComboPooledDataSource getCpds() {
258 boolean isAuthenticated() {
259 return authenticated;
262 String getDocumentID() {
266 void setDocumentID(final String documentID) {
267 this.documentID = documentID;
270 String getDefaultLocaleID() {
271 return defaultLocaleID;
274 void setDefaultLocaleID(final String localeID) {
275 this.defaultLocaleID = localeID;
281 DocumentInfo getDocumentInfo(final String localeID) {
282 final DocumentInfo documentInfo = new DocumentInfo();
284 // get arrays of table names and titles, and find the default table index
285 final List<String> tablesVec = document.getTableNames();
287 final int numTables = Utils.safeLongToInt(tablesVec.size());
288 // we don't know how many tables will be hidden so we'll use half of the number of tables for the default size
290 final ArrayList<String> tableNames = new ArrayList<String>(numTables / 2);
291 final ArrayList<String> tableTitles = new ArrayList<String>(numTables / 2);
292 boolean foundDefaultTable = false;
293 int visibleIndex = 0;
294 for (int i = 0; i < numTables; i++) {
295 final String tableName = tablesVec.get(i);
296 if (!document.getTableIsHidden(tableName)) {
297 tableNames.add(tableName);
298 // JNI is "expensive", the comparison will only be called if we haven't already found the default table
299 if (!foundDefaultTable && tableName.equals(document.getDefaultTable())) {
300 documentInfo.setDefaultTableIndex(visibleIndex);
301 foundDefaultTable = true;
303 tableTitles.add(document.getTableTitle(tableName, localeID));
308 // set everything we need
309 documentInfo.setTableNames(tableNames);
310 documentInfo.setTableTitles(tableTitles);
311 documentInfo.setTitle(document.getDatabaseTitle(localeID));
313 // Fetch arrays of locale IDs and titles:
314 final List<String> localesVec = document.getTranslationAvailableLocales();
315 final int numLocales = Utils.safeLongToInt(localesVec.size());
316 final ArrayList<String> localeIDs = new ArrayList<String>(numLocales);
317 final ArrayList<String> localeTitles = new ArrayList<String>(numLocales);
318 for (int i = 0; i < numLocales; i++) {
319 final String this_localeID = localesVec.get(i);
320 localeIDs.add(this_localeID);
322 // Use java.util.Locale to get a title for the locale:
323 final String[] locale_parts = this_localeID.split("_");
324 String locale_lang = this_localeID;
325 if (locale_parts.length > 0) {
326 locale_lang = locale_parts[0];
328 String locale_country = "";
329 if (locale_parts.length > 1) {
330 locale_country = locale_parts[1];
333 final Locale locale = new Locale(locale_lang, locale_country);
334 final String title = locale.getDisplayName(locale);
335 localeTitles.add(title);
337 documentInfo.setLocaleIDs(localeIDs);
338 documentInfo.setLocaleTitles(localeTitles);
344 * Gets the layout group for the list view using the defined layout list in the document or the table fields if
345 * there's no defined layout group for the list view.
347 private LayoutGroup getValidListViewLayoutGroup(final String tableName, final String localeID) {
349 // Try to return a cached version:
350 final LayoutGroup result = mapTableLayouts.getListLayout(tableName, localeID);
351 if (result != null) {
352 updateLayoutGroupExpectedResultSize(result, tableName);
356 final List<LayoutGroup> layoutGroupVec = document.getDataLayoutGroups("list", tableName);
358 final int listViewLayoutGroupSize = Utils.safeLongToInt(layoutGroupVec.size());
359 LayoutGroup libglomLayoutGroup = null;
360 if (listViewLayoutGroupSize > 0) {
361 // A list layout group is defined.
362 // We use the first group as the list.
363 if (listViewLayoutGroupSize > 1) {
364 Log.warn(documentID, tableName, "The size of the list layout group is greater than 1. "
365 + "Attempting to use the first item for the layout list view.");
368 libglomLayoutGroup = layoutGroupVec.get(0);
370 // A list layout group is *not* defined; we are going make a LayoutGroup from the list of fields.
372 Log.info(documentID, tableName,
373 "A list layout is not defined for this table. Displaying a list layout based on the field list.");
375 final List<Field> fieldsVec = document.getTableFields(tableName);
376 libglomLayoutGroup = new LayoutGroup();
377 for (int i = 0; i < fieldsVec.size(); i++) {
378 final Field field = fieldsVec.get(i);
379 final LayoutItemField layoutItemField = new LayoutItemField();
380 layoutItemField.setFullFieldDetails(field);
381 libglomLayoutGroup.addItem(layoutItemField);
385 // TODO: Clone the group and change the clone, to discard unwanted information (such as translations)
386 // store some information that we do not want to calculate on the client side.
388 // Note that we don't use clone() here, because that would need clone() implementations
389 // in classes which are also used in the client code (though the clone() methods would
390 // not be used) and that makes the GWT java->javascript compilation fail.
391 final LayoutGroup cloned = (LayoutGroup) Utils.deepCopy(libglomLayoutGroup);
392 if (cloned != null) {
393 updateTopLevelListLayoutGroup(cloned, tableName, localeID);
395 // Discard unwanted translations so that getTitle(void) returns what we want.
396 updateTitlesForLocale(cloned, localeID);
399 // Store it in the cache for next time.
400 mapTableLayouts.setListLayout(tableName, localeID, cloned);
406 * @param libglomLayoutGroup
408 private void updateTopLevelListLayoutGroup(final LayoutGroup layoutGroup, final String tableName,
409 final String localeID) {
410 final List<LayoutItem> layoutItemsVec = layoutGroup.getItems();
412 int primaryKeyIndex = -1;
414 final int numItems = Utils.safeLongToInt(layoutItemsVec.size());
415 for (int i = 0; i < numItems; i++) {
416 final LayoutItem layoutItem = layoutItemsVec.get(i);
418 if (layoutItem instanceof LayoutItemField) {
419 final LayoutItemField layoutItemField = (LayoutItemField) layoutItem;
420 final Field field = layoutItemField.getFullFieldDetails();
421 if ((field != null) && field.getPrimaryKey()) {
427 // Set the primary key index for the table
428 if (primaryKeyIndex < 0) {
429 // Add a LayoutItemField for the primary key to the end of the item list in the LayoutGroup because it
430 // doesn't already contain a primary key.
431 Field primaryKey = null;
432 final List<Field> fieldsVec = document.getTableFields(tableName);
433 for (int i = 0; i < Utils.safeLongToInt(fieldsVec.size()); i++) {
434 final Field field = fieldsVec.get(i);
435 if (field.getPrimaryKey()) {
441 if (primaryKey != null) {
442 final LayoutItemField layoutItemField = new LayoutItemField();
443 layoutItemField.setName(primaryKey.getName());
444 layoutItemField.setFullFieldDetails(primaryKey);
445 layoutGroup.addItem(layoutItemField);
446 layoutGroup.setPrimaryKeyIndex(layoutGroup.getItems().size() - 1);
447 layoutGroup.setHiddenPrimaryKey(true);
449 Log.error(document.getDatabaseTitleOriginal(), tableName,
450 "A primary key was not found in the FieldVector for this table. Navigation buttons will not work.");
453 layoutGroup.setPrimaryKeyIndex(primaryKeyIndex);
457 private void updateLayoutGroupExpectedResultSize(final LayoutGroup layoutGroup, final String tableName) {
458 final ListViewDBAccess listViewDBAccess = new ListViewDBAccess(document, documentID, cpds, tableName,
460 layoutGroup.setExpectedResultSize(listViewDBAccess.getExpectedResultSize());
469 * @param useSortClause
470 * @param sortColumnIndex
471 * The index of the column to sort by, or -1 for none.
475 ArrayList<DataItem[]> getListViewData(String tableName, final String quickFind, final int start, final int length,
476 final boolean useSortClause, final int sortColumnIndex, final boolean isAscending) {
477 // Validate the table name.
478 tableName = getTableNameToUse(tableName);
480 // Get the LayoutGroup that represents the list view.
481 // TODO: Performance: Avoid calling this again:
482 final LayoutGroup libglomLayoutGroup = getValidListViewLayoutGroup(tableName, "" /* irrelevant locale */);
484 // Create a database access object for the list view.
485 final ListViewDBAccess listViewDBAccess = new ListViewDBAccess(document, documentID, cpds, tableName,
489 return listViewDBAccess.getData(quickFind, start, length, sortColumnIndex, isAscending);
492 DataItem[] getDetailsData(String tableName, final TypedDataItem primaryKeyValue) {
493 // Validate the table name.
494 tableName = getTableNameToUse(tableName);
496 final DetailsDBAccess detailsDBAccess = new DetailsDBAccess(document, documentID, cpds, tableName);
498 return detailsDBAccess.getData(primaryKeyValue);
505 * @param foreignKeyValue
508 * @param sortColumnIndex
509 * The index of the column to sort by, or -1 for none.
513 ArrayList<DataItem[]> getRelatedListData(String tableName, final LayoutItemPortal portal,
514 final TypedDataItem foreignKeyValue, final int start, final int length, final int sortColumnIndex,
515 final boolean isAscending) {
516 if (portal == null) {
517 Log.error("getRelatedListData(): portal is null");
521 // Validate the table name.
522 tableName = getTableNameToUse(tableName);
524 // Create a database access object for the related list
525 final RelatedListDBAccess relatedListDBAccess = new RelatedListDBAccess(document, documentID, cpds, tableName,
529 return relatedListDBAccess.getData(start, length, foreignKeyValue, sortColumnIndex, isAscending);
532 List<LayoutGroup> getDetailsLayoutGroup(String tableName, final String localeID) {
533 // Validate the table name.
534 tableName = getTableNameToUse(tableName);
536 // Try to return a cached version:
537 final List<LayoutGroup> result = mapTableLayouts.getDetailsLayout(tableName, localeID);
538 if (result != null) {
539 updatePortalsExtras(result, tableName); // Update expected results sizes.
543 final List<LayoutGroup> listGroups = document.getDataLayoutGroups("details", tableName);
545 // Clone the group and change the clone, to discard unwanted information (such as translations)
546 // and to store some information that we do not want to calculate on the client side.
548 // Note that we don't use clone() here, because that would need clone() implementations
549 // in classes which are also used in the client code (though the clone() methods would
550 // not be used) and that makes the GWT java->javascript compilation fail.
551 final List<LayoutGroup> listCloned = new ArrayList<LayoutGroup>();
552 for (final LayoutGroup group : listGroups) {
553 final LayoutGroup cloned = (LayoutGroup) Utils.deepCopy(group);
554 if (cloned != null) {
555 listCloned.add(cloned);
559 updatePortalsExtras(listCloned, tableName);
560 updateFieldsExtras(listCloned, tableName);
562 // Discard unwanted translations so that getTitle(void) returns what we want.
563 updateTitlesForLocale(listCloned, localeID);
565 // Store it in the cache for next time.
566 mapTableLayouts.setDetailsLayout(tableName, localeID, listCloned);
575 private void updatePortalsExtras(final List<LayoutGroup> listGroups, final String tableName) {
576 for (final LayoutGroup group : listGroups) {
577 updatePortalsExtras(group, tableName);
586 private void updateFieldsExtras(final List<LayoutGroup> listGroups, final String tableName) {
587 for (final LayoutGroup group : listGroups) {
588 updateFieldsExtras(group, tableName);
596 private void updateTitlesForLocale(final List<LayoutGroup> listGroups, final String localeID) {
597 for (final LayoutGroup group : listGroups) {
598 updateTitlesForLocale(group, localeID);
602 private void updatePortalsExtras(final LayoutGroup group, final String tableName) {
603 if (group instanceof LayoutItemPortal) {
604 final LayoutItemPortal portal = (LayoutItemPortal) group;
605 final String tableNameUsed = portal.getTableUsed(tableName);
606 updateLayoutGroupExpectedResultSize(portal, tableNameUsed);
608 final Relationship relationship = portal.getRelationship();
609 if (relationship != null) {
611 // Cache the navigation information:
612 // layoutItemPortal.set_name(libglomLayoutItemPortal.get_relationship_name_used());
613 // layoutItemPortal.setTableName(relationship.get_from_table());
614 // layoutItemPortal.setFromField(relationship.get_from_field());
616 // get the primary key for the related list table
617 final String toTableName = relationship.getToTable();
618 if (!StringUtils.isEmpty(toTableName)) {
620 // get the LayoutItemField with details from its Field in the document
621 final List<Field> fields = document.getTableFields(toTableName); // TODO_Performance: Cache this.
622 for (final Field field : fields) {
623 // check the names to see if they're the same
624 if (field.getPrimaryKey()) {
625 final LayoutItemField layoutItemField = new LayoutItemField();
626 layoutItemField.setName(field.getName());
627 layoutItemField.setFullFieldDetails(field);
628 portal.addItem(layoutItemField);
629 portal.setPrimaryKeyIndex(portal.getItems().size() - 1);
630 portal.setHiddenPrimaryKey(true); // always hidden in portals
639 final List<LayoutItem> childItems = group.getItems();
640 for (final LayoutItem item : childItems) {
641 if (item instanceof LayoutGroup) {
642 final LayoutGroup childGroup = (LayoutGroup) item;
643 updatePortalsExtras(childGroup, tableName);
649 private void updateFieldsExtras(final LayoutGroup group, final String tableName) {
651 final List<LayoutItem> childItems = group.getItems();
652 for (final LayoutItem item : childItems) {
653 if (item instanceof LayoutGroup) {
655 final LayoutGroup childGroup = (LayoutGroup) item;
656 updateFieldsExtras(childGroup, tableName);
657 } else if (item instanceof LayoutItemField) {
658 final LayoutItemField field = (LayoutItemField) item;
660 // Set whether the field should have a navigation button,
661 // because it identifies a related record.
662 final String navigationTableName = document.getLayoutItemFieldShouldHaveNavigation(tableName, field);
663 if (navigationTableName != null) {
664 field.setNavigationTableName(navigationTableName);
670 private void updateTitlesForLocale(final LayoutGroup group, final String localeID) {
672 updateItemTitlesForLocale(group, localeID);
674 final List<LayoutItem> childItems = group.getItems();
675 for (final LayoutItem item : childItems) {
677 // Call makeTitleOriginal on all Translatable items and all special
678 // Translatable items that they use:
679 if (item instanceof LayoutItemField) {
680 final LayoutItemField layoutItemField = (LayoutItemField) item;
682 final Field field = layoutItemField.getFullFieldDetails();
684 field.makeTitleOriginal(localeID);
687 final CustomTitle customTitle = layoutItemField.getCustomTitle();
688 if (customTitle != null) {
689 customTitle.makeTitleOriginal(localeID);
693 updateItemTitlesForLocale(item, localeID);
695 if (item instanceof LayoutGroup) {
697 final LayoutGroup childGroup = (LayoutGroup) item;
698 updateTitlesForLocale(childGroup, localeID);
703 private void updateItemTitlesForLocale(final LayoutItem item, final String localeID) {
704 if (item instanceof UsesRelationship) {
705 final UsesRelationship usesRelationship = (UsesRelationship) item;
706 final Relationship rel = usesRelationship.getRelationship();
709 rel.makeTitleOriginal(localeID);
712 final Relationship relatedRel = usesRelationship.getRelatedRelationship();
713 if (relatedRel != null) {
714 relatedRel.makeTitleOriginal(localeID);
718 if (item instanceof Translatable) {
719 final Translatable translatable = item;
720 translatable.makeTitleOriginal(localeID);
725 * Gets the expected row count for a related list.
727 int getRelatedListRowCount(String tableName, final LayoutItemPortal portal, final TypedDataItem foreignKeyValue) {
728 if (portal == null) {
729 Log.error("getRelatedListData(): portal is null");
733 // Validate the table name.
734 tableName = getTableNameToUse(tableName);
736 // Create a database access object for the related list
737 final RelatedListDBAccess relatedListDBAccess = new RelatedListDBAccess(document, documentID, cpds, tableName,
740 // Return the row count
741 return relatedListDBAccess.getExpectedResultSize(foreignKeyValue);
744 NavigationRecord getSuitableRecordToViewDetails(String tableName, final LayoutItemPortal portal,
745 final TypedDataItem primaryKeyValue) {
746 // Validate the table name.
747 tableName = getTableNameToUse(tableName);
749 final RelatedListNavigation relatedListNavigation = new RelatedListNavigation(document, documentID, cpds,
752 return relatedListNavigation.getNavigationRecord(primaryKeyValue);
755 LayoutGroup getListViewLayoutGroup(String tableName, final String localeID) {
756 // Validate the table name.
757 tableName = getTableNameToUse(tableName);
758 return getValidListViewLayoutGroup(tableName, localeID);
762 * Gets the table name to use when accessing the database and the document. This method guards against SQL injection
763 * attacks by returning the default table if the requested table is not in the database or if the table name has not
767 * The table name to validate.
768 * @return The table name to use.
770 private String getTableNameToUse(final String tableName) {
771 if (StringUtils.isEmpty(tableName) || !document.getTableIsKnown(tableName)) {
772 return document.getDefaultTable();
782 public Reports getReports(final String tableName, final String localeID) {
783 final Reports result = new Reports();
785 final List<String> names = document.getReportNames(tableName);
787 final int count = Utils.safeLongToInt(names.size());
788 for (int i = 0; i < count; i++) {
789 final String name = names.get(i);
790 final Report report = document.getReport(tableName, name);
791 if (report == null) {
795 final String title = report.getTitle(localeID);
796 result.addReport(name, title);