From 77c4d2586bcf8ce13b9608cafa9e1514731a13ad Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Tue, 15 May 2012 11:15:08 +0200 Subject: [PATCH] Document: Correctly report the number of available translation locales. * src/main/java/org/glom/web/server/libglom/Document.java: Fill the available locale IDs list. * src/test/java/org/glom/web/server/libglom/DocumentTest.java: testLocales: Test this. --- ChangeLog | 9 ++++++++ .../java/org/glom/web/server/libglom/Document.java | 26 +++++++++++++++------- .../org/glom/web/server/libglom/DocumentTest.java | 12 ++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index c7b8dc0..713b34a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2012-05-15 Murray Cumming + Document: Correctly report the number of available translation locales. + + * src/main/java/org/glom/web/server/libglom/Document.java: Fill + the available locale IDs list. + * src/test/java/org/glom/web/server/libglom/DocumentTest.java: + testLocales: Test this. + +2012-05-15 Murray Cumming + SqlUtils: Use camelCase. * src/main/java/org/glom/web/server/SqlUtils.java: Use camelCase. diff --git a/src/main/java/org/glom/web/server/libglom/Document.java b/src/main/java/org/glom/web/server/libglom/Document.java index dc2c869..3bbbfb0 100644 --- a/src/main/java/org/glom/web/server/libglom/Document.java +++ b/src/main/java/org/glom/web/server/libglom/Document.java @@ -75,12 +75,14 @@ public class Document { private org.w3c.dom.Document xmlDocument = null; private Translatable databaseTitle = new Translatable(); - private List translationAvailableLocales = new ArrayList(); // TODO + private String translationOriginalLocale = ""; + private List translationAvailableLocales = new ArrayList(); private String connectionServer = ""; private String connectionDatabase = ""; private int connectionPort = 0; private final Hashtable tablesMap = new Hashtable(); + private static final String ATTRIBUTE_TRANSLATION_ORIGINAL_LOCALE = "translation_original_locale"; private static final String NODE_CONNECTION = "connection"; private static final String ATTRIBUTE_CONNECTION_SERVER = "server"; private static final String ATTRIBUTE_CONNECTION_DATABASE = "database"; @@ -177,6 +179,16 @@ public class Document { databaseTitle.setTitleOriginal(rootNode.getAttribute(ATTRIBUTE_TITLE)); + translationOriginalLocale = rootNode.getAttribute(ATTRIBUTE_TRANSLATION_ORIGINAL_LOCALE); + translationAvailableLocales.add(translationOriginalLocale); //Just a cache. + + final Element nodeConnection = getElementByName(rootNode, NODE_CONNECTION); + if (nodeConnection != null) { + connectionServer = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_SERVER); + connectionDatabase = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_DATABASE); + connectionPort = getAttributeAsDecimal(nodeConnection, ATTRIBUTE_CONNECTION_PORT); + } + // We first load the fields, relationships, etc, // for all tables: final List listTableNodes = getChildrenByTagName(rootNode, NODE_TABLE); @@ -211,13 +223,6 @@ public class Document { tablesMap.put(info.getName(), info); } - final Element nodeConnection = getElementByName(rootNode, NODE_CONNECTION); - if (nodeConnection != null) { - connectionServer = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_SERVER); - connectionDatabase = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_DATABASE); - connectionPort = getAttributeAsDecimal(nodeConnection, ATTRIBUTE_CONNECTION_PORT); - } - return true; }; @@ -285,6 +290,11 @@ public class Document { final String translatedTitle = element.getAttribute(ATTRIBUTE_TRANSLATION_TITLE); if (!StringUtils.isEmpty(locale) && !StringUtils.isEmpty(translatedTitle)) { title.setTitle(translatedTitle, locale); + + //Remember any new translation locales in our cached list: + if(!translationAvailableLocales.contains(locale)) { + translationAvailableLocales.add(locale); + } } } } diff --git a/src/test/java/org/glom/web/server/libglom/DocumentTest.java b/src/test/java/org/glom/web/server/libglom/DocumentTest.java index 23d52b0..f9ecc22 100644 --- a/src/test/java/org/glom/web/server/libglom/DocumentTest.java +++ b/src/test/java/org/glom/web/server/libglom/DocumentTest.java @@ -84,6 +84,18 @@ public class DocumentTest { } @Test + public void testLocales() { + final List localeIDs = document.getTranslationAvailableLocales(); + assertEquals(8, localeIDs.size()); + + String tables = localeIDs.get(0); + for (int i = 1; i < localeIDs.size(); i++) { + tables += ", " + localeIDs.get(i); + } + assertThat(tables, is("en, cs, de, es, fr, gl, pt_BR, sl")); + } + + @Test public void testReadTableNames() { final List tableNames = document.getTableNames(); assertEquals(4, tableNames.size()); -- 2.1.4