Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Controls module for Magnolia CMS (http://www.openmindlab.com/lab/products/controls.html) Copyright(C) 2008-2013, 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.mgnlcontrols.dialog;
 
 import  info.magnolia.cms.core.Content;
 import  info.magnolia.cms.gui.dialog.DialogControlImpl;
 import  info.magnolia.cms.gui.dialog.DialogTab;
 import  info.magnolia.cms.i18n.I18nContentSupportFactory;
 import  info.magnolia.cms.security.AccessDeniedException;
 
 import java.io.Writer;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 

Author(s):
dschivo
Version:
$Id: I18nDialogTab.java 4282 2013-08-22 11:06:56Z lucaboati $
 
 public class I18nDialogTab extends DialogTab
 {

    
Used to make sure that the javascript files are loaded only once
 
     private static final String ATTRIBUTE_MOOTOOLS_LOADED = "info.magnolia.cms.gui.dialog.mootools.loaded";
 
     private static final String ATTRIBUTE_JQUERY_LOADED = "info.magnolia.cms.gui.dialog.jquery.loaded";
 
     private static final String ATTRIBUTE_I18NTAB_LOADED = "info.magnolia.cms.gui.dialog.i18ntab.loaded";
 
     private Map<StringStringmapLocales = new LinkedHashMap<StringString>();

    
Logger.
 
     private static Logger log = LoggerFactory.getLogger(I18nDialogTab.class);
 
     private Set<StringlocalesToRender;
 
     private String localeSuffixSeparator;
 
     private String visibleLocale;
 
     private String newLocale = .;
 
     private String jsFramework;

    
 
     @Override
     public void init(HttpServletRequest requestHttpServletResponse response, Content storageNode, Content configNode)
         throws RepositoryException
     {
         super.init(requestresponsestorageNodeconfigNode);
          = getConfigValue("localeSuffixSeparator""_");
          = request.getParameter("mgnlI18nLocale");
 
         setConfiguredLanguages(configNode);
 
         if ( != null)
         {
              = Collections.singleton();
              = ;
        }
        else
        {
             = getConfigValue("defaultLocale".keySet().iterator().next());
             = new HashSet<String>();
            Content node = getStorageNode();
            for (String locale : .keySet())
            {
                if (locale.equals()
                    || (node != null && !node.getNodeDataCollection('*' +  + locale).isEmpty()))
                {
                    .add(locale);
                }
            }
        }
         = getConfigValue("jsFramework""jquery");
    }

    
    @Override
    public void drawHtmlPreSubs(Writer outthrows IOException
    {
        if ( != null)
        {
            return;
        }
        Locale fallbackLocale = I18nContentSupportFactory.getI18nSupport().getFallbackLocale();
        String fallbackLocaleCode = fallbackLocale.toString();
        String jsFrameworkAttributeName;
        String jsFrameworkFilename;
        if ("jquery".equals())
        {
            jsFrameworkAttributeName = ;
            jsFrameworkFilename = "jquery.min.js";
        }
        else
        {
            jsFrameworkAttributeName = ;
            jsFrameworkFilename = "mootools-1.2.4-core-yc.js";
        }
        // load the script once: if there are multiple instances
        if (getRequest().getAttribute(jsFrameworkAttributeName) == null)
        {
            out.write("<script type=\"text/javascript\" src=\""
                + this.getRequest().getContextPath()
                + "/.resources/controls/js/"
                + jsFrameworkFilename
                + "\"></script>");
            getRequest().setAttribute(jsFrameworkAttributeName"true");
        }
        if (getRequest().getAttribute() == null)
        {
            out.write("<script type=\"text/javascript\" src=\""
                + getRequest().getContextPath()
                + "/.resources/controls/js/i18ntab-"
                + 
                + ".js\"></script>");
            // array with all locale names
            out.write("<script type=\"text/javascript\">");
            out.write("var i18nTabLocales = [");
            boolean firstElement = true;
            for (String locale : .keySet())
            {
                if (!firstElement)
                {
                    out.write(",");
                }
                out.write("'" + locale + "'");
                firstElement = false;
            }
            out.write("];");
            out.write("</script>");
            getRequest().setAttribute("true");
        }
        String id = getId();
        out.write("<script type=\"text/javascript\">");
        String options = "{ctx: '"
            + getRequest().getContextPath()
            + "', path: '"
            + getParent().getConfigValue("path")
            + "', nodeCollection: '"
            + getParent().getConfigValue("nodeCollection")
            + "', node: '"
            + getParent().getConfigValue("node")
            + "', dialog: '"
            + getParent().getName()
            + "', tab: '"
            + getName()
            + "'}";
        if ("jquery".equals())
        {
            out.write("$(document).ready(function() { new $.I18nTab('" + id + "', " + options + "); });");
        }
        else
        {
            out.write("window.addEvent('domready', function() { new I18nTab('" + id + "', " + options + "); });");
        }
        out.write("</script>");
        super.drawHtmlPreSubs(out);
        out.write("<tr>");
        out.write("<td class=\"mgnlDialogBoxLabel\">Locale</td>");
        out.write("<td class=\"mgnlDialogBoxInput\">");
        out.write("<select id=\"" + id + "_select\" class=\"mgnlDialogControlSelect\" style=\"width: 50%\">");
        for (String locale : .keySet())
        {
            addLocaleOption(outlocalefallbackLocaleCode);
        }
        out.write("</select>");
        out.write("</td>");
        out.write("</tr>");
        out.write("</table>");
    }

    

Parameters:
out
locale
fallbackLocaleCode
Throws:
IOException
    private void addLocaleOption(Writer outString localeString fallbackLocaleCodethrows IOException
    {
        out.write("<option value=\"");
        out.write(locale);
        out.write("\"");
        if (.contains(locale) || (fallbackLocaleCode.equals(locale) && .contains("")))
        {
            out.write(" style=\"background-color: #9DB517 !important; font-weight: bold;\"");
        }
        if (locale.equals())
        {
            out.write(" selected=\"selected\"");
        }
        out.write(">");
        out.write(.get(locale));
        if (StringUtils.isNotBlank(locale))
        {
            out.write(" (" + locale + ")");
        }
        if (StringUtils.equals(localefallbackLocaleCode))
        {
            out.write(" default");
        }
        out.write("</option>");
    }

    
    @Override
    protected void drawSubs(Writer outthrows IOException
    {
        String id = getId();
        List<StringoriginalSubNames = getSubNames();
        for (String locale : .keySet())
        {
            if (.contains(locale))
            {
                changeSubNames(originalSubNameslocale);
                for (Object o : getSubs())
                {
                    ((DialogControlImpl) o).setValue(null);
                }
                out.write("<table id=\""
                    + id
                    + "_table_"
                    + locale
                    + "\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"table-layout:fixed;"
                    + (locale.equals() ? "" : " display: none;")
                    + "\">");
                out.write("<col width=\"200\" /><col />");
                super.drawSubs(out);
                out.write("</table>");
            }
        }
        changeSubNames(originalSubNamesnull);
    }

    
    @Override
    public void drawHtmlPostSubs(Writer outthrows IOException
    {
        if ( != null)
        {
            return;
        }
        out.write("<div id=\"" + getId() + "_append\"></div>");
        out.write("</td></tr></table></div>");
    }
    private List<StringgetSubNames()
    {
        List<Stringnames = new ArrayList<String>(getSubs().size());
        for (Object o : getSubs())
        {
            names.add(((DialogControlImpl) o).getName());
        }
        return names;
    }
    private void changeSubNames(List<StringnamesString suffix)
    {
        int i = 0;
        for (Object o : getSubs())
        {
            DialogControlImpl subControl = (DialogControlImpl) o;
            subControl.setName(names.get(i)
                + (StringUtils.isBlank(suffix) ? . :  + suffix));
            i++;
        }
    }

    

Parameters:
configNode
Throws:
PathNotFoundException
RepositoryException
AccessDeniedException
    private void setConfiguredLanguages(Content configNodethrows PathNotFoundExceptionRepositoryException,
        AccessDeniedException
    {
        Locale fallbackLocale = I18nContentSupportFactory.getI18nSupport().getFallbackLocale();
        Collection<Localelocales = I18nContentSupportFactory.getI18nSupport().getLocales();
        for (Locale locale : locales)
        {
            String code = locale.toString();
            if (locale.equals(fallbackLocale))
            {
                .put(""locale.getDisplayName());
            }
            else
            {
                .put(codelocale.getDisplayName());
            }
        }
    }
New to GrepCode? Check out our FAQ X