private void addMenuItem(
     final MenuBuilder menuBuilder,
     final String location,
     final Entry<String, String> entry,
     final ExecutionMode executionMode,
     final String titleKey,
     ScriptMetaData metaData) {
   final String scriptName = entry.getKey();
   final String translation = TextUtils.getText(titleKey, titleKey.replace('_', ' '));
   final String menuName =
       translation.contains("{0}")
           ? MessageFormat.format(translation, pimpMenuTitle(scriptName))
           : translation;
   menuBuilder.addAction(
       location,
       new ExecuteScriptAction(
           scriptName,
           menuName,
           entry.getValue(),
           executionMode,
           metaData.cacheContent(),
           metaData.getPermissions()),
       MenuBuilder.AS_CHILD);
 }
 private void registerScripts(
     final MenuBuilder menuBuilder, ScriptingConfiguration configuration) {
   final HashSet<String> registeredLocations = new HashSet<String>();
   for (final String scriptsParentLocation : ScriptingConfiguration.getScriptsParentLocations()) {
     final String scriptsLocation =
         ScriptingConfiguration.getScriptsLocation(scriptsParentLocation);
     addSubMenu(
         menuBuilder,
         scriptsParentLocation,
         scriptsLocation,
         TextUtils.getText("ExecuteScripts.text"));
     registeredLocations.add(scriptsLocation);
     if (configuration.getNameScriptMap().isEmpty()) {
       final String message =
           "<html><body><em>"
               + TextUtils.getText("ExecuteScripts.noScriptsAvailable")
               + "</em></body></html>";
       menuBuilder.addElement(scriptsLocation, new JMenuItem(message), 0);
     }
     for (final Entry<String, String> entry : configuration.getNameScriptMap().entrySet()) {
       final String scriptName = entry.getKey();
       final ScriptMetaData metaData = configuration.getNameScriptMetaDataMap().get(scriptName);
       // in the worst case three actions will cache a script - should not matter that much since
       // it's unlikely
       // that one script is used in multiple modes by the same user
       for (final ExecutionMode executionMode : metaData.getExecutionModes()) {
         final String titleKey;
         final String scriptLocation;
         String location = metaData.getMenuLocation(executionMode);
         // FIXME: reduce code duplication (VB)
         if (location == null) {
           location = scriptsLocation + "/" + scriptName;
           if (!registeredLocations.contains(location)) {
             final String parentMenuTitle = pimpMenuTitle(metaData.getScriptName());
             addSubMenu(menuBuilder, parentLocation(location), location, parentMenuTitle);
             registeredLocations.add(location);
           }
           titleKey = metaData.getTitleKey(executionMode);
           scriptLocation = location + "/" + titleKey;
         } else {
           if (!registeredLocations.contains(location)) {
             addSubMenu(menuBuilder, parentLocation(location), location, getMenuTitle(location));
             registeredLocations.add(location);
           }
           titleKey = metaData.getTitleKey(executionMode);
           scriptLocation = location + "/" + titleKey;
         }
         if (!registeredLocations.contains(scriptLocation)) {
           addMenuItem(menuBuilder, location, entry, executionMode, titleKey, metaData);
           registeredLocations.add(scriptLocation);
         }
       }
     }
   }
 }