From: <fg...@us...> - 2010-12-18 16:45:47
|
Revision: 3186 http://openutils.svn.sourceforge.net/openutils/?rev=3186&view=rev Author: fgiust Date: 2010-12-18 16:45:40 +0000 (Sat, 18 Dec 2010) Log Message: ----------- MESSAGES-9 import/export now always includes all the locales/messages Modified Paths: -------------- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/configuration/MessagesConfigurationManager.java trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/RepositoryMessagesImpl.java trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/MessagesImpExpPage.java Added Paths: ----------- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/NoDefaultBundlesMessagesImpl.java Removed Paths: ------------- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/IgnoreMissingBundlesMessagesImpl.java Modified: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/configuration/MessagesConfigurationManager.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/configuration/MessagesConfigurationManager.java 2010-12-18 15:12:23 UTC (rev 3185) +++ trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/configuration/MessagesConfigurationManager.java 2010-12-18 16:45:40 UTC (rev 3186) @@ -57,6 +57,8 @@ private List<Locale> locales = new ArrayList<Locale>(); + public static final String MESSAGES_REPO = "messages"; + /** * {@inheritDoc} */ Modified: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/RepositoryMessagesImpl.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/RepositoryMessagesImpl.java 2010-12-18 15:12:23 UTC (rev 3185) +++ trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/RepositoryMessagesImpl.java 2010-12-18 16:45:40 UTC (rev 3186) @@ -31,7 +31,6 @@ import info.magnolia.context.MgnlContext; import java.util.ArrayList; -import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -41,6 +40,8 @@ import javax.jcr.observation.EventIterator; import javax.jcr.observation.EventListener; +import net.sourceforge.openutils.mgnlmessages.configuration.MessagesConfigurationManager; + import org.apache.commons.lang.StringUtils; @@ -51,8 +52,6 @@ public class RepositoryMessagesImpl extends AbstractMessagesImpl { - private static final String MESS_REPO = "messages"; - private List<String> keys; /** @@ -62,7 +61,7 @@ public RepositoryMessagesImpl(String basename, Locale locale) { super(basename, locale); - ObservationUtil.registerChangeListener(MESS_REPO, "/", new EventListener() + ObservationUtil.registerChangeListener(MessagesConfigurationManager.MESSAGES_REPO, "/", new EventListener() { public void onEvent(EventIterator events) @@ -86,7 +85,8 @@ try { String handle = StringUtils.replace(key, ".", "/"); - HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager(MESS_REPO); + HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager( + MessagesConfigurationManager.MESSAGES_REPO); Content c = hm.getContent(handle); String locale1 = this.locale.getLanguage() + "_" + this.locale.getCountry(); String locale2 = this.locale.getLanguage(); @@ -137,10 +137,11 @@ try { - QueryManager qm = MgnlContext.getSystemContext().getQueryManager(MESS_REPO); + QueryManager qm = MgnlContext.getSystemContext().getQueryManager( + MessagesConfigurationManager.MESSAGES_REPO); Query q = qm.createQuery("//*", Query.XPATH); QueryResult qr = q.execute(); - for (Content c : (Collection<Content>) qr.getContent(ItemType.CONTENTNODE.getSystemName())) + for (Content c : qr.getContent(ItemType.CONTENTNODE.getSystemName())) { if (c.getNodeDataCollection().size() > 0) { Deleted: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/IgnoreMissingBundlesMessagesImpl.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/IgnoreMissingBundlesMessagesImpl.java 2010-12-18 15:12:23 UTC (rev 3185) +++ trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/IgnoreMissingBundlesMessagesImpl.java 2010-12-18 16:45:40 UTC (rev 3186) @@ -1,130 +0,0 @@ -/** - * - * Messages Module for Magnolia CMS (http://www.openmindlab.com/lab/products/messages.html) - * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package net.sourceforge.openutils.mgnlmessages.pages; - -import info.magnolia.cms.util.ClasspathResourcesUtil; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Locale; -import java.util.PropertyResourceBundle; -import java.util.ResourceBundle; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; - - -/** - * @author molaschi - * @version $Id: DefaultMessagesImpl.java 4124 2008-09-22 14:56:46Z fgiust $ - */ -public class IgnoreMissingBundlesMessagesImpl extends info.magnolia.cms.i18n.DefaultMessagesImpl -{ - - /** - * @param basename - * @param locale - */ - public IgnoreMissingBundlesMessagesImpl(String basename, Locale locale) - { - super(basename, locale); - } - - /** - * {@inheritDoc} - */ - @Override - public String get(String key) - { - if (this.getBundle() == null) - { - return "??????"; - } - return super.get(key); - } - - /** - * {@inheritDoc} - */ - @Override - protected ResourceBundle getBundle() - { - if (bundle == null) - { - InputStream stream = null; - try - { - - String file = "/" - + StringUtils.replace(basename, ".", "/") - + "_" - + getLocale().getLanguage() - + (getLocale().getCountry() != null ? "_" + getLocale().getCountry() : "") - + ".properties"; - - log.debug("loading bundle {}", file); - - stream = ClasspathResourcesUtil.getStream(file, false); - - if (stream != null) - { - bundle = new PropertyResourceBundle(stream); - } - else - { - bundle = null; - } - } - catch (IOException e) - { - log.error("can't load messages for " + basename); - } - finally - { - IOUtils.closeQuietly(stream); - } - } - return bundle; - } - - /** - * {@inheritDoc} - */ - public boolean equals(Object object) - { - if (!(object instanceof IgnoreMissingBundlesMessagesImpl)) - { - return false; - } - IgnoreMissingBundlesMessagesImpl rhs = (IgnoreMissingBundlesMessagesImpl) object; - return new EqualsBuilder().append(this.basename, rhs.basename).append(this.locale, rhs.locale).isEquals(); - } - - /** - * {@inheritDoc} - */ - public int hashCode() - { - return new HashCodeBuilder(-399088031, -1971683455).append(basename).append(locale).toHashCode(); - } - -} Modified: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/MessagesImpExpPage.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/MessagesImpExpPage.java 2010-12-18 15:12:23 UTC (rev 3185) +++ trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/MessagesImpExpPage.java 2010-12-18 16:45:40 UTC (rev 3186) @@ -31,7 +31,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; @@ -39,6 +38,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import javax.jcr.RepositoryException; import javax.servlet.http.HttpServletRequest; @@ -101,7 +101,9 @@ for (Locale locale : locales) { log.debug("Adding locale {}", locale); - msgs.add(new IgnoreMissingBundlesMessagesImpl(basename, locale)); + NoDefaultBundlesMessagesImpl bundle = new NoDefaultBundlesMessagesImpl(basename, locale); + msgs.add(bundle); + bundle.get(""); } messages.put(basename, msgs); @@ -146,22 +148,20 @@ log.debug("Processing {} with {} locales", basename, msgs.size()); - Messages referencelocale = msgs.iterator().next(); - - log.debug("Using reference locale {}", referencelocale.getLocale()); - - @SuppressWarnings("unchecked") - Iterator<String> it = referencelocale.keys(); - List<String> keys = new ArrayList<String>(); - while (it.hasNext()) + Set<String> keys = new TreeSet<String>(); + for (Messages smessage : msgs) { - keys.add(it.next()); + log.debug("Extracting keys from locale {}", smessage.getLocale()); + @SuppressWarnings("unchecked") + Iterator<String> it = smessage.keys(); + while (it.hasNext()) + { + keys.add(it.next()); + } } - Collections.sort(keys); + log.debug("Bundle {} has {} keys", basename, keys.size()); - log.debug("Locale {} has {} keys", referencelocale.getLocale(), keys.size()); - int r = 1; // for each key create a row in the sheet for (String key : keys) @@ -189,14 +189,10 @@ headerCell.setCellValue(localeCode); String value = entry.get(key); cell = row.createCell(c); - if (!value.startsWith("???")) + if (value != null) { cell.setCellValue(value); } - else - { - cell.setCellValue(""); - } c++; } r++; @@ -311,6 +307,8 @@ } } + AlertUtil.setMessage("Translations successfully loaded"); + return this.show(); } Copied: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/NoDefaultBundlesMessagesImpl.java (from rev 3185, trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/IgnoreMissingBundlesMessagesImpl.java) =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/NoDefaultBundlesMessagesImpl.java (rev 0) +++ trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/NoDefaultBundlesMessagesImpl.java 2010-12-18 16:45:40 UTC (rev 3186) @@ -0,0 +1,192 @@ +/** + * + * Messages Module for Magnolia CMS (http://www.openmindlab.com/lab/products/messages.html) + * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmessages.pages; + +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.util.ClasspathResourcesUtil; +import info.magnolia.cms.util.NodeDataUtil; +import info.magnolia.context.MgnlContext; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.PropertyResourceBundle; +import java.util.ResourceBundle; + +import javax.jcr.RepositoryException; + +import net.sourceforge.openutils.mgnlmessages.configuration.MessagesConfigurationManager; +import net.sourceforge.openutils.mgnlmessages.i18n.EmptyResourceBundle; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.slf4j.LoggerFactory; + + +/** + * @author molaschi + * @version $Id: DefaultMessagesImpl.java 4124 2008-09-22 14:56:46Z fgiust $ + */ +public class NoDefaultBundlesMessagesImpl extends info.magnolia.cms.i18n.DefaultMessagesImpl +{ + + /** + * @param basename + * @param locale + */ + public NoDefaultBundlesMessagesImpl(String basename, Locale locale) + { + super(basename, locale); + log = LoggerFactory.getLogger(getClass()); + + log.debug("initializing bundle {}", basename); + } + + /** + * {@inheritDoc} + */ + @Override + public String get(String key) + { + if (this.getBundle() == null) + { + return null; + } + String value = getFromRepository(key); + + if (value == null) + { + try + { + value = getBundle().getString(key); + } + catch (MissingResourceException e) + { + // ignore + } + } + + return value; + } + + /** + * @param key + * @param value + * @return + */ + private String getFromRepository(String key) + { + try + { + String handle = StringUtils.replace(key, ".", "/"); + HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager( + MessagesConfigurationManager.MESSAGES_REPO); + Content c = hm.getContent(handle); + String locale1 = this.locale.getLanguage() + + (StringUtils.isEmpty(this.locale.getCountry()) ? "" : "_" + this.locale.getCountry()); + + if (c != null && c.hasNodeData(locale1)) + { + return NodeDataUtil.getString(c, locale1); + } + + } + catch (MissingResourceException e) + { + // ignore + } + catch (RepositoryException e) + { + // ignore + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + protected ResourceBundle getBundle() + { + if (bundle == null) + { + InputStream stream = null; + try + { + + String file = "/" + + StringUtils.replace(basename, ".", "/") + + "_" + + getLocale().getLanguage() + + (StringUtils.isEmpty(getLocale().getCountry()) ? "" : ("_" + getLocale().getCountry())) + + ".properties"; + + log.debug("loading bundle {}", file); + + stream = ClasspathResourcesUtil.getStream(file, false); + + if (stream != null) + { + bundle = new PropertyResourceBundle(stream); + } + else + { + // empty bundle + bundle = new EmptyResourceBundle(); + } + } + catch (IOException e) + { + log.error("can't load messages for " + basename); + } + finally + { + IOUtils.closeQuietly(stream); + } + } + return bundle; + } + + /** + * {@inheritDoc} + */ + public boolean equals(Object object) + { + if (!(object instanceof NoDefaultBundlesMessagesImpl)) + { + return false; + } + NoDefaultBundlesMessagesImpl rhs = (NoDefaultBundlesMessagesImpl) object; + return new EqualsBuilder().append(this.basename, rhs.basename).append(this.locale, rhs.locale).isEquals(); + } + + /** + * {@inheritDoc} + */ + public int hashCode() + { + return new HashCodeBuilder(-399088031, -1971683455).append(basename).append(locale).toHashCode(); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2011-08-26 07:23:06
|
Revision: 3642 http://openutils.svn.sourceforge.net/openutils/?rev=3642&view=rev Author: diego_schivo Date: 2011-08-26 07:23:00 +0000 (Fri, 26 Aug 2011) Log Message: ----------- MESSAGES-14 MessagesEl.messageTextContains Modified Paths: -------------- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/el/MessagesEl.java trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/MessagesEditPage.java Modified: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/el/MessagesEl.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/el/MessagesEl.java 2011-08-26 07:19:52 UTC (rev 3641) +++ trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/el/MessagesEl.java 2011-08-26 07:23:00 UTC (rev 3642) @@ -140,4 +140,9 @@ public static String escapeJs(String msg) { return StringEscapeUtils.escapeJavaScript(msg); } + + public static boolean messageTextContains(String str, String searchStr) + { + return StringUtils.containsIgnoreCase(str, searchStr); + } } Modified: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/MessagesEditPage.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/MessagesEditPage.java 2011-08-26 07:19:52 UTC (rev 3641) +++ trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/pages/MessagesEditPage.java 2011-08-26 07:23:00 UTC (rev 3642) @@ -42,6 +42,7 @@ import javax.servlet.http.HttpServletResponse; import net.sourceforge.openutils.mgnlmessages.configuration.MessagesConfigurationManager; +import net.sourceforge.openutils.mgnlmessages.el.MessagesEl; import net.sourceforge.openutils.mgnlmessages.lifecycle.MessagesModuleLifecycle; import org.apache.commons.lang.StringUtils; @@ -237,7 +238,7 @@ { String curKey = it.next(); String curText = messages.get(curKey); - if (StringUtils.containsIgnoreCase(curText, text)) + if (MessagesEl.messageTextContains(curText, text)) { set.add(curKey); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |